From 0116a83aa6b5275cbe3cd2bd851dc6959cacf79b Mon Sep 17 00:00:00 2001
From: Mark Tiefenbruck <mark@fluxbox.org>
Date: Thu, 21 Aug 2008 03:22:57 -0700
Subject: add SendToNextHead/SendToPrevHead commands, plus some cleanup in
 CurrentWindowCmd

---
 ChangeLog                     |  3 ++
 doc/asciidoc/fluxbox-keys.txt |  6 ++++
 doc/fluxbox-keys.5            | 12 +++++--
 src/CurrentWindowCmd.cc       | 75 +++++++++++++++++++------------------------
 src/CurrentWindowCmd.hh       | 40 +++++------------------
 5 files changed, 60 insertions(+), 76 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index be9f9db..c3882f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
  (Format: Year/Month/Day)
 Changes for 1.1
+*08/08/21:
+   * Added SendToNextHead and SendToPrevHead commands (Mark)
+     CurrentWindowCmd.cc/hh
 *08/08/20:
    * Added SetDecor key command (Mark)
      CurrentWindowCmd.cc/hh
diff --git a/doc/asciidoc/fluxbox-keys.txt b/doc/asciidoc/fluxbox-keys.txt
index 8ba93ca..aaec83c 100644
--- a/doc/asciidoc/fluxbox-keys.txt
+++ b/doc/asciidoc/fluxbox-keys.txt
@@ -292,6 +292,12 @@ two arguments;;
 	Moves the window to the given display head. Only available when fluxbox
 	has been compiled with Xinerama support.
 
+*SendToNextHead* ['offset'] / *SendToPrevHead* ['offset']::
+	Sends the current window to the next/previous display head. If you
+	specify an 'offset' greater than *1*, it will move the window that many
+	heads. If this takes the window beyond the total number of heads, it
+	will wrap around to the beginning.
+
 Workspace Commands
 ~~~~~~~~~~~~~~~~~~
 These commands affect the entire workspace (or "desktop" as it is sometimes
diff --git a/doc/fluxbox-keys.5 b/doc/fluxbox-keys.5
index 61fa49a..f4155d3 100644
--- a/doc/fluxbox-keys.5
+++ b/doc/fluxbox-keys.5
@@ -1,11 +1,11 @@
 .\"     Title: fluxbox-keys
 .\"    Author: 
 .\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
-.\"      Date: 08/20/2008
+.\"      Date: 08/21/2008
 .\"    Manual: 
 .\"    Source: 
 .\"
-.TH "FLUXBOX\-KEYS" "5" "08/20/2008" "" ""
+.TH "FLUXBOX\-KEYS" "5" "08/21/2008" "" ""
 .\" disable hyphenation
 .nh
 .\" disable justification (adjust text to left margin only)
@@ -381,6 +381,14 @@ First value becomes the focused alpha, second becomes the unfocused alpha value\
 .RS 4
 Moves the window to the given display head\. Only available when fluxbox has been compiled with Xinerama support\.
 .RE
+.PP
+\fBSendToNextHead\fR [\fIoffset\fR] / \fBSendToPrevHead\fR [\fIoffset\fR]
+.RS 4
+Sends the current window to the next/previous display head\. If you specify an
+\fIoffset\fR
+greater than
+\fB1\fR, it will move the window that many heads\. If this takes the window beyond the total number of heads, it will wrap around to the beginning\.
+.RE
 .SS "Workspace Commands"
 These commands affect the entire workspace (or "desktop" as it is sometimes called)\.
 .PP
diff --git a/src/CurrentWindowCmd.cc b/src/CurrentWindowCmd.cc
index 6918db9..95f2933 100644
--- a/src/CurrentWindowCmd.cc
+++ b/src/CurrentWindowCmd.cc
@@ -157,7 +157,7 @@ namespace {
 
 FbTk::Command<void> *parseIntCmd(const string &command, const string &args,
                            bool trusted) {
-    int num = (command == "sethead" ? 0 : 1);
+    int num = 1;
     FbTk_istringstream iss(args.c_str());
     iss >> num;
     if (command == "sethead")
@@ -167,16 +167,19 @@ FbTk::Command<void> *parseIntCmd(const string &command, const string &args,
     else if (command == "sendtonextworkspace")
         return new SendToNextWorkspaceCmd(num);
     else if (command == "sendtoprevworkspace")
-        return new SendToPrevWorkspaceCmd(num);
+        return new SendToNextWorkspaceCmd(-num);
     else if (command == "taketonextworkspace")
-        return new TakeToNextWorkspaceCmd(num);
+        return new SendToNextWorkspaceCmd(num, true);
     else if (command == "taketoprevworkspace")
-        return new TakeToPrevWorkspaceCmd(num);
+        return new SendToNextWorkspaceCmd(-num, true);
     else if (command == "sendtoworkspace")
-        // workspaces appear 1-indexed to the user, hence the minus 1
-        return new SendToWorkspaceCmd(num-1);
+        return new SendToWorkspaceCmd(num);
     else if (command == "taketoworkspace")
-        return new TakeToWorkspaceCmd(num-1);
+        return new SendToWorkspaceCmd(num, true);
+    else if (command == "sendtonexthead")
+        return new SendToNextHeadCmd(num);
+    else if (command == "sendtoprevhead")
+        return new SendToNextHeadCmd(-num);
     return 0;
 }
 
@@ -188,6 +191,8 @@ REGISTER_COMMAND_PARSER(taketonextworkspace, parseIntCmd, void);
 REGISTER_COMMAND_PARSER(taketoprevworkspace, parseIntCmd, void);
 REGISTER_COMMAND_PARSER(sendtoworkspace, parseIntCmd, void);
 REGISTER_COMMAND_PARSER(taketoworkspace, parseIntCmd, void);
+REGISTER_COMMAND_PARSER(sendtonexthead, parseIntCmd, void);
+REGISTER_COMMAND_PARSER(sendtoprevhead, parseIntCmd, void);
 
 FbTk::Command<void> *parseFocusCmd(const string &command, const string &args,
                                    bool trusted) {
@@ -205,49 +210,35 @@ REGISTER_COMMAND_PARSER(focus, parseFocusCmd, void);
 }; // end anonymous namespace
 
 void SetHeadCmd::real_execute() {
-    fbwindow().setOnHead(m_head);
+    int num = m_head;
+    int total = fbwindow().screen().numHeads();
+    if (num < 0) num += total + 1;
+    if (num < 1) num = 1;
+    if (num > total) num = total;
+    fbwindow().setOnHead(num);
 }
 
 void SendToWorkspaceCmd::real_execute() {
-    fbwindow().screen().sendToWorkspace(m_workspace_num, &fbwindow(), false);
+    int num = m_workspace_num;
+    int total = fbwindow().screen().numberOfWorkspaces();
+    if (num < 0) num += total + 1;
+    if (num < 1) num = 1;
+    if (num > total) num = total;
+    fbwindow().screen().sendToWorkspace(num-1, &fbwindow(), m_take);
 }
 
 void SendToNextWorkspaceCmd::real_execute() {
-    const int ws_nr =
-        ( fbwindow().workspaceNumber() + m_delta ) %
-          fbwindow().screen().numberOfWorkspaces();
-    fbwindow().screen().sendToWorkspace(ws_nr, &fbwindow(), false);
+    int total = fbwindow().screen().numberOfWorkspaces();
+    const int ws_nr = (total + (fbwindow().workspaceNumber() + m_delta % total)) % total;
+    fbwindow().screen().sendToWorkspace(ws_nr, &fbwindow(), m_take);
 }
 
-void SendToPrevWorkspaceCmd::real_execute() {
-    int ws_nr = (fbwindow().workspaceNumber() - m_delta );
-    if ( ws_nr < 0 )
-        ws_nr += fbwindow().screen().numberOfWorkspaces();
-
-    ws_nr = ws_nr % fbwindow().screen().numberOfWorkspaces();
-
-    fbwindow().screen().sendToWorkspace(ws_nr, &fbwindow(), false);
-}
-
-void TakeToWorkspaceCmd::real_execute() {
-    fbwindow().screen().sendToWorkspace(m_workspace_num, &fbwindow());
-}
-
-void TakeToNextWorkspaceCmd::real_execute() {
-    unsigned int ws_nr =
-        ( fbwindow().workspaceNumber() + m_delta) %
-          fbwindow().screen().numberOfWorkspaces();
-    fbwindow().screen().sendToWorkspace(ws_nr, &fbwindow());
-}
-
-void TakeToPrevWorkspaceCmd::real_execute() {
-    int ws_nr = (fbwindow().workspaceNumber() - m_delta);
-    if ( ws_nr < 0 )
-        ws_nr += fbwindow().screen().numberOfWorkspaces();
-
-    ws_nr = ws_nr % fbwindow().screen().numberOfWorkspaces();
-
-    fbwindow().screen().sendToWorkspace(ws_nr, &fbwindow());
+void SendToNextHeadCmd::real_execute() {
+    int total = fbwindow().screen().numHeads();
+    if (total < 2)
+        return;
+    int num = (total + fbwindow().getOnHead() - 1 + (m_delta % total)) % total;
+    fbwindow().setOnHead(1 + num);
 }
 
 void GoToTabCmd::real_execute() {
diff --git a/src/CurrentWindowCmd.hh b/src/CurrentWindowCmd.hh
index 9b7d181..32cc5f0 100644
--- a/src/CurrentWindowCmd.hh
+++ b/src/CurrentWindowCmd.hh
@@ -74,59 +74,35 @@ private:
 
 class SendToWorkspaceCmd: public WindowHelperCmd {
 public:
-    explicit SendToWorkspaceCmd(int workspace_num):m_workspace_num(workspace_num) { }
+    explicit SendToWorkspaceCmd(int workspace_num, bool take = false):
+        m_workspace_num(workspace_num), m_take(take) { }
 protected:
     void real_execute();
 private:
     const int m_workspace_num;
+    const bool m_take;
 };
 
 class SendToNextWorkspaceCmd: public WindowHelperCmd {
 public:
-    explicit SendToNextWorkspaceCmd(int delta):m_delta(delta) { }
+    explicit SendToNextWorkspaceCmd(int delta, bool take = false):
+        m_delta(delta), m_take(take) { }
 protected:
     void real_execute();
 private:
     const int m_delta;
+    const bool m_take;
 };
 
-class SendToPrevWorkspaceCmd: public WindowHelperCmd {
+class SendToNextHeadCmd: public WindowHelperCmd {
 public:
-    explicit SendToPrevWorkspaceCmd(int delta):m_delta(delta) { }
+    explicit SendToNextHeadCmd(int delta): m_delta(delta) { }
 protected:
     void real_execute();
 private:
     const int m_delta;
 };
 
-class TakeToWorkspaceCmd : public WindowHelperCmd {
-public:
-    explicit TakeToWorkspaceCmd(int workspace_num) : m_workspace_num(workspace_num) { }
-protected:
-    void real_execute();
-private:
-    const int m_workspace_num;
-};
-
-class TakeToNextWorkspaceCmd : public WindowHelperCmd {
-public:
-    explicit TakeToNextWorkspaceCmd(int delta) : m_delta(delta) { }
-protected:
-    void real_execute();
-private:
-    const int m_delta;
-};
-
-class TakeToPrevWorkspaceCmd : public WindowHelperCmd {
-public:
-    explicit TakeToPrevWorkspaceCmd(int delta) : m_delta(delta) { }
-protected:
-    void real_execute();
-private:
-    const int m_delta;
-};
-
-
 // goto tab
 class GoToTabCmd: public WindowHelperCmd {
 public:
-- 
cgit v0.11.2