123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. void draw();
  36. Window m_window;
  37. int m_x;
  38. int m_y;
  39. int m_xoffset;
  40. int m_yoffset;
  41. int m_width;
  42. int m_height;
  43. int m_border;
  44. int m_padding;
  45. XColor m_forground, m_forgroundExact;
  46. XColor m_background, m_backgroundExact;
  47. };
  48. class XEngine {
  49. public:
  50. XEngine();
  51. ~XEngine();
  52. int init( std::string display );
  53. void tick();
  54. int grabCursor( is::CursorType type );
  55. int releaseCursor();
  56. void setCursor( is::CursorType type );
  57. void drawRect( int x, int y, unsigned int w, unsigned int h );
  58. void addRect( Rectangle* rect );
  59. void removeRect( Rectangle* rect );
  60. Display* m_display;
  61. Visual* m_visual;
  62. Screen* m_screen;
  63. Colormap m_colormap;
  64. Window m_root;
  65. int m_mousex;
  66. int m_mousey;
  67. std::vector<bool> m_mouse;
  68. bool mouseDown( unsigned int button );
  69. WindowRectangle m_hoverWindow;
  70. Window m_hoverXWindow;
  71. private:
  72. void updateHoverWindow();
  73. void updateHoverWindow( Window child );
  74. bool m_good;
  75. std::vector<Cursor> m_cursors;
  76. std::vector<Rectangle*> m_rects;
  77. Cursor getCursor( is::CursorType type );
  78. };
  79. }
  80. extern is::XEngine* xengine;
  81. #endif // IS_X_H_