x.hpp 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. };
  23. class WindowRectangle {
  24. public:
  25. int m_x;
  26. int m_y;
  27. unsigned int m_width;
  28. unsigned int m_height;
  29. unsigned int m_border;
  30. bool m_decorations;
  31. void setGeometry( Window win, bool decorations );
  32. };
  33. class XEngine {
  34. public:
  35. XEngine();
  36. ~XEngine();
  37. int init( std::string display );
  38. void tick();
  39. int grabCursor( slop::CursorType type );
  40. int grabKeyboard();
  41. bool anyKeyPressed();
  42. int releaseCursor();
  43. int releaseKeyboard();
  44. void setCursor( slop::CursorType type );
  45. void drawRect( int x, int y, unsigned int w, unsigned int h );
  46. int m_mousex;
  47. int m_mousey;
  48. Display* m_display;
  49. Visual* m_visual;
  50. Screen* m_screen;
  51. Colormap m_colormap;
  52. Window m_root;
  53. Window m_hoverWindow;
  54. std::vector<bool> m_mouse;
  55. bool mouseDown( unsigned int button );
  56. bool m_keypressed;
  57. private:
  58. bool m_good;
  59. std::vector<Cursor> m_cursors;
  60. Cursor getCursor( slop::CursorType type );
  61. void selectAllInputs( Window win, long event_mask);
  62. };
  63. int XEngineErrorHandler( Display* dpy, XErrorEvent* event );
  64. }
  65. extern slop::XEngine* xengine;
  66. #endif // IS_X_H_