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
), screen(scr
)
41 setLabel(i18n
->getMessage(ConfigmenuSet
, ConfigmenuConfigOptions
,
45 focusmenu
= new Focusmenu(this);
46 placementmenu
= new Placementmenu(this);
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
,
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());
78 Configmenu::~Configmenu() {
83 void Configmenu::itemSelected(int button
, int index
) {
87 BasemenuItem
*item
= find(index
);
89 if (!item
->function())
92 switch(item
->function()) {
94 screen
.setImageDither(!screen
.getImageControl()->doDither());
96 setItemSelected(index
, screen
.getImageControl()->doDither());
101 case 2: { // opaque move
102 screen
.setOpaqueMove(!screen
.opaqueMove());
104 setItemSelected(index
, screen
.opaqueMove());
109 case 3: { // full maximization
110 screen
.setFullMax(!screen
.fullMax());
112 setItemSelected(index
, screen
.fullMax());
116 case 4: { // focus new windows
117 screen
.setFocusNew(!screen
.focusNew());
119 setItemSelected(index
, screen
.focusNew());
123 case 5: { // focus last window on workspace
124 screen
.setFocusLast(!screen
.focusLast());
125 setItemSelected(index
, screen
.focusLast());
128 case 6:{ //toggle toolbar hide
129 screen
.setHideToolbar(!screen
.hideToolbar());
130 setItemSelected(index
, screen
.hideToolbar());
136 void Configmenu::reconfigure() {
138 focusmenu
->reconfigure();
139 placementmenu
->reconfigure();
141 Basemenu::reconfigure();
144 Configmenu::Focusmenu::Focusmenu(Configmenu
*cm
) : Basemenu(cm
->screen
) {
147 setLabel(i18n
->getMessage(ConfigmenuSet
, ConfigmenuFocusModel
,
151 insert(i18n
->getMessage(ConfigmenuSet
, ConfigmenuClickToFocus
,
152 "Click To Focus"), 1);
153 insert(i18n
->getMessage(ConfigmenuSet
, ConfigmenuSloppyFocus
,
155 insert(i18n
->getMessage(ConfigmenuSet
, ConfigmenuAutoRaise
,
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());
169 void Configmenu::Focusmenu::reconfigure() {
171 Basemenu::reconfigure();
174 void Configmenu::Focusmenu::itemSelected(int button
, int index
) {
178 BasemenuItem
*item
= find(index
);
180 if (!item
->function())
183 switch (item
->function()) {
184 case 1: // click to focus
185 configmenu
->screen
.setSloppyFocus(false);
186 configmenu
->screen
.setAutoRaise(false);
188 if (! configmenu
->screen
.getOpenbox().focusedWindow())
189 XSetInputFocus(configmenu
->screen
.getOpenbox().getXDisplay(),
190 configmenu
->screen
.getToolbar()->getWindowID(),
191 RevertToParent
, CurrentTime
);
193 XSetInputFocus(configmenu
->screen
.getOpenbox().getXDisplay(),
194 configmenu
->screen
.getOpenbox().
195 focusedWindow()->getClientWindow(),
196 RevertToParent
, CurrentTime
);
198 configmenu
->screen
.reconfigure();
202 case 2: // sloppy focus
203 configmenu
->screen
.setSloppyFocus(true);
205 configmenu
->screen
.reconfigure();
209 case 3: // auto raise with sloppy focus
210 bool change
= ((configmenu
->screen
.autoRaise()) ? false : true);
211 configmenu
->screen
.setAutoRaise(change
);
216 setItemSelected(0, !configmenu
->screen
.sloppyFocus());
217 setItemSelected(1, configmenu
->screen
.sloppyFocus());
218 setItemEnabled(2, configmenu
->screen
.sloppyFocus());
219 setItemSelected(2, configmenu
->screen
.autoRaise());
222 Configmenu::Placementmenu::Placementmenu(Configmenu
*cm
) :
223 Basemenu(cm
->screen
) {
226 setLabel(i18n
->getMessage(ConfigmenuSet
, ConfigmenuWindowPlacement
,
227 "Window Placement"));
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
);
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
);
268 bool rl
= (configmenu
->screen
.rowPlacementDirection() ==
270 tb
= (configmenu
->screen
.colPlacementDirection() ==
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
));
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
));
288 void Configmenu::Placementmenu::reconfigure() {
290 Basemenu::reconfigure();
293 void Configmenu::Placementmenu::itemSelected(int button
, int index
) {
297 BasemenuItem
*item
= find(index
);
299 if (!item
->function())
302 switch (item
->function()) {
303 case BScreen::RowSmartPlacement
:
304 configmenu
->screen
.setPlacementPolicy(item
->function());
307 case BScreen::ColSmartPlacement
:
308 configmenu
->screen
.setPlacementPolicy(item
->function());
311 case BScreen::CascadePlacement
:
312 configmenu
->screen
.setPlacementPolicy(item
->function());
315 case BScreen::BestFitPlacement
:
316 configmenu
->screen
.setPlacementPolicy(item
->function());
319 case BScreen::UnderMousePlacement
:
320 configmenu
->screen
.setPlacementPolicy(item
->function());
323 case BScreen::ClickMousePlacement
:
324 configmenu
->screen
.setPlacementPolicy(item
->function());
327 case BScreen::LeftRight
:
328 configmenu
->screen
.setRowPlacementDirection(BScreen::LeftRight
);
331 case BScreen::RightLeft
:
332 configmenu
->screen
.setRowPlacementDirection(BScreen::RightLeft
);
335 case BScreen::TopBottom
:
336 configmenu
->screen
.setColPlacementDirection(BScreen::TopBottom
);
339 case BScreen::BottomTop
:
340 configmenu
->screen
.setColPlacementDirection(BScreen::BottomTop
);