#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 {
typedef struct {
win_t *win; // the window
int height; // win height in _this_ tag
+ state_t state; // state of window
} row_t;
typedef struct {
typedef struct {
win_t *win; // the window
int x, y, w, h; // position of window (in this tag)
+ state_t state; // state of window
} flt_t;
typedef struct {
/********************
* Helper functions *
********************/
+static int sort_win(void *a, void *b)
+{
+ return ((win_t*)a)->x > ((win_t*)b)->x ? 1 :
+ ((win_t*)a)->x < ((win_t*)b)->x ? -1 : 0;
+}
+
static win_t *get_focus(void)
{
if (!wm_tag || !wm_dpy)
list_t *ldpy, *lcol, *lrow, *lflt;
layer_t layer = searchl(tag, win, &ldpy, &lcol, &lrow, &lflt);
- dpy_t *dpy = DPY(ldpy);
if (layer == tiling) {
- col_t *col = COL(lcol);
+ dpy_t *dpy = DPY(ldpy);
+ col_t *col = COL(lcol);
col->row = lrow->prev ? lrow->prev->data :
lrow->next ? lrow->next->data : NULL;
- col->rows = list_remove(col->rows, lrow);
+ col->rows = list_remove(col->rows, lrow, 1);
if (col->rows == NULL && (lcol->next || lcol->prev)) {
dpy->col = lcol->prev ? lcol->prev->data :
lcol->next ? lcol->next->data : NULL;
- dpy->cols = list_remove(dpy->cols, lcol);
+ dpy->cols = list_remove(dpy->cols, lcol, 1);
}
}
if (layer == floating) {
- dpy->flts = list_remove(dpy->flts, lflt);
+ dpy_t *dpy = DPY(ldpy);
+ dpy->flts = list_remove(dpy->flts, lflt, 1);
dpy->flt = dpy->flts ? list_last(dpy->flts)->data : NULL;
if (!dpy->flt && dpy->col && dpy->col->row)
dpy->layer = tiling;
break;
if (cur) {
flt_t *flt = cur->data;
- wm_dpy->flts = list_remove(wm_dpy->flts, cur);
+ wm_dpy->flts = list_remove(wm_dpy->flts, cur, 0);
wm_dpy->flts = list_append(wm_dpy->flts, flt);
sys_raise(win);
}
static void tag_switch(int name)
{
printf("tag_switch: %d\n", name);
- if ((wm_col == NULL || wm_row == NULL) && wm_flt == NULL)
- wm->tags = list_remove(wm->tags,
- list_find(wm->tags, wm_tag));
+ tag_t *old = wm_tag;
+ if ((wm_col == NULL || wm_row == NULL) && wm_flt == NULL) {
+ while (old->dpys) {
+ dpy_t *dpy = old->dpys->data;
+ while (dpy->cols)
+ dpy->cols = list_remove(dpy->cols, dpy->cols, 1);
+ old->dpys = list_remove(old->dpys, old->dpys, 1);
+ }
+ list_t *ltag = list_find(wm->tags, old);
+ wm->tags = list_remove(wm->tags, ltag, 1);
+ }
wm_tag = tag_find(name);
}
for (list_t *lrow = col->rows; lrow; lrow = lrow->next) {
win_t *win = ROW(lrow)->win;
win->h = ROW(lrow)->height;
+ state_t state = st_show;
int height = 0;
switch (col->mode) {
case split:
win_t *next = ROW(lrow->next)->win;
sys_move(next, x+MARGIN, y+MARGIN+STACK+MARGIN/2,
col->width, sy);
+ sys_show(next, st_show);
}
- height = win == col->row->win ? sy : STACK;
- sys_move(win, x+MARGIN, y+MARGIN,
- col->width, height);
- y += height + (MARGIN/2);
+ int isfocus = win == col->row->win;
+ state = isfocus ? st_show : st_shade;
+ sys_show(win, state);
+ sys_move(win, x+MARGIN, y+MARGIN, col->width, sy);
+ y += (isfocus ? sy : STACK) + (MARGIN/2);
break;
case max:
case tab:
sys_move(win, x+MARGIN, 0+MARGIN,
col->width, dpy->geom->h-2*MARGIN);
- if (focus == win)
- sys_raise(win);
break;
}
+ ROW(lrow)->state = state;
+ sys_show(win, state);
+ if (focus == win)
+ sys_raise(win);
ROW(lrow)->height = win->h;
}
x += col->width + MARGIN;
{
/* Show/hide tags */
tag_foreach_col(wm_tag, dpy, col, row, win)
- sys_show(win, st_show);
+ sys_show(win, ROW(row)->state);
tag_foreach_flt(wm_tag, dpy, flt, win)
- sys_show(win, st_show);
+ sys_show(win, FLT(flt)->state);
for (list_t *tag = wm ->tags; tag; tag = tag->next)
if (tag->data != wm_tag) {
tag_foreach_col(TAG(tag), dpy, col, row, win)
return set_move(win,ptr,resize), 1;
if (move_mode != none && mod.up)
return set_move(win,ptr,none), 1;
- if (key == key_mouse1 && !mod.up && win->h == STACK)
- return wm_update(), 0;
+ if (key == key_mouse1 && !mod.up && win->state == st_shade)
+ return set_focus(win), wm_update(), 0;
return 0;
}
#ifdef DEBUG
if (key == key_f1) return raise_float(win), 1;
if (key == key_f2) return set_focus(win), 1;
- if (key == key_f3) return sys_show(win, st_show), 1;
- if (key == key_f4) return sys_show(win, st_hide), 1;
+ if (key == key_f3) return sys_show(win, st_show), 1;
+ if (key == key_f4) return sys_show(win, st_hide), 1;
+ if (key == key_f7) return sys_show(win, st_shade), 1;
#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 */
}
/* Focus change */
- if (key == key_enter)
+ if (key == key_enter && win->state != st_shade)
return set_focus(win), 1;
if (key_mouse0 <= key && key <= key_mouse7)
print_txt();
for (list_t *tag = wm->tags; tag; tag = tag->next)
cut_win(win, tag->data);
+ free(win->wm);
set_focus(wm_focus);
wm_update();
print_txt();
}
+
void wm_init(win_t *root)
{
printf("wm_init: %p\n", root);
- /* Hack, fix screen order */
- list_t *screens = sys_info(root);
- list_t *left = screens;
- list_t *right = screens->next;
- if (left && right && WIN(left)->x > WIN(right)->x) {
- void *tmp = left->data;
- left->data = right->data;
- right->data = tmp;
- }
+ /* Load configuration */
+ MARGIN = conf_get_int("main.margin", MARGIN);
+ STACK = conf_get_int("main.stack", STACK);
wm = new0(wm_t);
wm->root = root;
- wm->screens = screens;
+ wm->screens = list_sort(sys_info(root), 0, sort_win);
wm->tag = tag_new(wm->screens, 1);
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',
- key_f1, key_f2, key_f3, key_f4, key_f5, key_f6,
+ key_f1, key_f2, key_f3, key_f4, key_f5, key_f6,
+ key_f7, key_f8, key_f9, key_f10, key_f11, key_f12,
key_mouse1, key_mouse3};
for (int i = 0; i < countof(keys_e); i++)
sys_watch(root, keys_e[i], MOD());
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);
+}