123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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( int minimumsize, 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 );
  66. int grabKeyboard();
  67. bool anyKeyPressed();
  68. int releaseCursor();
  69. int releaseKeyboard();
  70. void setCursor( slop::CursorType type );
  71. void drawRect( int x, int y, unsigned int w, unsigned int h );
  72. int getWidth();
  73. int getHeight();
  74. int m_mousex;
  75. int m_mousey;
  76. Display* m_display;
  77. Visual* m_visual;
  78. Screen* m_screen;
  79. Colormap m_colormap;
  80. Window m_root;
  81. Window m_hoverWindow;
  82. std::vector<bool> m_mouse;
  83. bool mouseDown( unsigned int button );
  84. bool m_keypressed;
  85. private:
  86. bool m_good;
  87. std::vector<Cursor> m_cursors;
  88. Cursor getCursor( slop::CursorType type );
  89. void selectAllInputs( Window win, long event_mask);
  90. };
  91. int XEngineErrorHandler( Display* dpy, XErrorEvent* event );
  92. }
  93. extern slop::XEngine* xengine;
  94. #endif // IS_X_H_