diff --git a/modules/juce_gui_basics/native/x11/juce_linux_X11_Symbols.cpp b/modules/juce_gui_basics/native/x11/juce_linux_X11_Symbols.cpp index e3f1cc880c..e00e103520 100644 --- a/modules/juce_gui_basics/native/x11/juce_linux_X11_Symbols.cpp +++ b/modules/juce_gui_basics/native/x11/juce_linux_X11_Symbols.cpp @@ -80,6 +80,7 @@ bool X11Symbols::loadAllSymbols() using namespace X11SymbolHelpers; if (! loadSymbols (xLib, xextLib, + makeSymbolBinding (xAllocClassHint, "XAllocClassHint"), makeSymbolBinding (xAllocSizeHints, "XAllocSizeHints"), makeSymbolBinding (xAllocWMHints, "XAllocWMHints"), makeSymbolBinding (xBitmapBitOrder, "XBitmapBitOrder"), @@ -169,6 +170,7 @@ bool X11Symbols::loadAllSymbols() makeSymbolBinding (xScreenNumberOfScreen, "XScreenNumberOfScreen"), makeSymbolBinding (xSelectInput, "XSelectInput"), makeSymbolBinding (xSendEvent, "XSendEvent"), + makeSymbolBinding (xSetClassHint, "XSetClassHint"), makeSymbolBinding (xSetErrorHandler, "XSetErrorHandler"), makeSymbolBinding (xSetIOErrorHandler, "XSetIOErrorHandler"), makeSymbolBinding (xSetInputFocus, "XSetInputFocus"), diff --git a/modules/juce_gui_basics/native/x11/juce_linux_X11_Symbols.h b/modules/juce_gui_basics/native/x11/juce_linux_X11_Symbols.h index e112873324..8d9bb68156 100644 --- a/modules/juce_gui_basics/native/x11/juce_linux_X11_Symbols.h +++ b/modules/juce_gui_basics/native/x11/juce_linux_X11_Symbols.h @@ -49,6 +49,10 @@ public: bool loadAllSymbols(); //============================================================================== + JUCE_GENERATE_FUNCTION_WITH_DEFAULT (XAllocClassHint, xAllocClassHint, + (), + XClassHint*) + JUCE_GENERATE_FUNCTION_WITH_DEFAULT (XAllocSizeHints, xAllocSizeHints, (), XSizeHints*) @@ -405,6 +409,10 @@ public: (::Display*, ::Window, Bool, long, XEvent*), Status) + JUCE_GENERATE_FUNCTION_WITH_DEFAULT (XSetClassHint, xSetClassHint, + (::Display*, ::Window, XClassHint*), + void) + JUCE_GENERATE_FUNCTION_WITH_DEFAULT (XSetErrorHandler, xSetErrorHandler, (XErrorHandler), XErrorHandler) diff --git a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp index cf8df3b721..e1923f9d52 100644 --- a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp +++ b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp @@ -1334,12 +1334,28 @@ static int getAllEventsMask (bool ignoresMouseClicks) } // Set window manager hints - auto* wmHints = X11Symbols::getInstance()->xAllocWMHints(); - wmHints->flags = InputHint | StateHint; - wmHints->input = True; - wmHints->initial_state = NormalState; - X11Symbols::getInstance()->xSetWMHints (display, windowH, wmHints); - X11Symbols::getInstance()->xFree (wmHints); + if (auto* wmHints = X11Symbols::getInstance()->xAllocWMHints()) + { + wmHints->flags = InputHint | StateHint; + wmHints->input = True; + wmHints->initial_state = NormalState; + X11Symbols::getInstance()->xSetWMHints (display, windowH, wmHints); + X11Symbols::getInstance()->xFree (wmHints); + } + + // Set class hint + if (auto* app = JUCEApplicationBase::getInstance()) + { + if (auto* classHint = X11Symbols::getInstance()->xAllocClassHint()) + { + auto appName = app->getApplicationName(); + classHint->res_name = (char*) appName.getCharPointer().getAddress(); + classHint->res_class = (char*) appName.getCharPointer().getAddress(); + + X11Symbols::getInstance()->xSetClassHint (display, windowH, classHint); + X11Symbols::getInstance()->xFree (classHint); + } + } // Set the window type setWindowType (windowH, styleFlags); @@ -1456,12 +1472,15 @@ void XWindowSystem::setIcon (::Window windowH, const Image& newIcon) const if (wmHints == nullptr) wmHints = X11Symbols::getInstance()->xAllocWMHints(); - wmHints->flags |= IconPixmapHint | IconMaskHint; - wmHints->icon_pixmap = PixmapHelpers::createColourPixmapFromImage (display, newIcon); - wmHints->icon_mask = PixmapHelpers::createMaskPixmapFromImage (display, newIcon); + if (wmHints != nullptr) + { + wmHints->flags |= IconPixmapHint | IconMaskHint; + wmHints->icon_pixmap = PixmapHelpers::createColourPixmapFromImage (display, newIcon); + wmHints->icon_mask = PixmapHelpers::createMaskPixmapFromImage (display, newIcon); - X11Symbols::getInstance()->xSetWMHints (display, windowH, wmHints); - X11Symbols::getInstance()->xFree (wmHints); + X11Symbols::getInstance()->xSetWMHints (display, windowH, wmHints); + X11Symbols::getInstance()->xFree (wmHints); + } X11Symbols::getInstance()->xSync (display, False); } @@ -1514,22 +1533,24 @@ void XWindowSystem::setBounds (::Window windowH, Rectangle newBounds, bool XWindowSystemUtilities::ScopedXLock xLock; - auto* hints = X11Symbols::getInstance()->xAllocSizeHints(); - hints->flags = USSize | USPosition; - hints->x = newBounds.getX(); - hints->y = newBounds.getY(); - hints->width = newBounds.getWidth(); - hints->height = newBounds.getHeight(); - - if ((peer->getStyleFlags() & ComponentPeer::windowIsResizable) == 0) + if (auto* hints = X11Symbols::getInstance()->xAllocSizeHints()) { - hints->min_width = hints->max_width = hints->width; - hints->min_height = hints->max_height = hints->height; - hints->flags |= PMinSize | PMaxSize; - } + hints->flags = USSize | USPosition; + hints->x = newBounds.getX(); + hints->y = newBounds.getY(); + hints->width = newBounds.getWidth(); + hints->height = newBounds.getHeight(); - X11Symbols::getInstance()->xSetWMNormalHints (display, windowH, hints); - X11Symbols::getInstance()->xFree (hints); + if ((peer->getStyleFlags() & ComponentPeer::windowIsResizable) == 0) + { + hints->min_width = hints->max_width = hints->width; + hints->min_height = hints->max_height = hints->height; + hints->flags |= PMinSize | PMaxSize; + } + + X11Symbols::getInstance()->xSetWMNormalHints (display, windowH, hints); + X11Symbols::getInstance()->xFree (hints); + } auto windowBorder = peer->getFrameSize();