From be2f40a10d9c11a56c0c53307be5557a127027e9 Mon Sep 17 00:00:00 2001 From: markt Date: Sun, 23 Jul 2006 09:51:54 +0000 Subject: use a timer to make sure focus always reverts if possible --- ChangeLog | 3 +++ src/FbTk/FbWindow.hh | 2 +- src/WinClient.cc | 6 ------ src/WinClient.hh | 4 ---- src/Window.cc | 2 +- src/fluxbox.cc | 26 ++++++++++++++++++++------ src/fluxbox.hh | 5 ++++- 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4efb323..fcb2d7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ (Format: Year/Month/Day) Changes for 1.0rc3: +*06/07/23: + * Use a timer to make sure focus always reverts if possible (Mark) + fluxbox.cc/hh and reverse patch from 06/07/20 *06/07/22: * Ewmh compliance updates: (Mark) - implemented _NET_WM_MOVERESIZE_CANCEL (new in version 1.4.draft-1) diff --git a/src/FbTk/FbWindow.hh b/src/FbTk/FbWindow.hh index 0226121..c5494b0 100644 --- a/src/FbTk/FbWindow.hh +++ b/src/FbTk/FbWindow.hh @@ -137,7 +137,7 @@ public: } virtual void lower(); virtual void raise(); - virtual void setInputFocus(int revert_to, int time); + void setInputFocus(int revert_to, int time); /// defines a cursor for this window void setCursor(Cursor cur); #ifdef NOT_USED diff --git a/src/WinClient.cc b/src/WinClient.cc index daf3d42..73b5d45 100644 --- a/src/WinClient.cc +++ b/src/WinClient.cc @@ -66,7 +66,6 @@ WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin):FbTk::Fb m_modal(0), send_focus_message(false), send_close_message(false), - m_waiting_focus(false), m_win_gravity(0), m_title(""), m_icon_title(""), m_class_name(""), m_instance_name(""), @@ -189,11 +188,6 @@ bool WinClient::sendFocus() { return true; } -void WinClient::setInputFocus(int revert_to, int time) { - FbTk::FbWindow::setInputFocus(revert_to, time); - m_waiting_focus = true; -} - void WinClient::sendClose(bool forceful) { if (forceful || !send_close_message) XKillClient(display(), window()); diff --git a/src/WinClient.hh b/src/WinClient.hh index 4808807..3a9d792 100644 --- a/src/WinClient.hh +++ b/src/WinClient.hh @@ -53,9 +53,6 @@ public: bool sendFocus(); // returns whether we sent a message or not // i.e. whether we assume the focus will get taken bool acceptsFocus() const; // will this window accept focus (according to hints) - void setInputFocus(int revert_to, int time); - inline bool isWaitingFocus() { return m_waiting_focus; } - void receivedFocus() { m_waiting_focus = false; m_focussig.notify(); } void sendClose(bool forceful = false); // not aware of anything that makes this false at present inline bool isClosable() const { return true; } @@ -200,7 +197,6 @@ private: // or indicates that we are modal if don't have any transients int m_modal; bool send_focus_message, send_close_message; - bool m_waiting_focus; int m_win_gravity; diff --git a/src/Window.cc b/src/Window.cc index 265d948..f2b57f2 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -2112,7 +2112,7 @@ void FluxboxWindow::setFocusFlag(bool focus) { if (was_focused != focus) { m_focussig.notify(); if (m_client) - m_client->receivedFocus(); + m_client->focusSig().notify(); } } diff --git a/src/fluxbox.cc b/src/fluxbox.cc index b5b5ddb..abe43d2 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -221,6 +221,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile m_masked(0), m_rc_file(rcfilename ? rcfilename : ""), m_argv(argv), m_argc(argc), + m_revert_screen(0), m_starting(true), m_restarting(false), m_shutdown(false), @@ -273,6 +274,13 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile m_reconfig_timer.setTimeout(to); m_reconfig_timer.setCommand(reconfig_cmd); m_reconfig_timer.fireOnce(true); + + // set a timer to revert focus on FocusOut, in case no FocusIn arrives + FbTk::RefCount revert_cmd(new FbTk::SimpleCommand(*this, &Fluxbox::revert_focus)); + m_revert_timer.setCommand(revert_cmd); + m_revert_timer.setTimeout(to); + m_revert_timer.fireOnce(true); + // XSynchronize(disp, True); s_singleton = this; @@ -681,9 +689,6 @@ void Fluxbox::handleEvent(XEvent * const e) { break; // found the screen, no more search } } - - if (screen != 0) - FocusControl::revertFocus(*screen); } // try FbTk::EventHandler first @@ -877,9 +882,12 @@ void Fluxbox::handleEvent(XEvent * const e) { #endif // DEBUG } else if (winclient && winclient == FocusControl::focusedWindow() && (winclient->fbwindow() == 0 - || !winclient->fbwindow()->isMoving())) + || !winclient->fbwindow()->isMoving())) { // we don't unfocus a moving window FocusControl::setFocusedWindow(0); + m_revert_screen = &winclient->screen(); + m_revert_timer.start(); + } } break; case ClientMessage: @@ -1300,8 +1308,9 @@ void Fluxbox::update(FbTk::Subject *changedsub) { FocusControl::unfocusWindow(client); // make sure nothing else uses this window before focus reverts FocusControl::setFocusedWindow(0); - } else if (!FocusControl::focusedWindow() && client.isWaitingFocus()) - FocusControl::revertFocus(screen); + m_revert_screen = &screen; + m_revert_timer.start(); + } } } @@ -1776,6 +1785,11 @@ void Fluxbox::timed_reconfigure() { m_reconfigure_wait = m_reread_menu_wait = false; } +void Fluxbox::revert_focus() { + if (m_revert_screen && !FocusControl::focusedWindow()) + FocusControl::revertFocus(*m_revert_screen); +} + bool Fluxbox::validateClient(const WinClient *client) const { WinClientMap::const_iterator it = find_if(m_window_search.begin(), diff --git a/src/fluxbox.hh b/src/fluxbox.hh index 7fa5f5d..e7bc18d 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -185,6 +185,7 @@ public: void attachSignals(WinClient &winclient); void timed_reconfigure(); + void revert_focus(); bool isStartup() const { return m_starting; } bool isRestarting() const { return m_restarting; } @@ -289,7 +290,9 @@ private: XEvent m_last_event; - FbTk::Timer m_reconfig_timer; ///< when we execute reconfig command we must wait at least to next event round + ///< when we execute reconfig command we must wait until next event round + FbTk::Timer m_reconfig_timer, m_revert_timer; + BScreen *m_revert_screen; std::auto_ptr m_key; -- cgit v0.11.2