aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2010-09-09 13:33:12 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2010-09-09 13:33:12 (GMT)
commit534db1d4092bae83d95620a18aef3dd362627fae (patch)
tree0d527059fe6a293e49abec941ef6e568107649fd /src
parent77f39235cf3ad79c5ff7d2b0f4717660476f3cf4 (diff)
downloadfluxbox-534db1d4092bae83d95620a18aef3dd362627fae.zip
fluxbox-534db1d4092bae83d95620a18aef3dd362627fae.tar.bz2
reduced 'switch/case' and 'else if' hell a little bit
Diffstat (limited to 'src')
-rw-r--r--src/ClientPattern.cc173
-rw-r--r--src/ClientPattern.hh2
2 files changed, 82 insertions, 93 deletions
diff --git a/src/ClientPattern.cc b/src/ClientPattern.cc
index d6c7212..3305d97 100644
--- a/src/ClientPattern.cc
+++ b/src/ClientPattern.cc
@@ -47,11 +47,78 @@
47 #include <stdio.h> 47 #include <stdio.h>
48#endif 48#endif
49 49
50#ifdef HAVE_CSTRING
51 #include <cstring>
52#else
53 #include <string.h>
54#endif
55
50// needed as well for index on some systems (e.g. solaris) 56// needed as well for index on some systems (e.g. solaris)
51#include <strings.h> 57#include <strings.h>
52 58
53using std::string; 59using std::string;
54 60
61namespace {
62
63struct Name2WinProperty {
64 const char* name;
65 ClientPattern::WinProperty prop;
66};
67
68Name2WinProperty name_2_winproperties[] = { // sorted for 'bsearch'
69 { "class", ClientPattern::CLASS },
70 { "focushidden", ClientPattern::FOCUSHIDDEN },
71 { "head", ClientPattern::HEAD },
72 { "iconhidden", ClientPattern::ICONHIDDEN },
73 { "layer", ClientPattern::LAYER },
74 { "maximized", ClientPattern::MAXIMIZED },
75 { "minimized", ClientPattern::MINIMIZED },
76 { "name", ClientPattern::NAME },
77 { "role", ClientPattern::ROLE },
78 { "screen", ClientPattern::SCREEN },
79 { "shaded", ClientPattern::SHADED },
80 { "stuck", ClientPattern::STUCK },
81 { "title", ClientPattern::TITLE },
82 { "transient", ClientPattern::TRANSIENT },
83 { "urgent", ClientPattern::URGENT },
84 { "workspace", ClientPattern::WORKSPACE },
85 { "workspacename", ClientPattern::WORKSPACENAME }
86};
87
88int name_2_winproperty_cmp(const void* a, const void* b) {
89 return strcmp(
90 reinterpret_cast<const Name2WinProperty*>(a)->name,
91 reinterpret_cast<const Name2WinProperty*>(b)->name);
92}
93
94struct Prop2String {
95 ClientPattern::WinProperty prop;
96 const char* str;
97};
98
99Prop2String property_2_strings[] = { // sorted by 'prop'
100 { ClientPattern::TITLE, "title=" },
101 { ClientPattern::CLASS, "class=" },
102 { ClientPattern::NAME, "name=" },
103 { ClientPattern::ROLE, "role=" },
104 { ClientPattern::TRANSIENT, "transient=" },
105 { ClientPattern::MAXIMIZED, "maximized=" },
106 { ClientPattern::MINIMIZED, "minimized=" },
107 { ClientPattern::SHADED, "shaded=" },
108 { ClientPattern::STUCK, "stuck=" },
109 { ClientPattern::FOCUSHIDDEN, "focushidden=" },
110 { ClientPattern::ICONHIDDEN, "iconhidden=" },
111 { ClientPattern::WORKSPACE, "workspace=" },
112 { ClientPattern::WORKSPACENAME, "workspacename=" },
113 { ClientPattern::HEAD, "head=" },
114 { ClientPattern::LAYER, "layer=" },
115 { ClientPattern::URGENT, "urgent=" },
116 { ClientPattern::SCREEN, "screen=" }
117};
118
119
120} // end of anonymous namespace
121
55 122
56ClientPattern::ClientPattern(): 123ClientPattern::ClientPattern():
57 m_matchlimit(0), 124 m_matchlimit(0),
@@ -105,44 +172,20 @@ ClientPattern::ClientPattern(const char *str):
105 172
106 memstr = FbTk::StringUtil::toLower(memstr); 173 memstr = FbTk::StringUtil::toLower(memstr);
107 174
108 if (memstr == "name") { 175 Name2WinProperty key = { memstr.c_str(), CLASS };
109 prop = NAME; 176 Name2WinProperty* i = reinterpret_cast<Name2WinProperty*>(
110 } else if (memstr == "class") { 177 bsearch(&key, name_2_winproperties,
111 prop = CLASS; 178 sizeof(name_2_winproperties) / sizeof(Name2WinProperty),
112 } else if (memstr == "title") { 179 sizeof(Name2WinProperty),
113 prop = TITLE; 180 name_2_winproperty_cmp));
114 } else if (memstr == "role") { 181
115 prop = ROLE; 182 if (i) {
116 } else if (memstr == "transient") { 183 prop = i->prop;
117 prop = TRANSIENT;
118 } else if (memstr == "maximized") {
119 prop = MAXIMIZED;
120 } else if (memstr == "minimized") {
121 prop = MINIMIZED;
122 } else if (memstr == "shaded") {
123 prop = SHADED;
124 } else if (memstr == "stuck") {
125 prop = STUCK;
126 } else if (memstr == "focushidden") {
127 prop = FOCUSHIDDEN;
128 } else if (memstr == "iconhidden") {
129 prop = ICONHIDDEN;
130 } else if (memstr == "workspace") {
131 prop = WORKSPACE;
132 } else if (memstr == "workspacename") {
133 prop = WORKSPACENAME;
134 } else if (memstr == "head") {
135 prop = HEAD;
136 } else if (memstr == "layer") {
137 prop = LAYER;
138 } else if (memstr == "urgent") {
139 prop = URGENT;
140 } else if (memstr == "screen") {
141 prop = SCREEN;
142 } else { 184 } else {
143 prop = NAME; 185 prop = NAME;
144 expr = match; 186 expr = match;
145 } 187 }
188
146 had_error = !addTerm(expr, prop, negate); 189 had_error = !addTerm(expr, prop, negate);
147 pos += err; 190 pos += err;
148 } 191 }
@@ -201,69 +244,15 @@ string ClientPattern::toString() const {
201 for (; it != it_end; ++it) { 244 for (; it != it_end; ++it) {
202 245
203 pat.append(" ("); 246 pat.append(" (");
204 247 pat.append(property_2_strings[(*it)->prop].str);
205 switch ((*it)->prop) {
206 case NAME:
207 pat.append("name=");
208 break;
209 case CLASS:
210 pat.append("class=");
211 break;
212 case TITLE:
213 pat.append("title=");
214 break;
215 case ROLE:
216 pat.append("role=");
217 break;
218 case TRANSIENT:
219 pat.append("transient=");
220 break;
221 case MAXIMIZED:
222 pat.append("maximized=");
223 break;
224 case MINIMIZED:
225 pat.append("minimized=");
226 break;
227 case SHADED:
228 pat.append("shaded=");
229 break;
230 case STUCK:
231 pat.append("stuck=");
232 break;
233 case FOCUSHIDDEN:
234 pat.append("focushidden=");
235 break;
236 case ICONHIDDEN:
237 pat.append("iconhidden=");
238 break;
239 case WORKSPACE:
240 pat.append("workspace=");
241 break;
242 case WORKSPACENAME:
243 pat.append("workspacename=");
244 break;
245 case HEAD:
246 pat.append("head=");
247 break;
248 case LAYER:
249 pat.append("layer=");
250 break;
251 case URGENT:
252 pat.append("urgent=");
253 break;
254 case SCREEN:
255 pat.append("screen=");
256 break;
257 }
258
259 pat.append((*it)->orig); 248 pat.append((*it)->orig);
260 pat.append(")"); 249 pat.append(")");
261 } 250 }
262 251
263 if (m_matchlimit > 0) { 252 if (m_matchlimit > 0) {
264 char num[20]; 253 pat.append(" {");
265 sprintf(num, " {%d}", m_matchlimit); 254 pat.append(FbTk::StringUtil::number2String(m_matchlimit));
266 pat.append(num); 255 pat.append("}");
267 } 256 }
268 return pat; 257 return pat;
269} 258}
diff --git a/src/ClientPattern.hh b/src/ClientPattern.hh
index 153b7c0..9eb7653 100644
--- a/src/ClientPattern.hh
+++ b/src/ClientPattern.hh
@@ -51,7 +51,7 @@ public:
51 std::string toString() const; 51 std::string toString() const;
52 52
53 enum WinProperty { 53 enum WinProperty {
54 TITLE, CLASS, NAME, ROLE, TRANSIENT, 54 TITLE = 0, CLASS, NAME, ROLE, TRANSIENT,
55 MAXIMIZED, MINIMIZED, SHADED, STUCK, FOCUSHIDDEN, ICONHIDDEN, 55 MAXIMIZED, MINIMIZED, SHADED, STUCK, FOCUSHIDDEN, ICONHIDDEN,
56 WORKSPACE, WORKSPACENAME, HEAD, LAYER, URGENT, SCREEN 56 WORKSPACE, WORKSPACENAME, HEAD, LAYER, URGENT, SCREEN
57 }; 57 };