Otclient  14/8/2020
x11window.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2016 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef X11WINDOW_H
24 #define X11WINDOW_H
25 
26 #include "platformwindow.h"
28 
29 #include <X11/Xlib.h>
30 #include <X11/Xatom.h>
31 
32 #ifdef OPENGL_ES
33 #include <EGL/egl.h>
34 #else
35 #include <GL/glx.h>
36 #endif
37 
38 class X11Window : public PlatformWindow
39 {
40  void internalOpenDisplay();
41  void internalCreateWindow();
42  bool internalSetupWindowInput();
43 
44  void internalCheckGL();
45  void internalChooseGLVisual();
46  void internalCreateGLContext();
47  void internalDestroyGLContext();
48  void internalConnectGLContext();
49 
50  void *getExtensionProcAddress(const char *ext);
51  bool isExtensionSupported(const char *ext);
52 
53 public:
54  X11Window();
55 
56  void init();
57  void terminate();
58 
59  void move(const Point& pos);
60  void resize(const Size& size);
61  void show();
62  void hide();
63  void maximize();
64  void poll();
65  void swapBuffers();
66  void showMouse();
67  void hideMouse();
68 
69  void setMouseCursor(int cursorId);
70  void restoreMouseCursor();
71 
72  void setTitle(const std::string& title);
73  void setMinimumSize(const Size& minimumSize);
74  void setFullscreen(bool fullscreen);
75  void setVerticalSync(bool enable);
76  void setIcon(const std::string& file);
77  void setClipboardText(const std::string& text);
78 
80  std::string getClipboardText();
81  std::string getPlatformType();
82 
83 protected:
84  int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot);
85 
86 private:
87  Display *m_display;
88  XVisualInfo *m_visual;
89  Window m_window;
90  Window m_rootWindow;
91  Colormap m_colormap;
92  std::vector<Cursor> m_cursors;
93  Cursor m_cursor;
94  Cursor m_hiddenCursor;
95  XIM m_xim;
96  XIC m_xic;
97  int m_screen;
98  Atom m_wmDelete;
99  std::string m_clipboardText;
100 
101 #ifndef OPENGL_ES
102  GLXContext m_glxContext;
103  GLXFBConfig *m_fbConfig;
104 #else
105  EGLConfig m_eglConfig;
106  EGLContext m_eglContext;
107  EGLDisplay m_eglDisplay;
108  EGLSurface m_eglSurface;
109 #endif
110 };
111 
112 #endif
113 
X11Window::X11Window
X11Window()
Definition: x11window.cpp:32
X11Window::init
void init()
Definition: x11window.cpp:211
X11Window::internalLoadMouseCursor
int internalLoadMouseCursor(const ImagePtr &image, const Point &hotSpot)
Definition: x11window.cpp:892
X11Window::setMinimumSize
void setMinimumSize(const Size &minimumSize)
Definition: x11window.cpp:936
X11Window::getPlatformType
std::string getPlatformType()
Definition: x11window.cpp:1070
platformwindow.h
X11Window::show
void show()
Definition: x11window.cpp:541
X11Window::move
void move(const Point &pos)
Definition: x11window.cpp:524
X11Window::setVerticalSync
void setVerticalSync(bool enable)
Definition: x11window.cpp:969
X11Window::hideMouse
void hideMouse()
Definition: x11window.cpp:855
PlatformWindow
Definition: platformwindow.h:32
glutil.h
X11Window::setTitle
void setTitle(const std::string &title)
Definition: x11window.cpp:930
X11Window::getDisplaySize
Size getDisplaySize()
Definition: x11window.cpp:1026
X11Window::setMouseCursor
void setMouseCursor(int cursorId)
Definition: x11window.cpp:874
X11Window::hide
void hide()
Definition: x11window.cpp:553
X11Window::restoreMouseCursor
void restoreMouseCursor()
Definition: x11window.cpp:886
X11Window::setIcon
void setIcon(const std::string &file)
Definition: x11window.cpp:987
X11Window::setClipboardText
void setClipboardText(const std::string &text)
Definition: x11window.cpp:1018
stdext::shared_object_ptr
Definition: shared_object.h:39
X11Window::poll
void poll()
Definition: x11window.cpp:584
X11Window::maximize
void maximize()
Definition: x11window.cpp:560
X11Window::swapBuffers
void swapBuffers()
Definition: x11window.cpp:841
X11Window::resize
void resize(const Size &size)
Definition: x11window.cpp:533
X11Window::terminate
void terminate()
Definition: x11window.cpp:220
TPoint< int >
X11Window::getClipboardText
std::string getClipboardText()
Definition: x11window.cpp:1031
TSize< int >
X11Window::setFullscreen
void setFullscreen(bool fullscreen)
Definition: x11window.cpp:946
X11Window::showMouse
void showMouse()
Definition: x11window.cpp:850
X11Window
Definition: x11window.h:38