]> Dogcows Code - chaz/openbox/blob - src/Configmenu.cc
better gcc3 compat. using ostrstream again. and using namespace std;
[chaz/openbox] / 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 setValues();
67 }
68
69 void Configmenu::setValues() {
70 setItemSelected(2, screen.getImageControl()->doDither());
71 setItemSelected(3, screen.opaqueMove());
72 setItemSelected(4, screen.fullMax());
73 setItemSelected(5, screen.focusNew());
74 setItemSelected(6, screen.focusLast());
75 setItemSelected(7, screen.hideToolbar());
76 }
77
78 Configmenu::~Configmenu() {
79 delete focusmenu;
80 delete placementmenu;
81 }
82
83 void Configmenu::itemSelected(int button, int index) {
84 if (button != 1)
85 return;
86
87 BasemenuItem *item = find(index);
88
89 if (!item->function())
90 return;
91
92 switch(item->function()) {
93 case 1: { // dither
94 screen.setImageDither(!screen.getImageControl()->doDither());
95
96 setItemSelected(index, screen.getImageControl()->doDither());
97
98 break;
99 }
100
101 case 2: { // opaque move
102 screen.setOpaqueMove(!screen.opaqueMove());
103
104 setItemSelected(index, screen.opaqueMove());
105
106 break;
107 }
108
109 case 3: { // full maximization
110 screen.setFullMax(!screen.fullMax());
111
112 setItemSelected(index, screen.fullMax());
113
114 break;
115 }
116 case 4: { // focus new windows
117 screen.setFocusNew(!screen.focusNew());
118
119 setItemSelected(index, screen.focusNew());
120 break;
121 }
122
123 case 5: { // focus last window on workspace
124 screen.setFocusLast(!screen.focusLast());
125 setItemSelected(index, screen.focusLast());
126 break;
127 }
128 case 6:{ //toggle toolbar hide
129 screen.setHideToolbar(!screen.hideToolbar());
130 setItemSelected(index, screen.hideToolbar());
131 break;
132 }
133 } // switch
134 }
135
136 void Configmenu::reconfigure() {
137 setValues();
138 focusmenu->reconfigure();
139 placementmenu->reconfigure();
140
141 Basemenu::reconfigure();
142 }
143
144 Configmenu::Focusmenu::Focusmenu(Configmenu *cm) : Basemenu(cm->screen) {
145 configmenu = cm;
146
147 setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusModel,
148 "Focus Model"));
149 setInternalMenu();
150
151 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuClickToFocus,
152 "Click To Focus"), 1);
153 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSloppyFocus,
154 "Sloppy Focus"), 2);
155 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuAutoRaise,
156 "Auto Raise"), 3);
157 update();
158
159 setValues();
160 }
161
162 void Configmenu::Focusmenu::setValues() {
163 setItemSelected(0, !configmenu->screen.sloppyFocus());
164 setItemSelected(1, configmenu->screen.sloppyFocus());
165 setItemEnabled(2, configmenu->screen.sloppyFocus());
166 setItemSelected(2, configmenu->screen.autoRaise());
167 }
168
169 void Configmenu::Focusmenu::reconfigure() {
170 setValues();
171 Basemenu::reconfigure();
172 }
173
174 void Configmenu::Focusmenu::itemSelected(int button, int index) {
175 if (button != 1)
176 return;
177
178 BasemenuItem *item = find(index);
179
180 if (!item->function())
181 return;
182
183 switch (item->function()) {
184 case 1: // click to focus
185 configmenu->screen.setSloppyFocus(false);
186 configmenu->screen.setAutoRaise(false);
187
188 if (! configmenu->screen.getOpenbox().focusedWindow())
189 XSetInputFocus(configmenu->screen.getOpenbox().getXDisplay(),
190 configmenu->screen.getToolbar()->getWindowID(),
191 RevertToParent, CurrentTime);
192 else
193 XSetInputFocus(configmenu->screen.getOpenbox().getXDisplay(),
194 configmenu->screen.getOpenbox().
195 focusedWindow()->getClientWindow(),
196 RevertToParent, CurrentTime);
197
198 configmenu->screen.reconfigure();
199
200 break;
201
202 case 2: // sloppy focus
203 configmenu->screen.setSloppyFocus(true);
204
205 configmenu->screen.reconfigure();
206
207 break;
208
209 case 3: // auto raise with sloppy focus
210 bool change = ((configmenu->screen.autoRaise()) ? false : true);
211 configmenu->screen.setAutoRaise(change);
212
213 break;
214 }
215
216 setItemSelected(0, !configmenu->screen.sloppyFocus());
217 setItemSelected(1, configmenu->screen.sloppyFocus());
218 setItemEnabled(2, configmenu->screen.sloppyFocus());
219 setItemSelected(2, configmenu->screen.autoRaise());
220 }
221
222 Configmenu::Placementmenu::Placementmenu(Configmenu *cm) :
223 Basemenu(cm->screen) {
224 configmenu = cm;
225
226 setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuWindowPlacement,
227 "Window Placement"));
228 setInternalMenu();
229
230 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSmartRows,
231 "Smart Placement (Rows)"),
232 BScreen::RowSmartPlacement);
233 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSmartCols,
234 "Smart Placement (Columns)"),
235 BScreen::ColSmartPlacement);
236 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuCascade,
237 "Cascade Placement"), BScreen::CascadePlacement);
238 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBestFit,
239 "Best Fit Placement"), BScreen::BestFitPlacement);
240 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuUnderMouse,
241 "Under Mouse Placement"),
242 BScreen::UnderMousePlacement);
243 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuClickMouse,
244 "Click Mouse Placement"),
245 BScreen::ClickMousePlacement);
246 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuLeftRight,
247 "Left to Right"), BScreen::LeftRight);
248 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuRightLeft,
249 "Right to Left"), BScreen::RightLeft);
250 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuTopBottom,
251 "Top to Bottom"), BScreen::TopBottom);
252 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBottomTop,
253 "Bottom to Top"), BScreen::BottomTop);
254 update();
255
256 setValues();
257 }
258
259 void Configmenu::Placementmenu::setValues() {
260 const int p = configmenu->screen.placementPolicy();
261 setItemSelected(0, p == BScreen::RowSmartPlacement);
262 setItemSelected(1, p == BScreen::ColSmartPlacement);
263 setItemSelected(2, p == BScreen::CascadePlacement);
264 setItemSelected(3, p == BScreen::BestFitPlacement);
265 setItemSelected(4, p == BScreen::UnderMousePlacement);
266 setItemSelected(5, p == BScreen::ClickMousePlacement);
267
268 bool rl = (configmenu->screen.rowPlacementDirection() ==
269 BScreen::LeftRight),
270 tb = (configmenu->screen.colPlacementDirection() ==
271 BScreen::TopBottom);
272
273 setItemSelected(6, rl);
274 setItemEnabled(6, (p != BScreen::UnderMousePlacement &&
275 p != BScreen::ClickMousePlacement));
276 setItemSelected(7, !rl);
277 setItemEnabled(7, (p != BScreen::UnderMousePlacement &&
278 p != BScreen::ClickMousePlacement));
279
280 setItemSelected(8, tb);
281 setItemEnabled(8, (p != BScreen::UnderMousePlacement &&
282 p != BScreen::ClickMousePlacement));
283 setItemSelected(9, !tb);
284 setItemEnabled(9, (p != BScreen::UnderMousePlacement &&
285 p != BScreen::ClickMousePlacement));
286 }
287
288 void Configmenu::Placementmenu::reconfigure() {
289 setValues();
290 Basemenu::reconfigure();
291 }
292
293 void Configmenu::Placementmenu::itemSelected(int button, int index) {
294 if (button != 1)
295 return;
296
297 BasemenuItem *item = find(index);
298
299 if (!item->function())
300 return;
301
302 switch (item->function()) {
303 case BScreen::RowSmartPlacement:
304 configmenu->screen.setPlacementPolicy(item->function());
305 break;
306
307 case BScreen::ColSmartPlacement:
308 configmenu->screen.setPlacementPolicy(item->function());
309 break;
310
311 case BScreen::CascadePlacement:
312 configmenu->screen.setPlacementPolicy(item->function());
313 break;
314
315 case BScreen::BestFitPlacement:
316 configmenu->screen.setPlacementPolicy(item->function());
317 break;
318
319 case BScreen::UnderMousePlacement:
320 configmenu->screen.setPlacementPolicy(item->function());
321 break;
322
323 case BScreen::ClickMousePlacement:
324 configmenu->screen.setPlacementPolicy(item->function());
325 break;
326
327 case BScreen::LeftRight:
328 configmenu->screen.setRowPlacementDirection(BScreen::LeftRight);
329 break;
330
331 case BScreen::RightLeft:
332 configmenu->screen.setRowPlacementDirection(BScreen::RightLeft);
333 break;
334
335 case BScreen::TopBottom:
336 configmenu->screen.setColPlacementDirection(BScreen::TopBottom);
337 break;
338
339 case BScreen::BottomTop:
340 configmenu->screen.setColPlacementDirection(BScreen::BottomTop);
341 break;
342 }
343 setValues();
344 }
This page took 0.051856 seconds and 4 git commands to generate.