summaryrefslogtreecommitdiff
path: root/src/bindings.cc
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2002-12-31 08:46:17 +0000
committerDana Jansens <danakj@orodu.net>2002-12-31 08:46:17 +0000
commitf7e3eb57294f9e73da2e342b503ca360485ae130 (patch)
tree17b11df55d04c342075e042347aa9c65abb51017 /src/bindings.cc
parent103372b02f783053c69f8f94db2c0e161f3e7d93 (diff)
add some globals to modify the default scripting behavior
Diffstat (limited to 'src/bindings.cc')
-rw-r--r--src/bindings.cc152
1 files changed, 26 insertions, 126 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,
}
}
-
}