Added a runtime option for hiding the toolbar totally. Will be cleaner
[mikachu/openbox.git] / src / Configmenu.cc
1 // Configmenu.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.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 // stupid macros needed to access some functions in version 2 of the GNU C
24 // library
25 #ifndef   _GNU_SOURCE
26 #  define _GNU_SOURCE
27 #endif // _GNU_SOURCE
28
29 #ifdef    HAVE_CONFIG_H
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
32
33 #include "i18n.h"
34 #include "Configmenu.h"
35 #include "Toolbar.h"
36 #include "Window.h"
37 #include "Screen.h"
38
39 Configmenu::Configmenu(BScreen &scr) : Basemenu(scr), screen(scr)
40 {
41   setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuConfigOptions,
42                             "Config options"));
43   setInternalMenu();
44
45   focusmenu = new Focusmenu(this);
46   placementmenu = new Placementmenu(this);
47
48   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusModel,
49                           "Focus Model"), focusmenu);
50   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuWindowPlacement,
51                           "Window Placement"), placementmenu);
52   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuImageDithering,
53                           "Image Dithering"), 1);
54   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuOpaqueMove,
55                           "Opaque Window Moving"), 2);
56   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFullMax,
57                           "Full Maximization"), 3);
58   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusNew,
59                           "Focus New Windows"), 4);
60   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusLast,
61                           "Focus Last Window on Workspace"), 5);
62   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuHideToolbar,
63                           "Hide toolbar"), 6);
64   update();
65
66   setItemSelected(2, screen.getImageControl()->doDither());
67   setItemSelected(3, screen.doOpaqueMove());
68   setItemSelected(4, screen.doFullMax());
69   setItemSelected(5, screen.doFocusNew());
70   setItemSelected(6, screen.doFocusLast());
71   setItemSelected(7, screen.doToolbarHide());
72 }
73
74 Configmenu::~Configmenu(void) {
75   delete focusmenu;
76   delete placementmenu;
77 }
78
79 void Configmenu::itemSelected(int button, int index) {
80   if (button != 1)
81     return;
82
83   BasemenuItem *item = find(index);
84
85   if (!item->function())
86     return;
87
88   switch(item->function()) {
89   case 1: { // dither
90     screen.getImageControl()->
91       setDither((! screen.getImageControl()->doDither()));
92
93     setItemSelected(index, screen.getImageControl()->doDither());
94
95     break;
96   }
97
98   case 2: { // opaque move
99     screen.saveOpaqueMove((! screen.doOpaqueMove()));
100
101     setItemSelected(index, screen.doOpaqueMove());
102
103     break;
104   }
105
106   case 3: { // full maximization
107     screen.saveFullMax((! screen.doFullMax()));
108
109     setItemSelected(index, screen.doFullMax());
110
111     break;
112   }
113   case 4: { // focus new windows
114     screen.saveFocusNew((! screen.doFocusNew()));
115
116     setItemSelected(index, screen.doFocusNew());
117     break;
118   }
119
120   case 5: { // focus last window on workspace
121     screen.saveFocusLast(!(screen.doFocusLast()));
122     setItemSelected(index, screen.doFocusLast());
123     break;
124   }
125   case 6:{ //toggle toolbar hide
126     screen.saveToolbarHide(!(screen.doToolbarHide()));
127     setItemSelected(index, screen.doToolbarHide());
128     break;
129   }
130   } // switch
131 }
132
133 void Configmenu::reconfigure(void) {
134   focusmenu->reconfigure();
135   placementmenu->reconfigure();
136
137   Basemenu::reconfigure();
138 }
139
140 Configmenu::Focusmenu::Focusmenu(Configmenu *cm) : Basemenu(cm->screen) {
141   configmenu = cm;
142
143   setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusModel,
144                             "Focus Model"));
145   setInternalMenu();
146
147   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuClickToFocus,
148                           "Click To Focus"), 1);
149   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSloppyFocus,
150                           "Sloppy Focus"), 2);
151   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuAutoRaise,
152                           "Auto Raise"), 3);
153   update();
154
155   setItemSelected(0, (! configmenu->screen.isSloppyFocus()));
156   setItemSelected(1, configmenu->screen.isSloppyFocus());
157   setItemEnabled(2, configmenu->screen.isSloppyFocus());
158   setItemSelected(2, configmenu->screen.doAutoRaise());
159 }
160
161 void Configmenu::Focusmenu::itemSelected(int button, int index) {
162   if (button != 1)
163     return;
164
165   BasemenuItem *item = find(index);
166
167   if (!item->function())
168     return;
169
170   switch (item->function()) {
171   case 1: // click to focus
172     configmenu->screen.saveSloppyFocus(False);
173     configmenu->screen.saveAutoRaise(False);
174
175     if (! configmenu->screen.getOpenbox().getFocusedWindow())
176       XSetInputFocus(configmenu->screen.getOpenbox().getXDisplay(),
177                      configmenu->screen.getToolbar()->getWindowID(),
178                      RevertToParent, CurrentTime);
179     else
180       XSetInputFocus(configmenu->screen.getOpenbox().getXDisplay(),
181                      configmenu->screen.getOpenbox().
182                      getFocusedWindow()->getClientWindow(),
183                      RevertToParent, CurrentTime);
184
185     configmenu->screen.reconfigure();
186
187     break;
188
189   case 2: // sloppy focus
190     configmenu->screen.saveSloppyFocus(True);
191
192     configmenu->screen.reconfigure();
193
194     break;
195
196   case 3: // auto raise with sloppy focus
197     Bool change = ((configmenu->screen.doAutoRaise()) ? False : True);
198     configmenu->screen.saveAutoRaise(change);
199
200     break;
201   }
202
203   setItemSelected(0, (! configmenu->screen.isSloppyFocus()));
204   setItemSelected(1, configmenu->screen.isSloppyFocus());
205   setItemEnabled(2, configmenu->screen.isSloppyFocus());
206   setItemSelected(2, configmenu->screen.doAutoRaise());
207 }
208
209 Configmenu::Placementmenu::Placementmenu(Configmenu *cm) :
210  Basemenu(cm->screen) {
211   configmenu = cm;
212
213   setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuWindowPlacement,
214                             "Window Placement"));
215   setInternalMenu();
216   
217   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSmartRows,
218                           "Smart Placement (Rows)"),
219          BScreen::RowSmartPlacement);
220   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSmartCols,
221                           "Smart Placement (Columns)"),
222          BScreen::ColSmartPlacement);
223   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuCascade,
224                           "Cascade Placement"), BScreen::CascadePlacement);
225   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBestFit,
226                           "Best Fit Placement"), BScreen::BestFitPlacement);
227   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuLeftRight,
228                           "Left to Right"), BScreen::LeftRight);
229   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuRightLeft,
230                           "Right to Left"), BScreen::RightLeft);
231   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuTopBottom,
232                           "Top to Bottom"), BScreen::TopBottom);
233   insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBottomTop,
234                           "Bottom to Top"), BScreen::BottomTop);
235   update();
236
237   switch (configmenu->screen.getPlacementPolicy()) {
238   case BScreen::RowSmartPlacement:
239     setItemSelected(0, True);
240     break;
241
242   case BScreen::ColSmartPlacement:
243     setItemSelected(1, True);
244     break;
245
246   case BScreen::CascadePlacement:
247     setItemSelected(2, True);
248     break;
249
250   case BScreen::BestFitPlacement:
251     setItemSelected(3, True);
252     break;
253   }
254
255   Bool rl = (configmenu->screen.getRowPlacementDirection() ==
256              BScreen::LeftRight),
257        tb = (configmenu->screen.getColPlacementDirection() ==
258              BScreen::TopBottom);
259
260   setItemSelected(4, rl);
261   setItemSelected(5, ! rl);
262
263   setItemSelected(6, tb);
264   setItemSelected(7, ! tb);
265 }
266
267 void Configmenu::Placementmenu::itemSelected(int button, int index) {
268   if (button != 1)
269     return;
270
271   BasemenuItem *item = find(index);
272
273   if (!item->function())
274     return;
275
276   switch (item->function()) {
277   case BScreen::RowSmartPlacement:
278     configmenu->screen.savePlacementPolicy(item->function());
279
280     setItemSelected(0, True);
281     setItemSelected(1, False);
282     setItemSelected(2, False);
283     setItemSelected(3, False);
284
285     break;
286
287   case BScreen::ColSmartPlacement:
288     configmenu->screen.savePlacementPolicy(item->function());
289
290     setItemSelected(0, False);
291     setItemSelected(1, True);
292     setItemSelected(2, False);
293     setItemSelected(3, False);
294
295     break;
296
297   case BScreen::CascadePlacement:
298     configmenu->screen.savePlacementPolicy(item->function());
299
300     setItemSelected(0, False);
301     setItemSelected(1, False);
302     setItemSelected(2, True);
303     setItemSelected(3, False);
304
305     break;
306
307   case BScreen::BestFitPlacement:
308     configmenu->screen.savePlacementPolicy(item->function());
309
310     setItemSelected(0, False);
311     setItemSelected(1, False);
312     setItemSelected(2, False);
313     setItemSelected(3, True);
314
315     break;
316
317   case BScreen::LeftRight:
318     configmenu->screen.saveRowPlacementDirection(BScreen::LeftRight);
319
320     setItemSelected(4, True);
321     setItemSelected(5, False);
322
323     break;
324
325   case BScreen::RightLeft:
326     configmenu->screen.saveRowPlacementDirection(BScreen::RightLeft);
327
328     setItemSelected(4, False);
329     setItemSelected(5, True);
330
331     break;
332
333   case BScreen::TopBottom:
334     configmenu->screen.saveColPlacementDirection(BScreen::TopBottom);
335
336     setItemSelected(5, True);
337     setItemSelected(6, False);
338
339     break;
340
341   case BScreen::BottomTop:
342     configmenu->screen.saveColPlacementDirection(BScreen::BottomTop);
343
344     setItemSelected(5, False);
345     setItemSelected(6, True);
346
347     break;
348   }
349 }