]> Pileus Git - wmpus/blobdiff - wm-wmii.c
Use config for sys-x11 and wm-wmii
[wmpus] / wm-wmii.c
index 06b71f67694830210204c2a374b23dd23c8d6f03..aab29217d453ee6de3dd5523db07a55fd80d2881 100644 (file)
--- a/wm-wmii.c
+++ b/wm-wmii.c
 #include <stdlib.h>
 
 #include "util.h"
+#include "conf.h"
 #include "sys.h"
 #include "wm.h"
 
+/* Configuration */
 #ifndef MODKEY
 #define MODKEY alt
 #endif
-#ifndef MARGIN
-#define MARGIN 0
-#endif
-#ifndef STACK
-#define STACK  25
-#endif
+static int MARGIN = 0;
+static int STACK  = 25;
 
 /* Enums */
 typedef enum {
@@ -739,6 +737,7 @@ int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr)
 #endif
                if (key == key_f5) return wm_update(),    1;
                if (key == key_f6) return print_txt(),    1;
+               if (key == 'q')    return sys_exit(),     1;
        }
 
        /* Floating layer */
@@ -885,6 +884,10 @@ void wm_init(win_t *root)
 {
        printf("wm_init: %p\n", root);
 
+       /* Load configuration */
+       MARGIN = conf_get_int("main.margin", MARGIN);
+       STACK  = conf_get_int("main.stack",  STACK);
+
        /* Hack, fix screen order */
        list_t *screens = sys_info(root);
        list_t *left  = screens;
@@ -902,7 +905,7 @@ void wm_init(win_t *root)
        wm->tags    = list_insert(NULL, wm->tag);
 
        Key_t keys_e[] = {key_enter, key_focus};
-       Key_t keys_s[] = {'h', 'j', 'k', 'l', ' ',
+       Key_t keys_s[] = {'h', 'j', 'k', 'l', 'q', ' ',
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        Key_t keys_m[] = {'h', 'j', 'k', 'l', 'd', 's', 'm', 't', ' ',
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
@@ -915,3 +918,25 @@ void wm_init(win_t *root)
        for (int i = 0; i < countof(keys_s); i++)
                sys_watch(root, keys_s[i], MOD(.MODKEY=1,.shift=1));
 }
+
+void wm_free(win_t *root)
+{
+       /* Re-show and free all windows */
+       while ( wm->tags) { tag_t *tag =  wm->tags->data;
+       while (tag->dpys) { dpy_t *dpy = tag->dpys->data;
+       while (dpy->cols) { col_t *col = dpy->cols->data;
+       while (col->rows) { row_t *row = col->rows->data;
+               sys_show(row->win, st_show);
+               free(row->win->wm);
+       col->rows = list_remove(col->rows, col->rows, 1); }
+       dpy->cols = list_remove(dpy->cols, dpy->cols, 1); }
+       while (dpy->flts) { flt_t *flt = dpy->flts->data;
+               sys_show(flt->win, st_show);
+               free(flt->win->wm);
+       dpy->flts = list_remove(dpy->flts, dpy->flts, 1); }
+       tag->dpys = list_remove(tag->dpys, tag->dpys, 1); }
+        wm->tags = list_remove( wm->tags,  wm->tags, 1); }
+
+       /* Free remaining data */
+       free(wm);
+}