summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-02-19 19:28:11 +0000
committerDana Jansens <danakj@orodu.net>2003-02-19 19:28:11 +0000
commitfeaf3ac4e5847d27e3747b09e7443915afa97b0b (patch)
tree6548af5ed3f15b15b2d3e4a66a2b9795b0a4e18b /src
parent1dac42d9ed074bcd44f9d1016b0971ae473cc2eb (diff)
time to refactor shit hard
Diffstat (limited to 'src')
-rw-r--r--src/actions.cc6
-rw-r--r--src/config.cc67
-rw-r--r--src/config.hh25
-rw-r--r--src/frame.cc4
-rw-r--r--src/openbox.cc64
-rw-r--r--src/openbox.hh17
-rw-r--r--src/python.cc75
-rw-r--r--src/python.hh5
-rw-r--r--src/screen.cc5
-rw-r--r--src/screen.hh7
10 files changed, 129 insertions, 146 deletions
diff --git a/src/actions.cc b/src/actions.cc
index 9659b2f0..c629006a 100644
--- a/src/actions.cc
+++ b/src/actions.cc
@@ -145,7 +145,8 @@ void Actions::buttonReleaseHandler(const XButtonEvent &e)
data.action = MouseAction::Click;
openbox->bindings()->fireButton(&data);
- long dblclick = openbox->screen(screen)->config().double_click_delay;
+ long dblclick = 0;
+ python_get_long("double_click_delay", &dblclick);
if (e.time - _release.time < (unsigned)dblclick &&
_release.win == e.window && _release.button == e.button) {
@@ -303,7 +304,8 @@ void Actions::motionHandler(const XMotionEvent &e)
if (!_dragging) {
int dx = x_root - _press.pos.x();
int dy = y_root - _press.pos.y();
- long threshold = openbox->screen(screen)->config().drag_threshold;
+ long threshold = 0;
+ python_get_long("drag_threshold", &threshold);
if (!(std::abs(dx) >= threshold || std::abs(dy) >= threshold))
return; // not at the threshold yet
}
diff --git a/src/config.cc b/src/config.cc
index 04728de2..5c6ddfe9 100644
--- a/src/config.cc
+++ b/src/config.cc
@@ -2,70 +2,7 @@
#include "config.h"
-#include "config.hh"
-#include "otk/screeninfo.hh"
-#include "otk/renderstyle.hh"
-#include "otk/util.hh"
-#include "otk/property.hh"
-#include "otk/display.hh"
-
-extern "C" {
-#include <Python.h>
-
-#include "gettext.h"
-#define _(str) gettext(str)
-}
-
-#include <cstring>
-
-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;
-
- std::string temp(PyString_AsString(val), PyString_Size(val));
- *value = temp;
- 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;
-}
-
-void Config::load()
-{
- const otk::ScreenInfo *info = otk::display->screenInfo(_screen);
- Window root = info->rootWindow();
-
- // set up access to the python global variables
- PyObject *obmodule = PyImport_ImportModule("config");
- obdict = PyModule_GetDict(obmodule);
- Py_DECREF(obmodule);
-
+/*
python_get_stringlist("DESKTOP_NAMES", &desktop_names);
python_get_string("THEME", &theme);
@@ -121,4 +58,4 @@ Config::~Config()
{
}
-}
+*/
diff --git a/src/config.hh b/src/config.hh
index 6cbbaacd..4f664c19 100644
--- a/src/config.hh
+++ b/src/config.hh
@@ -3,33 +3,12 @@
#define __config_hh
/*! @file config.hh
- @brief The Config class contains configuration options set by the user's
- scripts
+ @brief The Config class contains functions for accessing config variables
+ in the scripts.
*/
-#include "otk/ustring.hh"
-
-#include <vector>
-
namespace ob {
-class Config {
- int _screen;
-
-public:
- std::vector<otk::ustring> desktop_names;
- otk::ustring theme;
- otk::ustring titlebar_layout;
- long double_click_delay;
- long drag_threshold;
- long num_desktops;
-
- Config(int screen);
- ~Config();
-
- void load();
-};
-
}
#endif // __config_hh
diff --git a/src/frame.cc b/src/frame.cc
index 94384b3d..4e77d106 100644
--- a/src/frame.cc
+++ b/src/frame.cc
@@ -9,6 +9,7 @@ extern "C" {
}
#include "frame.hh"
+#include "config.hh"
#include "openbox.hh"
#include "otk/display.hh"
#include "otk/surface.hh"
@@ -99,7 +100,8 @@ Frame::Frame(Client *client)
applyStyle(*otk::RenderStyle::style(_client->screen()));
- _layout = openbox->screen(_client->screen())->config().titlebar_layout;
+ _layout = "ITMC";
+ python_get_string("titlebar_layout", &_layout);
// register all of the windows with the event dispatcher
Window *w = allWindows();
diff --git a/src/openbox.cc b/src/openbox.cc
index 951d4ab4..d2ce85fd 100644
--- a/src/openbox.cc
+++ b/src/openbox.cc
@@ -134,6 +134,7 @@ Openbox::Openbox(int argc, char **argv)
// initialize all the screens
_focused_screen = 0;
+ _managed_count = 0;
for (int i = 0, max = ScreenCount(**otk::display); i < max; ++i) {
Screen *screen;
@@ -148,77 +149,52 @@ Openbox::Openbox(int argc, char **argv)
_screens.push_back(screen);
if (!_focused_screen) // set this to the first screen managed
_focused_screen = screen;
+ _managed_count++;
} else {
delete screen;
_screens.push_back(0);
}
}
- if (_screens.empty()) {
+ if (!_managed_count) {
printf(_("No screens were found without a window manager. Exiting.\n"));
::exit(1);
}
assert(_focused_screen);
- ScreenList::iterator it, end = _screens.end();
-
- // run the user's script or the system defaults if that fails
- bool pyerr, doretry;
- do {
- // initialize scripting
- python_init(argv[0]);
-
- // load all of the screens' configs here so we have a theme set if
- // we decide to show the dialog below
- for (it = _screens.begin(); it != end; ++it)
- (*it)->config().load(); // load the defaults from config.py
-
- pyerr = doretry = false;
-
- // reset all the python stuff
- _bindings->removeAllKeys();
- _bindings->removeAllButtons();
- _bindings->removeAllEvents();
-
- int ret = python_exec(_scriptfilepath.c_str());
- if (ret == 2)
- pyerr = true;
-
- if (ret) {
- // reset all the python stuff
- _bindings->removeAllKeys();
- _bindings->removeAllButtons();
- _bindings->removeAllEvents();
-
- if (python_exec(SCRIPTDIR"/defaults.py")) // system default bahaviors
- pyerr = true;
- }
+ // initialize scripting
+ python_init(argv[0]);
- if (pyerr) {
+ // load the theme XXX TEMP SHIT
+ otk::RenderStyle::setStyle(0, "");
+
+ int ret = python_exec(_scriptfilepath.c_str());
+ if (ret == 2) {
std::string msg;
msg += _("An error occured while executing the python scripts.");
msg += "\n\n";
msg += _("See the exact error message in Openbox's output for details.");
otk::MessageDialog dia(this, _("Python Error"), msg);
otk::DialogButton ok(_("Okay"), true);
- otk::DialogButton retry(_("Retry"));
+ otk::DialogButton retry(_("Restart"));
dia.addButton(ok);
dia.addButton(retry);
dia.show();
dia.focus();
const otk::DialogButton &res = dia.run();
if (res == retry) {
- doretry = true;
- python_destroy(); // kill all the python modules so they reinit right
+ _restart = _shutdown = true;
+ return;
}
- }
- } while (pyerr && doretry);
-
- for (it = _screens.begin(); it != end; ++it) {
- (*it)->config().load(); // load the config as the scripts may change it
- (*it)->manageExisting();
}
+
+ if (ret)
+ python_exec(SCRIPTDIR"/defaults.py"); // system default bahaviors
+
+ ScreenList::iterator it, end = _screens.end();
+ for (it = _screens.begin(); it != end; ++it)
+ if (*it) (*it)->manageExisting();
// grab any keys set up before the screens existed
//_bindings->grabKeys(true);
diff --git a/src/openbox.hh b/src/openbox.hh
index eb3914aa..460caa0c 100644
--- a/src/openbox.hh
+++ b/src/openbox.hh
@@ -102,6 +102,9 @@ private:
//! A list of all the managed screens
ScreenList _screens;
+
+ //! The number of managed screens
+ int _managed_count;
//! The action interface through which all user-available actions occur
Actions *_actions;
@@ -175,10 +178,22 @@ public:
*/
inline Screen *screen(int num) {
assert(num >= 0); assert(num < (signed)ScreenCount(**otk::display));
- if (num >= (signed)_screens.size()) return 0;
+ if (num < 0 || num >= (signed)_screens.size()) return 0;
return _screens[num];
}
+ inline int managedScreenCount() const { return _managed_count; }
+
+ inline Screen *managedScreen(int num) {
+ assert(num >= 0); assert(num < _managed_count);
+ if (num < 0 || num >= _managed_count) return 0;
+ ScreenList::iterator it, end = _screens.end();
+ int i = -1;
+ for (it = _screens.begin(); it != end; ++it)
+ if (*it && ++i == num)
+ return *it;
+ }
+
//! Returns the mouse cursors used throughout Openbox
inline const Cursors &cursors() const { return _cursors; }
diff --git a/src/python.cc b/src/python.cc
index 0741f2da..75b7cc13 100644
--- a/src/python.cc
+++ b/src/python.cc
@@ -17,6 +17,8 @@ extern "C" {
namespace ob {
+static PyObject *get = NULL;
+
void python_init(char *argv0)
{
// start the python engine
@@ -28,6 +30,21 @@ void python_init(char *argv0)
PyRun_SimpleString(const_cast<char*>(("sys.path.insert(0, '" +
otk::expandTilde("~/.openbox/python") +
"')").c_str()));
+
+ return;
+ PyObject *obmodule = PyImport_ImportModule("config");
+ if (obmodule == NULL) {
+ PyErr_Print();
+ return;
+ }
+ PyObject *configdict = PyModule_GetDict(obmodule);
+ Py_DECREF(obmodule);
+
+ get = PyDict_GetItemString(configdict, "get");
+ if (get == NULL) {
+ PyErr_Print();
+ return;
+ }
}
void python_destroy()
@@ -63,4 +80,62 @@ int python_exec(const std::string &path)
return ret;
}
+bool python_get_long(const char *name, long *value)
+{
+ return false;
+ if (get == NULL) return false;
+ bool ret = false;
+
+ PyObject *val = PyObject_CallFunction(get, "ss", "openbox", name);
+ if (val == NULL)
+ PyErr_Print();
+ else if (PyInt_Check(val)) {
+ *value = PyInt_AsLong(val);
+ ret = true;
+ } else if (PyLong_Check(val)) {
+ *value = PyLong_AsLong(val);
+ ret = true;
+ }
+ Py_XDECREF(val);
+ return ret;
+}
+
+bool python_get_string(const char *name, otk::ustring *value)
+{
+ return false;
+ if (get == NULL) return false;
+ bool ret = false;
+
+ PyObject *val = PyObject_CallFunction(get, "ss", "openbox", name);
+ if (val == NULL)
+ PyErr_Print();
+ else if (PyString_Check(val)) {
+ *value = std::string(PyString_AsString(val), PyString_Size(val));
+ ret = true;
+ }
+ Py_XDECREF(val);
+ return ret;
+}
+
+bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value)
+{
+ return false;
+ if (get == NULL) return false;
+ bool ret = false;
+
+ PyObject *val = PyObject_CallFunction(get, "ss", "openbox", name);
+ if (val == NULL)
+ PyErr_Print();
+ else if (PyList_Check(val)) {
+ for (int i = 0, end = PyList_Size(val); i < end; ++i) {
+ PyObject *str = PyList_GET_ITEM(val, i);
+ if (PyString_Check(str))
+ value->push_back(std::string(PyString_AsString(str),
+ PyString_Size(str)));
+ }
+ }
+ Py_XDECREF(val);
+ return ret;
+}
+
}
diff --git a/src/python.hh b/src/python.hh
index 6acc538b..c1655503 100644
--- a/src/python.hh
+++ b/src/python.hh
@@ -19,6 +19,7 @@ extern "C" {
#include <string>
#include <vector>
+
namespace ob {
class Client;
@@ -232,6 +233,10 @@ void python_destroy();
//! Returns 0 for success, 1 for failing to open the file, 2 for an exception
int 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);
+
}
diff --git a/src/screen.cc b/src/screen.cc
index ff78e572..16e37df6 100644
--- a/src/screen.cc
+++ b/src/screen.cc
@@ -40,8 +40,7 @@ namespace ob {
Screen::Screen(int screen)
- : _number(screen),
- _config(screen)
+ : _number(screen)
{
assert(screen >= 0); assert(screen < ScreenCount(**otk::display));
_info = otk::display->screenInfo(screen);
@@ -80,7 +79,7 @@ Screen::Screen(int screen)
_desktop = 0;
- changeNumDesktops(1); // set the hint
+ changeNumDesktops(4); // set the hint
changeDesktop(0); // set the hint
// don't start in showing-desktop mode
diff --git a/src/screen.hh b/src/screen.hh
index 2f026083..20ba0a63 100644
--- a/src/screen.hh
+++ b/src/screen.hh
@@ -10,7 +10,6 @@ extern "C" {
#include <X11/Xlib.h>
}
-#include "config.hh"
#include "otk/strut.hh"
#include "otk/rect.hh"
#include "otk/screeninfo.hh"
@@ -67,9 +66,6 @@ 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
RectList _area;
@@ -160,9 +156,6 @@ public:
*/
inline bool managed() const { return _managed; }
- //! Returns the config options set by the user scripts
- Config& config() { return _config; }
-
//! An offscreen window which gets focus when nothing else has it
inline Window focuswindow() const { return _focuswindow; }
//! Returns the desktop being displayed