[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UPDATE: command: shift_cycle_monitor



Hi Tyler,

On Wed, Nov 28, 2012 at 04:32:13PM -0800, Tyler Thomas Hart wrote:
> As requested by Thorsten, here are my patches in plain text and not
> archived.
> 
>   shift_cycle_monitor [DELTA]

I renamed it to "shift_to_monitor" and did the following with your
patch:

  - I removed many trailing spaces,
  - corrected the commit message,
  - made DELTA mandatory, so that it becomes similar to move_index.
  - DELTA now behaves similar to the DELTA for move_index.
  - To avoid strange effects with negative numbers, I added the usage of
    the MOD macro from utils.h instead of the % operator.
  - And also similar to the patches before: full name in the author
    field and a new NEWS entry.

Please check the attached patch give me feedback or an acknowledgement
to merge it.

Regards,
Thorsten
>From 5b84002aa129741ee0c13682bb323a676776d623 Mon Sep 17 00:00:00 2001
From: Tyler Thomas Hart <htyler _at_ pdx _dot_ edu>
Date: Wed, 28 Nov 2012 15:32:02 -0800
Subject: [PATCH] Add the command shift_to_monitor

---
 NEWS                 |  1 +
 doc/herbstluftwm.txt |  5 +++++
 src/main.c           |  1 +
 src/monitor.c        | 21 +++++++++++++++++++++
 src/monitor.h        |  2 ++
 5 files changed, 30 insertions(+)

diff --git a/NEWS b/NEWS
index 2559bcd..fb62fca 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,7 @@ Changes:
     * floating, fullscreen, pseudotile: default to toggle if no argument is
       given
     * add error messages for herbstclient
+    * new command: shift_to_monitor
 
 Release: 0.4.1 on 2012-08-30
 ----------------------------
diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
index c617114..eee9a6f 100644
--- a/doc/herbstluftwm.txt
+++ b/doc/herbstluftwm.txt
@@ -367,6 +367,11 @@ shift ['-i'|'-e'] 'DIRECTION'::
     If 'focus_follows_shift' is set, then focus stays in the window; otherwise
     it stays in the frame.
 
+shift_to_monitor 'INDEX'::
+    Moves the focused window to the tag on monitor with the specified 'INDEX'.
+    If 'INDEX' starts with +++ or +-+, then 'INDEX' is treated relative to the
+    current monitor.
+
 remove::
     Removes focused frame and merges its windows to its neighbour frame.
 
diff --git a/src/main.c b/src/main.c
index 1dfea90..e0dc3e2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -111,6 +111,7 @@ CommandBinding g_commands[] = {
     CMD_BIND(             "resize",         frame_change_fraction_command),
     CMD_BIND(             "focus",          frame_focus_command),
     CMD_BIND(             "shift",          frame_move_window_command),
+    CMD_BIND(             "shift_to_monitor",shift_to_monitor),
     CMD_BIND_NO_OUTPUT(   "remove",         frame_remove_command),
     CMD_BIND(             "set",            settings_set_command),
     CMD_BIND(             "toggle",         settings_toggle),
diff --git a/src/monitor.c b/src/monitor.c
index ea99018..a3be74c 100644
--- a/src/monitor.c
+++ b/src/monitor.c
@@ -1024,3 +1024,24 @@ void monitor_restack(HSMonitor* monitor) {
     g_free(buf);
 }
 
+int shift_to_monitor(int argc, char** argv, GString* output) {
+    if (argc <= 1) {
+        return HERBST_NEED_MORE_ARGS;
+    }
+    char* index_str = argv[1];
+    bool is_relative = array_find("+-", 2, sizeof(char), &index_str[0]) >= 0;
+    int i = atoi(index_str);
+    if (is_relative) {
+        i += g_cur_monitor;
+        i = MOD(i, g_monitors->len);
+    }
+    HSMonitor* monitor = monitor_with_index(i);
+    if (!monitor) {
+        g_string_append_printf(output,
+            "%s: Invalid monitor\n", index_str);
+        return HERBST_INVALID_ARGUMENT;
+    }
+    tag_move_focused_client(monitor->tag);
+    return 0;
+}
+
diff --git a/src/monitor.h b/src/monitor.h
index 57e036c..1b7d9dd 100644
--- a/src/monitor.h
+++ b/src/monitor.h
@@ -93,5 +93,7 @@ bool detect_monitors_xinerama(XRectangle** ret_rects, size_t* ret_count);
 bool detect_monitors_simple(XRectangle** ret_rects, size_t* ret_count);
 int detect_monitors_command(int argc, char **argv, GString* output);
 
+int shift_to_monitor(int argc, char** argv, GString* output);
+
 #endif
 
-- 
1.8.0