all repos — fluxbox @ fbb2d16639491fdb0c49e388278fabcc4b0800f3

custom fork of the fluxbox windowmanager

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.
Thomas Lübking thomas.luebking@gmail.com
commit

fbb2d16639491fdb0c49e388278fabcc4b0800f3

parent

393ba45f91480bb10f510248837c6051b7ff6a03

M src/Screen.ccsrc/Screen.cc

@@ -392,6 +392,7 @@ if (!m_state.managed)

return; m_toolbar.reset(0); + m_toolButtonMap.reset(0); FbTk::EventManager *evm = FbTk::EventManager::instance(); evm->remove(rootWindow());

@@ -454,6 +455,7 @@ void BScreen::initWindows() {

#ifdef USE_TOOLBAR if (m_opts & Fluxbox::OPT_TOOLBAR) { + m_toolButtonMap.reset(new ToolButtonMap()); Toolbar* tb = new Toolbar(*this, *layerManager().getLayer(::ResourceLayer::NORMAL)); m_toolbar.reset(tb); }

@@ -1292,6 +1294,28 @@ ws->removeWindow(w, true);

getWorkspace(wkspc_id)->addWindow(*w); } } + +#if USE_TOOLBAR + +void BScreen::clearToolButtonMap() { + m_toolButtonMap->clear(); +} + +void BScreen::mapToolButton(std::string name, FbTk::TextButton *button) { + m_toolButtonMap->insert(std::pair<std::string, FbTk::TextButton*>(name, button)); +} + +bool BScreen::relabelToolButton(std::string button, std::string label) { + ToolButtonMap::const_iterator it = m_toolButtonMap->find(button); + if (it != m_toolButtonMap->end() && it->second) { + it->second->setText(label); + m_toolbar->relayout(); + return true; + } + return false; +} + +#endif void BScreen::initMenus() { m_workspacemenu.reset(MenuCreator::createMenuType("workspacemenu", screenNumber()));
M src/Screen.hhsrc/Screen.hh

@@ -69,8 +69,10 @@ class Menu;

class ImageControl; class LayerItem; class FbWindow; +class TextButton; } +typedef std::map<std::string, FbTk::TextButton*> ToolButtonMap; /// Handles screen connection, screen clients and workspaces /**

@@ -343,6 +345,14 @@ */

void reassociateWindow(FluxboxWindow *window, unsigned int workspace_id, bool ignore_sticky); +#if USE_TOOLBAR + /** + * manage a map of named FbTk::TextButton's + */ + void clearToolButtonMap(); + void mapToolButton(std::string name, FbTk::TextButton *button); + bool relabelToolButton(std::string button, std::string label); +#endif void reconfigure(); void reconfigureTabs();

@@ -489,6 +499,7 @@ Icons m_icon_list;

std::auto_ptr<Slit> m_slit; std::auto_ptr<Toolbar> m_toolbar; + std::auto_ptr<ToolButtonMap> m_toolButtonMap; Workspace *m_current_workspace;
M src/ToolFactory.ccsrc/ToolFactory.cc

@@ -119,6 +119,7 @@ m_screen.altName() + ".Toolbar." + name + ".Label");

if (label.empty()) return 0; FbTk::TextButton *btn = new FbTk::TextButton(parent, m_button_theme->font(), label); + screen().mapToolButton(name, btn); std::string cmd_str = FbTk::Resource<std::string> (m_screen.resourceManager(), "",
M src/Toolbar.ccsrc/Toolbar.cc

@@ -364,6 +364,12 @@ void Toolbar::screenChanged(BScreen &screen) {

reconfigure(); } +void Toolbar::relayout() { + forAll(m_item_list, std::mem_fun(&ToolbarItem::updateSizing)); + rearrangeItems(); + forAll(m_item_list, std::bind2nd(std::mem_fun(&ToolbarItem::renderTheme), alpha())); +} + void Toolbar::reconfigure() { updateVisibleState();

@@ -404,6 +410,7 @@ if (need_update) {

// destroy tools and rebuild them deleteItems(); + screen().clearToolButtonMap(); // they will be readded later menu().removeAll(); setupMenus(true); // rebuild menu but skip rebuild of placement menu

@@ -489,11 +496,7 @@

if (theme()->shape() && m_shape.get()) m_shape->update(); - forAll(m_item_list, std::mem_fun(&ToolbarItem::updateSizing)); - - rearrangeItems(); - - forAll(m_item_list, std::bind2nd(std::mem_fun(&ToolbarItem::renderTheme), alpha())); + relayout(); // we're done with all resizing and stuff now we can request a new // area to be reserved on screen
M src/Toolbar.hhsrc/Toolbar.hh

@@ -53,6 +53,7 @@

namespace FbTk { class ImageControl; class Shape; +class TextButton; } /// The toolbar.

@@ -100,6 +101,7 @@ void exposeEvent(XExposeEvent &ee);

void handleEvent(XEvent &event); //@} + void relayout(); void reconfigure(); void setPlacement(Placement where);
M src/WorkspaceCmd.ccsrc/WorkspaceCmd.cc

@@ -686,3 +686,28 @@ std::for_each(windows.begin(),

windows.end(), std::mem_fun(&FluxboxWindow::close)); } + +void RelabelButtonCmd::execute() { +#if USE_TOOLBAR + if (BScreen *screen = Fluxbox::instance()->mouseScreen()) + screen->relabelToolButton(m_button, m_label); +#endif +} + +FbTk::Command<void> *RelabelButtonCmd::parse(const std::string &command, + const std::string &args, bool trusted) { + std::string button, label; + std::size_t ws = args.find_first_of(" \t\n"); + if (ws != std::string::npos) { + button = args.substr(0, ws); + if (button.find("button.") == 0) { + label = args.substr(ws + 1, std::string::npos); + } else { + button.clear(); + } + } + return new RelabelButtonCmd(button, label); +} + +REGISTER_COMMAND_PARSER(relabelbutton, RelabelButtonCmd::parse, void); +
M src/WorkspaceCmd.hhsrc/WorkspaceCmd.hh

@@ -217,4 +217,15 @@ public:

void execute(); }; +class RelabelButtonCmd: public FbTk::Command<void> { +public: + explicit RelabelButtonCmd(std::string button, std::string label): + m_button(button), m_label(label) {} + void execute(); + static FbTk::Command<void> *parse(const std::string &command, + const std::string &args, bool trusted); +private: + std::string m_button, m_label; +}; + #endif // WORKSPACECMD_HH