2 * Copyright (c) 2013 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 monocule window manager */
34 /* Helper functions */
35 void wm_show(list_t *node)
39 sys_show(node->data, ST_MAX);
40 sys_raise(node->data);
41 sys_focus(node->data);
44 /* Window management functions */
45 int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr)
47 list_t *node = list_find(wins, win);
49 if (node && mod.MODKEY && ev == 'j')
50 return wm_show(node->next), 1;
51 if (node && mod.MODKEY && ev == 'k')
52 return wm_show(node->prev), 1;
54 if (mod.MODKEY && mod.shift && ev == 'c')
55 return sys_show(win, ST_CLOSE), 1;
56 if (mod.MODKEY && mod.shift && ev == 'q')
62 int wm_handle_ptr(win_t *cwin, ptr_t ptr)
67 int wm_handle_state(win_t *win, state_t prev, state_t next)
72 void wm_insert(win_t *win)
74 if (win->type == TYPE_NORMAL) {
75 wins = list_append(wins, win);
76 wm_show(list_last(wins));
78 if (win->type == TYPE_TOOLBAR) {
83 void wm_remove(win_t *win)
85 list_t *node = list_find(wins, win);
87 wm_show(node->prev ?: node->next);
88 wins = list_remove(wins, node, 0);
91 void wm_init(win_t *root)
93 screens = sys_info(root);
94 sys_watch(root, 'j', MOD(.MODKEY=1));
95 sys_watch(root, 'k', MOD(.MODKEY=1));
96 sys_watch(root, 'c', MOD(.MODKEY=1,.shift=1));
97 sys_watch(root, 'q', MOD(.MODKEY=1,.shift=1));
100 void wm_free(win_t *root)
103 wins = list_remove(wins, wins, 0);