x.hpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // x.hpp: handles starting and managing X
  2. #ifndef IS_X_H_
  3. #define IS_X_H_
  4. #include <unistd.h>
  5. #include <X11/Xlib.h>
  6. #include <X11/cursorfont.h>
  7. #include <X11/extensions/shape.h>
  8. #include <cstdlib>
  9. #include <cmath>
  10. #include <cstdio>
  11. #include <string>
  12. #include <vector>
  13. namespace slop {
  14. enum CursorType {
  15. Left,
  16. Crosshair,
  17. Cross,
  18. UpperLeftCorner,
  19. UpperRightCorner,
  20. LowerRightCorner,
  21. LowerLeftCorner,
  22. Dot,
  23. Box
  24. };
  25. class WindowRectangle {
  26. public:
  27. int m_x;
  28. int m_y;
  29. unsigned int m_width;
  30. unsigned int m_height;
  31. unsigned int m_border;
  32. bool m_decorations;
  33. void setGeometry( Window win, bool decorations );
  34. void applyPadding( int padding );
  35. void applyMinMaxSize( int minimumsize, int maximumsize );
  36. };
  37. class XEngine {
  38. public:
  39. XEngine();
  40. ~XEngine();
  41. int init( std::string display );
  42. void tick();
  43. int grabCursor( slop::CursorType type );
  44. int grabKeyboard();
  45. bool anyKeyPressed();
  46. int releaseCursor();
  47. int releaseKeyboard();
  48. void setCursor( slop::CursorType type );
  49. void drawRect( int x, int y, unsigned int w, unsigned int h );
  50. int getWidth();
  51. int getHeight();
  52. int m_mousex;
  53. int m_mousey;
  54. Display* m_display;
  55. Visual* m_visual;
  56. Screen* m_screen;
  57. Colormap m_colormap;
  58. Window m_root;
  59. Window m_hoverWindow;
  60. std::vector<bool> m_mouse;
  61. bool mouseDown( unsigned int button );
  62. bool m_keypressed;
  63. private:
  64. bool m_good;
  65. std::vector<Cursor> m_cursors;
  66. Cursor getCursor( slop::CursorType type );
  67. void selectAllInputs( Window win, long event_mask);
  68. };
  69. int XEngineErrorHandler( Display* dpy, XErrorEvent* event );
  70. }
  71. extern slop::XEngine* xengine;
  72. #endif // IS_X_H_