aboutsummaryrefslogtreecommitdiff
path: root/src/ClientMenu.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/ClientMenu.cc')
-rw-r--r--src/ClientMenu.cc58
1 files changed, 39 insertions, 19 deletions
diff --git a/src/ClientMenu.cc b/src/ClientMenu.cc
index 71f322c..02df7e4 100644
--- a/src/ClientMenu.cc
+++ b/src/ClientMenu.cc
@@ -37,10 +37,13 @@ public:
37 ClientMenuItem(Focusable &client, ClientMenu &menu): 37 ClientMenuItem(Focusable &client, ClientMenu &menu):
38 FbTk::MenuItem(client.title().c_str(), menu), 38 FbTk::MenuItem(client.title().c_str(), menu),
39 m_client(client) { 39 m_client(client) {
40 client.titleSig().attach(&menu); 40 m_signals.join(client.titleSig(),
41 client.dieSig().attach(&menu); 41 FbTk::MemFunSelectArg1(menu, &ClientMenu::titleChanged));
42 } 42 client.dieSig().attach(&menu);
43 ~ClientMenuItem() { m_client.titleSig().detach(menu()); } 43 }
44
45 ~ClientMenuItem() {
46 }
44 47
45 void click(int button, int time, unsigned int mods) { 48 void click(int button, int time, unsigned int mods) {
46 FluxboxWindow *fbwin = m_client.fbwindow(); 49 FluxboxWindow *fbwin = m_client.fbwindow();
@@ -75,6 +78,7 @@ public:
75 78
76private: 79private:
77 Focusable &m_client; 80 Focusable &m_client;
81 FbTk::SignalTracker m_signals;
78}; 82};
79 83
80} // end anonymous namespace 84} // end anonymous namespace
@@ -118,30 +122,46 @@ void ClientMenu::refreshMenu() {
118 updateMenu(); 122 updateMenu();
119} 123}
120 124
125namespace {
126
127ClientMenuItem* getMenuItem(ClientMenu& menu, Focusable& win) {
128 // find the corresponding menuitem
129 ClientMenuItem *cl_item = 0;
130 for (size_t i = 0; i < menu.numberOfItems(); i++) {
131 FbTk::MenuItem *item = menu.find(i);
132 if (item && typeid(*item) == typeid(ClientMenuItem)) {
133 cl_item = static_cast<ClientMenuItem *>(item);
134 if (cl_item->client() == &win)
135 break;
136 }
137 }
138
139 return cl_item;
140
141}
142
143} // anonymous
144
145void ClientMenu::titleChanged(Focusable& win) {
146 // find correct menu item
147 ClientMenuItem* cl_item = getMenuItem(*this, win);
148 if (cl_item)
149 FbTk::Menu::update(0);
150}
151
121void ClientMenu::update(FbTk::Subject *subj) { 152void ClientMenu::update(FbTk::Subject *subj) {
122 if (subj && typeid(*subj) == typeid(Focusable::FocusSubject)) { 153 if (subj && typeid(*subj) == typeid(Focusable::FocusSubject)) {
123 154
124 Focusable::FocusSubject *fsubj = static_cast<Focusable::FocusSubject *>(subj); 155 Focusable::FocusSubject *fsubj = static_cast<Focusable::FocusSubject *>(subj);
125 Focusable &win = fsubj->win(); 156 Focusable &win = fsubj->win();
126 157
127 // find the corresponding menuitem 158 // find correct menu item
128 ClientMenuItem *cl_item = 0; 159 ClientMenuItem* cl_item = getMenuItem(*this, win);
129 for (size_t i = 0; i < numberOfItems(); i++) {
130 FbTk::MenuItem *item = find(i);
131 if (item && typeid(*item) == typeid(ClientMenuItem)) {
132 cl_item = static_cast<ClientMenuItem *>(item);
133 if (cl_item->client() == &win)
134 break;
135 }
136 }
137 160
138 // update accordingly 161 // update accordingly
139 if (cl_item && fsubj == &win.dieSig()) 162 if (cl_item && fsubj == &win.dieSig()) {
140 remove(cl_item->getIndex()); 163 remove(cl_item->getIndex());
141 else if (cl_item && fsubj == &win.titleSig()) 164 }
142 // this could change the size of the menu, so do a full update
143 FbTk::Menu::update(subj);
144
145 } else 165 } else
146 FbTk::Menu::update(subj); 166 FbTk::Menu::update(subj);
147} 167}