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)
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:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
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.
24 // stupid macros needed to access some functions in version 2 of the GNU C
31 # include "../config.h"
32 #endif // HAVE_CONFIG_H
35 #include "Configmenu.h"
40 Configmenu::Configmenu(BScreen
&scr
) : Basemenu(scr
), screen(scr
)
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);
63 insert(i18n
->getMessage(ConfigmenuSet
, ConfigmenuHideToolbar
,
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());
79 Configmenu::~Configmenu() {
84 void Configmenu::itemSelected(int button
, int index
) {
88 BasemenuItem
*item
= find(index
);
90 if (!item
->function())
93 switch(item
->function()) {
95 screen
.setImageDither(!screen
.imageDither());
97 setItemSelected(index
, screen
.imageDither());
102 case 2: { // opaque move
103 screen
.setOpaqueMove(!screen
.opaqueMove());
105 setItemSelected(index
, screen
.opaqueMove());
110 case 3: { // full maximization
111 screen
.setFullMax(!screen
.fullMax());
113 setItemSelected(index
, screen
.fullMax());
117 case 4: { // focus new windows
118 screen
.setFocusNew(!screen
.focusNew());
120 setItemSelected(index
, screen
.focusNew());
124 case 5: { // focus last window on workspace
125 screen
.setFocusLast(!screen
.focusLast());
126 setItemSelected(index
, screen
.focusLast());
129 case 6:{ //toggle toolbar hide
130 screen
.setHideToolbar(!screen
.hideToolbar());
131 setItemSelected(index
, screen
.hideToolbar());
137 void Configmenu::reconfigure() {
139 focusmenu
->reconfigure();
140 placementmenu
->reconfigure();
142 Basemenu::reconfigure();
145 Configmenu::Focusmenu::Focusmenu(Configmenu
*cm
) : Basemenu(cm
->screen
) {
148 setLabel(i18n
->getMessage(ConfigmenuSet
, ConfigmenuFocusModel
,
152 insert(i18n
->getMessage(ConfigmenuSet
, ConfigmenuClickToFocus
,
153 "Click To Focus"), 1);
154 insert(i18n
->getMessage(ConfigmenuSet
, ConfigmenuSloppyFocus
,
156 insert(i18n
->getMessage(ConfigmenuSet
, ConfigmenuAutoRaise
,
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());
170 void Configmenu::Focusmenu::reconfigure() {
172 Basemenu::reconfigure();
175 void Configmenu::Focusmenu::itemSelected(int button
, int index
) {
179 BasemenuItem
*item
= find(index
);
181 if (!item
->function())
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();
192 case 2: // sloppy focus
193 configmenu
->screen
.setSloppyFocus(true);
194 // make windows stop grabbing button1 clicks
195 configmenu
->screen
.reconfigure();
198 case 3: // auto raise with sloppy focus
199 configmenu
->screen
.setAutoRaise(!configmenu
->screen
.autoRaise());
203 setItemSelected(0, !configmenu
->screen
.sloppyFocus());
204 setItemSelected(1, configmenu
->screen
.sloppyFocus());
205 setItemEnabled(2, configmenu
->screen
.sloppyFocus());
206 setItemSelected(2, configmenu
->screen
.autoRaise());
209 Configmenu::Placementmenu::Placementmenu(Configmenu
*cm
) :
210 Basemenu(cm
->screen
) {
213 setLabel(i18n
->getMessage(ConfigmenuSet
, ConfigmenuWindowPlacement
,
214 "Window Placement"));
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
);
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
);
255 bool rl
= (configmenu
->screen
.rowPlacementDirection() ==
257 tb
= (configmenu
->screen
.colPlacementDirection() ==
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
));
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
));
275 void Configmenu::Placementmenu::reconfigure() {
277 Basemenu::reconfigure();
280 void Configmenu::Placementmenu::itemSelected(int button
, int index
) {
284 BasemenuItem
*item
= find(index
);
286 if (!item
->function())
289 switch (item
->function()) {
290 case BScreen::RowSmartPlacement
:
291 configmenu
->screen
.setPlacementPolicy(item
->function());
294 case BScreen::ColSmartPlacement
:
295 configmenu
->screen
.setPlacementPolicy(item
->function());
298 case BScreen::CascadePlacement
:
299 configmenu
->screen
.setPlacementPolicy(item
->function());
302 case BScreen::BestFitPlacement
:
303 configmenu
->screen
.setPlacementPolicy(item
->function());
306 case BScreen::UnderMousePlacement
:
307 configmenu
->screen
.setPlacementPolicy(item
->function());
310 case BScreen::ClickMousePlacement
:
311 configmenu
->screen
.setPlacementPolicy(item
->function());
314 case BScreen::LeftRight
:
315 configmenu
->screen
.setRowPlacementDirection(BScreen::LeftRight
);
318 case BScreen::RightLeft
:
319 configmenu
->screen
.setRowPlacementDirection(BScreen::RightLeft
);
322 case BScreen::TopBottom
:
323 configmenu
->screen
.setColPlacementDirection(BScreen::TopBottom
);
326 case BScreen::BottomTop
:
327 configmenu
->screen
.setColPlacementDirection(BScreen::BottomTop
);