]> Pileus Git - wmpus/commitdiff
Use focus when moving windows
authorAndy Spencer <andy753421@gmail.com>
Sun, 18 Sep 2011 04:41:16 +0000 (04:41 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 18 Sep 2011 04:41:16 +0000 (04:41 +0000)
sys-x11.c
util.c
util.h
wm-wmii.c

index fd26bf64aed8be4b46ecc1af56498194646395aa..db711c94a3561e8d7bb6f9669b697939b5bf3fda 100644 (file)
--- 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 24100f2243d6576d8481109a17a43c614d4a7c1a..a91d1bdc329d151ee9dad33ec7c1df34fd15c3ee 100644 (file)
--- 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 7c0415cb789b8cd69ac7fded40e3f3edd971db6e..c4772727fe0b52a45575b04d366b8559acb1ac33 100644 (file)
--- 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);
index 800d0d3b71c2768744ac5d64946796209e13021c..df09dd45577595903f957e9bdf6e8c48a7a88a1e 100644 (file)
--- 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());