aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Gumz <akira@fluxbox.org>2015-01-21 20:54:30 (GMT)
committerMathias Gumz <akira@fluxbox.org>2015-01-21 20:54:30 (GMT)
commitf64727caff069f830dfadb63786df0eba7b3bdb4 (patch)
treece2557143bdf4bc9175fd3585c6d847ce7737cc9
parentdae7fca7cb38dc51b954c0035afbf43df9272f8c (diff)
downloadfluxbox-f64727caff069f830dfadb63786df0eba7b3bdb4.zip
fluxbox-f64727caff069f830dfadb63786df0eba7b3bdb4.tar.bz2
Cosmetic: less code bloat
-rw-r--r--src/Remember.cc126
1 files changed, 57 insertions, 69 deletions
diff --git a/src/Remember.cc b/src/Remember.cc
index 77cc889..f946ad0 100644
--- a/src/Remember.cc
+++ b/src/Remember.cc
@@ -34,6 +34,7 @@
34#include "Debug.hh" 34#include "Debug.hh"
35 35
36#include "FbTk/I18n.hh" 36#include "FbTk/I18n.hh"
37#include "FbTk/FbString.hh"
37#include "FbTk/StringUtil.hh" 38#include "FbTk/StringUtil.hh"
38#include "FbTk/FileUtil.hh" 39#include "FbTk/FileUtil.hh"
39#include "FbTk/MenuItem.hh" 40#include "FbTk/MenuItem.hh"
@@ -256,8 +257,8 @@ string escapeRememberChars(const string& str) {
256 257
257class RememberMenuItem : public FbTk::MenuItem { 258class RememberMenuItem : public FbTk::MenuItem {
258public: 259public:
259 RememberMenuItem(const FbTk::FbString &label, 260 RememberMenuItem(const FbTk::BiDiString &label,
260 Remember::Attribute attrib) : 261 const Remember::Attribute attrib) :
261 FbTk::MenuItem(label), 262 FbTk::MenuItem(label),
262 m_attrib(attrib) { 263 m_attrib(attrib) {
263 setToggleItem(true); 264 setToggleItem(true);
@@ -270,8 +271,7 @@ public:
270 271
271 if (FbMenu::window()->numClients()) // ensure it HAS clients 272 if (FbMenu::window()->numClients()) // ensure it HAS clients
272 return Remember::instance().isRemembered(FbMenu::window()->winClient(), m_attrib); 273 return Remember::instance().isRemembered(FbMenu::window()->winClient(), m_attrib);
273 else 274 return false;
274 return false;
275 } 275 }
276 276
277 bool isEnabled() const { 277 bool isEnabled() const {
@@ -282,21 +282,22 @@ public:
282 return true; 282 return true;
283 else if (FbMenu::window()->numClients()) 283 else if (FbMenu::window()->numClients())
284 return (Remember::instance().isRemembered(FbMenu::window()->winClient(), Remember::REM_WORKSPACE)); 284 return (Remember::instance().isRemembered(FbMenu::window()->winClient(), Remember::REM_WORKSPACE));
285 else 285 return false;
286 return false;
287 } 286 }
288 287
289 void click(int button, int time, unsigned int mods) { 288 void click(int button, int time, unsigned int mods) {
290 // reconfigure only does stuff if the apps file has changed 289 // reconfigure only does stuff if the apps file has changed
291 Remember::instance().checkReload(); 290 Remember& r = Remember::instance();
291 r.checkReload();
292 if (FbMenu::window() != 0) { 292 if (FbMenu::window() != 0) {
293 WinClient wc = FbMenu::window()->winClient();
293 if (isSelected()) { 294 if (isSelected()) {
294 Remember::instance().forgetAttrib(FbMenu::window()->winClient(), m_attrib); 295 r.forgetAttrib(wc, m_attrib);
295 } else { 296 } else {
296 Remember::instance().rememberAttrib(FbMenu::window()->winClient(), m_attrib); 297 r.rememberAttrib(wc, m_attrib);
297 } 298 }
298 } 299 }
299 Remember::instance().save(); 300 r.save();
300 FbTk::MenuItem::click(button, time, mods); 301 FbTk::MenuItem::click(button, time, mods);
301 } 302 }
302 303
@@ -305,51 +306,38 @@ private:
305}; 306};
306 307
307FbTk::Menu *createRememberMenu(BScreen &screen) { 308FbTk::Menu *createRememberMenu(BScreen &screen) {
309
310 _FB_USES_NLS;
311
312 typedef struct { bool is_alpha; const FbTk::BiDiString label; Remember::Attribute attr; } MenuEntry;
313 static const MenuEntry _entries[] = {
314 { false, _FB_XTEXT(Remember, Workspace, "Workspace", "Remember Workspace"), Remember::REM_WORKSPACE },
315 { false, _FB_XTEXT(Remember, JumpToWorkspace, "Jump to workspace", "Change active workspace to remembered one on open"), Remember::REM_JUMPWORKSPACE },
316 { false, _FB_XTEXT(Remember, Head, "Head", "Remember Head"), Remember::REM_HEAD},
317 { false, _FB_XTEXT(Remember, Dimensions, "Dimensions", "Remember Dimensions - with width and height"), Remember::REM_DIMENSIONS},
318 { false, _FB_XTEXT(Remember, Position, "Position", "Remember position - window co-ordinates"), Remember::REM_POSITION},
319 { false, _FB_XTEXT(Remember, Sticky, "Sticky", "Remember Sticky"), Remember::REM_STUCKSTATE},
320 { false, _FB_XTEXT(Remember, Decorations, "Decorations", "Remember window decorations"), Remember::REM_DECOSTATE},
321 { false, _FB_XTEXT(Remember, Shaded, "Shaded", "Remember shaded"), Remember::REM_SHADEDSTATE},
322 { false, _FB_XTEXT(Remember, Minimized, "Minimized", "Remember minimized"), Remember::REM_MINIMIZEDSTATE},
323 { false, _FB_XTEXT(Remember, Maximized, "Maximized", "Remember maximized"), Remember::REM_MAXIMIZEDSTATE},
324 { false, _FB_XTEXT(Remember, Fullscreen, "Fullscreen", "Remember fullscreen"), Remember::REM_FULLSCREENSTATE},
325 { true, _FB_XTEXT(Remember, Alpha, "Transparency", "Remember window tranparency settings"), Remember::REM_ALPHA},
326 { false, _FB_XTEXT(Remember, Layer, "Layer", "Remember Layer"), Remember::REM_LAYER},
327 { false, _FB_XTEXT(Remember, SaveOnClose, "Save on close", "Save remembered attributes on close"), Remember::REM_SAVEONCLOSE}
328 };
329 bool needs_alpha = (FbTk::Transparent::haveComposite() || FbTk::Transparent::haveRender());
330
308 // each fluxboxwindow has its own windowmenu 331 // each fluxboxwindow has its own windowmenu
309 // so we also create a remember menu just for it... 332 // so we also create a remember menu just for it...
310 FbTk::Menu *menu = MenuCreator::createMenu("Remember", screen); 333 FbTk::Menu *menu = MenuCreator::createMenu("Remember", screen);
311 334 size_t i;
312 // if enabled, then we want this to be a unavailable menu 335 for (i = 0; i < sizeof(_entries)/sizeof(_entries[0]); i++) {
313 /* 336 if (_entries[i].is_alpha && !needs_alpha) { // skip alpha-entry when not needed
314 if (!enabled) { 337 continue;
315 FbTk::MenuItem *item = new FbTk::MenuItem("unavailable"); 338 }
316 item->setEnabled(false); 339 menu->insertItem(new RememberMenuItem(_entries[i].label, _entries[i].attr));
317 menu->insert(item);
318 menu->updateMenu();
319 return menu;
320 } 340 }
321 */
322 _FB_USES_NLS;
323 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Workspace, "Workspace", "Remember Workspace"),
324 Remember::REM_WORKSPACE));
325 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, JumpToWorkspace, "Jump to workspace", "Change active workspace to remembered one on open"),
326 Remember::REM_JUMPWORKSPACE));
327 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Head, "Head", "Remember Head"),
328 Remember::REM_HEAD));
329 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Dimensions, "Dimensions", "Remember Dimensions - with width and height"),
330 Remember::REM_DIMENSIONS));
331 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Position, "Position", "Remember position - window co-ordinates"),
332 Remember::REM_POSITION));
333 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Sticky, "Sticky", "Remember Sticky"),
334 Remember::REM_STUCKSTATE));
335 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Decorations, "Decorations", "Remember window decorations"),
336 Remember::REM_DECOSTATE));
337 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Shaded, "Shaded", "Remember shaded"),
338 Remember::REM_SHADEDSTATE));
339 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Minimized, "Minimized", "Remember minimized"),
340 Remember::REM_MINIMIZEDSTATE));
341 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Maximized, "Maximized", "Remember maximized"),
342 Remember::REM_MAXIMIZEDSTATE));
343 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Fullscreen, "Fullscreen", "Remember fullscreen"),
344 Remember::REM_FULLSCREENSTATE));
345 if (FbTk::Transparent::haveComposite()
346 || FbTk::Transparent::haveRender())
347 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Alpha, "Transparency", "Remember window tranparency settings"),
348 Remember::REM_ALPHA));
349 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, Layer, "Layer", "Remember Layer"),
350 Remember::REM_LAYER));
351 menu->insertItem(new RememberMenuItem(_FB_XTEXT(Remember, SaveOnClose, "Save on close", "Save remembered attributes on close"),
352 Remember::REM_SAVEONCLOSE));
353 341
354 menu->updateMenu(); 342 menu->updateMenu();
355 return menu; 343 return menu;
@@ -462,6 +450,7 @@ int parseApp(ifstream &file, Application &app, string *first_line = 0) {
462 continue; //read next line 450 continue; //read next line
463 451
464 str_key = FbTk::StringUtil::toLower(str_key); 452 str_key = FbTk::StringUtil::toLower(str_key);
453 str_label = FbTk::StringUtil::toLower(str_label);
465 454
466 if (str_key == "workspace") { 455 if (str_key == "workspace") {
467 unsigned int w; 456 unsigned int w;
@@ -481,7 +470,7 @@ int parseApp(ifstream &file, Application &app, string *first_line = 0) {
481 if (!had_error) 470 if (!had_error)
482 app.rememberLayer(l); 471 app.rememberLayer(l);
483 } else if (str_key == "dimensions") { 472 } else if (str_key == "dimensions") {
484 unsigned int h,w; 473 unsigned int h, w;
485 if (sscanf(str_label.c_str(), "%u %u", &w, &h) == 2) { 474 if (sscanf(str_label.c_str(), "%u %u", &w, &h) == 2) {
486 app.rememberDimensions(w, h, false); 475 app.rememberDimensions(w, h, false);
487 } else if(sscanf(str_label.c_str(), "%u%% %u%%", &w, &h) == 2) { 476 } else if(sscanf(str_label.c_str(), "%u%% %u%%", &w, &h) == 2) {
@@ -509,16 +498,16 @@ int parseApp(ifstream &file, Application &app, string *first_line = 0) {
509 had_error = true; 498 had_error = true;
510 } 499 }
511 } else if (str_key == "shaded") { 500 } else if (str_key == "shaded") {
512 app.rememberShadedstate((strcasecmp(str_label.c_str(), "yes") == 0)); 501 app.rememberShadedstate(str_label == "yes");
513 } else if (str_key == "tab") { 502 } else if (str_key == "tab") {
514 app.rememberTabstate((strcasecmp(str_label.c_str(), "yes") == 0)); 503 app.rememberTabstate(str_label == "yes");
515 } else if (str_key == "focushidden") { 504 } else if (str_key == "focushidden") {
516 app.rememberFocusHiddenstate((strcasecmp(str_label.c_str(), "yes") == 0)); 505 app.rememberFocusHiddenstate(str_label == "yes");
517 } else if (str_key == "iconhidden") { 506 } else if (str_key == "iconhidden") {
518 app.rememberIconHiddenstate((strcasecmp(str_label.c_str(), "yes") == 0)); 507 app.rememberIconHiddenstate(str_label == "yes");
519 } else if (str_key == "hidden") { 508 } else if (str_key == "hidden") {
520 app.rememberIconHiddenstate((strcasecmp(str_label.c_str(), "yes") == 0)); 509 app.rememberIconHiddenstate(str_label == "yes");
521 app.rememberFocusHiddenstate((strcasecmp(str_label.c_str(), "yes") == 0)); 510 app.rememberFocusHiddenstate(str_label == "yes");
522 } else if (str_key == "deco") { 511 } else if (str_key == "deco") {
523 int deco = WindowState::getDecoMaskFromString(str_label); 512 int deco = WindowState::getDecoMaskFromString(str_label);
524 if (deco == -1) 513 if (deco == -1)
@@ -540,26 +529,25 @@ int parseApp(ifstream &file, Application &app, string *first_line = 0) {
540 break; 529 break;
541 } 530 }
542 } else if (str_key == "sticky") { 531 } else if (str_key == "sticky") {
543 app.rememberStuckstate((strcasecmp(str_label.c_str(), "yes") == 0)); 532 app.rememberStuckstate(str_label == "yes");
544 } else if (str_key == "focusnewwindow") { 533 } else if (str_key == "focusnewwindow") {
545 app.rememberFocusNewWindow((strcasecmp(str_label.c_str(), "yes") == 0)); 534 app.rememberFocusNewWindow(str_label == "yes");
546 } else if (str_key == "minimized") { 535 } else if (str_key == "minimized") {
547 app.rememberMinimizedstate((strcasecmp(str_label.c_str(), "yes") == 0)); 536 app.rememberMinimizedstate(str_label == "yes");
548 } else if (str_key == "maximized") { 537 } else if (str_key == "maximized") {
549 if (strcasecmp(str_label.c_str(), "yes") == 0) 538 if (str_label == "yes")
550 app.rememberMaximizedstate(WindowState::MAX_FULL); 539 app.rememberMaximizedstate(WindowState::MAX_FULL);
551 else if (strcasecmp(str_label.c_str(), "horz") == 0) 540 else if (str_label == "horz")
552 app.rememberMaximizedstate(WindowState::MAX_HORZ); 541 app.rememberMaximizedstate(WindowState::MAX_HORZ);
553 else if (strcasecmp(str_label.c_str(), "vert") == 0) 542 else if (str_label == "vert")
554 app.rememberMaximizedstate(WindowState::MAX_VERT); 543 app.rememberMaximizedstate(WindowState::MAX_VERT);
555 else 544 app.rememberMaximizedstate(WindowState::MAX_NONE);
556 app.rememberMaximizedstate(WindowState::MAX_NONE);
557 } else if (str_key == "fullscreen") { 545 } else if (str_key == "fullscreen") {
558 app.rememberFullscreenstate((strcasecmp(str_label.c_str(), "yes") == 0)); 546 app.rememberFullscreenstate(str_label == "yes");
559 } else if (str_key == "jump") { 547 } else if (str_key == "jump") {
560 app.rememberJumpworkspace((strcasecmp(str_label.c_str(), "yes") == 0)); 548 app.rememberJumpworkspace(str_label == "yes");
561 } else if (str_key == "close") { 549 } else if (str_key == "close") {
562 app.rememberSaveOnClose((strcasecmp(str_label.c_str(), "yes") == 0)); 550 app.rememberSaveOnClose(str_label == "yes");
563 } else if (str_key == "end") { 551 } else if (str_key == "end") {
564 return row; 552 return row;
565 } else { 553 } else {