x.hpp 2.0KB

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