X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=wm-wmii.c;h=e31f07422ec23b37da60e11379532fac9927a29e;hb=84fdb5249282e858b32f59f49a877a07350a48eb;hp=84250ea85736a24358297b9547b37e3b258392fd;hpb=6676472c287a8163d53b2ba14ca8ec39bf7443eb;p=wmpus diff --git a/wm-wmii.c b/wm-wmii.c index 84250ea..e31f074 100644 --- a/wm-wmii.c +++ b/wm-wmii.c @@ -15,9 +15,11 @@ #include #include +#include #include "util.h" #include "conf.h" +#include "types.h" #include "sys.h" #include "wm.h" @@ -35,7 +37,7 @@ typedef enum { typedef enum { SPLIT, STACK, FULL, TAB -} mode_t; +} layout_t; typedef enum { TILING, FLOATING @@ -45,44 +47,43 @@ typedef enum { struct win_wm { }; typedef struct { - win_t *win; // the window - int height; // win height in _this_ tag - state_t state; // state of window + win_t *win; // the window + int height; // win height in _this_ tag + state_t state; // state of window } row_t; typedef struct { - list_t *rows; // of row_t - row_t *row; // focused row - int width; // column width - mode_t mode; // display mode + list_t *rows; // of row_t + row_t *row; // focused row + int width; // column width + layout_t layout; // column layout } col_t; typedef struct { - win_t *win; // the window - int x, y, w, h; // position of window (in this tag) - state_t state; // state of window + 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 { - list_t *cols; // of col_t - col_t *col; // focused col - list_t *flts; // of flt_t - flt_t *flt; // focused flt - layer_t layer; // focused layer - win_t *geom; // display size and position + list_t *cols; // of col_t + col_t *col; // focused col + list_t *flts; // of flt_t + flt_t *flt; // focused flt + layer_t layer; // focused layer + win_t *geom; // display size and position } dpy_t; typedef struct { - list_t *dpys; // of dpy_t - dpy_t *dpy; // focused dpy - int name; // tag name + list_t *dpys; // of dpy_t + dpy_t *dpy; // focused dpy + char name[64]; // tag name } tag_t; typedef struct { - list_t *tags; // of tag_t - tag_t *tag; // focused tag - win_t *root; // root/background window - list_t *screens; // display geometry + list_t *tags; // of tag_t + tag_t *tag; // focused tag + list_t *screens; // display geometry } wm_t; #define WIN(node) ((win_t*)(node)->data) @@ -123,6 +124,9 @@ static ptr_t move_prev; static layer_t move_layer; static struct { int v, h; } move_dir; +/* Prototypes */ +void wm_update(void); + /******************** * Helper functions * ********************/ @@ -186,16 +190,16 @@ static int search(tag_t *tag, win_t *target, return -1; } -/* Set the mode for the windows column in the current tag */ -static void set_mode(win_t *win, mode_t mode) +/* Set the layout for the windows column in the current tag */ +static void set_mode(win_t *win, layout_t layout) { col_t *col; if (TILING != search(wm_tag, win, NULL, &col, NULL, NULL)) return; printf("set_mode: %p, %d -> %d\n", - col, col->mode, mode); - col->mode = mode; - if (col->mode == SPLIT) + col, col->layout, layout); + col->layout = layout; + if (col->layout == SPLIT) for (list_t *cur = col->rows; cur; cur = cur->next) { row_t *row = cur->data; row->height = wm_dpy->geom->h; @@ -207,8 +211,8 @@ static void set_mode(win_t *win, mode_t mode) * it as the currently focused window */ static void set_focus(win_t *win) { - if (win == NULL || win == wm->root) { - sys_focus(wm->root); + if (win == NULL) { + sys_focus(NULL); return; } @@ -254,7 +258,7 @@ static void print_txt(void) { for (list_t *ltag = wm->tags; ltag; ltag = ltag->next) { tag_t *tag = ltag->data; - printf("tag: <%-9p [%p->%p] >%-9p d=%-9p - %d\n", + printf("tag: <%-9p [%p->%p] >%-9p d=%-9p - %s\n", ltag->prev, ltag, ltag->data, ltag->next, tag->dpy, tag->name); for (list_t *ldpy = tag->dpys; ldpy; ldpy = ldpy->next) { @@ -269,11 +273,11 @@ static void print_txt(void) col_t *col = lcol->data; printf(" col: <%-9p [%p->%p] >%-9p r=%-9p - %dpx @ %d\n", lcol->prev, lcol, lcol->data, lcol->next, - col->row, col->width, col->mode); + col->row, col->width, col->layout); for (list_t *lrow = col->rows; lrow; lrow = lrow->next) { row_t *row = lrow->data; win_t *win = row->win; - printf(" win: <%-9p [%p>>%p] >%-9p focus=%d%d - %4dpx \n", + printf(" row: <%-9p [%p>>%p] >%-9p focus=%d%d - %4dpx \n", lrow->prev, lrow, win, lrow->next, col->row == row, wm_focus == win, win->h); } } @@ -325,7 +329,8 @@ static layer_t cut_win(win_t *win, tag_t *tag) static void put_win_col(win_t *win, tag_t *tag, dpy_t *dpy, col_t *col) { row_t *row = new0(row_t); - row->win = win; + row->win = win; + row->state = win->state; if (col == NULL) { col = new0(col_t); @@ -355,11 +360,12 @@ static void put_win_col(win_t *win, tag_t *tag, dpy_t *dpy, col_t *col) static void put_win_flt(win_t *win, tag_t *tag, dpy_t *dpy) { flt_t *flt = new0(flt_t); - flt->win = win; - flt->w = dpy->geom->w / 2; - flt->h = dpy->geom->h / 2; - flt->x = dpy->geom->x + flt->w / 2; - flt->y = dpy->geom->y + flt->h / 2; + flt->win = win; + flt->w = dpy->geom->w / 2; + flt->h = dpy->geom->h / 2; + flt->x = dpy->geom->x + flt->w / 2; + flt->y = dpy->geom->y + flt->h / 2; + flt->state = win->state ?: ST_SHOW; if (dpy->flt) { flt->x = dpy->flt->x + 20; flt->y = dpy->flt->y + 20; @@ -471,7 +477,7 @@ static void shift_focus(int cols, int rows) return; row_t *next = get_next(row, rows > 0)->data; set_focus(next->win); - if (COL(col)->mode != SPLIT) + if (COL(col)->layout != SPLIT) wm_update(); } if (cols != 0) { @@ -496,7 +502,7 @@ static void shift_focus(int cols, int rows) if (ncol && COL(ncol) && COL(ncol)->row) set_focus(COL(ncol)->row->win); else - sys_focus(wm->root); + sys_focus(NULL); } } @@ -536,10 +542,10 @@ static void set_layer(win_t *win) } /* Allocate a new tag */ -static tag_t *tag_new(list_t *screens, int name) +static tag_t *tag_new(list_t *screens, const char *name) { tag_t *tag = new0(tag_t); - tag->name = name; + strncpy(tag->name, name, sizeof(tag->name)); for (list_t *cur = screens; cur; cur = cur->next) { dpy_t *dpy = new0(dpy_t); dpy->geom = cur->data; @@ -555,11 +561,11 @@ static tag_t *tag_new(list_t *screens, int name) /* Search for a tag * If it does not exist it is based on the * display geometry in wm->screens */ -static tag_t *tag_find(int name) +static tag_t *tag_find(const char *name) { tag_t *tag = NULL; for (list_t *cur = wm->tags; cur; cur = cur->next) - if (name == TAG(cur)->name) { + if (!strcmp(name, TAG(cur)->name)) { tag = cur->data; break; } @@ -572,10 +578,10 @@ static tag_t *tag_find(int name) /* Move the window from the current tag to the new tag * Unlike wmii, only remove the current tag, not all tags */ -static void tag_set(win_t *win, int name) +static void tag_set(win_t *win, const char *name) { - printf("tag_set: %p %d\n", win, name); - if (wm_tag->name == name) + printf("tag_set: %p %s\n", win, name); + if (!strcmp(wm_tag->name, name)) return; tag_t *tag = tag_find(name); layer_t layer = cut_win(win, wm_tag); @@ -584,9 +590,9 @@ static void tag_set(win_t *win, int name) } /* Switch to a different tag */ -static void tag_switch(int name) +static void tag_switch(const char *name) { - printf("tag_switch: %d\n", name); + printf("tag_switch: %s\n", name); tag_t *old = wm_tag; if ((wm_col == NULL || wm_row == NULL) && wm_flt == NULL) { while (old->dpys) { @@ -633,10 +639,14 @@ static void wm_update_cols(dpy_t *dpy) - (nrows-1)* stack; for (list_t *lrow = col->rows; lrow; lrow = lrow->next) { win_t *win = ROW(lrow)->win; + if (ROW(lrow)->state != ST_SHOW) { + sys_show(win, ROW(lrow)->state); + continue; + } win->h = ROW(lrow)->height; state_t state = ST_SHOW; int height = 0; - switch (col->mode) { + switch (col->layout) { case SPLIT: sys_move(win, x+margin, y+margin, col->width, win->h * ((float)my / ty)); @@ -663,7 +673,6 @@ static void wm_update_cols(dpy_t *dpy) col->width, dpy->geom->h-2*margin); break; } - ROW(lrow)->state = state; sys_show(win, state); if (focus == win) sys_raise(win); @@ -673,9 +682,7 @@ static void wm_update_cols(dpy_t *dpy) } } -/******************************* - * Window management functions * - *******************************/ +/* Refresh the window layout */ void wm_update(void) { /* Updates window sizes */ @@ -685,19 +692,16 @@ void wm_update(void) flt_t *flt = lflt->data; sys_move(win, flt->x, flt->y, flt->w, flt->h); sys_raise(flt->win); + sys_show(flt->win, flt->state); } - /* Show/hide tags */ - tag_foreach_col(wm_tag, dpy, col, row, win) - sys_show(win, ROW(row)->state); - tag_foreach_flt(wm_tag, dpy, flt, win) - sys_show(win, FLT(flt)->state); + /* Hide other tags */ for (list_t *tag = wm ->tags; tag; tag = tag->next) if (tag->data != wm_tag) { tag_foreach_col(TAG(tag), dpy, col, row, win) - sys_show(win, ST_HIDE); + sys_show(win, ST_HIDE); tag_foreach_flt(TAG(tag), dpy, flt, win) - sys_show(win, ST_HIDE); + sys_show(win, ST_HIDE); } /* Set focused window */ @@ -705,9 +709,11 @@ void wm_update(void) set_focus(wm_focus); } +/******************************* + * Window management functions * + *******************************/ int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr) { - if (!win || win == wm_dpy->geom) return 0; //printf("wm_handle_event: %p - %x %c%c%c%c%c\n", win, ev, // mod.up ? '^' : 'v', // mod.alt ? 'a' : '-', @@ -716,13 +722,14 @@ int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr) // mod.win ? 'w' : '-'); /* Mouse events */ - if (EV_MOUSE0 <= ev && ev <= EV_MOUSE7) { + if (win && EV_MOUSE0 <= ev && ev <= EV_MOUSE7) { if (ev == EV_MOUSE1 && !mod.MODKEY && !mod.up) return raise_float(win), 0; + if ((ev == EV_MOUSE3 && mod.MODKEY && !mod.up) || + (ev == EV_MOUSE1 && mod.MODKEY && !mod.up && mod.shift)) + return set_move(win,ptr,RESIZE), 1; if (ev == EV_MOUSE1 && mod.MODKEY && !mod.up) return set_move(win,ptr,MOVE), 1; - if (ev == EV_MOUSE3 && mod.MODKEY && !mod.up) - return set_move(win,ptr,RESIZE), 1; if (move_mode != NONE && mod.up) return set_move(win,ptr,NONE), 1; if (ev == EV_MOUSE1 && !mod.up && win->state == ST_SHADE) @@ -732,28 +739,36 @@ int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr) /* Only handle key-down */ if (mod.up) - return 0; + return mod.MODKEY || ev == EV_ALT; /* Misc */ - if (mod.MODKEY) { #ifdef DEBUG + if (win && mod.MODKEY) { if (ev == EV_F1) return raise_float(win), 1; if (ev == EV_F2) return set_focus(win), 1; if (ev == EV_F3) return sys_show(win, ST_SHOW), 1; if (ev == EV_F4) return sys_show(win, ST_HIDE), 1; if (ev == EV_F7) return sys_show(win, ST_SHADE), 1; + } #endif + if (mod.MODKEY) { if (ev == EV_F5) return wm_update(), 1; if (ev == EV_F6) return print_txt(), 1; if (ev == 'q') return sys_exit(), 1; } - if (mod.MODKEY && mod.shift) { + if (win && mod.MODKEY) { + if (ev == 'f') return wm_handle_state(win, win->state, + win->state == ST_FULL ? ST_SHOW : ST_FULL); + if (ev == 'g') return wm_handle_state(win, win->state, + win->state == ST_MAX ? ST_SHOW : ST_MAX); + } + if (win && mod.MODKEY && mod.shift) { if (ev == 'c') return sys_show(win, ST_CLOSE), 1; } /* Floating layer */ if (ev == ' ') { - if (mod.MODKEY && mod.shift) + if (win && mod.MODKEY && mod.shift) return set_layer(win), 1; if (mod.MODKEY) return switch_layer(), 1; @@ -779,7 +794,7 @@ int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr) } } - /* Column mode commands */ + /* Column layout commands */ if (mod.MODKEY) { switch (ev) { case 'd': return set_mode(win, SPLIT), 1; @@ -792,25 +807,25 @@ int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr) /* Tag switching */ if (mod.MODKEY && '0' <= ev && ev <= '9') { - int name = ev - '0'; - if (mod.shift) + char name[] = {ev, '\0'}; + if (win && mod.shift) tag_set(win, name); - else + if (!mod.shift) tag_switch(name); wm_update(); } /* Focus change */ - if (ev == EV_ENTER && win->state != ST_SHADE) + if (win && ev == EV_ENTER && win->state != ST_SHADE) return set_focus(win), 1; /* Reset focus after after focus change, * not sure what is causing the focus change in the first place * but preventing that would be a better solution */ if (ev == EV_FOCUS) - sys_focus(wm_focus ?: wm->root); + sys_focus(wm_focus); - return 0; + return mod.MODKEY; } int wm_handle_ptr(win_t *cwin, ptr_t ptr) @@ -857,17 +872,50 @@ int wm_handle_ptr(win_t *cwin, ptr_t ptr) return 0; } +int wm_handle_state(win_t *win, state_t prev, state_t next) +{ + row_t *row = NULL; + flt_t *flt = NULL; + + printf("wm_handle_state - %p %x -> %x\n", win, prev, next); + + search(wm_tag, win, NULL, NULL, &row, &flt); + + if (!row && !flt && next == ST_SHOW) + return wm_insert(win), 1; + if ((row || flt) && (next == ST_HIDE || next == ST_ICON)) + return wm_remove(win), 1; + + if (row) row->state = next; + if (flt) flt->state = next; + + if (prev == ST_MAX || prev == ST_FULL || + next == ST_MAX || next == ST_FULL) + wm_update(); + + return 1; +} + void wm_insert(win_t *win) { printf("wm_insert: %p\n", win); print_txt(); + /* Make sure it's visible */ + if (win->state == ST_HIDE) + return; + + /* Check for toolbars */ + if (win->type == TYPE_TOOLBAR) + return wm_update(); + /* Initialize window */ - win->wm = new0(win_wm_t); sys_watch(win, EV_ENTER, MOD()); sys_watch(win, EV_FOCUS, MOD()); /* Add to screen */ + if (win->type == TYPE_DIALOG || win->parent) + wm_dpy->layer = FLOATING; put_win(win, wm_tag, wm_dpy->layer); /* Arrange */ @@ -880,45 +928,46 @@ void wm_remove(win_t *win) { printf("wm_remove: %p\n", win); print_txt(); + if (win->type == TYPE_TOOLBAR) + return wm_update(); 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) +void wm_init(void) { - printf("wm_init: %p\n", root); + printf("wm_init\n"); /* 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 = list_sort(sys_info(root), 0, sort_win); - wm->tag = tag_new(wm->screens, 1); + wm->screens = list_sort(sys_info(), 0, sort_win); + wm->tag = tag_new(wm->screens, "1"); wm->tags = list_insert(NULL, wm->tag); - event_t ev_e[] = {EV_ENTER, EV_FOCUS, EV_MOUSE1}; + event_t ev_e[] = {EV_ENTER, EV_FOCUS}; event_t ev_s[] = {'h', 'j', 'k', 'l', 'c', 'q', ' ', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; - event_t ev_m[] = {'h', 'j', 'k', 'l', 'd', 's', 'm', 't', ' ', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + EV_MOUSE1, EV_MOUSE3}; + event_t ev_m[] = {'h', 'j', 'k', 'l', 'd', 's', 'm', 't', 'f', 'g', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', EV_F1, EV_F2, EV_F3, EV_F4, EV_F5, EV_F6, EV_F7, EV_F8, EV_F9, EV_F10, EV_F11, EV_F12, EV_MOUSE1, EV_MOUSE3}; for (int i = 0; i < countof(ev_e); i++) - sys_watch(root, ev_e[i], MOD()); + sys_watch(NULL, ev_e[i], MOD()); for (int i = 0; i < countof(ev_m); i++) - sys_watch(root, ev_m[i], MOD(.MODKEY=1)); + sys_watch(NULL, ev_m[i], MOD(.MODKEY=1)); for (int i = 0; i < countof(ev_s); i++) - sys_watch(root, ev_s[i], MOD(.MODKEY=1,.shift=1)); + sys_watch(NULL, ev_s[i], MOD(.MODKEY=1,.shift=1)); } -void wm_free(win_t *root) +void wm_free(void) { /* Re-show and free all windows */ while ( wm->tags) { tag_t *tag = wm->tags->data; @@ -926,12 +975,10 @@ void wm_free(win_t *root) 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); }