diff options
Diffstat (limited to 'src/SendToMenu.cc')
-rw-r--r-- | src/SendToMenu.cc | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/SendToMenu.cc b/src/SendToMenu.cc new file mode 100644 index 0000000..825ed36 --- /dev/null +++ b/src/SendToMenu.cc | |||
@@ -0,0 +1,102 @@ | |||
1 | // SendToMenu.cc for Fluxbox | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // and Simon Bowden (rathnor at users.sourceforge.net) | ||
4 | // | ||
5 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
6 | // copy of this software and associated documentation files (the "Software"), | ||
7 | // to deal in the Software without restriction, including without limitation | ||
8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
9 | // and/or sell copies of the Software, and to permit persons to whom the | ||
10 | // Software is furnished to do so, subject to the following conditions: | ||
11 | // | ||
12 | // The above copyright notice and this permission notice shall be included in | ||
13 | // all copies or substantial portions of the Software. | ||
14 | // | ||
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
21 | // DEALINGS IN THE SOFTWARE. | ||
22 | |||
23 | // $Id: SendToMenu.cc,v 1.7 2003/12/18 18:03:21 fluxgen Exp $ | ||
24 | |||
25 | #include "SendToMenu.hh" | ||
26 | |||
27 | #include "Window.hh" | ||
28 | #include "Screen.hh" | ||
29 | #include "fluxbox.hh" | ||
30 | #include "Workspace.hh" | ||
31 | |||
32 | #include "FbTk/Command.hh" | ||
33 | |||
34 | class SendToCmd: public FbTk::Command { | ||
35 | public: | ||
36 | SendToCmd(FluxboxWindow &win, int workspace): | ||
37 | m_win(win), | ||
38 | m_workspace(workspace) { } | ||
39 | void execute() { | ||
40 | m_win.screen().sendToWorkspace(m_workspace, &m_win, false); | ||
41 | } | ||
42 | private: | ||
43 | FluxboxWindow &m_win; | ||
44 | const int m_workspace; | ||
45 | }; | ||
46 | |||
47 | SendToMenu::SendToMenu(FluxboxWindow &win): | ||
48 | FbMenu(win.screen().menuTheme(), | ||
49 | win.screen().imageControl(), | ||
50 | *win.screen().layerManager().getLayer(Fluxbox::instance()->getMenuLayer())), | ||
51 | m_win(win) { | ||
52 | // listen to: | ||
53 | // workspace count signal | ||
54 | // workspace names signal | ||
55 | // current workspace signal | ||
56 | // and window's workspace sig | ||
57 | win.screen().workspaceCountSig().attach(this); | ||
58 | win.screen().workspaceNamesSig().attach(this); | ||
59 | win.screen().currentWorkspaceSig().attach(this); | ||
60 | win.workspaceSig().attach(this); | ||
61 | |||
62 | disableTitle(); | ||
63 | // build menu | ||
64 | update(0); | ||
65 | } | ||
66 | |||
67 | void SendToMenu::update(FbTk::Subject *subj) { | ||
68 | if (subj != 0) { | ||
69 | // if workspace changed we enable all workspaces except the current one | ||
70 | if (subj == &(m_win.screen().currentWorkspaceSig()) || | ||
71 | subj == &(m_win.workspaceSig())) { | ||
72 | // enabled all workspaces | ||
73 | const BScreen::Workspaces &wlist = m_win.screen().getWorkspacesList(); | ||
74 | for (size_t i = 0; i < wlist.size(); ++i) | ||
75 | setItemEnabled(i, true); | ||
76 | // disable send to on the workspace which the window exist | ||
77 | setItemEnabled(m_win.workspaceNumber(), false); | ||
78 | FbMenu::update(); | ||
79 | // we're done | ||
80 | return; | ||
81 | } else if (subj == &(theme().reconfigSig())) { | ||
82 | // we got reconfig Theme signal, let base menu handle it | ||
83 | FbTk::Menu::update(subj); | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | } | ||
88 | // rebuild menu | ||
89 | |||
90 | removeAll(); | ||
91 | |||
92 | const BScreen::Workspaces &wlist = m_win.screen().getWorkspacesList(); | ||
93 | for (size_t i = 0; i < wlist.size(); ++i) { | ||
94 | FbTk::RefCount<FbTk::Command> sendto_cmd(new SendToCmd(m_win, i)); | ||
95 | insert(wlist[i]->name().c_str(), sendto_cmd); | ||
96 | |||
97 | } | ||
98 | |||
99 | setItemEnabled(m_win.workspaceNumber(), false); | ||
100 | |||
101 | FbMenu::update(); | ||
102 | } | ||