diff options
| author | Dana Jansens <danakj@orodu.net> | 2003-02-14 03:04:23 +0000 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2003-02-14 03:04:23 +0000 |
| commit | 059bc4dc24b68d637c3608c05344c53c64cc2c4b (patch) | |
| tree | 6772afd49bd8c7ea1cb07d8af631f25a618f5e11 /src | |
| parent | 1431cd19584e750309561e0054fd013d566965cb (diff) | |
add a Config class with config data from the scripts.
set up the functions for loading a style from a file.
use the Config class throughout instead of reading out of the python namespace all the time.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 4 | ||||
| -rw-r--r-- | src/actions.cc | 25 | ||||
| -rw-r--r-- | src/client.cc | 4 | ||||
| -rw-r--r-- | src/config.cc | 72 | ||||
| -rw-r--r-- | src/config.hh | 29 | ||||
| -rw-r--r-- | src/frame.cc | 2 | ||||
| -rw-r--r-- | src/frame.hh | 2 | ||||
| -rw-r--r-- | src/python.cc | 44 | ||||
| -rw-r--r-- | src/python.hh | 4 | ||||
| -rw-r--r-- | src/screen.cc | 27 | ||||
| -rw-r--r-- | src/screen.hh | 10 |
11 files changed, 130 insertions, 93 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 9288490a..107f7355 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,9 +16,9 @@ bin_PROGRAMS= openbox3 openbox3_LDADD=-L../otk -lotk @LIBINTL@ openbox3_LDFLAGS=-export-dynamic openbox3_SOURCES= actions.cc client.cc frame.cc openbox.cc screen.cc \ - main.cc python.cc bindings.cc + main.cc python.cc bindings.cc config.cc noinst_HEADERS= actions.hh bindings.hh client.hh frame.hh openbox.hh \ - python.hh screen.hh + python.hh screen.hh config.hh MAINTAINERCLEANFILES= Makefile.in diff --git a/src/actions.cc b/src/actions.cc index 65931fc6..cefa5778 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -165,12 +165,7 @@ void Actions::buttonReleaseHandler(const XButtonEvent &e) data.action = MouseAction::Click; openbox->bindings()->fireButton(&data); - - // XXX: dont load this every time!!@* - long dblclick; - if (!python_get_long("DOUBLE_CLICK_DELAY", &dblclick)) - dblclick = 300; - + long dblclick = openbox->screen(screen)->config().double_click_delay; if (e.time - _release.time < (unsigned)dblclick && _release.win == e.window && _release.button == e.button) { @@ -318,13 +313,17 @@ void Actions::motionHandler(const XMotionEvent &e) y_root = e.y_root; } + int screen; + Client *c = openbox->findClient(e.window); + if (c) + screen = c->screen(); + else + screen = otk::display->findScreen(e.root)->screen(); + if (!_dragging) { - long threshold; int dx = x_root - _posqueue[0]->pos.x(); int dy = y_root - _posqueue[0]->pos.y(); - // XXX: dont get this from python every time! - if (!python_get_long("DRAG_THRESHOLD", &threshold)) - threshold = 0; + long threshold = openbox->screen(screen)->config().drag_threshold; if (!(std::abs(dx) >= threshold || std::abs(dy) >= threshold)) return; // not at the threshold yet } @@ -337,12 +336,6 @@ void Actions::motionHandler(const XMotionEvent &e) unsigned int state = e.state & (ControlMask | ShiftMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask); unsigned int button = _posqueue[0]->button; - int screen; - Client *c = openbox->findClient(e.window); - if (c) - screen = c->screen(); - else - screen = otk::display->findScreen(e.root)->screen(); MouseData data(screen, c, e.time, state, button, context, MouseAction::Motion, x_root, y_root, _posqueue[0]->pos, _posqueue[0]->clientarea); diff --git a/src/client.cc b/src/client.cc index b3d444ea..bd7f7b83 100644 --- a/src/client.cc +++ b/src/client.cc @@ -446,7 +446,7 @@ void Client::calcLayer() { } c = c->_transient_for; } - if (!fs) { + if (!fs && _fullscreen) { // is one of our transients focused? c = searchFocusTree(this, this); if (c) fs = true; @@ -738,8 +738,6 @@ void Client::updateIcons() i += w * h; assert(i <= num); } - printf("i: %lu\n", i); - printf("bleffffffff\n"); delete [] data; } diff --git a/src/config.cc b/src/config.cc new file mode 100644 index 00000000..6feb94b2 --- /dev/null +++ b/src/config.cc @@ -0,0 +1,72 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +#include "config.h" + +#include "config.hh" + +extern "C" { +#include <Python.h> +} + +namespace ob { + +static PyObject *obdict = NULL; + +bool python_get_long(const char *name, long *value) +{ + PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name)); + if (!(val && PyInt_Check(val))) return false; + + *value = PyInt_AsLong(val); + return true; +} + +bool python_get_string(const char *name, otk::ustring *value) +{ + PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name)); + if (!(val && PyString_Check(val))) return false; + + *value = PyString_AsString(val); + return true; +} + +bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value) +{ + PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name)); + if (!(val && PyList_Check(val))) return false; + + value->clear(); + + for (int i = 0, end = PyList_Size(val); i < end; ++i) { + PyObject *str = PyList_GetItem(val, i); + if (PyString_Check(str)) + value->push_back(PyString_AsString(str)); + } + return true; +} + +Config::Config() +{ + PyRun_SimpleString("import config;"); + // set up access to the python global variables + PyObject *obmodule = PyImport_AddModule("config"); + obdict = PyModule_GetDict(obmodule); + + std::vector<otk::ustring> names; + python_get_stringlist("DESKTOP_NAMES", &names); + + python_get_string("THEME", &theme); + + if (!python_get_string("TITLEBAR_LAYOUT", &titlebar_layout)) + titlebar_layout = "NTIMC"; + printf("LAYOUT %s\n", titlebar_layout.c_str()); + + if (!python_get_long("DOUBLE_CLICK_DELAY", &double_click_delay)) + double_click_delay = 300; + if (!python_get_long("DRAG_THRESHOLD", &drag_threshold)) + drag_threshold = 3; + if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&num_desktops)) + num_desktops = 1; +} + +} diff --git a/src/config.hh b/src/config.hh new file mode 100644 index 00000000..8f8144e3 --- /dev/null +++ b/src/config.hh @@ -0,0 +1,29 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- +#ifndef __config_hh +#define __config_hh + +/*! @file config.hh + @brief The Config class contains configuration options set by the user's + scripts +*/ + +#include "otk/ustring.hh" + +#include <vector> + +namespace ob { + +struct Config { + std::vector<otk::ustring> desktop_names; + otk::ustring theme; + otk::ustring titlebar_layout; + long double_click_delay; + long drag_threshold; + long num_desktops; + + Config(); +}; + +} + +#endif // __config_hh diff --git a/src/frame.cc b/src/frame.cc index c9a83452..edcfdfcd 100644 --- a/src/frame.cc +++ b/src/frame.cc @@ -99,7 +99,7 @@ Frame::Frame(Client *client) applyStyle(*otk::RenderStyle::style(_client->screen())); - _layout = "NDITMC"; + _layout = openbox->screen(_client->screen())->config().titlebar_layout; // register all of the windows with the event dispatcher Window *w = allWindows(); diff --git a/src/frame.hh b/src/frame.hh index df353c7d..45916a1d 100644 --- a/src/frame.hh +++ b/src/frame.hh @@ -95,7 +95,7 @@ private: otk::Surface *_icon_sur; otk::Surface *_close_sur; - std::string _layout; // layout of the titlebar + otk::ustring _layout; // layout of the titlebar bool _max_press; bool _desk_press; diff --git a/src/python.cc b/src/python.cc index 2db948c2..08f8f506 100644 --- a/src/python.cc +++ b/src/python.cc @@ -14,8 +14,6 @@ extern "C" { namespace ob { -static PyObject *obdict = NULL; - void python_init(char *argv0) { // start the python engine @@ -27,15 +25,6 @@ void python_init(char *argv0) PyRun_SimpleString(const_cast<char*>(("sys.path.insert(0, '" + otk::expandTilde("~/.openbox/python") + "')").c_str())); - //PyRun_SimpleString("import ob; import otk; import config;"); - PyRun_SimpleString("import config;"); - // set up convenience global variables - //PyRun_SimpleString("ob.openbox = ob.Openbox_instance()"); - //PyRun_SimpleString("otk.display = otk.Display_instance()"); - - // set up access to the python global variables - PyObject *obmodule = PyImport_AddModule("config"); - obdict = PyModule_GetDict(obmodule); } void python_destroy() @@ -55,37 +44,4 @@ bool python_exec(const std::string &path) return true; } -bool python_get_long(const char *name, long *value) -{ - PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name)); - if (!(val && PyInt_Check(val))) return false; - - *value = PyInt_AsLong(val); - return true; -} - -bool python_get_string(const char *name, otk::ustring *value) -{ - PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name)); - if (!(val && PyString_Check(val))) return false; - - *value = PyString_AsString(val); - return true; -} - -bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value) -{ - PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name)); - if (!(val && PyList_Check(val))) return false; - - value->clear(); - - for (int i = 0, end = PyList_Size(val); i < end; ++i) { - PyObject *str = PyList_GetItem(val, i); - if (PyString_Check(str)) - value->push_back(PyString_AsString(str)); - } - return true; -} - } diff --git a/src/python.hh b/src/python.hh index b6f8ae7c..8c383904 100644 --- a/src/python.hh +++ b/src/python.hh @@ -233,10 +233,6 @@ void python_init(char *argv0); void python_destroy(); bool python_exec(const std::string &path); -bool python_get_long(const char *name, long *value); -bool python_get_string(const char *name, otk::ustring *value); -bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value); - #endif // SWIG } diff --git a/src/screen.cc b/src/screen.cc index 039d8205..17a8c225 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -66,21 +66,8 @@ Screen::Screen(int screen) XDefineCursor(**otk::display, _info->rootWindow(), openbox->cursors().session); - // XXX: initialize the screen's style - /* - otk::ustring stylepath; - python_get_string("THEME", &stylepath); - otk::Configuration sconfig(false); - sconfig.setFile(otk::expandTilde(stylepath.c_str())); - if (!sconfig.load()) { - sconfig.setFile(otk::expandTilde(DEFAULTSTYLE)); - if (!sconfig.load()) { - printf(_("Unable to load default style: %s. Aborting.\n"), DEFAULTSTYLE); - ::exit(1); - } - } - _style.load(sconfig); - */ + // initialize the screen's style + otk::RenderStyle::setStyle(_number, _config.theme); otk::display->renderControl(_number)-> drawRoot(*otk::RenderStyle::style(_number)->rootColor()); @@ -95,19 +82,15 @@ Screen::Screen(int screen) otk::Property::atoms.cardinal, geometry, 2); // Set the net_desktop_names property - std::vector<otk::ustring> names; - python_get_stringlist("DESKTOP_NAMES", &names); otk::Property::set(_info->rootWindow(), otk::Property::atoms.net_desktop_names, - otk::Property::utf8, names); + otk::Property::utf8, _config.desktop_names); // the above set() will cause the updateDesktopNames to fire right away so // we have a list of desktop names _desktop = 0; - - if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&_num_desktops)) - _num_desktops = 1; - changeNumDesktops(_num_desktops); // set the hint + + changeNumDesktops(_config.num_desktops); // set the hint changeDesktop(0); // set the hint diff --git a/src/screen.hh b/src/screen.hh index 4eb81d4a..457ca324 100644 --- a/src/screen.hh +++ b/src/screen.hh @@ -10,6 +10,7 @@ extern "C" { #include <X11/Xlib.h> } +#include "config.hh" #include "otk/strut.hh" #include "otk/rect.hh" #include "otk/screeninfo.hh" @@ -67,6 +68,9 @@ private: //! Information about this screen const otk::ScreenInfo *_info; + + //! Configuration options from the user scripts + Config _config; //! Area usable for placement etc (total - struts), one per desktop, //! plus one extra for windows on all desktops @@ -159,6 +163,10 @@ public: used. */ inline bool managed() const { return _managed; } + + //! Returns the config options set by the user scripts + const Config& config() const { return _config; } + //! An offscreen window which gets focus when nothing else has it inline Window focuswindow() const { return _focuswindow; } //! Returns the desktop being displayed @@ -176,6 +184,8 @@ public: */ const otk::Rect& area(unsigned int desktop) const; + //! Gives the layout of how the desktops are being displayed, the number of + //! rows and columns etc. const DesktopLayout& desktopLayout() const { return _layout; } //! Shows and focuses the desktop and hides all the client windows, or |
