static bool buttonvalue(const std::string &button, unsigned int *val)
{
- if (button == "1" || button == "Button1") {
+ if (button == "Left" || button == "1" || button == "Button1") {
*val |= Button1;
- } else if (button == "2" || button == "Button2") {
+ } else if (button == "Middle" || button == "2" || button == "Button2") {
*val |= Button2;
- } else if (button == "3" || button == "Button3") {
+ } else if (button == "Right" || button == "3" || button == "Button3") {
*val |= Button3;
- } else if (button == "4" || button == "Button4") {
+ } else if (button == "Up" || button == "4" || button == "Button4") {
*val |= Button4;
- } else if (button == "5" || button == "Button5") {
+ } else if (button == "Down" || button == "5" || button == "Button5") {
*val |= Button5;
} else
return false;
return true;
}
-bool OBBindings::translate(const std::string &str, Binding &b,bool askey) const
+bool Bindings::translate(const std::string &str, Binding &b,bool askey) const
{
// parse out the base key name
std::string::size_type keybegin = str.find_last_of('-');
printf(_("Invalid Key name in key binding: %s\n"), key.c_str());
return false;
}
- if (!(b.key = XKeysymToKeycode(otk::OBDisplay::display, sym)))
+ if (!(b.key = XKeysymToKeycode(otk::Display::display, sym)))
printf(_("No valid keycode for Key in key binding: %s\n"), key.c_str());
return b.key != 0;
} else {
}
}
-KeyBindingTree *OBBindings::buildtree(const StringVect &keylist,
+KeyBindingTree *Bindings::buildtree(const StringVect &keylist,
PyObject *callback) const
{
if (keylist.empty()) return 0; // nothing in the list.. return 0
}
-OBBindings::OBBindings()
+Bindings::Bindings()
: _curpos(&_keytree),
_resetkey(0,0),
_timer(Openbox::instance->timerManager(),
- (otk::OBTimeoutHandler)resetChains, this)
+ (otk::TimeoutHandler)resetChains, this)
{
_timer.setTimeout(5000); // chains reset after 5 seconds
}
-OBBindings::~OBBindings()
+Bindings::~Bindings()
{
grabKeys(false);
removeAllKeys();
- removeAllButtons();
+// removeAllButtons(); XXX
removeAllEvents();
}
-void OBBindings::assimilate(KeyBindingTree *node)
+void Bindings::assimilate(KeyBindingTree *node)
{
KeyBindingTree *a, *b, *tmp, *last;
}
-KeyBindingTree *OBBindings::find(KeyBindingTree *search,
+KeyBindingTree *Bindings::find(KeyBindingTree *search,
bool *conflict) const {
*conflict = false;
KeyBindingTree *a, *b;
}
-bool OBBindings::addKey(const StringVect &keylist, PyObject *callback)
+bool Bindings::addKey(const StringVect &keylist, PyObject *callback)
{
KeyBindingTree *tree, *t;
bool conflict;
t->callbacks.push_back(callback);
destroytree(tree);
} else {
+ // grab the server here to make sure no key pressed go missed
+ otk::Display::grab();
grabKeys(false);
// assimilate this built tree into the main tree
assimilate(tree); // assimilation destroys/uses the tree
grabKeys(true);
+ otk::Display::ungrab();
}
Py_INCREF(callback);
}
-bool OBBindings::removeKey(const StringVect &keylist, PyObject *callback)
+bool Bindings::removeKey(const StringVect &keylist, PyObject *callback)
{
assert(false); // XXX: function not implemented yet
t->callbacks.end(),
callback);
if (it != t->callbacks.end()) {
+ // grab the server here to make sure no key pressed go missed
+ otk::Display::grab();
grabKeys(false);
_curpos = &_keytree;
Py_XDECREF(*it);
grabKeys(true);
+ otk::Display::ungrab();
+
return true;
}
}
}
-void OBBindings::setResetKey(const std::string &key)
+void Bindings::setResetKey(const std::string &key)
{
Binding b(0, 0);
if (translate(key, b)) {
+ // grab the server here to make sure no key pressed go missed
+ otk::Display::grab();
grabKeys(false);
_resetkey.key = b.key;
_resetkey.modifiers = b.modifiers;
grabKeys(true);
+ otk::Display::ungrab();
}
}
}
-void OBBindings::removeAllKeys()
+void Bindings::removeAllKeys()
{
grabKeys(false);
if (_keytree.first_child) {
}
-void OBBindings::grabKeys(bool grab)
+void Bindings::grabKeys(bool grab)
{
for (int i = 0; i < Openbox::instance->screenCount(); ++i) {
- Window root = otk::OBDisplay::screenInfo(i)->rootWindow();
+ Window root = otk::Display::screenInfo(i)->rootWindow();
KeyBindingTree *p = _curpos->first_child;
while (p) {
if (grab) {
- otk::OBDisplay::grabKey(p->binding.key, p->binding.modifiers,
+ otk::Display::grabKey(p->binding.key, p->binding.modifiers,
root, false, GrabModeAsync, GrabModeAsync,
false);
}
else
- otk::OBDisplay::ungrabKey(p->binding.key, p->binding.modifiers,
+ otk::Display::ungrabKey(p->binding.key, p->binding.modifiers,
root);
p = p->next_sibling;
}
if (_resetkey.key)
if (grab)
- otk::OBDisplay::grabKey(_resetkey.key, _resetkey.modifiers,
+ otk::Display::grabKey(_resetkey.key, _resetkey.modifiers,
root, false, GrabModeAsync, GrabModeAsync,
false);
else
- otk::OBDisplay::ungrabKey(_resetkey.key, _resetkey.modifiers,
+ otk::Display::ungrabKey(_resetkey.key, _resetkey.modifiers,
root);
}
}
-void OBBindings::fireKey(int screen, unsigned int modifiers, unsigned int key,
+void Bindings::fireKey(int screen, unsigned int modifiers, unsigned int key,
Time time)
{
if (key == _resetkey.key && modifiers == _resetkey.modifiers) {
if (p->binding.key == key && p->binding.modifiers == modifiers) {
if (p->chain) {
_timer.start(); // start/restart the timer
+ // 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 {
- Window win = None;
- OBClient *c = Openbox::instance->focusedClient();
- if (c) win = c->window();
- KeyData *data = new_key_data(screen, win, time, modifiers, key);
+ Client *c = Openbox::instance->focusedClient();
+ KeyData data(screen, c, time, modifiers, key);
CallbackList::iterator it, end = p->callbacks.end();
for (it = p->callbacks.begin(); it != end; ++it)
- python_callback(*it, (PyObject*)data);
- Py_XDECREF((PyObject*)data);
+ python_callback(*it, &data);
resetChains(this);
}
break;
}
}
-void OBBindings::resetChains(OBBindings *self)
+void Bindings::resetChains(Bindings *self)
{
self->_timer.stop();
+ // grab the server here to make sure no key pressed go missed
+ otk::Display::grab();
self->grabKeys(false);
self->_curpos = &self->_keytree;
self->grabKeys(true);
+ otk::Display::ungrab();
}
-bool OBBindings::addButton(const std::string &but, MouseContext context,
+bool Bindings::addButton(const std::string &but, MouseContext context,
MouseAction action, PyObject *callback)
{
assert(context >= 0 && context < NUM_MOUSE_CONTEXT);
_buttons[context].push_back(bind);
// grab the button on all clients
for (int sn = 0; sn < Openbox::instance->screenCount(); ++sn) {
- OBScreen *s = Openbox::instance->screen(sn);
- OBClient::List::iterator c_it, c_end = s->clients.end();
+ Screen *s = Openbox::instance->screen(sn);
+ 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);
}
return true;
}
-void OBBindings::removeAllButtons()
+void Bindings::removeAllButtons()
{
- for (int i = i; i < NUM_MOUSE_CONTEXT; ++i) {
+ for (int i = 0; i < 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) {
}
// ungrab the button on all clients
for (int sn = 0; sn < Openbox::instance->screenCount(); ++sn) {
- OBScreen *s = Openbox::instance->screen(sn);
- OBClient::List::iterator c_it, c_end = s->clients.end();
+ Screen *s = Openbox::instance->screen(sn);
+ 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);
}
}
}
-void OBBindings::grabButton(bool grab, const Binding &b, MouseContext context,
- OBClient *client)
+void Bindings::grabButton(bool grab, const Binding &b, MouseContext context,
+ Client *client)
{
Window win;
int mode = GrabModeAsync;
+ unsigned int mask;
switch(context) {
case MC_Frame:
win = client->frame->window();
+ mask = ButtonPressMask | ButtonMotionMask | ButtonReleaseMask;
break;
case MC_Window:
win = client->frame->plate();
mode = GrabModeSync; // this is handled in fireButton
+ mask = ButtonPressMask; // can't catch more than this with Sync mode
+ // the release event is manufactured by the
+ // master buttonPressHandler
break;
default:
// any other elements already get button events, don't grab on them
return;
}
if (grab)
- otk::OBDisplay::grabButton(b.key, b.modifiers, win, false,
- ButtonPressMask | ButtonMotionMask |
- ButtonReleaseMask, mode, GrabModeAsync,
- None, None, false);
+ otk::Display::grabButton(b.key, b.modifiers, win, false, mask, mode,
+ GrabModeAsync, None, None, false);
else
- otk::OBDisplay::ungrabButton(b.key, b.modifiers, win);
+ otk::Display::ungrabButton(b.key, b.modifiers, win);
}
-void OBBindings::grabButtons(bool grab, OBClient *client)
+void Bindings::grabButtons(bool grab, Client *client)
{
for (int i = 0; i < NUM_MOUSE_CONTEXT; ++i) {
ButtonBindingList::iterator it, end = _buttons[i].end();
}
}
-void OBBindings::fireButton(ButtonData *data)
+void Bindings::fireButton(MouseData *data)
{
if (data->context == MC_Window) {
- // these are grabbed in Sync mode to allow the press to be normal to the
- // client
- XAllowEvents(otk::OBDisplay::display, ReplayPointer, data->time);
+ // Replay the event, so it goes to the client, and ungrab the device.
+ XAllowEvents(otk::Display::display, ReplayPointer, data->time);
}
ButtonBindingList::iterator it, end = _buttons[data->context].end();
CallbackList::iterator c_it,c_end = (*it)->callbacks[data->action].end();
for (c_it = (*it)->callbacks[data->action].begin();
c_it != c_end; ++c_it)
- python_callback(*c_it, (PyObject*)data);
+ python_callback(*c_it, data);
}
}
-bool OBBindings::addEvent(EventAction action, PyObject *callback)
+bool Bindings::addEvent(EventAction action, PyObject *callback)
{
if (action < 0 || action >= NUM_EVENTS) {
return false;
}
-
+#ifdef XKB
+ if (action == EventBell && _eventlist[action].empty())
+ XkbSelectEvents(otk::Display::display, XkbUseCoreKbd,
+ XkbBellNotifyMask, XkbBellNotifyMask);
+#endif // XKB
_eventlist[action].push_back(callback);
Py_INCREF(callback);
return true;
}
-bool OBBindings::removeEvent(EventAction action, PyObject *callback)
+bool Bindings::removeEvent(EventAction action, PyObject *callback)
{
if (action < 0 || action >= NUM_EVENTS) {
return false;
if (it != _eventlist[action].end()) {
Py_XDECREF(*it);
_eventlist[action].erase(it);
+#ifdef XKB
+ if (action == EventBell && _eventlist[action].empty())
+ XkbSelectEvents(otk::Display::display, XkbUseCoreKbd,
+ XkbBellNotifyMask, 0);
+#endif // XKB
return true;
}
return false;
}
-void OBBindings::removeAllEvents()
+void Bindings::removeAllEvents()
{
for (int i = 0; i < NUM_EVENTS; ++i) {
while (!_eventlist[i].empty()) {
}
}
-void OBBindings::fireEvent(EventData *data)
+void Bindings::fireEvent(EventData *data)
{
CallbackList::iterator c_it, c_end = _eventlist[data->action].end();
for (c_it = _eventlist[data->action].begin(); c_it != c_end; ++c_it)
- python_callback(*c_it, (PyObject*)data);
+ python_callback(*c_it, data);
}
}