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, ConfigmenuLeftRight,
219 "Left to Right"), BScreen::LeftRight);
220 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuRightLeft,
221 "Right to Left"), BScreen::RightLeft);
222 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuTopBottom,
223 "Top to Bottom"), BScreen::TopBottom);
224 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBottomTop,
225 "Bottom to Top"), BScreen::BottomTop);
228 switch (configmenu->screen->getPlacementPolicy()) {
229 case BScreen::RowSmartPlacement:
230 setItemSelected(0, True);
233 case BScreen::ColSmartPlacement:
234 setItemSelected(1, True);
237 case BScreen::CascadePlacement:
238 setItemSelected(2, True);
242 Bool rl = (configmenu->screen->getRowPlacementDirection() ==
244 tb = (configmenu->screen->getColPlacementDirection() ==
247 setItemSelected(3, rl);
248 setItemSelected(4, ! rl);
250 setItemSelected(5, tb);
251 setItemSelected(6, ! tb);
254 void Configmenu::Placementmenu::itemSelected(int button, int index) {
258 BasemenuItem *item = find(index);
260 if (!item->function())
263 switch (item->function()) {
264 case BScreen::RowSmartPlacement:
265 configmenu->screen->savePlacementPolicy(item->function());
267 setItemSelected(0, True);
268 setItemSelected(1, False);
269 setItemSelected(2, False);
273 case BScreen::ColSmartPlacement:
274 configmenu->screen->savePlacementPolicy(item->function());
276 setItemSelected(0, False);
277 setItemSelected(1, True);
278 setItemSelected(2, False);
282 case BScreen::CascadePlacement:
283 configmenu->screen->savePlacementPolicy(item->function());
285 setItemSelected(0, False);
286 setItemSelected(1, False);
287 setItemSelected(2, True);
291 case BScreen::LeftRight:
292 configmenu->screen->saveRowPlacementDirection(BScreen::LeftRight);
294 setItemSelected(3, True);
295 setItemSelected(4, False);
299 case BScreen::RightLeft:
300 configmenu->screen->saveRowPlacementDirection(BScreen::RightLeft);
302 setItemSelected(3, False);
303 setItemSelected(4, True);
307 case BScreen::TopBottom:
308 configmenu->screen->saveColPlacementDirection(BScreen::TopBottom);
310 setItemSelected(5, True);
311 setItemSelected(6, False);
315 case BScreen::BottomTop:
316 configmenu->screen->saveColPlacementDirection(BScreen::BottomTop);
318 setItemSelected(5, False);
319 setItemSelected(6, True);