2 * Copyright (c) 2011, Andy Spencer <andy753421@gmail.com>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 /* Brain-dead multiple desktop manager */
33 /* Window management functions */
38 int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr)
45 if (key < '0' || '9' < key)
51 list_t *node = list_find(tags[tag], win);
52 tags[tag] = list_remove(tags[tag], node, 0);
53 tags[new] = list_insert(tags[new], win);
54 sys_show(win, st_hide);
56 for (list_t *cur = tags[new]; cur; cur = cur->next)
57 sys_show(cur->data, st_show);
58 for (list_t *cur = tags[tag]; cur; cur = cur->next)
59 sys_show(cur->data, st_hide);
65 int wm_handle_ptr(win_t *cwin, ptr_t ptr)
70 void wm_insert(win_t *win)
72 tags[tag] = list_insert(tags[tag], win);
75 void wm_remove(win_t *win)
77 for (int i = 0; i < 10; i++) {
78 list_t *node = list_find(tags[i], win);
79 tags[i] = list_remove(tags[i], node, 0);
83 void wm_init(win_t *root)
85 Key_t keys[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
86 for (int i = 0; i < countof(keys); i++) {
87 sys_watch(root, keys[i], MOD(.MODKEY=1));
88 sys_watch(root, keys[i], MOD(.MODKEY=1,.shift=1));
92 void wm_free(win_t *root)
94 for (int i = 0; i < 10; i++) {
96 sys_show(tags[i]->data, st_show);
97 tags[i] = list_remove(tags[i], tags[i], 0);