]> Dogcows Code - chaz/openbox/blob - src/Configmenu.cc
*** empty log message ***
[chaz/openbox] / src / Configmenu.cc
1 // Configmenu.cc for Openbox
2 // Copyright (c) 2002 - 2002 Ben Jansens <ben@orodu.net>
3 // Copyright (c) 2001 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 // stupid macros needed to access some functions in version 2 of the GNU C
25 // library
26 #ifndef _GNU_SOURCE
27 # define _GNU_SOURCE
28 #endif // _GNU_SOURCE
29
30 #ifdef HAVE_CONFIG_H
31 # include "../config.h"
32 #endif // HAVE_CONFIG_H
33
34 #include "i18n.h"
35 #include "Configmenu.h"
36 #include "Toolbar.h"
37 #include "Window.h"
38 #include "Screen.h"
39
40 Configmenu::Configmenu(BScreen &scr) : Basemenu(scr), screen(scr)
41 {
42 setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuConfigOptions,
43 "Config options"));
44 setInternalMenu();
45
46 focusmenu = new Focusmenu(this);
47 placementmenu = new Placementmenu(this);
48
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);
63 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuHideToolbar,
64 "Hide toolbar"), 6);
65 update();
66
67 setValues();
68 }
69
70 void Configmenu::setValues() {
71 setItemSelected(2, screen.imageDither());
72 setItemSelected(3, screen.opaqueMove());
73 setItemSelected(4, screen.fullMax());
74 setItemSelected(5, screen.focusNew());
75 setItemSelected(6, screen.focusLast());
76 setItemSelected(7, screen.hideToolbar());
77 }
78
79 Configmenu::~Configmenu() {
80 delete focusmenu;
81 delete placementmenu;
82 }
83
84 void Configmenu::itemSelected(int button, int index) {
85 if (button != 1)
86 return;
87
88 BasemenuItem *item = find(index);
89
90 if (!item->function())
91 return;
92
93 switch(item->function()) {
94 case 1: { // dither
95 screen.setImageDither(!screen.imageDither());
96
97 setItemSelected(index, screen.imageDither());
98
99 break;
100 }
101
102 case 2: { // opaque move
103 screen.setOpaqueMove(!screen.opaqueMove());
104
105 setItemSelected(index, screen.opaqueMove());
106
107 break;
108 }
109
110 case 3: { // full maximization
111 screen.setFullMax(!screen.fullMax());
112
113 setItemSelected(index, screen.fullMax());
114
115 break;
116 }
117 case 4: { // focus new windows
118 screen.setFocusNew(!screen.focusNew());
119
120 setItemSelected(index, screen.focusNew());
121 break;
122 }
123
124 case 5: { // focus last window on workspace
125 screen.setFocusLast(!screen.focusLast());
126 setItemSelected(index, screen.focusLast());
127 break;
128 }
129 case 6:{ //toggle toolbar hide
130 screen.setHideToolbar(!screen.hideToolbar());
131 setItemSelected(index, screen.hideToolbar());
132 break;
133 }
134 } // switch
135 }
136
137 void Configmenu::reconfigure() {
138 setValues();
139 focusmenu->reconfigure();
140 placementmenu->reconfigure();
141
142 Basemenu::reconfigure();
143 }
144
145 Configmenu::Focusmenu::Focusmenu(Configmenu *cm) : Basemenu(cm->screen) {
146 configmenu = cm;
147
148 setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusModel,
149 "Focus Model"));
150 setInternalMenu();
151
152 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuClickToFocus,
153 "Click To Focus"), 1);
154 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSloppyFocus,
155 "Sloppy Focus"), 2);
156 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuAutoRaise,
157 "Auto Raise"), 3);
158 update();
159
160 setValues();
161 }
162
163 void Configmenu::Focusmenu::setValues() {
164 setItemSelected(0, !configmenu->screen.sloppyFocus());
165 setItemSelected(1, configmenu->screen.sloppyFocus());
166 setItemEnabled(2, configmenu->screen.sloppyFocus());
167 setItemSelected(2, configmenu->screen.autoRaise());
168 }
169
170 void Configmenu::Focusmenu::reconfigure() {
171 setValues();
172 Basemenu::reconfigure();
173 }
174
175 void Configmenu::Focusmenu::itemSelected(int button, int index) {
176 if (button != 1)
177 return;
178
179 BasemenuItem *item = find(index);
180
181 if (!item->function())
182 return;
183
184 switch (item->function()) {
185 case 1: // click to focus
186 configmenu->screen.setSloppyFocus(false);
187 configmenu->screen.setAutoRaise(false);
188 // make windows all grab button1 clicks
189 configmenu->screen.reconfigure();
190 break;
191
192 case 2: // sloppy focus
193 configmenu->screen.setSloppyFocus(true);
194 // make windows stop grabbing button1 clicks
195 configmenu->screen.reconfigure();
196 break;
197
198 case 3: // auto raise with sloppy focus
199 configmenu->screen.setAutoRaise(!configmenu->screen.autoRaise());
200 break;
201 }
202
203 setItemSelected(0, !configmenu->screen.sloppyFocus());
204 setItemSelected(1, configmenu->screen.sloppyFocus());
205 setItemEnabled(2, configmenu->screen.sloppyFocus());
206 setItemSelected(2, configmenu->screen.autoRaise());
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, ConfigmenuUnderMouse,
228 "Under Mouse Placement"),
229 BScreen::UnderMousePlacement);
230 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuClickMouse,
231 "Click Mouse Placement"),
232 BScreen::ClickMousePlacement);
233 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuLeftRight,
234 "Left to Right"), BScreen::LeftRight);
235 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuRightLeft,
236 "Right to Left"), BScreen::RightLeft);
237 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuTopBottom,
238 "Top to Bottom"), BScreen::TopBottom);
239 insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBottomTop,
240 "Bottom to Top"), BScreen::BottomTop);
241 update();
242
243 setValues();
244 }
245
246 void Configmenu::Placementmenu::setValues() {
247 const int p = configmenu->screen.placementPolicy();
248 setItemSelected(0, p == BScreen::RowSmartPlacement);
249 setItemSelected(1, p == BScreen::ColSmartPlacement);
250 setItemSelected(2, p == BScreen::CascadePlacement);
251 setItemSelected(3, p == BScreen::BestFitPlacement);
252 setItemSelected(4, p == BScreen::UnderMousePlacement);
253 setItemSelected(5, p == BScreen::ClickMousePlacement);
254
255 bool rl = (configmenu->screen.rowPlacementDirection() ==
256 BScreen::LeftRight),
257 tb = (configmenu->screen.colPlacementDirection() ==
258 BScreen::TopBottom);
259
260 setItemSelected(6, rl);
261 setItemEnabled(6, (p != BScreen::UnderMousePlacement &&
262 p != BScreen::ClickMousePlacement));
263 setItemSelected(7, !rl);
264 setItemEnabled(7, (p != BScreen::UnderMousePlacement &&
265 p != BScreen::ClickMousePlacement));
266
267 setItemSelected(8, tb);
268 setItemEnabled(8, (p != BScreen::UnderMousePlacement &&
269 p != BScreen::ClickMousePlacement));
270 setItemSelected(9, !tb);
271 setItemEnabled(9, (p != BScreen::UnderMousePlacement &&
272 p != BScreen::ClickMousePlacement));
273 }
274
275 void Configmenu::Placementmenu::reconfigure() {
276 setValues();
277 Basemenu::reconfigure();
278 }
279
280 void Configmenu::Placementmenu::itemSelected(int button, int index) {
281 if (button != 1)
282 return;
283
284 BasemenuItem *item = find(index);
285
286 if (!item->function())
287 return;
288
289 switch (item->function()) {
290 case BScreen::RowSmartPlacement:
291 configmenu->screen.setPlacementPolicy(item->function());
292 break;
293
294 case BScreen::ColSmartPlacement:
295 configmenu->screen.setPlacementPolicy(item->function());
296 break;
297
298 case BScreen::CascadePlacement:
299 configmenu->screen.setPlacementPolicy(item->function());
300 break;
301
302 case BScreen::BestFitPlacement:
303 configmenu->screen.setPlacementPolicy(item->function());
304 break;
305
306 case BScreen::UnderMousePlacement:
307 configmenu->screen.setPlacementPolicy(item->function());
308 break;
309
310 case BScreen::ClickMousePlacement:
311 configmenu->screen.setPlacementPolicy(item->function());
312 break;
313
314 case BScreen::LeftRight:
315 configmenu->screen.setRowPlacementDirection(BScreen::LeftRight);
316 break;
317
318 case BScreen::RightLeft:
319 configmenu->screen.setRowPlacementDirection(BScreen::RightLeft);
320 break;
321
322 case BScreen::TopBottom:
323 configmenu->screen.setColPlacementDirection(BScreen::TopBottom);
324 break;
325
326 case BScreen::BottomTop:
327 configmenu->screen.setColPlacementDirection(BScreen::BottomTop);
328 break;
329 }
330 setValues();
331 }
This page took 0.047088 seconds and 4 git commands to generate.