1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 Rectangle {
  22. public:
  23. Rectangle( int x, int y, int width, int height, int border, int padding );
  24. ~Rectangle();
  25. void setPos( int x, int y );
  26. void setDim( int w, int h );
  27. void draw();
  28. Window m_window;
  29. int m_x;
  30. int m_y;
  31. int m_xoffset;
  32. int m_yoffset;
  33. int m_width;
  34. int m_height;
  35. int m_border;
  36. int m_padding;
  37. XColor m_forground, m_forgroundExact;
  38. XColor m_background, m_backgroundExact;
  39. };
  40. class XEngine {
  41. public:
  42. XEngine();
  43. ~XEngine();
  44. int init( std::string display );
  45. void tick();
  46. int grabCursor( is::CursorType type );
  47. int releaseCursor();
  48. void setCursor( is::CursorType type );
  49. void drawRect( int x, int y, unsigned int w, unsigned int h );
  50. void addRect( Rectangle* rect );
  51. void removeRect( Rectangle* rect );
  52. Display* m_display;
  53. Visual* m_visual;
  54. Screen* m_screen;
  55. Colormap m_colormap;
  56. Window m_root;
  57. int m_mousex;
  58. int m_mousey;
  59. std::vector<bool> m_mouse;
  60. bool mouseDown( unsigned int button );
  61. private:
  62. bool m_good;
  63. std::vector<Cursor> m_cursors;
  64. std::vector<Rectangle*> m_rects;
  65. Cursor getCursor( is::CursorType type );
  66. };
  67. }
  68. extern is::XEngine* xengine;
  69. #endif // IS_X_H_