2002-12-30 06:31:45 +00:00
|
|
|
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "bindings.hh"
|
2002-12-30 22:27:46 +00:00
|
|
|
#include "screen.hh"
|
|
|
|
#include "openbox.hh"
|
|
|
|
#include "client.hh"
|
|
|
|
#include "frame.hh"
|
|
|
|
#include "python.hh"
|
2002-12-30 06:31:45 +00:00
|
|
|
#include "otk/display.hh"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <X11/Xlib.h>
|
2002-12-30 07:38:45 +00:00
|
|
|
|
|
|
|
#include "gettext.h"
|
|
|
|
#define _(str) gettext(str)
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace ob {
|
|
|
|
|
2002-12-30 16:42:15 +00:00
|
|
|
static bool buttonvalue(const std::string &button, unsigned int *val)
|
|
|
|
{
|
|
|
|
if (button == "1" || button == "Button1") {
|
|
|
|
*val |= Button1;
|
|
|
|
} else if (button == "2" || button == "Button2") {
|
|
|
|
*val |= Button2;
|
|
|
|
} else if (button == "3" || button == "Button3") {
|
|
|
|
*val |= Button3;
|
|
|
|
} else if (button == "4" || button == "Button4") {
|
|
|
|
*val |= Button4;
|
|
|
|
} else if (button == "5" || button == "Button5") {
|
|
|
|
*val |= Button5;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-12-30 08:59:46 +00:00
|
|
|
static bool modvalue(const std::string &mod, unsigned int *val)
|
|
|
|
{
|
|
|
|
if (mod == "C") { // control
|
|
|
|
*val |= ControlMask;
|
|
|
|
} else if (mod == "S") { // shift
|
|
|
|
*val |= ShiftMask;
|
|
|
|
} else if (mod == "A" || // alt/mod1
|
|
|
|
mod == "M" ||
|
2002-12-30 09:00:28 +00:00
|
|
|
mod == "Mod1" ||
|
|
|
|
mod == "M1") {
|
2002-12-30 08:59:46 +00:00
|
|
|
*val |= Mod1Mask;
|
2002-12-30 09:00:28 +00:00
|
|
|
} else if (mod == "Mod2" || // mod2
|
|
|
|
mod == "M2") {
|
2002-12-30 08:59:46 +00:00
|
|
|
*val |= Mod2Mask;
|
2002-12-30 09:00:28 +00:00
|
|
|
} else if (mod == "Mod3" || // mod3
|
|
|
|
mod == "M3") {
|
2002-12-30 08:59:46 +00:00
|
|
|
*val |= Mod3Mask;
|
|
|
|
} else if (mod == "W" || // windows/mod4
|
2002-12-30 09:00:28 +00:00
|
|
|
mod == "Mod4" ||
|
|
|
|
mod == "M4") {
|
2002-12-30 08:59:46 +00:00
|
|
|
*val |= Mod4Mask;
|
2002-12-30 09:00:28 +00:00
|
|
|
} else if (mod == "Mod5" || // mod5
|
|
|
|
mod == "M5") {
|
2002-12-30 08:59:46 +00:00
|
|
|
*val |= Mod5Mask;
|
|
|
|
} else { // invalid
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2002-12-30 06:31:45 +00:00
|
|
|
|
2003-01-02 22:58:32 +00:00
|
|
|
bool OBBindings::translate(const std::string &str, Binding &b,bool askey) const
|
2002-12-30 06:31:45 +00:00
|
|
|
{
|
2002-12-30 07:33:13 +00:00
|
|
|
// parse out the base key name
|
2002-12-30 06:44:14 +00:00
|
|
|
std::string::size_type keybegin = str.find_last_of('-');
|
2002-12-30 07:33:13 +00:00
|
|
|
keybegin = (keybegin == std::string::npos) ? 0 : keybegin + 1;
|
|
|
|
std::string key(str, keybegin);
|
2002-12-30 06:44:14 +00:00
|
|
|
|
2002-12-30 07:33:13 +00:00
|
|
|
// parse out the requested modifier keys
|
2002-12-30 08:59:46 +00:00
|
|
|
unsigned int modval = 0;
|
2002-12-30 07:33:13 +00:00
|
|
|
std::string::size_type begin = 0, end;
|
|
|
|
while (begin != keybegin) {
|
|
|
|
end = str.find_first_of('-', begin);
|
|
|
|
|
|
|
|
std::string mod(str, begin, end-begin);
|
2002-12-30 08:59:46 +00:00
|
|
|
if (!modvalue(mod, &modval)) {
|
2002-12-31 06:59:46 +00:00
|
|
|
printf(_("Invalid modifier element in key binding: %s\n"), mod.c_str());
|
2002-12-30 07:36:06 +00:00
|
|
|
return false;
|
2002-12-30 07:33:13 +00:00
|
|
|
}
|
2002-12-30 08:59:46 +00:00
|
|
|
|
2002-12-30 07:33:13 +00:00
|
|
|
begin = end + 1;
|
|
|
|
}
|
2002-12-30 08:59:46 +00:00
|
|
|
|
|
|
|
// set the binding
|
|
|
|
b.modifiers = modval;
|
2003-01-02 22:58:32 +00:00
|
|
|
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 {
|
|
|
|
return buttonvalue(key, &b.key);
|
2002-12-30 16:42:15 +00:00
|
|
|
}
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
static void destroytree(KeyBindingTree *tree)
|
2002-12-30 08:52:46 +00:00
|
|
|
{
|
|
|
|
while (tree) {
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *c = tree->first_child;
|
2002-12-30 08:52:46 +00:00
|
|
|
delete tree;
|
|
|
|
tree = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *OBBindings::buildtree(const StringVect &keylist,
|
2003-01-02 20:36:14 +00:00
|
|
|
PyObject *callback) const
|
2002-12-30 06:31:45 +00:00
|
|
|
{
|
|
|
|
if (keylist.empty()) return 0; // nothing in the list.. return 0
|
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *ret = 0, *p;
|
2002-12-30 06:31:45 +00:00
|
|
|
|
2002-12-30 08:52:46 +00:00
|
|
|
StringVect::const_reverse_iterator it, end = keylist.rend();
|
|
|
|
for (it = keylist.rbegin(); it != end; ++it) {
|
2002-12-30 06:31:45 +00:00
|
|
|
p = ret;
|
2003-01-03 02:48:25 +00:00
|
|
|
ret = new KeyBindingTree(callback);
|
2002-12-30 21:06:08 +00:00
|
|
|
if (!p) ret->chain = false; // only the first built node
|
2002-12-30 08:52:46 +00:00
|
|
|
ret->first_child = p;
|
2002-12-31 09:17:16 +00:00
|
|
|
if (!translate(*it, ret->binding)) {
|
2002-12-30 08:52:46 +00:00
|
|
|
destroytree(ret);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OBBindings::OBBindings()
|
2003-01-03 02:48:25 +00:00
|
|
|
: _curpos(&_keytree),
|
2002-12-31 19:15:24 +00:00
|
|
|
_resetkey(0,0),
|
|
|
|
_timer(Openbox::instance->timerManager(),
|
|
|
|
(otk::OBTimeoutHandler)reset, this)
|
2002-12-30 06:31:45 +00:00
|
|
|
{
|
2002-12-31 19:15:24 +00:00
|
|
|
_timer.setTimeout(5000); // chains reset after 5 seconds
|
|
|
|
|
2002-12-31 06:59:46 +00:00
|
|
|
setResetKey("C-g"); // set the default reset key
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OBBindings::~OBBindings()
|
|
|
|
{
|
2002-12-30 22:27:46 +00:00
|
|
|
grabKeys(false);
|
2003-01-02 20:36:14 +00:00
|
|
|
removeAll();
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
void OBBindings::assimilate(KeyBindingTree *node)
|
2002-12-30 06:31:45 +00:00
|
|
|
{
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *a, *b, *tmp, *last;
|
2002-12-30 06:31:45 +00:00
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
if (!_keytree.first_child) {
|
2002-12-30 06:31:45 +00:00
|
|
|
// there are no nodes at this level yet
|
2003-01-03 02:48:25 +00:00
|
|
|
_keytree.first_child = node;
|
2002-12-30 06:31:45 +00:00
|
|
|
} else {
|
2003-01-03 02:48:25 +00:00
|
|
|
a = _keytree.first_child;
|
2002-12-30 07:28:42 +00:00
|
|
|
last = a;
|
|
|
|
b = node;
|
2002-12-30 08:40:38 +00:00
|
|
|
while (a) {
|
2002-12-30 07:28:42 +00:00
|
|
|
last = a;
|
|
|
|
if (a->binding != b->binding) {
|
|
|
|
a = a->next_sibling;
|
|
|
|
} else {
|
2002-12-30 07:33:13 +00:00
|
|
|
tmp = b;
|
2002-12-30 07:28:42 +00:00
|
|
|
b = b->first_child;
|
2002-12-30 07:33:13 +00:00
|
|
|
delete tmp;
|
2002-12-30 07:28:42 +00:00
|
|
|
a = a->first_child;
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-30 08:40:38 +00:00
|
|
|
if (last->binding != b->binding)
|
|
|
|
last->next_sibling = b;
|
2002-12-30 21:10:13 +00:00
|
|
|
else {
|
2002-12-30 08:40:38 +00:00
|
|
|
last->first_child = b->first_child;
|
2002-12-30 21:10:13 +00:00
|
|
|
delete b;
|
|
|
|
}
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
PyObject *OBBindings::find(KeyBindingTree *search, bool *conflict) const {
|
2003-01-02 20:36:14 +00:00
|
|
|
*conflict = false;
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *a, *b;
|
|
|
|
a = _keytree.first_child;
|
2002-12-30 06:31:45 +00:00
|
|
|
b = search;
|
|
|
|
while (a && b) {
|
|
|
|
if (a->binding != b->binding) {
|
|
|
|
a = a->next_sibling;
|
|
|
|
} else {
|
|
|
|
if (a->chain == b->chain) {
|
2002-12-30 21:04:09 +00:00
|
|
|
if (!a->chain) {
|
2003-01-02 20:36:14 +00:00
|
|
|
// found it! (return the actual id, not the search's)
|
|
|
|
return a->callback;
|
2002-12-30 21:04:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-01-02 20:36:14 +00:00
|
|
|
*conflict = true;
|
|
|
|
return 0; // the chain status' don't match (conflict!)
|
2002-12-30 21:04:09 +00:00
|
|
|
}
|
2002-12-30 06:31:45 +00:00
|
|
|
b = b->first_child;
|
|
|
|
a = a->first_child;
|
|
|
|
}
|
|
|
|
}
|
2003-01-02 20:36:14 +00:00
|
|
|
return 0; // it just isn't in here
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
|
2002-12-30 22:27:46 +00:00
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
bool OBBindings::add(const StringVect &keylist, PyObject *callback)
|
2002-12-30 06:31:45 +00:00
|
|
|
{
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *tree;
|
2003-01-02 20:36:14 +00:00
|
|
|
bool conflict;
|
2002-12-30 06:31:45 +00:00
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
if (!(tree = buildtree(keylist, callback)))
|
2002-12-30 06:31:45 +00:00
|
|
|
return false; // invalid binding requested
|
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
if (find(tree, &conflict) || conflict) {
|
2002-12-30 06:31:45 +00:00
|
|
|
// conflicts with another binding
|
|
|
|
destroytree(tree);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-12-30 22:27:46 +00:00
|
|
|
grabKeys(false);
|
|
|
|
|
2002-12-30 06:31:45 +00:00
|
|
|
// assimilate this built tree into the main tree
|
2002-12-30 07:33:13 +00:00
|
|
|
assimilate(tree); // assimilation destroys/uses the tree
|
2002-12-30 20:55:33 +00:00
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
Py_INCREF(callback);
|
|
|
|
|
2002-12-30 22:27:46 +00:00
|
|
|
grabKeys(true);
|
|
|
|
|
2002-12-30 06:31:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
bool OBBindings::remove(const StringVect &keylist)
|
2002-12-30 06:31:45 +00:00
|
|
|
{
|
2003-01-02 20:36:14 +00:00
|
|
|
assert(false); // XXX: function not implemented yet
|
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *tree;
|
2003-01-02 20:36:14 +00:00
|
|
|
bool conflict;
|
2002-12-30 06:31:45 +00:00
|
|
|
|
|
|
|
if (!(tree = buildtree(keylist, 0)))
|
|
|
|
return false; // invalid binding requested
|
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
PyObject *func = find(tree, &conflict);
|
|
|
|
if (func) {
|
|
|
|
grabKeys(false);
|
2002-12-30 22:27:46 +00:00
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
_curpos = &_keytree;
|
2003-01-02 20:36:14 +00:00
|
|
|
|
|
|
|
// XXX do shit here ...
|
|
|
|
Py_DECREF(func);
|
|
|
|
|
|
|
|
grabKeys(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-31 06:59:46 +00:00
|
|
|
void OBBindings::setResetKey(const std::string &key)
|
|
|
|
{
|
|
|
|
Binding b(0, 0);
|
2002-12-31 09:17:16 +00:00
|
|
|
if (translate(key, b)) {
|
2002-12-31 06:59:46 +00:00
|
|
|
grabKeys(false);
|
|
|
|
_resetkey.key = b.key;
|
|
|
|
_resetkey.modifiers = b.modifiers;
|
|
|
|
grabKeys(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
static void remove_branch(KeyBindingTree *first)
|
2002-12-30 06:31:45 +00:00
|
|
|
{
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *p = first;
|
2002-12-30 06:31:45 +00:00
|
|
|
|
|
|
|
while (p) {
|
|
|
|
if (p->first_child)
|
|
|
|
remove_branch(p->first_child);
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *s = p->next_sibling;
|
2003-01-02 20:36:14 +00:00
|
|
|
Py_XDECREF(p->callback);
|
2002-12-30 06:31:45 +00:00
|
|
|
delete p;
|
|
|
|
p = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
void OBBindings::removeAll()
|
2002-12-30 06:31:45 +00:00
|
|
|
{
|
2003-01-03 02:48:25 +00:00
|
|
|
if (_keytree.first_child) {
|
|
|
|
remove_branch(_keytree.first_child);
|
|
|
|
_keytree.first_child = 0;
|
2002-12-30 16:42:15 +00:00
|
|
|
}
|
2002-12-30 22:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OBBindings::grabKeys(bool grab)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < Openbox::instance->screenCount(); ++i) {
|
|
|
|
Window root = otk::OBDisplay::screenInfo(i)->rootWindow();
|
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *p = _curpos->first_child;
|
2002-12-30 22:27:46 +00:00
|
|
|
while (p) {
|
2002-12-31 19:15:24 +00:00
|
|
|
if (grab) {
|
2002-12-30 22:27:46 +00:00
|
|
|
otk::OBDisplay::grabKey(p->binding.key, p->binding.modifiers,
|
|
|
|
root, false, GrabModeAsync, GrabModeAsync,
|
|
|
|
false);
|
2002-12-31 19:15:24 +00:00
|
|
|
}
|
2002-12-30 22:27:46 +00:00
|
|
|
else
|
|
|
|
otk::OBDisplay::ungrabKey(p->binding.key, p->binding.modifiers,
|
|
|
|
root);
|
|
|
|
p = p->next_sibling;
|
|
|
|
}
|
2002-12-31 06:59:46 +00:00
|
|
|
|
|
|
|
if (grab)
|
|
|
|
otk::OBDisplay::grabKey(_resetkey.key, _resetkey.modifiers,
|
|
|
|
root, true, GrabModeAsync, GrabModeAsync,
|
|
|
|
false);
|
|
|
|
else
|
|
|
|
otk::OBDisplay::ungrabKey(_resetkey.key, _resetkey.modifiers,
|
|
|
|
root);
|
2002-12-30 22:27:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-02 20:36:14 +00:00
|
|
|
void OBBindings::fire(unsigned int modifiers, unsigned int key, Time time)
|
2002-12-30 22:27:46 +00:00
|
|
|
{
|
2002-12-31 08:46:17 +00:00
|
|
|
if (key == _resetkey.key && modifiers == _resetkey.modifiers) {
|
2002-12-31 19:15:24 +00:00
|
|
|
reset(this);
|
2002-12-30 22:27:46 +00:00
|
|
|
} else {
|
2003-01-03 02:48:25 +00:00
|
|
|
KeyBindingTree *p = _curpos->first_child;
|
2002-12-30 22:27:46 +00:00
|
|
|
while (p) {
|
|
|
|
if (p->binding.key == key && p->binding.modifiers == modifiers) {
|
2002-12-31 08:46:17 +00:00
|
|
|
if (p->chain) {
|
2002-12-31 19:15:24 +00:00
|
|
|
_timer.start(); // start/restart the timer
|
2002-12-31 08:46:17 +00:00
|
|
|
grabKeys(false);
|
|
|
|
_curpos = p;
|
|
|
|
grabKeys(true);
|
|
|
|
} else {
|
2003-01-02 20:36:14 +00:00
|
|
|
Window win = None;
|
|
|
|
OBClient *c = Openbox::instance->focusedClient();
|
|
|
|
if (c) win = c->window();
|
2003-01-03 05:26:04 +00:00
|
|
|
KeyData *data = new_key_data(win, time, modifiers, key);
|
|
|
|
python_callback(p->callback, (PyObject*)data);
|
|
|
|
Py_DECREF((PyObject*)data);
|
2002-12-31 19:15:24 +00:00
|
|
|
reset(this);
|
2002-12-31 08:46:17 +00:00
|
|
|
}
|
2002-12-30 22:27:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = p->next_sibling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-31 19:15:24 +00:00
|
|
|
void OBBindings::reset(OBBindings *self)
|
|
|
|
{
|
|
|
|
self->_timer.stop();
|
|
|
|
self->grabKeys(false);
|
2003-01-03 02:48:25 +00:00
|
|
|
self->_curpos = &self->_keytree;
|
2002-12-31 19:15:24 +00:00
|
|
|
self->grabKeys(true);
|
|
|
|
}
|
|
|
|
|
2003-01-03 02:48:25 +00:00
|
|
|
|
|
|
|
bool OBBindings::addButton(const std::string &but, MouseContext context,
|
|
|
|
MouseAction action, PyObject *callback)
|
|
|
|
{
|
|
|
|
assert(context >= 0 && context < NUM_MOUSE_CONTEXT);
|
|
|
|
|
|
|
|
Binding b(0,0);
|
|
|
|
if (!translate(but, b, false))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ButtonBindingList::iterator it, end = _buttons[context].end();
|
|
|
|
|
|
|
|
// look for a duplicate binding
|
|
|
|
for (it = _buttons[context].begin(); it != end; ++it)
|
|
|
|
if ((*it)->binding.key == b.key &&
|
|
|
|
(*it)->binding.modifiers == b.modifiers) {
|
2003-01-03 06:55:04 +00:00
|
|
|
if ((*it)->callback[action] == callback)
|
|
|
|
return true; // already bound
|
2003-01-03 02:48:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonBinding *bind;
|
|
|
|
|
|
|
|
// the binding didnt exist yet, add it
|
|
|
|
if (it == end) {
|
|
|
|
bind = new ButtonBinding();
|
|
|
|
bind->binding.key = b.key;
|
|
|
|
bind->binding.modifiers = b.modifiers;
|
|
|
|
_buttons[context].push_back(bind);
|
|
|
|
// XXX GRAB the new button everywhere!
|
|
|
|
} else
|
|
|
|
bind = *it;
|
2003-01-03 06:55:04 +00:00
|
|
|
Py_XDECREF(bind->callback[action]); // if it was already bound, unbind it
|
|
|
|
bind->callback[action] = callback;
|
2003-01-03 02:48:25 +00:00
|
|
|
Py_INCREF(callback);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBBindings::grabButtons(bool grab, OBClient *client)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_MOUSE_CONTEXT; ++i) {
|
2003-01-03 06:05:08 +00:00
|
|
|
Window win;
|
|
|
|
int mode = GrabModeAsync;
|
2003-01-03 02:48:25 +00:00
|
|
|
switch (i) {
|
|
|
|
case MC_Frame:
|
2003-01-03 06:05:08 +00:00
|
|
|
win = client->frame->window();
|
2003-01-03 02:48:25 +00:00
|
|
|
break;
|
|
|
|
case MC_Window:
|
2003-01-03 06:05:08 +00:00
|
|
|
win = client->frame->plate();
|
|
|
|
mode = GrabModeSync; // this is handled in the plate's buttonPressHandler
|
2003-01-03 02:48:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-01-03 06:07:53 +00:00
|
|
|
// any other elements already get button events, don't grab on them
|
2003-01-03 06:05:08 +00:00
|
|
|
continue;
|
2003-01-03 02:48:25 +00:00
|
|
|
}
|
|
|
|
ButtonBindingList::iterator it, end = _buttons[i].end();
|
|
|
|
for (it = _buttons[i].begin(); it != end; ++it)
|
2003-01-03 06:05:08 +00:00
|
|
|
if (grab)
|
|
|
|
otk::OBDisplay::grabButton((*it)->binding.key,
|
|
|
|
(*it)->binding.modifiers, win, false,
|
|
|
|
ButtonPressMask | ButtonMotionMask |
|
|
|
|
ButtonReleaseMask, mode, GrabModeAsync,
|
|
|
|
None, None, false);
|
|
|
|
else
|
|
|
|
otk::OBDisplay::ungrabButton((*it)->binding.key,
|
|
|
|
(*it)->binding.modifiers, win);
|
2003-01-03 02:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-03 05:26:04 +00:00
|
|
|
void OBBindings::fire(ButtonData *data)
|
2003-01-03 02:48:25 +00:00
|
|
|
{
|
2003-01-03 05:26:04 +00:00
|
|
|
printf("but.mods %d.%d\n", data->button, data->state);
|
2003-01-03 02:48:25 +00:00
|
|
|
|
2003-01-03 05:26:04 +00:00
|
|
|
ButtonBindingList::iterator it, end = _buttons[data->context].end();
|
|
|
|
for (it = _buttons[data->context].begin(); it != end; ++it)
|
|
|
|
if ((*it)->binding.key == data->button &&
|
|
|
|
(*it)->binding.modifiers == data->state) {
|
2003-01-03 06:55:04 +00:00
|
|
|
if ((*it)->callback[data->action])
|
|
|
|
python_callback((*it)->callback[data->action], (PyObject*)data);
|
2003-01-03 02:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-30 06:31:45 +00:00
|
|
|
}
|