From 3d8b7565d4e87d694501857583fa815114ab311a Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 6 Mar 2008 11:41:26 +0100 Subject: [PATCH 1/5] Comments widgets functions --- widget.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/widget.c b/widget.c index 66c07dc4..508cc7d1 100644 --- a/widget.c +++ b/widget.c @@ -1,7 +1,7 @@ /* * widget.c - widget managing * - * Copyright © 2007 Julien Danjou + * Copyright © 2007-2008 Julien Danjou * Copyright © 2007 Aldo Cortesi * * This program is free software; you can redistribute it and/or modify @@ -28,6 +28,11 @@ extern AwesomeConf globalconf; #include "widgetgen.h" +/** Compute widget alignment. + * This will process all widget starting at `widget' and will check their + * alignment and guess it if set to AlignAuto. + * \param widget a linked list of all widgets + */ void widget_calculate_alignments(Widget *widget) { @@ -64,6 +69,12 @@ widget_calculate_alignments(Widget *widget) } } +/** Compute offset for drawing the first pixel of a widget. + * \param barwidth the statusbar width + * \param widgetwidth the widget width + * \param alignment the widget alignment on statusbar + * \return the x coordinate to draw at + */ int widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment) { @@ -76,6 +87,11 @@ widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment return barwidth - offset - widgetwidth; } +/** Find a widget on a screen by its name + * \param name the widget name + * \param screen the screen to look into + * \return a widget + */ static Widget * widget_find(char *name, int screen) { @@ -90,6 +106,11 @@ widget_find(char *name, int screen) return NULL; } +/** Common function for button press event on widget. + * It will look into configuration to find the callback function to call. + * \param widget the widget + * \param ev the XButtonPressedEvent the widget received + */ static void widget_common_button_press(Widget *widget, XButtonPressedEvent *ev) { @@ -103,20 +124,27 @@ widget_common_button_press(Widget *widget, XButtonPressedEvent *ev) } } +/** Common tell function for widget, which only warn user that widget + * cannot be told anything + * \param widget the widget + * \param command unused argument + */ static void widget_common_tell(Widget *widget, char *command __attribute__ ((unused))) { warn("%s widget does not accept commands.\n", widget->name); } +/** Common function for creating a widget + * \param widget The allocated widget + * \param statusbar the statusbar the widget is on + * \param config the cfg_t structure we will parse to set common info + */ void -widget_common_new(Widget *widget, Statusbar *statusbar, cfg_t* config) +widget_common_new(Widget *widget, Statusbar *statusbar, cfg_t *config) { - const char *name; - widget->statusbar = statusbar; - name = cfg_title(config); - widget->name = a_strdup(name); + widget->name = a_strdup(cfg_title(config)); widget->tell = widget_common_tell; widget->button_press = widget_common_button_press; widget->area.x = cfg_getint(config, "x"); @@ -125,6 +153,12 @@ widget_common_new(Widget *widget, Statusbar *statusbar, cfg_t* config) widget->user_supplied_y = (widget->area.y != (int) 0xffffffff); } +/** Invalidate widgets which should be refresh upon + * external modifications. Widget who watch flags will + * be set to be refreshed. + * \param screen screen id + * \param flags cache flags + */ void widget_invalidate_cache(int screen, int flags) { From b58631581b68776dc340f970fd102b85d585a90d Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 6 Mar 2008 16:03:01 +0100 Subject: [PATCH 2/5] Add comments to some layout functions --- layout.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/layout.c b/layout.c index 4c439c65..c7e20ab0 100644 --- a/layout.c +++ b/layout.c @@ -86,6 +86,9 @@ arrange(int screen) globalconf.screens[screen].need_arrange = False; } +/** Refresh the screen disposition + * \return true if the screen was arranged, false otherwise + */ int layout_refresh(void) { @@ -102,6 +105,10 @@ layout_refresh(void) return arranged; } +/** Get current layout used on screen + * \param screen screen id + * \return layout used on that screen + */ Layout * layout_get_current(int screen) { From fcf086ec08bd4da0906ace2a4fccc95dddcb4344 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 6 Mar 2008 16:04:58 +0100 Subject: [PATCH 3/5] Add some comments to window functions --- window.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/window.c b/window.c index 35b30219..210c1349 100644 --- a/window.c +++ b/window.c @@ -27,7 +27,7 @@ extern AwesomeConf globalconf; -/** Mask shorthands, used in event.c and window.c */ +/** Mask shorthands */ #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask) /** Set client WM_STATE property @@ -67,6 +67,12 @@ window_getstate(Window w) return result; } +/** Configure a window with its new geometry and border + * \param win the X window id + * \param geometry the new window geometry + * \param border new border size + * \return the XSendEvent() status + */ Status window_configure(Window win, Area geometry, int border) { @@ -119,6 +125,9 @@ window_grabbuttons(int phys_screen, Window win) XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, phys_screen)); } +/** Grab button on root window + * \param phys_screen physical screen id + */ void window_root_grabbuttons(int phys_screen) { From d10036a366bf412c1ab6fc55f5a5714f7ce6f451 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 6 Mar 2008 16:09:38 +0100 Subject: [PATCH 4/5] Remove useless call to get_phys_screen() in grabkeys() screen is already a physical screen since we use ScreenCount() --- event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/event.c b/event.c index fb5b1437..49a3d378 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(get_phys_screen(screen)); + grabkeys(screen); } /** Handle XMapRequest events From bd2f4a212ee0cc72fbb9e9d4a039ff8785e45a77 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 6 Mar 2008 16:16:39 +0100 Subject: [PATCH 5/5] 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);