openbox/src/Configmenu.cc

350 lines
9.7 KiB
C++
Raw Normal View History

2002-04-11 03:20:38 +00:00
// Configmenu.cc for Openbox
// Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// stupid macros needed to access some functions in version 2 of the GNU C
// library
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif // _GNU_SOURCE
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif // HAVE_CONFIG_H
#include "i18n.h"
#include "Configmenu.h"
#include "Toolbar.h"
#include "Window.h"
#include "Screen.h"
Configmenu::Configmenu(BScreen &scr) : Basemenu(scr), screen(scr)
{
2002-04-11 03:20:38 +00:00
setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuConfigOptions,
"Config options"));
setInternalMenu();
focusmenu = new Focusmenu(this);
placementmenu = new Placementmenu(this);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusModel,
"Focus Model"), focusmenu);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuWindowPlacement,
"Window Placement"), placementmenu);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuImageDithering,
"Image Dithering"), 1);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuOpaqueMove,
"Opaque Window Moving"), 2);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFullMax,
"Full Maximization"), 3);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusNew,
"Focus New Windows"), 4);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusLast,
"Focus Last Window on Workspace"), 5);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuHideToolbar,
"Hide toolbar"), 6);
2002-04-11 03:20:38 +00:00
update();
setItemSelected(2, screen.getImageControl()->doDither());
setItemSelected(3, screen.opaqueMove());
setItemSelected(4, screen.fullMax());
setItemSelected(5, screen.focusNew());
setItemSelected(6, screen.focusLast());
setItemSelected(7, screen.hideToolbar());
2002-04-11 03:20:38 +00:00
}
Configmenu::~Configmenu(void) {
delete focusmenu;
delete placementmenu;
}
void Configmenu::itemSelected(int button, int index) {
if (button != 1)
return;
BasemenuItem *item = find(index);
if (!item->function())
return;
switch(item->function()) {
case 1: { // dither
screen.getImageControl()->
setDither((! screen.getImageControl()->doDither()));
2002-04-11 03:20:38 +00:00
setItemSelected(index, screen.getImageControl()->doDither());
2002-04-11 03:20:38 +00:00
break;
}
case 2: { // opaque move
screen.setOpaqueMove(!screen.opaqueMove());
2002-04-11 03:20:38 +00:00
setItemSelected(index, screen.opaqueMove());
2002-04-11 03:20:38 +00:00
break;
}
case 3: { // full maximization
screen.setFullMax(!screen.fullMax());
2002-04-11 03:20:38 +00:00
setItemSelected(index, screen.fullMax());
2002-04-11 03:20:38 +00:00
break;
}
case 4: { // focus new windows
screen.setFocusNew(!screen.focusNew());
2002-04-11 03:20:38 +00:00
setItemSelected(index, screen.focusNew());
2002-04-11 03:20:38 +00:00
break;
}
case 5: { // focus last window on workspace
screen.setFocusLast(!screen.focusLast());
setItemSelected(index, screen.focusLast());
2002-04-11 03:20:38 +00:00
break;
}
case 6:{ //toggle toolbar hide
screen.setHideToolbar(!screen.hideToolbar());
setItemSelected(index, screen.hideToolbar());
break;
}
2002-04-11 03:20:38 +00:00
} // switch
}
void Configmenu::reconfigure(void) {
focusmenu->reconfigure();
placementmenu->reconfigure();
Basemenu::reconfigure();
}
Configmenu::Focusmenu::Focusmenu(Configmenu *cm) : Basemenu(cm->screen) {
configmenu = cm;
setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuFocusModel,
"Focus Model"));
setInternalMenu();
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuClickToFocus,
"Click To Focus"), 1);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSloppyFocus,
"Sloppy Focus"), 2);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuAutoRaise,
"Auto Raise"), 3);
update();
setItemSelected(0, !configmenu->screen.sloppyFocus());
setItemSelected(1, configmenu->screen.sloppyFocus());
setItemEnabled(2, configmenu->screen.sloppyFocus());
setItemSelected(2, configmenu->screen.autoRaise());
2002-04-11 03:20:38 +00:00
}
void Configmenu::Focusmenu::itemSelected(int button, int index) {
if (button != 1)
return;
BasemenuItem *item = find(index);
if (!item->function())
return;
switch (item->function()) {
case 1: // click to focus
configmenu->screen.setSloppyFocus(false);
configmenu->screen.setAutoRaise(false);
2002-04-11 03:20:38 +00:00
if (! configmenu->screen.getOpenbox().getFocusedWindow())
XSetInputFocus(configmenu->screen.getOpenbox().getXDisplay(),
configmenu->screen.getToolbar()->getWindowID(),
2002-04-11 03:20:38 +00:00
RevertToParent, CurrentTime);
else
XSetInputFocus(configmenu->screen.getOpenbox().getXDisplay(),
configmenu->screen.getOpenbox().
2002-04-11 03:20:38 +00:00
getFocusedWindow()->getClientWindow(),
RevertToParent, CurrentTime);
configmenu->screen.reconfigure();
2002-04-11 03:20:38 +00:00
break;
case 2: // sloppy focus
configmenu->screen.setSloppyFocus(true);
2002-04-11 03:20:38 +00:00
configmenu->screen.reconfigure();
2002-04-11 03:20:38 +00:00
break;
case 3: // auto raise with sloppy focus
bool change = ((configmenu->screen.autoRaise()) ? false : true);
configmenu->screen.setAutoRaise(change);
2002-04-11 03:20:38 +00:00
break;
}
setItemSelected(0, !configmenu->screen.sloppyFocus());
setItemSelected(1, configmenu->screen.sloppyFocus());
setItemEnabled(2, configmenu->screen.sloppyFocus());
setItemSelected(2, configmenu->screen.autoRaise());
2002-04-11 03:20:38 +00:00
}
Configmenu::Placementmenu::Placementmenu(Configmenu *cm) :
Basemenu(cm->screen) {
configmenu = cm;
setLabel(i18n->getMessage(ConfigmenuSet, ConfigmenuWindowPlacement,
"Window Placement"));
setInternalMenu();
2002-04-11 03:20:38 +00:00
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSmartRows,
"Smart Placement (Rows)"),
BScreen::RowSmartPlacement);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuSmartCols,
"Smart Placement (Columns)"),
BScreen::ColSmartPlacement);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuCascade,
"Cascade Placement"), BScreen::CascadePlacement);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBestFit,
"Best Fit Placement"), BScreen::BestFitPlacement);
2002-04-11 03:20:38 +00:00
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuLeftRight,
"Left to Right"), BScreen::LeftRight);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuRightLeft,
"Right to Left"), BScreen::RightLeft);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuTopBottom,
"Top to Bottom"), BScreen::TopBottom);
insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBottomTop,
"Bottom to Top"), BScreen::BottomTop);
update();
switch (configmenu->screen.placementPolicy()) {
2002-04-11 03:20:38 +00:00
case BScreen::RowSmartPlacement:
setItemSelected(0, True);
break;
case BScreen::ColSmartPlacement:
setItemSelected(1, True);
break;
case BScreen::CascadePlacement:
setItemSelected(2, True);
break;
case BScreen::BestFitPlacement:
setItemSelected(3, True);
break;
2002-04-11 03:20:38 +00:00
}
Bool rl = (configmenu->screen.rowPlacementDirection() ==
2002-04-11 03:20:38 +00:00
BScreen::LeftRight),
tb = (configmenu->screen.colPlacementDirection() ==
2002-04-11 03:20:38 +00:00
BScreen::TopBottom);
setItemSelected(4, rl);
setItemSelected(5, !rl);
2002-04-11 03:20:38 +00:00
setItemSelected(6, tb);
setItemSelected(7, !tb);
2002-04-11 03:20:38 +00:00
}
void Configmenu::Placementmenu::itemSelected(int button, int index) {
if (button != 1)
return;
BasemenuItem *item = find(index);
if (!item->function())
return;
switch (item->function()) {
case BScreen::RowSmartPlacement:
configmenu->screen.setPlacementPolicy(item->function());
2002-04-11 03:20:38 +00:00
setItemSelected(0, True);
setItemSelected(1, False);
setItemSelected(2, False);
setItemSelected(3, False);
2002-04-11 03:20:38 +00:00
break;
case BScreen::ColSmartPlacement:
configmenu->screen.setPlacementPolicy(item->function());
2002-04-11 03:20:38 +00:00
setItemSelected(0, False);
setItemSelected(1, True);
setItemSelected(2, False);
setItemSelected(3, False);
2002-04-11 03:20:38 +00:00
break;
case BScreen::CascadePlacement:
configmenu->screen.setPlacementPolicy(item->function());
2002-04-11 03:20:38 +00:00
setItemSelected(0, False);
setItemSelected(1, False);
setItemSelected(2, True);
setItemSelected(3, False);
break;
case BScreen::BestFitPlacement:
configmenu->screen.setPlacementPolicy(item->function());
setItemSelected(0, False);
setItemSelected(1, False);
setItemSelected(2, False);
setItemSelected(3, True);
2002-04-11 03:20:38 +00:00
break;
case BScreen::LeftRight:
configmenu->screen.setRowPlacementDirection(BScreen::LeftRight);
2002-04-11 03:20:38 +00:00
setItemSelected(4, True);
setItemSelected(5, False);
2002-04-11 03:20:38 +00:00
break;
case BScreen::RightLeft:
configmenu->screen.setRowPlacementDirection(BScreen::RightLeft);
2002-04-11 03:20:38 +00:00
setItemSelected(4, False);
setItemSelected(5, True);
2002-04-11 03:20:38 +00:00
break;
case BScreen::TopBottom:
configmenu->screen.setColPlacementDirection(BScreen::TopBottom);
2002-04-11 03:20:38 +00:00
setItemSelected(5, True);
setItemSelected(6, False);
break;
case BScreen::BottomTop:
configmenu->screen.setColPlacementDirection(BScreen::BottomTop);
2002-04-11 03:20:38 +00:00
setItemSelected(5, False);
setItemSelected(6, True);
break;
}
}