diff options
| author | Dana Jansens <danakj@orodu.net> | 2002-12-31 08:46:17 +0000 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2002-12-31 08:46:17 +0000 |
| commit | f7e3eb57294f9e73da2e342b503ca360485ae130 (patch) | |
| tree | 17b11df55d04c342075e042347aa9c65abb51017 /src | |
| parent | 103372b02f783053c69f8f94db2c0e161f3e7d93 (diff) | |
add some globals to modify the default scripting behavior
Diffstat (limited to 'src')
| -rw-r--r-- | src/bindings.cc | 152 | ||||
| -rw-r--r-- | src/bindings.hh | 35 | ||||
| -rw-r--r-- | src/screen.cc | 4 |
3 files changed, 35 insertions, 156 deletions
diff --git a/src/bindings.cc b/src/bindings.cc index 08b2ca21..a6b91dc4 100644 --- a/src/bindings.cc +++ b/src/bindings.cc @@ -68,8 +68,7 @@ static bool modvalue(const std::string &mod, unsigned int *val) return true; } -bool OBBindings::translate(const std::string &str, Binding &b, - bool askey) const +bool OBBindings::translate(const std::string &str, Binding &b) const { // parse out the base key name std::string::size_type keybegin = str.find_last_of('-'); @@ -93,22 +92,14 @@ bool OBBindings::translate(const std::string &str, Binding &b, // set the binding b.modifiers = modval; - if (askey) { - KeySym sym = XStringToKeysym(const_cast<char *>(key.c_str())); - if (sym == NoSymbol) { - printf(_("Invalid Key name in key binding: %s\n"), key.c_str()); - return false; - } - if (!(b.key = XKeysymToKeycode(otk::OBDisplay::display, sym))) - printf(_("No valid keycode for Key in key binding: %s\n"), key.c_str()); - return b.key != 0; - } else { - if (!buttonvalue(key, &b.key)) { - printf(_("Invalid Button name in mouse binding: %s\n"), key.c_str()); - return false; - } else - return true; + KeySym sym = XStringToKeysym(const_cast<char *>(key.c_str())); + if (sym == NoSymbol) { + printf(_("Invalid Key name in key binding: %s\n"), key.c_str()); + return false; } + if (!(b.key = XKeysymToKeycode(otk::OBDisplay::display, sym))) + printf(_("No valid keycode for Key in key binding: %s\n"), key.c_str()); + return b.key != 0; } static void destroytree(BindingTree *tree) @@ -143,7 +134,7 @@ BindingTree *OBBindings::buildtree(const StringVect &keylist, int id) const OBBindings::OBBindings() - : _curpos(&_keytree), _mousetree(0), _resetkey(0,0) + : _curpos(&_keytree), _resetkey(0,0) { setResetKey("C-g"); // set the default reset key } @@ -151,53 +142,11 @@ OBBindings::OBBindings() OBBindings::~OBBindings() { - grabMouseOnAll(false); // ungrab everything grabKeys(false); remove_all(); } -bool OBBindings::add_mouse(const std::string &button, int id) -{ - BindingTree n; - - if (!translate(button, n.binding, false)) - return false; - - BindingTree *p = _mousetree, **newp = &_mousetree; - while (p) { - if (p->binding == n.binding) - return false; // conflict - p = p->next_sibling; - newp = &p->next_sibling; - } - - grabMouseOnAll(false); // ungrab everything - - *newp = new BindingTree(id); - (*newp)->chain = false; - (*newp)->binding.key = n.binding.key; - (*newp)->binding.modifiers = n.binding.modifiers; - - grabMouseOnAll(true); - - return true; -} - - -int OBBindings::remove_mouse(const std::string &button) -{ - (void)button; - assert(false); // XXX: function not implemented yet - - grabMouseOnAll(false); // ungrab everything - - // do shit... - - grabMouseOnAll(true); -} - - void OBBindings::assimilate(BindingTree *node) { BindingTree *a, *b, *tmp, *last; @@ -340,43 +289,6 @@ void OBBindings::remove_all() remove_branch(_keytree.first_child); _keytree.first_child = 0; } - BindingTree *p = _mousetree; - while (p) { - BindingTree *n = p->next_sibling; - delete p; - p = n; - } - _mousetree = 0; -} - - -void OBBindings::grabMouse(bool grab, const OBClient *client) -{ - BindingTree *p = _mousetree; - while (p) { - if (grab) - otk::OBDisplay::grabButton(p->binding.key, p->binding.modifiers, - client->frame->window(), false, - ButtonMotionMask | ButtonPressMask | - ButtonReleaseMask, GrabModeAsync, - GrabModeAsync, None, None, false); - else - otk::OBDisplay::ungrabButton(p->binding.key, p->binding.modifiers, - client->frame->window()); - p = p->next_sibling; - } -} - - -void OBBindings::grabMouseOnAll(bool grab) -{ - for (int i = 0; i < Openbox::instance->screenCount(); ++i) { - OBScreen *s = Openbox::instance->screen(i); - assert(s); - OBScreen::ClientList::iterator it, end = s->clients.end(); - for (it = s->clients.begin(); it != end; ++it) - grabMouse(grab, *it); - } } @@ -408,38 +320,27 @@ void OBBindings::grabKeys(bool grab) } -void OBBindings::fire(OBActions::ActionType type, Window window, - unsigned int modifiers, unsigned int key, Time time) +void OBBindings::fire(Window window, unsigned int modifiers, unsigned int key, + Time time) { - if (type == OBActions::Action_KeyPress) { - if (key == _resetkey.key && modifiers == _resetkey.modifiers) { - grabKeys(false); - _curpos = &_keytree; - grabKeys(true); - } else { - BindingTree *p = _curpos->first_child; - while (p) { - if (p->binding.key == key && p->binding.modifiers == modifiers) { - if (p->chain) { - grabKeys(false); - _curpos = p; - grabKeys(true); - } else { - python_callback_binding(p->id, type, window, modifiers, key, time); - grabKeys(false); - _curpos = &_keytree; - grabKeys(true); - } - break; - } - p = p->next_sibling; - } - } + if (key == _resetkey.key && modifiers == _resetkey.modifiers) { + grabKeys(false); + _curpos = &_keytree; + grabKeys(true); } else { - BindingTree *p = _mousetree; + BindingTree *p = _curpos->first_child; while (p) { if (p->binding.key == key && p->binding.modifiers == modifiers) { - python_callback_binding(p->id, type, window, modifiers, key, time); + if (p->chain) { + grabKeys(false); + _curpos = p; + grabKeys(true); + } else { + python_callback_binding(p->id, type, window, modifiers, key, time); + grabKeys(false); + _curpos = &_keytree; + grabKeys(true); + } break; } p = p->next_sibling; @@ -447,5 +348,4 @@ void OBBindings::fire(OBActions::ActionType type, Window window, } } - } diff --git a/src/bindings.hh b/src/bindings.hh index e04a7b18..dde79949 100644 --- a/src/bindings.hh +++ b/src/bindings.hh @@ -49,55 +49,36 @@ public: typedef std::vector<std::string> StringVect; private: - BindingTree _keytree; // root node of the tree (this doesn't have siblings!) + BindingTree _tree; // root node of the tree (this doesn't have siblings!) BindingTree *_curpos; // position in the keytree - BindingTree *_mousetree; // this tree is a list. it has only siblings - Binding _resetkey; // the key which resets the key chain status - int find_key(BindingTree *search) const; - bool translate(const std::string &str, Binding &b, bool askey) const; + 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); - void grabMouseOnAll(bool grab); - public: //! Initializes an OBBinding object OBBindings(); //! Destroys the OBBinding object virtual ~OBBindings(); - //! Adds a new mouse binding - /*! - A binding will fail to be added if the binding already exists, or if the - string is invalid. - @return true if the binding could be added; false if it could not. - */ - bool add_mouse(const std::string &button, int id); - - //! Removes a mouse binding - /*! - @return The id of the binding that was removed, or '< 0' if none were - removed. - */ - int remove_mouse(const std::string &button); - //! Adds a new key binding /*! A binding will fail to be added if the binding already exists (as part of a chain or not), or if any of the strings in the keylist are invalid. @return true if the binding could be added; false if it could not. */ - bool add_key(const StringVect &keylist, int id); + bool add(const StringVect &keylist, int id); //! Removes a key binding /*! @return The id of the binding that was removed, or '< 0' if none were removed. */ - int remove_key(const StringVect &keylist); + int remove(const StringVect &keylist); //! Removes all key bindings void remove_all(); @@ -107,14 +88,12 @@ public: @return -1 if the keybinding was not found but does not conflict with any others; -2 if the keybinding conflicts with another. */ - int find_key(const StringVect &keylist); + int find(const StringVect &keylist); - void fire(OBActions::ActionType type, Window window, unsigned int modifiers, - unsigned int key, Time time); + void fire(Window window, unsigned int modifiers,unsigned int key, Time time); void setResetKey(const std::string &key); - void grabMouse(bool grab, const OBClient *client); void grabKeys(bool grab); }; diff --git a/src/screen.cc b/src/screen.cc index e4518fba..7e9d0ea0 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -402,7 +402,7 @@ void OBScreen::manageWindow(Window window) // update the root properties setClientList(); - // grab buttons/keys on the window + // grab buttons on the window Openbox::instance->bindings()->grabMouse(true, client); } @@ -411,7 +411,7 @@ void OBScreen::unmanageWindow(OBClient *client) { OBFrame *frame = client->frame; - // ungrab buttons/keys on the window + // ungrab buttons on the window Openbox::instance->bindings()->grabMouse(false, client); // XXX: pass around focus if this window was focused |
