-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtag.c
129 lines (110 loc) · 4.25 KB
/
tag.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* GoomwWM, Get out of my way, Window Manager!
MIT/X11 License
Copyright (c) 2012 Sean Pringle <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// for the benefit of EWMH type pagers, tag = desktop
// but, since a window can have multiple tags... oh well
unsigned int tag_to_desktop(unsigned int tag)
{
unsigned int i; for (i = 0; i < TAGS; i++) if (tag & (1<<i)) return i;
return 0xffffffff;
}
unsigned int desktop_to_tag(unsigned int desktop)
{
return (desktop == 0xffffffff) ? 0: 1<<desktop;
}
// update current desktop on all roots
void tag_set_current(unsigned int tag)
{
current_tag = tag; unsigned long d = tag_to_desktop(current_tag);
window_set_cardinal_prop(root, netatoms[_NET_CURRENT_DESKTOP], &d, 1);
}
// raise all windows in a tag
void tag_raise(unsigned int tag)
{
int i, found = 0, shaded = 0; Window w; client *c;
winlist *stack;
// if this tag was previously hidden, reveal it
clients_ascend(windows_shaded, i, w, c)
if (c->manage && c->cache->tags & tag)
{ client_reveal(c); shaded++; }
if (shaded)
{
XSync(display, False);
reset_cache_xattr();
reset_cache_client();
reset_cache_inplay();
}
stack = winlist_new();
// locate windows with _NET_WM_STATE_ABOVE and _NET_WM_STATE_STICKY
managed_descend(i, w, c)
if (winlist_find(stack, w) < 0 && c->visible && c->trans == None
&& client_has_state(c, netatoms[_NET_WM_STATE_ABOVE])
&& client_has_state(c, netatoms[_NET_WM_STATE_STICKY]))
client_stack_family(c, stack);
// locate windows with _NET_WM_STATE_ABOVE in this tag
tag_descend(i, w, c, tag)
if (winlist_find(stack, w) < 0 && c->visible && c->trans == None
&& client_has_state(c, netatoms[_NET_WM_STATE_ABOVE]))
{ client_stack_family(c, stack); found++; }
// locate _NET_WM_WINDOW_TYPE_DOCK windows
clients_descend(windows_in_play(), i, w, c)
if (winlist_find(stack, w) < 0 && c->visible && c->trans == None
&& c->type == netatoms[_NET_WM_WINDOW_TYPE_DOCK])
client_stack_family(c, stack);
// locate all other windows in the tag
tag_descend(i, w, c, tag)
if (winlist_find(stack, w) < 0 && c->trans == None)
{ client_stack_family(c, stack); found++; }
// raise the top window in the stack
if (stack->len) XRaiseWindow(display, stack->array[0]);
// stack everything else, in order, underneath top window
if (stack->len > 1) XRestackWindows(display, stack->array, stack->len);
winlist_free(stack);
tag_set_current(tag);
if (config_only_auto) tag_only(tag);
// focus the last-focused client in the tag
clients_descend(windows_activated, i, w, c) if (c->cache->tags & tag)
{ client_activate(c, RAISE, WARPDEF); break; }
// in case no windows are in the tag, show some activity
if (found) notice("Tag %d", tag_to_desktop(tag)+1);
else notice("Tag %d (empty!)", tag_to_desktop(tag)+1);
}
// check active client. if
void tag_auto_switch()
{
client *c = client_active(0);
if (c && c->cache->tags && !(c->cache->tags & current_tag))
{
int i, n = 0; Window w; client *o; tag_descend(i, w, o, current_tag) n++;
if (!n) tag_raise(desktop_to_tag(tag_to_desktop(c->cache->tags)));
}
}
void tag_only(unsigned int tag)
{
int i; Window w; client *c;
managed_descend(i, w, c)
if (!(c->cache->tags & tag))
client_shade(c);
}
void tag_close(unsigned int tag)
{
int i; Window w; client *c;
tag_descend(i, w, c, tag) client_close(c);
}