dwm.c
changeset 1228 b5b7a1d8dc4f
parent 1227 1f0e2de78c35
child 1229 818892d66dc4
equal deleted inserted replaced
1227:1f0e2de78c35 1228:b5b7a1d8dc4f
    59 enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
    59 enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
    60 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
    60 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
    61 
    61 
    62 /* typedefs */
    62 /* typedefs */
    63 typedef unsigned int uint;
    63 typedef unsigned int uint;
       
    64 typedef unsigned long ulong;
    64 typedef struct Client Client;
    65 typedef struct Client Client;
    65 struct Client {
    66 struct Client {
    66 	char name[256];
    67 	char name[256];
    67 	int x, y, w, h;
    68 	int x, y, w, h;
    68 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
    69 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
    77 	Window win;
    78 	Window win;
    78 };
    79 };
    79 
    80 
    80 typedef struct {
    81 typedef struct {
    81 	int x, y, w, h;
    82 	int x, y, w, h;
    82 	unsigned long norm[ColLast];
    83 	ulong norm[ColLast];
    83 	unsigned long sel[ColLast];
    84 	ulong sel[ColLast];
    84 	Drawable drawable;
    85 	Drawable drawable;
    85 	GC gc;
    86 	GC gc;
    86 	struct {
    87 	struct {
    87 		int ascent;
    88 		int ascent;
    88 		int descent;
    89 		int descent;
    91 		XFontStruct *xfont;
    92 		XFontStruct *xfont;
    92 	} font;
    93 	} font;
    93 } DC; /* draw context */
    94 } DC; /* draw context */
    94 
    95 
    95 typedef struct {
    96 typedef struct {
    96 	unsigned long mod;
    97 	ulong mod;
    97 	KeySym keysym;
    98 	KeySym keysym;
    98 	void (*func)(const void *arg);
    99 	void (*func)(const void *arg);
    99 	const void *arg;
   100 	const void *arg;
   100 } Key;
   101 } Key;
   101 
   102 
   127 void configurerequest(XEvent *e);
   128 void configurerequest(XEvent *e);
   128 void destroynotify(XEvent *e);
   129 void destroynotify(XEvent *e);
   129 void detach(Client *c);
   130 void detach(Client *c);
   130 void detachstack(Client *c);
   131 void detachstack(Client *c);
   131 void drawbar(void);
   132 void drawbar(void);
   132 void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
   133 void drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]);
   133 void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
   134 void drawtext(const char *text, ulong col[ColLast], Bool invert);
   134 void *emallocz(uint size);
   135 void *emallocz(uint size);
   135 void enternotify(XEvent *e);
   136 void enternotify(XEvent *e);
   136 void eprint(const char *errstr, ...);
   137 void eprint(const char *errstr, ...);
   137 void expose(XEvent *e);
   138 void expose(XEvent *e);
   138 void focus(Client *c);
   139 void focus(Client *c);
   139 void focusin(XEvent *e);
   140 void focusin(XEvent *e);
   140 void focusnext(const void *arg);
   141 void focusnext(const void *arg);
   141 void focusprev(const void *arg);
   142 void focusprev(const void *arg);
   142 Client *getclient(Window w);
   143 Client *getclient(Window w);
   143 unsigned long getcolor(const char *colstr);
   144 ulong getcolor(const char *colstr);
   144 long getstate(Window w);
   145 long getstate(Window w);
   145 Bool gettextprop(Window w, Atom atom, char *text, uint size);
   146 Bool gettextprop(Window w, Atom atom, char *text, uint size);
   146 void grabbuttons(Client *c, Bool focused);
   147 void grabbuttons(Client *c, Bool focused);
   147 void grabkeys(void);
   148 void grabkeys(void);
   148 void initfont(const char *fontstr);
   149 void initfont(const char *fontstr);
   537 	XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
   538 	XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
   538 	XSync(dpy, False);
   539 	XSync(dpy, False);
   539 }
   540 }
   540 
   541 
   541 void
   542 void
   542 drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
   543 drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]) {
   543 	int x;
   544 	int x;
   544 	XGCValues gcv;
   545 	XGCValues gcv;
   545 	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
   546 	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
   546 
   547 
   547 	gcv.foreground = col[invert ? ColBG : ColFG];
   548 	gcv.foreground = col[invert ? ColBG : ColFG];
   558 		XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
   559 		XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
   559 	}
   560 	}
   560 }
   561 }
   561 
   562 
   562 void
   563 void
   563 drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
   564 drawtext(const char *text, ulong col[ColLast], Bool invert) {
   564 	int x, y, w, h;
   565 	int x, y, w, h;
   565 	uint len, olen;
   566 	uint len, olen;
   566 	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
   567 	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
   567 	char buf[256];
   568 	char buf[256];
   568 
   569 
   705 
   706 
   706 	for(c = clients; c && c->win != w; c = c->next);
   707 	for(c = clients; c && c->win != w; c = c->next);
   707 	return c;
   708 	return c;
   708 }
   709 }
   709 
   710 
   710 unsigned long
   711 ulong
   711 getcolor(const char *colstr) {
   712 getcolor(const char *colstr) {
   712 	Colormap cmap = DefaultColormap(dpy, screen);
   713 	Colormap cmap = DefaultColormap(dpy, screen);
   713 	XColor color;
   714 	XColor color;
   714 
   715 
   715 	if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
   716 	if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
   720 long
   721 long
   721 getstate(Window w) {
   722 getstate(Window w) {
   722 	int format, status;
   723 	int format, status;
   723 	long result = -1;
   724 	long result = -1;
   724 	unsigned char *p = NULL;
   725 	unsigned char *p = NULL;
   725 	unsigned long n, extra;
   726 	ulong n, extra;
   726 	Atom real;
   727 	Atom real;
   727 
   728 
   728 	status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
   729 	status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
   729 			&real, &format, &n, &extra, (unsigned char **)&p);
   730 			&real, &format, &n, &extra, (unsigned char **)&p);
   730 	if(status != Success)
   731 	if(status != Success)