x.hpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. bool m_decorations;
  53. void setGeometry( Window win, bool decorations );
  54. void applyPadding( int padding );
  55. void applyMinMaxSize( int minimumsize, int maximumsize );
  56. };
  57. class XEngine {
  58. public:
  59. XEngine();
  60. ~XEngine();
  61. int init( std::string display );
  62. void tick();
  63. int grabCursor( slop::CursorType type );
  64. int grabKeyboard();
  65. bool anyKeyPressed();
  66. int releaseCursor();
  67. int releaseKeyboard();
  68. void setCursor( slop::CursorType type );
  69. void drawRect( int x, int y, unsigned int w, unsigned int h );
  70. int getWidth();
  71. int getHeight();
  72. int m_mousex;
  73. int m_mousey;
  74. Display* m_display;
  75. Visual* m_visual;
  76. Screen* m_screen;
  77. Colormap m_colormap;
  78. Window m_root;
  79. Window m_hoverWindow;
  80. std::vector<bool> m_mouse;
  81. bool mouseDown( unsigned int button );
  82. bool m_keypressed;
  83. private:
  84. bool m_good;
  85. std::vector<Cursor> m_cursors;
  86. Cursor getCursor( slop::CursorType type );
  87. void selectAllInputs( Window win, long event_mask);
  88. };
  89. int XEngineErrorHandler( Display* dpy, XErrorEvent* event );
  90. }
  91. extern slop::XEngine* xengine;
  92. #endif // IS_X_H_