diff options
| author | Dana Jansens <danakj@orodu.net> | 2003-01-25 16:36:55 +0000 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2003-01-25 16:36:55 +0000 |
| commit | 997f94cf8657201ea9d1f2497e4ec4f56342e22f (patch) | |
| tree | 11d43c9fdadb3c23b6903f4d3a794ba40d2e89b6 /src | |
| parent | 02d6362111a9e679b0a2f108d396f105243da4b5 (diff) | |
new/better/cleaner scripting interface
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 2 | ||||
| -rw-r--r-- | src/actions.cc | 25 | ||||
| -rw-r--r-- | src/bindings.cc | 128 | ||||
| -rw-r--r-- | src/bindings.hh | 18 | ||||
| -rw-r--r-- | src/client.cc | 5 | ||||
| -rw-r--r-- | src/openbox.cc | 29 | ||||
| -rw-r--r-- | src/openbox.hh | 19 | ||||
| -rw-r--r-- | src/openbox.i | 2 | ||||
| -rw-r--r-- | src/python.cc | 32 | ||||
| -rw-r--r-- | src/python.hh | 121 | ||||
| -rw-r--r-- | src/screen.cc | 10 | ||||
| -rw-r--r-- | src/widgetbase.hh | 28 |
12 files changed, 214 insertions, 205 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index b15f60b8..e697fc45 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,7 @@ openbox3_SOURCES= actions.cc client.cc frame.cc openbox.cc screen.cc \ openbox_wrap.cc openbox3_LDFLAGS= $(PYTHON_LDFLAGS) -script_DATA = openbox.py +script_DATA = ob.py EXTRA_DIST = $(script_DATA) diff --git a/src/actions.cc b/src/actions.cc index e2999b76..6059f00d 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -88,14 +88,14 @@ void Actions::buttonPressHandler(const XButtonEvent &e) else screen = otk::display->findScreen(e.root)->screen(); MouseData data(screen, c, e.time, state, e.button, w->mcontext(), - MousePress); + MouseAction::Press); openbox->bindings()->fireButton(&data); if (_button) return; // won't count toward CLICK events _button = e.button; - if (w->mcontext() == MC_Window) { + if (w->mcontext() == MouseContext::Window) { /* Because of how events are grabbed on the client window, we can't get ButtonRelease events, so instead we simply manufacture them here, so that @@ -143,7 +143,7 @@ void Actions::buttonReleaseHandler(const XButtonEvent &e) else screen = otk::display->findScreen(e.root)->screen(); MouseData data(screen, c, e.time, state, e.button, w->mcontext(), - MouseClick); + MouseAction::Click); openbox->bindings()->fireButton(&data); @@ -156,7 +156,7 @@ void Actions::buttonReleaseHandler(const XButtonEvent &e) _release.win == e.window && _release.button == e.button) { // run the DOUBLECLICK python hook - data.action = MouseDoubleClick; + data.action = MouseAction::DoubleClick; openbox->bindings()->fireButton(&data); // reset so you cant triple click for 2 doubleclicks @@ -183,7 +183,7 @@ void Actions::enterHandler(const XCrossingEvent &e) screen = c->screen(); else screen = otk::display->findScreen(e.root)->screen(); - EventData data(screen, c, EventEnterWindow, e.state); + EventData data(screen, c, EventAction::EnterWindow, e.state); openbox->bindings()->fireEvent(&data); } @@ -199,14 +199,13 @@ void Actions::leaveHandler(const XCrossingEvent &e) screen = c->screen(); else screen = otk::display->findScreen(e.root)->screen(); - EventData data(screen, c, EventLeaveWindow, e.state); + EventData data(screen, c, EventAction::LeaveWindow, e.state); openbox->bindings()->fireEvent(&data); } void Actions::keyPressHandler(const XKeyEvent &e) { - printf("press\n"); otk::EventHandler::keyPressHandler(e); // kill off the Button1Mask etc, only want the modifiers @@ -214,13 +213,12 @@ void Actions::keyPressHandler(const XKeyEvent &e) Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask); openbox->bindings()-> fireKey(otk::display->findScreen(e.root)->screen(), - state, e.keycode, e.time, EventKeyPress); + state, e.keycode, e.time, KeyAction::Press); } void Actions::keyReleaseHandler(const XKeyEvent &e) { - printf("release\n"); otk::EventHandler::keyReleaseHandler(e); // kill off the Button1Mask etc, only want the modifiers @@ -248,7 +246,7 @@ void Actions::keyReleaseHandler(const XKeyEvent &e) openbox->bindings()-> fireKey(otk::display->findScreen(e.root)->screen(), - state, e.keycode, e.time, EventKeyRelease); + state, e.keycode, e.time, KeyAction::Release); } @@ -301,8 +299,9 @@ void Actions::motionHandler(const XMotionEvent &e) screen = c->screen(); else screen = otk::display->findScreen(e.root)->screen(); - MouseData data(screen, c, e.time, state, button, w->mcontext(), MouseMotion, - x_root, y_root, _posqueue[0]->pos, _posqueue[0]->clientarea); + MouseData data(screen, c, e.time, state, button, w->mcontext(), + MouseAction::Motion, x_root, y_root, + _posqueue[0]->pos, _posqueue[0]->clientarea); openbox->bindings()->fireButton(&data); } @@ -322,7 +321,7 @@ void Actions::xkbHandler(const XkbEvent &e) screen = c->screen(); else screen = openbox->focusedScreen()->number(); - EventData data(screen, c, EventBell, 0); + EventData data(screen, c, EventAction::Bell, 0); openbox->bindings()->fireEvent(&data); break; } diff --git a/src/bindings.cc b/src/bindings.cc index aa9c288d..78fc74cd 100644 --- a/src/bindings.cc +++ b/src/bindings.cc @@ -344,7 +344,9 @@ void Bindings::removeAllKeys() void Bindings::grabKeys(bool grab) { - for (int i = 0; i < openbox->screenCount(); ++i) { + for (int i = 0; i < ScreenCount(**otk::display); ++i) { + Screen *sc = openbox->screen(i); + if (!sc) continue; // not a managed screen Window root = otk::display->screenInfo(i)->rootWindow(); KeyBindingTree *p = _curpos->first_child; @@ -377,18 +379,13 @@ bool Bindings::grabKeyboard(int screen, PyObject *callback) assert(callback); if (_keybgrab_callback) return false; // already grabbed - int i; - for (i = 0; i < openbox->screenCount(); ++i) - if (openbox->screen(screen)->number() == screen) - break; - if (i >= openbox->screenCount()) - return false; // couldn't find the screen.. it's not managed + if (!openbox->screen(screen)) + return false; // the screen is not managed - Window root = otk::display->screenInfo(i)->rootWindow(); + Window root = otk::display->screenInfo(screen)->rootWindow(); if (XGrabKeyboard(**otk::display, root, false, GrabModeAsync, - GrabModeSync, CurrentTime)) + GrabModeAsync, CurrentTime)) return false; - printf("****GRABBED****\n"); _keybgrab_callback = callback; return true; } @@ -400,51 +397,50 @@ void Bindings::ungrabKeyboard() _keybgrab_callback = 0; XUngrabKeyboard(**otk::display, CurrentTime); - printf("****UNGRABBED****\n"); } void Bindings::fireKey(int screen, unsigned int modifiers, unsigned int key, - Time time, KeyAction action) + Time time, KeyAction::KA action) { if (_keybgrab_callback) { Client *c = openbox->focusedClient(); KeyData data(screen, c, time, modifiers, key, action); python_callback(_keybgrab_callback, &data); - } else { - // KeyRelease events only occur during keyboard grabs - if (action == EventKeyRelease) return; + } + + // KeyRelease events only occur during keyboard grabs + if (action == KeyAction::Release) return; - if (key == _resetkey.key && modifiers == _resetkey.modifiers) { - resetChains(this); - } else { - KeyBindingTree *p = _curpos->first_child; - while (p) { - if (p->binding.key == key && p->binding.modifiers == modifiers) { - if (p->chain) { - if (_timer) - delete _timer; - _timer = new otk::Timer(5000, // 5 second timeout - (otk::Timer::TimeoutHandler)resetChains, - this); - // grab the server here to make sure no key pressed go missed - otk::display->grab(); - grabKeys(false); - _curpos = p; - grabKeys(true); - otk::display->ungrab(); - } else { - Client *c = openbox->focusedClient(); - KeyData data(screen, c, time, modifiers, key, action); - CallbackList::iterator it, end = p->callbacks.end(); - for (it = p->callbacks.begin(); it != end; ++it) - python_callback(*it, &data); - resetChains(this); - } - break; + if (key == _resetkey.key && modifiers == _resetkey.modifiers) { + resetChains(this); + } else { + KeyBindingTree *p = _curpos->first_child; + while (p) { + if (p->binding.key == key && p->binding.modifiers == modifiers) { + if (p->chain) { + if (_timer) + delete _timer; + _timer = new otk::Timer(5000, // 5 second timeout + (otk::Timer::TimeoutHandler)resetChains, + this); + // grab the server here to make sure no key pressed go missed + otk::display->grab(); + grabKeys(false); + _curpos = p; + grabKeys(true); + otk::display->ungrab(); + } else { + Client *c = openbox->focusedClient(); + KeyData data(screen, c, time, modifiers, key, action); + CallbackList::iterator it, end = p->callbacks.end(); + for (it = p->callbacks.begin(); it != end; ++it) + python_callback(*it, &data); + resetChains(this); } - p = p->next_sibling; + break; } + p = p->next_sibling; } } } @@ -464,10 +460,10 @@ void Bindings::resetChains(Bindings *self) } -bool Bindings::addButton(const std::string &but, MouseContext context, - MouseAction action, PyObject *callback) +bool Bindings::addButton(const std::string &but, MouseContext::MC context, + MouseAction::MA action, PyObject *callback) { - assert(context >= 0 && context < NUM_MOUSE_CONTEXT); + assert(context >= 0 && context < MouseContext::NUM_MOUSE_CONTEXT); Binding b(0,0); if (!translate(but, b, false)) @@ -491,8 +487,9 @@ bool Bindings::addButton(const std::string &but, MouseContext context, bind->binding.modifiers = b.modifiers; _buttons[context].push_back(bind); // grab the button on all clients - for (int sn = 0; sn < openbox->screenCount(); ++sn) { + for (int sn = 0; sn < ScreenCount(**otk::display); ++sn) { Screen *s = openbox->screen(sn); + if (!s) continue; // not managed Client::List::iterator c_it, c_end = s->clients.end(); for (c_it = s->clients.begin(); c_it != c_end; ++c_it) { grabButton(true, bind->binding, context, *c_it); @@ -507,39 +504,40 @@ bool Bindings::addButton(const std::string &but, MouseContext context, void Bindings::removeAllButtons() { - for (int i = 0; i < NUM_MOUSE_CONTEXT; ++i) { + for (int i = 0; i < MouseContext::NUM_MOUSE_CONTEXT; ++i) { ButtonBindingList::iterator it, end = _buttons[i].end(); for (it = _buttons[i].begin(); it != end; ++it) { - for (int a = 0; a < NUM_MOUSE_ACTION; ++a) { + for (int a = 0; a < MouseAction::NUM_MOUSE_ACTION; ++a) { while (!(*it)->callbacks[a].empty()) { Py_XDECREF((*it)->callbacks[a].front()); (*it)->callbacks[a].pop_front(); } } // ungrab the button on all clients - for (int sn = 0; sn < openbox->screenCount(); ++sn) { + for (int sn = 0; sn < ScreenCount(**otk::display); ++sn) { Screen *s = openbox->screen(sn); + if (!s) continue; // not managed Client::List::iterator c_it, c_end = s->clients.end(); for (c_it = s->clients.begin(); c_it != c_end; ++c_it) { - grabButton(false, (*it)->binding, (MouseContext)i, *c_it); + grabButton(false, (*it)->binding, (MouseContext::MC)i, *c_it); } } } } } -void Bindings::grabButton(bool grab, const Binding &b, MouseContext context, - Client *client) +void Bindings::grabButton(bool grab, const Binding &b, + MouseContext::MC context, Client *client) { Window win; int mode = GrabModeAsync; unsigned int mask; switch(context) { - case MC_Frame: + case MouseContext::Frame: win = client->frame->window(); mask = ButtonPressMask | ButtonMotionMask | ButtonReleaseMask; break; - case MC_Window: + case MouseContext::Window: win = client->frame->plate(); mode = GrabModeSync; // this is handled in fireButton mask = ButtonPressMask; // can't catch more than this with Sync mode @@ -559,16 +557,16 @@ void Bindings::grabButton(bool grab, const Binding &b, MouseContext context, void Bindings::grabButtons(bool grab, Client *client) { - for (int i = 0; i < NUM_MOUSE_CONTEXT; ++i) { + for (int i = 0; i < MouseContext::NUM_MOUSE_CONTEXT; ++i) { ButtonBindingList::iterator it, end = _buttons[i].end(); for (it = _buttons[i].begin(); it != end; ++it) - grabButton(grab, (*it)->binding, (MouseContext)i, client); + grabButton(grab, (*it)->binding, (MouseContext::MC)i, client); } } void Bindings::fireButton(MouseData *data) { - if (data->context == MC_Window) { + if (data->context == MouseContext::Window) { // Replay the event, so it goes to the client XAllowEvents(**otk::display, ReplayPointer, data->time); } @@ -585,13 +583,13 @@ void Bindings::fireButton(MouseData *data) } -bool Bindings::addEvent(EventAction action, PyObject *callback) +bool Bindings::addEvent(EventAction::EA action, PyObject *callback) { - if (action < 0 || action >= NUM_EVENTS) { + if (action < 0 || action >= EventAction::NUM_EVENTS) { return false; } #ifdef XKB - if (action == EventBell && _eventlist[action].empty()) + if (action == EventAction::Bell && _eventlist[action].empty()) XkbSelectEvents(**otk::display, XkbUseCoreKbd, XkbBellNotifyMask, XkbBellNotifyMask); #endif // XKB @@ -600,9 +598,9 @@ bool Bindings::addEvent(EventAction action, PyObject *callback) return true; } -bool Bindings::removeEvent(EventAction action, PyObject *callback) +bool Bindings::removeEvent(EventAction::EA action, PyObject *callback) { - if (action < 0 || action >= NUM_EVENTS) { + if (action < 0 || action >= EventAction::NUM_EVENTS) { return false; } @@ -613,7 +611,7 @@ bool Bindings::removeEvent(EventAction action, PyObject *callback) Py_XDECREF(*it); _eventlist[action].erase(it); #ifdef XKB - if (action == EventBell && _eventlist[action].empty()) + if (action == EventAction::Bell && _eventlist[action].empty()) XkbSelectEvents(**otk::display, XkbUseCoreKbd, XkbBellNotifyMask, 0); #endif // XKB @@ -624,7 +622,7 @@ bool Bindings::removeEvent(EventAction action, PyObject *callback) void Bindings::removeAllEvents() { - for (int i = 0; i < NUM_EVENTS; ++i) { + for (int i = 0; i < EventAction::NUM_EVENTS; ++i) { while (!_eventlist[i].empty()) { Py_XDECREF(_eventlist[i].front()); _eventlist[i].pop_front(); diff --git a/src/bindings.hh b/src/bindings.hh index 259686d2..2b2260e2 100644 --- a/src/bindings.hh +++ b/src/bindings.hh @@ -51,7 +51,7 @@ typedef struct KeyBindingTree { typedef struct ButtonBinding { Binding binding; - CallbackList callbacks[NUM_MOUSE_ACTION]; + CallbackList callbacks[MouseAction::NUM_MOUSE_ACTION]; ButtonBinding() : binding(0, 0) {} }; @@ -77,12 +77,12 @@ private: static void resetChains(Bindings *self); // the timer's timeout function typedef std::list <ButtonBinding*> ButtonBindingList; - ButtonBindingList _buttons[NUM_MOUSE_CONTEXT]; + ButtonBindingList _buttons[MouseContext::NUM_MOUSE_CONTEXT]; - void grabButton(bool grab, const Binding &b, MouseContext context, + void grabButton(bool grab, const Binding &b, MouseContext::MC context, Client *client); - CallbackList _eventlist[NUM_EVENTS]; + CallbackList _eventlist[EventAction::NUM_EVENTS]; PyObject *_keybgrab_callback; @@ -114,7 +114,7 @@ public: void removeAllKeys(); void fireKey(int screen, unsigned int modifiers,unsigned int key, Time time, - KeyAction action); + KeyAction::KA action); void setResetKey(const std::string &key); @@ -123,8 +123,8 @@ public: bool grabKeyboard(int screen, PyObject *callback); void ungrabKeyboard(); - bool addButton(const std::string &but, MouseContext context, - MouseAction action, PyObject *callback); + bool addButton(const std::string &but, MouseContext::MC context, + MouseAction::MA action, PyObject *callback); void grabButtons(bool grab, Client *client); @@ -134,10 +134,10 @@ public: void fireButton(MouseData *data); //! Bind a callback for an event - bool addEvent(EventAction action, PyObject *callback); + bool addEvent(EventAction::EA action, PyObject *callback); //! Unbind the callback function from an event - bool removeEvent(EventAction action, PyObject *callback); + bool removeEvent(EventAction::EA action, PyObject *callback); //! Remove all callback functions void removeAllEvents(); diff --git a/src/client.cc b/src/client.cc index fb4b924d..2c3d3ad3 100644 --- a/src/client.cc +++ b/src/client.cc @@ -133,7 +133,7 @@ void Client::getDesktop() otk::Property::atoms.cardinal, (long unsigned*)&_desktop)) { #ifdef DEBUG - printf("DEBUG: Window requested desktop: %ld\n", _desktop); +// printf("Window requested desktop: %ld\n", _desktop); #endif } } @@ -1181,7 +1181,6 @@ void Client::applyStartupState() // these are in a carefully crafted order.. if (_iconic) { - printf("MAP ICONIC\n"); _iconic = false; setDesktop(ICONIC_DESKTOP); } @@ -1210,7 +1209,7 @@ void Client::applyStartupState() void Client::fireUrgent() { // call the python UrgentWindow callbacks - EventData data(_screen, this, EventUrgentWindow, 0); + EventData data(_screen, this, EventAction::UrgentWindow, 0); openbox->bindings()->fireEvent(&data); } diff --git a/src/openbox.cc b/src/openbox.cc index edee736e..5e53fb06 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -147,24 +147,28 @@ Openbox::Openbox(int argc, char **argv) python_init(argv[0]); // load config values - python_exec(SCRIPTDIR"/config.py"); // load openbox config values + //python_exec(SCRIPTDIR"/config.py"); // load openbox config values // run all of the python scripts - python_exec(SCRIPTDIR"/builtins.py"); // builtin callbacks - python_exec(SCRIPTDIR"/focus.py"); // focus helpers + //python_exec(SCRIPTDIR"/builtins.py"); // builtin callbacks + //python_exec(SCRIPTDIR"/focus.py"); // focus helpers // run the user's script or the system defaults if that fails if (!python_exec(_scriptfilepath.c_str())) python_exec(SCRIPTDIR"/defaults.py"); // system default bahaviors // initialize all the screens - Screen *screen; - int i = _single ? DefaultScreen(**otk::display) : 0; - int max = _single ? i + 1 : ScreenCount(**otk::display); - for (; i < max; ++i) { + for (int i = 0, max = ScreenCount(**otk::display); i < max; ++i) { + Screen *screen; + if (_single && i != DefaultScreen(**otk::display)) { + _screens.push_back(0); + continue; + } screen = new Screen(i); if (screen->managed()) _screens.push_back(screen); - else + else { delete screen; + _screens.push_back(0); + } } if (_screens.empty()) { @@ -390,16 +394,9 @@ void Openbox::setFocusedClient(Client *c) } // call the python Focus callbacks - EventData data(_focused_screen->number(), c, EventFocus, 0); + EventData data(_focused_screen->number(), c, EventAction::Focus, 0); _bindings->fireEvent(&data); } -void Openbox::execute(int screen, const std::string &bin) -{ - if (screen >= ScreenCount(**otk::display)) - screen = 0; - otk::bexec(bin, otk::display->screenInfo(screen)->displayString()); -} - } diff --git a/src/openbox.hh b/src/openbox.hh index 2b8e8b07..163b9132 100644 --- a/src/openbox.hh +++ b/src/openbox.hh @@ -174,19 +174,17 @@ public: //! Returns the Bindings instance for the window manager inline Bindings *bindings() const { return _bindings; } - //! Returns a managed screen + //! Returns a managed screen or a null pointer + /*! + ALWAYS check the return value for a non-null, as any unmanaged screens + will return one. This includes screen(0) if the first managed screen is 1. + */ inline Screen *screen(int num) { - assert(num >= 0); assert(num < (signed)_screens.size()); - if (num < 0 || num >= screenCount()) - return NULL; + assert(num >= 0); assert(num < (signed)ScreenCount(**otk::display)); + if (num >= (signed)_screens.size()) return 0; return _screens[num]; } - //! Returns the number of managed screens - inline int screenCount() const { - return (signed)_screens.size(); - } - //! Returns the mouse cursors used throughout Openbox inline const Cursors &cursors() const { return _cursors; } @@ -231,9 +229,6 @@ public: inline void restart(const std::string &bin = "") { _shutdown = true; _restart = true; _restart_prog = bin; } - - //! Executes a command on a screen - void execute(int screen, const std::string &bin); }; } diff --git a/src/openbox.i b/src/openbox.i index 66ec8ee6..7ab588e1 100644 --- a/src/openbox.i +++ b/src/openbox.i @@ -1,6 +1,6 @@ // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -%module openbox +%module ob %{ #ifdef HAVE_CONFIG_H diff --git a/src/python.cc b/src/python.cc index ff02d6d4..f95d4723 100644 --- a/src/python.cc +++ b/src/python.cc @@ -10,7 +10,7 @@ extern "C" { // The initializer in openbox_wrap.cc -extern void init_openbox(void); +extern void init_ob(void); } namespace ob { @@ -23,21 +23,20 @@ void python_init(char *argv0) Py_SetProgramName(argv0); Py_Initialize(); // initialize the C python module - init_openbox(); + init_ob(); // include the openbox directories for python scripts in the sys path PyRun_SimpleString("import sys"); - PyRun_SimpleString("sys.path.append('" SCRIPTDIR "')"); PyRun_SimpleString(const_cast<char*>(("sys.path.append('" + otk::expandTilde("~/.openbox/python") + "')").c_str())); - // import the otk and openbox modules into the main namespace - PyRun_SimpleString("from openbox import *;"); + PyRun_SimpleString("sys.path.append('" SCRIPTDIR "')"); + PyRun_SimpleString("import ob;"); // set up convenience global variables - PyRun_SimpleString("openbox = Openbox_instance()"); - PyRun_SimpleString("display = Display_instance()"); + PyRun_SimpleString("ob.openbox = ob.Openbox_instance()"); + PyRun_SimpleString("ob.display = ob.Display_instance()"); // set up access to the python global variables - PyObject *obmodule = PyImport_AddModule("__main__"); + PyObject *obmodule = PyImport_AddModule("config"); obdict = PyModule_GetDict(obmodule); } @@ -93,8 +92,8 @@ bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value) // Stuff for calling from Python scripts // // ************************************* // -PyObject *mbind(const std::string &button, ob::MouseContext context, - ob::MouseAction action, PyObject *func) +PyObject *mbind(const std::string &button, ob::MouseContext::MC context, + ob::MouseAction::MA action, PyObject *func) { if (!PyCallable_Check(func)) { PyErr_SetString(PyExc_TypeError, "Invalid callback function."); @@ -102,14 +101,14 @@ PyObject *mbind(const std::string &button, ob::MouseContext context, } if (!ob::openbox->bindings()->addButton(button, context, - action, func)) { + action, func)) { PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); return NULL; } Py_INCREF(Py_None); return Py_None; } -PyObject *ebind(ob::EventAction action, PyObject *func) +PyObject *ebind(ob::EventAction::EA action, PyObject *func) { if (!PyCallable_Check(func)) { PyErr_SetString(PyExc_TypeError, "Invalid callback function."); @@ -143,7 +142,7 @@ PyObject *kungrab() Py_INCREF(Py_None); return Py_None; } -PyObject *kbind(PyObject *keylist, ob::KeyContext context, PyObject *func) +PyObject *kbind(PyObject *keylist, ob::KeyContext::KC context, PyObject *func) { if (!PyCallable_Check(func)) { PyErr_SetString(PyExc_TypeError, "Invalid callback function."); @@ -233,4 +232,11 @@ PyObject *send_client_msg(Window target, Atom type, Window about, Py_INCREF(Py_None); return Py_None; } +void execute(const std::string &bin, int screen) +{ + if (screen >= ScreenCount(**otk::display)) + screen = 0; + otk::bexec(bin, otk::display->screenInfo(screen)->displayString()); +} + } diff --git a/src/python.hh b/src/python.hh index 7c31e85c..ac5bd3e1 100644 --- a/src/python.hh +++ b/src/python.hh @@ -24,53 +24,63 @@ namespace ob { class Client; -enum MouseContext { - MC_Frame, - MC_Titlebar, - MC_Handle, - MC_Window, - MC_MaximizeButton, - MC_CloseButton, - MC_IconifyButton, - MC_AllDesktopsButton, - MC_Grip, - MC_Root, - MC_MenuItem, - NUM_MOUSE_CONTEXT +struct MouseContext { + enum MC { + Frame, + Titlebar, + Handle, + Window, + MaximizeButton, + CloseButton, + IconifyButton, + AllDesktopsButton, + Grip, + Root, + MenuItem, + NUM_MOUSE_CONTEXT + }; }; -enum MouseAction { - MousePress, - MouseClick, - MouseDoubleClick, - MouseMotion, - NUM_MOUSE_ACTION +struct MouseAction { + enum MA { + Press, + Click, + DoubleClick, + Motion, + NUM_MOUSE_ACTION + }; }; -enum KeyContext { - KC_Menu, - KC_All, - NUM_KEY_CONTEXT +struct KeyContext { + enum KC { + Menu, + All, + NUM_KEY_CONTEXT + }; }; -enum KeyAction { - EventKeyPress, - EventKeyRelease, - NUM_KEY_ACTION +struct KeyAction { + enum KA { + Press, + Release, + NUM_KEY_ACTION + }; }; -enum EventAction { - EventEnterWindow, - EventLeaveWindow, - EventPlaceWindow, - EventNewWindow, - EventCloseWindow, - EventStartup, - EventShutdown, - EventFocus, - EventBell, - EventUrgentWindow, - NUM_EVENTS +struct EventAction { + enum EA { + EnterWindow, + LeaveWindow, + PlaceWindow, + NewWindow, + CloseWindow, + Startup, + Shutdown, + Focus, + Bell, + UrgentWindow, + NUM_EVENTS + }; }; class MouseData { @@ -80,8 +90,8 @@ public: Time time; unsigned int state; unsigned int button; - MouseContext context; - MouseAction action; + MouseContext::MC context; + MouseAction::MA action; int xroot; int yroot; int pressx; @@ -92,9 +102,9 @@ public: int press_clientheight; MouseData(int screen, Client *client, Time time, unsigned int state, - unsigned int button, MouseContext context, MouseAction action, - int xroot, int yroot, const otk::Point &initpos, - const otk::Rect &initarea) { + unsigned int button, MouseContext::MC context, + MouseAction::MA action, int xroot, int yroot, + const otk::Point &initpos, const otk::Rect &initarea) { this->screen = screen; this->client = client; this->time = time; @@ -112,7 +122,8 @@ public: this->press_clientheight = initarea.height(); } MouseData(int screen, Client *client, Time time, unsigned int state, - unsigned int button, MouseContext context, MouseAction action) { + unsigned int button, MouseContext::MC context, + MouseAction::MA action) { this->screen = screen; this->client = client; this->time = time; @@ -136,9 +147,9 @@ public: int screen; Client *client; unsigned int state; - EventAction action; + EventAction::EA action; - EventData(int screen, Client *client, EventAction action, + EventData(int screen, Client *client, EventAction::EA action, unsigned int state) { this->screen = screen; this->client = client; @@ -154,10 +165,10 @@ public: Time time; unsigned int state; char *key; - KeyAction action; + KeyAction::KA action; KeyData(int screen, Client *client, Time time, unsigned int state, - unsigned int key, KeyAction action) { + unsigned int key, KeyAction::KA action) { this->screen = screen; this->client = client; this->time = time; @@ -187,21 +198,25 @@ void python_callback(PyObject *func, KeyData *data); #endif // SWIG -PyObject *mbind(const std::string &button, ob::MouseContext context, - ob::MouseAction action, PyObject *func); +PyObject *mbind(const std::string &button, ob::MouseContext::MC context, + ob::MouseAction::MA action, PyObject *func); -PyObject *kbind(PyObject *keylist, ob::KeyContext context, PyObject *func); +PyObject *kbind(PyObject *keylist, ob::KeyContext::KC context, PyObject *func); PyObject *kgrab(int screen, PyObject *func); PyObject *kungrab(); -PyObject *ebind(ob::EventAction action, PyObject *func); +PyObject *ebind(ob::EventAction::EA action, PyObject *func); void set_reset_key(const std::string &key); PyObject *send_client_msg(Window target, Atom type, Window about, long data, long data1 = 0, long data2 = 0, long data3 = 0, long data4 = 0); + + +void execute(const std::string &bin, int screen=0); + } diff --git a/src/screen.cc b/src/screen.cc index 2a7711de..51a6f76e 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -134,7 +134,7 @@ Screen::Screen(int screen) openbox->registerHandler(_info->rootWindow(), this); // call the python Startup callbacks - EventData data(_number, 0, EventShutdown, 0); + EventData data(_number, 0, EventAction::Shutdown, 0); openbox->bindings()->fireEvent(&data); } @@ -150,7 +150,7 @@ Screen::~Screen() unmanageWindow(clients.front()); // call the python Shutdown callbacks - EventData data(_number, 0, EventShutdown, 0); + EventData data(_number, 0, EventAction::Shutdown, 0); openbox->bindings()->fireEvent(&data); XDestroyWindow(**otk::display, _focuswindow); @@ -498,7 +498,7 @@ void Screen::manageWindow(Window window) client->positionRequested())) { // position the window intelligenty .. hopefully :) // call the python PLACEWINDOW binding - EventData data(_number, client, EventPlaceWindow, 0); + EventData data(_number, client, EventAction::PlaceWindow, 0); openbox->bindings()->fireEvent(&data); } @@ -523,7 +523,7 @@ void Screen::manageWindow(Window window) openbox->bindings()->grabButtons(true, client); // call the python NEWWINDOW binding - EventData data(_number, client, EventNewWindow, 0); + EventData data(_number, client, EventAction::NewWindow, 0); openbox->bindings()->fireEvent(&data); #ifdef DEBUG @@ -538,7 +538,7 @@ void Screen::unmanageWindow(Client *client) Frame *frame = client->frame; // call the python CLOSEWINDOW binding - EventData data(_number, client, EventCloseWindow, 0); + EventData data(_number, client, EventAction::CloseWindow, 0); openbox->bindings()->fireEvent(&data); openbox->bindings()->grabButtons(false, client); diff --git a/src/widgetbase.hh b/src/widgetbase.hh index d8307574..46aacb9f 100644 --- a/src/widgetbase.hh +++ b/src/widgetbase.hh @@ -32,34 +32,34 @@ public: inline WidgetType type() const { return _type; } - inline MouseContext mcontext() const { + inline MouseContext::MC mcontext() const { switch (_type) { case Type_Frame: - return MC_Frame; + return MouseContext::Frame; case Type_Titlebar: - return MC_Titlebar; + return MouseContext::Titlebar; case Type_Handle: - return MC_Handle; + return MouseContext::Handle; case Type_Plate: - return MC_Window; + return MouseContext::Window; case Type_Label: - return MC_Titlebar; + return MouseContext::Titlebar; case Type_MaximizeButton: - return MC_MaximizeButton; + return MouseContext::MaximizeButton; case Type_CloseButton: - return MC_CloseButton; + return MouseContext::CloseButton; case Type_IconifyButton: - return MC_IconifyButton; + return MouseContext::IconifyButton; case Type_AllDesktopsButton: - return MC_AllDesktopsButton; + return MouseContext::AllDesktopsButton; case Type_LeftGrip: - return MC_Grip; + return MouseContext::Grip; case Type_RightGrip: - return MC_Grip; + return MouseContext::Grip; case Type_Client: - return MC_Window; + return MouseContext::Window; case Type_Root: - return MC_Root; + return MouseContext::Root; default: assert(false); // unhandled type } |
