aboutsummaryrefslogtreecommitdiff
path: root/src/Workspace.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Workspace.cc')
-rw-r--r--src/Workspace.cc118
1 files changed, 6 insertions, 112 deletions
diff --git a/src/Workspace.cc b/src/Workspace.cc
index 66dd4a6..e65a89f 100644
--- a/src/Workspace.cc
+++ b/src/Workspace.cc
@@ -30,13 +30,10 @@
30#include "Window.hh" 30#include "Window.hh"
31#include "WinClient.hh" 31#include "WinClient.hh"
32#include "FbWinFrame.hh" 32#include "FbWinFrame.hh"
33#include "WindowCmd.hh"
34#include "FocusControl.hh" 33#include "FocusControl.hh"
35#include "PlacementStrategy.hh" 34#include "PlacementStrategy.hh"
36#include "Layer.hh"
37 35
38#include "FbTk/I18n.hh" 36#include "FbTk/I18n.hh"
39#include "FbTk/MenuItem.hh"
40#include "FbTk/StringUtil.hh" 37#include "FbTk/StringUtil.hh"
41#include "FbTk/FbString.hh" 38#include "FbTk/FbString.hh"
42 39
@@ -65,7 +62,6 @@
65 62
66#include <algorithm> 63#include <algorithm>
67#include <iostream> 64#include <iostream>
68#include <iterator>
69 65
70using std::string; 66using std::string;
71using std::vector; 67using std::vector;
@@ -76,83 +72,11 @@ using std::cerr;
76using std::endl; 72using std::endl;
77#endif // DEBUG 73#endif // DEBUG
78 74
79namespace { // anonymous
80
81int countTransients(const WinClient &client) {
82 if (client.transientList().empty())
83 return 0;
84 // now go throu the entire tree and count transients
85 size_t ret = client.transientList().size();
86 WinClient::TransientList::const_iterator it = client.transientList().begin();
87 WinClient::TransientList::const_iterator it_end = client.transientList().end();
88 for (; it != it_end; ++it)
89 ret += countTransients(*(*it));
90
91 return ret;
92}
93
94class ClientMenuItem:public FbTk::MenuItem {
95public:
96 ClientMenuItem(WinClient &client):
97 FbTk::MenuItem(client.title().c_str(), &client.screen().windowMenu()),
98 m_client(client) {
99
100 }
101 FbTk::Menu *submenu() { return &m_client.screen().windowMenu(); }
102 const FbTk::Menu *submenu() const { return &m_client.screen().windowMenu(); }
103
104 void showSubmenu() {
105 WindowCmd<void>::setClient(&m_client);
106 FbTk::MenuItem::showSubmenu();
107 }
108
109 void click(int button, int time) {
110 if (m_client.fbwindow() == 0)
111 return;
112 FluxboxWindow &win = *m_client.fbwindow();
113
114 if (win.screen().currentWorkspaceID() != win.workspaceNumber() &&
115 !win.isStuck()) {
116 win.menu().hide();
117 BScreen::FollowModel model = win.screen().getUserFollowModel();
118 if (model == BScreen::IGNORE_OTHER_WORKSPACES)
119 return;
120 // fetch the window to the current workspace
121 else if ((button == 3) ^ (model == BScreen::FETCH_ACTIVE_WINDOW ||
122 win.isIconic() && model == BScreen::SEMIFOLLOW_ACTIVE_WINDOW)) {
123 win.screen().sendToWorkspace(win.screen().currentWorkspaceID(), &win, true);
124 return;
125 }
126 // warp to the workspace of the window
127 win.screen().changeWorkspaceID(win.workspaceNumber());
128 }
129 win.setCurrentClient(m_client);
130 win.raiseAndFocus();
131 }
132
133 const string &label() const { return m_client.title(); }
134 bool isSelected() const {
135 if (m_client.fbwindow() == 0)
136 return false;
137 if (m_client.fbwindow()->isFocused() == false)
138 return false;
139 return (&(m_client.fbwindow()->winClient()) == &m_client);
140
141 }
142private:
143 WinClient &m_client;
144};
145
146};
147
148Workspace::GroupList Workspace::m_groups; 75Workspace::GroupList Workspace::m_groups;
149 76
150Workspace::Workspace(BScreen &scrn, FbTk::MultLayers &layermanager, 77Workspace::Workspace(BScreen &scrn, const string &name, unsigned int id):
151 const string &name, unsigned int id):
152 m_screen(scrn), 78 m_screen(scrn),
153 m_clientmenu(scrn.menuTheme(), scrn.imageControl(), 79 m_clientmenu(scrn, m_windowlist, &m_clientlist_sig),
154 *scrn.layerManager().getLayer(Layer::MENU)),
155 m_layermanager(layermanager),
156 m_name(name), 80 m_name(name),
157 m_id(id) { 81 m_id(id) {
158 82
@@ -171,14 +95,12 @@ void Workspace::addWindow(FluxboxWindow &w, bool place) {
171 return; 95 return;
172 96
173 w.setWorkspace(m_id); 97 w.setWorkspace(m_id);
174 // attach signals
175 w.titleSig().attach(this);
176 98
177 if (place) 99 if (place)
178 placeWindow(w); 100 placeWindow(w);
179 101
180 m_windowlist.push_back(&w); 102 m_windowlist.push_back(&w);
181 updateClientmenu(); 103 m_clientlist_sig.notify();
182 104
183 if (!w.isStuck()) { 105 if (!w.isStuck()) {
184 FluxboxWindow::ClientList::iterator client_it = 106 FluxboxWindow::ClientList::iterator client_it =
@@ -200,19 +122,11 @@ int Workspace::removeWindow(FluxboxWindow *w, bool still_alive) {
200 if (w == 0) 122 if (w == 0)
201 return -1; 123 return -1;
202 124
203 // detach from signals
204 w->titleSig().detach(this);
205
206 if (w->isFocused() && still_alive) 125 if (w->isFocused() && still_alive)
207 FocusControl::unfocusWindow(w->winClient(), true, true); 126 FocusControl::unfocusWindow(w->winClient(), true, true);
208 127
209 // we don't remove it from the layermanager, as it may be being moved 128 m_windowlist.remove(w);
210 Windows::iterator erase_it = remove(m_windowlist.begin(), 129 m_clientlist_sig.notify();
211 m_windowlist.end(), w);
212 if (erase_it != m_windowlist.end())
213 m_windowlist.erase(erase_it);
214
215 updateClientmenu();
216 130
217 if (!w->isStuck()) { 131 if (!w->isStuck()) {
218 FluxboxWindow::ClientList::iterator client_it = 132 FluxboxWindow::ClientList::iterator client_it =
@@ -361,11 +275,6 @@ bool Workspace::loadGroups(const string &filename) {
361 return true; 275 return true;
362} 276}
363 277
364void Workspace::update(FbTk::Subject *subj) {
365 updateClientmenu();
366}
367
368
369void Workspace::setName(const string &name) { 278void Workspace::setName(const string &name) {
370 if (!name.empty() && name != "") { 279 if (!name.empty() && name != "") {
371 m_name = name; 280 m_name = name;
@@ -399,22 +308,7 @@ void Workspace::shutdown() {
399} 308}
400 309
401void Workspace::updateClientmenu() { 310void Workspace::updateClientmenu() {
402 // remove all items and then add them again 311 m_clientlist_sig.notify();
403 menu().removeAll();
404 // for each fluxboxwindow add every client in them to our clientlist
405 Windows::iterator win_it = m_windowlist.begin();
406 Windows::iterator win_it_end = m_windowlist.end();
407 for (; win_it != win_it_end; ++win_it) {
408 // add every client in this fluxboxwindow to menu
409 FluxboxWindow::ClientList::iterator client_it =
410 (*win_it)->clientList().begin();
411 FluxboxWindow::ClientList::iterator client_it_end =
412 (*win_it)->clientList().end();
413 for (; client_it != client_it_end; ++client_it)
414 menu().insert(new ClientMenuItem(*(*client_it)));
415 }
416
417 menu().updateMenu();
418} 312}
419 313
420void Workspace::placeWindow(FluxboxWindow &win) { 314void Workspace::placeWindow(FluxboxWindow &win) {