summaryrefslogtreecommitdiff
path: root/lib/libstuff/x11/windows/createwindow_visual.c
blob: 32bd3d61bd404e1b019b44a5a519ad4fd6f3c177 (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
/* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
 * See LICENSE file for license details.
 */
#include "../x11.h"
#include <string.h>
#include <unistd.h>

#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 255
#endif

static char hostname[HOST_NAME_MAX + 1];
static long pid;

Window*
createwindow_visual(Window *parent, Rectangle r,
		    int depth, Visual *vis, uint class,
		    WinAttr *wa, int valmask) {
	Window *w;
	WinAttr wa_empty;

	assert(parent->type == WWindow);

	if(wa == nil)
		wa = &wa_empty;

	w = emallocz(sizeof *w);
	w->visual = vis;
	w->type = WWindow;
	w->parent = parent;
	if(valmask & CWColormap)
		w->colormap = wa->colormap;
	if(valmask & CWEventMask)
		w->eventmask = wa->event_mask;

	w->xid = XCreateWindow(display, parent->xid, r.min.x, r.min.y, Dx(r), Dy(r),
				0 /* border */, depth, class, vis, valmask, wa);
#if 0
	print("createwindow_visual(%W, %R, %d, %p, %ud, %p, %x) = %W\n",
			parent, r, depth, vis, class, wa, valmask, w);
#endif
	if(class != InputOnly)
		w->gc = XCreateGC(display, w->xid, 0, nil);

	if(pid == 0)
		pid = getpid();
	changeprop_long(w, "_NET_WM_PID", "CARDINAL", &pid, 1);

	if(!hostname[0])
		gethostname(hostname, sizeof(hostname) - 1);
	if(hostname[0])
		changeprop_char(w, "WM_CLIENT_MACHINE", "STRING", hostname, strlen(hostname));

	w->r = r;
	w->depth = depth;
	return w;
}