From 22aa93c56de131b80dfb161615650c4fb6cf6832 Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Tue, 5 Aug 2008 05:00:48 -0700 Subject: fix the Focus key command --- ChangeLog | 2 ++ doc/asciidoc/fluxbox-keys.txt | 9 ++++++--- doc/fluxbox-keys.5 | 14 +++++++++++--- src/CurrentWindowCmd.cc | 16 ++++++++++++---- src/CurrentWindowCmd.hh | 10 ++++++++++ src/FocusableList.cc | 11 ++++++++++- src/FocusableList.hh | 2 ++ 7 files changed, 53 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index af47839..f5020fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ (Format: Year/Month/Day) Changes for 1.1 *08/08/05: + * Fixed Focus key command (Mark) + CurrentWindowCmd.cc/hh FocusableList.cc/hh * Added new SetLayer key command (Mark) CurrentWindowCmd.cc/hh * Make ShowDesktop command toggle between showing windows and desktop (Mark) diff --git a/doc/asciidoc/fluxbox-keys.txt b/doc/asciidoc/fluxbox-keys.txt index 70f3b66..e52ffa8 100644 --- a/doc/asciidoc/fluxbox-keys.txt +++ b/doc/asciidoc/fluxbox-keys.txt @@ -163,10 +163,13 @@ BottomRight* Window Commands ~~~~~~~~~~~~~~~ -These commands affect only the currently focused window. +These commands ordinarily affect only the currently focused window. The +*OnWindow* modifier and *ForEach* command may affect the window that is used. -*Activate* | *Focus*:: - Set the focus to the window matching the argument, and raise it. +*Activate* ['pattern'] | *Focus* ['pattern']:: + Set the focus to the window matching the argument. If 'pattern' is + omitted, this may be used with the *OnWindow* modifier to set the + focus. See *CLIENT PATTERNS* for more about the 'pattern' arguments. *Minimize* | *MinimizeWindow* | *Iconify*:: Minimize the current window, equivalent to the window button. diff --git a/doc/fluxbox-keys.5 b/doc/fluxbox-keys.5 index aa0523a..75af5ab 100644 --- a/doc/fluxbox-keys.5 +++ b/doc/fluxbox-keys.5 @@ -165,11 +165,19 @@ By default \fIcorner\fR is \fBBottomRight\fR, but may be overridden with one of: Start dragging to add this window to another\'s tabgroup\. .RE .SS "Window Commands" -These commands affect only the currently focused window\. +These commands ordinarily affect only the currently focused window\. The \fBOnWindow\fR modifier and \fBForEach\fR command may affect the window that is used\. .PP -\fBActivate\fR | \fBFocus\fR +\fBActivate\fR [\fIpattern\fR] | \fBFocus\fR [\fIpattern\fR] .RS 4 -Set the focus to the window matching the argument, and raise it\. +Set the focus to the window matching the argument\. If +\fIpattern\fR +is omitted, this may be used with the +\fBOnWindow\fR +modifier to set the focus\. See +\fBCLIENT PATTERNS\fR +for more about the +\fIpattern\fR +arguments\. .RE .PP \fBMinimize\fR | \fBMinimizeWindow\fR | \fBIconify\fR diff --git a/src/CurrentWindowCmd.cc b/src/CurrentWindowCmd.cc index 42ee69c..9253058 100644 --- a/src/CurrentWindowCmd.cc +++ b/src/CurrentWindowCmd.cc @@ -56,8 +56,6 @@ FbTk::Command *createCurrentWindowCmd(const std::string &command, return new CurrentWindowCmd(&FluxboxWindow::lower); else if (command == "lowerlayer") return new CurrentWindowCmd(&FluxboxWindow::lowerLayer); - else if (command == "activate" || command == "focus") - return new CurrentWindowCmd((void (FluxboxWindow::*)())&FluxboxWindow::focus); else if (command == "close") return new CurrentWindowCmd(&FluxboxWindow::close); else if (command == "killwindow" || command == "kill") @@ -98,8 +96,6 @@ REGISTER_COMMAND_PARSER(raise, createCurrentWindowCmd, void); REGISTER_COMMAND_PARSER(raiselayer, createCurrentWindowCmd, void); REGISTER_COMMAND_PARSER(lower, createCurrentWindowCmd, void); REGISTER_COMMAND_PARSER(lowerlayer, createCurrentWindowCmd, void); -REGISTER_COMMAND_PARSER(activate, createCurrentWindowCmd, void); -REGISTER_COMMAND_PARSER(focus, createCurrentWindowCmd, void); REGISTER_COMMAND_PARSER(close, createCurrentWindowCmd, void); REGISTER_COMMAND_PARSER(killwindow, createCurrentWindowCmd, void); REGISTER_COMMAND_PARSER(kill, createCurrentWindowCmd, void); @@ -252,6 +248,18 @@ void GoToTabCmd::real_execute() { (*it)->focus(); } +REGISTER_COMMAND_WITH_ARGS(activate, FocusCmd, void); +REGISTER_COMMAND_WITH_ARGS(focus, FocusCmd, void); + +void FocusCmd::real_execute() { + Focusable *win = 0; + if (!m_pat.error()) + win = fbwindow().screen().focusControl().focusedOrderWinList().find(m_pat); + if (!win) + win = &fbwindow(); + win->focus(); +} + REGISTER_COMMAND(startmoving, StartMovingCmd, void); void StartMovingCmd::real_execute() { diff --git a/src/CurrentWindowCmd.hh b/src/CurrentWindowCmd.hh index 5d381a2..d70e2fb 100644 --- a/src/CurrentWindowCmd.hh +++ b/src/CurrentWindowCmd.hh @@ -137,6 +137,16 @@ private: const int m_tab_num; }; +// focus the window +class FocusCmd: public WindowHelperCmd { +public: + explicit FocusCmd(const std::string &pat): m_pat(pat.c_str()) { } +protected: + void real_execute(); +private: + const ClientPattern m_pat; +}; + // begin moving with mouse class StartMovingCmd: public WindowHelperCmd { public: diff --git a/src/FocusableList.cc b/src/FocusableList.cc index 70f415e..d15e10a 100644 --- a/src/FocusableList.cc +++ b/src/FocusableList.cc @@ -286,10 +286,19 @@ void FocusableList::reset() { bool FocusableList::contains(const Focusable &win) const { Focusables::const_iterator it = m_list.begin(), it_end = m_list.end(); - it = find(it, it_end, &win); + it = std::find(it, it_end, &win); return (it != it_end); } +Focusable *FocusableList::find(const ClientPattern &pat) const { + Focusables::const_iterator it = m_list.begin(), it_end = m_list.end(); + for (; it != it_end; ++it) { + if (pat.match(**it)) + return *it; + } + return 0; +} + void FocusableList::attachChild(FocusableList &child) const { m_addsig.attach(&child); m_removesig.attach(&child); diff --git a/src/FocusableList.hh b/src/FocusableList.hh index cdf6bec..a72e2f0 100644 --- a/src/FocusableList.hh +++ b/src/FocusableList.hh @@ -70,6 +70,8 @@ public: bool empty() const { return m_list.empty(); } /// does the list contain the given window? bool contains(const Focusable &win) const; + /// find the first window matching the pattern + Focusable *find(const ClientPattern &pattern) const; /** @name signals -- cgit v0.11.2