From bd2f4a212ee0cc72fbb9e9d4a039ff8785e45a77 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 6 Mar 2008 16:16:39 +0100 Subject: [PATCH] Move grabkeys() out of event, and move it into window; clean and remove setup() function in awesome.c --- awesome.c | 66 ++++++++++++++++++++++++++------------------------------------- event.c | 25 +----------------------- event.h | 2 -- window.c | 26 ++++++++++++++++++++++++- window.h | 1 + 5 files changed, 54 insertions(+), 66 deletions(-) diff --git a/awesome.c b/awesome.c index 8ab5984c..e631a2d6 100644 --- a/awesome.c +++ b/awesome.c @@ -108,44 +108,6 @@ scan() } } -/** Setup everything before running - * \param screen Screen number - * \todo clean things... - */ -static void -setup(int screen) -{ - XSetWindowAttributes wa; - Statusbar *statusbar; - int phys_screen = get_phys_screen(screen); - - /* init cursors */ - globalconf.cursor[CurNormal] = XCreateFontCursor(globalconf.display, XC_left_ptr); - globalconf.cursor[CurResize] = XCreateFontCursor(globalconf.display, XC_sizing); - globalconf.cursor[CurMove] = XCreateFontCursor(globalconf.display, XC_fleur); - - /* select for events */ - wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask - | EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PointerMotionMask; - wa.cursor = globalconf.cursor[CurNormal]; - - XChangeWindowAttributes(globalconf.display, - RootWindow(globalconf.display, phys_screen), - CWEventMask | CWCursor, &wa); - - XSelectInput(globalconf.display, - RootWindow(globalconf.display, phys_screen), - wa.event_mask); - - grabkeys(phys_screen); - - /* view at least one tag */ - tag_view(globalconf.screens[screen].tags, True); - - for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) - statusbar_init(statusbar); -} - /** Startup Error handler to check if another window manager * is already running. * \param disp Display @@ -223,12 +185,14 @@ main(int argc, char *argv[]) const char *confpath = NULL; int r, xfd, e_dummy, csfd, shape_event, randr_event_base, i, screen, opt; ssize_t cmdlen = 1; + Statusbar *statusbar; fd_set rd; XEvent ev; Display * dpy; event_handler **handler; struct sockaddr_un *addr; Client *c; + XSetWindowAttributes wa; static struct option long_options[] = { {"help", 0, NULL, 'h'}, @@ -306,18 +270,42 @@ main(int argc, char *argv[]) /* parse config */ config_parse(confpath); + /* scan existing windows */ scan(); + /* init cursors */ + globalconf.cursor[CurNormal] = XCreateFontCursor(globalconf.display, XC_left_ptr); + globalconf.cursor[CurResize] = XCreateFontCursor(globalconf.display, XC_sizing); + globalconf.cursor[CurMove] = XCreateFontCursor(globalconf.display, XC_fleur); + /* for each virtual screen */ for(screen = 0; screen < globalconf.nscreen; screen++) - setup(screen); + { + /* view at least one tag */ + tag_view(globalconf.screens[screen].tags, True); + + for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) + statusbar_init(statusbar); + } + + /* select for events */ + wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask + | EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PointerMotionMask; + wa.cursor = globalconf.cursor[CurNormal]; /* do this only for real screen */ for(screen = 0; screen < ScreenCount(dpy); screen++) { + XChangeWindowAttributes(globalconf.display, + RootWindow(globalconf.display, screen), + CWEventMask | CWCursor, &wa); + XSelectInput(globalconf.display, + RootWindow(globalconf.display, screen), + wa.event_mask); ewmh_set_supported_hints(screen); /* call this to at least grab root window clicks */ window_root_grabbuttons(screen); + window_root_grabkeys(screen); } handler = p_new(event_handler *, LASTEvent); diff --git a/event.c b/event.c index 49a3d378..64a732c3 100644 --- a/event.c +++ b/event.c @@ -360,7 +360,7 @@ event_handle_mappingnotify(XEvent *e) XRefreshKeyboardMapping(ev); if(ev->request == MappingKeyboard) for(screen = 0; screen < ScreenCount(e->xany.display); screen++) - grabkeys(screen); + window_root_grabkeys(screen); } /** Handle XMapRequest events @@ -473,27 +473,4 @@ event_handle_clientmessage(XEvent *e) ewmh_process_client_message(&e->xclient); } -/** Grab keys on root window - * \param phys_screen physical screen id - */ -void -grabkeys(int phys_screen) -{ - Key *k; - - XUngrabKey(globalconf.display, AnyKey, AnyModifier, RootWindow(globalconf.display, phys_screen)); - - for(k = globalconf.keys; k; k = k->next) - if(k->keycode) - { - XGrabKey(globalconf.display, k->keycode, k->mod, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); - XGrabKey(globalconf.display, k->keycode, k->mod | LockMask, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); - XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); - XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask | LockMask, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); - } -} // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/event.h b/event.h index 8ef38207..d984ae7e 100644 --- a/event.h +++ b/event.h @@ -26,8 +26,6 @@ #define CLEANMASK(mask) (mask & ~(globalconf.numlockmask | LockMask)) -void grabkeys(int); - void event_handle_buttonpress(XEvent *); void event_handle_configurerequest(XEvent *); void event_handle_configurenotify(XEvent *); diff --git a/window.c b/window.c index 210c1349..9d6ea2eb 100644 --- a/window.c +++ b/window.c @@ -125,7 +125,7 @@ window_grabbuttons(int phys_screen, Window win) XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, phys_screen)); } -/** Grab button on root window +/** Grab buttons on root window * \param phys_screen physical screen id */ void @@ -150,6 +150,30 @@ window_root_grabbuttons(int phys_screen) } } +/** Grab keys on root window + * \param phys_screen physical screen id + */ +void +window_root_grabkeys(int phys_screen) +{ + Key *k; + + XUngrabKey(globalconf.display, AnyKey, AnyModifier, RootWindow(globalconf.display, phys_screen)); + + for(k = globalconf.keys; k; k = k->next) + if(k->keycode) + { + XGrabKey(globalconf.display, k->keycode, k->mod, + RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); + XGrabKey(globalconf.display, k->keycode, k->mod | LockMask, + RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); + XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask, + RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); + XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask | LockMask, + RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); + } +} + void window_setshape(int screen, Window win) { diff --git a/window.h b/window.h index 08578e20..e25e36e6 100644 --- a/window.h +++ b/window.h @@ -29,6 +29,7 @@ long window_getstate(Window); Status window_configure(Window, Area, int); void window_grabbuttons(int, Window); void window_root_grabbuttons(int); +void window_root_grabkeys(int); void window_setshape(int, Window); int window_settrans(Window, double); -- 2.11.4.GIT