]> Dogcows Code - chaz/openbox/blob - src/Configmenu.cc
had an extra window placement menu
[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::UnderMousePlacement;
281
282 setItemSelected(5, rl);
283 setItemSelected(6, ! rl);
284 setItemEnabled(5, e);
285 setItemEnabled(6, e);
286
287 setItemSelected(7, tb);
288 setItemSelected(8, ! tb);
289 setItemEnabled(7, e);
290 setItemEnabled(8, e);
291
292 setItemSelected(9, getScreen()->getPlaceIgnoreShaded());
293 setItemSelected(10, getScreen()->getPlaceIgnoreMaximized());
294 }
295
296
297 void Configmenu::Placementmenu::reconfigure(void) {
298 setValues();
299 Basemenu::reconfigure();
300 }
301
302
303 void Configmenu::Placementmenu::itemSelected(int button, unsigned int index) {
304 if (button != 1)
305 return;
306
307 BasemenuItem *item = find(index);
308
309 if (! item->function())
310 return;
311
312 switch (item->function()) {
313 case BScreen::RowSmartPlacement:
314 getScreen()->savePlacementPolicy(item->function());
315
316 setItemSelected(0, true);
317 setItemSelected(1, false);
318 setItemSelected(2, false);
319 setItemSelected(3, false);
320 setItemSelected(4, false);
321 setItemEnabled(5, true);
322 setItemEnabled(6, true);
323 setItemEnabled(7, true);
324 setItemEnabled(8, true);
325
326 break;
327
328 case BScreen::ColSmartPlacement:
329 getScreen()->savePlacementPolicy(item->function());
330
331 setItemSelected(0, false);
332 setItemSelected(1, true);
333 setItemSelected(2, false);
334 setItemSelected(3, false);
335 setItemSelected(4, false);
336 setItemEnabled(5, true);
337 setItemEnabled(6, true);
338 setItemEnabled(7, true);
339 setItemEnabled(8, true);
340
341 break;
342
343 case BScreen::CascadePlacement:
344 getScreen()->savePlacementPolicy(item->function());
345
346 setItemSelected(0, false);
347 setItemSelected(1, false);
348 setItemSelected(2, true);
349 setItemSelected(3, false);
350 setItemSelected(4, false);
351 setItemEnabled(5, true);
352 setItemEnabled(6, true);
353 setItemEnabled(7, true);
354 setItemEnabled(8, true);
355
356 break;
357
358 case BScreen::UnderMousePlacement:
359 getScreen()->savePlacementPolicy(item->function());
360
361 setItemSelected(0, false);
362 setItemSelected(1, false);
363 setItemSelected(2, false);
364 setItemSelected(3, true);
365 setItemSelected(4, false);
366 setItemEnabled(5, false);
367 setItemEnabled(6, false);
368 setItemEnabled(7, false);
369 setItemEnabled(8, false);
370
371 break;
372
373 case BScreen::ClickMousePlacement:
374 getScreen()->savePlacementPolicy(item->function());
375
376 setItemSelected(0, false);
377 setItemSelected(1, false);
378 setItemSelected(2, false);
379 setItemSelected(3, false);
380 setItemSelected(4, true);
381 setItemEnabled(5, false);
382 setItemEnabled(6, false);
383 setItemEnabled(7, false);
384 setItemEnabled(8, false);
385
386 break;
387
388 case BScreen::LeftRight:
389 getScreen()->saveRowPlacementDirection(BScreen::LeftRight);
390
391 setItemSelected(5, true);
392 setItemSelected(6, false);
393
394 break;
395
396 case BScreen::RightLeft:
397 getScreen()->saveRowPlacementDirection(BScreen::RightLeft);
398
399 setItemSelected(5, false);
400 setItemSelected(6, true);
401
402 break;
403
404 case BScreen::TopBottom:
405 getScreen()->saveColPlacementDirection(BScreen::TopBottom);
406
407 setItemSelected(7, true);
408 setItemSelected(8, false);
409
410 break;
411
412 case BScreen::BottomTop:
413 getScreen()->saveColPlacementDirection(BScreen::BottomTop);
414
415 setItemSelected(7, false);
416 setItemSelected(8, true);
417
418 break;
419
420 case BScreen::IgnoreShaded:
421 getScreen()->savePlaceIgnoreShaded(! getScreen()->getPlaceIgnoreShaded());
422
423 setItemSelected(9, getScreen()->getPlaceIgnoreShaded());
424
425 break;
426
427 case BScreen::IgnoreMaximized:
428 getScreen()->
429 savePlaceIgnoreMaximized(! getScreen()->getPlaceIgnoreMaximized());
430
431 setItemSelected(10, getScreen()->getPlaceIgnoreMaximized());
432
433 break;
434 }
435 }
436
437
438 Configmenu::WindowToWindowSnapmenu::WindowToWindowSnapmenu(Configmenu *cm) :
439 Basemenu(cm->getScreen()) {
440 setLabel(i18n(ConfigmenuSet, ConfigmenuWindowToWindowSnap,
441 "Window-To-Window Snapping"));
442 setInternalMenu();
443
444 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoSnapNo, "No Snapping"), 1);
445 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoSnap, "Edge Snapping"), 2);
446 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoResistance,
447 "Edge Resistance"), 3);
448 insert(i18n(ConfigmenuSet, ConfigmenuWindowCornerSnap,
449 "Window Corner Snapping"), 4);
450 update();
451 setValues();
452 }
453
454
455 void Configmenu::WindowToWindowSnapmenu::setValues(void) {
456 setItemSelected(0, (getScreen()->getWindowToWindowSnap() ==
457 BScreen::WindowNoSnap));
458 setItemSelected(1, (getScreen()->getWindowToWindowSnap() ==
459 BScreen::WindowSnap));
460 setItemSelected(2, (getScreen()->getWindowToWindowSnap() ==
461 BScreen::WindowResistance));
462
463 setItemEnabled(3, getScreen()->getWindowToWindowSnap());
464 setItemSelected(3, getScreen()->getWindowCornerSnap());
465 }
466
467
468 void Configmenu::WindowToWindowSnapmenu::reconfigure(void) {
469 setValues();
470 Basemenu::reconfigure();
471 }
472
473
474 void Configmenu::WindowToWindowSnapmenu::itemSelected(int button, unsigned int index) {
475 if (button != 1)
476 return;
477
478 BasemenuItem *item = find(index);
479
480 if (! item->function())
481 return;
482
483 switch (item->function()) {
484 case 1: // none
485 getScreen()->saveWindowToWindowSnap(BScreen::WindowNoSnap);
486 break;
487
488 case 2: // edge snapping
489 getScreen()->saveWindowToWindowSnap(BScreen::WindowSnap);
490 break;
491
492 case 3: // edge resistance
493 getScreen()->saveWindowToWindowSnap(BScreen::WindowResistance);
494 break;
495
496 case 4: // window corner snapping
497 getScreen()->saveWindowCornerSnap(! getScreen()->getWindowCornerSnap());
498 break;
499
500 }
501 setValues();
502 }
503
504
505 Configmenu::WindowToEdgeSnapmenu::WindowToEdgeSnapmenu(Configmenu *cm) :
506 Basemenu(cm->getScreen()) {
507 setLabel(i18n(ConfigmenuSet, ConfigmenuWindowToEdgeSnap,
508 "Window-To-Edge Snapping"));
509 setInternalMenu();
510
511 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoSnapNo, "No Snapping"), 1);
512 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoSnap, "Edge Snapping"), 2);
513 insert(i18n(ConfigmenuSet, ConfigmenuWindowDoResistance,
514 "Edge Resistance"), 3);
515 update();
516 setValues();
517 }
518
519
520 void Configmenu::WindowToEdgeSnapmenu::setValues(void) {
521 setItemSelected(0, (getScreen()->getWindowToEdgeSnap() ==
522 BScreen::WindowNoSnap));
523 setItemSelected(1, (getScreen()->getWindowToEdgeSnap() ==
524 BScreen::WindowSnap));
525 setItemSelected(2, (getScreen()->getWindowToEdgeSnap() ==
526 BScreen::WindowResistance));
527 }
528
529
530 void Configmenu::WindowToEdgeSnapmenu::reconfigure(void) {
531 setValues();
532 Basemenu::reconfigure();
533 }
534
535
536 void Configmenu::WindowToEdgeSnapmenu::itemSelected(int button, unsigned int index) {
537 if (button != 1)
538 return;
539
540 BasemenuItem *item = find(index);
541
542 if (! item->function())
543 return;
544
545 switch (item->function()) {
546 case 1: // none
547 getScreen()->saveWindowToEdgeSnap(BScreen::WindowNoSnap);
548 break;
549
550 case 2: // edge snapping
551 getScreen()->saveWindowToEdgeSnap(BScreen::WindowSnap);
552 break;
553
554 case 3: // edge resistance
555 getScreen()->saveWindowToEdgeSnap(BScreen::WindowResistance);
556 break;
557 }
558 setValues();
559 }
560
561
562 #ifdef XINERAMA
563 Configmenu::Xineramamenu::Xineramamenu(Configmenu *cm):
564 Basemenu(cm->getScreen()) {
565 setLabel(i18n(ConfigmenuSet, ConfigmenuXineramaSupport, "Xinerama Support"));
566 setInternalMenu();
567
568 insert(i18n(ConfigmenuSet, ConfigmenuXineramaPlacement, "Window Placement"),
569 1);
570 insert(i18n(ConfigmenuSet, ConfigmenuXineramaMaximizing, "Window Maximizing"),
571 2);
572 insert(i18n(ConfigmenuSet, ConfigmenuXineramaSnapping, "Window Snapping"),
573 3);
574
575 update();
576 setValues();
577 }
578
579
580 void Configmenu::Xineramamenu::setValues(void) {
581 setItemSelected(0, getScreen()->getBlackbox()->doXineramaPlacement());
582 setItemSelected(1, getScreen()->getBlackbox()->doXineramaMaximizing());
583 setItemSelected(2, getScreen()->getBlackbox()->doXineramaSnapping());
584 }
585
586
587 void Configmenu::Xineramamenu::reconfigure(void) {
588 setValues();
589 Basemenu::reconfigure();
590 }
591
592
593 void Configmenu::Xineramamenu::itemSelected(int button, unsigned int index) {
594 if (button != 1)
595 return;
596
597 BasemenuItem *item = find(index);
598
599 if (! item->function())
600 return;
601
602 Blackbox *bb = getScreen()->getBlackbox();
603
604 switch (item->function()) {
605 case 1: // window placement
606 bb->saveXineramaPlacement(! bb->doXineramaPlacement());
607 setItemSelected(0, bb->doXineramaPlacement());
608 break;
609
610 case 2: // window maximizing
611 bb->saveXineramaMaximizing(! bb->doXineramaMaximizing());
612 setItemSelected(1, bb->doXineramaMaximizing());
613 break;
614
615 case 3: // window snapping
616 bb->saveXineramaSnapping(! bb->doXineramaSnapping());
617 setItemSelected(2, bb->doXineramaSnapping());
618 break;
619 }
620 }
621 #endif // XINERAMA
This page took 0.062847 seconds and 4 git commands to generate.