Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore a window with Xlib?

I've managed to iconify a window using XIconifyWindow, but haven't managed to later restore it. I tried the following:

XMapRaised (display, window);

And:

XMapWindow (display, window);

And:

XClientMessageEvent ev;
std::memset (&ev, 0, sizeof ev);
ev.type = ClientMessage;
ev.window = window;
ev.message_type = XInternAtom(display, "WM_CHANGE_STATE", False);
ev.format = 32;
ev.data.l[0] = NormalState;
XSendEvent (display, RootWindow(display, XDefaultScreen(display)), False,
  SubstructureRedirectMask |SubstructureNotifyMask, (XEvent*)&ev);
XFlush (display);

To no success. I'm using Debian Jessie with GNOME 3.14.0.

like image 525
Yaron Cohen-Tal Avatar asked May 12 '15 13:05

Yaron Cohen-Tal


1 Answers

After a lot of stuggles, finally solved!

In GNOME 3, windows have no "iconify/minimize" button. It appears that a window can't be minimized, neither by the user nor from code. When I called XIconifyWindow, the window wasn't minimized. If it had been minimized, I'd have gotten an "UnmapNotify" event, which I didn't. What did happen is, the window was hidden (" _NET_WM_STATE_HIDDEN" was added to the window's "_NET_WM_STATE" property), and another window was activated. So all I had to do to "unminimize" the window was to activate it:

XClientMessageEvent ev;
std::memset (&ev, 0, sizeof ev);
ev.type = ClientMessage;
ev.window = window;
ev.message_type = XInternAtom(display, "_NET_ACTIVE_WINDOW", True);
ev.format = 32;
ev.data.l[0] = 1;
ev.data.l[1] = CurrentTime;
ev.data.l[2] = ev.data.l[3] = ev.data.l[4] = 0;
XSendEvent (display, RootWindow(display, XDefaultScreen(display)), False,
  SubstructureRedirectMask |SubstructureNotifyMask, (XEvent*)&ev);
XFlush (display);

Btw calling XRaiseWindow instead didn't work, it seems like it had to be activated.

like image 74
Yaron Cohen-Tal Avatar answered Nov 06 '22 22:11

Yaron Cohen-Tal