about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--client.c50
-rw-r--r--config.mk4
-rw-r--r--dwm.h8
-rw-r--r--event.c8
-rw-r--r--main.c6
-rw-r--r--screen.c48
6 files changed, 23 insertions, 101 deletions
diff --git a/client.c b/client.c
index c03770b..9dd08b1 100644
--- a/client.c
+++ b/client.c
@@ -1,14 +1,11 @@
 /* See LICENSE file for copyright and license details. */
 #include "dwm.h"
 #include <stdlib.h>
-#include <string.h>
 #include <X11/Xatom.h>
 #include <X11/Xutil.h>
 
 /* static */
 
-static char buf[128];
-
 static void
 attachstack(Client *c) {
 	c->snext = stack;
@@ -102,10 +99,8 @@ void
 ban(Client *c) {
 	if(c->isbanned)
 		return;
-	XUnmapWindow(dpy, c->win);
-	setclientstate(c, IconicState);
+	XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
 	c->isbanned = True;
-	c->unmapped++;
 }
 
 void
@@ -181,21 +176,6 @@ killclient(const char *arg) {
 		XKillClient(dpy, sel->win);
 }
 
-Bool
-getprops(Client *c) {
-	unsigned int i;
-	Bool result = False;
-
-	if(gettextprop(c->win, dwmprops, buf, sizeof buf)) {
-		for(i = 0; i < ntags && i < sizeof buf - 1 && buf[i] != '\0'; i++)
-			if((c->tags[i] = buf[i] == '1'))
-				result = True;
-		if(i < sizeof buf - 1 && buf[i] != '\0')
-			c->isfloating = buf[i] == '1';
-	}
-	return result;
-}
-
 void
 manage(Window w, XWindowAttributes *wa) {
 	unsigned int i;
@@ -242,15 +222,14 @@ manage(Window w, XWindowAttributes *wa) {
 	if(t)
 		for(i = 0; i < ntags; i++)
 			c->tags[i] = t->tags[i];
-	if(!getprops(c))
-		applyrules(c);
+	applyrules(c);
 	if(!c->isfloating)
 		c->isfloating = (rettrans == Success) || c->isfixed;
-	setprops(c);
 	attach(c);
 	attachstack(c);
 	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
 	ban(c);
+	XMapWindow(dpy, c->win);
 	arrange();
 }
 
@@ -318,29 +297,15 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
 }
 
 void
-setprops(Client *c) {
-	unsigned int i;
-
-	for(i = 0; i < ntags && i < sizeof buf - 1; i++)
-		buf[i] = c->tags[i] ? '1' : '0';
-	if(i < sizeof buf - 1)
-		buf[i++] = c->isfloating ? '1' : '0';
-	buf[i] = '\0';
-	XChangeProperty(dpy, c->win, dwmprops, XA_STRING, 8,
-			PropModeReplace, (unsigned char *)buf, i);
-}
-
-void
 unban(Client *c) {
 	if(!c->isbanned)
 		return;
-	XMapWindow(dpy, c->win);
-	setclientstate(c, NormalState);
+	XMoveWindow(dpy, c->win, c->x, c->y);
 	c->isbanned = False;
 }
 
 void
-unmanage(Client *c, long state) {
+unmanage(Client *c) {
 	XWindowChanges wc;
 
 	wc.border_width = c->oldborder;
@@ -353,14 +318,13 @@ unmanage(Client *c, long state) {
 	if(sel == c)
 		focus(NULL);
 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
-	setclientstate(c, state);
+	setclientstate(c, WithdrawnState);
 	free(c->tags);
 	free(c);
 	XSync(dpy, False);
 	XSetErrorHandler(xerror);
 	XUngrabServer(dpy);
-	if(state != NormalState)
-		arrange();
+	arrange();
 }
 
 void
diff --git a/config.mk b/config.mk
index 320aea1..682bb41 100644
--- a/config.mk
+++ b/config.mk
@@ -20,8 +20,8 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
 # flags
 CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
 LDFLAGS = -s ${LIBS}
-#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
-#LDFLAGS = -g ${LIBS}
+CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
+LDFLAGS = -g ${LIBS}
 
 # Solaris
 #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
diff --git a/dwm.h b/dwm.h
index 0d55143..1a12322 100644
--- a/dwm.h
+++ b/dwm.h
@@ -48,7 +48,6 @@ struct Client {
 	int rx, ry, rw, rh; /* revert geometry */
 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
 	int minax, maxax, minay, maxay;
-	int unmapped;
 	long flags; 
 	unsigned int border, oldborder;
 	Bool isbanned, isfixed, ismax, isfloating;
@@ -81,7 +80,7 @@ extern int wax, way, wah, waw;			/* windowarea geometry */
 extern unsigned int bh, blw, bpos;		/* bar height, bar layout label width, bar position */
 extern unsigned int ntags, numlockmask;		/* number of tags, numlock mask */
 extern void (*handler[LASTEvent])(XEvent *);	/* event handler */
-extern Atom dwmprops, wmatom[WMLast], netatom[NetLast];
+extern Atom wmatom[WMLast], netatom[NetLast];
 extern Bool selscreen, *seltags;		/* seltags is array of Bool */
 extern Client *clients, *sel, *stack;		/* global client list and stack */
 extern Cursor cursor[CurLast];
@@ -96,13 +95,11 @@ void configure(Client *c);		/* send synthetic configure event */
 void detach(Client *c);			/* detaches c from global client list */
 void focus(Client *c);			/* focus c if visible && !NULL, or focus top visible */
 void killclient(const char *arg);	/* kill sel  nicely */
-Bool getprops(Client *c);		/* gets client properties */
 void manage(Window w, XWindowAttributes *wa);	/* manage new client */
 void resize(Client *c, int x, int y,
 		int w, int h, Bool sizehints);	/* resize with given coordinates c*/
-void setprops(Client *c);		/* sets client properties */
 void unban(Client *c);			/* unbans c */
-void unmanage(Client *c, long state);	/* unmanage c */
+void unmanage(Client *c);		/* unmanage c */
 void updatesizehints(Client *c);	/* update the size hint variables of c */
 void updatetitle(Client *c);		/* update the name of c */
 
@@ -131,7 +128,6 @@ void initlayouts(void);			/* initialize layout array */
 Bool isarrange(void (*func)());		/* returns True if func is the layout function in use */
 Bool isfloating(void);			/* returns True if floating layout is enabled */
 Bool isvisible(Client *c);		/* returns True if client is visible */
-void getdwmprops(void);			/* gets dwm properties */
 Client *nexttiled(Client *c);		/* returns tiled successor of c */
 void restack(void);			/* restores z layers of all clients */
 void setlayout(const char *arg);	/* sets layout, NULL means next layout */
diff --git a/event.c b/event.c
index b96aba9..9e83178 100644
--- a/event.c
+++ b/event.c
@@ -221,7 +221,7 @@ destroynotify(XEvent *e) {
 	XDestroyWindowEvent *ev = &e->xdestroywindow;
 
 	if((c = getclient(ev->window)))
-		unmanage(c, WithdrawnState);
+		unmanage(c);
 }
 
 static void
@@ -332,10 +332,8 @@ unmapnotify(XEvent *e) {
 	Client *c;
 	XUnmapEvent *ev = &e->xunmap;
 
-	if((c = getclient(ev->window)) && (ev->event == root)) {
-		if(ev->send_event || c->unmapped-- == 0)
-			unmanage(c, WithdrawnState);
-	}
+	if((c = getclient(ev->window)))
+		unmanage(c);
 }
 
 /* extern */
diff --git a/main.c b/main.c
index 79b301d..338fed4 100644
--- a/main.c
+++ b/main.c
@@ -20,7 +20,7 @@ int screen, sx, sy, sw, sh, wax, way, waw, wah;
 unsigned int bh, ntags;
 unsigned int bpos = BARPOS;
 unsigned int numlockmask = 0;
-Atom dwmprops, wmatom[WMLast], netatom[NetLast];
+Atom wmatom[WMLast], netatom[NetLast];
 Bool *seltags;
 Bool selscreen = True;
 Client *clients = NULL;
@@ -42,7 +42,7 @@ cleanup(void) {
 	close(STDIN_FILENO);
 	while(stack) {
 		unban(stack);
-		unmanage(stack, NormalState);
+		unmanage(stack);
 	}
 	if(dc.font.set)
 		XFreeFontSet(dpy, dc.font.set);
@@ -165,7 +165,6 @@ setup(void) {
 	XSetWindowAttributes wa;
 
 	/* init atoms */
-	dwmprops = XInternAtom(dpy, "_DWM_PROPERTIES", False);
 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
 	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
 	wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);
@@ -231,7 +230,6 @@ setup(void) {
 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
 	/* multihead support */
 	selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
-	getdwmprops();
 }
 
 /*
diff --git a/screen.c b/screen.c
index ec8637f..b534766 100644
--- a/screen.c
+++ b/screen.c
@@ -3,8 +3,6 @@
 #include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <X11/Xatom.h>
 #include <X11/Xutil.h>
 
 /* static */
@@ -28,7 +26,6 @@ typedef struct {
 TAGS
 RULES
 
-static char buf[512];
 static unsigned int nrules = 0;
 static unsigned int nlayouts = 0;
 static unsigned int ltidx = 0; /* default */
@@ -53,19 +50,6 @@ floating(void) { /* default floating layout */
 			resize(c, c->x, c->y, c->w, c->h, True);
 }
 
-static void
-setdwmprops(void) {
-	unsigned int i;
-
-	for(i = 0; i < ntags && i < sizeof buf - 1; i++)
-		buf[i] = seltags[i] ? '1' : '0';
-	if(i < sizeof buf - 1)
-		buf[i++] = (char)ltidx + '0';
-	buf[i] = '\0';
-	XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
-			PropModeReplace, (unsigned char *)buf, i);
-}
-
 LAYOUTS
 
 /* extern */
@@ -74,6 +58,7 @@ unsigned int blw = 0;
 
 void
 applyrules(Client *c) {
+	static char buf[512];
 	unsigned int i, j;
 	regmatch_t tmp;
 	Bool matched = False;
@@ -215,20 +200,6 @@ isvisible(Client *c) {
 	return False;
 }
 
-void
-getdwmprops(void) {
-	unsigned int i;
-
-	if(gettextprop(root, dwmprops, buf, sizeof buf)) {
-		for(i = 0; i < ntags && i < sizeof buf - 1 && buf[i] != '\0'; i++)
-			seltags[i] = buf[i] == '1';
-		if(i < sizeof buf - 1 && buf[i] != '\0') {
-			if((unsigned int)(buf[i] - '0') < nlayouts)
-				ltidx = buf[i] - '0';
-		}
-	}
-}
-
 Client *
 nexttiled(Client *c) {
 	for(; c && (c->isfloating || !isvisible(c)); c = c->next);
@@ -266,15 +237,17 @@ restack(void) {
 
 void
 setlayout(const char *arg) {
-	int i;
+	unsigned int i;
 
 	if(!arg) {
 		if(++ltidx == nlayouts)
 			ltidx = 0;;
 	}
 	else {
-		i = atoi(arg);
-		if(i < 0 || i >= nlayouts)
+		for(i = 0; i < nlayouts; i++)
+			if(arg == layouts[i].symbol)
+				break;
+		if(i == nlayouts)
 			return;
 		ltidx = i;
 	}
@@ -282,7 +255,6 @@ setlayout(const char *arg) {
 		arrange();
 	else
 		drawstatus();
-	setdwmprops();
 }
 
 void
@@ -296,7 +268,6 @@ tag(const char *arg) {
 	i = idxoftag(arg);
 	if(i >= 0 && i < ntags)
 		sel->tags[i] = True;
-	setprops(sel);
 	arrange();
 }
 
@@ -315,10 +286,8 @@ togglefloating(const char *arg) {
 	if(!sel || isfloating())
 		return;
 	sel->isfloating = !sel->isfloating;
-	if(sel->isfloating) {
+	if(sel->isfloating)
 		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
-		setprops(sel);
-	}
 	arrange();
 }
 
@@ -352,7 +321,6 @@ toggletag(const char *arg) {
 	for(j = 0; j < ntags && !sel->tags[j]; j++);
 	if(j == ntags)
 		sel->tags[i] = True;
-	setprops(sel);
 	arrange();
 }
 
@@ -365,7 +333,6 @@ toggleview(const char *arg) {
 	for(j = 0; j < ntags && !seltags[j]; j++);
 	if(j == ntags)
 		seltags[i] = True; /* cannot toggle last view */
-	setdwmprops();
 	arrange();
 }
 
@@ -404,6 +371,5 @@ view(const char *arg) {
 	i = idxoftag(arg);
 	if(i >= 0 && i < ntags)
 		seltags[i] = True;
-	setdwmprops();
 	arrange();
 }
href='#n718'>718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 protocols[i] == wmatom[WMDelete]) protos |= WM_PROTOCOL_DELWIN; } free((char *) protocols); return protos; } void sendevent(Window w, Atom a, long value) { XEvent e; e.type = ClientMessage; e.xclient.window = w; e.xclient.message_type = a; e.xclient.format = 32; e.xclient.data.l[0] = value; e.xclient.data.l[1] = CurrentTime; XSendEvent(dpy, w, False, NoEventMask, &e); XSync(dpy, False); } void quit(Arg *arg) { running = False; } /* * There's no way to check accesses to destroyed windows, thus those cases are * ignored (especially on UnmapNotify's). Other types of errors call Xlibs * default error handler, which calls exit(). */ int xerror(Display *dpy, XErrorEvent *ee) { if(ee->error_code == BadWindow || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable) || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) || (ee->request_code == X_GrabKey && ee->error_code == BadAccess)) return 0; fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", ee->request_code, ee->error_code); return xerrorxlib(dpy, ee); /* may call exit() */ } int main(int argc, char *argv[]) { int i, n; fd_set rd; XSetWindowAttributes wa; unsigned int mask; Bool readstdin = True; Window w; XEvent ev; for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { switch (argv[i][1]) { default: eprint("usage: dwm [-v]\n"); break; case 'v': fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); exit(EXIT_SUCCESS); break; } } dpy = XOpenDisplay(0); if(!dpy) eprint("dwm: cannot connect X server\n"); screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); /* check if another WM is already running */ otherwm = False; XSetErrorHandler(xerrorstart); /* this causes an error if some other WM is running */ XSelectInput(dpy, root, SubstructureRedirectMask); XSync(dpy, False); if(otherwm) eprint("dwm: another window manager is already running\n"); XSetErrorHandler(NULL); xerrorxlib = XSetErrorHandler(xerror); /* init atoms */ wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, PropModeReplace, (unsigned char *) netatom, NetLast); /* init cursors */ cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); grabkeys(); /* style */ dc.bg = getcolor(BGCOLOR); dc.fg = getcolor(FGCOLOR); dc.border = getcolor(BORDERCOLOR); setfont(FONT); sx = sy = 0; sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); mw = (sw * MASTERW) / 100; wa.override_redirect = 1; wa.background_pixmap = ParentRelative; wa.event_mask = ButtonPressMask | ExposureMask; bx = by = 0; bw = sw; dc.h = bh = dc.font.height + 4; barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(dpy, barwin, cursor[CurNormal]); XMapRaised(dpy, barwin); dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, 0); drawstatus(); issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ | LeaveWindowMask; wa.cursor = cursor[CurNormal]; XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); strcpy(stext, "dwm-"VERSION); scan(); /* main event loop, reads status text from stdin as well */ Mainloop: while(running) { FD_ZERO(&rd); if(readstdin) FD_SET(STDIN_FILENO, &rd); FD_SET(ConnectionNumber(dpy), &rd); i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); if(i == -1 && errno == EINTR) continue; if(i < 0) eprint("select failed\n"); else if(i > 0) { if(FD_ISSET(ConnectionNumber(dpy), &rd)) { while(XPending(dpy)) { XNextEvent(dpy, &ev); if(handler[ev.type]) (handler[ev.type])(&ev); /* call handler */ } } if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) { i = n = 0; for(;;) { if((i = getchar()) == EOF) { /* broken pipe/end of producer */ readstdin = False; strcpy(stext, "broken pipe"); goto Mainloop; } if(i == '\n' || n >= sizeof(stext) - 1) break; stext[n++] = i; } stext[n] = 0; drawstatus(); } } } cleanup(); XCloseDisplay(dpy); return 0; } href='#n2078'>2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178