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_SystemTrayIcon_linux.cpp
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
30{
31public:
32 Pimpl (const Image& im, Window windowH) : image (im)
33 {
35
36 auto* display = XWindowSystem::getInstance()->getDisplay();
37
38 auto* screen = X11Symbols::getInstance()->xDefaultScreenOfDisplay (display);
39 auto screenNumber = X11Symbols::getInstance()->xScreenNumberOfScreen (screen);
40
41 String screenAtom ("_NET_SYSTEM_TRAY_S");
43 Atom selectionAtom = XWindowSystemUtilities::Atoms::getCreating (display, screenAtom.toUTF8());
44
45 X11Symbols::getInstance()->xGrabServer (display);
46 auto managerWin = X11Symbols::getInstance()->xGetSelectionOwner (display, selectionAtom);
47
48 if (managerWin != None)
49 X11Symbols::getInstance()->xSelectInput (display, managerWin, StructureNotifyMask);
50
51 X11Symbols::getInstance()->xUngrabServer (display);
52 X11Symbols::getInstance()->xFlush (display);
53
54 if (managerWin != None)
55 {
56 XEvent ev = { 0 };
57 ev.xclient.type = ClientMessage;
58 ev.xclient.window = managerWin;
59 ev.xclient.message_type = XWindowSystemUtilities::Atoms::getCreating (display, "_NET_SYSTEM_TRAY_OPCODE");
60 ev.xclient.format = 32;
61 ev.xclient.data.l[0] = CurrentTime;
62 ev.xclient.data.l[1] = 0 /*SYSTEM_TRAY_REQUEST_DOCK*/;
63 ev.xclient.data.l[2] = (long) windowH;
64 ev.xclient.data.l[3] = 0;
65 ev.xclient.data.l[4] = 0;
66
67 X11Symbols::getInstance()->xSendEvent (display, managerWin, False, NoEventMask, &ev);
68 X11Symbols::getInstance()->xSync (display, False);
69 }
70
71 // For older KDE's ...
72 long atomData = 1;
73 Atom trayAtom = XWindowSystemUtilities::Atoms::getCreating (display, "KWM_DOCKWINDOW");
74 X11Symbols::getInstance()->xChangeProperty (display, windowH, trayAtom, trayAtom,
75 32, PropModeReplace, (unsigned char*) &atomData, 1);
76
77 // For more recent KDE's...
78 trayAtom = XWindowSystemUtilities::Atoms::getCreating (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR");
79 X11Symbols::getInstance()->xChangeProperty (display, windowH, trayAtom, XA_WINDOW,
80 32, PropModeReplace, (unsigned char*) &windowH, 1);
81
82 // A minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
83 if (auto* hints = X11Symbols::getInstance()->xAllocSizeHints())
84 {
85 hints->flags = PMinSize;
86 hints->min_width = 22;
87 hints->min_height = 22;
88 X11Symbols::getInstance()->xSetWMNormalHints (display, windowH, hints);
89 X11Symbols::getInstance()->xFree (hints);
90 }
91 }
92
93 Image image;
94
95private:
97};
98
99
100//==============================================================================
102{
103 pimpl.reset();
104
105 if (colourImage.isValid())
106 {
107 if (! isOnDesktop())
108 addToDesktop (0);
109
110 pimpl.reset (new Pimpl (colourImage, (Window) getWindowHandle()));
111
112 setVisible (true);
113 toFront (false);
114 }
115
116 repaint();
117}
118
120{
121 if (pimpl != nullptr)
122 g.drawImage (pimpl->image, getLocalBounds().toFloat(),
124}
125
127{
128 // xxx Not implemented!
129}
130
132{
133 // xxx Not implemented!
134}
135
136void SystemTrayIconComponent::showInfoBubble (const String& /*title*/, const String& /*content*/)
137{
138 // xxx Not implemented!
139}
140
142{
143 // xxx Not implemented!
144}
145
147{
148 return getWindowHandle();
149}
150
151} // namespace juce
void * getWindowHandle() const
Returns the underlying native window handle for this component.
void toFront(bool shouldAlsoGainKeyboardFocus)
Brings the component to the front of its siblings.
void repaint()
Marks the whole component as needing to be redrawn.
bool isOnDesktop() const noexcept
Returns true if this component is currently showing on the desktop.
virtual void addToDesktop(int windowStyleFlags, void *nativeWindowToAttachTo=nullptr)
Makes this component appear as a window on the desktop.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
virtual void paint(Graphics &g)
Components can override this method to draw their content.
virtual void setVisible(bool shouldBeVisible)
Makes the component visible or invisible.
A graphics context, used for drawing a component or image.
void drawImage(const Image &imageToDraw, int destX, int destY, int destWidth, int destHeight, int sourceX, int sourceY, int sourceWidth, int sourceHeight, bool fillAlphaChannelWithCurrentBrush=false) const
Draws part of an image, rescaling it to fit in a given target region.
Holds a fixed-size bitmap.
Definition juce_Image.h:58
@ onlyReduceInSize
Indicates that the source rectangle can be reduced in size if required, but should never be made larg...
@ yTop
Indicates that the source's top edge should be aligned with the top edge of the destination rectangle...
@ xLeft
Indicates that the source rectangle's left edge should be aligned with the left edge of the target re...
The JUCE String class!
Definition juce_String.h:53
void setHighlighted(bool)
Highlights the icon (if the current OS supports this).
void showInfoBubble(const String &title, const String &content)
Shows a floating text bubble pointing to the icon (if the current OS supports this).
void setIconTooltip(const String &tooltip)
Changes the icon's tooltip (if the current OS supports this).
void setIconImage(const Image &colourImage, const Image &templateImage)
Changes the image shown in the taskbar.
void * getNativeHandle() const
Returns the raw handle to whatever kind of internal OS structure is involved in showing this icon.
void hideInfoBubble()
Hides the icon's floating text bubble (if the current OS supports this).
#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 ...
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
T reset(T... args)
A handy struct that uses XLockDisplay and XUnlockDisplay to lock the X server using RAII.
typedef long