]> Dogcows Code - chaz/openbox/blob - src/Configmenu.cc
sync with bb-cvs
[chaz/openbox] / src / Configmenu.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Configmenu.cc for Blackbox - An X11 Window Manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #ifdef HAVE_CONFIG_H
25 # include "../config.h"
26 #endif // HAVE_CONFIG_H
27
28 #include "i18n.hh"
29 #include "Configmenu.hh"
30 #include "Image.hh"
31 #include "Toolbar.hh"
32 #include "Window.hh"
33 #include "Screen.hh"
34
35 Configmenu::Configmenu(BScreen *scr) : Basemenu(scr) {
36 setLabel(i18n(ConfigmenuSet, ConfigmenuConfigOptions, "Config options"));
37 setInternalMenu();
38
39 focusmenu = new Focusmenu(this);
40 placementmenu = new Placementmenu(this);
41 windowsnapmenu = new WindowToWindowSnapmenu(this);
42 edgesnapmenu = new WindowToEdgeSnapmenu(this);
43 #ifdef XINERAMA
44 xineramamenu = new Xineramamenu(this);
45 #endif // XINERAMA
46
47 insert(i18n(ConfigmenuSet, ConfigmenuFocusModel,
48 "Focus Model"), focusmenu);
49 insert(i18n(ConfigmenuSet, ConfigmenuWindowPlacement,
50 "Window Placement"), placementmenu);
51 insert(i18n(ConfigmenuSet, ConfigmenuWindowToWindowSnap,
52 "Window-To-Window Snapping"), windowsnapmenu);
53 insert(i18n(ConfigmenuSet, ConfigmenuWindowToEdgeSnap,
54 "Window-To-Edge Snapping"), edgesnapmenu);
55 #ifdef XINERAMA
56 insert(i18n(ConfigmenuSet, ConfigmenuXineramaSupport,
57 "XineramaSupport"), xineramamenu);
58 #endif // XINERAMA
59 insert(i18n(ConfigmenuSet, ConfigmenuImageDithering,
60 "Image Dithering"), 1);
61 insert(i18n(ConfigmenuSet, ConfigmenuOpaqueMove,
62 "Opaque Window Moving"), 2);
63 insert(i18n(ConfigmenuSet, ConfigmenuWorkspaceWarping,
64 "Workspace Warping"), 3);
65 insert(i18n(ConfigmenuSet, ConfigmenuFullMax,
66 "Full Maximization"), 4);
67 insert(i18n(ConfigmenuSet, ConfigmenuFocusNew,
68 "Focus New Windows"), 5);
69 insert(i18n(ConfigmenuSet, ConfigmenuFocusLast,
70 "Focus Last Window on Workspace"), 6);
71 insert(i18n(ConfigmenuSet, ConfigmenuDisableBindings,
72 "Disable Mouse with Scroll Lock"), 7);
73 insert(i18n(ConfigmenuSet, ConfigmenuHideToolbar,
74 "Hide Toolbar"), 8);
75 update();
76 setValues();
77 }
78
79
80 void Configmenu::setValues(void) {
81 int index = 4;
82 #ifdef XINERAMA
83 ++index;
84 #endif // XINERAMA
85 setItemSelected(index++, getScreen()->doImageDither());
86 setItemSelected(index++, getScreen()->doOpaqueMove());
87 setItemSelected(index++, getScreen()->doWorkspaceWarping());
88 setItemSelected(index++, getScreen()->doFullMax());
89 setItemSelected(index++, getScreen()->doFocusNew());
90 setItemSelected(index++, getScreen()->doFocusLast());
91 setItemSelected(index++, getScreen()->allowScrollLock());
92 setItemSelected(index++, getScreen()->doHideToolbar());
93 }
94
95
96 Configmenu::~Configmenu(void) {
97 delete focusmenu;
98 delete placementmenu;
99 delete windowsnapmenu;
100 delete edgesnapmenu;
101 #ifdef XINERAMA
102 delete xineramamenu;
103 #endif // XINERAMA
104 }
105
106
107 void Configmenu::itemSelected(int button, unsigned int index) {
108 if (button != 1)
109 return;
110
111 BasemenuItem *item = find(index);
112
113 if (! item->function())
114 return;
115
116 switch(item->function()) {
117 case 1: // dither
118 getScreen()->saveImageDither(! getScreen()->doImageDither());
119 setItemSelected(index, getScreen()->doImageDither());
120 break;
121
122 case 2: // opaque move
123 getScreen()->saveOpaqueMove(! getScreen()->doOpaqueMove());
124 setItemSelected(index, getScreen()->doOpaqueMove());
125 break;
126
127 case 3: // workspace wrapping
128 getScreen()->saveWorkspaceWarping(! getScreen()->doWorkspaceWarping());
129 setItemSelected(index, getScreen()->doWorkspaceWarping());
130 break;
131
132 case 4: // full maximization
133 getScreen()->saveFullMax(! getScreen()->doFullMax());
134 setItemSelected(index, getScreen()->doFullMax());
135 break;
136
137 case 5: // focus new windows
138 getScreen()->saveFocusNew(! getScreen()->doFocusNew());
139 setItemSelected(index, getScreen()->doFocusNew());
140 break;
141
142 case 6: // focus last window on workspace
143 getScreen()->saveFocusLast(! getScreen()->doFocusLast());
144 setItemSelected(index, getScreen()->doFocusLast());
145 break;
146
147 case 7: // disable mouse bindings with Scroll Lock
148 getScreen()->saveAllowScrollLock(! getScreen()->allowScrollLock());
149 setItemSelected(index, getScreen()->allowScrollLock());
150 getScreen()->reconfigure();
151 break;
152
153 case 8: // hide toolbar
154 getScreen()->saveHideToolbar(! getScreen()->doHideToolbar());
155 setItemSelected(index, getScreen()->doHideToolbar());
156 break;
157 }
158 }
159
160
161 void Configmenu::reconfigure(void) {
162 setValues();
163 focusmenu->reconfigure();
164 placementmenu->reconfigure();
165 windowsnapmenu->reconfigure();
166 edgesnapmenu->reconfigure();
167 #ifdef XINERAMA
168 xineramamenu->reconfigure();
169 #endif // XINERAMA
170
171 Basemenu::reconfigure();
172 }
173
174
175 Configmenu::Focusmenu::Focusmenu(Configmenu *cm) : Basemenu(cm->getScreen()) {
176 setLabel(i18n(ConfigmenuSet, ConfigmenuFocusModel, "Focus Model"));
177 setInternalMenu();
178
179 insert(i18n(ConfigmenuSet, ConfigmenuClickToFocus, "Click To Focus"), 1);
180 insert(i18n(ConfigmenuSet, ConfigmenuSloppyFocus, "Sloppy Focus"), 2);
181 insert(i18n(ConfigmenuSet, ConfigmenuAutoRaise, "Auto Raise"), 3);
182 insert(i18n(ConfigmenuSet, ConfigmenuClickRaise, "Click Raise"), 4);
183 update();
184 setValues();
185 }
186
187
188 void Configmenu::Focusmenu::setValues(void) {
189 setItemSelected(0, ! getScreen()->isSloppyFocus());
190 setItemSelected(1, getScreen()->isSloppyFocus());
191 setItemEnabled(2, getScreen()->isSloppyFocus());
192 setItemSelected(2, getScreen()->doAutoRaise());
193 setItemEnabled(3, getScreen()->isSloppyFocus());
194 setItemSelected(3, getScreen()->doClickRaise());
195 }
196
197
198 void Configmenu::Focusmenu::reconfigure(void) {
199 setValues();
200 Basemenu::reconfigure();
201 }
202
203
204 void Configmenu::Focusmenu::itemSelected(int button, unsigned int index) {
205 if (button != 1)
206 return;
207
208 BasemenuItem *item = find(index);
209
210 if (! item->function())
211 return;
212
213 switch (item->function()) {
214 case 1: // click to focus
215 getScreen()->toggleFocusModel(BScreen::ClickToFocus);
216 break;
217
218 case 2: // sloppy focus
219 getScreen()->toggleFocusModel(BScreen::SloppyFocus);
220 break;
221
222 case 3: // auto raise with sloppy focus
223 getScreen()->saveAutoRaise(! getScreen()->doAutoRaise());
224 break;
225
226 case 4: // click raise with sloppy focus
227 getScreen()->saveClickRaise(! getScreen()->doClickRaise());
228 // make sure the appropriate mouse buttons are grabbed on the windows
229 getScreen()->toggleFocusModel(BScreen::SloppyFocus);
230 break;
231 }
232 setValues();
233 }
234
235
236 Configmenu::Placementmenu::Placementmenu(Configmenu *cm):
237 Basemenu(cm->getScreen()) {
238 setLabel(i18n(ConfigmenuSet, ConfigmenuWindowPlacement, "Window Placement"));
239 setInternalMenu();
240
241 insert(i18n(ConfigmenuSet, ConfigmenuSmartRows, "Smart Placement (Rows)"),
242 BScreen::RowSmartPlacement);
243 insert(i18n(ConfigmenuSet, ConfigmenuSmartCols, "Smart Placement (Columns)"),
244 BScreen::ColSmartPlacement);
245 insert(i18n(ConfigmenuSet, ConfigmenuCascade, "Cascade Placement"),
246 BScreen::CascadePlacement);
247 insert(i18n(ConfigmenuSet, ConfigmenuUnderMouse, "Under Mouse Placement"),
248 BScreen::UnderMousePlacement);
249 insert(i18n(ConfigmenuSet, ConfigmenuClickMouse, "Click Mouse Placement"),
250 BScreen::ClickMousePlacement);
251 insert(i18n(ConfigmenuSet, ConfigmenuLeftRight, "Left to Right"),
252 BScreen::LeftRight);
253 insert(i18n(ConfigmenuSet, ConfigmenuRightLeft, "Right to Left"),
254 BScreen::RightLeft);
255 insert(i18n(ConfigmenuSet, ConfigmenuTopBottom, "Top to Bottom"),
256 BScreen::TopBottom);
257 insert(i18n(ConfigmenuSet, ConfigmenuBottomTop, "Bottom to Top"),
258 BScreen::BottomTop);
259 insert(i18n(ConfigmenuSet, ConfigmenuIgnoreShaded, "Ignore Shaded Windows"),
260 BScreen::IgnoreShaded);
261 insert(i18n(ConfigmenuSet, ConfigmenuIgnoreMax,
262 "Ignore Full-Maximized Windows"),
263 BScreen::IgnoreMaximized);
264 update();
265 setValues();
266 }
267
268
269 void Configmenu::Placementmenu::setValues(void) {
270 int placement = getScreen()->getPlacementPolicy();
271
272 setItemSelected(0, placement == BScreen::RowSmartPlacement);
273 setItemSelected(1, placement == BScreen::ColSmartPlacement);
274 setItemSelected(2, placement == BScreen::CascadePlacement);
275 setItemSelected(3, placement == BScreen::UnderMousePlacement);
276 setItemSelected(4, placement == BScreen::ClickMousePlacement);
277
278 bool rl = (getScreen()->getRowPlacementDirection() == BScreen::LeftRight),
279 tb = (getScreen()->getColPlacementDirection() == BScreen::TopBottom),
280 e = (placement == BScreen::RowSmartPlacement ||
281 placement == BScreen::ColSmartPlacement);
282
283 setItemSelected(5, rl);
284 setItemSelected(6, ! rl);
285 setItemEnabled(5, e);
286 setItemEnabled(6, e);
287
288 setItemSelected(7, tb);
289 setItemSelected(8, ! tb);
290 setItemEnabled(7, e);
291 setItemEnabled(8, e);
292
293 setItemSelected(9, getScreen()->getPlaceIgnoreShaded());
294 setItemSelected(10, getScreen()->getPlaceIgnoreMaximized());
295 setItemEnabled(9, e);
296 setItemEnabled(10, e);
297 }
298
299
300 void Configmenu::Placementmenu::reconfigure(void) {
301 setValues();
302 Basemenu::reconfigure();
303 }
304
305
306 void Configmenu::Placementmenu::itemSelected(int button, unsigned int index) {
307 if (button != 1)
308 return;
309
310 BasemenuItem *item = find(index);
311
312 if (! item->function())
313 return;
314
315 switch (item->function()) {
316 case BScreen::RowSmartPlacement:
317 getScreen()->savePlacementPolicy(item->function());
318 break;
319
320 case BScreen::ColSmartPlacement:
321 getScreen()->savePlacementPolicy(item->function());
322 break;
323
324 case BScreen::CascadePlacement:
325 getScreen()->savePlacementPolicy(item->function());
326 break;
327
328 case BScreen::UnderMousePlacement:
329 getScreen()->savePlacementPolicy(item->function());
330 break;
331
332 case BScreen::ClickMousePlacement:
333 getScreen()->savePlacementPolicy(item->function());
334 break;
335
336 case BScreen::LeftRight:
337 getScreen()->saveRowPlacementDirection(BScreen::LeftRight);
338 break;
339
340 case BScreen::RightLeft:
341 getScreen()->saveRowPlacementDirection(BScreen::RightLeft);
342 break;
343
344 case BScreen::TopBottom:
345 getScreen()->saveColPlacementDirection(BScreen::TopBottom);
346 break;
347
348 case BScreen::BottomTop:
349 getScreen()->saveColPlacementDirection(BScreen::BottomTop);
350 break;
351
352 case BScreen::IgnoreShaded:
353 getScreen()->savePlaceIgnoreShaded(! getScreen()->getPlaceIgnoreShaded());
354 break;
355
356 case BScreen::IgnoreMaximized:
357 getScreen()->
358 savePlaceIgnoreMaximized(! getScreen()->getPlaceIgnoreMaximized());
359 break;
360 }
361 setValues();
362 }
363
364
365 Configmenu::WindowToWindowSnapmenu::WindowToWindowSnapmenu(Configmenu *cm) :
366 Basemenu(cm->getScreen()) {
367 setLabel(i18n(ConfigmenuSet, ConfigmenuWindowToWindowSnap,
368 "Window-To-Window Snapping"));
369 setInternalMenu();
370
371 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoSnapNo, "No Snapping"), 1);
372 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoSnap, "Edge Snapping"), 2);
373 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoResistance,
374 "Edge Resistance"), 3);
375 insert(i18n(ConfigmenuSet, ConfigmenuWindowCornerSnap,
376 "Window Corner Snapping"), 4);
377 update();
378 setValues();
379 }
380
381
382 void Configmenu::WindowToWindowSnapmenu::setValues(void) {
383 setItemSelected(0, (getScreen()->getWindowToWindowSnap() ==
384 BScreen::WindowNoSnap));
385 setItemSelected(1, (getScreen()->getWindowToWindowSnap() ==
386 BScreen::WindowSnap));
387 setItemSelected(2, (getScreen()->getWindowToWindowSnap() ==
388 BScreen::WindowResistance));
389
390 setItemEnabled(3, getScreen()->getWindowToWindowSnap());
391 setItemSelected(3, getScreen()->getWindowCornerSnap());
392 }
393
394
395 void Configmenu::WindowToWindowSnapmenu::reconfigure(void) {
396 setValues();
397 Basemenu::reconfigure();
398 }
399
400
401 void Configmenu::WindowToWindowSnapmenu::itemSelected(int button, unsigned int index) {
402 if (button != 1)
403 return;
404
405 BasemenuItem *item = find(index);
406
407 if (! item->function())
408 return;
409
410 switch (item->function()) {
411 case 1: // none
412 getScreen()->saveWindowToWindowSnap(BScreen::WindowNoSnap);
413 break;
414
415 case 2: // edge snapping
416 getScreen()->saveWindowToWindowSnap(BScreen::WindowSnap);
417 break;
418
419 case 3: // edge resistance
420 getScreen()->saveWindowToWindowSnap(BScreen::WindowResistance);
421 break;
422
423 case 4: // window corner snapping
424 getScreen()->saveWindowCornerSnap(! getScreen()->getWindowCornerSnap());
425 break;
426
427 }
428 setValues();
429 }
430
431
432 Configmenu::WindowToEdgeSnapmenu::WindowToEdgeSnapmenu(Configmenu *cm) :
433 Basemenu(cm->getScreen()) {
434 setLabel(i18n(ConfigmenuSet, ConfigmenuWindowToEdgeSnap,
435 "Window-To-Edge Snapping"));
436 setInternalMenu();
437
438 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoSnapNo, "No Snapping"), 1);
439 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoSnap, "Edge Snapping"), 2);
440 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoResistance,
441 "Edge Resistance"), 3);
442 update();
443 setValues();
444 }
445
446
447 void Configmenu::WindowToEdgeSnapmenu::setValues(void) {
448 setItemSelected(0, (getScreen()->getWindowToEdgeSnap() ==
449 BScreen::WindowNoSnap));
450 setItemSelected(1, (getScreen()->getWindowToEdgeSnap() ==
451 BScreen::WindowSnap));
452 setItemSelected(2, (getScreen()->getWindowToEdgeSnap() ==
453 BScreen::WindowResistance));
454 }
455
456
457 void Configmenu::WindowToEdgeSnapmenu::reconfigure(void) {
458 setValues();
459 Basemenu::reconfigure();
460 }
461
462
463 void Configmenu::WindowToEdgeSnapmenu::itemSelected(int button, unsigned int index) {
464 if (button != 1)
465 return;
466
467 BasemenuItem *item = find(index);
468
469 if (! item->function())
470 return;
471
472 switch (item->function()) {
473 case 1: // none
474 getScreen()->saveWindowToEdgeSnap(BScreen::WindowNoSnap);
475 break;
476
477 case 2: // edge snapping
478 getScreen()->saveWindowToEdgeSnap(BScreen::WindowSnap);
479 break;
480
481 case 3: // edge resistance
482 getScreen()->saveWindowToEdgeSnap(BScreen::WindowResistance);
483 break;
484 }
485 setValues();
486 }
487
488
489 #ifdef XINERAMA
490 Configmenu::Xineramamenu::Xineramamenu(Configmenu *cm):
491 Basemenu(cm->getScreen()) {
492 setLabel(i18n(ConfigmenuSet, ConfigmenuXineramaSupport, "Xinerama Support"));
493 setInternalMenu();
494
495 insert(i18n(ConfigmenuSet, ConfigmenuXineramaPlacement, "Window Placement"),
496 1);
497 insert(i18n(ConfigmenuSet, ConfigmenuXineramaMaximizing, "Window Maximizing"),
498 2);
499 insert(i18n(ConfigmenuSet, ConfigmenuXineramaSnapping, "Window Snapping"),
500 3);
501
502 update();
503 setValues();
504 }
505
506
507 void Configmenu::Xineramamenu::setValues(void) {
508 setItemSelected(0, getScreen()->getBlackbox()->doXineramaPlacement());
509 setItemSelected(1, getScreen()->getBlackbox()->doXineramaMaximizing());
510 setItemSelected(2, getScreen()->getBlackbox()->doXineramaSnapping());
511 }
512
513
514 void Configmenu::Xineramamenu::reconfigure(void) {
515 setValues();
516 Basemenu::reconfigure();
517 }
518
519
520 void Configmenu::Xineramamenu::itemSelected(int button, unsigned int index) {
521 if (button != 1)
522 return;
523
524 BasemenuItem *item = find(index);
525
526 if (! item->function())
527 return;
528
529 Blackbox *bb = getScreen()->getBlackbox();
530
531 switch (item->function()) {
532 case 1: // window placement
533 bb->saveXineramaPlacement(! bb->doXineramaPlacement());
534 setItemSelected(0, bb->doXineramaPlacement());
535 break;
536
537 case 2: // window maximizing
538 bb->saveXineramaMaximizing(! bb->doXineramaMaximizing());
539 setItemSelected(1, bb->doXineramaMaximizing());
540 break;
541
542 case 3: // window snapping
543 bb->saveXineramaSnapping(! bb->doXineramaSnapping());
544 setItemSelected(2, bb->doXineramaSnapping());
545 break;
546 }
547 }
548 #endif // XINERAMA
This page took 0.062631 seconds and 4 git commands to generate.