]> Dogcows Code - chaz/openbox/blob - src/Configmenu.cc
13266d3696bede209824f6e59cca7cfe62930d68
[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 #ifdef XINERAMA
42 xineramamenu = new Xineramamenu(this);
43 #endif // XINERAMA
44
45 insert(i18n(ConfigmenuSet, ConfigmenuFocusModel,
46 "Focus Model"), focusmenu);
47 insert(i18n(ConfigmenuSet, ConfigmenuWindowPlacement,
48 "Window Placement"), placementmenu);
49 #ifdef XINERAMA
50 insert(i18n(ConfigmenuSet, ConfigmenuXineramaSupport,
51 "XineramaSupport"), xineramamenu);
52 #endif // XINERAMA
53 insert(i18n(ConfigmenuSet, ConfigmenuImageDithering,
54 "Image Dithering"), 1);
55 insert(i18n(ConfigmenuSet, ConfigmenuOpaqueMove,
56 "Opaque Window Moving"), 2);
57 insert(i18n(ConfigmenuSet, ConfigmenuFullMax,
58 "Full Maximization"), 3);
59 insert(i18n(ConfigmenuSet, ConfigmenuFocusNew,
60 "Focus New Windows"), 4);
61 insert(i18n(ConfigmenuSet, ConfigmenuFocusLast,
62 "Focus Last Window on Workspace"), 5);
63 insert(i18n(ConfigmenuSet, ConfigmenuWindowToWindowSnap,
64 "Window-To-Window Snapping"), 6);
65 insert(i18n(ConfigmenuSet, ConfigmenuWindowCornerSnap,
66 "Window Corner Snapping"), 7);
67 insert(i18n(ConfigmenuSet, ConfigmenuDisableBindings,
68 "Disable Mouse with Scroll Lock"), 8);
69 insert(i18n(ConfigmenuSet, ConfigmenuHideToolbar,
70 "Hide Toolbar"), 9);
71 update();
72 setValues();
73 }
74
75
76 void Configmenu::setValues(void) {
77 int index = 2;
78 #ifdef XINERAMA
79 ++index;
80 #endif // XINERAMA
81 setItemSelected(index++, getScreen()->doImageDither());
82 setItemSelected(index++, getScreen()->doOpaqueMove());
83 setItemSelected(index++, getScreen()->doFullMax());
84 setItemSelected(index++, getScreen()->doFocusNew());
85 setItemSelected(index++, getScreen()->doFocusLast());
86 setItemSelected(index++, getScreen()->getWindowToWindowSnap());
87
88 setItemSelected(index, getScreen()->getWindowCornerSnap());
89 setItemEnabled(index++, getScreen()->getWindowToWindowSnap());
90
91 setItemSelected(index++, getScreen()->allowScrollLock());
92 setItemSelected(index++, getScreen()->doHideToolbar());
93 }
94
95
96 Configmenu::~Configmenu(void) {
97 delete focusmenu;
98 delete placementmenu;
99 #ifdef XINERAMA
100 delete xineramamenu;
101 #endif // XINERAMA
102 }
103
104
105 void Configmenu::itemSelected(int button, unsigned int index) {
106 if (button != 1)
107 return;
108
109 BasemenuItem *item = find(index);
110
111 if (! item->function())
112 return;
113
114 switch(item->function()) {
115 case 1: // dither
116 getScreen()->saveImageDither(! getScreen()->doImageDither());
117 setItemSelected(index, getScreen()->doImageDither());
118 break;
119
120 case 2: // opaque move
121 getScreen()->saveOpaqueMove(! getScreen()->doOpaqueMove());
122 setItemSelected(index, getScreen()->doOpaqueMove());
123 break;
124
125 case 3: // full maximization
126 getScreen()->saveFullMax(! getScreen()->doFullMax());
127 setItemSelected(index, getScreen()->doFullMax());
128 break;
129
130 case 4: // focus new windows
131 getScreen()->saveFocusNew(! getScreen()->doFocusNew());
132 setItemSelected(index, getScreen()->doFocusNew());
133 break;
134
135 case 5: // focus last window on workspace
136 getScreen()->saveFocusLast(! getScreen()->doFocusLast());
137 setItemSelected(index, getScreen()->doFocusLast());
138 break;
139
140 case 6: // window-to-window snapping
141 getScreen()->saveWindowToWindowSnap(! getScreen()->getWindowToWindowSnap());
142 setItemSelected(index, getScreen()->getWindowToWindowSnap());
143 setItemEnabled(index + 1, getScreen()->getWindowToWindowSnap());
144 break;
145
146 case 7: // window corner snapping
147 getScreen()->saveWindowCornerSnap(! getScreen()->getWindowCornerSnap());
148 setItemSelected(index, getScreen()->getWindowCornerSnap());
149 break;
150
151 case 8: // disable mouse bindings with Scroll Lock
152 getScreen()->saveAllowScrollLock(! getScreen()->allowScrollLock());
153 setItemSelected(index, getScreen()->allowScrollLock());
154 getScreen()->reconfigure();
155 break;
156
157 case 9: // hide toolbar
158 getScreen()->saveHideToolbar(! getScreen()->doHideToolbar());
159 setItemSelected(index, getScreen()->doHideToolbar());
160 break;
161 }
162 }
163
164
165 void Configmenu::reconfigure(void) {
166 setValues();
167 focusmenu->reconfigure();
168 placementmenu->reconfigure();
169 #ifdef XINERAMA
170 xineramamenu->reconfigure();
171 #endif // XINERAMA
172
173 Basemenu::reconfigure();
174 }
175
176
177 Configmenu::Focusmenu::Focusmenu(Configmenu *cm) : Basemenu(cm->getScreen()) {
178 setLabel(i18n(ConfigmenuSet, ConfigmenuFocusModel, "Focus Model"));
179 setInternalMenu();
180
181 insert(i18n(ConfigmenuSet, ConfigmenuClickToFocus, "Click To Focus"), 1);
182 insert(i18n(ConfigmenuSet, ConfigmenuSloppyFocus, "Sloppy Focus"), 2);
183 insert(i18n(ConfigmenuSet, ConfigmenuAutoRaise, "Auto Raise"), 3);
184 insert(i18n(ConfigmenuSet, ConfigmenuClickRaise, "Click Raise"), 4);
185 update();
186 setValues();
187 }
188
189
190 void Configmenu::Focusmenu::setValues(void) {
191 setItemSelected(0, ! getScreen()->isSloppyFocus());
192 setItemSelected(1, getScreen()->isSloppyFocus());
193 setItemEnabled(2, getScreen()->isSloppyFocus());
194 setItemSelected(2, getScreen()->doAutoRaise());
195 setItemEnabled(3, getScreen()->isSloppyFocus());
196 setItemSelected(3, getScreen()->doClickRaise());
197 }
198
199
200 void Configmenu::Focusmenu::reconfigure(void) {
201 setValues();
202 Basemenu::reconfigure();
203 }
204
205
206 void Configmenu::Focusmenu::itemSelected(int button, unsigned int index) {
207 if (button != 1)
208 return;
209
210 BasemenuItem *item = find(index);
211
212 if (! item->function())
213 return;
214
215 switch (item->function()) {
216 case 1: // click to focus
217 getScreen()->toggleFocusModel(BScreen::ClickToFocus);
218 break;
219
220 case 2: // sloppy focus
221 getScreen()->toggleFocusModel(BScreen::SloppyFocus);
222 break;
223
224 case 3: // auto raise with sloppy focus
225 getScreen()->saveAutoRaise(! getScreen()->doAutoRaise());
226 break;
227
228 case 4: // click raise with sloppy focus
229 getScreen()->saveClickRaise(! getScreen()->doClickRaise());
230 // make sure the appropriate mouse buttons are grabbed on the windows
231 getScreen()->toggleFocusModel(BScreen::SloppyFocus);
232 break;
233 }
234 setValues();
235 }
236
237
238 Configmenu::Placementmenu::Placementmenu(Configmenu *cm):
239 Basemenu(cm->getScreen()) {
240 setLabel(i18n(ConfigmenuSet, ConfigmenuWindowPlacement, "Window Placement"));
241 setInternalMenu();
242
243 insert(i18n(ConfigmenuSet, ConfigmenuSmartRows, "Smart Placement (Rows)"),
244 BScreen::RowSmartPlacement);
245 insert(i18n(ConfigmenuSet, ConfigmenuSmartCols, "Smart Placement (Columns)"),
246 BScreen::ColSmartPlacement);
247 insert(i18n(ConfigmenuSet, ConfigmenuCascade, "Cascade Placement"),
248 BScreen::CascadePlacement);
249 insert(i18n(ConfigmenuSet, ConfigmenuUnderMouse, "Under Mouse Placement"),
250 BScreen::UnderMousePlacement);
251 insert(i18n(ConfigmenuSet, ConfigmenuClickMouse, "Click Mouse Placement"),
252 BScreen::ClickMousePlacement);
253 insert(i18n(ConfigmenuSet, ConfigmenuLeftRight, "Left to Right"),
254 BScreen::LeftRight);
255 insert(i18n(ConfigmenuSet, ConfigmenuRightLeft, "Right to Left"),
256 BScreen::RightLeft);
257 insert(i18n(ConfigmenuSet, ConfigmenuTopBottom, "Top to Bottom"),
258 BScreen::TopBottom);
259 insert(i18n(ConfigmenuSet, ConfigmenuBottomTop, "Bottom to Top"),
260 BScreen::BottomTop);
261 insert(i18n(ConfigmenuSet, ConfigmenuIgnoreShaded, "Ignore Shaded Windows"),
262 BScreen::IgnoreShaded);
263 insert(i18n(ConfigmenuSet, ConfigmenuIgnoreMax,
264 "Ignore Full-Maximized Windows"),
265 BScreen::IgnoreMaximized);
266 update();
267 setValues();
268 }
269
270
271 void Configmenu::Placementmenu::setValues(void) {
272 int placement = getScreen()->getPlacementPolicy();
273
274 setItemSelected(0, placement == BScreen::RowSmartPlacement);
275 setItemSelected(1, placement == BScreen::ColSmartPlacement);
276 setItemSelected(2, placement == BScreen::CascadePlacement);
277 setItemSelected(3, placement == BScreen::UnderMousePlacement);
278 setItemSelected(4, placement == BScreen::ClickMousePlacement);
279
280 bool rl = (getScreen()->getRowPlacementDirection() == BScreen::LeftRight),
281 tb = (getScreen()->getColPlacementDirection() == BScreen::TopBottom),
282 e = placement != BScreen::UnderMousePlacement;
283
284 setItemSelected(5, rl);
285 setItemSelected(6, ! rl);
286 setItemEnabled(5, e);
287 setItemEnabled(6, e);
288
289 setItemSelected(7, tb);
290 setItemSelected(8, ! tb);
291 setItemEnabled(7, e);
292 setItemEnabled(8, e);
293
294 setItemSelected(9, getScreen()->getPlaceIgnoreShaded());
295 setItemSelected(10, getScreen()->getPlaceIgnoreMaximized());
296 }
297
298
299 void Configmenu::Placementmenu::reconfigure(void) {
300 setValues();
301 Basemenu::reconfigure();
302 }
303
304
305 void Configmenu::Placementmenu::itemSelected(int button, unsigned int index) {
306 if (button != 1)
307 return;
308
309 BasemenuItem *item = find(index);
310
311 if (! item->function())
312 return;
313
314 switch (item->function()) {
315 case BScreen::RowSmartPlacement:
316 getScreen()->savePlacementPolicy(item->function());
317
318 setItemSelected(0, true);
319 setItemSelected(1, false);
320 setItemSelected(2, false);
321 setItemSelected(3, false);
322 setItemSelected(4, false);
323 setItemEnabled(5, true);
324 setItemEnabled(6, true);
325 setItemEnabled(7, true);
326 setItemEnabled(8, true);
327
328 break;
329
330 case BScreen::ColSmartPlacement:
331 getScreen()->savePlacementPolicy(item->function());
332
333 setItemSelected(0, false);
334 setItemSelected(1, true);
335 setItemSelected(2, false);
336 setItemSelected(3, false);
337 setItemSelected(4, false);
338 setItemEnabled(5, true);
339 setItemEnabled(6, true);
340 setItemEnabled(7, true);
341 setItemEnabled(8, true);
342
343 break;
344
345 case BScreen::CascadePlacement:
346 getScreen()->savePlacementPolicy(item->function());
347
348 setItemSelected(0, false);
349 setItemSelected(1, false);
350 setItemSelected(2, true);
351 setItemSelected(3, false);
352 setItemSelected(4, false);
353 setItemEnabled(5, true);
354 setItemEnabled(6, true);
355 setItemEnabled(7, true);
356 setItemEnabled(8, true);
357
358 break;
359
360 case BScreen::UnderMousePlacement:
361 getScreen()->savePlacementPolicy(item->function());
362
363 setItemSelected(0, false);
364 setItemSelected(1, false);
365 setItemSelected(2, false);
366 setItemSelected(3, true);
367 setItemSelected(4, false);
368 setItemEnabled(5, false);
369 setItemEnabled(6, false);
370 setItemEnabled(7, false);
371 setItemEnabled(8, false);
372
373 break;
374
375 case BScreen::ClickMousePlacement:
376 getScreen()->savePlacementPolicy(item->function());
377
378 setItemSelected(0, false);
379 setItemSelected(1, false);
380 setItemSelected(2, false);
381 setItemSelected(3, false);
382 setItemSelected(4, true);
383 setItemEnabled(5, false);
384 setItemEnabled(6, false);
385 setItemEnabled(7, false);
386 setItemEnabled(8, false);
387
388 break;
389
390 case BScreen::LeftRight:
391 getScreen()->saveRowPlacementDirection(BScreen::LeftRight);
392
393 setItemSelected(5, true);
394 setItemSelected(6, false);
395
396 break;
397
398 case BScreen::RightLeft:
399 getScreen()->saveRowPlacementDirection(BScreen::RightLeft);
400
401 setItemSelected(5, false);
402 setItemSelected(6, true);
403
404 break;
405
406 case BScreen::TopBottom:
407 getScreen()->saveColPlacementDirection(BScreen::TopBottom);
408
409 setItemSelected(7, true);
410 setItemSelected(8, false);
411
412 break;
413
414 case BScreen::BottomTop:
415 getScreen()->saveColPlacementDirection(BScreen::BottomTop);
416
417 setItemSelected(7, false);
418 setItemSelected(8, true);
419
420 break;
421
422 case BScreen::IgnoreShaded:
423 getScreen()->savePlaceIgnoreShaded(! getScreen()->getPlaceIgnoreShaded());
424
425 setItemSelected(9, getScreen()->getPlaceIgnoreShaded());
426
427 break;
428
429 case BScreen::IgnoreMaximized:
430 getScreen()->
431 savePlaceIgnoreMaximized(! getScreen()->getPlaceIgnoreMaximized());
432
433 setItemSelected(10, getScreen()->getPlaceIgnoreMaximized());
434
435 break;
436 }
437 }
438
439
440 #ifdef XINERAMA
441 Configmenu::Xineramamenu::Xineramamenu(Configmenu *cm):
442 Basemenu(cm->getScreen()) {
443 setLabel(i18n(ConfigmenuSet, ConfigmenuXineramaSupport, "Xinerama Support"));
444 setInternalMenu();
445
446 insert(i18n(ConfigmenuSet, ConfigmenuXineramaPlacement, "Window Placement"),
447 1);
448 insert(i18n(ConfigmenuSet, ConfigmenuXineramaMaximizing, "Window Maximizing"),
449 2);
450 insert(i18n(ConfigmenuSet, ConfigmenuXineramaSnapping, "Window Snapping"),
451 3);
452
453 update();
454 setValues();
455 }
456
457
458 void Configmenu::Xineramamenu::setValues(void) {
459 setItemSelected(0, getScreen()->getBlackbox()->doXineramaPlacement());
460 setItemSelected(1, getScreen()->getBlackbox()->doXineramaMaximizing());
461 setItemSelected(2, getScreen()->getBlackbox()->doXineramaSnapping());
462 }
463
464
465 void Configmenu::Xineramamenu::reconfigure(void) {
466 setValues();
467 Basemenu::reconfigure();
468 }
469
470
471 void Configmenu::Xineramamenu::itemSelected(int button, unsigned int index) {
472 if (button != 1)
473 return;
474
475 BasemenuItem *item = find(index);
476
477 if (! item->function())
478 return;
479
480 Blackbox *bb = getScreen()->getBlackbox();
481
482 switch (item->function()) {
483 case 1: // window placement
484 bb->saveXineramaPlacement(! bb->doXineramaPlacement());
485 setItemSelected(0, bb->doXineramaPlacement());
486 break;
487
488 case 2: // window maximizing
489 bb->saveXineramaMaximizing(! bb->doXineramaMaximizing());
490 setItemSelected(1, bb->doXineramaMaximizing());
491 break;
492
493 case 3: // window snapping
494 bb->saveXineramaSnapping(! bb->doXineramaSnapping());
495 setItemSelected(2, bb->doXineramaSnapping());
496 break;
497 }
498 }
499 #endif // XINERAMA
This page took 0.058789 seconds and 4 git commands to generate.