x.hpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <stdlib.h>
  27. #include <cstring>
  28. #include <cstdlib>
  29. #include <cmath>
  30. #include <cstdio>
  31. #include <string>
  32. #include <vector>
  33. namespace slop {
  34. enum CursorType {
  35. Left,
  36. Crosshair,
  37. Cross,
  38. UpperLeftCorner,
  39. UpperRightCorner,
  40. LowerRightCorner,
  41. LowerLeftCorner,
  42. Dot,
  43. Box
  44. };
  45. class WindowRectangle {
  46. public:
  47. int m_x;
  48. int m_y;
  49. unsigned int m_width;
  50. unsigned int m_height;
  51. unsigned int m_border;
  52. Window m_window;
  53. bool m_decorations;
  54. Window getWindow();
  55. void setGeometry( Window win, bool decorations );
  56. void applyPadding( int padding );
  57. void applyMinMaxSize( unsigned int minimumsize, unsigned int maximumsize );
  58. };
  59. class XEngine {
  60. public:
  61. XEngine();
  62. ~XEngine();
  63. int init( std::string display );
  64. void tick();
  65. int grabCursor( slop::CursorType type, double waittime );
  66. int grabKeyboard();
  67. bool anyKeyPressed();
  68. bool keyPressed( KeySym key );
  69. int releaseCursor();
  70. int releaseKeyboard();
  71. void setCursor( slop::CursorType type );
  72. void drawRect( int x, int y, unsigned int w, unsigned int h );
  73. unsigned int getWidth();
  74. unsigned int getHeight();
  75. int m_mousex;
  76. int m_mousey;
  77. Display* m_display;
  78. Visual* m_visual;
  79. Screen* m_screen;
  80. Colormap m_colormap;
  81. Window m_root;
  82. Window m_hoverWindow;
  83. std::vector<bool> m_mouse;
  84. bool mouseDown( unsigned int button );
  85. bool m_keypressed;
  86. private:
  87. bool m_good;
  88. std::vector<Cursor> m_cursors;
  89. Cursor getCursor( slop::CursorType type );
  90. void selectAllInputs( Window win, long event_mask);
  91. };
  92. int XEngineErrorHandler( Display* dpy, XErrorEvent* event );
  93. }
  94. extern slop::XEngine* xengine;
  95. #endif // IS_X_H_