wm.c
changeset 34 cd30cce52b78
parent 33 e90449e03167
equal deleted inserted replaced
33:e90449e03167 34:cd30cce52b78
    35 
    35 
    36 char stext[1024];
    36 char stext[1024];
    37 int tsel = Tdev; /* default tag */
    37 int tsel = Tdev; /* default tag */
    38 int screen, sx, sy, sw, sh, th;
    38 int screen, sx, sy, sw, sh, th;
    39 
    39 
    40 Brush brush = {0};
    40 DC dc = {0};
    41 Client *clients = NULL;
    41 Client *clients = NULL;
    42 Client *stack = NULL;
    42 Client *stack = NULL;
    43 
    43 
    44 static Bool other_wm_running;
    44 static Bool other_wm_running;
    45 static const char version[] =
    45 static const char version[] =
    46 	"gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    46 	"dwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    47 static int (*x_error_handler) (Display *, XErrorEvent *);
    47 static int (*x_error_handler) (Display *, XErrorEvent *);
    48 
    48 
    49 static void
    49 static void
    50 usage() {	error("usage: gridwm [-v]\n"); }
    50 usage() {	error("usage: dwm [-v]\n"); }
    51 
    51 
    52 static void
    52 static void
    53 scan_wins()
    53 scan_wins()
    54 {
    54 {
    55 	unsigned int i, num;
    55 	unsigned int i, num;
   147 			|| (error->request_code == X_ConfigureWindow
   147 			|| (error->request_code == X_ConfigureWindow
   148 				&& error->error_code == BadMatch)
   148 				&& error->error_code == BadMatch)
   149 			|| (error->request_code == X_GrabKey
   149 			|| (error->request_code == X_GrabKey
   150 				&& error->error_code == BadAccess))
   150 				&& error->error_code == BadAccess))
   151 		return 0;
   151 		return 0;
   152 	fprintf(stderr, "gridwm: fatal error: request code=%d, error code=%d\n",
   152 	fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
   153 			error->request_code, error->error_code);
   153 			error->request_code, error->error_code);
   154 	return x_error_handler(dpy, error); /* may call exit() */
   154 	return x_error_handler(dpy, error); /* may call exit() */
   155 }
   155 }
   156 
   156 
   157 /*
   157 /*
   201 		}
   201 		}
   202 	}
   202 	}
   203 
   203 
   204 	dpy = XOpenDisplay(0);
   204 	dpy = XOpenDisplay(0);
   205 	if(!dpy)
   205 	if(!dpy)
   206 		error("gridwm: cannot connect X server\n");
   206 		error("dwm: cannot connect X server\n");
   207 
   207 
   208 	screen = DefaultScreen(dpy);
   208 	screen = DefaultScreen(dpy);
   209 	root = RootWindow(dpy, screen);
   209 	root = RootWindow(dpy, screen);
   210 
   210 
   211 	/* check if another WM is already running */
   211 	/* check if another WM is already running */
   214 	/* this causes an error if some other WM is running */
   214 	/* this causes an error if some other WM is running */
   215 	XSelectInput(dpy, root, SubstructureRedirectMask);
   215 	XSelectInput(dpy, root, SubstructureRedirectMask);
   216 	XFlush(dpy);
   216 	XFlush(dpy);
   217 
   217 
   218 	if(other_wm_running)
   218 	if(other_wm_running)
   219 		error("gridwm: another window manager is already running\n");
   219 		error("dwm: another window manager is already running\n");
   220 
   220 
   221 	sx = sy = 0;
   221 	sx = sy = 0;
   222 	sw = DisplayWidth(dpy, screen);
   222 	sw = DisplayWidth(dpy, screen);
   223 	sh = DisplayHeight(dpy, screen);
   223 	sh = DisplayHeight(dpy, screen);
   224 	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
   224 	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
   242 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
   242 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
   243 
   243 
   244 	update_keys();
   244 	update_keys();
   245 
   245 
   246 	/* style */
   246 	/* style */
   247 	loadcolors(screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR);
   247 	initcolors(BGCOLOR, FGCOLOR, BORDERCOLOR);
   248 	loadfont(&brush.font, FONT);
   248 	initfont(&dc.font, FONT);
   249 
   249 
   250 	th = texth(&brush.font);
   250 	th = texth(&dc.font);
   251 
   251 
   252 	brush.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen));
   252 	dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen));
   253 	brush.gc = XCreateGC(dpy, root, 0, 0);
   253 	dc.gc = XCreateGC(dpy, root, 0, 0);
   254 
   254 
   255 	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
   255 	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
   256 					| LeaveWindowMask;
   256 					| LeaveWindowMask;
   257 	wa.cursor = cursor[CurNormal];
   257 	wa.cursor = cursor[CurNormal];
   258 	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   258 	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   259 
   259 
   260 	arrange = grid;
       
   261 	scan_wins();
   260 	scan_wins();
   262 
   261 
   263 	while(running) {
   262 	while(running) {
   264 		XNextEvent(dpy, &ev);
   263 		XNextEvent(dpy, &ev);
   265 		if(handler[ev.type])
   264 		if(handler[ev.type])