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)
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:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
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.
23 // stupid macros needed to access some functions in version 2 of the GNU C
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
34 #include "Configmenu.h"
39 Configmenu::Configmenu(BScreen *scr) : Basemenu(scr) {
41 openbox = screen->getOpenbox();
42 setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuConfigOptions,
46 focusmenu = new Focusmenu(this);
47 placementmenu = new Placementmenu(this);
49 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusModel,
50 "Focus Model"), focusmenu);
51 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuWindowPlacement,
52 "Window Placement"), placementmenu);
53 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuImageDithering,
54 "Image Dithering"), 1);
55 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuOpaqueMove,
56 "Opaque Window Moving"), 2);
57 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFullMax,
58 "Full Maximization"), 3);
59 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusNew,
60 "Focus New Windows"), 4);
61 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusLast,
62 "Focus Last Window on Workspace"), 5);
65 setItemSelected(2, screen->getImageControl()->doDither());
66 setItemSelected(3, screen->doOpaqueMove());
67 setItemSelected(4, screen->doFullMax());
68 setItemSelected(5, screen->doFocusNew());
69 setItemSelected(6, screen->doFocusLast());
72 Configmenu::~Configmenu(void) {
77 void Configmenu::itemSelected(int button, int index) {
81 BasemenuItem *item = find(index);
83 if (!item->function())
86 switch(item->function()) {
88 screen->getImageControl()->
89 setDither((! screen->getImageControl()->doDither()));
91 setItemSelected(index, screen->getImageControl()->doDither());
96 case 2: { // opaque move
97 screen->saveOpaqueMove((! screen->doOpaqueMove()));
99 setItemSelected(index, screen->doOpaqueMove());
104 case 3: { // full maximization
105 screen->saveFullMax((! screen->doFullMax()));
107 setItemSelected(index, screen->doFullMax());
111 case 4: { // focus new windows
112 screen->saveFocusNew((! screen->doFocusNew()));
114 setItemSelected(index, screen->doFocusNew());
118 case 5: { // focus last window on workspace
119 screen->saveFocusLast((! screen->doFocusLast()));
120 setItemSelected(index, screen->doFocusLast());
126 void Configmenu::reconfigure(void) {
127 focusmenu->reconfigure();
128 placementmenu->reconfigure();
130 Basemenu::reconfigure();
133 Configmenu::Focusmenu::Focusmenu(Configmenu *cm) : Basemenu(cm->screen) {
136 setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusModel,
140 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuClickToFocus,
141 "Click To Focus"), 1);
142 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSloppyFocus,
144 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuAutoRaise,
148 setItemSelected(0, (! configmenu->screen->isSloppyFocus()));
149 setItemSelected(1, configmenu->screen->isSloppyFocus());
150 setItemEnabled(2, configmenu->screen->isSloppyFocus());
151 setItemSelected(2, configmenu->screen->doAutoRaise());
154 void Configmenu::Focusmenu::itemSelected(int button, int index) {
158 BasemenuItem *item = find(index);
160 if (!item->function())
163 switch (item->function()) {
164 case 1: // click to focus
165 configmenu->screen->saveSloppyFocus(False);
166 configmenu->screen->saveAutoRaise(False);
168 if (! configmenu->screen->getOpenbox()->getFocusedWindow())
169 XSetInputFocus(configmenu->screen->getOpenbox()->getXDisplay(),
170 configmenu->screen->getToolbar()->getWindowID(),
171 RevertToParent, CurrentTime);
173 XSetInputFocus(configmenu->screen->getOpenbox()->getXDisplay(),
174 configmenu->screen->getOpenbox()->
175 getFocusedWindow()->getClientWindow(),
176 RevertToParent, CurrentTime);
178 configmenu->screen->reconfigure();
182 case 2: // sloppy focus
183 configmenu->screen->saveSloppyFocus(True);
185 configmenu->screen->reconfigure();
189 case 3: // auto raise with sloppy focus
190 Bool change = ((configmenu->screen->doAutoRaise()) ? False : True);
191 configmenu->screen->saveAutoRaise(change);
196 setItemSelected(0, (! configmenu->screen->isSloppyFocus()));
197 setItemSelected(1, configmenu->screen->isSloppyFocus());
198 setItemEnabled(2, configmenu->screen->isSloppyFocus());
199 setItemSelected(2, configmenu->screen->doAutoRaise());
202 Configmenu::Placementmenu::Placementmenu(Configmenu *cm) :
203 Basemenu(cm->screen) {
206 setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuWindowPlacement,
207 "Window Placement"));
210 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSmartRows,
211 "Smart Placement (Rows)"),
212 BScreen::RowSmartPlacement);
213 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSmartCols,
214 "Smart Placement (Columns)"),
215 BScreen::ColSmartPlacement);
216 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuCascade,
217 "Cascade Placement"), BScreen::CascadePlacement);
218 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBestFit,
219 "Best Fit Placement"), BScreen::BestFitPlacement);
220 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuLeftRight,
221 "Left to Right"), BScreen::LeftRight);
222 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuRightLeft,
223 "Right to Left"), BScreen::RightLeft);
224 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuTopBottom,
225 "Top to Bottom"), BScreen::TopBottom);
226 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBottomTop,
227 "Bottom to Top"), BScreen::BottomTop);
230 switch (configmenu->screen->getPlacementPolicy()) {
231 case BScreen::RowSmartPlacement:
232 setItemSelected(0, True);
235 case BScreen::ColSmartPlacement:
236 setItemSelected(1, True);
239 case BScreen::CascadePlacement:
240 setItemSelected(2, True);
243 case BScreen::BestFitPlacement:
244 setItemSelected(3, True);
248 Bool rl = (configmenu->screen->getRowPlacementDirection() ==
250 tb = (configmenu->screen->getColPlacementDirection() ==
253 setItemSelected(4, rl);
254 setItemSelected(5, ! rl);
256 setItemSelected(6, tb);
257 setItemSelected(7, ! tb);
260 void Configmenu::Placementmenu::itemSelected(int button, int index) {
264 BasemenuItem *item = find(index);
266 if (!item->function())
269 switch (item->function()) {
270 case BScreen::RowSmartPlacement:
271 configmenu->screen->savePlacementPolicy(item->function());
273 setItemSelected(0, True);
274 setItemSelected(1, False);
275 setItemSelected(2, False);
276 setItemSelected(3, False);
280 case BScreen::ColSmartPlacement:
281 configmenu->screen->savePlacementPolicy(item->function());
283 setItemSelected(0, False);
284 setItemSelected(1, True);
285 setItemSelected(2, False);
286 setItemSelected(3, False);
290 case BScreen::CascadePlacement:
291 configmenu->screen->savePlacementPolicy(item->function());
293 setItemSelected(0, False);
294 setItemSelected(1, False);
295 setItemSelected(2, True);
296 setItemSelected(3, False);
300 case BScreen::BestFitPlacement:
301 configmenu->screen->savePlacementPolicy(item->function());
303 setItemSelected(0, False);
304 setItemSelected(1, False);
305 setItemSelected(2, False);
306 setItemSelected(3, True);
310 case BScreen::LeftRight:
311 configmenu->screen->saveRowPlacementDirection(BScreen::LeftRight);
313 setItemSelected(4, True);
314 setItemSelected(5, False);
318 case BScreen::RightLeft:
319 configmenu->screen->saveRowPlacementDirection(BScreen::RightLeft);
321 setItemSelected(4, False);
322 setItemSelected(5, True);
326 case BScreen::TopBottom:
327 configmenu->screen->saveColPlacementDirection(BScreen::TopBottom);
329 setItemSelected(5, True);
330 setItemSelected(6, False);
334 case BScreen::BottomTop:
335 configmenu->screen->saveColPlacementDirection(BScreen::BottomTop);
337 setItemSelected(5, False);
338 setItemSelected(6, True);