x.hpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* x.hpp: Handles starting and managing X.
  2. *
  3. * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
  4. *
  5. * This file is part of Slop.
  6. *
  7. * Slop is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Slop is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Slop. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef IS_X_H_
  21. #define IS_X_H_
  22. #include <unistd.h>
  23. #include <X11/Xlib.h>
  24. #include <X11/cursorfont.h>
  25. #include <X11/extensions/shape.h>
  26. #include <X11/extensions/Xrandr.h>
  27. #include <stdlib.h>
  28. #include <cstring>
  29. #include <cstdlib>
  30. #include <cmath>
  31. #include <cstdio>
  32. #include <string>
  33. #include <vector>
  34. namespace slop {
  35. enum CursorType {
  36. Left,
  37. Crosshair,
  38. Cross,
  39. UpperLeftCorner,
  40. UpperRightCorner,
  41. LowerRightCorner,
  42. LowerLeftCorner,
  43. Dot,
  44. Box
  45. };
  46. class WindowRectangle {
  47. public:
  48. int m_x;
  49. int m_y;
  50. unsigned int m_width;
  51. unsigned int m_height;
  52. unsigned int m_border;
  53. Window m_window;
  54. bool m_decorations;
  55. Window getWindow();
  56. void setGeometry( Window win, bool decorations );
  57. void applyPadding( int padding );
  58. void applyMinMaxSize( unsigned int minimumsize, unsigned int maximumsize );
  59. };
  60. class XEngine {
  61. public:
  62. XEngine();
  63. ~XEngine();
  64. int init( std::string display );
  65. void tick();
  66. int grabCursor( slop::CursorType type, double waittime );
  67. int grabKeyboard();
  68. bool anyKeyPressed();
  69. bool keyPressed( KeySym key );
  70. int releaseCursor();
  71. int releaseKeyboard();
  72. void setCursor( slop::CursorType type );
  73. slop::CursorType getCursor();
  74. void drawRect( int x, int y, unsigned int w, unsigned int h );
  75. unsigned int getWidth();
  76. unsigned int getHeight();
  77. #ifdef OPENGL_ENABLED
  78. std::vector<XRRCrtcInfo*> getCRTCS();
  79. void freeCRTCS( std::vector<XRRCrtcInfo*> monitors );
  80. #endif // OPENGL_ENABLED
  81. int m_mousex;
  82. int m_mousey;
  83. Display* m_display;
  84. Visual* m_visual;
  85. Screen* m_screen;
  86. Colormap m_colormap;
  87. Window m_root;
  88. Window m_hoverWindow;
  89. std::vector<bool> m_mouse;
  90. bool mouseDown( unsigned int button );
  91. bool m_keypressed;
  92. XRRScreenResources* m_res;
  93. private:
  94. slop::CursorType m_currentCursor;
  95. bool m_good;
  96. std::vector<Cursor> m_cursors;
  97. Cursor makeCursor( slop::CursorType type );
  98. void selectAllInputs( Window win, long event_mask);
  99. };
  100. int XEngineErrorHandler( Display* dpy, XErrorEvent* event );
  101. }
  102. extern slop::XEngine* xengine;
  103. #endif // IS_X_H_