1 | // LAF OS Library |
2 | // Copyright (C) 2018-2022 Igara Studio S.A. |
3 | // Copyright (C) 2016-2018 David Capello |
4 | // |
5 | // This file is released under the terms of the MIT license. |
6 | // Read LICENSE.txt for more information. |
7 | |
8 | #ifndef OS_X11_WINDOW_INCLUDED |
9 | #define OS_X11_WINDOW_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "base/time.h" |
13 | #include "gfx/border.h" |
14 | #include "gfx/color_space.h" // Include here avoid error with None |
15 | #include "gfx/fwd.h" |
16 | #include "gfx/size.h" |
17 | #include "os/color_space.h" |
18 | #include "os/event.h" |
19 | #include "os/native_cursor.h" |
20 | #include "os/screen.h" |
21 | #include "os/surface_list.h" |
22 | #include "os/window.h" |
23 | |
24 | #include <X11/Xatom.h> |
25 | #include <X11/Xlib.h> |
26 | #include <X11/Xutil.h> |
27 | |
28 | #include <cstring> |
29 | #include <string> |
30 | |
31 | namespace os { |
32 | |
33 | class Surface; |
34 | class WindowSpec; |
35 | |
36 | class WindowX11 : public Window { |
37 | public: |
38 | WindowX11(::Display* display, |
39 | const WindowSpec& spec); |
40 | ~WindowX11(); |
41 | |
42 | os::ScreenRef screen() const override; |
43 | os::ColorSpaceRef colorSpace() const override; |
44 | |
45 | int scale() const override { return m_scale; } |
46 | void setScale(const int scale) override; |
47 | |
48 | bool isVisible() const override; |
49 | void setVisible(bool visible) override; |
50 | |
51 | void activate() override; |
52 | void maximize() override; |
53 | void minimize() override; |
54 | bool isMaximized() const override; |
55 | bool isMinimized() const override; |
56 | bool isTransparent() const override; |
57 | |
58 | bool isFullscreen() const override; |
59 | void setFullscreen(bool state) override; |
60 | |
61 | void setTitle(const std::string& title) override; |
62 | void setIcons(const SurfaceList& icons) override; |
63 | |
64 | gfx::Rect frame() const override; |
65 | void setFrame(const gfx::Rect& bounds) override; |
66 | gfx::Rect contentRect() const override; |
67 | gfx::Rect restoredFrame() const override; |
68 | std::string title() const override; |
69 | |
70 | gfx::Size clientSize() const; |
71 | void captureMouse() override; |
72 | void releaseMouse() override; |
73 | void setMousePosition(const gfx::Point& position) override; |
74 | void invalidateRegion(const gfx::Region& rgn) override; |
75 | bool setCursor(NativeCursor cursor) override; |
76 | bool setCursor(const CursorRef& cursor) override; |
77 | |
78 | void performWindowAction(const WindowAction action, |
79 | const Event* event) override; |
80 | |
81 | ::Display* x11display() const { return m_display; } |
82 | ::Window x11window() const { return m_window; } |
83 | ::GC gc() const { return m_gc; } |
84 | |
85 | NativeHandle nativeHandle() const override { return (NativeHandle)x11window(); } |
86 | |
87 | void setTranslateDeadKeys(bool state) { |
88 | g_translateDeadKeys = state; |
89 | } |
90 | |
91 | static bool translateDeadKeys() { |
92 | return g_translateDeadKeys; |
93 | } |
94 | |
95 | void processX11Event(XEvent& event); |
96 | static WindowX11* getPointerFromHandle(::Window handle); |
97 | |
98 | // Only used for debugging purposes. |
99 | static size_t countActiveWindows(); |
100 | |
101 | protected: |
102 | virtual void onPaint(const gfx::Rect& rc) = 0; |
103 | virtual void onResize(const gfx::Size& sz) = 0; |
104 | |
105 | private: |
106 | void setWMClass(const std::string& res_class); |
107 | void setAllowedActions(); |
108 | bool setX11Cursor(::Cursor xcursor); |
109 | bool requestX11FrameExtents(); |
110 | void getX11FrameExtents(); |
111 | static void addWindow(WindowX11* window); |
112 | static void removeWindow(WindowX11* window); |
113 | |
114 | ::Display* m_display; |
115 | ::Window m_window; |
116 | ::GC m_gc; |
117 | ::XIC m_xic; |
118 | int m_scale; |
119 | gfx::Point m_lastMousePos; |
120 | gfx::Size m_lastClientSize; |
121 | gfx::Border m_frameExtents; |
122 | bool m_initializingActions = true; |
123 | bool m_fullscreen = false; |
124 | bool m_borderless = false; |
125 | bool m_closable = false; |
126 | bool m_maximizable = false; |
127 | bool m_minimizable = false; |
128 | bool m_resizable = false; |
129 | bool m_transparent = false; |
130 | |
131 | // Double-click info |
132 | Event::MouseButton m_doubleClickButton; |
133 | base::tick_t m_doubleClickTick; |
134 | |
135 | static bool g_translateDeadKeys; |
136 | }; |
137 | |
138 | } // namespace os |
139 | |
140 | #endif |
141 | |