From 745e840547b5443ecfb9b6f0a4f14b0d035d59c2 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 31 Dec 2002 19:15:24 +0000 Subject: [PATCH] load config options from the python environment --- scripts/Makefile.am | 2 +- scripts/config.py | 34 ++++++++++++ scripts/globals.py | 39 ++------------ src/bindings.cc | 27 +++++++--- src/bindings.hh | 5 ++ src/frame.cc | 36 +++++++++++++ src/frame.hh | 3 ++ src/openbox.cc | 63 +++++++--------------- src/openbox.hh | 5 +- src/openbox_wrap.cc | 127 ++++++++++++++++++++++++++++++-------------- src/python.cc | 45 ++++++++++++++++ src/python.hh | 6 +++ src/screen.cc | 24 +++++---- src/screen.hh | 5 +- 14 files changed, 274 insertions(+), 147 deletions(-) create mode 100644 scripts/config.py diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 5b55ecae..303ab327 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -1,6 +1,6 @@ scriptdir = $(libdir)/openbox/python MAINTAINERCLEANFILES = Makefile.in -script_DATA = clientmotion.py clicks.py globals.py +script_DATA = clientmotion.py clicks.py globals.py config.py EXTRA_DIST = $(script_DATA) distclean-local: diff --git a/scripts/config.py b/scripts/config.py new file mode 100644 index 00000000..c3c43754 --- /dev/null +++ b/scripts/config.py @@ -0,0 +1,34 @@ +############################################################################# +### Options that can be defined on startup that affect the behavior of ### +### openbox. ### +############################################################################# + +# client_buttons - a list of the modifier(s) and buttons which are grabbed on +# client windows (for interactive move/resize, etc). +# examples: "A-2", "C-A-2", "W-1" +client_buttons = ["A-1", "A-2", "A-3"] + +# theme - the theme used to decorate everything. +theme = "/usr/local/share/openbox/styles/nyz" + + +############################################################################# +### Options that can be modified by the user to change the default hooks' ### +### behaviors. ### +############################################################################# + +# click_focus - '1' if clicking in a client will cause it to focus in the +# default hook functions; else '0'. +click_focus = 0 +# click_raise - '1' if clicking in a client will cause it to raise to the +# top of its stacking layer; else '0'. +click_raise = 0 +# enter_focus - '1' if entering a client window will cause it to focus in the +# default hook functions; else '0'. +enter_focus = 1 +# leave_unfocus - '1' if leaving a client window will cause it to unfocus in +# the default hook functions; else '0'. +leave_unfocus = 1 + + +print "Loaded config.py" diff --git a/scripts/globals.py b/scripts/globals.py index 0a3389ec..450ee8b7 100644 --- a/scripts/globals.py +++ b/scripts/globals.py @@ -1,35 +1,3 @@ -############################################################################# -### Options that can be defined on startup that affect the behavior of ### -### openbox. ### -############################################################################# - -# client_buttons - a list of the modifier(s) and buttons which are grabbed on -# client windows (for interactive move/resize, etc) -# examples: "A-2", "C-A-2", "W-1" -client_buttons = ["A-1", "A-2", "A-3"] - - - -############################################################################# -### Options that can be modified by the user to change the default hooks' ### -### behaviors. ### -############################################################################# - -# click_focus - true if clicking in a client will cause it to focus in the -# default hook functions -click_focus = 0 -# click_raise - true if clicking in a client will cause it to raise to the -# top of its stacking layer -click_raise = 0 -# enter_focus - true if entering a client window will cause it to focus in the -# default hook functions -enter_focus = 1 -# leave_unfocus - true if leaving a client window will cause it to unfocus in -# the default hook functions -leave_unfocus = 1 - - - ############################################################################# ### Variables defined for other scripts to use. ### ############################################################################# @@ -37,11 +5,10 @@ leave_unfocus = 1 # openbox - pointer to the current Openbox instance openbox = Openbox_instance() -# screen - list of all screens in the current openbox instance -screen = [] +# screens - list of all screens in the current openbox instance +screens = [] for i in range(Openbox_screenCount(openbox)): - screen.append(Openbox_screen(openbox, i)) - + screens.append(Openbox_screen(openbox, i)) print "Loaded globals.py" diff --git a/src/bindings.cc b/src/bindings.cc index ef14d585..42a92591 100644 --- a/src/bindings.cc +++ b/src/bindings.cc @@ -134,8 +134,13 @@ BindingTree *OBBindings::buildtree(const StringVect &keylist, int id) const OBBindings::OBBindings() - : _curpos(&_tree), _resetkey(0,0) + : _curpos(&_tree), + _resetkey(0,0), + _timer(Openbox::instance->timerManager(), + (otk::OBTimeoutHandler)reset, this) { + _timer.setTimeout(5000); // chains reset after 5 seconds + setResetKey("C-g"); // set the default reset key } @@ -299,10 +304,11 @@ void OBBindings::grabKeys(bool grab) BindingTree *p = _curpos->first_child; while (p) { - if (grab) + if (grab) { otk::OBDisplay::grabKey(p->binding.key, p->binding.modifiers, root, false, GrabModeAsync, GrabModeAsync, false); + } else otk::OBDisplay::ungrabKey(p->binding.key, p->binding.modifiers, root); @@ -324,22 +330,19 @@ void OBBindings::fire(Window window, unsigned int modifiers, unsigned int key, Time time) { if (key == _resetkey.key && modifiers == _resetkey.modifiers) { - grabKeys(false); - _curpos = &_tree; - grabKeys(true); + reset(this); } else { BindingTree *p = _curpos->first_child; while (p) { if (p->binding.key == key && p->binding.modifiers == modifiers) { if (p->chain) { + _timer.start(); // start/restart the timer grabKeys(false); _curpos = p; grabKeys(true); } else { python_callback_binding(p->id, window, modifiers, key, time); - grabKeys(false); - _curpos = &_tree; - grabKeys(true); + reset(this); } break; } @@ -348,4 +351,12 @@ void OBBindings::fire(Window window, unsigned int modifiers, unsigned int key, } } +void OBBindings::reset(OBBindings *self) +{ + self->_timer.stop(); + self->grabKeys(false); + self->_curpos = &self->_tree; + self->grabKeys(true); +} + } diff --git a/src/bindings.hh b/src/bindings.hh index dde79949..0ae03576 100644 --- a/src/bindings.hh +++ b/src/bindings.hh @@ -7,6 +7,7 @@ */ #include "actions.hh" +#include "otk/timer.hh" #include #include @@ -53,12 +54,16 @@ private: BindingTree *_curpos; // position in the keytree Binding _resetkey; // the key which resets the key chain status + + otk::OBTimer _timer; int find(BindingTree *search) const; bool translate(const std::string &str, Binding &b) const; BindingTree *buildtree(const StringVect &keylist, int id) const; void assimilate(BindingTree *node); + static void reset(OBBindings *self); + public: //! Initializes an OBBinding object OBBindings(); diff --git a/src/frame.cc b/src/frame.cc index 4f466b46..072edc70 100644 --- a/src/frame.cc +++ b/src/frame.cc @@ -56,15 +56,51 @@ OBFrame::OBFrame(OBClient *client, otk::Style *style) _plate.show(); // the other stuff is shown based on decor settings grabClient(); + + grabButtons(true); } OBFrame::~OBFrame() { + grabButtons(false); releaseClient(false); } +void OBFrame::grabButtons(bool grab) +{ + if (grab) { + // grab simple button clicks on the client, but pass them through too + otk::OBDisplay::grabButton(Button1, 0, _plate.window(), true, + ButtonPressMask, GrabModeSync, GrabModeSync, + _plate.window(), None, false); + otk::OBDisplay::grabButton(Button2, 0, _plate.window(), true, + ButtonPressMask, GrabModeSync, GrabModeSync, + _plate.window(), None, false); + otk::OBDisplay::grabButton(Button3, 0, _plate.window(), true, + ButtonPressMask, GrabModeSync, GrabModeSync, + _plate.window(), None, false); + otk::OBDisplay::grabButton(Button4, 0, _plate.window(), true, + ButtonPressMask, GrabModeSync, GrabModeSync, + _plate.window(), None, false); + otk::OBDisplay::grabButton(Button5, 0, _plate.window(), true, + ButtonPressMask, GrabModeSync, GrabModeSync, + _plate.window(), None, false); + } else { + } + + // grab any requested buttons on the entire frame + if (grab) { + + otk::OBDisplay::grabButton(Button1, 0, _plate.window(), true, + ButtonPressMask, GrabModeSync, GrabModeSync, + _plate.window(), None, false); + } else { + } +} + + void OBFrame::setTitle(const std::string &text) { _label.setText(text); diff --git a/src/frame.hh b/src/frame.hh index ab1e1b03..7313c3a1 100644 --- a/src/frame.hh +++ b/src/frame.hh @@ -80,6 +80,9 @@ private: //! Shape the frame window to the client window void adjustShape(); + //! Grabs or ungrabs buttons on the frame + void grabButtons(bool grab); + public: //! Constructs an OBFrame object, and reparents the client to itself /*! diff --git a/src/openbox.cc b/src/openbox.cc index 474ba029..01316d79 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -10,6 +10,7 @@ #include "screen.hh" #include "actions.hh" #include "bindings.hh" +#include "python.hh" #include "otk/property.hh" #include "otk/display.hh" #include "otk/assassin.hh" @@ -43,13 +44,6 @@ extern "C" { # include #endif // HAVE_SYS_SELECT_H -#include - -// The initializer in openbox_wrap.cc -extern void init_openbox(void); -// The initializer in otk_wrap.cc -extern void init_otk(void); - #include "gettext.h" #define _(str) gettext(str) } @@ -83,17 +77,6 @@ void Openbox::signalHandler(int signal) } -static void runPython(const char *s) { - FILE *rcpyfd = fopen(s, "r"); - if (!rcpyfd) { - printf("failed to load python file %s\n", s); - } else { - PyRun_SimpleFile(rcpyfd, const_cast(s)); - fclose(rcpyfd); - } -} - - Openbox::Openbox(int argc, char **argv) : otk::OtkEventDispatcher(), otk::OtkEventHandler() @@ -114,20 +97,6 @@ Openbox::Openbox(int argc, char **argv) parseCommandLine(argc, argv); - // TEMPORARY: using the xrdb rc3 - _config.setFile(_rcfilepath); - if (!_config.load()) { - printf("failed to load rc file %s\n", _config.file().c_str()); - ::exit(2); - } - std::string s; - _config.getValue("session.styleFile", s); - _config.setFile(s); - if (!_config.load()) { - printf("failed to load style %s\n", _config.file().c_str()); - ::exit(2); - } - // open the X display (and gets some info about it, and its screens) otk::OBDisplay::initialize(_displayreq); assert(otk::OBDisplay::display); @@ -159,9 +128,13 @@ Openbox::Openbox(int argc, char **argv) _cursors.ul_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ul_angle); _cursors.ur_angle = XCreateFontCursor(otk::OBDisplay::display, XC_ur_angle); + // start up python and load config values + python_init(argv[0]); + python_exec(SCRIPTDIR"/config.py"); // load openbox config values + // initialize all the screens OBScreen *screen; - screen = new OBScreen(0, _config); + screen = new OBScreen(0); if (screen->managed()) { _screens.push_back(screen); // XXX: "change to" the first workspace on the screen to initialize stuff @@ -173,21 +146,16 @@ Openbox::Openbox(int argc, char **argv) ::exit(1); } - // start up python and run the user's startup script - Py_SetProgramName(argv[0]); - Py_Initialize(); - init_otk(); - init_openbox(); - PyRun_SimpleString("from _otk import *; from _openbox import *;"); - - runPython(SCRIPTDIR"/globals.py"); // create/set global vars - runPython(SCRIPTDIR"/clientmotion.py"); // moving and resizing clients - runPython(SCRIPTDIR"/clicks.py"); // titlebar/root clicks and dblclicks - runPython(_scriptfilepath.c_str()); + // run all of the python scripts, including the user's + python_exec(SCRIPTDIR"/globals.py"); // create/set global vars + python_exec(SCRIPTDIR"/clientmotion.py"); // moving and resizing clients + python_exec(SCRIPTDIR"/clicks.py"); // titlebar/root clicks and dblclicks + python_exec(_scriptfilepath.c_str()); ScreenList::iterator it, end = _screens.end(); - for (it = _screens.begin(); it != end; ++it) + for (it = _screens.begin(); it != end; ++it) { (*it)->manageExisting(); + } // grab any keys set up before the screens existed _bindings->grabKeys(true); @@ -357,5 +325,10 @@ void Openbox::setFocusedClient(OBClient *c) } } + +bool Openbox::getConfigString(const char *name, std::string *value) { + return python_get_string(name, value); +} + } diff --git a/src/openbox.hh b/src/openbox.hh index d64068f1..b5956e46 100644 --- a/src/openbox.hh +++ b/src/openbox.hh @@ -137,9 +137,6 @@ private: //! When set to true, the Openbox::eventLoop function will stop and return bool _doshutdown; - //! The configuration of the application. TEMPORARY - otk::Configuration _config; - //! The client with input focus /*! Updated by the clients themselves. @@ -244,6 +241,8 @@ public: manager can be destroyed. */ inline void shutdown() { _doshutdown = true; } + + bool getConfigString(const char *name, std::string *value); }; } diff --git a/src/openbox_wrap.cc b/src/openbox_wrap.cc index 8539963c..587e1abb 100644 --- a/src/openbox_wrap.cc +++ b/src/openbox_wrap.cc @@ -656,20 +656,20 @@ SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) { #define SWIGTYPE_p_otk__Strut swig_types[8] #define SWIGTYPE_p_XShapeEvent swig_types[9] #define SWIGTYPE_p_XConfigureRequestEvent swig_types[10] -#define SWIGTYPE_p_otk__OtkEventHandler swig_types[11] -#define SWIGTYPE_p_otk__Rect swig_types[12] -#define SWIGTYPE_p_ob__OBWidget swig_types[13] -#define SWIGTYPE_p_XFocusChangeEvent swig_types[14] -#define SWIGTYPE_p_XClientMessageEvent swig_types[15] -#define SWIGTYPE_p_otk__OBProperty swig_types[16] -#define SWIGTYPE_p_otk__OtkEventDispatcher swig_types[17] -#define SWIGTYPE_p_XPropertyEvent swig_types[18] -#define SWIGTYPE_p_XDestroyWindowEvent swig_types[19] -#define SWIGTYPE_p_otk__BImageControl swig_types[20] -#define SWIGTYPE_p_PyObject swig_types[21] -#define SWIGTYPE_p_ob__OBBindings swig_types[22] -#define SWIGTYPE_p_ob__MwmHints swig_types[23] -#define SWIGTYPE_p_otk__Configuration swig_types[24] +#define SWIGTYPE_p_std__string swig_types[11] +#define SWIGTYPE_p_otk__OtkEventHandler swig_types[12] +#define SWIGTYPE_p_otk__Rect swig_types[13] +#define SWIGTYPE_p_ob__OBWidget swig_types[14] +#define SWIGTYPE_p_XFocusChangeEvent swig_types[15] +#define SWIGTYPE_p_XClientMessageEvent swig_types[16] +#define SWIGTYPE_p_otk__OBProperty swig_types[17] +#define SWIGTYPE_p_otk__OtkEventDispatcher swig_types[18] +#define SWIGTYPE_p_XPropertyEvent swig_types[19] +#define SWIGTYPE_p_XDestroyWindowEvent swig_types[20] +#define SWIGTYPE_p_otk__BImageControl swig_types[21] +#define SWIGTYPE_p_PyObject swig_types[22] +#define SWIGTYPE_p_ob__OBBindings swig_types[23] +#define SWIGTYPE_p_ob__MwmHints swig_types[24] #define SWIGTYPE_p_XUnmapEvent swig_types[25] static swig_type_info *swig_types[27]; @@ -1319,6 +1319,27 @@ static PyObject *_wrap_Openbox_shutdown(PyObject *self, PyObject *args) { } +static PyObject *_wrap_Openbox_getConfigString(PyObject *self, PyObject *args) { + PyObject *resultobj; + ob::Openbox *arg1 = (ob::Openbox *) 0 ; + char *arg2 ; + std::string *arg3 = (std::string *) 0 ; + bool result; + PyObject * obj0 = 0 ; + PyObject * obj2 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"OsO:Openbox_getConfigString",&obj0,&arg2,&obj2)) goto fail; + if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__Openbox,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + if ((SWIG_ConvertPtr(obj2,(void **) &arg3, SWIGTYPE_p_std__string,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + result = (bool)(arg1)->getConfigString((char const *)arg2,arg3); + + resultobj = PyInt_FromLong((long)result); + return resultobj; + fail: + return NULL; +} + + static PyObject * Openbox_swigregister(PyObject *self, PyObject *args) { PyObject *obj; if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL; @@ -1487,28 +1508,6 @@ static PyObject *_wrap_OBScreen_removeStrut(PyObject *self, PyObject *args) { } -static PyObject *_wrap_OBScreen_loadStyle(PyObject *self, PyObject *args) { - PyObject *resultobj; - ob::OBScreen *arg1 = (ob::OBScreen *) 0 ; - otk::Configuration *arg2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - - if(!PyArg_ParseTuple(args,(char *)"OO:OBScreen_loadStyle",&obj0,&obj1)) goto fail; - if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_ob__OBScreen,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; - if ((SWIG_ConvertPtr(obj1,(void **) &arg2, SWIGTYPE_p_otk__Configuration,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; - if (arg2 == NULL) { - PyErr_SetString(PyExc_TypeError,"null reference"); SWIG_fail; - } - (arg1)->loadStyle((otk::Configuration const &)*arg2); - - Py_INCREF(Py_None); resultobj = Py_None; - return resultobj; - fail: - return NULL; -} - - static PyObject *_wrap_OBScreen_manageExisting(PyObject *self, PyObject *args) { PyObject *resultobj; ob::OBScreen *arg1 = (ob::OBScreen *) 0 ; @@ -2501,6 +2500,53 @@ static PyObject * OBClient_swigregister(PyObject *self, PyObject *args) { Py_INCREF(obj); return Py_BuildValue((char *)""); } +static PyObject *_wrap_python_init(PyObject *self, PyObject *args) { + PyObject *resultobj; + char *arg1 ; + + if(!PyArg_ParseTuple(args,(char *)"s:python_init",&arg1)) goto fail; + ob::python_init(arg1); + + Py_INCREF(Py_None); resultobj = Py_None; + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_python_exec(PyObject *self, PyObject *args) { + PyObject *resultobj; + char *arg1 ; + bool result; + + if(!PyArg_ParseTuple(args,(char *)"s:python_exec",&arg1)) goto fail; + result = (bool)ob::python_exec((char const *)arg1); + + resultobj = PyInt_FromLong((long)result); + return resultobj; + fail: + return NULL; +} + + +static PyObject *_wrap_python_get_string(PyObject *self, PyObject *args) { + PyObject *resultobj; + char *arg1 ; + std::string *arg2 = (std::string *) 0 ; + bool result; + PyObject * obj1 = 0 ; + + if(!PyArg_ParseTuple(args,(char *)"sO:python_get_string",&arg1,&obj1)) goto fail; + if ((SWIG_ConvertPtr(obj1,(void **) &arg2, SWIGTYPE_p_std__string,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; + result = (bool)ob::python_get_string((char const *)arg1,arg2); + + resultobj = PyInt_FromLong((long)result); + return resultobj; + fail: + return NULL; +} + + static PyObject *_wrap_register(PyObject *self, PyObject *args) { PyObject *resultobj; int arg1 ; @@ -2703,6 +2749,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Openbox_setFocusedClient", _wrap_Openbox_setFocusedClient, METH_VARARGS }, { (char *)"Openbox_focusedScreen", _wrap_Openbox_focusedScreen, METH_VARARGS }, { (char *)"Openbox_shutdown", _wrap_Openbox_shutdown, METH_VARARGS }, + { (char *)"Openbox_getConfigString", _wrap_Openbox_getConfigString, METH_VARARGS }, { (char *)"Openbox_swigregister", Openbox_swigregister, METH_VARARGS }, { (char *)"OBScreen_client", _wrap_OBScreen_client, METH_VARARGS }, { (char *)"OBScreen_clientCount", _wrap_OBScreen_clientCount, METH_VARARGS }, @@ -2713,7 +2760,6 @@ static PyMethodDef SwigMethods[] = { { (char *)"OBScreen_focuswindow", _wrap_OBScreen_focuswindow, METH_VARARGS }, { (char *)"OBScreen_addStrut", _wrap_OBScreen_addStrut, METH_VARARGS }, { (char *)"OBScreen_removeStrut", _wrap_OBScreen_removeStrut, METH_VARARGS }, - { (char *)"OBScreen_loadStyle", _wrap_OBScreen_loadStyle, METH_VARARGS }, { (char *)"OBScreen_manageExisting", _wrap_OBScreen_manageExisting, METH_VARARGS }, { (char *)"OBScreen_manageWindow", _wrap_OBScreen_manageWindow, METH_VARARGS }, { (char *)"OBScreen_unmanageWindow", _wrap_OBScreen_unmanageWindow, METH_VARARGS }, @@ -2769,6 +2815,9 @@ static PyMethodDef SwigMethods[] = { { (char *)"OBClient_destroyHandler", _wrap_OBClient_destroyHandler, METH_VARARGS }, { (char *)"OBClient_reparentHandler", _wrap_OBClient_reparentHandler, METH_VARARGS }, { (char *)"OBClient_swigregister", OBClient_swigregister, METH_VARARGS }, + { (char *)"python_init", _wrap_python_init, METH_VARARGS }, + { (char *)"python_exec", _wrap_python_exec, METH_VARARGS }, + { (char *)"python_get_string", _wrap_python_get_string, METH_VARARGS }, { (char *)"register", _wrap_register, METH_VARARGS }, { (char *)"preregister", _wrap_preregister, METH_VARARGS }, { (char *)"unregister", _wrap_unregister, METH_VARARGS }, @@ -2807,6 +2856,7 @@ static swig_type_info _swigt__p_ob__Openbox[] = {{"_p_ob__Openbox", 0, "ob::Open static swig_type_info _swigt__p_otk__Strut[] = {{"_p_otk__Strut", 0, "otk::Strut *", 0},{"_p_otk__Strut"},{0}}; static swig_type_info _swigt__p_XShapeEvent[] = {{"_p_XShapeEvent", 0, "XShapeEvent *", 0},{"_p_XShapeEvent"},{0}}; static swig_type_info _swigt__p_XConfigureRequestEvent[] = {{"_p_XConfigureRequestEvent", 0, "XConfigureRequestEvent *", 0},{"_p_XConfigureRequestEvent"},{0}}; +static swig_type_info _swigt__p_std__string[] = {{"_p_std__string", 0, "std::string *", 0},{"_p_std__string"},{0}}; static swig_type_info _swigt__p_otk__OtkEventHandler[] = {{"_p_otk__OtkEventHandler", 0, "otk::OtkEventHandler *", 0},{"_p_otk__OtkEventHandler"},{"_p_ob__Openbox", _p_ob__OpenboxTo_p_otk__OtkEventHandler},{"_p_ob__OBClient", _p_ob__OBClientTo_p_otk__OtkEventHandler},{0}}; static swig_type_info _swigt__p_otk__Rect[] = {{"_p_otk__Rect", 0, "otk::Rect *", 0},{"_p_otk__Rect"},{0}}; static swig_type_info _swigt__p_ob__OBWidget[] = {{"_p_ob__OBWidget", 0, "ob::OBWidget *", 0},{"_p_ob__OBWidget"},{"_p_ob__OBClient", _p_ob__OBClientTo_p_ob__OBWidget},{0}}; @@ -2820,7 +2870,6 @@ static swig_type_info _swigt__p_otk__BImageControl[] = {{"_p_otk__BImageControl" static swig_type_info _swigt__p_PyObject[] = {{"_p_PyObject", 0, "PyObject *", 0},{"_p_PyObject"},{0}}; static swig_type_info _swigt__p_ob__OBBindings[] = {{"_p_ob__OBBindings", 0, "ob::OBBindings *", 0},{"_p_ob__OBBindings"},{0}}; static swig_type_info _swigt__p_ob__MwmHints[] = {{"_p_ob__MwmHints", 0, "ob::MwmHints *", 0},{"_p_ob__MwmHints"},{0}}; -static swig_type_info _swigt__p_otk__Configuration[] = {{"_p_otk__Configuration", 0, "otk::Configuration *", 0},{"_p_otk__Configuration"},{0}}; static swig_type_info _swigt__p_XUnmapEvent[] = {{"_p_XUnmapEvent", 0, "XUnmapEvent *", 0},{"_p_XUnmapEvent"},{0}}; static swig_type_info *swig_types_initial[] = { @@ -2835,6 +2884,7 @@ _swigt__p_ob__Openbox, _swigt__p_otk__Strut, _swigt__p_XShapeEvent, _swigt__p_XConfigureRequestEvent, +_swigt__p_std__string, _swigt__p_otk__OtkEventHandler, _swigt__p_otk__Rect, _swigt__p_ob__OBWidget, @@ -2848,7 +2898,6 @@ _swigt__p_otk__BImageControl, _swigt__p_PyObject, _swigt__p_ob__OBBindings, _swigt__p_ob__MwmHints, -_swigt__p_otk__Configuration, _swigt__p_XUnmapEvent, 0 }; diff --git a/src/python.cc b/src/python.cc index dbe35f5d..ddd10d0f 100644 --- a/src/python.cc +++ b/src/python.cc @@ -7,6 +7,15 @@ #include #include +extern "C" { +#include + +// The initializer in openbox_wrap.cc +extern void init_openbox(void); +// The initializer in otk_wrap.cc +extern void init_otk(void); +} + namespace ob { typedef std::vector FunctionList; @@ -14,6 +23,42 @@ typedef std::vector FunctionList; static FunctionList callbacks[OBActions::NUM_ACTIONS]; static FunctionList bindfuncs; +static PyObject *obdict; + +void python_init(char *argv0) +{ + Py_SetProgramName(argv0); + Py_Initialize(); + init_otk(); + init_openbox(); + PyRun_SimpleString("from _otk import *; from _openbox import *;"); + + // set up access to the python global variables + PyObject *obmodule = PyImport_AddModule("__main__"); + obdict = PyModule_GetDict(obmodule); +} + +bool python_exec(const char *file) { + FILE *rcpyfd = fopen(file, "r"); + if (!rcpyfd) { + printf("failed to load python file %s\n", file); + return false; + } + PyRun_SimpleFile(rcpyfd, const_cast(file)); + fclose(rcpyfd); + return true; +} + +bool python_get_string(const char *name, std::string *value) +{ + PyObject *val = PyDict_GetItemString(obdict, const_cast(name)); + if (!val) return false; + + *value = PyString_AsString(val); + return true; +} + + bool python_register(int action, PyObject *callback) { if (action < 0 || action >= OBActions::NUM_ACTIONS || diff --git a/src/python.hh b/src/python.hh index a654152b..7566f817 100644 --- a/src/python.hh +++ b/src/python.hh @@ -14,8 +14,14 @@ extern "C" { #include } +#include + namespace ob { +void python_init(char *argv0); +bool python_exec(const char *file); +bool python_get_string(const char *name, std::string *value); + //! Add a python callback funtion to the back of the hook list /*! Registering functions for KeyPress events is pointless. Use python_bind diff --git a/src/screen.cc b/src/screen.cc index 61869a17..80b9083d 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -37,7 +37,7 @@ static int anotherWMRunning(Display *display, XErrorEvent *) { namespace ob { -OBScreen::OBScreen(int screen, const otk::Configuration &config) +OBScreen::OBScreen(int screen) : _number(screen), _root(screen) { @@ -74,8 +74,18 @@ OBScreen::OBScreen(int screen, const otk::Configuration &config) // initialize the screen's style _style.setImageControl(_image_control); - _style.load(config); - + std::string stylepath; + Openbox::instance->getConfigString("theme", &stylepath); + otk::Configuration sconfig(false); + sconfig.setFile(otk::expandTilde(stylepath)); + 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); // Set the netwm atoms for geomtery and viewport unsigned long geometry[] = { _info->width(), @@ -323,14 +333,6 @@ void OBScreen::setWorkArea() { } -void OBScreen::loadStyle(const otk::Configuration &config) -{ - _style.load(config); - - // XXX: make stuff redraw! -} - - void OBScreen::manageWindow(Window window) { OBClient *client = 0; diff --git a/src/screen.hh b/src/screen.hh index 37f22d88..14e81111 100644 --- a/src/screen.hh +++ b/src/screen.hh @@ -100,7 +100,7 @@ private: public: #ifndef SWIG //! Constructs a new OBScreen object - OBScreen(int screen, const otk::Configuration &config); + OBScreen(int screen); //! Destroys the OBScreen object virtual ~OBScreen(); #endif @@ -125,9 +125,6 @@ public: //! Removes a window's strut from the screen's list of reserved spaces void removeStrut(otk::Strut *strut); - //! Loads a new style on the screen - void loadStyle(const otk::Configuration &config); - //! Manage any pre-existing windows on the screen void manageExisting(); //! Manage a client window -- 2.45.2