Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. extern ::Display* display;
  18. //==============================================================================
  19. class SystemTrayIconComponent::Pimpl
  20. {
  21. public:
  22. Pimpl (const Image& im, Window windowH) : image (im)
  23. {
  24. ScopedXLock xlock;
  25. Screen* const screen = XDefaultScreenOfDisplay (display);
  26. const int screenNumber = XScreenNumberOfScreen (screen);
  27. String screenAtom ("_NET_SYSTEM_TRAY_S");
  28. screenAtom << screenNumber;
  29. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  30. XGrabServer (display);
  31. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  32. if (managerWin != None)
  33. XSelectInput (display, managerWin, StructureNotifyMask);
  34. XUngrabServer (display);
  35. XFlush (display);
  36. if (managerWin != None)
  37. {
  38. XEvent ev = { 0 };
  39. ev.xclient.type = ClientMessage;
  40. ev.xclient.window = managerWin;
  41. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  42. ev.xclient.format = 32;
  43. ev.xclient.data.l[0] = CurrentTime;
  44. ev.xclient.data.l[1] = 0 /*SYSTEM_TRAY_REQUEST_DOCK*/;
  45. ev.xclient.data.l[2] = (long) windowH;
  46. ev.xclient.data.l[3] = 0;
  47. ev.xclient.data.l[4] = 0;
  48. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  49. XSync (display, False);
  50. }
  51. // For older KDE's ...
  52. long atomData = 1;
  53. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  54. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  55. // For more recent KDE's...
  56. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  57. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  58. // A minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  59. XSizeHints* hints = XAllocSizeHints();
  60. hints->flags = PMinSize;
  61. hints->min_width = 22;
  62. hints->min_height = 22;
  63. XSetWMNormalHints (display, windowH, hints);
  64. XFree (hints);
  65. }
  66. Image image;
  67. private:
  68. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
  69. };
  70. //==============================================================================
  71. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  72. {
  73. pimpl = nullptr;
  74. if (newImage.isValid())
  75. {
  76. if (! isOnDesktop())
  77. addToDesktop (0);
  78. pimpl = new Pimpl (newImage, (Window) getWindowHandle());
  79. setVisible (true);
  80. toFront (false);
  81. }
  82. repaint();
  83. }
  84. void SystemTrayIconComponent::paint (Graphics& g)
  85. {
  86. if (pimpl != nullptr)
  87. g.drawImageWithin (pimpl->image, 0, 0, getWidth(), getHeight(),
  88. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize, false);
  89. }
  90. void SystemTrayIconComponent::setIconTooltip (const String& /*tooltip*/)
  91. {
  92. // xxx Not implemented!
  93. }
  94. void SystemTrayIconComponent::setHighlighted (bool)
  95. {
  96. // xxx Not implemented!
  97. }
  98. void SystemTrayIconComponent::showInfoBubble (const String& /*title*/, const String& /*content*/)
  99. {
  100. // xxx Not implemented!
  101. }
  102. void SystemTrayIconComponent::hideInfoBubble()
  103. {
  104. // xxx Not implemented!
  105. }
  106. void* SystemTrayIconComponent::getNativeHandle() const
  107. {
  108. return getWindowHandle();
  109. }