JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_XWindowSystem_linux.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
30namespace XWindowSystemUtilities
31{
32 //==============================================================================
39 {
42 };
43
44 //==============================================================================
51 {
52 GetXProperty (::Display* display, ::Window windowH, Atom property,
53 long offset, long length, bool shouldDelete, Atom requestedType);
55
56 bool success = false;
57 unsigned char* data = nullptr;
58 unsigned long numItems = 0, bytesLeft = 0;
59 Atom actualType;
60 int actualFormat = -1;
61 };
62
63 //==============================================================================
68 struct Atoms
69 {
70 enum ProtocolItems
71 {
72 TAKE_FOCUS = 0,
73 DELETE_WINDOW = 1,
74 PING = 2
75 };
76
77 Atoms() = default;
78 explicit Atoms (::Display*);
79
80 static Atom getIfExists (::Display*, const char* name);
81 static Atom getCreating (::Display*, const char* name);
82
83 static String getName (::Display*, Atom);
84 static bool isMimeTypeFile (::Display*, Atom);
85
86 static constexpr unsigned long DndVersion = 3;
87
88 Atom protocols, protocolList[3], changeState, state, userTime, activeWin, pid, windowType, windowState, windowStateHidden,
89 XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus, XdndDrop, XdndFinished, XdndSelection,
90 XdndTypeList, XdndActionList, XdndActionDescription, XdndActionCopy, XdndActionPrivate,
91 XembedMsgType, XembedInfo, allowedActions[5], allowedMimeTypes[4], utf8String, clipboard, targets;
92 };
93
94 //==============================================================================
99 struct XSetting
100 {
101 enum class Type
102 {
103 integer,
104 string,
105 colour,
106 invalid
107 };
108
109 XSetting() = default;
110
111 XSetting (const String& n, int v) : name (n), type (Type::integer), integerValue (v) {}
112 XSetting (const String& n, const String& v) : name (n), type (Type::string), stringValue (v) {}
113 XSetting (const String& n, const Colour& v) : name (n), type (Type::colour), colourValue (v) {}
114
115 bool isValid() const noexcept { return type != Type::invalid; }
116
117 String name;
118 Type type = Type::invalid;
119
120 int integerValue = -1;
121 String stringValue;
122 Colour colourValue;
123 };
124
131 {
132 public:
133 static std::unique_ptr<XSettings> createXSettings (::Display*);
134
135 //==============================================================================
136 void update();
137 ::Window getSettingsWindow() const noexcept { return settingsWindow; }
138
139 XSetting getSetting (const String& settingName) const;
140
141 //==============================================================================
142 struct Listener
143 {
144 virtual ~Listener() = default;
145 virtual void settingChanged (const XSetting& settingThatHasChanged) = 0;
146 };
147
148 void addListener (Listener* listenerToAdd) { listeners.add (listenerToAdd); }
149 void removeListener (Listener* listenerToRemove) { listeners.remove (listenerToRemove); }
150
151 private:
152 ::Display* display = nullptr;
153 ::Window settingsWindow = None;
154 Atom settingsAtom;
155
156 int lastUpdateSerial = -1;
157
159 ListenerList<Listener> listeners;
160
161 XSettings (::Display*, Atom, ::Window);
162
163 //==============================================================================
165 };
166}
167
168//==============================================================================
169class LinuxComponentPeer;
170
172{
173public:
174 //==============================================================================
175 ::Window createWindow (::Window parentWindow, LinuxComponentPeer*) const;
176 void destroyWindow (::Window);
177
178 void setTitle (::Window, const String&) const;
179 void setIcon (::Window , const Image&) const;
180 void setVisible (::Window, bool shouldBeVisible) const;
181 void setBounds (::Window, Rectangle<int>, bool fullScreen) const;
182 void updateConstraints (::Window) const;
183
184 ComponentPeer::OptionalBorderSize getBorderSize (::Window) const;
185 Rectangle<int> getWindowBounds (::Window, ::Window parentWindow);
186 Point<int> getPhysicalParentScreenPosition() const;
187
188 bool contains (::Window, Point<int> localPos) const;
189
190 void setMinimised (::Window, bool shouldBeMinimised) const;
191 bool isMinimised (::Window) const;
192
193 void setMaximised (::Window, bool shouldBeMinimised) const;
194
195 void toFront (::Window, bool makeActive) const;
196 void toBehind (::Window, ::Window otherWindow) const;
197
198 bool isFocused (::Window) const;
199 bool grabFocus (::Window) const;
200
201 bool canUseSemiTransparentWindows() const;
202 bool canUseARGBImages() const;
203 bool isDarkModeActive() const;
204
205 int getNumPaintsPendingForWindow (::Window);
206 void processPendingPaintsForWindow (::Window);
207 void addPendingPaintForWindow (::Window);
208 void removePendingPaintForWindow (::Window);
209
210 Image createImage (bool isSemiTransparentWindow, int width, int height, bool argb) const;
211 void blitToWindow (::Window, Image, Rectangle<int> destinationRect, Rectangle<int> totalRect) const;
212
213 void setScreenSaverEnabled (bool enabled) const;
214
215 Point<float> getCurrentMousePosition() const;
216 void setMousePosition (Point<float> pos) const;
217
218 Cursor createCustomMouseCursorInfo (const Image&, Point<int> hotspot) const;
219 void deleteMouseCursor (Cursor cursorHandle) const;
220 Cursor createStandardMouseCursor (MouseCursor::StandardCursorType) const;
221 void showCursor (::Window, Cursor cursorHandle) const;
222
223 bool isKeyCurrentlyDown (int keyCode) const;
224 ModifierKeys getNativeRealtimeModifiers() const;
225
226 Array<Displays::Display> findDisplays (float masterScale) const;
227
228 ::Window createKeyProxy (::Window);
229 void deleteKeyProxy (::Window) const;
230
231 bool externalDragFileInit (LinuxComponentPeer*, const StringArray& files, bool canMove, std::function<void()>&& callback) const;
232 bool externalDragTextInit (LinuxComponentPeer*, const String& text, std::function<void()>&& callback) const;
233
234 void copyTextToClipboard (const String&);
235 String getTextFromClipboard() const;
236 String getLocalClipboardContent() const noexcept { return localClipboardContent; }
237
238 ::Display* getDisplay() const noexcept { return display; }
239 const XWindowSystemUtilities::Atoms& getAtoms() const noexcept { return atoms; }
240 XWindowSystemUtilities::XSettings* getXSettings() const noexcept { return xSettings.get(); }
241
242 bool isX11Available() const noexcept { return xIsAvailable; }
243
244 void startHostManagedResize (::Window window,
246
247 static String getWindowScalingFactorSettingName() { return "Gdk/WindowScalingFactor"; }
248 static String getThemeNameSettingName() { return "Net/ThemeName"; }
249
250 //==============================================================================
251 void handleWindowMessage (LinuxComponentPeer*, XEvent&) const;
252 bool isParentWindowOf (::Window, ::Window possibleChild) const;
253
254 //==============================================================================
256
257private:
260
261 //==============================================================================
262 struct VisualAndDepth
263 {
264 Visual* visual;
265 int depth;
266 };
267
268 struct DisplayVisuals
269 {
270 explicit DisplayVisuals (::Display*);
271
272 VisualAndDepth getBestVisualForWindow (bool) const;
273 bool isValid() const noexcept;
274
275 Visual* visual16Bit = nullptr;
276 Visual* visual24Bit = nullptr;
277 Visual* visual32Bit = nullptr;
278 };
279
280 bool initialiseXDisplay();
281 void destroyXDisplay();
282
283 //==============================================================================
284 ::Window getFocusWindow (::Window) const;
285
286 bool isFrontWindow (::Window) const;
287
288 //==============================================================================
289 void xchangeProperty (::Window, Atom, Atom, int, const void*, int) const;
290
291 void removeWindowDecorations (::Window) const;
292 void addWindowButtons (::Window, int) const;
293 void setWindowType (::Window, int) const;
294
295 void initialisePointerMap();
296 void deleteIconPixmaps (::Window) const;
297 void updateModifierMappings() const;
298
299 long getUserTime (::Window) const;
300 bool isHidden (Window) const;
301 bool isIconic (Window) const;
302
303 void initialiseXSettings();
304
305 //==============================================================================
306 void handleKeyPressEvent (LinuxComponentPeer*, XKeyEvent&) const;
307 void handleKeyReleaseEvent (LinuxComponentPeer*, const XKeyEvent&) const;
308 void handleWheelEvent (LinuxComponentPeer*, const XButtonPressedEvent&, float) const;
309 void handleButtonPressEvent (LinuxComponentPeer*, const XButtonPressedEvent&, int) const;
310 void handleButtonPressEvent (LinuxComponentPeer*, const XButtonPressedEvent&) const;
311 void handleButtonReleaseEvent (LinuxComponentPeer*, const XButtonReleasedEvent&) const;
312 void handleMotionNotifyEvent (LinuxComponentPeer*, const XPointerMovedEvent&) const;
313 void handleEnterNotifyEvent (LinuxComponentPeer*, const XEnterWindowEvent&) const;
314 void handleLeaveNotifyEvent (LinuxComponentPeer*, const XLeaveWindowEvent&) const;
315 void handleFocusInEvent (LinuxComponentPeer*) const;
316 void handleFocusOutEvent (LinuxComponentPeer*) const;
317 void handleExposeEvent (LinuxComponentPeer*, XExposeEvent&) const;
318 void handleConfigureNotifyEvent (LinuxComponentPeer*, XConfigureEvent&) const;
319 void handleGravityNotify (LinuxComponentPeer*) const;
320 void propertyNotifyEvent (LinuxComponentPeer*, const XPropertyEvent&) const;
321 void handleMappingNotify (XMappingEvent&) const;
322 void handleClientMessageEvent (LinuxComponentPeer*, XClientMessageEvent&, XEvent&) const;
323 void handleXEmbedMessage (LinuxComponentPeer*, XClientMessageEvent&) const;
324
325 void dismissBlockingModals (LinuxComponentPeer*) const;
326 void dismissBlockingModals (LinuxComponentPeer*, const XConfigureEvent&) const;
327 void updateConstraints (::Window, ComponentPeer&) const;
328
329 ::Window findTopLevelWindowOf (::Window) const;
330
331 static void windowMessageReceive (XEvent&);
332
333 //==============================================================================
334 bool xIsAvailable = false;
335
337 ::Display* display = nullptr;
338 std::unique_ptr<DisplayVisuals> displayVisuals;
340
341 #if JUCE_USE_XSHM
343 #endif
344
345 int shmCompletionEvent = 0;
346 int pointerMap[5] = {};
347 String localClipboardContent;
348
349 Point<int> parentScreenPosition;
350
351 //==============================================================================
353};
354
355} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
Represents the window borders around a window component.
The Component class uses a ComponentPeer internally to create and manage a real operating-system wind...
Classes derived from this will be automatically deleted when the application exits.
Holds a fixed-size bitmap.
Definition juce_Image.h:58
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
Represents the state of the mouse buttons and modifier keys.
StandardCursorType
The set of available standard mouse cursors.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Manages a rectangle and allows geometric operations to be performed on it.
Represents the different sections of a resizable border, which allow it to resized in different ways.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
Parses and stores the X11 settings for a display according to the XSETTINGS specification.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
#define JUCE_DECLARE_SINGLETON(Classname, doNotRecreateAfterDeletion)
Macro to generate the appropriate methods and boilerplate for a singleton class.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
Initialises and stores some atoms for the display.
Gets a specified window property and stores its associated data, freeing it on deletion.
A handy struct that uses XLockDisplay and XUnlockDisplay to lock the X server using RAII.
Represents a setting according to the XSETTINGS specification.