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)
41 if (!win || !mod.MODKEY || mod.up || new == tag ||
42 key < '0' || key > '9')
46 list_t *node = list_find(tags[tag], win);
49 tags[tag] = list_remove(tags[tag], node, 0);
50 tags[new] = list_insert(tags[new], win);
51 sys_show(win, st_hide);
53 for (list_t *cur = tags[new]; cur; cur = cur->next)
54 sys_show(cur->data, st_show);
55 for (list_t *cur = tags[tag]; cur; cur = cur->next)
56 sys_show(cur->data, st_hide);
62 int wm_handle_ptr(win_t *cwin, ptr_t ptr)
67 void wm_insert(win_t *win)
69 tags[tag] = list_insert(tags[tag], win);
72 void wm_remove(win_t *win)
74 for (int i = 0; i < 10; i++) {
75 list_t *node = list_find(tags[i], win);
78 tags[i] = list_remove(tags[i], node, 0);
82 void wm_init(win_t *root)
84 Key_t keys[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
85 for (int i = 0; i < countof(keys); i++) {
86 sys_watch(root, keys[i], MOD(.MODKEY=1));
87 sys_watch(root, keys[i], MOD(.MODKEY=1,.shift=1));
91 void wm_free(win_t *root)
93 for (int i = 0; i < 10; i++) {
95 sys_show(tags[i]->data, st_show);
96 tags[i] = list_remove(tags[i], tags[i], 0);