main.c
changeset 74 5370ef170cc9
parent 73 c2ddb9dbbd10
child 75 f08271b7cb20
equal deleted inserted replaced
73:c2ddb9dbbd10 74:5370ef170cc9
    44 Client *sel = NULL;
    44 Client *sel = NULL;
    45 
    45 
    46 static Bool other_wm_running;
    46 static Bool other_wm_running;
    47 static const char version[] =
    47 static const char version[] =
    48 	"dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    48 	"dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    49 static int (*x_error_handler) (Display *, XErrorEvent *);
    49 static int (*x_xerror) (Display *, XErrorEvent *);
    50 
    50 
    51 static void
    51 static void
    52 usage() {	error("usage: dwm [-v]\n"); }
    52 usage() {	error("usage: dwm [-v]\n"); }
    53 
    53 
    54 static void
    54 static void
    92 	}
    92 	}
    93 	return res;
    93 	return res;
    94 }
    94 }
    95 
    95 
    96 int
    96 int
    97 win_proto(Window w)
    97 proto(Window w)
    98 {
    98 {
    99 	unsigned char *protocols;
    99 	unsigned char *protocols;
   100 	long res;
   100 	long res;
   101 	int protos = 0;
   101 	int protos = 0;
   102 	int i;
   102 	int i;
   112 	free((char *) protocols);
   112 	free((char *) protocols);
   113 	return protos;
   113 	return protos;
   114 }
   114 }
   115 
   115 
   116 void
   116 void
   117 send_message(Window w, Atom a, long value)
   117 sendevent(Window w, Atom a, long value)
   118 {
   118 {
   119 	XEvent e;
   119 	XEvent e;
   120 
   120 
   121 	e.type = ClientMessage;
   121 	e.type = ClientMessage;
   122 	e.xclient.window = w;
   122 	e.xclient.window = w;
   133  * those cases are ignored (especially on UnmapNotify's).
   133  * those cases are ignored (especially on UnmapNotify's).
   134  * Other types of errors call Xlib's default error handler, which
   134  * Other types of errors call Xlib's default error handler, which
   135  * calls exit().
   135  * calls exit().
   136  */
   136  */
   137 int
   137 int
   138 error_handler(Display *dpy, XErrorEvent *error)
   138 xerror(Display *dpy, XErrorEvent *error)
   139 {
   139 {
   140 	if(error->error_code == BadWindow
   140 	if(error->error_code == BadWindow
   141 			|| (error->request_code == X_SetInputFocus
   141 			|| (error->request_code == X_SetInputFocus
   142 				&& error->error_code == BadMatch)
   142 				&& error->error_code == BadMatch)
   143 			|| (error->request_code == X_PolyText8
   143 			|| (error->request_code == X_PolyText8
   151 			|| (error->request_code == X_GrabKey
   151 			|| (error->request_code == X_GrabKey
   152 				&& error->error_code == BadAccess))
   152 				&& error->error_code == BadAccess))
   153 		return 0;
   153 		return 0;
   154 	fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
   154 	fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
   155 			error->request_code, error->error_code);
   155 			error->request_code, error->error_code);
   156 	return x_error_handler(dpy, error); /* may call exit() */
   156 	return x_xerror(dpy, error); /* may call exit() */
   157 }
   157 }
   158 
   158 
   159 /*
   159 /*
   160  * Startup Error handler to check if another window manager
   160  * Startup Error handler to check if another window manager
   161  * is already running.
   161  * is already running.
   162  */
   162  */
   163 static int
   163 static int
   164 startup_error_handler(Display *dpy, XErrorEvent *error)
   164 startup_xerror(Display *dpy, XErrorEvent *error)
   165 {
   165 {
   166 	other_wm_running = True;
   166 	other_wm_running = True;
   167 	return -1;
   167 	return -1;
   168 }
   168 }
   169 
   169 
   213 	screen = DefaultScreen(dpy);
   213 	screen = DefaultScreen(dpy);
   214 	root = RootWindow(dpy, screen);
   214 	root = RootWindow(dpy, screen);
   215 
   215 
   216 	/* check if another WM is already running */
   216 	/* check if another WM is already running */
   217 	other_wm_running = False;
   217 	other_wm_running = False;
   218 	XSetErrorHandler(startup_error_handler);
   218 	XSetErrorHandler(startup_xerror);
   219 	/* this causes an error if some other WM is running */
   219 	/* this causes an error if some other WM is running */
   220 	XSelectInput(dpy, root, SubstructureRedirectMask);
   220 	XSelectInput(dpy, root, SubstructureRedirectMask);
   221 	XFlush(dpy);
   221 	XFlush(dpy);
   222 
   222 
   223 	if(other_wm_running)
   223 	if(other_wm_running)
   224 		error("dwm: another window manager is already running\n");
   224 		error("dwm: another window manager is already running\n");
   225 
   225 
   226 	XSetErrorHandler(0);
   226 	XSetErrorHandler(0);
   227 	x_error_handler = XSetErrorHandler(error_handler);
   227 	x_xerror = XSetErrorHandler(xerror);
   228 
   228 
   229 	/* init atoms */
   229 	/* init atoms */
   230 	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
   230 	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
   231 	wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
   231 	wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
   232 	net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
   232 	net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
   240 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
   240 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
   241 
   241 
   242 	grabkeys();
   242 	grabkeys();
   243 
   243 
   244 	/* style */
   244 	/* style */
   245 	dc.bg = initcolor(BGCOLOR);
   245 	dc.bg = getcolor(BGCOLOR);
   246 	dc.fg = initcolor(FGCOLOR);
   246 	dc.fg = getcolor(FGCOLOR);
   247 	dc.border = initcolor(BORDERCOLOR);
   247 	dc.border = getcolor(BORDERCOLOR);
   248 	initfont(FONT);
   248 	setfont(FONT);
   249 
   249 
   250 	sx = sy = 0;
   250 	sx = sy = 0;
   251 	sw = DisplayWidth(dpy, screen);
   251 	sw = DisplayWidth(dpy, screen);
   252 	sh = DisplayHeight(dpy, screen);
   252 	sh = DisplayHeight(dpy, screen);
   253 	mw = (sw * MASTERW) / 100;
   253 	mw = (sw * MASTERW) / 100;
   265 	XDefineCursor(dpy, barwin, cursor[CurNormal]);
   265 	XDefineCursor(dpy, barwin, cursor[CurNormal]);
   266 	XMapRaised(dpy, barwin);
   266 	XMapRaised(dpy, barwin);
   267 
   267 
   268 	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
   268 	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
   269 	dc.gc = XCreateGC(dpy, root, 0, 0);
   269 	dc.gc = XCreateGC(dpy, root, 0, 0);
   270 	draw_bar();
   270 	drawstatus();
   271 
   271 
   272 	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
   272 	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
   273 
   273 
   274 	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
   274 	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
   275 					| LeaveWindowMask;
   275 					| LeaveWindowMask;
   313 					if(i == '\n' || n >= sizeof(stext) - 1)
   313 					if(i == '\n' || n >= sizeof(stext) - 1)
   314 						break;
   314 						break;
   315 					stext[n++] = i;
   315 					stext[n++] = i;
   316 				}
   316 				}
   317 				stext[n] = 0;
   317 				stext[n] = 0;
   318 				draw_bar();
   318 				drawstatus();
   319 			}
   319 			}
   320 		}
   320 		}
   321 	}
   321 	}
   322 
   322 
   323 	cleanup();
   323 	cleanup();