about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@gmail.com>2007-08-19 10:40:07 +0200
committerAnselm R. Garbe <garbeam@gmail.com>2007-08-19 10:40:07 +0200
commit96d7fe16eaf6b656800f08da3156bacd75ca3b08 (patch)
tree98d884e096b5108d8181914540718b6b82c6893e
parent78d1a22d4e847d0e596af59d7707da1bbfe9583a (diff)
downloaddwm-96d7fe16eaf6b656800f08da3156bacd75ca3b08.tar.gz
prepared merging layout.c and tag.c into screen.c
-rw-r--r--client.c36
-rw-r--r--dwm.h4
-rw-r--r--layout.c17
-rw-r--r--main.c28
4 files changed, 39 insertions, 46 deletions
diff --git a/client.c b/client.c
index d11ef7f..d94c0ed 100644
--- a/client.c
+++ b/client.c
@@ -185,15 +185,8 @@ Bool
 loadprops(Client *c) {
 	unsigned int i;
 	Bool result = False;
-	XTextProperty name;
-
-	/* check if window has set a property */
-	name.nitems = 0;
-	XGetTextProperty(dpy, c->win, &name, dwmprops);
-	if(name.nitems && name.encoding == XA_STRING) {
-		strncpy(prop, (char *)name.value, sizeof prop - 1);
-		prop[sizeof prop - 1] = '\0';
-		XFree(name.value);
+
+	if(gettextprop(c->win, dwmprops, prop, sizeof prop)) {
 		for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
 			if((c->tags[i] = prop[i] == '1'))
 				result = True;
@@ -424,27 +417,6 @@ updatesizehints(Client *c) {
 
 void
 updatetitle(Client *c) {
-	char **list = NULL;
-	int n;
-	XTextProperty name;
-
-	name.nitems = 0;
-	c->name[0] = 0;
-	XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
-	if(!name.nitems)
-		XGetWMName(dpy, c->win, &name);
-	if(!name.nitems)
-		return;
-	if(name.encoding == XA_STRING)
-		strncpy(c->name, (char *)name.value, sizeof c->name - 1);
-	else {
-		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
-		&& n > 0 && *list)
-		{
-			strncpy(c->name, *list, sizeof c->name - 1);
-			XFreeStringList(list);
-		}
-	}
-	c->name[sizeof c->name - 1] = '\0';
-	XFree(name.value);
+	if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
+		gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name);
 }
diff --git a/dwm.h b/dwm.h
index 9dd764f..36a0266 100644
--- a/dwm.h
+++ b/dwm.h
@@ -39,7 +39,7 @@ enum { BarTop, BarBot, BarOff };			/* bar position */
 enum { CurNormal, CurResize, CurMove, CurLast };	/* cursor */
 enum { ColBorder, ColFG, ColBG, ColLast };		/* color */
 enum { NetSupported, NetWMName, NetLast };		/* EWMH atoms */
-enum { WMProtocols, WMDelete, WMState, WMLast };	/* default atoms */
+enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
 
 typedef struct Client Client;
 struct Client {
@@ -131,6 +131,8 @@ void togglebar(const char *arg);	/* shows/hides the bar */
 void togglemax(const char *arg);	/* toggles maximization of floating client */
 
 /* main.c */
+Bool gettextprop(Window w, Atom atom,
+		char *text, unsigned int size); /* return text property, UTF-8 compliant */
 void updatebarpos(void);		/* updates the bar position */
 void quit(const char *arg);		/* quit dwm nicely */
 int xerror(Display *dsply, XErrorEvent *ee);	/* dwm's X error handler */
diff --git a/layout.c b/layout.c
index 96e125a..2763d2c 100644
--- a/layout.c
+++ b/layout.c
@@ -98,7 +98,6 @@ void
 initlayouts(void) {
 	unsigned int i, w;
 
-	/* TODO deserialize ltidx if present */
 	nlayouts = sizeof layouts / sizeof layouts[0];
 	for(blw = i = 0; i < nlayouts; i++) {
 		w = textw(layouts[i].symbol);
@@ -110,21 +109,13 @@ initlayouts(void) {
 void
 loaddwmprops(void) {
 	unsigned int i;
-	XTextProperty name;
-
-	/* check if window has set a property */
-	name.nitems = 0;
-	XGetTextProperty(dpy, root, &name, dwmprops);
-	if(name.nitems && name.encoding == XA_STRING) {
-		strncpy(prop, (char *)name.value, sizeof prop - 1);
-		prop[sizeof prop - 1] = '\0';
-		XFree(name.value);
+
+	if(gettextprop(root, dwmprops, prop, sizeof prop)) {
 		for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
 			seltags[i] = prop[i] == '1';
 		if(i < sizeof prop - 1 && prop[i] != '\0') {
-			i = prop[i];
-			if(i < nlayouts)
-				ltidx = i;
+			if(prop[i] < nlayouts)
+				ltidx = prop[i];
 		}
 	}
 }
diff --git a/main.c b/main.c
index 7cc5ecf..9127d16 100644
--- a/main.c
+++ b/main.c
@@ -143,6 +143,7 @@ setup(void) {
 	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);
 	wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
 	netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
 	netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
@@ -220,6 +221,33 @@ xerrorstart(Display *dsply, XErrorEvent *ee) {
 
 /* extern */
 
+Bool
+gettextprop(Window w, Atom atom, char *text, unsigned int size) {
+	char **list = NULL;
+	int n;
+	XTextProperty name;
+
+	if(!text || size == 0)
+		return False;
+	text[0] = '\0';
+	XGetTextProperty(dpy, w, &name, atom);
+	if(!name.nitems)
+		return False;
+	if(name.encoding == XA_STRING)
+		strncpy(text, (char *)name.value, size - 1);
+	else {
+		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
+		&& n > 0 && *list)
+		{
+			strncpy(text, *list, size - 1);
+			XFreeStringList(list);
+		}
+	}
+	text[size - 1] = '\0';
+	XFree(name.value);
+	return True;
+}
+
 void
 quit(const char *arg) {
 	readin = running = False;
examples/ex10.subx.html?h=hlt&id=9d27e966b5e9bf1bd3da48f49d7e133d112a2bbe'>^
39d718af ^
14a38052 ^



1a4de9dd ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137