1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-22 01:34:21 +00:00

Linux: Set class hint for windows so they behave correctly in the dock

This commit is contained in:
ed 2020-07-15 09:21:06 +01:00
parent 5b5554b7eb
commit 9db01c4362
3 changed files with 56 additions and 25 deletions

View file

@ -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"),

View file

@ -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)

View file

@ -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<int> 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();