]> Pileus Git - wmpus/blob - wm-mono.c
Allow adding hidden windows
[wmpus] / wm-mono.c
1 /*
2  * Copyright (c) 2013 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 monocule window manager */
17
18 #include <stdio.h>
19
20 #include "util.h"
21 #include "types.h"
22 #include "sys.h"
23 #include "wm.h"
24
25 /* Configuration */
26 #ifndef MODKEY
27 #define MODKEY alt
28 #endif
29
30 /* Data */
31 list_t *wins;
32 list_t *focus;
33 list_t *screens;
34
35 /* Helper functions */
36 static void wm_show(list_t *node)
37 {
38         focus = node;
39         if (!node) return;
40         sys_show(node->data, ST_MAX);
41         sys_raise(node->data);
42         sys_focus(node->data);
43 }
44
45 /* Window management functions */
46 int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr)
47 {
48         list_t *node = list_find(wins, win);
49
50         if (node && mod.MODKEY && ev == 'j')
51                 return wm_show(node->next), 1;
52         if (node && mod.MODKEY && ev == 'k')
53                 return wm_show(node->prev), 1;
54
55         if (mod.MODKEY && mod.shift && ev == 'c')
56                 return sys_show(win, ST_CLOSE), 1;
57         if (mod.MODKEY && mod.shift && ev == 'q')
58                 return sys_exit(), 1;
59
60         return 0;
61 }
62
63 int wm_handle_ptr(win_t *cwin, ptr_t ptr)
64 {
65         return 0;
66 }
67
68 int wm_handle_state(win_t *win, state_t prev, state_t next)
69 {
70         return 0;
71 }
72
73 void wm_insert(win_t *win)
74 {
75         if (win->type == TYPE_NORMAL) {
76                 wins = list_append(wins, win);
77                 wm_show(list_last(wins));
78         }
79         if (win->type == TYPE_TOOLBAR) {
80                 wm_show(focus);
81         }
82 }
83
84 void wm_remove(win_t *win)
85 {
86         list_t *node = list_find(wins, win);
87         if (node == focus)
88                 wm_show(node->prev ?: node->next);
89         wins = list_remove(wins, node, 0);
90 }
91
92 void wm_init(void)
93 {
94         screens = sys_info();
95         sys_watch(NULL, 'j', MOD(.MODKEY=1));
96         sys_watch(NULL, 'k', MOD(.MODKEY=1));
97         sys_watch(NULL, 'c', MOD(.MODKEY=1,.shift=1));
98         sys_watch(NULL, 'q', MOD(.MODKEY=1,.shift=1));
99 }
100
101 void wm_free(void)
102 {
103         while (wins)
104                 wins = list_remove(wins, wins, 0);
105 }