-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathxnotif.c
146 lines (133 loc) · 3.52 KB
/
xnotif.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
145
146
#include "shod.h"
/* create notification window */
static void
notifnew(Window win, int w, int h)
{
struct Notification *notif;
notif = emalloc(sizeof(*notif));
*notif = (struct Notification){
.w = w + 2 * config.borderwidth,
.h = h + 2 * config.borderwidth,
.pix = None,
.obj.class = notif_class,
.obj.win = win,
};
TAILQ_INSERT_TAIL(&wm.notifq, (struct Object *)notif, entry);
notif->frame = createframe((XRectangle){0, 0, 1, 1});
XReparentWindow(dpy, notif->obj.win, notif->frame, 0, 0);
XMapWindow(dpy, notif->obj.win);
}
/* decorate notification */
void
notifdecorate(struct Notification *n)
{
/* (re)create pixmap */
if (n->pw != n->w || n->ph != n->h || n->pix == None) {
if (n->pix != None)
XFreePixmap(dpy, n->pix);
n->pix = XCreatePixmap(dpy, n->frame, n->w, n->h, depth);
}
n->pw = n->w;
n->ph = n->h;
drawborders(n->pix, n->w, n->h, FOCUSED);
drawcommit(n->pix, n->frame);
}
/* place notifications */
void
notifplace(void)
{
struct Object *n;
struct Notification *notif;
int x, y, h;
h = 0;
TAILQ_FOREACH(n, &wm.notifq, entry) {
notif = (struct Notification *)n;
x = TAILQ_FIRST(&wm.monq)->wx;
y = TAILQ_FIRST(&wm.monq)->wy;
switch (config.notifgravity[0]) {
case 'N':
switch (config.notifgravity[1]) {
case 'W':
break;
case 'E':
x += TAILQ_FIRST(&wm.monq)->ww - notif->w;
break;
default:
x += (TAILQ_FIRST(&wm.monq)->ww - notif->w) / 2;
break;
}
break;
case 'S':
switch(config.notifgravity[1]) {
case 'W':
y += TAILQ_FIRST(&wm.monq)->wh - notif->h;
break;
case 'E':
x += TAILQ_FIRST(&wm.monq)->ww - notif->w;
y += TAILQ_FIRST(&wm.monq)->wh - notif->h;
break;
default:
x += (TAILQ_FIRST(&wm.monq)->ww - notif->w) / 2;
y += TAILQ_FIRST(&wm.monq)->wh - notif->h;
break;
}
break;
case 'W':
y += (TAILQ_FIRST(&wm.monq)->wh - notif->h) / 2;
break;
case 'C':
x += (TAILQ_FIRST(&wm.monq)->ww - notif->w) / 2;
y += (TAILQ_FIRST(&wm.monq)->wh - notif->h) / 2;
break;
case 'E':
x += TAILQ_FIRST(&wm.monq)->ww - notif->w;
y += (TAILQ_FIRST(&wm.monq)->wh - notif->h) / 2;
break;
default:
x += TAILQ_FIRST(&wm.monq)->ww - notif->w;
break;
}
if (config.notifgravity[0] == 'S')
y -= h;
else
y += h;
h += notif->h + config.notifgap + config.borderwidth * 2;
XMoveResizeWindow(dpy, notif->frame, x, y, notif->w, notif->h);
XMoveResizeWindow(dpy, notif->obj.win, config.borderwidth, config.borderwidth, notif->w - 2 * config.borderwidth, notif->h - 2 * config.borderwidth);
XMapWindow(dpy, notif->frame);
if (notif->pw != notif->w || notif->ph != notif->h) {
notifdecorate(notif);
}
winnotify(notif->obj.win, x + config.borderwidth, y + config.borderwidth, notif->w - 2 * config.borderwidth, notif->h - 2 * config.borderwidth);
}
}
static void
manage(struct Tab *tab, struct Monitor *mon, int desk, Window win, Window leader, XRectangle rect, enum State state)
{
(void)tab;
(void)mon;
(void)desk;
(void)leader;
(void)state;
notifnew(win, rect.width, rect.height);
notifplace();
}
static void
unmanage(struct Object *obj)
{
struct Notification *notif;
notif = (struct Notification *)obj;
TAILQ_REMOVE(&wm.notifq, (struct Object *)notif, entry);
if (notif->pix != None)
XFreePixmap(dpy, notif->pix);
XReparentWindow(dpy, notif->obj.win, root, 0, 0);
XDestroyWindow(dpy, notif->frame);
free(notif);
notifplace();
}
struct Class *notif_class = &(struct Class){
.type = TYPE_NOTIFICATION,
.setstate = NULL,
.manage = manage,
.unmanage = unmanage,
};