From Matthias Helsing, "Here is the changed source to prefer using _NET_WM_STATE_ABOVE but fall back to XRaiseWindow should the Atoms not be supported. I'm not sure how many might be using the raiseWindow feature but I needed it for a splash on Ubuntu 12.04."

This commit is contained in:
Robert Osfield
2013-06-21 08:56:24 +00:00
parent 4738a2607b
commit c3f28a52e4

View File

@@ -994,7 +994,7 @@ bool GraphicsWindowX11::createWindow()
XFlush( _eventDisplay );
XSync( _eventDisplay, 0 );
rescanModifierMapping();
return true;
}
@@ -2151,31 +2151,61 @@ extern "C" void graphicswindow_X11(void)
osg::GraphicsContext::setWindowingSystemInterface(new X11WindowingSystemInterface);
}
void GraphicsWindowX11::raiseWindow()
{
Display* display = getDisplayToUse();
XWindowAttributes winAttrib;
if(!display) return;
Window root_return, parent_return, *children;
unsigned int nchildren, i=0;
XTextProperty windowName;
bool xraise = false;
XQueryTree(display, _parent, &root_return, &parent_return, &children, &nchildren);
while (!xraise && i<nchildren)
// get handles to window props of interest
Atom stateAbove = XInternAtom(display, "_NET_WM_STATE_ABOVE", True);
Atom stateAtom = XInternAtom(display, "_NET_WM_STATE", True);
// check that atoms are supported
if(stateAbove != None && stateAtom != None)
{
XGetWMName(display,children[i++],&windowName);
if ((windowName.nitems != 0) && (strcmp(_traits->windowName.c_str(),(const char *)windowName.value) == 0)) xraise = true;
// fill an XEvent struct to send
XEvent xev;
xev.xclient.type = ClientMessage;
xev.xclient.serial = 0;
xev.xclient.send_event = True;
xev.xclient.window = _window;
xev.xclient.message_type = stateAtom;
xev.xclient.format = 32;
xev.xclient.data.l[0] = 1;
xev.xclient.data.l[1] = stateAbove;
xev.xclient.data.l[2] = 0;
XSendEvent(display, RootWindow(display, DefaultScreen(display)),
False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
}
if (xraise) XRaiseWindow(display,_window);
else
{
XGetWindowAttributes(display, _window, &winAttrib);
XReparentWindow(display, _window, _parent, winAttrib.x, winAttrib.y);
// one or both of _NET_WM_STATE and _NET_WM_STATE_ABOVE aren't supported
// try to use XRaiseWindow
XWindowAttributes winAttrib;
Window root_return, parent_return, *children;
unsigned int nchildren, i=0;
XTextProperty windowName;
bool xraise = false;
// get the window tree around our current window
XQueryTree(display, _parent, &root_return, &parent_return, &children, &nchildren);
while (!xraise && i<nchildren)
{
XGetWMName(display,children[i++],&windowName);
if ((windowName.nitems != 0) && (strcmp(_traits->windowName.c_str(),(const char *)windowName.value) == 0))
xraise = true;
}
if (xraise)
XRaiseWindow(display,_window);
else
{
XGetWindowAttributes(display, _window, &winAttrib);
XReparentWindow(display, _window, _parent, winAttrib.x, winAttrib.y);
}
XFree(children);
}
XFree(children);
XFlush(display);
XSync(display,0);