-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwlist.c
144 lines (128 loc) · 2.33 KB
/
wlist.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* -*- tab-width: 4; c-basic-offset: 4; -*- */
/*
* wlist.c
*
* This module provides some helper functions to deal with
* windows.
*
* Copyright (c) 1999-2003, by Ivan Pascal <[email protected]>
*/
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <X11/Xlib.h>
#ifdef SHAPE_EXT
#include <X11/extensions/shape.h>
#endif
#include "xxkb.h"
#include "wlist.h"
static WInfo *winlist = NULL, *last = NULL;
WInfo*
win_find(Window w)
{
WInfo *pt = winlist;
while (pt != NULL) {
if (pt->win == w)
break;
pt = pt->next;
}
return pt;
}
WInfo*
button_find(Window w)
{
WInfo *pt = winlist;
while (pt != NULL) {
if (pt->button == w)
break;
pt = pt->next;
}
return pt;
}
void
win_update(Window win, XXkbElement *elem, GC gc, int group, int win_x, int win_y)
{
if (win && elem->pictures[group]) {
XClearWindow(dpy, win);
#ifdef SHAPE_EXT
if (shape_ext) {
/* Set clip region */
XShapeCombineMask(dpy, win,
ShapeClip,
win_x, win_y,
elem->shapemask[group], ShapeSet);
/* Set boundary region */
XShapeCombineMask(dpy, win,
ShapeBounding,
win_x - elem->border_width, win_y - elem->border_width,
elem->boundmask[group], ShapeSet);
}
/* Try to emulate shape extension */
else {
#endif
XSetClipOrigin(dpy, gc, 0, 0);
XSetClipMask(dpy, gc, elem->shapemask[group]);
#ifdef SHAPE_EXT
}
#endif
XCopyArea(dpy, elem->pictures[group], win, gc,
0, 0,
elem->geometry.width,
elem->geometry.height,
win_x, win_y);
}
}
WInfo*
win_add(Window w, kbdState *state)
{
WInfo *pt;
pt = (WInfo*) malloc(sizeof(WInfo));
if (pt != NULL) {
pt->win = w;
pt->button = 0;
memcpy((void*) &pt->state, (void*) state, sizeof(kbdState));
pt->next = 0;
if (last != NULL)
last->next = pt;
if (winlist == NULL)
winlist = pt;
last = pt;
}
return pt;
}
void
win_free(Window w)
{
WInfo *pt = winlist, *prev = NULL;
while (pt != NULL) {
if (pt->win == w)
break;
prev = pt;
pt = pt->next;
}
if (pt == NULL) {
warnx("Window not in list");
return;
}
if (prev == NULL)
winlist = pt->next;
else
prev->next = pt->next;
if (last == pt)
last = prev;
free(pt);
return;
}
void
win_free_list(void)
{
WInfo *pt = winlist, *tmp;
while (pt != NULL) {
tmp = pt->next;
if (pt->button) {
XDestroyWindow(dpy, pt->button);
}
free(pt);
pt = tmp;
}
}