summaryrefslogtreecommitdiff
path: root/patch/bar_anybar.c
blob: d9bdb2712a70177483e26764c8b508734d8d291c (plain)
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
void
managealtbar(Window win, XWindowAttributes *wa)
{
	Monitor *m;
	Bar *bar;
	int i = 0;
	if (!(m = recttomon(wa->x, wa->y, wa->width, wa->height)))
		return;
	for (bar = m->bar; bar && bar->win && bar->next; bar = bar->next); // find last bar
	if (!bar) {
		bar = m->bar = ecalloc(1, sizeof(Bar));
		bar->topbar = topbar;
	} else if (bar && bar->win) {
		i = bar->idx + 1;
		bar->next = ecalloc(1, sizeof(Bar));
		#if BAR_ANYBAR_TOP_AND_BOTTOM_BARS_PATCH
		bar->next->topbar = !bar->topbar;
		#else
		bar->next->topbar = topbar;
		#endif // BAR_ANYBAR_TOP_AND_BOTTOM_BARS_PATCH
		bar = bar->next;
	}
	bar->external = 1;
	bar->showbar = 1;
	bar->mon = m;
	bar->idx = i;
	bar->borderpx = 0;
	bar->win = win;
	bar->bw = wa->width;
	bar->bh = wa->height;
	updatebarpos(m);
	arrange(m);
	XSelectInput(dpy, win, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
	XMapWindow(dpy, win);
	XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh);
	arrange(selmon);
	XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
		(unsigned char *) &win, 1);
}

void
spawnbar()
{
	if (*altbarcmd)
		system(altbarcmd);
}

void
unmanagealtbar(Window w)
{
	Monitor *m = wintomon(w);
	Bar *bar, *next, *prev = NULL;

	if (!m)
		return;

	for (bar = m->bar; bar && bar->win; bar = next) {
		next = bar->next;
		if (bar->win == w) {
			if (prev)
				prev->next = next;
			else
				m->bar = next;
			free(bar);
			break;
		}
		prev = bar;
	}
	updatebarpos(m);
	arrange(m);
}

int
wmclasscontains(Window win, const char *class, const char *name)
{
	XClassHint ch = { NULL, NULL };
	int res = 1;

	if (XGetClassHint(dpy, win, &ch)) {
		if (ch.res_name && strstr(ch.res_name, name) == NULL)
			res = 0;
		if (ch.res_class && strstr(ch.res_class, class) == NULL)
			res = 0;
	} else
		res = 0;

	if (ch.res_class)
		XFree(ch.res_class);
	if (ch.res_name)
		XFree(ch.res_name);

	return res;
}