wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

createwindow_visual.c (1290B)


      1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
      2  * See LICENSE file for license details.
      3  */
      4 #include "../x11.h"
      5 #include <string.h>
      6 #include <unistd.h>
      7 
      8 static char hostname[HOST_NAME_MAX + 1];
      9 static long pid;
     10 
     11 Window*
     12 createwindow_visual(Window *parent, Rectangle r,
     13 		    int depth, Visual *vis, uint class,
     14 		    WinAttr *wa, int valmask) {
     15 	Window *w;
     16 	WinAttr wa_empty;
     17 
     18 	assert(parent->type == WWindow);
     19 
     20 	if(wa == nil)
     21 		wa = &wa_empty;
     22 
     23 	w = emallocz(sizeof *w);
     24 	w->visual = vis;
     25 	w->type = WWindow;
     26 	w->parent = parent;
     27 	if(valmask & CWColormap)
     28 		w->colormap = wa->colormap;
     29 	if(valmask & CWEventMask)
     30 		w->eventmask = wa->event_mask;
     31 
     32 	w->xid = XCreateWindow(display, parent->xid, r.min.x, r.min.y, Dx(r), Dy(r),
     33 				0 /* border */, depth, class, vis, valmask, wa);
     34 #if 0
     35 	print("createwindow_visual(%W, %R, %d, %p, %ud, %p, %x) = %W\n",
     36 			parent, r, depth, vis, class, wa, valmask, w);
     37 #endif
     38 	if(class != InputOnly)
     39 		w->gc = XCreateGC(display, w->xid, 0, nil);
     40 
     41 	if(pid == 0)
     42 		pid = getpid();
     43 	changeprop_long(w, "_NET_WM_PID", "CARDINAL", &pid, 1);
     44 
     45 	if(!hostname[0])
     46 		gethostname(hostname, sizeof(hostname) - 1);
     47 	if(hostname[0])
     48 		changeprop_char(w, "WM_CLIENT_MACHINE", "STRING", hostname, strlen(hostname));
     49 
     50 	w->r = r;
     51 	w->depth = depth;
     52 	return w;
     53 }