12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <cstring>
  9. #include <cstdlib>
  10. #include <cmath>
  11. #include <cstdio>
  12. #include <string>
  13. #include <vector>
  14. namespace slop {
  15. enum CursorType {
  16. Left,
  17. Crosshair,
  18. Cross,
  19. UpperLeftCorner,
  20. UpperRightCorner,
  21. LowerRightCorner,
  22. LowerLeftCorner,
  23. Dot,
  24. Box
  25. };
  26. class WindowRectangle {
  27. public:
  28. int m_x;
  29. int m_y;
  30. unsigned int m_width;
  31. unsigned int m_height;
  32. unsigned int m_border;
  33. bool m_decorations;
  34. void setGeometry( Window win, bool decorations );
  35. void applyPadding( int padding );
  36. void applyMinMaxSize( int minimumsize, int maximumsize );
  37. };
  38. class XEngine {
  39. public:
  40. XEngine();
  41. ~XEngine();
  42. int init( std::string display );
  43. void tick();
  44. int grabCursor( slop::CursorType type );
  45. int grabKeyboard();
  46. bool anyKeyPressed();
  47. int releaseCursor();
  48. int releaseKeyboard();
  49. void setCursor( slop::CursorType type );
  50. void drawRect( int x, int y, unsigned int w, unsigned int h );
  51. int getWidth();
  52. int getHeight();
  53. int m_mousex;
  54. int m_mousey;
  55. Display* m_display;
  56. Visual* m_visual;
  57. Screen* m_screen;
  58. Colormap m_colormap;
  59. Window m_root;
  60. Window m_hoverWindow;
  61. std::vector<bool> m_mouse;
  62. bool mouseDown( unsigned int button );
  63. bool m_keypressed;
  64. private:
  65. bool m_good;
  66. std::vector<Cursor> m_cursors;
  67. Cursor getCursor( slop::CursorType type );
  68. void selectAllInputs( Window win, long event_mask);
  69. };
  70. int XEngineErrorHandler( Display* dpy, XErrorEvent* event );
  71. }
  72. extern slop::XEngine* xengine;
  73. #endif // IS_X_H_