]> Pileus Git - wmpus/blob - wm-tags.c
Add brain-dead multiple desktop manager
[wmpus] / wm-tags.c
1 /*
2  * Copyright (c) 2011, Andy Spencer <andy753421@gmail.com>
3  *
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.
7  *
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
14  */
15
16 /* Brain-dead multiple desktop manager */
17
18 #include <stdio.h>
19
20 #include "util.h"
21 #include "sys.h"
22 #include "wm.h"
23
24 /* Configuration */
25 #ifndef MODKEY
26 #define MODKEY alt
27 #endif
28
29 /* Data */
30 int     tag = 1;
31 list_t *tags[10];
32
33 /* Window management functions */
34 void wm_update(void)
35 {
36 }
37
38 int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr)
39 {
40         int new = key - '0';
41         if (!win)
42                 return 0;
43         if (!mod.MODKEY)
44                 return 0;
45         if (key < '0' || '9' < key)
46                 return 0;
47         if (new == tag)
48                 return 0;
49
50         if (mod.shift) {
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);
55         } else {
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);
60                 tag = new;
61         }
62         return 1;
63 }
64
65 int wm_handle_ptr(win_t *cwin, ptr_t ptr)
66 {
67         return 0;
68 }
69
70 void wm_insert(win_t *win)
71 {
72         tags[tag] = list_insert(tags[tag], win);
73 }
74
75 void wm_remove(win_t *win)
76 {
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);
80         }
81 }
82
83 void wm_init(win_t *root)
84 {
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));
89         }
90 }
91
92 void wm_free(win_t *root)
93 {
94         for (int i = 0; i < 10; i++) {
95                 while (tags[i]) {
96                         sys_show(tags[i]->data, st_show);
97                         tags[i] = list_remove(tags[i], tags[i], 0);
98                 }
99         }
100 }