From a5ba4a375a2ba0c87d369bebc58a767223710e99 Mon Sep 17 00:00:00 2001 From: Mike Fulbright Date: Thu, 1 Aug 2002 00:12:23 +0000 Subject: mini-wm from otaylor --- mini-wm.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 mini-wm.c (limited to 'mini-wm.c') diff --git a/mini-wm.c b/mini-wm.c new file mode 100644 index 000000000..e988dbd5b --- /dev/null +++ b/mini-wm.c @@ -0,0 +1,84 @@ +/* + * mini-wm.c - simple keyboard focus handling 'wm'. + * + * Owen Taylor + * + * Copyright 2002 Red Hat, Inc. + * + * This software may be freely redistributed under the terms of the GNU + * public license. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + + +#include + +#include +#include + +static void +check_focus () +{ + Window *children; + unsigned int n_children; + Window root; + Window parent; + + XQueryTree (GDK_DISPLAY(), GDK_ROOT_WINDOW(), + &root, &parent, &children, &n_children); + + if (n_children > 0) { + gdk_error_trap_push (); + XSetInputFocus (GDK_DISPLAY(), children[n_children-1], + RevertToPointerRoot, CurrentTime); + XSync (GDK_DISPLAY(), 0); + if (gdk_error_trap_pop () != 0) + printf("Failed on XSetInputFocus()"); + } + + XFree (children); +} + +GdkFilterReturn +mini_wm_root_filter (GdkXEvent *xevent, + GdkEvent *event, + gpointer data) +{ + XEvent *xev = xevent; + + if (xev->xany.type == MapNotify || + xev->xany.type == UnmapNotify || + xev->xany.type == ConfigureNotify) + check_focus (); + + return GDK_FILTER_CONTINUE; +} + +void +mini_wm_start (void) +{ + XWindowAttributes attrs; + + XGetWindowAttributes (GDK_DISPLAY(), GDK_ROOT_WINDOW(), &attrs); + XSelectInput (GDK_DISPLAY(), GDK_ROOT_WINDOW(), + attrs.your_event_mask | SubstructureNotifyMask); + + gdk_window_add_filter (GDK_ROOT_PARENT (), mini_wm_root_filter, NULL); +} + +int main( int argc, + char *argv[] ) +{ + + gtk_init (&argc, &argv); + + mini_wm_start (); + + gtk_main(); + + return(0); +} -- cgit