X-Git-Url: http://pileus.org/git/?p=wmpus;a=blobdiff_plain;f=wm-wmii.c;h=ad114ebe49ccd5f218dcee3d30e9c2ff6d519cfd;hp=9e44400899a69377e160839f4f991e3a8d7eb6a8;hb=c5d281c2e042c1153109dd46b74ef3d41fcacd93;hpb=bdfa912aef69869a2385d65d5e8486080fc66895 diff --git a/wm-wmii.c b/wm-wmii.c index 9e44400..ad114eb 100644 --- a/wm-wmii.c +++ b/wm-wmii.c @@ -1,36 +1,32 @@ /* - * Copyright (C) 2011 Andy Spencer + * Copyright (c) 2011, Andy Spencer * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF */ #include #include #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 { @@ -285,8 +281,9 @@ static void print_txt(void) } } for (list_t *lflt = dpy->flts; lflt; lflt = lflt->next) { flt_t *flt = lflt->data; - printf(" flt: <%-9p [%p->%p] >%-9p focus=%d%d - %d,%d %dx%d \n", - lflt->prev, lflt, lflt->data, lflt->next, + win_t *win = flt->win; + printf(" flt: <%-9p [%p>>%p] >%-9p focus=%d%d - %d,%d %dx%d \n", + lflt->prev, lflt, win, lflt->next, dpy->flt == flt, wm_focus == flt->win, flt->x, flt->y, flt->h, flt->w); } } } @@ -300,21 +297,22 @@ static layer_t cut_win(win_t *win, tag_t *tag) 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; @@ -514,10 +512,10 @@ static void raise_float(win_t *win) 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); } - sys_raise(win); } /* Toggle between floating and tiling layers */ @@ -588,9 +586,17 @@ static void tag_set(win_t *win, int name) 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); } @@ -613,6 +619,7 @@ static void wm_update_cols(dpy_t *dpy) COL(lcol)->width *= (float)mx / tx; /* Scale each column vertically */ + win_t *focus = get_focus(); for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next) { col_t *col = lcol->data; int nrows = list_length(col->rows); @@ -650,7 +657,7 @@ static void wm_update_cols(dpy_t *dpy) case tab: sys_move(win, x+MARGIN, 0+MARGIN, col->width, dpy->geom->h-2*MARGIN); - if (col->row->win == win) + if (focus == win) sys_raise(win); break; } @@ -711,7 +718,7 @@ int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr) 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; + return set_focus(win), wm_update(), 0; return 0; } @@ -729,6 +736,7 @@ int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr) #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 */ @@ -781,7 +789,7 @@ int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr) } /* Focus change */ - if (key == key_enter) + if (key == key_enter && win->h != STACK) return set_focus(win), 1; if (key_mouse0 <= key && key <= key_mouse7) @@ -849,7 +857,6 @@ void wm_insert(win_t *win) win->wm = new0(win_wm_t); sys_watch(win, key_enter, MOD()); sys_watch(win, key_focus, MOD()); - sys_watch(win, key_mouse1, MOD()); /* Add to screen */ put_win(win, wm_tag, wm_dpy->layer); @@ -866,14 +873,20 @@ void wm_remove(win_t *win) 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); + /* Load configuration */ + MARGIN = conf_get_int("main.margin", MARGIN); + STACK = conf_get_int("main.stack", STACK); + /* Hack, fix screen order */ list_t *screens = sys_info(root); list_t *left = screens; @@ -891,7 +904,7 @@ void wm_init(win_t *root) 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', @@ -904,3 +917,25 @@ void wm_init(win_t *root) 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); +}