all repos — fluxbox @ 04a1d2a83b96eb6d1b1958e4f3e25ffdf295aa4d

custom fork of the fluxbox windowmanager

don't let KeyRelease events propagate to windows
Mark Tiefenbruck mark@fluxbox.org
commit

04a1d2a83b96eb6d1b1958e4f3e25ffdf295aa4d

parent

c8022b3bdb90259352d08838576e98b559a9db68

M src/FbTk/EventHandler.hhsrc/FbTk/EventHandler.hh

@@ -56,7 +56,6 @@ virtual void keyReleaseEvent(XKeyEvent &) { }

virtual void leaveNotifyEvent(XCrossingEvent &) { } virtual void enterNotifyEvent(XCrossingEvent &) { } - virtual void notifyUngrabKeyboard() { } virtual void grabButtons() { } };
M src/FbTk/EventManager.ccsrc/FbTk/EventManager.cc

@@ -65,25 +65,14 @@ EventHandler *EventManager::find(Window win) {

return m_eventhandlers[win]; } -bool EventManager::grabKeyboard(EventHandler &ev, Window win) { - if (m_grabbing_keyboard) - ungrabKeyboard(); - +bool EventManager::grabKeyboard(Window win) { int ret = XGrabKeyboard(App::instance()->display(), win, False, GrabModeAsync, GrabModeAsync, CurrentTime); - - if (ret == Success) { - m_grabbing_keyboard = &ev; - return true; - } - return false; + return (ret == Success); } void EventManager::ungrabKeyboard() { XUngrabKeyboard(App::instance()->display(), CurrentTime); - if (m_grabbing_keyboard) - m_grabbing_keyboard->notifyUngrabKeyboard(); - m_grabbing_keyboard = 0; } Window EventManager::getEventWindow(XEvent &ev) {

@@ -190,10 +179,14 @@ case Expose:

evhand->exposeEvent(ev.xexpose); break; case EnterNotify: - evhand->enterNotifyEvent(ev.xcrossing); + if (ev.xcrossing.mode != NotifyGrab && + ev.xcrossing.mode != NotifyUngrab) + evhand->enterNotifyEvent(ev.xcrossing); break; case LeaveNotify: - evhand->leaveNotifyEvent(ev.xcrossing); + if (ev.xcrossing.mode != NotifyGrab && + ev.xcrossing.mode != NotifyUngrab) + evhand->leaveNotifyEvent(ev.xcrossing); break; default: evhand->handleEvent(ev);
M src/FbTk/EventManager.hhsrc/FbTk/EventManager.hh

@@ -42,9 +42,8 @@ void remove(const FbWindow &win);

void add(EventHandler &ev, Window win) { registerEventHandler(ev, win); } void remove(Window win) { unregisterEventHandler(win); } - bool grabKeyboard(EventHandler &ev, Window win); + bool grabKeyboard(Window win); void ungrabKeyboard(); - EventHandler *grabbingKeyboard() { return m_grabbing_keyboard; } EventHandler *find(Window win);
M src/FocusControl.ccsrc/FocusControl.cc

@@ -91,7 +91,7 @@ void FocusControl::cycleFocus(const FocusableList &window_list,

const ClientPattern *pat, bool cycle_reverse) { if (!m_cycling_list) { - if (&m_screen == FbTk::EventManager::instance()->grabbingKeyboard()) + if (m_screen.isCycling()) // only set this when we're waiting for modifiers m_cycling_list = &window_list; m_was_iconic = 0;
M src/Keys.ccsrc/Keys.cc

@@ -510,12 +510,6 @@

// grab "None Escape" to exit keychain in the middle unsigned int esc = FbTk::KeyUtil::getKey("Escape"); - // if focus changes, windows will get NotifyWhileGrabbed, - // which they tend to ignore - if (temp_key && type == KeyPress && - !FbTk::EventManager::instance()->grabbingKeyboard()) - XUngrabKeyboard(Fluxbox::instance()->display(), CurrentTime); - if (temp_key && !temp_key->keylist.empty()) { // emacs-style if (!saved_keymode) saved_keymode = m_keylist;

@@ -535,6 +529,11 @@ }

} return false; } + + // if focus changes, windows will get NotifyWhileGrabbed, + // which they tend to ignore + if (type == KeyPress) + XUngrabKeyboard(Fluxbox::instance()->display(), CurrentTime); WinClient *old = WindowCmd<void>::client(); WindowCmd<void>::setClient(current);
M src/Screen.ccsrc/Screen.cc

@@ -856,19 +856,26 @@ m_bg_change_sig.emit(*this);

} void BScreen::keyPressEvent(XKeyEvent &ke) { - Fluxbox::instance()->keys()->doAction(ke.type, ke.state, ke.keycode, - Keys::GLOBAL|Keys::ON_DESKTOP); + if (Fluxbox::instance()->keys()->doAction(ke.type, ke.state, ke.keycode, + Keys::GLOBAL|Keys::ON_DESKTOP)) + // re-grab keyboard, so we don't pass KeyRelease to clients + FbTk::EventManager::instance()->grabKeyboard(rootWindow().window()); + } void BScreen::keyReleaseEvent(XKeyEvent &ke) { - if (!m_cycling) - return; + if (m_cycling) { + unsigned int state = FbTk::KeyUtil::instance().cleanMods(ke.state); + state &= ~FbTk::KeyUtil::instance().keycodeToModmask(ke.keycode); - unsigned int state = FbTk::KeyUtil::instance().cleanMods(ke.state); - state &= ~FbTk::KeyUtil::instance().keycodeToModmask(ke.keycode); + if (state) // still cycling + return; - if (!state) // all modifiers were released - FbTk::EventManager::instance()->ungrabKeyboard(); + m_cycling = false; + focusControl().stopCyclingFocus(); + } + + FbTk::EventManager::instance()->ungrabKeyboard(); } void BScreen::buttonPressEvent(XButtonEvent &be) {

@@ -880,11 +887,6 @@ keys->doAction(be.type, be.state, be.button, Keys::GLOBAL|Keys::ON_DESKTOP,

0, be.time); } -void BScreen::notifyUngrabKeyboard() { - m_cycling = false; - focusControl().stopCyclingFocus(); -} - void BScreen::cycleFocus(int options, const ClientPattern *pat, bool reverse) { // get modifiers from event that causes this for focus order cycling XEvent ev = Fluxbox::instance()->lastEvent();

@@ -896,7 +898,7 @@ mods = FbTk::KeyUtil::instance().cleanMods(ev.xbutton.state);

if (!m_cycling && mods) { m_cycling = true; - FbTk::EventManager::instance()->grabKeyboard(*this, rootWindow().window()); + FbTk::EventManager::instance()->grabKeyboard(rootWindow().window()); } if (mods == 0) // can't stacked cycle unless there is a mod to grab
M src/Screen.hhsrc/Screen.hh

@@ -237,7 +237,6 @@ void propertyNotify(Atom atom);

void keyPressEvent(XKeyEvent &ke); void keyReleaseEvent(XKeyEvent &ke); void buttonPressEvent(XButtonEvent &be); - void notifyUngrabKeyboard(); /** * Cycles focus of windows

@@ -246,6 +245,8 @@ * @param pat specific pattern to match windows with

* @param reverse the order of cycling */ void cycleFocus(int opts = 0, const ClientPattern *pat = 0, bool reverse = false); + + bool isCycling() const { return m_cycling; } /** * Creates an empty menu with specified label