1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <cstdio>
  9. #include <string>
  10. #include <vector>
  11. namespace is {
  12. enum CursorType {
  13. Left,
  14. Crosshair,
  15. Cross,
  16. UpperLeftCorner,
  17. UpperRightCorner,
  18. LowerRightCorner,
  19. LowerLeftCorner
  20. };
  21. class WindowRectangle {
  22. public:
  23. int m_x;
  24. int m_y;
  25. unsigned int m_width;
  26. unsigned int m_height;
  27. unsigned int m_border;
  28. };
  29. class Rectangle {
  30. public:
  31. Rectangle( int x, int y, int width, int height, int border, int padding );
  32. ~Rectangle();
  33. void setPos( int x, int y );
  34. void setDim( int w, int h );
  35. Window m_window;
  36. int m_x;
  37. int m_y;
  38. int m_xoffset;
  39. int m_yoffset;
  40. int m_width;
  41. int m_height;
  42. int m_border;
  43. int m_padding;
  44. XColor m_forground, m_forgroundExact;
  45. XColor m_background, m_backgroundExact;
  46. };
  47. class XEngine {
  48. public:
  49. XEngine();
  50. ~XEngine();
  51. int init( std::string display );
  52. void tick();
  53. int grabCursor( is::CursorType type );
  54. int releaseCursor();
  55. void setCursor( is::CursorType type );
  56. void drawRect( int x, int y, unsigned int w, unsigned int h );
  57. void addRect( Rectangle* rect );
  58. void removeRect( Rectangle* rect );
  59. Display* m_display;
  60. Visual* m_visual;
  61. Screen* m_screen;
  62. Colormap m_colormap;
  63. Window m_root;
  64. int m_mousex;
  65. int m_mousey;
  66. std::vector<bool> m_mouse;
  67. bool mouseDown( unsigned int button );
  68. WindowRectangle m_hoverWindow;
  69. Window m_hoverXWindow;
  70. private:
  71. void updateHoverWindow();
  72. void updateHoverWindow( Window child );
  73. bool m_good;
  74. std::vector<Cursor> m_cursors;
  75. std::vector<Rectangle*> m_rects;
  76. Cursor getCursor( is::CursorType type );
  77. };
  78. }
  79. extern is::XEngine* xengine;
  80. #endif // IS_X_H_