aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lübking <thomas.luebking@gmail.com>2016-06-29 15:27:28 (GMT)
committerMathias Gumz <akira@fluxbox.org>2016-08-26 06:18:48 (GMT)
commitfbb2d16639491fdb0c49e388278fabcc4b0800f3 (patch)
treeb216515b1265dd6164722ebd77ff580738dfc9a0
parent393ba45f91480bb10f510248837c6051b7ff6a03 (diff)
downloadfluxbox-fbb2d16639491fdb0c49e388278fabcc4b0800f3.zip
fluxbox-fbb2d16639491fdb0c49e388278fabcc4b0800f3.tar.bz2
allow to alter button labels via fluxbox-remote
Command is "RelabelButton button.foo $LABEL" This is useful to eg. hint the amount of unread mails in a button to start your MUA, reflect the $USER in a session menu button etc.
-rw-r--r--src/Screen.cc24
-rw-r--r--src/Screen.hh11
-rw-r--r--src/ToolFactory.cc1
-rw-r--r--src/Toolbar.cc13
-rw-r--r--src/Toolbar.hh2
-rw-r--r--src/WorkspaceCmd.cc25
-rw-r--r--src/WorkspaceCmd.hh11
7 files changed, 82 insertions, 5 deletions
diff --git a/src/Screen.cc b/src/Screen.cc
index 24e0607..83a864b 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -392,6 +392,7 @@ BScreen::~BScreen() {
392 return; 392 return;
393 393
394 m_toolbar.reset(0); 394 m_toolbar.reset(0);
395 m_toolButtonMap.reset(0);
395 396
396 FbTk::EventManager *evm = FbTk::EventManager::instance(); 397 FbTk::EventManager *evm = FbTk::EventManager::instance();
397 evm->remove(rootWindow()); 398 evm->remove(rootWindow());
@@ -454,6 +455,7 @@ void BScreen::initWindows() {
454 455
455#ifdef USE_TOOLBAR 456#ifdef USE_TOOLBAR
456 if (m_opts & Fluxbox::OPT_TOOLBAR) { 457 if (m_opts & Fluxbox::OPT_TOOLBAR) {
458 m_toolButtonMap.reset(new ToolButtonMap());
457 Toolbar* tb = new Toolbar(*this, *layerManager().getLayer(::ResourceLayer::NORMAL)); 459 Toolbar* tb = new Toolbar(*this, *layerManager().getLayer(::ResourceLayer::NORMAL));
458 m_toolbar.reset(tb); 460 m_toolbar.reset(tb);
459 } 461 }
@@ -1293,6 +1295,28 @@ void BScreen::reassociateWindow(FluxboxWindow *w, unsigned int wkspc_id,
1293 } 1295 }
1294} 1296}
1295 1297
1298#if USE_TOOLBAR
1299
1300void BScreen::clearToolButtonMap() {
1301 m_toolButtonMap->clear();
1302}
1303
1304void BScreen::mapToolButton(std::string name, FbTk::TextButton *button) {
1305 m_toolButtonMap->insert(std::pair<std::string, FbTk::TextButton*>(name, button));
1306}
1307
1308bool BScreen::relabelToolButton(std::string button, std::string label) {
1309 ToolButtonMap::const_iterator it = m_toolButtonMap->find(button);
1310 if (it != m_toolButtonMap->end() && it->second) {
1311 it->second->setText(label);
1312 m_toolbar->relayout();
1313 return true;
1314 }
1315 return false;
1316}
1317
1318#endif
1319
1296void BScreen::initMenus() { 1320void BScreen::initMenus() {
1297 m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber())); 1321 m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber()));
1298 m_rootmenu->reloadHelper()->setMainFile(Fluxbox::instance()->getMenuFilename()); 1322 m_rootmenu->reloadHelper()->setMainFile(Fluxbox::instance()->getMenuFilename());
diff --git a/src/Screen.hh b/src/Screen.hh
index a6aa9fb..f418d0c 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -69,8 +69,10 @@ class Menu;
69class ImageControl; 69class ImageControl;
70class LayerItem; 70class LayerItem;
71class FbWindow; 71class FbWindow;
72class TextButton;
72} 73}
73 74
75typedef std::map<std::string, FbTk::TextButton*> ToolButtonMap;
74 76
75/// Handles screen connection, screen clients and workspaces 77/// Handles screen connection, screen clients and workspaces
76/** 78/**
@@ -343,6 +345,14 @@ public:
343 void reassociateWindow(FluxboxWindow *window, unsigned int workspace_id, 345 void reassociateWindow(FluxboxWindow *window, unsigned int workspace_id,
344 bool ignore_sticky); 346 bool ignore_sticky);
345 347
348#if USE_TOOLBAR
349 /**
350 * manage a map of named FbTk::TextButton's
351 */
352 void clearToolButtonMap();
353 void mapToolButton(std::string name, FbTk::TextButton *button);
354 bool relabelToolButton(std::string button, std::string label);
355#endif
346 356
347 void reconfigure(); 357 void reconfigure();
348 void reconfigureTabs(); 358 void reconfigureTabs();
@@ -489,6 +499,7 @@ private:
489 499
490 std::auto_ptr<Slit> m_slit; 500 std::auto_ptr<Slit> m_slit;
491 std::auto_ptr<Toolbar> m_toolbar; 501 std::auto_ptr<Toolbar> m_toolbar;
502 std::auto_ptr<ToolButtonMap> m_toolButtonMap;
492 503
493 Workspace *m_current_workspace; 504 Workspace *m_current_workspace;
494 505
diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc
index 4a932ea..d1d3581 100644
--- a/src/ToolFactory.cc
+++ b/src/ToolFactory.cc
@@ -119,6 +119,7 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &
119 if (label.empty()) 119 if (label.empty())
120 return 0; 120 return 0;
121 FbTk::TextButton *btn = new FbTk::TextButton(parent, m_button_theme->font(), label); 121 FbTk::TextButton *btn = new FbTk::TextButton(parent, m_button_theme->font(), label);
122 screen().mapToolButton(name, btn);
122 123
123 std::string cmd_str = FbTk::Resource<std::string> 124 std::string cmd_str = FbTk::Resource<std::string>
124 (m_screen.resourceManager(), "", 125 (m_screen.resourceManager(), "",
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index 2920925..3ceb880 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -364,6 +364,12 @@ void Toolbar::screenChanged(BScreen &screen) {
364 reconfigure(); 364 reconfigure();
365} 365}
366 366
367void Toolbar::relayout() {
368 forAll(m_item_list, std::mem_fun(&ToolbarItem::updateSizing));
369 rearrangeItems();
370 forAll(m_item_list, std::bind2nd(std::mem_fun(&ToolbarItem::renderTheme), alpha()));
371}
372
367void Toolbar::reconfigure() { 373void Toolbar::reconfigure() {
368 374
369 updateVisibleState(); 375 updateVisibleState();
@@ -404,6 +410,7 @@ void Toolbar::reconfigure() {
404 410
405 // destroy tools and rebuild them 411 // destroy tools and rebuild them
406 deleteItems(); 412 deleteItems();
413 screen().clearToolButtonMap();
407 // they will be readded later 414 // they will be readded later
408 menu().removeAll(); 415 menu().removeAll();
409 setupMenus(true); // rebuild menu but skip rebuild of placement menu 416 setupMenus(true); // rebuild menu but skip rebuild of placement menu
@@ -489,11 +496,7 @@ void Toolbar::reconfigure() {
489 if (theme()->shape() && m_shape.get()) 496 if (theme()->shape() && m_shape.get())
490 m_shape->update(); 497 m_shape->update();
491 498
492 forAll(m_item_list, std::mem_fun(&ToolbarItem::updateSizing)); 499 relayout();
493
494 rearrangeItems();
495
496 forAll(m_item_list, std::bind2nd(std::mem_fun(&ToolbarItem::renderTheme), alpha()));
497 500
498 // we're done with all resizing and stuff now we can request a new 501 // we're done with all resizing and stuff now we can request a new
499 // area to be reserved on screen 502 // area to be reserved on screen
diff --git a/src/Toolbar.hh b/src/Toolbar.hh
index c31a85f..919b22f 100644
--- a/src/Toolbar.hh
+++ b/src/Toolbar.hh
@@ -53,6 +53,7 @@ class ToolbarItem;
53namespace FbTk { 53namespace FbTk {
54class ImageControl; 54class ImageControl;
55class Shape; 55class Shape;
56class TextButton;
56} 57}
57 58
58/// The toolbar. 59/// The toolbar.
@@ -100,6 +101,7 @@ public:
100 void handleEvent(XEvent &event); 101 void handleEvent(XEvent &event);
101 //@} 102 //@}
102 103
104 void relayout();
103 void reconfigure(); 105 void reconfigure();
104 void setPlacement(Placement where); 106 void setPlacement(Placement where);
105 107
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc
index bdba96c..a642008 100644
--- a/src/WorkspaceCmd.cc
+++ b/src/WorkspaceCmd.cc
@@ -686,3 +686,28 @@ void CloseAllWindowsCmd::execute() {
686 windows.end(), std::mem_fun(&FluxboxWindow::close)); 686 windows.end(), std::mem_fun(&FluxboxWindow::close));
687 687
688} 688}
689
690void RelabelButtonCmd::execute() {
691#if USE_TOOLBAR
692 if (BScreen *screen = Fluxbox::instance()->mouseScreen())
693 screen->relabelToolButton(m_button, m_label);
694#endif
695}
696
697FbTk::Command<void> *RelabelButtonCmd::parse(const std::string &command,
698 const std::string &args, bool trusted) {
699 std::string button, label;
700 std::size_t ws = args.find_first_of(" \t\n");
701 if (ws != std::string::npos) {
702 button = args.substr(0, ws);
703 if (button.find("button.") == 0) {
704 label = args.substr(ws + 1, std::string::npos);
705 } else {
706 button.clear();
707 }
708 }
709 return new RelabelButtonCmd(button, label);
710}
711
712REGISTER_COMMAND_PARSER(relabelbutton, RelabelButtonCmd::parse, void);
713
diff --git a/src/WorkspaceCmd.hh b/src/WorkspaceCmd.hh
index ae0b577..b118d02 100644
--- a/src/WorkspaceCmd.hh
+++ b/src/WorkspaceCmd.hh
@@ -217,4 +217,15 @@ public:
217 void execute(); 217 void execute();
218}; 218};
219 219
220class RelabelButtonCmd: public FbTk::Command<void> {
221public:
222 explicit RelabelButtonCmd(std::string button, std::string label):
223 m_button(button), m_label(label) {}
224 void execute();
225 static FbTk::Command<void> *parse(const std::string &command,
226 const std::string &args, bool trusted);
227private:
228 std::string m_button, m_label;
229};
230
220#endif // WORKSPACECMD_HH 231#endif // WORKSPACECMD_HH