X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=wm-wmii.c;h=06a258fd49d954af42a94a16b3521fc2a7db9c4b;hb=2babe7f2be8297a853fcaa24c45bb4533cef7c03;hp=a2be22d69a4520f15db4fc52006fe841a284cbf3;hpb=7e8ce091da421353576edbd2a4a4e620fe0a62bd;p=wmpus diff --git a/wm-wmii.c b/wm-wmii.c index a2be22d..06a258f 100644 --- a/wm-wmii.c +++ b/wm-wmii.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Andy Spencer + * Copyright (c) 2011-2012, Andy Spencer * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -35,7 +35,7 @@ typedef enum { typedef enum { SPLIT, STACK, FULL, TAB -} mode_t; +} layout_t; typedef enum { TILING, FLOATING @@ -45,44 +45,44 @@ 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 + int name; // 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 + win_t *root; // root/background window + list_t *screens; // display geometry } wm_t; #define WIN(node) ((win_t*)(node)->data) @@ -186,16 +186,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; @@ -212,16 +212,6 @@ static void set_focus(win_t *win) return; } - /* - Only grab mouse button on unfocused window, - * this prevents stealing all mouse clicks from client windows, - * - A better way may be to re-send mouse clicks to client windows - * using the return value from wm_handle_key */ - for (int i = EV_MOUSE1; i < EV_MOUSE7; i++) { - if (wm_focus) - sys_watch(wm_focus, i, MOD()); - sys_unwatch(win, i, MOD()); - } - dpy_t *dpy; col_t *col; row_t *row; flt_t *flt; switch (search(wm_tag, win, &dpy, &col, &row, &flt)) { case TILING: @@ -279,7 +269,7 @@ 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; @@ -335,7 +325,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 ?: ST_SHOW; if (col == NULL) { col = new0(col_t); @@ -365,11 +356,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; @@ -481,7 +473,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) { @@ -643,10 +635,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)); @@ -673,7 +669,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); @@ -688,11 +683,17 @@ static void wm_update_cols(dpy_t *dpy) *******************************/ void wm_update(void) { - /* 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); + /* Updates window sizes */ + for (list_t *ldpy = wm_tag->dpys; ldpy; ldpy = ldpy->next) + wm_update_cols(ldpy->data); + tag_foreach_flt(wm_tag, ldpy, lflt, win) { + 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); + } + + /* 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) @@ -701,14 +702,7 @@ void wm_update(void) sys_show(win, ST_HIDE); } - /* Refresh the display */ - for (list_t *ldpy = wm_tag->dpys; ldpy; ldpy = ldpy->next) - wm_update_cols(ldpy->data); - tag_foreach_flt(wm_tag, ldpy, lflt, win) { - flt_t *flt = lflt->data; - sys_move(win, flt->x, flt->y, flt->w, flt->h); - sys_raise(flt->win); - } + /* Set focused window */ if (wm_focus) set_focus(wm_focus); } @@ -723,10 +717,10 @@ int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr) // mod.shift ? 's' : '-', // mod.win ? 'w' : '-'); - /* Mouse movement */ - if (ev == EV_MOUSE1) - raise_float(win); + /* Mouse events */ if (EV_MOUSE0 <= ev && ev <= EV_MOUSE7) { + if (ev == EV_MOUSE1 && !mod.MODKEY && !mod.up) + return raise_float(win), 0; if (ev == EV_MOUSE1 && mod.MODKEY && !mod.up) return set_move(win,ptr,MOVE), 1; if (ev == EV_MOUSE3 && mod.MODKEY && !mod.up) @@ -754,6 +748,11 @@ int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr) if (ev == EV_F5) return wm_update(), 1; if (ev == EV_F6) return print_txt(), 1; if (ev == 'q') return sys_exit(), 1; + if (ev == 'f') return wm_handle_state(win, win->state, + win->state == ST_FULL ? ST_SHOW : ST_FULL); + } + if (mod.MODKEY && mod.shift) { + if (ev == 'c') return sys_show(win, ST_CLOSE), 1; } /* Floating layer */ @@ -784,7 +783,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; @@ -809,9 +808,6 @@ int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr) if (ev == EV_ENTER && win->state != ST_SHADE) return set_focus(win), 1; - if (EV_MOUSE0 <= ev && ev <= EV_MOUSE7) - return set_focus(win), 0; - /* 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 */ @@ -865,6 +861,23 @@ 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; + + search(wm_tag, win, NULL, NULL, &row, &flt); + + 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); @@ -880,7 +893,7 @@ void wm_insert(win_t *win) /* Arrange */ wm_update(); - set_focus(wm_focus); + set_focus(win); print_txt(); } @@ -911,9 +924,9 @@ void wm_init(win_t *root) wm->tags = list_insert(NULL, wm->tag); event_t ev_e[] = {EV_ENTER, EV_FOCUS}; - event_t ev_s[] = {'h', 'j', 'k', 'l', 'q', ' ', + 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', ' ', + event_t ev_m[] = {'h', 'j', 'k', 'l', 'd', 's', 'm', 't', 'f', ' ', '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,