x.hpp 2.2KB

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