main.c
changeset 291 8e6e0aa5e2ae
parent 281 0d0444d32c59
child 292 4aa632b6ba66
equal deleted inserted replaced
290:5c3b8c5286f5 291:8e6e0aa5e2ae
     9 #include <stdlib.h>
     9 #include <stdlib.h>
    10 #include <string.h>
    10 #include <string.h>
    11 #include <unistd.h>
    11 #include <unistd.h>
    12 #include <sys/select.h>
    12 #include <sys/select.h>
    13 #include <X11/cursorfont.h>
    13 #include <X11/cursorfont.h>
       
    14 #include <X11/keysym.h>
    14 #include <X11/Xatom.h>
    15 #include <X11/Xatom.h>
    15 #include <X11/Xproto.h>
    16 #include <X11/Xproto.h>
    16 
    17 
    17 /* static */
    18 /* static */
    18 
    19 
    83 /* extern */
    84 /* extern */
    84 
    85 
    85 char stext[1024];
    86 char stext[1024];
    86 Bool *seltag;
    87 Bool *seltag;
    87 int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
    88 int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
    88 unsigned int ntags;
    89 unsigned int ntags, numlockmask;
    89 Atom wmatom[WMLast], netatom[NetLast];
    90 Atom wmatom[WMLast], netatom[NetLast];
    90 Bool running = True;
    91 Bool running = True;
    91 Bool issel = True;
    92 Bool issel = True;
    92 Client *clients = NULL;
    93 Client *clients = NULL;
    93 Client *sel = NULL;
    94 Client *sel = NULL;
   160 }
   161 }
   161 
   162 
   162 int
   163 int
   163 main(int argc, char *argv[])
   164 main(int argc, char *argv[])
   164 {
   165 {
   165 	int i, xfd;
   166 	int i, j, xfd;
   166 	unsigned int mask;
   167 	unsigned int mask;
   167 	fd_set rd;
   168 	fd_set rd;
   168 	Bool readin = True;
   169 	Bool readin = True;
   169 	Window w;
   170 	Window w;
   170 	XEvent ev;
   171 	XEvent ev;
       
   172 	XModifierKeymap *modmap;
   171 	XSetWindowAttributes wa;
   173 	XSetWindowAttributes wa;
   172 
   174 
   173 	if(argc == 2 && !strncmp("-v", argv[1], 3)) {
   175 	if(argc == 2 && !strncmp("-v", argv[1], 3)) {
   174 		fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
   176 		fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
   175 		exit(EXIT_SUCCESS);
   177 		exit(EXIT_SUCCESS);
   209 	/* init cursors */
   211 	/* init cursors */
   210 	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
   212 	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
   211 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
   213 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
   212 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
   214 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
   213 
   215 
   214 	wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
   216 	modmap = XGetModifierMapping(dpy);
       
   217 	for (i = 0; i < 8; i++) {
       
   218 		for (j = 0; j < modmap->max_keypermod; j++) {
       
   219 			if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
       
   220 				numlockmask = (1 << i);
       
   221 		}
       
   222 	}
       
   223 	XFree(modmap);
       
   224 
       
   225 	wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask;
   215 	wa.cursor = cursor[CurNormal];
   226 	wa.cursor = cursor[CurNormal];
   216 	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   227 	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   217 
   228 
   218 	grabkeys();
   229 	grabkeys();
   219 	initrregs();
   230 	initrregs();
   231 	sx = sy = 0;
   242 	sx = sy = 0;
   232 	sw = DisplayWidth(dpy, screen);
   243 	sw = DisplayWidth(dpy, screen);
   233 	sh = DisplayHeight(dpy, screen);
   244 	sh = DisplayHeight(dpy, screen);
   234 	mw = (sw * MASTERW) / 100;
   245 	mw = (sw * MASTERW) / 100;
   235 
   246 
       
   247 	bx = by = 0;
       
   248 	bw = sw;
       
   249 	dc.h = bh = dc.font.height + 4;
   236 	wa.override_redirect = 1;
   250 	wa.override_redirect = 1;
   237 	wa.background_pixmap = ParentRelative;
   251 	wa.background_pixmap = ParentRelative;
   238 	wa.event_mask = ButtonPressMask | ExposureMask;
   252 	wa.event_mask = ButtonPressMask | ExposureMask;
   239 
       
   240 	bx = by = 0;
       
   241 	bw = sw;
       
   242 	dc.h = bh = dc.font.height + 4;
       
   243 	barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
   253 	barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
   244 			CopyFromParent, DefaultVisual(dpy, screen),
   254 			CopyFromParent, DefaultVisual(dpy, screen),
   245 			CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
   255 			CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
   246 	XDefineCursor(dpy, barwin, cursor[CurNormal]);
   256 	XDefineCursor(dpy, barwin, cursor[CurNormal]);
   247 	XMapRaised(dpy, barwin);
   257 	XMapRaised(dpy, barwin);
   256 
   266 
   257 	scan();
   267 	scan();
   258 
   268 
   259 	/* main event loop, also reads status text from stdin */
   269 	/* main event loop, also reads status text from stdin */
   260 	XSync(dpy, False);
   270 	XSync(dpy, False);
       
   271 	goto XLoop;
   261 	while(running) {
   272 	while(running) {
   262 		FD_ZERO(&rd);
   273 		FD_ZERO(&rd);
   263 		if(readin)
   274 		if(readin)
   264 			FD_SET(STDIN_FILENO, &rd);
   275 			FD_SET(STDIN_FILENO, &rd);
   265 		FD_SET(xfd, &rd);
   276 		FD_SET(xfd, &rd);
   276 				else 
   287 				else 
   277 					strcpy(stext, "broken pipe");
   288 					strcpy(stext, "broken pipe");
   278 				drawstatus();
   289 				drawstatus();
   279 			}
   290 			}
   280 			if(FD_ISSET(xfd, &rd)) {
   291 			if(FD_ISSET(xfd, &rd)) {
       
   292 XLoop:
   281 				while(XPending(dpy)) {
   293 				while(XPending(dpy)) {
   282 					XNextEvent(dpy, &ev);
   294 					XNextEvent(dpy, &ev);
   283 					if(handler[ev.type])
   295 					if(handler[ev.type])
   284 						(handler[ev.type])(&ev); /* call handler */
   296 						(handler[ev.type])(&ev); /* call handler */
   285 				}
   297 				}