add Configuration class for generic configuration data load/save-ing.

use Configuration class throughout code. no longer save rc file on exit, save when any options are changed.
This commit is contained in:
Dana Jansens 2002-05-26 20:25:38 +00:00
parent 60b2990e39
commit 0305cbdc3a
19 changed files with 1291 additions and 977 deletions

View file

@ -54,14 +54,19 @@ Configmenu::Configmenu(BScreen *scr) : Basemenu(scr) {
insert(i18n(ConfigmenuSet, ConfigmenuFocusLast,
"Focus Last Window on Workspace"), 5);
update();
setValues();
}
setItemSelected(2, getScreen()->getImageControl()->doDither());
void Configmenu::setValues(void) {
setItemSelected(2, getScreen()->doImageDither());
setItemSelected(3, getScreen()->doOpaqueMove());
setItemSelected(4, getScreen()->doFullMax());
setItemSelected(5, getScreen()->doFocusNew());
setItemSelected(6, getScreen()->doFocusLast());
}
Configmenu::~Configmenu(void) {
delete focusmenu;
delete placementmenu;
@ -78,32 +83,24 @@ void Configmenu::itemSelected(int button, unsigned int index) {
switch(item->function()) {
case 1: { // dither
getScreen()->getImageControl()->
setDither((! getScreen()->getImageControl()->doDither()));
setItemSelected(index, getScreen()->getImageControl()->doDither());
getScreen()->saveImageDither(! getScreen()->doImageDither());
setItemSelected(index, getScreen()->doImageDither());
break;
}
case 2: { // opaque move
getScreen()->saveOpaqueMove((! getScreen()->doOpaqueMove()));
setItemSelected(index, getScreen()->doOpaqueMove());
break;
}
case 3: { // full maximization
getScreen()->saveFullMax((! getScreen()->doFullMax()));
setItemSelected(index, getScreen()->doFullMax());
break;
}
case 4: { // focus new windows
getScreen()->saveFocusNew((! getScreen()->doFocusNew()));
setItemSelected(index, getScreen()->doFocusNew());
break;
}
@ -118,6 +115,7 @@ void Configmenu::itemSelected(int button, unsigned int index) {
void Configmenu::reconfigure(void) {
setValues();
focusmenu->reconfigure();
placementmenu->reconfigure();
@ -134,8 +132,12 @@ Configmenu::Focusmenu::Focusmenu(Configmenu *cm) : Basemenu(cm->getScreen()) {
insert(i18n(ConfigmenuSet, ConfigmenuAutoRaise, "Auto Raise"), 3);
insert(i18n(ConfigmenuSet, ConfigmenuClickRaise, "Click Raise"), 4);
update();
setValues();
}
setItemSelected(0, (! getScreen()->isSloppyFocus()));
void Configmenu::Focusmenu::setValues(void) {
setItemSelected(0, ! getScreen()->isSloppyFocus());
setItemSelected(1, getScreen()->isSloppyFocus());
setItemEnabled(2, getScreen()->isSloppyFocus());
setItemSelected(2, getScreen()->doAutoRaise());
@ -144,6 +146,12 @@ Configmenu::Focusmenu::Focusmenu(Configmenu *cm) : Basemenu(cm->getScreen()) {
}
void Configmenu::Focusmenu::reconfigure(void) {
setValues();
Basemenu::reconfigure();
}
void Configmenu::Focusmenu::itemSelected(int button, unsigned int index) {
if (button != 1)
return;
@ -171,13 +179,7 @@ void Configmenu::Focusmenu::itemSelected(int button, unsigned int index) {
getScreen()->updateFocusModel();
break;
}
setItemSelected(0, (! getScreen()->isSloppyFocus()));
setItemSelected(1, getScreen()->isSloppyFocus());
setItemEnabled(2, getScreen()->isSloppyFocus());
setItemSelected(2, getScreen()->doAutoRaise());
setItemEnabled(3, getScreen()->isSloppyFocus());
setItemSelected(3, getScreen()->doClickRaise());
setValues();
}
@ -201,7 +203,11 @@ Configmenu::Placementmenu::Placementmenu(Configmenu *cm):
insert(i18n(ConfigmenuSet, ConfigmenuBottomTop, "Bottom to Top"),
BScreen::BottomTop);
update();
setValues();
}
void Configmenu::Placementmenu::setValues(void) {
switch (getScreen()->getPlacementPolicy()) {
case BScreen::RowSmartPlacement:
setItemSelected(0, True);
@ -216,10 +222,8 @@ Configmenu::Placementmenu::Placementmenu(Configmenu *cm):
break;
}
bool rl = (getScreen()->getRowPlacementDirection() ==
BScreen::LeftRight),
tb = (getScreen()->getColPlacementDirection() ==
BScreen::TopBottom);
bool rl = (getScreen()->getRowPlacementDirection() == BScreen::LeftRight),
tb = (getScreen()->getColPlacementDirection() == BScreen::TopBottom);
setItemSelected(3, rl);
setItemSelected(4, ! rl);
@ -229,6 +233,12 @@ Configmenu::Placementmenu::Placementmenu(Configmenu *cm):
}
void Configmenu::Placementmenu::reconfigure(void) {
setValues();
Basemenu::reconfigure();
}
void Configmenu::Placementmenu::itemSelected(int button, unsigned int index) {
if (button != 1)
return;

View file

@ -40,9 +40,11 @@ private:
protected:
virtual void itemSelected(int button, unsigned int index);
virtual void setValues(void);
public:
Focusmenu(Configmenu *cm);
virtual void reconfigure(void);
};
class Placementmenu : public Basemenu {
@ -52,9 +54,11 @@ private:
protected:
virtual void itemSelected(int button, unsigned int index);
virtual void setValues(void);
public:
Placementmenu(Configmenu *cm);
virtual void reconfigure(void);
};
Focusmenu *focusmenu;
@ -68,6 +72,7 @@ private:
protected:
virtual void itemSelected(int button, unsigned int index);
virtual void setValues(void);
public:
Configmenu(BScreen *scr);
@ -76,7 +81,7 @@ public:
inline Basemenu *getFocusmenu(void) { return focusmenu; }
inline Basemenu *getPlacementmenu(void) { return placementmenu; }
void reconfigure(void);
virtual void reconfigure(void);
};
#endif // __Configmenu_hh

238
src/Configuration.cc Normal file
View file

@ -0,0 +1,238 @@
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
// Configuration.hh for Blackbox - an X11 Window manager
// Copyright (c) 2002 - 2002 Ben Jansens (ben@orodu.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.
#include "../config.h"
#include "Configuration.hh"
#include "Util.hh"
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif // HAVE_STDLIB_H
using std::string;
bool Configuration::m_initialized = false;
Configuration::Configuration(const string &file) {
setFile(file);
m_modified = false;
m_database = NULL;
m_autosave = true;
if (! m_initialized) {
XrmInitialize();
m_initialized = true;
}
}
Configuration::Configuration() {
m_modified = false;
m_database = NULL;
m_autosave = true;
if (! m_initialized) {
XrmInitialize();
m_initialized = true;
}
}
Configuration::~Configuration() {
if (m_database != NULL)
XrmDestroyDatabase(m_database);
}
void Configuration::setFile(const string &file) {
m_file = file;
}
void Configuration::setAutoSave(bool autosave) {
m_autosave = autosave;
}
void Configuration::save() {
assert(m_database != NULL);
XrmPutFileDatabase(m_database, m_file.c_str());
m_modified = false;
}
bool Configuration::load() {
if (m_database != NULL)
XrmDestroyDatabase(m_database);
m_modified = false;
if (NULL == (m_database = XrmGetFileDatabase(m_file.c_str())))
return false;
return true;
}
void Configuration::create() {
if (m_database != NULL)
XrmDestroyDatabase(m_database);
m_modified = false;
assert(NULL != (m_database = XrmGetStringDatabase("")));
}
void Configuration::setValue(const string &rname, bool value) {
assert(m_database != NULL);
const char *val = (value ? "True" : "False");
string rc_string = rname + ": " + val;
XrmPutLineResource(&m_database, rc_string.c_str());
m_modified = true;
if (m_autosave)
save();
}
void Configuration::setValue(const string &rname, unsigned long value) {
assert(m_database != NULL);
string rc_string = rname + ": " + itostring(value);
XrmPutLineResource(&m_database, rc_string.c_str());
m_modified = true;
if (m_autosave)
save();
}
void Configuration::setValue(const string &rname, long value) {
assert(m_database != NULL);
string rc_string = rname + ": " + itostring(value);
XrmPutLineResource(&m_database, rc_string.c_str());
m_modified = true;
if (m_autosave)
save();
}
void Configuration::setValue(const string &rname, const char *value) {
assert(m_database != NULL);
assert(value != NULL);
string rc_string = rname + ": " + value;
XrmPutLineResource(&m_database, rc_string.c_str());
m_modified = true;
if (m_autosave)
save();
}
void Configuration::setValue(const string &rname, const string &value) {
assert(m_database != NULL);
string rc_string = rname + ": " + value;
XrmPutLineResource(&m_database, rc_string.c_str());
m_modified = true;
if (m_autosave)
save();
}
bool Configuration::getValue(const string &rname, bool &value) const {
assert(m_database != NULL);
string rclass = createClassName(rname);
char *rettype;
XrmValue retvalue;
if (0 == XrmGetResource(m_database, rname.c_str(), rclass.c_str(),
&rettype, &retvalue) || retvalue.addr == NULL)
return false;
string val = retvalue.addr;
if (val == "true" || val == "True")
value = true;
else
value = false;
return true;
}
bool Configuration::getValue(const string &rname, long &value) const {
assert(m_database != NULL);
string rclass = createClassName(rname);
char *rettype;
XrmValue retvalue;
if (0 == XrmGetResource(m_database, rname.c_str(), rclass.c_str(),
&rettype, &retvalue) || retvalue.addr == NULL)
return false;
char *end;
value = strtol(retvalue.addr, &end, 10);
if (end == retvalue.addr)
return false;
return true;
}
bool Configuration::getValue(const string &rname, unsigned long &value) const {
assert(m_database != NULL);
string rclass = createClassName(rname);
char *rettype;
XrmValue retvalue;
if (0 == XrmGetResource(m_database, rname.c_str(), rclass.c_str(),
&rettype, &retvalue) || retvalue.addr == NULL)
return false;
char *end;
value = strtoul(retvalue.addr, &end, 10);
if (end == retvalue.addr)
return false;
return true;
}
bool Configuration::getValue(const string &rname,
string &value) const {
assert(m_database != NULL);
string rclass = createClassName(rname);
char *rettype;
XrmValue retvalue;
if (0 == XrmGetResource(m_database, rname.c_str(), rclass.c_str(),
&rettype, &retvalue) || retvalue.addr == NULL)
return false;
value = retvalue.addr;
return true;
}
string Configuration::createClassName(const string &rname) const {
string rclass(rname);
string::iterator it = rclass.begin(), end = rclass.end();
while (true) {
*it = toUpper(*it);
++it;
if (it == end) break;
it = std::find(it, rclass.end(), '.');
if (it == end) break;
++it;
if (it == end) break;
}
return rclass;
}
char Configuration::toUpper(char c) const {
if (c >= 'a' && c <= 'z')
return c - 'a' + 'A';
return c;
}

97
src/Configuration.hh Normal file
View file

@ -0,0 +1,97 @@
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
// Configuration.hh for Blackbox - an X11 Window manager
// Copyright (c) 2002 - 2002 Ben Jansens (ben@orodu.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.
#ifndef __Configuration_hh
#define __Configuration_hh
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <string>
/*
* The Configuration class is a generic wrapper for configuration settings.
*
* This class is used for the global rc/config file, and for styles.
*
* This implementation of the Configuration class wraps an X resource database
* file.
*/
class Configuration {
public:
explicit Configuration(const std::string &file);
Configuration();
virtual ~Configuration();
inline const std::string &file() const {
return static_cast<const std::string &>(m_file);
}
void setFile(const std::string &file);
// defaults to true!
inline bool autoSave() const {
return m_autosave;
}
void setAutoSave(bool);
inline bool isModified() const {
return m_modified;
}
void save();
bool load();
void create();
void setValue(const std::string &rname, bool value);
inline void setValue(const std::string &rname, int value) {
setValue(rname, (long) value);
}
inline void setValue(const std::string &rname, unsigned int value) {
setValue(rname, (unsigned long) value);
}
void setValue(const std::string &rname, long value);
void setValue(const std::string &rname, unsigned long value);
void setValue(const std::string &rname, const std::string &value);
void setValue(const std::string &rname, const char *value);
bool getValue(const std::string &rname, bool &value) const;
inline bool getValue(const std::string &rname, int &value) const {
return getValue(rname, (long) value);
}
inline bool getValue(const std::string &rname, unsigned int &value) const {
return getValue(rname, (unsigned long) value);
}
bool getValue(const std::string &rname, long &value) const;
bool getValue(const std::string &rname, unsigned long &value) const;
bool getValue(const std::string &rname, std::string &value) const;
private:
std::string createClassName(const std::string &rname) const;
char toUpper(char) const;
static bool m_initialized;
std::string m_file;
bool m_modified;
bool m_autosave;
XrmDatabase m_database;
};
#endif // __Configuration_hh

View file

@ -30,7 +30,7 @@ CPPFLAGS= @CPPFLAGS@ @SHAPE@ @ORDEREDPSEUDO@ \
bin_PROGRAMS= openbox
openbox_SOURCES= BaseDisplay.cc Basemenu.cc Clientmenu.cc Color.cc Configmenu.cc GCCache.cc Iconmenu.cc Image.cc ImageControl.cc Netizen.cc Rootmenu.cc Screen.cc Slit.cc Texture.cc Timer.cc Toolbar.cc Util.cc Window.cc Windowmenu.cc Workspace.cc Workspacemenu.cc blackbox.cc i18n.cc main.cc
openbox_SOURCES= BaseDisplay.cc Basemenu.cc Clientmenu.cc Color.cc Configmenu.cc Configuration.cc GCCache.cc Iconmenu.cc Image.cc ImageControl.cc Netizen.cc Rootmenu.cc Screen.cc Slit.cc Texture.cc Timer.cc Toolbar.cc Util.cc Window.cc Windowmenu.cc Workspace.cc Workspacemenu.cc blackbox.cc i18n.cc main.cc
MAINTAINERCLEANFILES= Makefile.in
@ -39,87 +39,86 @@ distclean-local:
# local dependencies
BaseDisplay.o: BaseDisplay.cc ../config.h i18n.hh \
../nls/blackbox-nls.hh BaseDisplay.hh Timer.hh GCCache.hh Color.hh \
Util.hh
Basemenu.o: Basemenu.cc ../config.h i18n.hh ../nls/blackbox-nls.hh \
blackbox.hh BaseDisplay.hh Timer.hh Basemenu.hh GCCache.hh Color.hh \
Image.hh Screen.hh Texture.hh Util.hh Configmenu.hh Iconmenu.hh \
BaseDisplay.o: BaseDisplay.cc i18n.hh ../nls/blackbox-nls.hh \
BaseDisplay.hh Timer.hh Util.hh GCCache.hh Color.hh
Basemenu.o: Basemenu.cc i18n.hh ../nls/blackbox-nls.hh blackbox.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh Basemenu.hh GCCache.hh \
Color.hh Image.hh Screen.hh Texture.hh Configmenu.hh Iconmenu.hh \
Netizen.hh Rootmenu.hh Workspace.hh Workspacemenu.hh
Clientmenu.o: Clientmenu.cc ../config.h blackbox.hh i18n.hh \
../nls/blackbox-nls.hh BaseDisplay.hh Timer.hh Clientmenu.hh \
Basemenu.hh Screen.hh Color.hh Texture.hh Util.hh Configmenu.hh \
Clientmenu.o: Clientmenu.cc blackbox.hh i18n.hh ../nls/blackbox-nls.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh Clientmenu.hh \
Basemenu.hh Screen.hh Color.hh Texture.hh Image.hh Configmenu.hh \
Iconmenu.hh Netizen.hh Rootmenu.hh Workspace.hh Workspacemenu.hh \
Window.hh Windowmenu.hh
Color.o: Color.cc ../config.h Color.hh BaseDisplay.hh Timer.hh
Configmenu.o: Configmenu.cc ../config.h i18n.hh ../nls/blackbox-nls.hh \
Configmenu.hh Basemenu.hh Image.hh Timer.hh BaseDisplay.hh Color.hh \
Toolbar.hh Screen.hh Texture.hh Util.hh Iconmenu.hh Netizen.hh \
Rootmenu.hh Workspace.hh Workspacemenu.hh blackbox.hh Window.hh \
Color.o: Color.cc Color.hh BaseDisplay.hh Timer.hh Util.hh
Configmenu.o: Configmenu.cc i18n.hh ../nls/blackbox-nls.hh Configmenu.hh \
Basemenu.hh Image.hh Timer.hh BaseDisplay.hh Util.hh Color.hh \
Toolbar.hh Screen.hh Texture.hh Iconmenu.hh Netizen.hh Rootmenu.hh \
Workspace.hh Workspacemenu.hh blackbox.hh Configuration.hh Window.hh \
Windowmenu.hh
GCCache.o: GCCache.cc ../config.h GCCache.hh BaseDisplay.hh Timer.hh \
Color.hh Util.hh
Iconmenu.o: Iconmenu.cc ../config.h i18n.hh ../nls/blackbox-nls.hh \
Iconmenu.hh Basemenu.hh Screen.hh Color.hh Texture.hh Util.hh \
Configmenu.hh Netizen.hh Rootmenu.hh Timer.hh Workspace.hh \
Workspacemenu.hh blackbox.hh BaseDisplay.hh Window.hh Windowmenu.hh
Image.o: Image.cc ../config.h blackbox.hh i18n.hh \
../nls/blackbox-nls.hh BaseDisplay.hh Timer.hh GCCache.hh Color.hh \
Image.hh Texture.hh Util.hh
ImageControl.o: ImageControl.cc ../config.h blackbox.hh i18n.hh \
../nls/blackbox-nls.hh BaseDisplay.hh Timer.hh Color.hh Image.hh \
Texture.hh Util.hh
Netizen.o: Netizen.cc ../config.h Netizen.hh Screen.hh Color.hh \
Texture.hh Util.hh Configmenu.hh Basemenu.hh Iconmenu.hh Rootmenu.hh \
Timer.hh Workspace.hh Workspacemenu.hh blackbox.hh i18n.hh \
../nls/blackbox-nls.hh BaseDisplay.hh
Rootmenu.o: Rootmenu.cc ../config.h blackbox.hh i18n.hh \
../nls/blackbox-nls.hh BaseDisplay.hh Timer.hh Rootmenu.hh \
Basemenu.hh Screen.hh Color.hh Texture.hh Util.hh Configmenu.hh \
Configuration.o: Configuration.cc ../config.h Configuration.hh Util.hh
GCCache.o: GCCache.cc GCCache.hh BaseDisplay.hh Timer.hh Util.hh Color.hh
Iconmenu.o: Iconmenu.cc i18n.hh ../nls/blackbox-nls.hh Iconmenu.hh \
Basemenu.hh Screen.hh Color.hh Texture.hh Util.hh Image.hh Timer.hh \
BaseDisplay.hh Configmenu.hh Netizen.hh Rootmenu.hh Workspace.hh \
Workspacemenu.hh blackbox.hh Configuration.hh Window.hh Windowmenu.hh
Image.o: Image.cc blackbox.hh i18n.hh ../nls/blackbox-nls.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh GCCache.hh Color.hh \
Image.hh Texture.hh
ImageControl.o: ImageControl.cc blackbox.hh i18n.hh \
../nls/blackbox-nls.hh BaseDisplay.hh Timer.hh Util.hh Configuration.hh \
Color.hh Image.hh Texture.hh
Netizen.o: Netizen.cc Netizen.hh Screen.hh Color.hh Texture.hh Util.hh \
Image.hh Timer.hh BaseDisplay.hh Configmenu.hh Basemenu.hh Iconmenu.hh \
Rootmenu.hh Workspace.hh Workspacemenu.hh blackbox.hh i18n.hh \
../nls/blackbox-nls.hh Configuration.hh
Rootmenu.o: Rootmenu.cc blackbox.hh i18n.hh ../nls/blackbox-nls.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh Rootmenu.hh \
Basemenu.hh Screen.hh Color.hh Texture.hh Image.hh Configmenu.hh \
Iconmenu.hh Netizen.hh Workspace.hh Workspacemenu.hh
Screen.o: Screen.cc ../config.h i18n.hh ../nls/blackbox-nls.hh \
blackbox.hh BaseDisplay.hh Timer.hh Clientmenu.hh Basemenu.hh \
GCCache.hh Color.hh Iconmenu.hh Image.hh Screen.hh Texture.hh Util.hh \
Configmenu.hh Netizen.hh Rootmenu.hh Workspace.hh Workspacemenu.hh \
Slit.hh Toolbar.hh Window.hh Windowmenu.hh
Slit.o: Slit.cc ../config.h i18n.hh ../nls/blackbox-nls.hh blackbox.hh \
BaseDisplay.hh Timer.hh Image.hh Color.hh Screen.hh Texture.hh \
Util.hh Configmenu.hh Basemenu.hh Iconmenu.hh Netizen.hh Rootmenu.hh \
Screen.o: Screen.cc i18n.hh ../nls/blackbox-nls.hh blackbox.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh Clientmenu.hh \
Basemenu.hh GCCache.hh Color.hh Iconmenu.hh Image.hh Screen.hh \
Texture.hh Configmenu.hh Netizen.hh Rootmenu.hh Workspace.hh \
Workspacemenu.hh Slit.hh Toolbar.hh Window.hh Windowmenu.hh
Slit.o: Slit.cc i18n.hh ../nls/blackbox-nls.hh blackbox.hh BaseDisplay.hh \
Timer.hh Util.hh Configuration.hh Image.hh Color.hh Screen.hh \
Texture.hh Configmenu.hh Basemenu.hh Iconmenu.hh Netizen.hh Rootmenu.hh \
Workspace.hh Workspacemenu.hh Slit.hh Toolbar.hh
Texture.o: Texture.cc ../config.h Texture.hh Color.hh Util.hh \
BaseDisplay.hh Timer.hh Image.hh Screen.hh Configmenu.hh Basemenu.hh \
Iconmenu.hh Netizen.hh Rootmenu.hh Workspace.hh Workspacemenu.hh \
blackbox.hh i18n.hh ../nls/blackbox-nls.hh
Timer.o: Timer.cc ../config.h BaseDisplay.hh Timer.hh Util.hh
Toolbar.o: Toolbar.cc ../config.h i18n.hh ../nls/blackbox-nls.hh \
blackbox.hh BaseDisplay.hh Timer.hh Clientmenu.hh Basemenu.hh \
GCCache.hh Color.hh Iconmenu.hh Image.hh Rootmenu.hh Screen.hh \
Texture.hh Util.hh Configmenu.hh Netizen.hh Workspace.hh \
Texture.o: Texture.cc Texture.hh Color.hh Util.hh BaseDisplay.hh Timer.hh \
Image.hh Screen.hh Configmenu.hh Basemenu.hh Iconmenu.hh Netizen.hh \
Rootmenu.hh Workspace.hh Workspacemenu.hh blackbox.hh i18n.hh \
../nls/blackbox-nls.hh Configuration.hh
Timer.o: Timer.cc BaseDisplay.hh Timer.hh Util.hh
Toolbar.o: Toolbar.cc i18n.hh ../nls/blackbox-nls.hh blackbox.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh Clientmenu.hh \
Basemenu.hh GCCache.hh Color.hh Iconmenu.hh Image.hh Rootmenu.hh \
Screen.hh Texture.hh Configmenu.hh Netizen.hh Workspace.hh \
Workspacemenu.hh Toolbar.hh Window.hh Windowmenu.hh Slit.hh
Util.o: Util.cc ../config.h Util.hh
Window.o: Window.cc ../config.h i18n.hh ../nls/blackbox-nls.hh \
blackbox.hh BaseDisplay.hh Timer.hh GCCache.hh Color.hh Iconmenu.hh \
Basemenu.hh Image.hh Screen.hh Texture.hh Util.hh Configmenu.hh \
Util.o: Util.cc Util.hh
Window.o: Window.cc i18n.hh ../nls/blackbox-nls.hh blackbox.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh GCCache.hh Color.hh \
Iconmenu.hh Basemenu.hh Image.hh Screen.hh Texture.hh Configmenu.hh \
Netizen.hh Rootmenu.hh Workspace.hh Workspacemenu.hh Toolbar.hh \
Window.hh Windowmenu.hh Slit.hh
Windowmenu.o: Windowmenu.cc ../config.h i18n.hh ../nls/blackbox-nls.hh \
blackbox.hh BaseDisplay.hh Timer.hh Screen.hh Color.hh Texture.hh \
Util.hh Configmenu.hh Basemenu.hh Iconmenu.hh Netizen.hh Rootmenu.hh \
Workspace.hh Workspacemenu.hh Window.hh Windowmenu.hh
Workspace.o: Workspace.cc ../config.h i18n.hh ../nls/blackbox-nls.hh \
blackbox.hh BaseDisplay.hh Timer.hh Clientmenu.hh Basemenu.hh \
Netizen.hh Screen.hh Color.hh Texture.hh Util.hh Configmenu.hh \
Iconmenu.hh Rootmenu.hh Workspace.hh Workspacemenu.hh Toolbar.hh \
Window.hh Windowmenu.hh
Workspacemenu.o: Workspacemenu.cc ../config.h i18n.hh \
../nls/blackbox-nls.hh blackbox.hh BaseDisplay.hh Timer.hh Screen.hh \
Color.hh Texture.hh Util.hh Configmenu.hh Basemenu.hh Iconmenu.hh \
Windowmenu.o: Windowmenu.cc i18n.hh ../nls/blackbox-nls.hh blackbox.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh Screen.hh Color.hh \
Texture.hh Image.hh Configmenu.hh Basemenu.hh Iconmenu.hh Netizen.hh \
Rootmenu.hh Workspace.hh Workspacemenu.hh Window.hh Windowmenu.hh
Workspace.o: Workspace.cc i18n.hh ../nls/blackbox-nls.hh blackbox.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh Clientmenu.hh \
Basemenu.hh Netizen.hh Screen.hh Color.hh Texture.hh Image.hh \
Configmenu.hh Iconmenu.hh Rootmenu.hh Workspace.hh Workspacemenu.hh \
Toolbar.hh Window.hh Windowmenu.hh
Workspacemenu.o: Workspacemenu.cc i18n.hh ../nls/blackbox-nls.hh \
blackbox.hh BaseDisplay.hh Timer.hh Util.hh Configuration.hh Screen.hh \
Color.hh Texture.hh Image.hh Configmenu.hh Basemenu.hh Iconmenu.hh \
Netizen.hh Rootmenu.hh Workspace.hh Workspacemenu.hh Toolbar.hh
blackbox.o: blackbox.cc ../config.h i18n.hh ../nls/blackbox-nls.hh \
blackbox.hh BaseDisplay.hh Timer.hh Basemenu.hh Clientmenu.hh \
GCCache.hh Color.hh Image.hh Rootmenu.hh Screen.hh Texture.hh Util.hh \
Configmenu.hh Iconmenu.hh Netizen.hh Workspace.hh Workspacemenu.hh \
Slit.hh Toolbar.hh Window.hh Windowmenu.hh
i18n.o: i18n.cc ../config.h i18n.hh ../nls/blackbox-nls.hh
main.o: main.cc ../version.h ../config.h i18n.hh \
../nls/blackbox-nls.hh blackbox.hh BaseDisplay.hh Timer.hh
blackbox.o: blackbox.cc i18n.hh ../nls/blackbox-nls.hh blackbox.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh Basemenu.hh \
Clientmenu.hh GCCache.hh Color.hh Image.hh Rootmenu.hh Screen.hh \
Texture.hh Configmenu.hh Iconmenu.hh Netizen.hh Workspace.hh \
Workspacemenu.hh Slit.hh Toolbar.hh Window.hh Windowmenu.hh
i18n.o: i18n.cc i18n.hh ../nls/blackbox-nls.hh
main.o: main.cc ../version.h i18n.hh ../nls/blackbox-nls.hh blackbox.hh \
BaseDisplay.hh Timer.hh Util.hh Configuration.hh

View file

@ -108,6 +108,8 @@ static int anotherWMRunning(Display *display, XErrorEvent *) {
BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
blackbox = bb;
screenstr = (string)"session.screen" + itostring(scrn) + '.';
config = blackbox->getConfig();
event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
SubstructureRedirectMask | ButtonPressMask | ButtonReleaseMask;
@ -127,7 +129,6 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
getDepth());
rootmenu = 0;
resource.stylerc = 0;
resource.mstyle.t_fontset = resource.mstyle.f_fontset =
resource.tstyle.fontset = resource.wstyle.fontset = (XFontSet) 0;
@ -155,10 +156,7 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
image_control->installRootColormap();
root_colormap_installed = True;
blackbox->load_rc(this);
image_control->setDither(resource.image_dither);
load_rc();
LoadStyle();
XGCValues gcv;
@ -352,8 +350,261 @@ void BScreen::removeWorkspaceNames(void) {
workspaceNames.clear();
}
void BScreen::saveSloppyFocus(bool s) {
resource.sloppy_focus = s;
string fmodel;
if (resource.sloppy_focus) {
fmodel = "SloppyFocus";
if (resource.auto_raise) fmodel += " AutoRaise";
if (resource.click_raise) fmodel += " ClickRaise";
} else {
fmodel = "ClickToFocus";
}
config->setValue(screenstr + "focusModel", fmodel);
}
void BScreen::saveAutoRaise(bool a) {
resource.auto_raise = a;
saveSloppyFocus(resource.sloppy_focus);
}
void BScreen::saveClickRaise(bool c) {
resource.click_raise = c;
saveSloppyFocus(resource.sloppy_focus);
}
void BScreen::saveImageDither(bool d) {
image_control->setDither(d);
config->setValue(screenstr + "imageDither", doImageDither());
}
void BScreen::saveOpaqueMove(bool o) {
resource.opaque_move = o;
config->setValue(screenstr + "opaqueMove", resource.opaque_move);
}
void BScreen::saveFullMax(bool f) {
resource.full_max = f;
config->setValue(screenstr + "fullMaximization", resource.full_max);
}
void BScreen::saveFocusNew(bool f) {
resource.focus_new = f;
config->setValue(screenstr + "focusNewWindows", resource.focus_new);
}
void BScreen::saveFocusLast(bool f) {
resource.focus_last = f;
config->setValue(screenstr + "focusLastWindow", resource.focus_last);
}
void BScreen::saveWorkspaces(unsigned int w) {
resource.workspaces = w;
config->setValue(screenstr + "workspaces", resource.workspaces);
}
void BScreen::savePlacementPolicy(int p) {
resource.placement_policy = p;
const char *placement;
switch (resource.placement_policy) {
case CascadePlacement: placement = "CascadePlacement"; break;
case ColSmartPlacement: placement = "ColSmartPlacement"; break;
case RowSmartPlacement: default: placement = "RowSmartPlacement"; break;
}
config->setValue(screenstr + "windowPlacement", placement);
}
void BScreen::saveEdgeSnapThreshold(int t) {
resource.edge_snap_threshold = t;
config->setValue(screenstr + "edgeSnapThreshold",
resource.edge_snap_threshold);
}
void BScreen::saveRowPlacementDirection(int d) {
resource.row_direction = d;
config->setValue(screenstr + "rowPlacementDirection",
resource.row_direction == LeftRight ?
"LeftToRight" : "RightToLeft");
}
void BScreen::saveColPlacementDirection(int d) {
resource.col_direction = d;
config->setValue(screenstr + "colPlacementDirection",
resource.col_direction == TopBottom ?
"TopToBottom" : "BottomToTop");
}
#ifdef HAVE_STRFTIME
void BScreen::saveStrftimeFormat(const std::string& format) {
resource.strftime_format = format;
config->setValue(screenstr + "strftimeFormat", resource.strftime_format);
}
#else // !HAVE_STRFTIME
void BScreen::saveDateFormat(int f) {
resource.date_format = f;
config->setValue(screenstr + "dateFormat",
resource.date_format == B_EuropeanDate ?
"European" : "American");
}
void BScreen::saveClock24Hour(Bool c) {
resource.clock24hour = c;
config->setValue(screenstr + "clockFormat", resource.clock24hour ? 24 : 12);
}
#endif // HAVE_STRFTIME
void BScreen::saveWorkspaceNames() {
string save_string = getWorkspace(0)->getName();
for (unsigned int i = 1; i < getWorkspaceCount(); ++i)
save_string += ',' + getWorkspace(i)->getName();
config->setValue(screenstr + "workspaceNames", save_string);
}
void BScreen::save_rc(void) {
saveSloppyFocus(resource.sloppy_focus);
saveAutoRaise(resource.auto_raise);
saveImageDither(doImageDither());
saveOpaqueMove(resource.opaque_move);
saveFullMax(resource.full_max);
saveFocusNew(resource.focus_new);
saveFocusLast(resource.focus_last);
saveWorkspaces(resource.workspaces);
savePlacementPolicy(resource.placement_policy);
saveEdgeSnapThreshold(resource.edge_snap_threshold);
saveRowPlacementDirection(resource.row_direction);
saveColPlacementDirection(resource.col_direction);
#ifdef HAVE_STRFTIME
saveStrftimeFormat(resource.strftime_format);
#else // !HAVE_STRFTIME
saveDateFormat(resource.date_format);
savwClock24Hour(resource.clock24hour);
#endif // HAVE_STRFTIME
toolbar->save_rc();
slit->save_rc();
}
void BScreen::load_rc(void) {
std::string s;
bool b;
if (! config->getValue(screenstr + "fullMaximization", resource.full_max))
resource.full_max = false;
if (! config->getValue(screenstr + "focusNewWindows", resource.focus_new))
resource.focus_new = false;
if (! config->getValue(screenstr + "focusLastWindow", resource.focus_last))
resource.focus_last = false;
if (! config->getValue(screenstr + "workspaces", resource.workspaces))
resource.workspaces = 1;
if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
resource.opaque_move = false;
if (! config->getValue(screenstr + "imageDither", b))
b = true;
image_control->setDither(b);
if (! config->getValue(screenstr + "edgeSnapThreshold",
resource.edge_snap_threshold))
resource.edge_snap_threshold = 4;
if (config->getValue(screenstr + "rowPlacementDirection", s) &&
s == "RightToLeft")
resource.row_direction = RightLeft;
else
resource.row_direction = LeftRight;
if (config->getValue(screenstr + "colPlacementDirection", s) &&
s == "BottomToTop")
resource.col_direction = BottomTop;
else
resource.col_direction = TopBottom;
removeWorkspaceNames();
if (config->getValue(screenstr + "workspaceNames", s)) {
string::const_iterator it = s.begin(), end = s.end();
while(1) {
string::const_iterator tmp = it; // current string.begin()
it = std::find(tmp, end, ','); // look for comma between tmp and end
addWorkspaceName(string(tmp, it)); // s[tmp:it]
if (it == end)
break;
++it;
}
}
resource.sloppy_focus = true;
resource.auto_raise = false;
resource.click_raise = false;
if (config->getValue(screenstr + "focusModel", s)) {
if (s.find("ClickToFocus") != string::npos) {
resource.sloppy_focus = false;
} else {
// must be sloppy
if (s.find("AutoRaise") != string::npos)
resource.auto_raise = true;
if (s.find("ClickRaise") != string::npos)
resource.click_raise = true;
}
}
if (config->getValue(screenstr + "windowPlacement", s)) {
if (s == "CascadePlacement")
resource.placement_policy = CascadePlacement;
else if (s == "ColSmartPlacement")
resource.placement_policy = ColSmartPlacement;
else //if (s == "RowSmartPlacement")
resource.placement_policy = RowSmartPlacement;
} else
resource.placement_policy = RowSmartPlacement;
#ifdef HAVE_STRFTIME
if (config->getValue(screenstr + "strftimeFormat", s))
resource.strftime_format = s;
else
resource.strftime_format = "%I:%M %p";
#else // !HAVE_STRFTIME
long l;
if (config->getValue(screenstr + "dateFormat", s) && s == "European")
resource.date_format = B_EuropeanDate;
else
resource.date_format = B_AmericanDate;
if (! config->getValue(screenstr + "clockFormat", l))
l = 12;
resource.clock24hour = l == 24;
#endif // HAVE_STRFTIME
}
void BScreen::reconfigure(void) {
load_rc();
toolbar->load_rc();
slit->load_rc();
LoadStyle();
XGCValues gcv;
@ -442,12 +693,19 @@ void BScreen::rereadMenu(void) {
void BScreen::LoadStyle(void) {
resource.stylerc = XrmGetFileDatabase(blackbox->getStyleFilename());
if (! resource.stylerc)
resource.stylerc = XrmGetFileDatabase(DEFAULTSTYLE);
Configuration style;
XrmValue value;
char *value_type;
const char *sfile = blackbox->getStyleFilename();
if (sfile != NULL) {
style.setFile(sfile);
if (! style.load()) {
style.setFile(DEFAULTSTYLE);
if (! style.load())
style.create(); // hardcoded default values will be used.
}
}
string s;
// load fonts/fontsets
if (resource.wstyle.fontset)
@ -476,14 +734,10 @@ void BScreen::LoadStyle(void) {
resource.mstyle.t_font = 0;
if (i18n.multibyte()) {
resource.wstyle.fontset =
readDatabaseFontSet("window.font", "Window.Font");
resource.tstyle.fontset =
readDatabaseFontSet("toolbar.font", "Toolbar.Font");
resource.mstyle.t_fontset =
readDatabaseFontSet("menu.title.font", "Menu.Title.Font");
resource.mstyle.f_fontset =
readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font");
resource.wstyle.fontset = readDatabaseFontSet("window.font", style);
resource.tstyle.fontset = readDatabaseFontSet("toolbar.font", style);
resource.mstyle.t_fontset = readDatabaseFontSet("menu.title.font", style);
resource.mstyle.f_fontset = readDatabaseFontSet("menu.frame.font", style);
resource.mstyle.t_fontset_extents =
XExtentsOfFontSet(resource.mstyle.t_fontset);
@ -494,207 +748,155 @@ void BScreen::LoadStyle(void) {
resource.wstyle.fontset_extents =
XExtentsOfFontSet(resource.wstyle.fontset);
} else {
resource.wstyle.font =
readDatabaseFont("window.font", "Window.Font");
resource.tstyle.font =
readDatabaseFont("toolbar.font", "Toolbar.Font");
resource.mstyle.t_font =
readDatabaseFont("menu.title.font", "Menu.Title.Font");
resource.mstyle.f_font =
readDatabaseFont("menu.frame.font", "Menu.Frame.Font");
resource.wstyle.font = readDatabaseFont("window.font", style);
resource.tstyle.font = readDatabaseFont("toolbar.font", style);
resource.mstyle.t_font = readDatabaseFont("menu.title.font", style);
resource.mstyle.f_font = readDatabaseFont("menu.frame.font", style);
}
// load window config
resource.wstyle.t_focus =
readDatabaseTexture("window.title.focus", "Window.Title.Focus", "white");
readDatabaseTexture("window.title.focus", "white", style);
resource.wstyle.t_unfocus =
readDatabaseTexture("window.title.unfocus",
"Window.Title.Unfocus", "black");
readDatabaseTexture("window.title.unfocus", "black", style);
resource.wstyle.l_focus =
readDatabaseTexture("window.label.focus", "Window.Label.Focus", "white" );
readDatabaseTexture("window.label.focus", "white", style);
resource.wstyle.l_unfocus =
readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
"black");
readDatabaseTexture("window.label.unfocus", "black", style);
resource.wstyle.h_focus =
readDatabaseTexture("window.handle.focus", "Window.Handle.Focus", "white");
readDatabaseTexture("window.handle.focus", "white", style);
resource.wstyle.h_unfocus =
readDatabaseTexture("window.handle.unfocus",
"Window.Handle.Unfocus", "black");
readDatabaseTexture("window.handle.unfocus", "black", style);
resource.wstyle.g_focus =
readDatabaseTexture("window.grip.focus", "Window.Grip.Focus", "white");
readDatabaseTexture("window.grip.focus", "white", style);
resource.wstyle.g_unfocus =
readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus", "black");
readDatabaseTexture("window.grip.unfocus", "black", style);
resource.wstyle.b_focus =
readDatabaseTexture("window.button.focus", "Window.Button.Focus", "white");
readDatabaseTexture("window.button.focus", "white", style);
resource.wstyle.b_unfocus =
readDatabaseTexture("window.button.unfocus",
"Window.Button.Unfocus", "black");
readDatabaseTexture("window.button.unfocus", "black", style);
resource.wstyle.b_pressed =
readDatabaseTexture("window.button.pressed",
"Window.Button.Pressed", "black");
readDatabaseTexture("window.button.pressed", "black", style);
resource.wstyle.f_focus =
readDatabaseColor("window.frame.focusColor",
"Window.Frame.FocusColor", "white");
readDatabaseColor("window.frame.focusColor", "white", style);
resource.wstyle.f_unfocus =
readDatabaseColor("window.frame.unfocusColor",
"Window.Frame.UnfocusColor", "black");
readDatabaseColor("window.frame.unfocusColor", "black", style);
resource.wstyle.l_text_focus =
readDatabaseColor("window.label.focus.textColor",
"Window.Label.Focus.TextColor", "black");
readDatabaseColor("window.label.focus.textColor", "black", style);
resource.wstyle.l_text_unfocus =
readDatabaseColor("window.label.unfocus.textColor",
"Window.Label.Unfocus.TextColor", "white");
readDatabaseColor("window.label.unfocus.textColor", "white", style);
resource.wstyle.b_pic_focus =
readDatabaseColor("window.button.focus.picColor",
"Window.Button.Focus.PicColor", "black");
readDatabaseColor("window.button.focus.picColor", "black", style);
resource.wstyle.b_pic_unfocus =
readDatabaseColor("window.button.unfocus.picColor",
"Window.Button.Unfocus.PicColor", "white");
readDatabaseColor("window.button.unfocus.picColor", "white", style);
resource.wstyle.justify = LeftJustify;
if (XrmGetResource(resource.stylerc, "window.justify", "Window.Justify",
&value_type, &value)) {
if (strstr(value.addr, "right") || strstr(value.addr, "Right"))
if (style.getValue("window.justify", s)) {
if (s == "right" || s == "Right")
resource.wstyle.justify = RightJustify;
else if (strstr(value.addr, "center") || strstr(value.addr, "Center"))
else if (s == "center" || s == "Center")
resource.wstyle.justify = CenterJustify;
}
// load toolbar config
resource.tstyle.toolbar =
readDatabaseTexture("toolbar", "Toolbar", "black");
readDatabaseTexture("toolbar", "black", style);
resource.tstyle.label =
readDatabaseTexture("toolbar.label", "Toolbar.Label", "black");
readDatabaseTexture("toolbar.label", "black", style);
resource.tstyle.window =
readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel", "black");
readDatabaseTexture("toolbar.windowLabel", "black", style);
resource.tstyle.button =
readDatabaseTexture("toolbar.button", "Toolbar.Button", "white");
readDatabaseTexture("toolbar.button", "white", style);
resource.tstyle.pressed =
readDatabaseTexture("toolbar.button.pressed",
"Toolbar.Button.Pressed", "black");
readDatabaseTexture("toolbar.button.pressed", "black", style);
resource.tstyle.clock =
readDatabaseTexture("toolbar.clock", "Toolbar.Clock", "black");
readDatabaseTexture("toolbar.clock", "black", style);
resource.tstyle.l_text =
readDatabaseColor("toolbar.label.textColor",
"Toolbar.Label.TextColor", "white");
readDatabaseColor("toolbar.label.textColor", "white", style);
resource.tstyle.w_text =
readDatabaseColor("toolbar.windowLabel.textColor",
"Toolbar.WindowLabel.TextColor", "white");
readDatabaseColor("toolbar.windowLabel.textColor", "white", style);
resource.tstyle.c_text =
readDatabaseColor("toolbar.clock.textColor",
"Toolbar.Clock.TextColor", "white");
readDatabaseColor("toolbar.clock.textColor", "white", style);
resource.tstyle.b_pic =
readDatabaseColor("toolbar.button.picColor",
"Toolbar.Button.PicColor", "black");
readDatabaseColor("toolbar.button.picColor", "black", style);
resource.tstyle.justify = LeftJustify;
if (XrmGetResource(resource.stylerc, "toolbar.justify",
"Toolbar.Justify", &value_type, &value)) {
if (strstr(value.addr, "right") || strstr(value.addr, "Right"))
if (style.getValue("toolbar.justify", s)) {
if (s == "right" || s == "Right")
resource.tstyle.justify = RightJustify;
else if (strstr(value.addr, "center") || strstr(value.addr, "Center"))
else if (s == "center" || s == "Center")
resource.tstyle.justify = CenterJustify;
}
// load menu config
resource.mstyle.title =
readDatabaseTexture("menu.title", "Menu.Title", "white");
readDatabaseTexture("menu.title", "white", style);
resource.mstyle.frame =
readDatabaseTexture("menu.frame", "Menu.Frame", "black");
readDatabaseTexture("menu.frame", "black", style);
resource.mstyle.hilite =
readDatabaseTexture("menu.hilite", "Menu.Hilite", "white");
readDatabaseTexture("menu.hilite", "white", style);
resource.mstyle.t_text =
readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor", "black");
readDatabaseColor("menu.title.textColor", "black", style);
resource.mstyle.f_text =
readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor", "white");
readDatabaseColor("menu.frame.textColor", "white", style);
resource.mstyle.d_text =
readDatabaseColor("menu.frame.disableColor",
"Menu.Frame.DisableColor", "black");
readDatabaseColor("menu.frame.disableColor", "black", style);
resource.mstyle.h_text =
readDatabaseColor("menu.hilite.textColor",
"Menu.Hilite.TextColor", "black");
readDatabaseColor("menu.hilite.textColor", "black", style);
resource.mstyle.t_justify = LeftJustify;
if (XrmGetResource(resource.stylerc, "menu.title.justify",
"Menu.Title.Justify",
&value_type, &value)) {
if (strstr(value.addr, "right") || strstr(value.addr, "Right"))
if (style.getValue("menu.title.justify", s)) {
if (s == "right" || s == "Right")
resource.mstyle.t_justify = RightJustify;
else if (strstr(value.addr, "center") || strstr(value.addr, "Center"))
else if (s == "center" || s == "Center")
resource.mstyle.t_justify = CenterJustify;
}
resource.mstyle.f_justify = LeftJustify;
if (XrmGetResource(resource.stylerc, "menu.frame.justify",
"Menu.Frame.Justify",
&value_type, &value)) {
if (strstr(value.addr, "right") || strstr(value.addr, "Right"))
if (style.getValue("menu.frame.justify", s)) {
if (s == "right" || s == "Right")
resource.mstyle.f_justify = RightJustify;
else if (strstr(value.addr, "center") || strstr(value.addr, "Center"))
else if (s == "center" || s == "Center")
resource.mstyle.f_justify = CenterJustify;
}
resource.mstyle.bullet = Basemenu::Triangle;
if (XrmGetResource(resource.stylerc, "menu.bullet", "Menu.Bullet",
&value_type, &value)) {
if (! strncasecmp(value.addr, "empty", value.size))
if (style.getValue("menu.bullet", s)) {
if (s == "empty" || s == "Empty")
resource.mstyle.bullet = Basemenu::Empty;
else if (! strncasecmp(value.addr, "square", value.size))
else if (s == "square" || s == "Square")
resource.mstyle.bullet = Basemenu::Square;
else if (! strncasecmp(value.addr, "diamond", value.size))
else if (s == "diamond" || s == "Diamond")
resource.mstyle.bullet = Basemenu::Diamond;
}
resource.mstyle.bullet_pos = Basemenu::Left;
if (XrmGetResource(resource.stylerc, "menu.bullet.position",
"Menu.Bullet.Position", &value_type, &value)) {
if (! strncasecmp(value.addr, "right", value.size))
if (style.getValue("menu.bullet.position", s)) {
if (s == "right" || s == "Right")
resource.mstyle.bullet_pos = Basemenu::Right;
}
resource.border_color =
readDatabaseColor("borderColor", "BorderColor", "black");
unsigned int uint_value;
readDatabaseColor("borderColor", "black", style);
// load bevel, border and handle widths
if (! style.getValue("handleWidth", resource.handle_width) ||
resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
resource.handle_width = 6;
if (XrmGetResource(resource.stylerc, "handleWidth", "HandleWidth",
&value_type, &value) &&
sscanf(value.addr, "%u", &uint_value) == 1 &&
uint_value <= (getWidth() / 2) && uint_value != 0) {
resource.handle_width = uint_value;
}
if (! style.getValue("borderWidth", resource.border_width))
resource.border_width = 1;
if (XrmGetResource(resource.stylerc, "borderWidth", "BorderWidth",
&value_type, &value) &&
sscanf(value.addr, "%u", &uint_value) == 1) {
resource.border_width = uint_value;
}
if (! style.getValue("bevelWidth", resource.bevel_width) ||
resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
resource.bevel_width = 3;
if (XrmGetResource(resource.stylerc, "bevelWidth", "BevelWidth",
&value_type, &value) &&
sscanf(value.addr, "%u", &uint_value) == 1 &&
uint_value <= (getWidth() / 2) && uint_value != 0) {
resource.bevel_width = uint_value;
}
if (! style.getValue("frameWidth", resource.frame_width) ||
resource.frame_width > (getWidth() / 2))
resource.frame_width = resource.bevel_width;
if (XrmGetResource(resource.stylerc, "frameWidth", "FrameWidth",
&value_type, &value) &&
sscanf(value.addr, "%u", &uint_value) == 1 &&
uint_value <= (getWidth() / 2)) {
resource.frame_width = uint_value;
}
if (XrmGetResource(resource.stylerc, "rootCommand", "RootCommand",
&value_type, &value)) {
bexec(value.addr, displayString());
}
XrmDestroyDatabase(resource.stylerc);
if (style.getValue("rootCommand", s))
bexec(s, displayString());
}
@ -741,6 +943,8 @@ BlackboxWindow *BScreen::getIcon(unsigned int index) {
unsigned int BScreen::addWorkspace(void) {
Workspace *wkspc = new Workspace(this, workspacesList.size());
workspacesList.push_back(wkspc);
saveWorkspaces(getWorkspaceCount() + 1);
saveWorkspaceNames();
workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
wkspc->getID() + 2);
@ -771,6 +975,9 @@ unsigned int BScreen::removeLastWorkspace(void) {
workspacesList.pop_back();
delete wkspc;
saveWorkspaces(getWorkspaceCount() - 1);
saveWorkspaceNames();
toolbar->reconfigure();
updateNetizenWorkspaceCount();
@ -981,13 +1188,6 @@ void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
}
#ifdef HAVE_STRFTIME
void BScreen::saveStrftimeFormat(const string& format) {
resource.strftime_format = format;
}
#endif // HAVE_STRFTIME
void BScreen::addWorkspaceName(const string& name) {
workspaceNames.push_back(name);
}
@ -1746,15 +1946,13 @@ void BScreen::updateFocusModel()
BTexture BScreen::readDatabaseTexture(const string &rname,
const string &rclass,
const string &default_color) {
const string &default_color,
Configuration &style) {
BTexture texture;
XrmValue value;
char *value_type;
string s;
if (XrmGetResource(resource.stylerc, rname.c_str(), rclass.c_str(),
&value_type, &value))
texture = BTexture(value.addr);
if (style.getValue(rname, s))
texture = BTexture(s);
else
texture.setTexture(BTexture::Solid | BTexture::Flat);
@ -1764,32 +1962,27 @@ BTexture BScreen::readDatabaseTexture(const string &rname,
if (texture.texture() & BTexture::Solid) {
texture.setColor(readDatabaseColor(rname + ".color",
rclass + ".Color",
default_color));
default_color, style));
texture.setColorTo(readDatabaseColor(rname + ".colorTo",
rclass + ".ColorTo",
default_color));
default_color, style));
} else if (texture.texture() & BTexture::Gradient) {
texture.setColor(readDatabaseColor(rname + ".color",
rclass + ".Color",
default_color));
default_color, style));
texture.setColorTo(readDatabaseColor(rname + ".colorTo",
rclass + ".ColorTo",
default_color));
default_color, style));
}
return texture;
}
BColor BScreen::readDatabaseColor(const string &rname, const string &rclass,
const string &default_color) {
BColor BScreen::readDatabaseColor(const string &rname,
const string &default_color,
Configuration &style) {
BColor color;
XrmValue value;
char *value_type;
if (XrmGetResource(resource.stylerc, rname.c_str(), rclass.c_str(),
&value_type, &value))
color = BColor(value.addr, getBaseDisplay(), getScreenNumber());
string s;
if (style.getValue(rname, s))
color = BColor(s, getBaseDisplay(), getScreenNumber());
else
color = BColor(default_color, getBaseDisplay(), getScreenNumber());
return color;
@ -1797,18 +1990,14 @@ BColor BScreen::readDatabaseColor(const string &rname, const string &rclass,
XFontSet BScreen::readDatabaseFontSet(const string &rname,
const string &rclass) {
Configuration &style) {
char *defaultFont = "fixed";
bool load_default = True;
XrmValue value;
char *value_type;
string s;
XFontSet fontset = 0;
if (XrmGetResource(resource.stylerc, rname.c_str(), rclass.c_str(),
&value_type, &value) &&
(fontset = createFontSet(value.addr))) {
if (style.getValue(rname, s) && (fontset = createFontSet(s)))
load_default = False;
}
if (load_default) {
fontset = createFontSet(defaultFont);
@ -1826,20 +2015,18 @@ XFontSet BScreen::readDatabaseFontSet(const string &rname,
XFontStruct *BScreen::readDatabaseFont(const string &rname,
const string &rclass) {
Configuration &style) {
char *defaultFont = "fixed";
bool load_default = False;
XrmValue value;
char *value_type;
string s;
XFontStruct *font = 0;
if (XrmGetResource(resource.stylerc, rname.c_str(), rclass.c_str(),
&value_type, &value)) {
if ((font = XLoadQueryFont(blackbox->getXDisplay(), value.addr)) == NULL) {
if (style.getValue(rname, s)) {
if ((font = XLoadQueryFont(blackbox->getXDisplay(), s.c_str())) == NULL) {
fprintf(stderr,
i18n(ScreenSet, ScreenFontLoadFail,
"BScreen::setCurrentStyle(): couldn't load font '%s'\n"),
value.addr);
s.c_str());
load_default = True;
}

View file

@ -45,6 +45,7 @@ extern "C" {
#include "Color.hh"
#include "Texture.hh"
#include "Image.hh"
#include "Configmenu.hh"
#include "Iconmenu.hh"
#include "Netizen.hh"
@ -117,6 +118,7 @@ private:
Configmenu *configmenu;
Iconmenu *iconmenu;
Rootmenu *rootmenu;
Configuration *config;
typedef std::list<Rootmenu*> RootmenuList;
RootmenuList rootmenuList;
@ -147,19 +149,14 @@ private:
ToolbarStyle tstyle;
MenuStyle mstyle;
bool toolbar_on_top, toolbar_auto_hide, sloppy_focus, auto_raise,
auto_edge_balance, image_dither, ordered_dither, opaque_move, full_max,
focus_new, focus_last, click_raise;
bool sloppy_focus, auto_raise, auto_edge_balance, ordered_dither,
opaque_move, full_max, focus_new, focus_last, click_raise;
BColor border_color;
XrmDatabase stylerc;
unsigned int workspaces;
int toolbar_placement, toolbar_width_percent, placement_policy,
edge_snap_threshold, row_direction, col_direction;
bool slit_on_top, slit_auto_hide;
int slit_placement, slit_direction;
unsigned int handle_width, bevel_width, frame_width, border_width;
#ifdef HAVE_STRFTIME
@ -170,6 +167,7 @@ private:
#endif // HAVE_STRFTIME
} resource;
std::string screenstr;
BScreen(const BScreen&);
BScreen& operator=(const BScreen&);
@ -177,15 +175,13 @@ private:
bool parseMenuFile(FILE *file, Rootmenu *menu);
BTexture readDatabaseTexture(const std::string &rname,
const std::string &rclass,
const std::string &default_color);
const std::string &default_color,
Configuration &style);
BColor readDatabaseColor(const std::string &rname,
const std::string &rclass,
const std::string &default_color);
XFontSet readDatabaseFontSet(const std::string &rname,
const std::string &rclass);
XFontStruct *readDatabaseFont(const std::string &rname,
const std::string &rclass);
const std::string &default_color,
Configuration &style);
XFontSet readDatabaseFontSet(const std::string &rname, Configuration &style);
XFontStruct *readDatabaseFont(const std::string &rname, Configuration &style);
XFontSet createFontSet(const std::string &fontname);
void InitMenu(void);
@ -204,21 +200,14 @@ public:
BScreen(Blackbox *bb, unsigned int scrn);
~BScreen(void);
inline bool isToolbarOnTop(void) const
{ return resource.toolbar_on_top; }
inline bool doToolbarAutoHide(void) const
{ return resource.toolbar_auto_hide; }
inline bool isSloppyFocus(void) const
{ return resource.sloppy_focus; }
inline bool isSloppyFocus(void) const { return resource.sloppy_focus; }
inline bool isRootColormapInstalled(void) const
{ return root_colormap_installed; }
inline bool doAutoRaise(void) const { return resource.auto_raise; }
inline bool doClickRaise(void) const { return resource.click_raise; }
inline bool isScreenManaged(void) const { return managed; }
inline bool doImageDither(void) const
{ return resource.image_dither; }
inline bool doOrderedDither(void) const
{ return resource.ordered_dither; }
inline bool doImageDither(void) const { return image_control->doDither(); }
inline bool doOrderedDither(void) const { return resource.ordered_dither; }
inline bool doOpaqueMove(void) const { return resource.opaque_move; }
inline bool doFullMax(void) const { return resource.full_max; }
inline bool doFocusNew(void) const { return resource.focus_new; }
@ -231,19 +220,7 @@ public:
inline BImageControl *getImageControl(void) { return image_control; }
inline Rootmenu *getRootmenu(void) { return rootmenu; }
inline bool isSlitOnTop(void) const { return resource.slit_on_top; }
inline bool doSlitAutoHide(void) const
{ return resource.slit_auto_hide; }
inline Slit *getSlit(void) { return slit; }
inline int getSlitPlacement(void) const
{ return resource.slit_placement; }
inline int getSlitDirection(void) const
{ return resource.slit_direction; }
inline void saveSlitPlacement(int p) { resource.slit_placement = p; }
inline void saveSlitDirection(int d) { resource.slit_direction = d; }
inline void saveSlitOnTop(bool t) { resource.slit_on_top = t; }
inline void saveSlitAutoHide(bool t) { resource.slit_auto_hide = t; }
inline Toolbar *getToolbar(void) { return toolbar; }
Workspace *getWorkspace(unsigned int index);
@ -268,10 +245,6 @@ public:
inline unsigned int getIconCount(void) { return iconList.size(); }
inline unsigned int getNumberOfWorkspaces(void) const
{ return resource.workspaces; }
inline int getToolbarPlacement(void) const
{ return resource.toolbar_placement; }
inline int getToolbarWidthPercent(void) const
{ return resource.toolbar_width_percent; }
inline int getPlacementPolicy(void) const
{ return resource.placement_policy; }
inline int getEdgeSnapThreshold(void) const
@ -282,25 +255,19 @@ public:
{ return resource.col_direction; }
inline void setRootColormapInstalled(bool r) { root_colormap_installed = r; }
inline void saveSloppyFocus(bool s) { resource.sloppy_focus = s; }
inline void saveAutoRaise(bool a) { resource.auto_raise = a; }
inline void saveClickRaise(bool c) { resource.click_raise = c; }
inline void saveWorkspaces(unsigned int w) { resource.workspaces = w; }
inline void saveToolbarOnTop(bool r) { resource.toolbar_on_top = r; }
inline void saveToolbarAutoHide(bool r) { resource.toolbar_auto_hide = r; }
inline void saveToolbarWidthPercent(int w)
{ resource.toolbar_width_percent = w; }
inline void saveToolbarPlacement(int p) { resource.toolbar_placement = p; }
inline void savePlacementPolicy(int p) { resource.placement_policy = p; }
inline void saveRowPlacementDirection(int d) { resource.row_direction = d; }
inline void saveColPlacementDirection(int d) { resource.col_direction = d; }
inline void saveEdgeSnapThreshold(int t)
{ resource.edge_snap_threshold = t; }
inline void saveImageDither(bool d) { resource.image_dither = d; }
inline void saveOpaqueMove(bool o) { resource.opaque_move = o; }
inline void saveFullMax(bool f) { resource.full_max = f; }
inline void saveFocusNew(bool f) { resource.focus_new = f; }
inline void saveFocusLast(bool f) { resource.focus_last = f; }
void saveSloppyFocus(bool s);
void saveAutoRaise(bool a);
void saveClickRaise(bool c);
void saveWorkspaces(unsigned int w);
void savePlacementPolicy(int p);
void saveRowPlacementDirection(int d);
void saveColPlacementDirection(int d);
void saveEdgeSnapThreshold(int t);
void saveImageDither(bool d);
void saveOpaqueMove(bool o);
void saveFullMax(bool f);
void saveFocusNew(bool f);
void saveFocusLast(bool f);
inline void iconUpdate(void) { iconmenu->update(); }
#ifdef HAVE_STRFTIME
@ -309,9 +276,9 @@ public:
void saveStrftimeFormat(const std::string& format);
#else // !HAVE_STRFTIME
inline int getDateFormat(void) { return resource.date_format; }
inline void saveDateFormat(int f) { resource.date_format = f; }
inline void saveDateFormat(int f);
inline bool isClock24Hour(void) { return resource.clock24hour; }
inline void saveClock24Hour(bool c) { resource.clock24hour = c; }
inline void saveClock24Hour(bool c);
#endif // HAVE_STRFTIME
inline WindowStyle *getWindowStyle(void) { return &resource.wstyle; }
@ -331,6 +298,7 @@ public:
void addWorkspaceName(const std::string& name);
const std::string getNameOfWorkspace(unsigned int id);
void changeWorkspaceID(unsigned int id);
void saveWorkspaceNames(void);
void addNetizen(Netizen *n);
void removeNetizen(Window w);
@ -347,6 +315,8 @@ public:
void prevFocus(void);
void nextFocus(void);
void raiseFocus(void);
void load_rc(void);
void save_rc(void);
void reconfigure(void);
void toggleFocusModel(FocusModel model);
void updateFocusModel(void);

View file

@ -40,9 +40,11 @@ extern "C" {
Slit::Slit(BScreen *scr) {
screen = scr;
blackbox = screen->getBlackbox();
slitstr = (std::string)"session.screen" + itostring(screen->getScreenNumber())
+ ".slit.";
config = blackbox->getConfig();
on_top = screen->isSlitOnTop();
hidden = do_auto_hide = screen->doSlitAutoHide();
load_rc();
display = screen->getBaseDisplay()->getXDisplay();
frame.window = frame.pixmap = None;
@ -197,6 +199,82 @@ void Slit::removeClient(Window w, bool remap) {
}
void Slit::saveOnTop(bool b) {
on_top = b;
config->setValue(slitstr + "onTop", on_top);
}
void Slit::saveAutoHide(bool b) {
do_auto_hide = b;
config->setValue(slitstr + "autoHide", do_auto_hide);
}
void Slit::savePlacement(int p) {
placement = p;
const char *pname;
switch (placement) {
case TopLeft: pname = "TopLeft"; break;
case CenterLeft: pname = "CenterLeft"; break;
case BottomLeft: pname = "BottomLeft"; break;
case TopCenter: pname = "TopCenter"; break;
case BottomCenter: pname = "BottomCenter"; break;
case TopRight: pname = "TopRight"; break;
case BottomRight: pname = "BottomRight"; break;
case CenterRight: default: pname = "CenterRight"; break;
}
config->setValue(slitstr + "placement", pname);
}
void Slit::saveDirection(int d) {
direction = d;
config->setValue(slitstr + "direction", (direction == Horizontal ?
"Horizontal" : "Vertical"));
}
void Slit::save_rc(void) {
saveOnTop(on_top);
saveAutoHide(do_auto_hide);
savePlacement(placement);
saveDirection(direction);
}
void Slit::load_rc(void) {
std::string s;
if (! config->getValue(slitstr + "onTop", on_top))
on_top = false;
if (! config->getValue(slitstr + "autoHide", do_auto_hide))
do_auto_hide = false;
hidden = do_auto_hide;
if (config->getValue(slitstr + "direction", s) && s == "Horizontal")
direction = Horizontal;
else
direction = Vertical;
if (config->getValue(slitstr + "placement", s)) {
if (s == "TopLeft")
placement = TopLeft;
else if (s == "CenterLeft")
placement = CenterLeft;
else if (s == "BottomLeft")
placement = BottomLeft;
else if (s == "TopCenter")
placement = TopCenter;
else if (s == "BottomCenter")
placement = BottomCenter;
else if (s == "TopRight")
placement = TopRight;
else if (s == "BottomRight")
placement = BottomRight;
else //if (s == "CenterRight")
placement = CenterRight;
} else
placement = CenterRight;
}
void Slit::reconfigure(void) {
SlitClientList::iterator it = clientList.begin();
const SlitClientList::iterator end = clientList.end();
@ -204,7 +282,7 @@ void Slit::reconfigure(void) {
unsigned int width = 0, height = 0;
switch (screen->getSlitDirection()) {
switch (direction) {
case Vertical:
for (; it != end; ++it) {
client = *it;
@ -274,7 +352,7 @@ void Slit::reconfigure(void) {
int x, y;
switch (screen->getSlitDirection()) {
switch (direction) {
case Vertical:
x = 0;
y = screen->getBevelWidth();
@ -355,9 +433,9 @@ void Slit::updateStrut(void) {
strut.top = strut.bottom = strut.left = strut.right = 0;
if (! clientList.empty()) {
switch (screen->getSlitDirection()) {
switch (direction) {
case Vertical:
switch (screen->getSlitPlacement()) {
switch (placement) {
case TopCenter:
strut.top = getY() + getExposedHeight() +
(screen->getBorderWidth() * 2);
@ -378,7 +456,7 @@ void Slit::updateStrut(void) {
}
break;
case Horizontal:
switch (screen->getSlitPlacement()) {
switch (placement) {
case TopCenter:
case TopLeft:
case TopRight:
@ -408,11 +486,11 @@ void Slit::updateStrut(void) {
void Slit::reposition(void) {
// place the slit in the appropriate place
switch (screen->getSlitPlacement()) {
switch (placement) {
case TopLeft:
frame.rect.setPos(0, 0);
if (screen->getSlitDirection() == Vertical) {
if (direction == Vertical) {
frame.x_hidden = screen->getBevelWidth() - screen->getBorderWidth()
- frame.rect.width();
frame.y_hidden = 0;
@ -435,7 +513,7 @@ void Slit::reposition(void) {
frame.rect.setPos(0, (screen->getHeight() - frame.rect.height()
- (screen->getBorderWidth() * 2)));
if (screen->getSlitDirection() == Vertical) {
if (direction == Vertical) {
frame.x_hidden = screen->getBevelWidth() - screen->getBorderWidth()
- frame.rect.width();
frame.y_hidden = frame.rect.y();
@ -467,7 +545,7 @@ void Slit::reposition(void) {
frame.rect.setPos((screen->getWidth() - frame.rect.width()
- (screen->getBorderWidth() * 2)), 0);
if (screen->getSlitDirection() == Vertical) {
if (direction == Vertical) {
frame.x_hidden = screen->getWidth() - screen->getBevelWidth()
- screen->getBorderWidth();
frame.y_hidden = 0;
@ -495,7 +573,7 @@ void Slit::reposition(void) {
(screen->getHeight() - frame.rect.height()
- (screen->getBorderWidth() * 2)));
if (screen->getSlitDirection() == Vertical) {
if (direction == Vertical) {
frame.x_hidden = screen->getWidth() - screen->getBevelWidth()
- screen->getBorderWidth();
frame.y_hidden = frame.rect.y();
@ -523,7 +601,7 @@ void Slit::reposition(void) {
delta = -delta;
}
frame.rect.setY(frame.rect.y() + delta);
if (screen->getSlitDirection() == Vertical)
if (direction == Vertical)
frame.y_hidden += delta;
}
@ -644,7 +722,7 @@ void Slit::timeout(void) {
void Slit::toggleAutoHide(void) {
do_auto_hide = (do_auto_hide) ? False : True;
saveAutoHide(do_auto_hide ? False : True);
updateStrut();
@ -699,8 +777,8 @@ void Slitmenu::itemSelected(int button, unsigned int index) {
switch (item->function()) {
case 1: { // always on top
slit->on_top = ((slit->isOnTop()) ? False : True);
setItemSelected(2, slit->on_top);
slit->saveOnTop(! slit->isOnTop());
setItemSelected(2, slit->isOnTop());
if (slit->isOnTop()) slit->screen->raiseWindows((Window *) 0, 0);
break;
@ -708,7 +786,7 @@ void Slitmenu::itemSelected(int button, unsigned int index) {
case 2: { // auto hide
slit->toggleAutoHide();
setItemSelected(3, slit->do_auto_hide);
setItemSelected(3, slit->doAutoHide());
break;
}
@ -732,7 +810,7 @@ void Slitmenu::reconfigure(void) {
Slitmenu::Directionmenu::Directionmenu(Slitmenu *sm)
: Basemenu(sm->slit->screen) {
: Basemenu(sm->slit->screen), slit(sm->slit) {
setLabel(i18n(SlitSet, SlitSlitDirection, "Slit Direction"));
setInternalMenu();
@ -743,11 +821,20 @@ Slitmenu::Directionmenu::Directionmenu(Slitmenu *sm)
Slit::Vertical);
update();
setValues();
}
if (getScreen()->getSlitDirection() == Slit::Horizontal)
setItemSelected(0, True);
else
setItemSelected(1, True);
void Slitmenu::Directionmenu::reconfigure(void) {
setValues();
Basemenu::reconfigure();
}
void Slitmenu::Directionmenu::setValues(void) {
const bool horiz = slit->getDirection() == Slit::Horizontal;
setItemSelected(0, horiz);
setItemSelected(1, ! horiz);
}
@ -758,23 +845,14 @@ void Slitmenu::Directionmenu::itemSelected(int button, unsigned int index) {
BasemenuItem *item = find(index);
if (! item) return;
getScreen()->saveSlitDirection(item->function());
if (item->function() == Slit::Horizontal) {
setItemSelected(0, True);
setItemSelected(1, False);
} else {
setItemSelected(0, False);
setItemSelected(1, True);
}
slit->saveDirection(item->function());
hide();
getScreen()->getSlit()->reconfigure();
slit->reconfigure();
}
Slitmenu::Placementmenu::Placementmenu(Slitmenu *sm)
: Basemenu(sm->slit->screen) {
: Basemenu(sm->slit->screen), slit(sm->slit) {
setLabel(i18n(SlitSet, SlitSlitPlacement, "Slit Placement"));
setMinimumSublevels(3);
@ -799,6 +877,45 @@ Slitmenu::Placementmenu::Placementmenu(Slitmenu *sm)
Slit::BottomRight);
update();
setValues();
}
void Slitmenu::Placementmenu::reconfigure(void) {
setValues();
Basemenu::reconfigure();
}
void Slitmenu::Placementmenu::setValues(void) {
int place = 0;
switch (slit->getPlacement()) {
case Slit::BottomRight:
place++;
case Slit::CenterRight:
place++;
case Slit::TopRight:
place++;
case Slit::BottomCenter:
place++;
case Slit::TopCenter:
place++;
case Slit::BottomLeft:
place++;
case Slit::CenterLeft:
place++;
case Slit::TopLeft:
break;
}
setItemSelected(0, 0 == place);
setItemSelected(1, 1 == place);
setItemSelected(2, 2 == place);
setItemSelected(3, 3 == place);
setItemSelected(5, 4 == place);
setItemSelected(6, 5 == place);
setItemSelected(7, 6 == place);
setItemSelected(8, 7 == place);
}
@ -809,8 +926,8 @@ void Slitmenu::Placementmenu::itemSelected(int button, unsigned int index) {
BasemenuItem *item = find(index);
if (! (item && item->function())) return;
getScreen()->saveSlitPlacement(item->function());
slit->savePlacement(item->function());
hide();
getScreen()->getSlit()->reconfigure();
slit->reconfigure();
}

View file

@ -30,6 +30,7 @@ extern "C" {
}
#include <list>
#include <string>
#include "Screen.hh"
#include "Basemenu.hh"
@ -44,24 +45,30 @@ private:
private:
Directionmenu(const Directionmenu&);
Directionmenu& operator=(const Directionmenu&);
Slit *slit;
protected:
virtual void itemSelected(int button, unsigned int index);
virtual void setValues(void);
public:
Directionmenu(Slitmenu *sm);
virtual void reconfigure(void);
};
class Placementmenu : public Basemenu {
private:
Placementmenu(const Placementmenu&);
Placementmenu& operator=(const Placementmenu&);
Slit *slit;
protected:
virtual void itemSelected(int buton, unsigned int index);
virtual void setValues(void);
public:
Placementmenu(Slitmenu *sm);
virtual void reconfigure(void);
};
Directionmenu *directionmenu;
@ -103,10 +110,13 @@ private:
typedef std::list<SlitClient*> SlitClientList;
bool on_top, hidden, do_auto_hide;
int direction, placement;
std::string slitstr;
Display *display;
Blackbox *blackbox;
BScreen *screen;
Configuration *config;
BTimer *timer;
Strut strut;
@ -137,6 +147,13 @@ public:
inline bool isOnTop(void) const { return on_top; }
inline bool isHidden(void) const { return hidden; }
inline bool doAutoHide(void) const { return do_auto_hide; }
inline int getPlacement(void) const { return placement; }
inline int getDirection(void) const { return direction; }
void saveOnTop(bool);
void saveAutoHide(bool);
void savePlacement(int);
void saveDirection(int);
inline Slitmenu *getMenu(void) { return slitmenu; }
@ -149,13 +166,13 @@ public:
inline unsigned int getWidth(void) const { return frame.rect.width(); }
inline unsigned int getExposedWidth(void) const {
if (screen->getSlitDirection() == Vertical && do_auto_hide)
if (direction == Vertical && do_auto_hide)
return screen->getBevelWidth();
return frame.rect.width();
}
inline unsigned int getHeight(void) const { return frame.rect.height(); }
inline unsigned int getExposedHeight(void) const {
if (screen->getSlitDirection() == Horizontal && do_auto_hide)
if (direction == Horizontal && do_auto_hide)
return screen->getBevelWidth();
return frame.rect.height();
}
@ -163,6 +180,8 @@ public:
void addClient(Window w);
void removeClient(SlitClient *client, bool remap = True);
void removeClient(Window w, bool remap = True);
void load_rc(void);
void save_rc(void);
void reconfigure(void);
void updateSlit(void);
void reposition(void);

View file

@ -76,6 +76,11 @@ static long aMinuteFromNow(void) {
Toolbar::Toolbar(BScreen *scrn) {
screen = scrn;
blackbox = screen->getBlackbox();
toolbarstr = (string)"session.screen" + itostring(screen->getScreenNumber())
+ ".toolbar.";
config = blackbox->getConfig();
load_rc();
// get the clock updating every minute
clock_timer = new BTimer(blackbox, this);
@ -88,9 +93,6 @@ Toolbar::Toolbar(BScreen *scrn) {
hide_timer = new BTimer(blackbox, &hide_handler);
hide_timer->setTimeout(blackbox->getAutoRaiseDelay());
on_top = screen->isToolbarOnTop();
hidden = do_auto_hide = screen->doToolbarAutoHide();
editing = False;
new_name_pos = 0;
frame.grab_x = frame.grab_y = 0;
@ -196,9 +198,82 @@ Toolbar::~Toolbar(void) {
}
void Toolbar::saveOnTop(bool b) {
on_top = b;
config->setValue(toolbarstr + "onTop", on_top);
}
void Toolbar::saveAutoHide(bool b) {
do_auto_hide = b;
config->setValue(toolbarstr + "autoHide", do_auto_hide);
}
void Toolbar::saveWidthPercent(unsigned int w) {
width_percent = w;
config->setValue(toolbarstr + "widthPercent", width_percent);
}
void Toolbar::savePlacement(int p) {
placement = p;
const char *pname;
switch (placement) {
case TopLeft: pname = "TopLeft"; break;
case BottomLeft: pname = "BottomLeft"; break;
case TopCenter: pname = "TopCenter"; break;
case TopRight: pname = "TopRight"; break;
case BottomRight: pname = "BottomRight"; break;
case BottomCenter: default: pname = "BottomCenter"; break;
}
config->setValue(toolbarstr + "placement", pname);
}
void Toolbar::save_rc(void) {
saveOnTop(on_top);
saveAutoHide(do_auto_hide);
saveWidthPercent(width_percent);
savePlacement(placement);
}
void Toolbar::load_rc(void) {
string s;
if (! config->getValue(toolbarstr + "onTop", on_top))
on_top = false;
if (! config->getValue(toolbarstr + "autoHide", do_auto_hide))
do_auto_hide = false;
hidden = do_auto_hide;
if (! config->getValue(toolbarstr + "widthPercent", width_percent) ||
width_percent == 0 || width_percent > 100)
width_percent = 66;
if (config->getValue(toolbarstr + "placement", s)) {
if (s == "TopLeft")
placement = TopLeft;
else if (s == "BottomLeft")
placement = BottomLeft;
else if (s == "TopCenter")
placement = TopCenter;
else if (s == "TopRight")
placement = TopRight;
else if (s == "BottomRight")
placement = BottomRight;
else //if (s == "BottomCenter")
placement = BottomCenter;
} else
placement = BottomCenter;
}
void Toolbar::reconfigure(void) {
unsigned int height = 0,
width = (screen->getWidth() * screen->getToolbarWidthPercent()) / 100;
width = (screen->getWidth() * width_percent) / 100;
if (i18n.multibyte())
height = screen->getToolbarStyle()->fontset_extents->max_ink_extent.height;
@ -215,13 +290,13 @@ void Toolbar::reconfigure(void) {
frame.rect.setSize(width, height);
int x, y;
switch (screen->getToolbarPlacement()) {
switch (placement) {
case TopLeft:
case TopRight:
case TopCenter:
if (screen->getToolbarPlacement() == TopLeft)
if (placement == TopLeft)
x = 0;
else if (screen->getToolbarPlacement() == TopRight)
else if (placement == TopRight)
x = screen->getWidth() - frame.rect.width()
- (screen->getBorderWidth() * 2);
else
@ -238,9 +313,9 @@ void Toolbar::reconfigure(void) {
case BottomRight:
case BottomCenter:
default:
if (screen->getToolbarPlacement() == BottomLeft)
if (placement == BottomLeft)
x = 0;
else if (screen->getToolbarPlacement() == BottomRight)
else if (placement == BottomRight)
x = screen->getWidth() - frame.rect.width()
- (screen->getBorderWidth() * 2);
else
@ -436,7 +511,7 @@ void Toolbar::updateStrut(void) {
// left and right are always 0
strut.top = strut.bottom = 0;
switch(screen->getToolbarPlacement()) {
switch(placement) {
case TopLeft:
case TopCenter:
case TopRight:
@ -973,7 +1048,7 @@ void Toolbar::HideHandler::timeout(void) {
void Toolbar::toggleAutoHide(void) {
do_auto_hide = (do_auto_hide) ? False : True;
saveAutoHide(! doAutoHide());
updateStrut();
screen->getSlit()->reposition();
@ -1002,9 +1077,13 @@ Toolbarmenu::Toolbarmenu(Toolbar *tb) : Basemenu(tb->screen) {
"Edit current workspace name"), 3);
update();
setValues();
}
if (toolbar->isOnTop()) setItemSelected(1, True);
if (toolbar->doAutoHide()) setItemSelected(2, True);
void Toolbarmenu::setValues() {
setItemSelected(1, toolbar->isOnTop());
setItemSelected(2, toolbar->doAutoHide());
}
@ -1022,8 +1101,8 @@ void Toolbarmenu::itemSelected(int button, unsigned int index) {
switch (item->function()) {
case 1: { // always on top
toolbar->on_top = ((toolbar->isOnTop()) ? False : True);;
setItemSelected(1, toolbar->on_top);
toolbar->saveOnTop(! toolbar->isOnTop());
setItemSelected(1, toolbar->isOnTop());
if (toolbar->isOnTop()) getScreen()->raiseWindows((Window *) 0, 0);
break;
@ -1031,7 +1110,7 @@ void Toolbarmenu::itemSelected(int button, unsigned int index) {
case 2: { // auto hide
toolbar->toggleAutoHide();
setItemSelected(2, toolbar->do_auto_hide);
setItemSelected(2, toolbar->doAutoHide());
break;
}
@ -1054,6 +1133,7 @@ void Toolbarmenu::internal_hide(void) {
void Toolbarmenu::reconfigure(void) {
setValues();
placementmenu->reconfigure();
Basemenu::reconfigure();
@ -1061,7 +1141,7 @@ void Toolbarmenu::reconfigure(void) {
Toolbarmenu::Placementmenu::Placementmenu(Toolbarmenu *tm)
: Basemenu(tm->toolbar->screen) {
: Basemenu(tm->toolbar->screen), toolbar(tm->toolbar) {
setLabel(i18n(ToolbarSet, ToolbarToolbarPlacement, "Toolbar Placement"));
setInternalMenu();
setMinimumSublevels(3);
@ -1079,6 +1159,38 @@ Toolbarmenu::Placementmenu::Placementmenu(Toolbarmenu *tm)
insert(i18n(CommonSet, CommonPlacementBottomRight, "Bottom Right"),
Toolbar::BottomRight);
update();
setValues();
}
void Toolbarmenu::Placementmenu::setValues(void) {
int place = 0;
switch (toolbar->getPlacement()) {
case Toolbar::BottomRight:
place++;
case Toolbar::TopRight:
place++;
case Toolbar::BottomCenter:
place++;
case Toolbar::TopCenter:
place++;
case Toolbar::BottomLeft:
place++;
case Toolbar::TopLeft:
break;
}
setItemSelected(0, 0 == place);
setItemSelected(1, 1 == place);
setItemSelected(2, 2 == place);
setItemSelected(3, 3 == place);
setItemSelected(4, 4 == place);
setItemSelected(5, 5 == place);
}
void Toolbarmenu::Placementmenu::reconfigure(void) {
setValues();
Basemenu::reconfigure();
}
@ -1089,9 +1201,9 @@ void Toolbarmenu::Placementmenu::itemSelected(int button, unsigned int index) {
BasemenuItem *item = find(index);
if (! item) return;
getScreen()->saveToolbarPlacement(item->function());
toolbar->savePlacement(item->function());
hide();
getScreen()->getToolbar()->reconfigure();
toolbar->reconfigure();
// reposition the slit as well to make sure it doesn't intersect the
// toolbar

View file

@ -41,12 +41,15 @@ private:
private:
Placementmenu(const Placementmenu&);
Placementmenu& operator=(const Placementmenu&);
Toolbar *toolbar;
protected:
virtual void itemSelected(int button, unsigned int index);
virtual void setValues(void);
public:
Placementmenu(Toolbarmenu *tm);
virtual void reconfigure(void);
};
Toolbar *toolbar;
@ -61,6 +64,7 @@ private:
protected:
virtual void itemSelected(int button, unsigned int index);
virtual void internal_hide(void);
virtual void setValues(void);
public:
Toolbarmenu(Toolbar *tb);
@ -68,13 +72,16 @@ public:
inline Basemenu *getPlacementmenu(void) { return placementmenu; }
void reconfigure(void);
virtual void reconfigure(void);
};
class Toolbar : public TimeoutHandler {
private:
bool on_top, editing, hidden, do_auto_hide;
unsigned int width_percent;
int placement;
std::string toolbarstr;
Display *display;
struct ToolbarFrame {
@ -99,6 +106,7 @@ private:
Blackbox *blackbox;
BScreen *screen;
Configuration *config;
BTimer *clock_timer, *hide_timer;
Toolbarmenu *toolbarmenu;
Strut strut;
@ -136,6 +144,16 @@ public:
inline bool isOnTop(void) const { return on_top; }
inline bool isHidden(void) const { return hidden; }
inline bool doAutoHide(void) const { return do_auto_hide; }
inline unsigned int getWidthPercent(void) const { return width_percent; }
inline int getPlacement(void) const { return placement; }
void saveOnTop(bool);
void saveAutoHide(bool);
void saveWidthPercent(unsigned int);
void savePlacement(int);
void save_rc(void);
void load_rc(void);
inline Window getWindowID(void) const { return frame.window; }

View file

@ -220,3 +220,24 @@ timeval normalizeTimeval(const timeval &tm) {
return ret;
}
string itostring(unsigned long i) {
if (i == 0)
return string("0");
string tmp;
for (; i > 0; i /= 10)
tmp.insert(tmp.begin(), "0123456789"[i%10]);
return tmp;
}
string itostring(long i) {
if (i < 0) {
std::string tmp = itostring( (unsigned long) -i);
tmp.insert(tmp.begin(), '-');
return tmp;
} else
return itostring( (unsigned long) i);
}

View file

@ -99,4 +99,13 @@ struct PointerAssassin {
}
};
std::string itostring(unsigned long i);
std::string itostring(long i);
inline std::string itostring(unsigned int i) {
return itostring((unsigned long) i);
}
inline std::string itostring(int i) {
return itostring((long) i);
}
#endif

View file

@ -28,7 +28,6 @@
extern "C" {
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
@ -146,6 +145,7 @@ Blackbox::Blackbox(char **m_argv, char *dpy_name, char *rc, char *menu)
argv = m_argv;
if (! rc) rc = "~/.openbox/rc";
rc_file = expandTilde(rc);
config.setFile(rc_file);
if (! menu) menu = "~/.openbox/menu";
menu_file = expandTilde(menu);
@ -184,6 +184,9 @@ Blackbox::Blackbox(char **m_argv, char *dpy_name, char *rc, char *menu)
::exit(3);
}
// save current settings and default values
save_rc();
// set the screen with mouse to the first managed screen
active_screen = screenList.front();
setFocusedWindow(0);
@ -716,11 +719,8 @@ void Blackbox::process_event(XEvent *e) {
bool Blackbox::handleSignal(int sig) {
switch (sig) {
case SIGHUP:
reconfigure();
break;
case SIGUSR1:
reload_rc();
reconfigure();
break;
case SIGUSR2:
@ -969,546 +969,69 @@ void Blackbox::shutdown(void) {
std::mem_fun(&BScreen::shutdown));
XSync(getXDisplay(), False);
save_rc();
}
/*
* Save all values as they are so that the defaults will be written to the rc
* file
*/
void Blackbox::save_rc(void) {
XrmDatabase new_blackboxrc = (XrmDatabase) 0;
char rc_string[1024];
config.setAutoSave(false);
load_rc();
sprintf(rc_string, "session.colorsPerChannel: %d",
resource.colors_per_channel);
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.doubleClickInterval: %lu",
config.setValue("session.colorsPerChannel", resource.colors_per_channel);
config.setValue("session.doubleClickInterval",
resource.double_click_interval);
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.autoRaiseDelay: %lu",
config.setValue("session.autoRaiseDelay",
((resource.auto_raise_delay.tv_sec * 1000) +
(resource.auto_raise_delay.tv_usec / 1000)));
XrmPutLineResource(&new_blackboxrc, rc_string);
config.setValue("session.cacheLife", resource.cache_life / 60000);
config.setValue("session.cacheMax", resource.cache_max);
config.setValue("session.styleFile", resource.style_file);
sprintf(rc_string, "session.cacheLife: %lu", resource.cache_life / 60000);
XrmPutLineResource(&new_blackboxrc, rc_string);
std::for_each(screenList.begin(), screenList.end(),
std::mem_fun(&BScreen::save_rc));
sprintf(rc_string, "session.cacheMax: %lu", resource.cache_max);
XrmPutLineResource(&new_blackboxrc, rc_string);
ScreenList::iterator it = screenList.begin();
for (; it != screenList.end(); ++it) {
BScreen *screen = *it;
int screen_number = screen->getScreenNumber();
char *placement = (char *) 0;
switch (screen->getSlitPlacement()) {
case Slit::TopLeft: placement = "TopLeft"; break;
case Slit::CenterLeft: placement = "CenterLeft"; break;
case Slit::BottomLeft: placement = "BottomLeft"; break;
case Slit::TopCenter: placement = "TopCenter"; break;
case Slit::BottomCenter: placement = "BottomCenter"; break;
case Slit::TopRight: placement = "TopRight"; break;
case Slit::BottomRight: placement = "BottomRight"; break;
case Slit::CenterRight: default: placement = "CenterRight"; break;
}
sprintf(rc_string, "session.screen%d.slit.placement: %s", screen_number,
placement);
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.slit.direction: %s", screen_number,
((screen->getSlitDirection() == Slit::Horizontal) ? "Horizontal" :
"Vertical"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.slit.onTop: %s", screen_number,
((screen->getSlit()->isOnTop()) ? "True" : "False"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.slit.autoHide: %s", screen_number,
((screen->getSlit()->doAutoHide()) ? "True" : "False"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.opaqueMove: %s",
((screen->doOpaqueMove()) ? "True" : "False"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.imageDither: %s",
((screen->getImageControl()->doDither()) ? "True" : "False"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.fullMaximization: %s", screen_number,
((screen->doFullMax()) ? "True" : "False"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.focusNewWindows: %s", screen_number,
((screen->doFocusNew()) ? "True" : "False"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.focusLastWindow: %s", screen_number,
((screen->doFocusLast()) ? "True" : "False"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.rowPlacementDirection: %s",
screen_number,
((screen->getRowPlacementDirection() == BScreen::LeftRight) ?
"LeftToRight" : "RightToLeft"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.colPlacementDirection: %s",
screen_number,
((screen->getColPlacementDirection() == BScreen::TopBottom) ?
"TopToBottom" : "BottomToTop"));
XrmPutLineResource(&new_blackboxrc, rc_string);
switch (screen->getPlacementPolicy()) {
case BScreen::CascadePlacement:
placement = "CascadePlacement";
break;
case BScreen::ColSmartPlacement:
placement = "ColSmartPlacement";
break;
case BScreen::RowSmartPlacement:
default:
placement = "RowSmartPlacement";
break;
}
sprintf(rc_string, "session.screen%d.windowPlacement: %s", screen_number,
placement);
XrmPutLineResource(&new_blackboxrc, rc_string);
string fmodel;
if (screen->isSloppyFocus()) {
fmodel = "SloppyFocus";
if (screen->doAutoRaise()) fmodel += " AutoRaise";
if (screen->doClickRaise()) fmodel += " ClickRaise";
} else {
fmodel = "ClickToFocus";
}
sprintf(rc_string, "session.screen%d.focusModel: %s", screen_number,
fmodel.c_str());
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.workspaces: %d", screen_number,
screen->getWorkspaceCount());
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.toolbar.onTop: %s", screen_number,
((screen->getToolbar()->isOnTop()) ? "True" : "False"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.toolbar.autoHide: %s",
screen_number,
((screen->getToolbar()->doAutoHide()) ? "True" : "False"));
XrmPutLineResource(&new_blackboxrc, rc_string);
switch (screen->getToolbarPlacement()) {
case Toolbar::TopLeft: placement = "TopLeft"; break;
case Toolbar::BottomLeft: placement = "BottomLeft"; break;
case Toolbar::TopCenter: placement = "TopCenter"; break;
case Toolbar::TopRight: placement = "TopRight"; break;
case Toolbar::BottomRight: placement = "BottomRight"; break;
case Toolbar::BottomCenter: default: placement = "BottomCenter"; break;
}
sprintf(rc_string, "session.screen%d.toolbar.placement: %s",
screen_number, placement);
XrmPutLineResource(&new_blackboxrc, rc_string);
load_rc(screen);
// these are static, but may not be saved in the users .blackboxrc,
// writing these resources will allow the user to edit them at a later
// time... but loading the defaults before saving allows us to rewrite the
// users changes...
#ifdef HAVE_STRFTIME
sprintf(rc_string, "session.screen%d.strftimeFormat: %s", screen_number,
screen->getStrftimeFormat());
XrmPutLineResource(&new_blackboxrc, rc_string);
#else // !HAVE_STRFTIME
sprintf(rc_string, "session.screen%d.dateFormat: %s", screen_number,
((screen->getDateFormat() == B_EuropeanDate) ?
"European" : "American"));
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.clockFormat: %d", screen_number,
((screen->isClock24Hour()) ? 24 : 12));
XrmPutLineResource(&new_blackboxrc, rc_string);
#endif // HAVE_STRFTIME
sprintf(rc_string, "session.screen%d.edgeSnapThreshold: %d",
screen_number, screen->getEdgeSnapThreshold());
XrmPutLineResource(&new_blackboxrc, rc_string);
sprintf(rc_string, "session.screen%d.toolbar.widthPercent: %d",
screen_number, screen->getToolbarWidthPercent());
XrmPutLineResource(&new_blackboxrc, rc_string);
// write out the user's workspace names
string save_string = screen->getWorkspace(0)->getName();
for (unsigned int i = 1; i < screen->getWorkspaceCount(); ++i) {
save_string += ',';
save_string += screen->getWorkspace(i)->getName();
}
char *resource_string = new char[save_string.length() + 48];
sprintf(resource_string, "session.screen%d.workspaceNames: %s",
screen_number, save_string.c_str());
XrmPutLineResource(&new_blackboxrc, resource_string);
delete [] resource_string;
}
XrmDatabase old_blackboxrc = XrmGetFileDatabase(rc_file.c_str());
XrmMergeDatabases(new_blackboxrc, &old_blackboxrc);
XrmPutFileDatabase(old_blackboxrc, rc_file.c_str());
XrmDestroyDatabase(old_blackboxrc);
config.setAutoSave(true);
config.save();
}
void Blackbox::load_rc(void) {
XrmDatabase database = (XrmDatabase) 0;
if (! config.load())
config.create();
database = XrmGetFileDatabase(rc_file.c_str());
XrmValue value;
char *value_type;
int int_value;
unsigned long long_value;
string s;
if (! config.getValue("session.colorsPerChannel",
resource.colors_per_channel))
resource.colors_per_channel = 4;
if (XrmGetResource(database, "session.colorsPerChannel",
"Session.ColorsPerChannel", &value_type, &value) &&
sscanf(value.addr, "%d", &int_value) == 1) {
resource.colors_per_channel = int_value;
if (resource.colors_per_channel < 2) resource.colors_per_channel = 2;
if (resource.colors_per_channel > 6) resource.colors_per_channel = 6;
}
else if (resource.colors_per_channel > 6) resource.colors_per_channel = 6;
if (XrmGetResource(database, "session.styleFile", "Session.StyleFile",
&value_type, &value))
resource.style_file = expandTilde(value.addr);
if (config.getValue("session.styleFile", s))
resource.style_file = expandTilde(s);
else
resource.style_file = DEFAULTSTYLE;
if (! config.getValue("session.doubleClickInterval",
resource.double_click_interval));
resource.double_click_interval = 250;
if (XrmGetResource(database, "session.doubleClickInterval",
"Session.DoubleClickInterval", &value_type, &value) &&
sscanf(value.addr, "%lu", &long_value) == 1) {
resource.double_click_interval = long_value;
}
if (! config.getValue("session.autoRaiseDelay",
resource.auto_raise_delay.tv_usec))
resource.auto_raise_delay.tv_usec = 400;
if (XrmGetResource(database, "session.autoRaiseDelay",
"Session.AutoRaiseDelay", &value_type, &value) &&
sscanf(value.addr, "%lu", &long_value) == 1) {
resource.auto_raise_delay.tv_usec = long_value;
}
resource.auto_raise_delay.tv_sec = resource.auto_raise_delay.tv_usec / 1000;
resource.auto_raise_delay.tv_usec -=
(resource.auto_raise_delay.tv_sec * 1000);
resource.auto_raise_delay.tv_usec *= 1000;
resource.cache_life = 5l;
if (XrmGetResource(database, "session.cacheLife", "Session.CacheLife",
&value_type, &value) &&
sscanf(value.addr, "%lu", &long_value) == 1) {
resource.cache_life = long_value;
}
if (! config.getValue("session.cacheLife", resource.cache_life))
resource.cache_life = 5;
resource.cache_life *= 60000;
if (! config.getValue("session.cacheMax", resource.cache_max))
resource.cache_max = 200;
if (XrmGetResource(database, "session.cacheMax", "Session.CacheMax",
&value_type, &value) &&
sscanf(value.addr, "%lu", &long_value) == 1) {
resource.cache_max = long_value;
}
}
void Blackbox::load_rc(BScreen *screen) {
XrmDatabase database = (XrmDatabase) 0;
database = XrmGetFileDatabase(rc_file.c_str());
XrmValue value;
char *value_type, name_lookup[1024], class_lookup[1024];
int screen_number = screen->getScreenNumber();
int int_value;
sprintf(name_lookup, "session.screen%d.fullMaximization", screen_number);
sprintf(class_lookup, "Session.Screen%d.FullMaximization", screen_number);
screen->saveFullMax(False);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
! strncasecmp(value.addr, "true", value.size)) {
screen->saveFullMax(True);
}
sprintf(name_lookup, "session.screen%d.focusNewWindows", screen_number);
sprintf(class_lookup, "Session.Screen%d.FocusNewWindows", screen_number);
screen->saveFocusNew(False);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
! strncasecmp(value.addr, "true", value.size)) {
screen->saveFocusNew(True);
}
sprintf(name_lookup, "session.screen%d.focusLastWindow", screen_number);
sprintf(class_lookup, "Session.Screen%d.focusLastWindow", screen_number);
screen->saveFocusLast(False);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
! strncasecmp(value.addr, "true", value.size)) {
screen->saveFocusLast(True);
}
sprintf(name_lookup, "session.screen%d.rowPlacementDirection",
screen_number);
sprintf(class_lookup, "Session.Screen%d.RowPlacementDirection",
screen_number);
screen->saveRowPlacementDirection(BScreen::LeftRight);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
! strncasecmp(value.addr, "righttoleft", value.size)) {
screen->saveRowPlacementDirection(BScreen::RightLeft);
}
sprintf(name_lookup, "session.screen%d.colPlacementDirection",
screen_number);
sprintf(class_lookup, "Session.Screen%d.ColPlacementDirection",
screen_number);
screen->saveColPlacementDirection(BScreen::TopBottom);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
! strncasecmp(value.addr, "bottomtotop", value.size)) {
screen->saveColPlacementDirection(BScreen::BottomTop);
}
sprintf(name_lookup, "session.screen%d.workspaces", screen_number);
sprintf(class_lookup, "Session.Screen%d.Workspaces", screen_number);
screen->saveWorkspaces(1);
if (XrmGetResource(database, name_lookup, class_lookup,
&value_type, &value) &&
sscanf(value.addr, "%d", &int_value) == 1 &&
int_value > 0 && int_value < 128) {
screen->saveWorkspaces(int_value);
}
sprintf(name_lookup, "session.screen%d.toolbar.widthPercent",
screen_number);
sprintf(class_lookup, "Session.Screen%d.Toolbar.WidthPercent",
screen_number);
screen->saveToolbarWidthPercent(66);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
sscanf(value.addr, "%d", &int_value) == 1 &&
int_value > 0 && int_value <= 100) {
screen->saveToolbarWidthPercent(int_value);
}
sprintf(name_lookup, "session.screen%d.toolbar.placement", screen_number);
sprintf(class_lookup, "Session.Screen%d.Toolbar.Placement", screen_number);
screen->saveToolbarPlacement(Toolbar::BottomCenter);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value)) {
if (! strncasecmp(value.addr, "TopLeft", value.size))
screen->saveToolbarPlacement(Toolbar::TopLeft);
else if (! strncasecmp(value.addr, "BottomLeft", value.size))
screen->saveToolbarPlacement(Toolbar::BottomLeft);
else if (! strncasecmp(value.addr, "TopCenter", value.size))
screen->saveToolbarPlacement(Toolbar::TopCenter);
else if (! strncasecmp(value.addr, "TopRight", value.size))
screen->saveToolbarPlacement(Toolbar::TopRight);
else if (! strncasecmp(value.addr, "BottomRight", value.size))
screen->saveToolbarPlacement(Toolbar::BottomRight);
}
screen->removeWorkspaceNames();
sprintf(name_lookup, "session.screen%d.workspaceNames", screen_number);
sprintf(class_lookup, "Session.Screen%d.WorkspaceNames", screen_number);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value)) {
string search = value.addr;
string::const_iterator it = search.begin(),
end = search.end();
while (1) {
string::const_iterator tmp = it; // current string.begin()
it = std::find(tmp, end, ','); // look for comma between tmp and end
screen->addWorkspaceName(string(tmp, it)); // string = search[tmp:it]
if (it == end) break;
++it;
}
}
sprintf(name_lookup, "session.screen%d.toolbar.onTop", screen_number);
sprintf(class_lookup, "Session.Screen%d.Toolbar.OnTop", screen_number);
screen->saveToolbarOnTop(False);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
! strncasecmp(value.addr, "true", value.size)) {
screen->saveToolbarOnTop(True);
}
sprintf(name_lookup, "session.screen%d.toolbar.autoHide", screen_number);
sprintf(class_lookup, "Session.Screen%d.Toolbar.autoHide", screen_number);
screen->saveToolbarAutoHide(False);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
! strncasecmp(value.addr, "true", value.size)) {
screen->saveToolbarAutoHide(True);
}
sprintf(name_lookup, "session.screen%d.focusModel", screen_number);
sprintf(class_lookup, "Session.Screen%d.FocusModel", screen_number);
screen->saveSloppyFocus(True);
screen->saveAutoRaise(False);
screen->saveClickRaise(False);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value)) {
string fmodel = value.addr;
if (fmodel.find("ClickToFocus") != string::npos) {
screen->saveSloppyFocus(False);
} else {
// must be sloppy
if (fmodel.find("AutoRaise") != string::npos)
screen->saveAutoRaise(True);
if (fmodel.find("ClickRaise") != string::npos)
screen->saveClickRaise(True);
}
}
sprintf(name_lookup, "session.screen%d.windowPlacement", screen_number);
sprintf(class_lookup, "Session.Screen%d.WindowPlacement", screen_number);
screen->savePlacementPolicy(BScreen::RowSmartPlacement);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value)) {
if (! strncasecmp(value.addr, "RowSmartPlacement", value.size))
/* pass */;
else if (! strncasecmp(value.addr, "ColSmartPlacement", value.size))
screen->savePlacementPolicy(BScreen::ColSmartPlacement);
else if (! strncasecmp(value.addr, "CascadePlacement", value.size))
screen->savePlacementPolicy(BScreen::CascadePlacement);
}
sprintf(name_lookup, "session.screen%d.slit.placement", screen_number);
sprintf(class_lookup, "Session.Screen%d.Slit.Placement", screen_number);
screen->saveSlitPlacement(Slit::CenterRight);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value)) {
if (! strncasecmp(value.addr, "TopLeft", value.size))
screen->saveSlitPlacement(Slit::TopLeft);
else if (! strncasecmp(value.addr, "CenterLeft", value.size))
screen->saveSlitPlacement(Slit::CenterLeft);
else if (! strncasecmp(value.addr, "BottomLeft", value.size))
screen->saveSlitPlacement(Slit::BottomLeft);
else if (! strncasecmp(value.addr, "TopCenter", value.size))
screen->saveSlitPlacement(Slit::TopCenter);
else if (! strncasecmp(value.addr, "BottomCenter", value.size))
screen->saveSlitPlacement(Slit::BottomCenter);
else if (! strncasecmp(value.addr, "TopRight", value.size))
screen->saveSlitPlacement(Slit::TopRight);
else if (! strncasecmp(value.addr, "BottomRight", value.size))
screen->saveSlitPlacement(Slit::BottomRight);
}
sprintf(name_lookup, "session.screen%d.slit.direction", screen_number);
sprintf(class_lookup, "Session.Screen%d.Slit.Direction", screen_number);
screen->saveSlitDirection(Slit::Vertical);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
! strncasecmp(value.addr, "Horizontal", value.size)) {
screen->saveSlitDirection(Slit::Horizontal);
}
sprintf(name_lookup, "session.screen%d.slit.onTop", screen_number);
sprintf(class_lookup, "Session.Screen%d.Slit.OnTop", screen_number);
screen->saveSlitOnTop(False);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
! strncasecmp(value.addr, "True", value.size)) {
screen->saveSlitOnTop(True);
}
sprintf(name_lookup, "session.screen%d.slit.autoHide", screen_number);
sprintf(class_lookup, "Session.Screen%d.Slit.AutoHide", screen_number);
screen->saveSlitAutoHide(False);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
! strncasecmp(value.addr, "true", value.size)) {
screen->saveSlitAutoHide(True);
}
#ifdef HAVE_STRFTIME
sprintf(name_lookup, "session.screen%d.strftimeFormat", screen_number);
sprintf(class_lookup, "Session.Screen%d.StrftimeFormat", screen_number);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value)) {
screen->saveStrftimeFormat(value.addr);
} else {
screen->saveStrftimeFormat("%I:%M %p");
}
#else // HAVE_STRFTIME
sprintf(name_lookup, "session.screen%d.dateFormat", screen_number);
sprintf(class_lookup, "Session.Screen%d.DateFormat", screen_number);
screen->saveDateFormat(B_AmericanDate);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value)) {
if (! strncasecmp(value.addr, "european", value.size))
screen->saveDateFormat(B_EuropeanDate);
}
sprintf(name_lookup, "session.screen%d.clockFormat", screen_number);
sprintf(class_lookup, "Session.Screen%d.ClockFormat", screen_number);
screen->saveClock24Hour(False);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
sscanf(value.addr, "%d", &int_value) == 1 && int_value == 24) {
screen->saveClock24Hour(True);
}
#endif // HAVE_STRFTIME
sprintf(name_lookup, "session.screen%d.edgeSnapThreshold", screen_number);
sprintf(class_lookup, "Session.Screen%d.EdgeSnapThreshold", screen_number);
if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
&value) &&
sscanf(value.addr, "%d", &int_value) == 1) {
screen->saveEdgeSnapThreshold(int_value);
}
screen->saveImageDither(True);
if (XrmGetResource(database, "session.imageDither", "Session.ImageDither",
&value_type, &value) &&
! strncasecmp("false", value.addr, value.size)) {
screen->saveImageDither(False);
}
screen->saveOpaqueMove(False);
if (XrmGetResource(database, "session.opaqueMove", "Session.OpaqueMove",
&value_type, &value) &&
! strncasecmp("true", value.addr, value.size)) {
screen->saveOpaqueMove(True);
}
XrmDestroyDatabase(database);
}
void Blackbox::reload_rc(void) {
load_rc();
reconfigure();
}
@ -1520,19 +1043,7 @@ void Blackbox::reconfigure(void) {
void Blackbox::real_reconfigure(void) {
XrmDatabase new_blackboxrc = (XrmDatabase) 0;
char *style = new char[resource.style_file.length() + 20];
sprintf(style, "session.styleFile: %s", getStyleFilename());
XrmPutLineResource(&new_blackboxrc, style);
delete [] style;
XrmDatabase old_blackboxrc = XrmGetFileDatabase(rc_file.c_str());
XrmMergeDatabases(new_blackboxrc, &old_blackboxrc);
XrmPutFileDatabase(old_blackboxrc, rc_file.c_str());
if (old_blackboxrc) XrmDestroyDatabase(old_blackboxrc);
load_rc();
std::for_each(menuTimestamps.begin(), menuTimestamps.end(),
PointerAssassin());
@ -1584,6 +1095,7 @@ void Blackbox::real_rereadMenu(void) {
void Blackbox::saveStyleFilename(const string& filename) {
assert(! filename.empty());
resource.style_file = filename;
config.setValue("session.styleFile", resource.style_file);
}

View file

@ -26,7 +26,6 @@
extern "C" {
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#ifdef HAVE_STDIO_H
# include <stdio.h>
@ -50,6 +49,7 @@ extern "C" {
#include "i18n.hh"
#include "BaseDisplay.hh"
#include "Configuration.hh"
#include "Timer.hh"
#define AttribShaded (1l << 0)
@ -144,6 +144,7 @@ private:
BScreen *active_screen;
BlackboxWindow *focused_window;
BTimer *timer;
Configuration config;
bool no_focus, reconfigure_wait, reread_menu_wait;
Time last_time;
@ -195,7 +196,6 @@ private:
void load_rc(void);
void save_rc(void);
void reload_rc(void);
void real_rereadMenu(void);
void real_reconfigure(void);
@ -228,6 +228,7 @@ public:
inline BlackboxWindow *getFocusedWindow(void) { return focused_window; }
inline Configuration *getConfig() { return &config; }
inline const Time &getDoubleClickInterval(void) const
{ return resource.double_click_interval; }
inline const Time &getLastTime(void) const { return last_time; }
@ -261,7 +262,6 @@ public:
void setFocusedWindow(BlackboxWindow *w);
void shutdown(void);
void load_rc(BScreen *screen);
void saveStyleFilename(const std::string& filename);
void addMenuTimestamp(const std::string& filename);
void restart(const char *prog = 0);