-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
244 lines (223 loc) · 6.21 KB
/
Copy pathclient.c
File metadata and controls
244 lines (223 loc) · 6.21 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/* evilwm - Minimalist Window Manager for X
* Copyright (C) 1999-2002 Ciaran Anscomb <evilwm@6809.org.uk>
* see README for license and other details. */
#include "yeahwm.h"
#include <stdlib.h>
#include <stdio.h>
#ifdef SHAPE
#include <X11/extensions/shape.h>
#endif
static int send_xmessage(Window w, Atom a, long x);
/* used all over the place. return the client that has specified window as
* either window or parent */
Client *find_client(Window w)
{
Client *c;
for (c = head_client; c; c = c->next)
if (w == c->parent || w == c->window || w == c->tab)
return c;
return NULL;
}
static void __set_wm_state(const Window win, const Atom a, int state, long vis)
{
long data[2];
data[0] = (long) state;
data[1] = vis;
XChangeProperty(dpy, win, a, a, 32, PropModeReplace, (unsigned char *) data, 2);
}
void set_wm_state(Client * c, int state)
{
/* iconify window and set state */
__set_wm_state(c->window, xa_wm_state, state, None);
}
static long *_g_wm_state(const Window win, const Atom where)
{
Atom real_type;
int real_format;
unsigned long n, extra;
unsigned char *data;
if ((XGetWindowProperty(dpy, win, where, 0L, 2L, False,
AnyPropertyType, &real_type, &real_format, &n, &extra, &data) == Success) && n) {
return (long *) data;
}
return NULL;
}
static int __wm_state(const Window win, const Atom where)
{
long *data, state = WithdrawnState;
data = _g_wm_state(win, where);
if (data) {
state = *data;
XFree(data);
}
return state;
}
int wm_state(Client * c)
{
return __wm_state(c->window, xa_wm_state);
}
void send_config(Client * c)
{
XConfigureEvent ce;
ce.type = ConfigureNotify;
ce.event = c->window;
ce.window = c->window;
ce.x = c->x;
ce.y = c->y;
ce.width = c->width;
ce.height = c->height;
ce.border_width = 0;
ce.above = None;
ce.override_redirect = 0;
XSendEvent(dpy, c->window, False, StructureNotifyMask, (XEvent *) & ce);
}
void remove_client(Client * c)
{
Client *p;
#ifdef DEBUG
fprintf(stderr, "remove_client() : Removing...\n");
#endif
XGrabServer(dpy);
XSetErrorHandler(ignore_xerror);
if (!quitting) {
#ifdef DEBUG
fprintf(stderr, "\tremove_client() : setting WithdrawnState\n");
#endif
set_wm_state(c, WithdrawnState);
XRemoveFromSaveSet(dpy, c->window);
}
ungravitate(c);
XSetWindowBorderWidth(dpy, c->window, 1);
XReparentWindow(dpy, c->window, root, c->x, c->y);
if (c->parent)
XDestroyWindow(dpy, c->parent);;
if (c->tab)
XDestroyWindow(dpy, c->tab);
if (head_client == c)
head_client = c->next;
else
for (p = head_client; p && p->next; p = p->next)
if (p->next == c)
p->next = c->next;
if (c->size)
XFree(c->size);
if (c->name)
XFree(c->name);
if (current == c)
current = NULL; /* an enter event should set this up again */
free(c);
#ifdef DEBUG
{
Client *p;
int i = 0;
for (p = head_client; p; p = p->next)
i++;
fprintf(stderr, "\tremove_client() : free(), window count now %d\n", i);
}
#endif
XSync(dpy, False);
XSetErrorHandler(handle_xerror);
XUngrabServer(dpy);
}
void change_gravity(Client * c, int multiplier)
{
int dx = 0, dy = 0;
int gravity = (c->size->flags & PWinGravity) ? c->size->win_gravity : NorthWestGravity;
switch (gravity) {
case NorthWestGravity:
case SouthWestGravity:
case NorthEastGravity:
case StaticGravity:
dx = c->border;
case NorthGravity:
dy = c->border;
break;
}
c->x += multiplier * dx;
c->y += multiplier * dy;
#ifdef DEBUG
if (dx || dy) {
fprintf(stderr, "change_gravity() : window adjustment of %d,%d for ", multiplier * dx, multiplier * dy);
switch (gravity) {
case NorthWestGravity:
fprintf(stderr, "NorthWestGravity\n");
break;
case SouthWestGravity:
fprintf(stderr, "SouthWestGravity\n");
break;
case NorthEastGravity:
fprintf(stderr, "NorthEastGravity\n");
break;
case NorthGravity:
fprintf(stderr, "NorthGravity\n");
break;
case StaticGravity:
fprintf(stderr, "StaticGravity\n");
break;
default:
fprintf(stderr, "unhandled gravity %d\n", gravity);
break;
}
}
#endif
}
void send_wm_delete(Client * c)
{
int i, n, found = 0;
Atom *protocols;
if (c) {
if (XGetWMProtocols(dpy, c->window, &protocols, &n)) {
for (i = 0; i < n; i++)
if (protocols[i] == xa_wm_delete)
found++;
XFree(protocols);
}
if (found)
send_xmessage(c->window, xa_wm_protos, xa_wm_delete);
else
XKillClient(dpy, c->window);
}
}
static int send_xmessage(Window w, Atom a, long x)
{
XEvent ev;
ev.type = ClientMessage;
ev.xclient.window = w;
ev.xclient.message_type = a;
ev.xclient.format = 32;
ev.xclient.data.l[0] = x;
ev.xclient.data.l[1] = CurrentTime;
return XSendEvent(dpy, w, False, NoEventMask, &ev);
}
#ifdef SHAPE
void set_shape(Client * c)
{
int n, order;
XRectangle *rect;
rect = XShapeGetRectangles(dpy, c->window, ShapeBounding, &n, &order);
if (n > 1)
XShapeCombineShape(dpy, c->parent, ShapeBounding, c->border, c->border, c->window, ShapeBounding, ShapeSet);
XFree((void *) rect);
}
#endif
void client_update_current(Client * c)
{
if (c) {
if (c->vdesk == STICKY) {
XSetWindowBackground(dpy, c->parent, fc.pixel);
XSetWindowBackground(dpy, c->tab, fc.pixel);
} else {
XSetWindowBackground(dpy, c->parent, abg.pixel);
XSetWindowBackground(dpy, c->tab, abg.pixel);
}
XClearWindow(dpy, c->parent);
if (c == current)
return;
}
if (current) {
XSetWindowBackground(dpy, current->parent, bg.pixel);
XSetWindowBackground(dpy, current->tab, bg.pixel);
XClearWindow(dpy, current->parent);
}
current = c;
}