diff options
author | fluxgen <fluxgen> | 2001-12-11 20:47:02 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2001-12-11 20:47:02 (GMT) |
commit | 18830ac9add80cbd3bf7369307d7e35a519dca9b (patch) | |
tree | 4759a5434a34ba317fe77bbf8b0ed9bb57bb6018 /src/Windowmenu.cc | |
parent | 1523b48bff07dead084af3064ad11c79a9b25df0 (diff) | |
download | fluxbox_pavel-18830ac9add80cbd3bf7369307d7e35a519dca9b.zip fluxbox_pavel-18830ac9add80cbd3bf7369307d7e35a519dca9b.tar.bz2 |
Initial revision
Diffstat (limited to 'src/Windowmenu.cc')
-rw-r--r-- | src/Windowmenu.cc | 323 |
1 files changed, 323 insertions, 0 deletions
diff --git a/src/Windowmenu.cc b/src/Windowmenu.cc new file mode 100644 index 0000000..159f090 --- /dev/null +++ b/src/Windowmenu.cc | |||
@@ -0,0 +1,323 @@ | |||
1 | // Windowmenu.cc for Blackbox - an X11 Window manager | ||
2 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // stupid macros needed to access some functions in version 2 of the GNU C | ||
23 | // library | ||
24 | #ifndef _GNU_SOURCE | ||
25 | #define _GNU_SOURCE | ||
26 | #endif // _GNU_SOURCE | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | # include "../config.h" | ||
30 | #endif // HAVE_CONFIG_H | ||
31 | |||
32 | #include "i18n.hh" | ||
33 | #include "fluxbox.hh" | ||
34 | #include "Screen.hh" | ||
35 | #include "Window.hh" | ||
36 | #include "Windowmenu.hh" | ||
37 | #include "Workspace.hh" | ||
38 | |||
39 | #ifdef STDC_HEADERS | ||
40 | # include <string.h> | ||
41 | #endif // STDC_HEADERS | ||
42 | |||
43 | |||
44 | Windowmenu::Windowmenu(FluxboxWindow *win) : Basemenu(win->getScreen()) { | ||
45 | window = win; | ||
46 | screen = window->getScreen(); | ||
47 | |||
48 | setTitleVisibility(False); | ||
49 | setMovable(False); | ||
50 | setInternalMenu(); | ||
51 | |||
52 | I18n *i18n = I18n::instance(); | ||
53 | |||
54 | sendToMenu = new SendtoWorkspacemenu(this); | ||
55 | sendGroupToMenu = new SendGroupToWorkspacemenu(this); | ||
56 | |||
57 | insert(i18n->getMessage( | ||
58 | #ifdef NLS | ||
59 | WindowmenuSet, WindowmenuSendTo, | ||
60 | #else // !NLS | ||
61 | 0, 0, | ||
62 | #endif // NLS | ||
63 | "Send To ..."), | ||
64 | sendToMenu); | ||
65 | |||
66 | insert(i18n->getMessage( | ||
67 | #ifdef NLS | ||
68 | WindowmenuSet, WindowmenuSendGroupTo, | ||
69 | #else // !NLS | ||
70 | 0, 0, | ||
71 | #endif // NLS | ||
72 | "Send Group To ..."), | ||
73 | sendGroupToMenu); | ||
74 | |||
75 | insert(i18n->getMessage( | ||
76 | #ifdef NLS | ||
77 | WindowmenuSet, WindowmenuShade, | ||
78 | #else // !NLS | ||
79 | 0, 0, | ||
80 | #endif // NLS | ||
81 | "Shade"), | ||
82 | BScreen::WindowShade); | ||
83 | insert(i18n->getMessage( | ||
84 | #ifdef NLS | ||
85 | WindowmenuSet, WindowmenuIconify, | ||
86 | #else // !NLS | ||
87 | 0, 0, | ||
88 | #endif // NLS | ||
89 | "Iconify"), | ||
90 | BScreen::WindowIconify); | ||
91 | insert(i18n->getMessage( | ||
92 | #ifdef NLS | ||
93 | WindowmenuSet, WindowmenuMaximize, | ||
94 | #else // !NLS | ||
95 | 0, 0, | ||
96 | #endif // NLS | ||
97 | "Maximize"), | ||
98 | BScreen::WindowMaximize); | ||
99 | insert(i18n->getMessage( | ||
100 | #ifdef NLS | ||
101 | WindowmenuSet, WindowmenuRaise, | ||
102 | #else // !NLS | ||
103 | 0, 0, | ||
104 | #endif // NLS | ||
105 | "Raise"), | ||
106 | BScreen::WindowRaise); | ||
107 | insert(i18n->getMessage( | ||
108 | #ifdef NLS | ||
109 | WindowmenuSet, WindowmenuLower, | ||
110 | #else // !NLS | ||
111 | 0, 0, | ||
112 | #endif // NLS | ||
113 | "Lower"), | ||
114 | BScreen::WindowLower); | ||
115 | insert(i18n->getMessage( | ||
116 | #ifdef NLS | ||
117 | WindowmenuSet, WindowmenuStick, | ||
118 | #else // !NLS | ||
119 | 0, 0, | ||
120 | #endif // NLS | ||
121 | "Stick"), | ||
122 | BScreen::WindowStick); | ||
123 | insert(i18n->getMessage( | ||
124 | #ifdef NLS | ||
125 | WindowmenuSet, WindowmenuKillClient, | ||
126 | #else // !NLS | ||
127 | 0, 0, | ||
128 | #endif // NLS | ||
129 | "Kill Client"), | ||
130 | BScreen::WindowKill); | ||
131 | insert(i18n->getMessage( | ||
132 | #ifdef NLS | ||
133 | WindowmenuSet, WindowmenuClose, | ||
134 | #else // !NLS | ||
135 | 0, 0, | ||
136 | #endif // NLS | ||
137 | "Close"), | ||
138 | BScreen::WindowClose); | ||
139 | |||
140 | //TODO: nls | ||
141 | insert("Tab", BScreen::WindowTab); | ||
142 | |||
143 | update(); | ||
144 | |||
145 | setItemEnabled(1, window->hasTitlebar()); | ||
146 | setItemEnabled(2, window->isIconifiable()); | ||
147 | setItemEnabled(3, window->isMaximizable()); | ||
148 | setItemEnabled(8, window->isClosable()); | ||
149 | setItemEnabled(9, window->hasTab()); | ||
150 | } | ||
151 | |||
152 | |||
153 | Windowmenu::~Windowmenu(void) { | ||
154 | delete sendToMenu; | ||
155 | delete sendGroupToMenu; | ||
156 | } | ||
157 | |||
158 | |||
159 | void Windowmenu::show(void) { | ||
160 | if (isItemEnabled(1)) setItemSelected(1, window->isShaded()); | ||
161 | if (isItemEnabled(3)) setItemSelected(3, window->isMaximized()); | ||
162 | if (isItemEnabled(6)) setItemSelected(6, window->isStuck()); | ||
163 | |||
164 | Basemenu::show(); | ||
165 | } | ||
166 | |||
167 | |||
168 | void Windowmenu::itemSelected(int button, int index) { | ||
169 | BasemenuItem *item = find(index); | ||
170 | |||
171 | switch (item->function()) { | ||
172 | case BScreen::WindowShade: | ||
173 | hide(); | ||
174 | if (window->getTab()) | ||
175 | window->getTab()->shade(); | ||
176 | window->shade(); | ||
177 | break; | ||
178 | |||
179 | case BScreen::WindowIconify: | ||
180 | hide(); | ||
181 | window->iconify(); | ||
182 | break; | ||
183 | |||
184 | case BScreen::WindowMaximize: | ||
185 | hide(); | ||
186 | window->maximize((unsigned int) button); | ||
187 | break; | ||
188 | |||
189 | case BScreen::WindowClose: | ||
190 | hide(); | ||
191 | window->close(); | ||
192 | break; | ||
193 | |||
194 | case BScreen::WindowRaise: | ||
195 | hide(); | ||
196 | screen->getWorkspace(window->getWorkspaceNumber())->raiseWindow(window); | ||
197 | break; | ||
198 | |||
199 | case BScreen::WindowLower: | ||
200 | hide(); | ||
201 | screen->getWorkspace(window->getWorkspaceNumber())->lowerWindow(window); | ||
202 | break; | ||
203 | |||
204 | case BScreen::WindowStick: | ||
205 | hide(); | ||
206 | window->stick(); | ||
207 | break; | ||
208 | |||
209 | case BScreen::WindowKill: | ||
210 | hide(); | ||
211 | XKillClient(screen->getBaseDisplay()->getXDisplay(), | ||
212 | window->getClientWindow()); | ||
213 | break; | ||
214 | case BScreen::WindowTab: | ||
215 | hide(); | ||
216 | window->setTab(!window->hasTab()); | ||
217 | break; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | |||
222 | void Windowmenu::reconfigure(void) { | ||
223 | setItemEnabled(1, window->hasTitlebar()); | ||
224 | setItemEnabled(2, window->isIconifiable()); | ||
225 | setItemEnabled(3, window->isMaximizable()); | ||
226 | setItemEnabled(8, window->isClosable()); | ||
227 | |||
228 | sendToMenu->reconfigure(); | ||
229 | sendGroupToMenu->reconfigure(); | ||
230 | |||
231 | Basemenu::reconfigure(); | ||
232 | } | ||
233 | |||
234 | |||
235 | Windowmenu::SendtoWorkspacemenu::SendtoWorkspacemenu(Windowmenu *w) | ||
236 | : Basemenu(w->screen) | ||
237 | { | ||
238 | windowmenu = w; | ||
239 | |||
240 | setTitleVisibility(False); | ||
241 | setMovable(False); | ||
242 | setInternalMenu(); | ||
243 | update(); | ||
244 | } | ||
245 | |||
246 | |||
247 | void Windowmenu::SendtoWorkspacemenu::itemSelected(int button, int index) { | ||
248 | if (button > 2) return; | ||
249 | |||
250 | if (index <= windowmenu->screen->getCount()) { | ||
251 | if (index == windowmenu->screen->getCurrentWorkspaceID()) return; | ||
252 | if (windowmenu->window->isStuck()) windowmenu->window->stick(); | ||
253 | |||
254 | if (button == 1) windowmenu->window->withdraw(); | ||
255 | windowmenu->screen->reassociateWindow(windowmenu->window, index, True); | ||
256 | if (windowmenu->window->getTab()) { | ||
257 | windowmenu->window->getTab()->disconnect(); | ||
258 | windowmenu->window->getTab()->setPosition(); | ||
259 | } | ||
260 | if (button == 2) windowmenu->screen->changeWorkspaceID(index); | ||
261 | } | ||
262 | hide(); | ||
263 | } | ||
264 | |||
265 | |||
266 | void Windowmenu::SendtoWorkspacemenu::update(void) { | ||
267 | int i, r = getCount(); | ||
268 | |||
269 | if (getCount() != 0) | ||
270 | for (i = 0; i < r; ++i) | ||
271 | remove(0); | ||
272 | |||
273 | for (i = 0; i < windowmenu->screen->getCount(); ++i) | ||
274 | insert(windowmenu->screen->getWorkspace(i)->getName()); | ||
275 | |||
276 | Basemenu::update(); | ||
277 | } | ||
278 | |||
279 | |||
280 | void Windowmenu::SendtoWorkspacemenu::show(void) { | ||
281 | update(); | ||
282 | |||
283 | Basemenu::show(); | ||
284 | } | ||
285 | |||
286 | void Windowmenu::SendGroupToWorkspacemenu::itemSelected(int button, int index) { | ||
287 | if (button > 2) | ||
288 | return; | ||
289 | |||
290 | if (index <= getWindowMenu()->screen->getCount()) { | ||
291 | if (index == getWindowMenu()->screen->getCurrentWorkspaceID()) | ||
292 | return; | ||
293 | if (getWindowMenu()->window->isStuck()) | ||
294 | getWindowMenu()->window->stick(); | ||
295 | |||
296 | if (button == 1) { | ||
297 | if (getWindowMenu()->window->hasTab()) { | ||
298 | for (Tab *first = Tab::getFirst(getWindowMenu()->window->getTab()); | ||
299 | first!=0; first=first->next()) { | ||
300 | first->withdraw(); | ||
301 | first->getWindow()->withdraw(); | ||
302 | getWindowMenu()->screen->reassociateWindow(first->getWindow(), index, True); | ||
303 | |||
304 | } | ||
305 | } else { | ||
306 | getWindowMenu()->window->withdraw(); | ||
307 | getWindowMenu()->screen->reassociateWindow(getWindowMenu()->window, index, True); | ||
308 | } | ||
309 | |||
310 | } | ||
311 | |||
312 | if (button == 2) | ||
313 | getWindowMenu()->screen->changeWorkspaceID(index); | ||
314 | } | ||
315 | hide(); | ||
316 | } | ||
317 | |||
318 | Windowmenu::SendGroupToWorkspacemenu::SendGroupToWorkspacemenu(Windowmenu *w):SendtoWorkspacemenu(w) | ||
319 | { | ||
320 | |||
321 | } | ||
322 | |||
323 | |||