main.c
changeset 57 f005d46462e8
parent 52 d18f6dd0cf23
child 58 1269bd127551
equal deleted inserted replaced
56:b72b7086c385 57:f005d46462e8
     4  */
     4  */
     5 
     5 
     6 #include <stdarg.h>
     6 #include <stdarg.h>
     7 #include <stdio.h>
     7 #include <stdio.h>
     8 #include <stdlib.h>
     8 #include <stdlib.h>
       
     9 #include <string.h>
     9 
    10 
    10 #include <X11/cursorfont.h>
    11 #include <X11/cursorfont.h>
    11 #include <X11/Xatom.h>
    12 #include <X11/Xatom.h>
    12 #include <X11/Xproto.h>
    13 #include <X11/Xproto.h>
    13 
    14 
    32 Cursor cursor[CurLast];
    33 Cursor cursor[CurLast];
    33 Bool running = True;
    34 Bool running = True;
    34 Bool issel;
    35 Bool issel;
    35 
    36 
    36 int tsel = Tdev; /* default tag */
    37 int tsel = Tdev; /* default tag */
    37 int screen, sx, sy, sw, sh, mw, th;
    38 int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
       
    39 char stext[1024];
    38 
    40 
    39 DC dc = {0};
    41 DC dc = {0};
    40 Client *clients = NULL;
    42 Client *clients = NULL;
    41 Client *sel = NULL;
    43 Client *sel = NULL;
    42 
    44 
    43 static Bool other_wm_running;
    45 static Bool other_wm_running;
    44 static const char version[] =
    46 static const char version[] =
    45 	"dwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    47 	"dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    46 static int (*x_error_handler) (Display *, XErrorEvent *);
    48 static int (*x_error_handler) (Display *, XErrorEvent *);
    47 
    49 
    48 static void
    50 static void
    49 usage() {	error("usage: dwm [-v]\n"); }
    51 usage() {	error("usage: dwm [-v]\n"); }
    50 
    52 
   217 	XFlush(dpy);
   219 	XFlush(dpy);
   218 
   220 
   219 	if(other_wm_running)
   221 	if(other_wm_running)
   220 		error("dwm: another window manager is already running\n");
   222 		error("dwm: another window manager is already running\n");
   221 
   223 
   222 	sx = sy = 0;
       
   223 	sw = DisplayWidth(dpy, screen);
       
   224 	sh = DisplayHeight(dpy, screen);
       
   225 	mw = (sw * MASTERW) / 100;
       
   226 	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
       
   227 
       
   228 	XSetErrorHandler(0);
   224 	XSetErrorHandler(0);
   229 	x_error_handler = XSetErrorHandler(error_handler);
   225 	x_error_handler = XSetErrorHandler(error_handler);
   230 
   226 
   231 	/* init atoms */
   227 	/* init atoms */
   232 	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
   228 	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
   233 	wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
   229 	wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
   234 	net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
   230 	net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
   235 	net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
   231 	net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
   236 
       
   237 	XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
   232 	XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
   238 			PropModeReplace, (unsigned char *) net_atom, NetLast);
   233 			PropModeReplace, (unsigned char *) net_atom, NetLast);
   239 
       
   240 
   234 
   241 	/* init cursors */
   235 	/* init cursors */
   242 	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
   236 	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
   243 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
   237 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
   244 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
   238 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
   249 	dc.bg = initcolor(BGCOLOR);
   243 	dc.bg = initcolor(BGCOLOR);
   250 	dc.fg = initcolor(FGCOLOR);
   244 	dc.fg = initcolor(FGCOLOR);
   251 	dc.border = initcolor(BORDERCOLOR);
   245 	dc.border = initcolor(BORDERCOLOR);
   252 	initfont(FONT);
   246 	initfont(FONT);
   253 
   247 
   254 	th = dc.font.height + 4;
   248 	sx = sy = 0;
   255 
   249 	sw = DisplayWidth(dpy, screen);
   256 	dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen));
   250 	sh = DisplayHeight(dpy, screen);
   257 	dc.gc = XCreateGC(dpy, root, 0, 0);
   251 	mw = (sw * MASTERW) / 100;
       
   252 
       
   253 	wa.override_redirect = 1;
       
   254 	wa.background_pixmap = ParentRelative;
       
   255 	wa.event_mask = ExposureMask;
       
   256 
       
   257 	bx = by = 0;
       
   258 	bw = sw;
       
   259 	dc.h = bh = dc.font.height + 4;
       
   260 	barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
       
   261 			CopyFromParent, DefaultVisual(dpy, screen),
       
   262 			CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
       
   263 	XDefineCursor(dpy, barwin, cursor[CurNormal]);
       
   264 	XMapRaised(dpy, barwin);
       
   265 
       
   266 	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
   258 
   267 
   259 	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
   268 	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
   260 					| LeaveWindowMask;
   269 					| LeaveWindowMask;
   261 	wa.cursor = cursor[CurNormal];
   270 	wa.cursor = cursor[CurNormal];
       
   271 
   262 	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   272 	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   263 
   273 
       
   274 	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
       
   275 	dc.gc = XCreateGC(dpy, root, 0, 0);
       
   276 
       
   277 	strcpy(stext, "dwm-"VERSION);
   264 	scan_wins();
   278 	scan_wins();
       
   279 	draw_bar();
   265 
   280 
   266 	while(running) {
   281 	while(running) {
   267 		XNextEvent(dpy, &ev);
   282 		XNextEvent(dpy, &ev);
   268 		if(handler[ev.type])
   283 		if(handler[ev.type])
   269 			(handler[ev.type])(&ev); /* call handler */
   284 			(handler[ev.type])(&ev); /* call handler */