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