From 354101b66a115a36599d856fc7f3b4b350c080e4 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 18 Sep 2011 04:41:16 +0000 Subject: [PATCH] Use focus when moving windows --- sys-x11.c | 2 +- util.c | 12 ++++++++++++ util.h | 2 ++ wm-wmii.c | 30 +++++++++++++++++++++--------- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/sys-x11.c b/sys-x11.c index fd26bf6..db711c9 100644 --- a/sys-x11.c +++ b/sys-x11.c @@ -288,7 +288,7 @@ void sys_move(win_t *win, int x, int y, int w, int h) win->x = MAX(x,0); win->y = MAX(y,0); win->w = MAX(w,1); win->h = MAX(h,1); XMoveResizeWindow(win->sys->dpy, win->sys->xid, - win->x, win->y, win->w, win-h); + win->x, win->y, win->w, win->h); /* Flush events, so moving window doesn't cuase re-focus * There's probably a better way to do this */ diff --git a/util.c b/util.c index 24100f2..a91d1bd 100644 --- a/util.c +++ b/util.c @@ -15,6 +15,18 @@ list_t *list_insert(list_t *next, void *data) return node; } +void list_insert_after(list_t *prev, void *data) +{ + // prev must be valid, + // as we cannot return the original list head + list_t *node = new0(list_t); + node->data = data; + node->prev = prev; + node->next = prev->next; + prev->next = node; + if (node->next) node->next->prev = node; +} + list_t *list_append(list_t *head, void *data) { list_t *last = head; diff --git a/util.h b/util.h index 7c0415c..c477272 100644 --- a/util.h +++ b/util.h @@ -26,6 +26,8 @@ typedef struct list { list_t *list_insert(list_t *after, void *data); +void list_insert_after(list_t *after, void *data); + list_t *list_append(list_t *before, void *data); list_t *list_remove(list_t *head, list_t *item); diff --git a/wm-wmii.c b/wm-wmii.c index 800d0d3..df09dd4 100644 --- a/wm-wmii.c +++ b/wm-wmii.c @@ -63,11 +63,15 @@ static void print_txt(list_t *cols) { for (list_t *cnode = cols; cnode; cnode = cnode->next) { col_t *col = cnode->data; - printf("col:\t%p - %dpx @ %d\n", col, col->width, col->group); + printf("col:\t%p - %dpx @ %d !!%p\n", col, col->width, col->group, col->focus); for (list_t *wnode = col->rows; wnode; wnode = wnode->next) { win_t *win = wnode->data; - printf(" win:\t%p - %4dpx focus=%d%d\n", win, win->h, - col->focus == win, wm_focus == win); + printf(" win:\t^%-9p <%-9p [%p=%p] >%-9p %4dpx focus=%d%d\n", + win->wm->col->data, + (win->wm->row->prev ? win->wm->row->prev->data : NULL), + win->wm->row->data, win, + (win->wm->row->next ? win->wm->row->next->data : NULL), + win->h, col->focus == win, wm_focus == win); } } } @@ -118,7 +122,7 @@ static void cut_window(win_t *win) lcol->prev ? ((col_t*)lcol->prev->data)->focus : lcol->next ? ((col_t*)lcol->next->data)->focus : NULL; - col->rows = list_remove(col->rows, win->wm->row); + col->rows = list_remove(col->rows, lrow); if (col->rows == NULL) wm_cols = list_remove(wm_cols, lcol); } @@ -126,15 +130,20 @@ static void cut_window(win_t *win) static void put_window(win_t *win, list_t *lcol) { col_t *col = lcol->data; - col->rows = list_insert(col->rows, win); - win->wm->row = col->rows; + int nrows = list_length(col->rows); + if (col->focus) { + list_insert_after(col->focus->wm->row, win); + win->wm->row = col->focus->wm->row->next; + } else { + col->rows = list_insert(col->rows, win); + win->wm->row = col->rows; + } win->wm->col = lcol; col->focus = win; wm_focus = win; - int nrows = list_length(col->rows); - win->h = wm_root->h / MAX(nrows-1,1); - if (nrows == 1) { // new column + win->h = wm_root->h / MAX(nrows,1); + if (nrows == 0) { int ncols = list_length(wm_cols); col->width = wm_root->w / MAX(ncols-1,1); } @@ -211,6 +220,8 @@ int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr) return sys_raise(win), 1; if (key == key_f1 && mod.MODKEY) sys_raise(win); + if (key == key_f12 && mod.MODKEY) + print_txt(wm_cols); if (key_mouse0 <= key && key <= key_mouse7) sys_raise(win); @@ -333,6 +344,7 @@ void wm_init(win_t *root) printf("wm_init: %p\n", root); wm_root = root; sys_watch(root, key_f1, MOD(.MODKEY=1)); + sys_watch(root, key_f12, MOD(.MODKEY=1)); sys_watch(root, key_mouse1, MOD(.MODKEY=1)); sys_watch(root, key_mouse3, MOD(.MODKEY=1)); sys_watch(root, key_enter, MOD()); -- 2.43.2