Skip to content

Instantly share code, notes, and snippets.

@Wollw
Created July 1, 2012 07:28
Show Gist options
  • Select an option

  • Save Wollw/3027327 to your computer and use it in GitHub Desktop.

Select an option

Save Wollw/3027327 to your computer and use it in GitHub Desktop.
A patch for fluxbox that adds support for NextFocus and PrevFocus that do the same thing as NextWindow and PrevWindow but don't raise the window the focus is changed to.
diff --git a/src/FocusControl.cc b/src/FocusControl.cc
index 5bf113f..bc54311 100644
--- a/src/FocusControl.cc
+++ b/src/FocusControl.cc
@@ -88,8 +88,10 @@ FocusControl::FocusControl(BScreen &screen):
}
void FocusControl::cycleFocus(const FocusableList &window_list,
- const ClientPattern *pat, bool cycle_reverse) {
+ const ClientPattern *pat, bool cycle_reverse,
+ bool noRaise) {
+ m_focus_cycling = noRaise;
if (!m_cycling_list) {
if (m_screen.isCycling())
// only set this when we're waiting for modifiers
@@ -102,8 +104,9 @@ void FocusControl::cycleFocus(const FocusableList &window_list,
Focusables::const_iterator it_begin = window_list.clientList().begin();
Focusables::const_iterator it_end = window_list.clientList().end();
- // too many things can go wrong with remembering this
m_cycling_window = find(it_begin, it_end, s_focused_window);
+
+ // too many things can go wrong with remembering this
if (m_cycling_window == it_end)
m_cycling_window = find(it_begin, it_end, s_focused_fbwindow);
@@ -159,6 +162,7 @@ void FocusControl::cycleFocus(const FocusableList &window_list,
if (!isCycling())
fbwin->raise();
+
m_cycling_last = last_client;
m_was_iconic = was_iconic;
@@ -235,7 +239,7 @@ void FocusControl::stopCyclingFocus() {
// put currently focused window to top
if (s_focused_window) {
setScreenFocusedWindow(*s_focused_window);
- if (s_focused_fbwindow)
+ if (s_focused_fbwindow && !m_focus_cycling)
s_focused_fbwindow->raise();
} else
revertFocus(m_screen);
diff --git a/src/FocusControl.hh b/src/FocusControl.hh
index c265253..3ccfc0a 100644
--- a/src/FocusControl.hh
+++ b/src/FocusControl.hh
@@ -71,8 +71,7 @@ public:
* @param pat pattern for matching focusables
* @param reverse reverse the cycle order
*/
- void cycleFocus(const FocusableList &winlist, const ClientPattern *pat = 0,
- bool reverse = false);
+ void cycleFocus(const FocusableList &winlist, const ClientPattern *pat = 0, bool reverse = false, bool noRaise = false);
void goToWindowNumber(const FocusableList &winlist, int num,
const ClientPattern *pat = 0);
@@ -111,6 +110,8 @@ public:
/// @return true if cycling is in progress
bool isCycling() const { return m_cycling_list != 0; }
+ /// @return true if we are cycling without raising
+ bool isFocusCycling() const { return m_focus_cycling; }
/// Appends a client to the front of the focus list
void addFocusBack(WinClient &client);
/// Appends a client to the front of the focus list
@@ -170,6 +171,7 @@ private:
FocusableList m_creation_order_win_list;
Focusables::const_iterator m_cycling_window;
+ bool m_focus_cycling;
const FocusableList *m_cycling_list;
Focusable *m_was_iconic;
WinClient *m_cycling_last;
diff --git a/src/Screen.cc b/src/Screen.cc
index 6757af0..f8cb3ff 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -819,7 +819,7 @@ void BScreen::buttonPressEvent(XButtonEvent &be) {
0, be.time);
}
-void BScreen::cycleFocus(int options, const ClientPattern *pat, bool reverse) {
+void BScreen::cycleFocus(int options, const ClientPattern *pat, bool reverse, bool noRaise) {
// get modifiers from event that causes this for focus order cycling
XEvent ev = Fluxbox::instance()->lastEvent();
unsigned int mods = 0;
@@ -838,7 +838,7 @@ void BScreen::cycleFocus(int options, const ClientPattern *pat, bool reverse) {
const FocusableList *win_list =
FocusableList::getListFromOptions(*this, options);
- focusControl().cycleFocus(*win_list, pat, reverse);
+ focusControl().cycleFocus(*win_list, pat, reverse, noRaise);
}
diff --git a/src/Screen.hh b/src/Screen.hh
index fe8d127..43ae630 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -228,7 +228,7 @@ public:
* @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);
+ void cycleFocus(int opts = 0, const ClientPattern *pat = 0, bool reverse = false, bool noRaise = false);
bool isCycling() const { return m_cycling; }
diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc
index ee4666e..3cf675d 100644
--- a/src/ToolFactory.cc
+++ b/src/ToolFactory.cc
@@ -93,7 +93,8 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &
} else {
std::string cmd_str = name;
- if (name == "prevwindow" || name == "nextwindow") {
+ if (name == "prevwindow" || name == "nextwindow" ||
+ name == "prevfocus" || name == "nextfocus") {
cmd_str += " (workspace=[current])";
}
diff --git a/src/Window.cc b/src/Window.cc
index f5a2fe2..d41827b 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -1762,7 +1762,7 @@ void FluxboxWindow::setFocusFlag(bool focus) {
if (focus != frame().focused())
frame().setFocus(focus);
- if (focus && screen().focusControl().isCycling())
+ if (focus && screen().focusControl().isCycling() && !screen().focusControl().isFocusCycling())
tempRaise();
else if (screen().doAutoRaise()) {
if (m_focused)
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc
index 42cc05e..c4755b9 100644
--- a/src/WorkspaceCmd.cc
+++ b/src/WorkspaceCmd.cc
@@ -169,11 +169,15 @@ FbTk::Command<void> *parseWindowList(const string &command,
return new AttachCmd(pat);
else if (command == "nextwindow")
return new NextWindowCmd(opts, pat);
+ else if (command == "nextfocus")
+ return new NextFocusCmd(opts, pat);
else if (command == "nextgroup") {
opts |= FocusableList::LIST_GROUPS;
return new NextWindowCmd(opts, pat);
} else if (command == "prevwindow")
return new PrevWindowCmd(opts, pat);
+ else if (command == "prevfocus")
+ return new PrevFocusCmd(opts, pat);
else if (command == "prevgroup") {
opts |= FocusableList::LIST_GROUPS;
return new PrevWindowCmd(opts, pat);
@@ -192,8 +196,10 @@ FbTk::Command<void> *parseWindowList(const string &command,
REGISTER_COMMAND_PARSER(attach, parseWindowList, void);
REGISTER_COMMAND_PARSER(nextwindow, parseWindowList, void);
+REGISTER_COMMAND_PARSER(nextfocus, parseWindowList, void);
REGISTER_COMMAND_PARSER(nextgroup, parseWindowList, void);
REGISTER_COMMAND_PARSER(prevwindow, parseWindowList, void);
+REGISTER_COMMAND_PARSER(prevfocus, parseWindowList, void);
REGISTER_COMMAND_PARSER(prevgroup, parseWindowList, void);
REGISTER_COMMAND_PARSER(arrangewindows, parseWindowList, void);
REGISTER_COMMAND_PARSER(arrangewindowsvertical, parseWindowList, void);
@@ -233,6 +239,18 @@ void PrevWindowCmd::execute() {
screen->cycleFocus(m_option, &m_pat, true);
}
+void NextFocusCmd::execute() {
+ BScreen *screen = Fluxbox::instance()->keyScreen();
+ if (screen != 0)
+ screen->cycleFocus(m_option, &m_pat, false, true);
+}
+
+void PrevFocusCmd::execute() {
+ BScreen *screen = Fluxbox::instance()->keyScreen();
+ if (screen != 0)
+ screen->cycleFocus(m_option, &m_pat, true, true);
+}
+
FbTk::Command<void> *GoToWindowCmd::parse(const string &command,
const string &arguments, bool trusted) {
int num, opts;
diff --git a/src/WorkspaceCmd.hh b/src/WorkspaceCmd.hh
index f4f90a6..1361594 100644
--- a/src/WorkspaceCmd.hh
+++ b/src/WorkspaceCmd.hh
@@ -94,6 +94,26 @@ private:
const ClientPattern m_pat;
};
+class NextFocusCmd: public FbTk::Command<void> {
+public:
+ explicit NextFocusCmd(int option, std::string &pat):
+ m_option(option), m_pat(pat.c_str()) { }
+ void execute();
+private:
+ const int m_option;
+ const ClientPattern m_pat;
+};
+
+class PrevFocusCmd: public FbTk::Command<void> {
+public:
+ explicit PrevFocusCmd(int option, std::string &pat):
+ m_option(option), m_pat(pat.c_str()) { }
+ void execute();
+private:
+ const int m_option;
+ const ClientPattern m_pat;
+};
+
class GoToWindowCmd: public FbTk::Command<void> {
public:
GoToWindowCmd(int num, int option, std::string &pat):
diff --git a/util/fluxbox-update_configs.cc b/util/fluxbox-update_configs.cc
index a8052a2..dae55df 100644
--- a/util/fluxbox-update_configs.cc
+++ b/util/fluxbox-update_configs.cc
@@ -370,6 +370,13 @@ void update_update_keys_file_for_nextwindow_syntax_changes(FbTk::ResourceManager
"prevgroup")))
pos = (pos > old_pos && keyfile + pos < loc) ?
pos : (loc - keyfile) + 9;
+ if ((loc = FbTk::StringUtil::strcasestr(keyfile + old_pos,
+ "nextfocus")))
+ pos = (loc - keyfile) + 10;
+ if ((loc = FbTk::StringUtil::strcasestr(keyfile + old_pos,
+ "prevfocus")))
+ pos = (pos > old_pos && keyfile + pos < loc) ?
+ pos : (loc - keyfile) + 10;
if (pos == old_pos)
break;
@@ -467,8 +474,8 @@ void update_limit_nextwindow_to_current_workspace(FbTk::ResourceManager& rm,
break;
case CMD:
if (isspace(c) || c == '}' || c == '#' || c == '!' ) {
- if (last_word == "nextwindow" || last_word == "nextgroup" ||
- last_word == "prevwindow" || last_word == "prevgroup") {
+ if (last_word == "nextwindow" || last_word == "nextgroup" || last_word == "nextfocus" ||
+ last_word == "prevwindow" || last_word == "prevgroup" || last_word == "prevfocus") {
// ':NewWindow[\n!#]' or 'MacroCmd {NextWindow}'
if (c == '\n' || c == '#' || c == '!' || c == '}') {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment