View Single Post
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#29
Originally Posted by hqh View Post
- I do not know if previous application can be easily resumed, XSetInputFocus had no effect
Code:
static void show_window (Window win)
{
	    XEvent event;

	    event.xclient.type = ClientMessage;
	    event.xclient.serial = 0;
	    event.xclient.send_event = True;
	    event.xclient.message_type = XInternAtom (dpy, "_NET_ACTIVE_WINDOW", False);
	    event.xclient.window = win;
	    event.xclient.format = 32;
	    event.xclient.data.l[0] = 0;
	    event.xclient.data.l[1] = 0;
	    event.xclient.data.l[2] = 0;
	    event.xclient.data.l[3] = 0;
	    event.xclient.data.l[4] = 0;

		if (XSendEvent(dpy, DefaultRootWindow (dpy), False, SubstructureRedirectMask | SubstructureNotifyMask, &event))
			XMapRaised(dpy, win);
}
That, stolen from wmctrl, works.

This snippet below gets the topmost window. You have two choices here: You can use _NET_ACTIVE_WINDOW which will always return you the ID of any window on the screen, or you can use _MB_CURRENT_APP_WINDOW which returns 0x0 if the focus is on the desktop/dashboard.

Code:
static Window get_topmost_window (void)
{
    Atom realtype;
    int format;
    unsigned long nitems;
    unsigned long b_after;
    unsigned char *prop;
    int xpropertyerr;
    Window win = (Window) 0;

    xpropertyerr = XGetWindowProperty (dpy, DefaultRootWindow (dpy), XInternAtom (dpy, "_NET_ACTIVE_WINDOW", False), 0L, (~0L), False, XA_WINDOW, &realtype, &format, &nitems, &b_after, &prop);

    if (!(xpropertyerr == Success && realtype == XA_WINDOW && format == 32 && nitems == 1 && prop != NULL))
		exit (EXIT_FAILURE);

    win = *((Window *) prop);

    XFree (prop);

    return win;
}
If you could get it to return to the last activated window, it would be nice.

Last edited by qwerty12; 2009-12-26 at 16:46.
 

The Following 5 Users Say Thank You to qwerty12 For This Useful Post: