diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2009-10-01 06:57:31 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2009-10-01 06:57:31 (GMT) |
commit | c4c96ec830f7e22c5f5183886de1f399333f60cd (patch) | |
tree | 3ded4864f71f3f092697268ea879e73b8dc978e7 /src | |
parent | 710ad1d4568239bbb1c19e82d764215b492d94db (diff) | |
download | fluxbox_lack-c4c96ec830f7e22c5f5183886de1f399333f60cd.zip fluxbox_lack-c4c96ec830f7e22c5f5183886de1f399333f60cd.tar.bz2 |
simpler code
Diffstat (limited to 'src')
-rw-r--r-- | src/ClientPattern.cc | 64 | ||||
-rw-r--r-- | src/FbCommands.cc | 5 | ||||
-rw-r--r-- | src/FbTk/StringUtil.cc | 7 | ||||
-rw-r--r-- | src/FbTk/StringUtil.hh | 2 | ||||
-rw-r--r-- | src/Layer.hh | 50 | ||||
-rw-r--r-- | src/Screen.cc | 4 | ||||
-rw-r--r-- | src/SystemTray.cc | 8 |
7 files changed, 60 insertions, 80 deletions
diff --git a/src/ClientPattern.cc b/src/ClientPattern.cc index 84f421a..41080fa 100644 --- a/src/ClientPattern.cc +++ b/src/ClientPattern.cc | |||
@@ -102,39 +102,42 @@ ClientPattern::ClientPattern(const char *str): | |||
102 | negate = true; | 102 | negate = true; |
103 | memstr.assign(memstr, 0, memstr.length()-1); | 103 | memstr.assign(memstr, 0, memstr.length()-1); |
104 | } | 104 | } |
105 | if (strcasecmp(memstr.c_str(), "name") == 0) { | 105 | |
106 | memstr = FbTk::StringUtil::toLower(memstr); | ||
107 | |||
108 | if (memstr == "name") { | ||
106 | prop = NAME; | 109 | prop = NAME; |
107 | } else if (strcasecmp(memstr.c_str(), "class") == 0) { | 110 | } else if (memstr == "class") { |
108 | prop = CLASS; | 111 | prop = CLASS; |
109 | } else if (strcasecmp(memstr.c_str(), "title") == 0) { | 112 | } else if (memstr == "title") { |
110 | prop = TITLE; | 113 | prop = TITLE; |
111 | } else if (strcasecmp(memstr.c_str(), "role") == 0) { | 114 | } else if (memstr == "role") { |
112 | prop = ROLE; | 115 | prop = ROLE; |
113 | } else if (strcasecmp(memstr.c_str(), "transient") == 0) { | 116 | } else if (memstr == "transient") { |
114 | prop = TRANSIENT; | 117 | prop = TRANSIENT; |
115 | } else if (strcasecmp(memstr.c_str(), "maximized") == 0) { | 118 | } else if (memstr == "maximized") { |
116 | prop = MAXIMIZED; | 119 | prop = MAXIMIZED; |
117 | } else if (strcasecmp(memstr.c_str(), "minimized") == 0) { | 120 | } else if (memstr == "minimized") { |
118 | prop = MINIMIZED; | 121 | prop = MINIMIZED; |
119 | } else if (strcasecmp(memstr.c_str(), "shaded") == 0) { | 122 | } else if (memstr == "shaded") { |
120 | prop = SHADED; | 123 | prop = SHADED; |
121 | } else if (strcasecmp(memstr.c_str(), "stuck") == 0) { | 124 | } else if (memstr == "stuck") { |
122 | prop = STUCK; | 125 | prop = STUCK; |
123 | } else if (strcasecmp(memstr.c_str(), "focushidden") == 0) { | 126 | } else if (memstr == "focushidden") { |
124 | prop = FOCUSHIDDEN; | 127 | prop = FOCUSHIDDEN; |
125 | } else if (strcasecmp(memstr.c_str(), "iconhidden") == 0) { | 128 | } else if (memstr == "iconhidden") { |
126 | prop = ICONHIDDEN; | 129 | prop = ICONHIDDEN; |
127 | } else if (strcasecmp(memstr.c_str(), "workspace") == 0) { | 130 | } else if (memstr == "workspace") { |
128 | prop = WORKSPACE; | 131 | prop = WORKSPACE; |
129 | } else if (strcasecmp(memstr.c_str(), "workspacename") == 0) { | 132 | } else if (memstr == "workspacename") { |
130 | prop = WORKSPACENAME; | 133 | prop = WORKSPACENAME; |
131 | } else if (strcasecmp(memstr.c_str(), "head") == 0) { | 134 | } else if (memstr == "head") { |
132 | prop = HEAD; | 135 | prop = HEAD; |
133 | } else if (strcasecmp(memstr.c_str(), "layer") == 0) { | 136 | } else if (memstr == "layer") { |
134 | prop = LAYER; | 137 | prop = LAYER; |
135 | } else if (strcasecmp(memstr.c_str(), "urgent") == 0) { | 138 | } else if (memstr == "urgent") { |
136 | prop = URGENT; | 139 | prop = URGENT; |
137 | } else if (strcasecmp(memstr.c_str(), "screen") == 0) { | 140 | } else if (memstr == "screen") { |
138 | prop = SCREEN; | 141 | prop = SCREEN; |
139 | } else { | 142 | } else { |
140 | prop = NAME; | 143 | prop = NAME; |
@@ -279,9 +282,7 @@ bool ClientPattern::match(const Focusable &win) const { | |||
279 | if ((*it)->orig == "[current]") { | 282 | if ((*it)->orig == "[current]") { |
280 | WinClient *focused = FocusControl::focusedWindow(); | 283 | WinClient *focused = FocusControl::focusedWindow(); |
281 | if ((*it)->prop == WORKSPACE) { | 284 | if ((*it)->prop == WORKSPACE) { |
282 | char tmpstr[128]; | 285 | if (!(*it)->negate ^ (getProperty((*it)->prop, win) == FbTk::StringUtil::number2String(win.screen().currentWorkspaceID()))) |
283 | sprintf(tmpstr, "%d", win.screen().currentWorkspaceID()); | ||
284 | if (!(*it)->negate ^ (getProperty((*it)->prop, win) == tmpstr)) | ||
285 | return false; | 286 | return false; |
286 | } else if ((*it)->prop == WORKSPACENAME) { | 287 | } else if ((*it)->prop == WORKSPACENAME) { |
287 | const Workspace *w = win.screen().currentWorkspace(); | 288 | const Workspace *w = win.screen().currentWorkspace(); |
@@ -292,16 +293,11 @@ bool ClientPattern::match(const Focusable &win) const { | |||
292 | (getProperty((*it)->prop, win) == | 293 | (getProperty((*it)->prop, win) == |
293 | getProperty((*it)->prop, *focused)))) | 294 | getProperty((*it)->prop, *focused)))) |
294 | return false; | 295 | return false; |
295 | } else if ((*it)->prop == HEAD && | 296 | } else if ((*it)->prop == HEAD && (*it)->orig == "[mouse]") { |
296 | (*it)->orig == "[mouse]") { | 297 | if (!(*it)->negate ^ (getProperty((*it)->prop, win) == FbTk::StringUtil::number2String(win.screen().getCurrHead()))) |
297 | int mouse_head = win.screen().getCurrHead(); | ||
298 | char num[32]; | ||
299 | sprintf(num, "%d", mouse_head); | ||
300 | if (!(*it)->negate ^ (getProperty((*it)->prop, win) == num)) | ||
301 | return false; | 298 | return false; |
302 | 299 | ||
303 | } else if (!(*it)->negate ^ | 300 | } else if (!(*it)->negate ^ (*it)->regexp.match(getProperty((*it)->prop, win))) |
304 | (*it)->regexp.match(getProperty((*it)->prop, win))) | ||
305 | return false; | 301 | return false; |
306 | } | 302 | } |
307 | return true; | 303 | return true; |
@@ -385,9 +381,7 @@ string ClientPattern::getProperty(WinProperty prop, const Focusable &client) { | |||
385 | break; | 381 | break; |
386 | case WORKSPACE: { | 382 | case WORKSPACE: { |
387 | unsigned int wsnum = (fbwin ? fbwin->workspaceNumber() : client.screen().currentWorkspaceID()); | 383 | unsigned int wsnum = (fbwin ? fbwin->workspaceNumber() : client.screen().currentWorkspaceID()); |
388 | char tmpstr[128]; | 384 | return FbTk::StringUtil::number2String(wsnum); |
389 | sprintf(tmpstr, "%d", wsnum); | ||
390 | return std::string(tmpstr); | ||
391 | break; | 385 | break; |
392 | } | 386 | } |
393 | case WORKSPACENAME: { | 387 | case WORKSPACENAME: { |
@@ -401,9 +395,7 @@ string ClientPattern::getProperty(WinProperty prop, const Focusable &client) { | |||
401 | if (!fbwin) | 395 | if (!fbwin) |
402 | return ""; | 396 | return ""; |
403 | int head = client.screen().getHead(fbwin->fbWindow()); | 397 | int head = client.screen().getHead(fbwin->fbWindow()); |
404 | char tmpstr[128]; | 398 | return FbTk::StringUtil::number2String(head); |
405 | sprintf(tmpstr, "%d", head); | ||
406 | return std::string(tmpstr); | ||
407 | break; | 399 | break; |
408 | } | 400 | } |
409 | case LAYER: | 401 | case LAYER: |
@@ -415,9 +407,7 @@ string ClientPattern::getProperty(WinProperty prop, const Focusable &client) { | |||
415 | break; | 407 | break; |
416 | case SCREEN: { | 408 | case SCREEN: { |
417 | int screenId = client.screen().screenNumber(); | 409 | int screenId = client.screen().screenNumber(); |
418 | char tmpstr[32]; | 410 | return FbTk::StringUtil::number2String(screenId); |
419 | sprintf(tmpstr, "%d", screenId); | ||
420 | return std::string(tmpstr); | ||
421 | break; | 411 | break; |
422 | } | 412 | } |
423 | } | 413 | } |
diff --git a/src/FbCommands.cc b/src/FbCommands.cc index 26a431a..f050669 100644 --- a/src/FbCommands.cc +++ b/src/FbCommands.cc | |||
@@ -144,7 +144,6 @@ int ExecuteCmd::run() { | |||
144 | 144 | ||
145 | string displaystring("DISPLAY="); | 145 | string displaystring("DISPLAY="); |
146 | displaystring += DisplayString(FbTk::App::instance()->display()); | 146 | displaystring += DisplayString(FbTk::App::instance()->display()); |
147 | char intbuff[64]; | ||
148 | int screen_num = m_screen_num; | 147 | int screen_num = m_screen_num; |
149 | if (screen_num < 0) { | 148 | if (screen_num < 0) { |
150 | if (Fluxbox::instance()->mouseScreen() == 0) | 149 | if (Fluxbox::instance()->mouseScreen() == 0) |
@@ -153,8 +152,6 @@ int ExecuteCmd::run() { | |||
153 | screen_num = Fluxbox::instance()->mouseScreen()->screenNumber(); | 152 | screen_num = Fluxbox::instance()->mouseScreen()->screenNumber(); |
154 | } | 153 | } |
155 | 154 | ||
156 | sprintf(intbuff, "%d", screen_num); | ||
157 | |||
158 | // get shell path from the environment | 155 | // get shell path from the environment |
159 | // this process exits immediately, so we don't have to worry about memleaks | 156 | // this process exits immediately, so we don't have to worry about memleaks |
160 | const char *shell = getenv("SHELL"); | 157 | const char *shell = getenv("SHELL"); |
@@ -163,7 +160,7 @@ int ExecuteCmd::run() { | |||
163 | 160 | ||
164 | // remove last number of display and add screen num | 161 | // remove last number of display and add screen num |
165 | displaystring.erase(displaystring.size()-1); | 162 | displaystring.erase(displaystring.size()-1); |
166 | displaystring += intbuff; | 163 | displaystring += FbTk::StringUtil::number2String(screen_num); |
167 | 164 | ||
168 | setsid(); | 165 | setsid(); |
169 | putenv(const_cast<char *>(displaystring.c_str())); | 166 | putenv(const_cast<char *>(displaystring.c_str())); |
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc index 18e000e..a0e402d 100644 --- a/src/FbTk/StringUtil.cc +++ b/src/FbTk/StringUtil.cc | |||
@@ -60,6 +60,13 @@ namespace FbTk { | |||
60 | 60 | ||
61 | namespace StringUtil { | 61 | namespace StringUtil { |
62 | 62 | ||
63 | |||
64 | std::string number2String(int num) { | ||
65 | char s[128]; | ||
66 | sprintf(s, "%d", num); | ||
67 | return std::string(s); | ||
68 | } | ||
69 | |||
63 | /** | 70 | /** |
64 | Tries to find a string in another and | 71 | Tries to find a string in another and |
65 | ignoring the case of the characters | 72 | ignoring the case of the characters |
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh index 35f23a2..6493f74 100644 --- a/src/FbTk/StringUtil.hh +++ b/src/FbTk/StringUtil.hh | |||
@@ -30,6 +30,8 @@ namespace FbTk { | |||
30 | 30 | ||
31 | namespace StringUtil { | 31 | namespace StringUtil { |
32 | 32 | ||
33 | /// creates a number to a string | ||
34 | std::string number2String(int num); | ||
33 | 35 | ||
34 | /// Similar to `strstr' but this function ignores the case of both strings | 36 | /// Similar to `strstr' but this function ignores the case of both strings |
35 | const char *strcasestr(const char *str, const char *ptn); | 37 | const char *strcasestr(const char *str, const char *ptn); |
diff --git a/src/Layer.hh b/src/Layer.hh index da8f04c..14054b0 100644 --- a/src/Layer.hh +++ b/src/Layer.hh | |||
@@ -22,16 +22,7 @@ | |||
22 | #ifndef LAYER_HH | 22 | #ifndef LAYER_HH |
23 | #define LAYER_HH | 23 | #define LAYER_HH |
24 | 24 | ||
25 | #include <string> | 25 | #include "FbTk/StringUtil.hh" |
26 | #include <cstdio> | ||
27 | |||
28 | #ifdef HAVE_CSTRING | ||
29 | #include <cstring> | ||
30 | #else | ||
31 | #include <string.h> | ||
32 | #endif | ||
33 | |||
34 | using std::string; | ||
35 | 26 | ||
36 | /** | 27 | /** |
37 | * (This is not the layer->raise/lower handling stuff, @see FbTk::Layer) | 28 | * (This is not the layer->raise/lower handling stuff, @see FbTk::Layer) |
@@ -54,52 +45,51 @@ public: | |||
54 | 45 | ||
55 | explicit Layer(int i) : m_num(i) {}; | 46 | explicit Layer(int i) : m_num(i) {}; |
56 | 47 | ||
57 | static int getNumFromString(const string &str) { | 48 | static int getNumFromString(const std::string &str) { |
58 | int tempnum = 0; | 49 | int tempnum = 0; |
50 | std::string v = FbTk::StringUtil::toLower(str); | ||
59 | if (sscanf(str.c_str(), "%d", &tempnum) == 1) | 51 | if (sscanf(str.c_str(), "%d", &tempnum) == 1) |
60 | return tempnum; | 52 | return tempnum; |
61 | if (strcasecmp(str.c_str(), "Menu") == 0) | 53 | if (v == "menu") |
62 | return ::Layer::MENU; | 54 | return ::Layer::MENU; |
63 | if (strcasecmp(str.c_str(), "AboveDock") == 0) | 55 | if (v == "abovedock") |
64 | return ::Layer::ABOVE_DOCK; | 56 | return ::Layer::ABOVE_DOCK; |
65 | if (strcasecmp(str.c_str(), "Dock") == 0) | 57 | if (v == "dock") |
66 | return ::Layer::DOCK; | 58 | return ::Layer::DOCK; |
67 | if (strcasecmp(str.c_str(), "Top") == 0) | 59 | if (v == "top") |
68 | return ::Layer::TOP; | 60 | return ::Layer::TOP; |
69 | if (strcasecmp(str.c_str(), "Normal") == 0) | 61 | if (v == "normal") |
70 | return ::Layer::NORMAL; | 62 | return ::Layer::NORMAL; |
71 | if (strcasecmp(str.c_str(), "Bottom") == 0) | 63 | if (v == "bottom") |
72 | return ::Layer::BOTTOM; | 64 | return ::Layer::BOTTOM; |
73 | if (strcasecmp(str.c_str(), "Desktop") == 0) | 65 | if (v == "desktop") |
74 | return ::Layer::DESKTOP; | 66 | return ::Layer::DESKTOP; |
75 | return -1; | 67 | return -1; |
76 | } | 68 | } |
77 | 69 | ||
78 | static string getString(int num) { | 70 | static std::string getString(int num) { |
79 | switch (num) { | 71 | switch (num) { |
80 | case ::Layer::MENU: | 72 | case ::Layer::MENU: |
81 | return string("Menu"); | 73 | return std::string("Menu"); |
82 | case ::Layer::ABOVE_DOCK: | 74 | case ::Layer::ABOVE_DOCK: |
83 | return string("AboveDock"); | 75 | return std::string("AboveDock"); |
84 | case ::Layer::DOCK: | 76 | case ::Layer::DOCK: |
85 | return string("Dock"); | 77 | return std::string("Dock"); |
86 | case ::Layer::TOP: | 78 | case ::Layer::TOP: |
87 | return string("Top"); | 79 | return std::string("Top"); |
88 | case ::Layer::NORMAL: | 80 | case ::Layer::NORMAL: |
89 | return string("Normal"); | 81 | return std::string("Normal"); |
90 | case ::Layer::BOTTOM: | 82 | case ::Layer::BOTTOM: |
91 | return string("Bottom"); | 83 | return std::string("Bottom"); |
92 | case ::Layer::DESKTOP: | 84 | case ::Layer::DESKTOP: |
93 | return string("Desktop"); | 85 | return std::string("Desktop"); |
94 | default: | 86 | default: |
95 | char tmpstr[128]; | 87 | return FbTk::StringUtil::number2String(num); |
96 | sprintf(tmpstr, "%d", num); | ||
97 | return string(tmpstr); | ||
98 | } | 88 | } |
99 | } | 89 | } |
100 | 90 | ||
101 | int getNum() const { return m_num; } | 91 | int getNum() const { return m_num; } |
102 | string getString() const { return getString(m_num); } | 92 | std::string getString() const { return getString(m_num); } |
103 | 93 | ||
104 | Layer &operator=(int num) { m_num = num; return *this; } | 94 | Layer &operator=(int num) { m_num = num; return *this; } |
105 | 95 | ||
diff --git a/src/Screen.cc b/src/Screen.cc index 1581571..9e340f8 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -1231,10 +1231,8 @@ bool BScreen::isKdeDockapp(Window client) const { | |||
1231 | bool BScreen::addKdeDockapp(Window client) { | 1231 | bool BScreen::addKdeDockapp(Window client) { |
1232 | 1232 | ||
1233 | XSelectInput(FbTk::App::instance()->display(), client, StructureNotifyMask); | 1233 | XSelectInput(FbTk::App::instance()->display(), client, StructureNotifyMask); |
1234 | char intbuff[16]; | ||
1235 | sprintf(intbuff, "%d", screenNumber()); | ||
1236 | string atom_name("_NET_SYSTEM_TRAY_S"); | 1234 | string atom_name("_NET_SYSTEM_TRAY_S"); |
1237 | atom_name += intbuff; // append number | 1235 | atom_name += FbTk::StringUtil::number2String(screenNumber()); |
1238 | // find the right atomhandler that has the name: _NET_SYSTEM_TRAY_S<num> | 1236 | // find the right atomhandler that has the name: _NET_SYSTEM_TRAY_S<num> |
1239 | AtomHandler *handler = Fluxbox::instance()->getAtomHandler(atom_name); | 1237 | AtomHandler *handler = Fluxbox::instance()->getAtomHandler(atom_name); |
1240 | FbTk::EventHandler *evh = 0; | 1238 | FbTk::EventHandler *evh = 0; |
diff --git a/src/SystemTray.cc b/src/SystemTray.cc index 05d8d09..3a38bb1 100644 --- a/src/SystemTray.cc +++ b/src/SystemTray.cc | |||
@@ -180,10 +180,8 @@ SystemTray::SystemTray(const FbTk::FbWindow& parent, | |||
180 | Display *disp = fluxbox->display(); | 180 | Display *disp = fluxbox->display(); |
181 | 181 | ||
182 | // setup atom name to _NET_SYSTEM_TRAY_S<screen number> | 182 | // setup atom name to _NET_SYSTEM_TRAY_S<screen number> |
183 | char intbuff[16]; | ||
184 | sprintf(intbuff, "%d", m_window.screenNumber()); | ||
185 | string atom_name("_NET_SYSTEM_TRAY_S"); | 183 | string atom_name("_NET_SYSTEM_TRAY_S"); |
186 | atom_name += intbuff; // append number | 184 | atom_name += FbTk::StringUtil::number2String(m_window.screenNumber()); |
187 | 185 | ||
188 | // get selection owner and see if it's free | 186 | // get selection owner and see if it's free |
189 | Atom tray_atom = XInternAtom(disp, atom_name.c_str(), False); | 187 | Atom tray_atom = XInternAtom(disp, atom_name.c_str(), False); |
@@ -232,10 +230,8 @@ SystemTray::~SystemTray() { | |||
232 | fluxbox->removeAtomHandler(m_handler.get()); | 230 | fluxbox->removeAtomHandler(m_handler.get()); |
233 | Display *disp = fluxbox->display(); | 231 | Display *disp = fluxbox->display(); |
234 | // setup atom name to _NET_SYSTEM_TRAY_S<screen number> | 232 | // setup atom name to _NET_SYSTEM_TRAY_S<screen number> |
235 | char intbuff[16]; | ||
236 | sprintf(intbuff, "%d", m_window.screenNumber()); | ||
237 | string atom_name("_NET_SYSTEM_TRAY_S"); | 233 | string atom_name("_NET_SYSTEM_TRAY_S"); |
238 | atom_name += intbuff; // append number | 234 | atom_name += FbTk::StringUtil::number2String(m_window.screenNumber()); |
239 | 235 | ||
240 | // get selection owner and see if it's free | 236 | // get selection owner and see if it's free |
241 | Atom tray_atom = XInternAtom(disp, atom_name.c_str(), False); | 237 | Atom tray_atom = XInternAtom(disp, atom_name.c_str(), False); |