x11GraphicsWindow.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Filename: x11GraphicsWindow.h
  2. // Created by: rdb (07Jul09)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef X11GRAPHICSWINDOW_H
  15. #define X11GRAPHICSWINDOW_H
  16. #include "pandabase.h"
  17. #include "x11GraphicsPipe.h"
  18. #include "graphicsWindow.h"
  19. #include "buttonHandle.h"
  20. #ifdef HAVE_XRANDR
  21. typedef unsigned short Rotation;
  22. typedef unsigned short SizeID;
  23. #endif
  24. ////////////////////////////////////////////////////////////////////
  25. // Class : x11GraphicsWindow
  26. // Description : Interfaces to the X11 window system.
  27. ////////////////////////////////////////////////////////////////////
  28. class x11GraphicsWindow : public GraphicsWindow {
  29. public:
  30. x11GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
  31. const string &name,
  32. const FrameBufferProperties &fb_prop,
  33. const WindowProperties &win_prop,
  34. int flags,
  35. GraphicsStateGuardian *gsg,
  36. GraphicsOutput *host);
  37. virtual ~x11GraphicsWindow();
  38. virtual bool move_pointer(int device, int x, int y);
  39. virtual bool begin_frame(FrameMode mode, Thread *current_thread);
  40. virtual void end_frame(FrameMode mode, Thread *current_thread);
  41. virtual void process_events();
  42. virtual void set_properties_now(WindowProperties &properties);
  43. INLINE X11_Window get_xwindow() const;
  44. protected:
  45. virtual void close_window();
  46. virtual bool open_window();
  47. virtual void mouse_mode_absolute();
  48. virtual void mouse_mode_relative();
  49. void set_wm_properties(const WindowProperties &properties,
  50. bool already_mapped);
  51. virtual void setup_colormap(XVisualInfo *visual);
  52. void handle_keystroke(XKeyEvent &event);
  53. void handle_keypress(XKeyEvent &event);
  54. void handle_keyrelease(XKeyEvent &event);
  55. ButtonHandle get_button(XKeyEvent &key_event, bool allow_shift);
  56. ButtonHandle map_button(KeySym key) const;
  57. ButtonHandle map_raw_button(KeyCode key) const;
  58. ButtonHandle get_mouse_button(XButtonEvent &button_event);
  59. virtual ButtonMap *get_keyboard_map() const;
  60. static Bool check_event(X11_Display *display, XEvent *event, char *arg);
  61. void open_raw_mice();
  62. void poll_raw_mice();
  63. private:
  64. X11_Cursor get_cursor(const Filename &filename);
  65. #ifdef HAVE_XCURSOR
  66. X11_Cursor read_ico(istream &ico);
  67. #endif
  68. protected:
  69. X11_Display *_display;
  70. int _screen;
  71. X11_Window _xwindow;
  72. Colormap _colormap;
  73. XIC _ic;
  74. XVisualInfo *_visual_info;
  75. bool _have_xrandr;
  76. #ifdef HAVE_XRANDR
  77. Rotation _orig_rotation;
  78. SizeID _orig_size_id;
  79. #endif
  80. LVecBase2i _fixed_size;
  81. long _event_mask;
  82. bool _awaiting_configure;
  83. bool _dga_mouse_enabled;
  84. Bool _override_redirect;
  85. Atom _wm_delete_window;
  86. struct MouseDeviceInfo {
  87. int _fd;
  88. int _input_device_index;
  89. string _io_buffer;
  90. };
  91. pvector<MouseDeviceInfo> _mouse_device_info;
  92. public:
  93. static TypeHandle get_class_type() {
  94. return _type_handle;
  95. }
  96. static void init_type() {
  97. GraphicsWindow::init_type();
  98. register_type(_type_handle, "x11GraphicsWindow",
  99. GraphicsWindow::get_class_type());
  100. }
  101. virtual TypeHandle get_type() const {
  102. return get_class_type();
  103. }
  104. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  105. private:
  106. static TypeHandle _type_handle;
  107. // Since the Panda API requests icons and cursors by filename, we
  108. // need a table mapping filenames to handles, so we can avoid
  109. // re-reading the file each time we change icons.
  110. pmap<Filename, X11_Cursor> _cursor_filenames;
  111. };
  112. #include "x11GraphicsWindow.I"
  113. #endif