[PATCH] Add consequence to move a client to a monitor

Wesley Merkel ooesili at gmail.com
Sat Mar 15 07:01:36 CET 2014


The new 'monitor' consequence will move the client to the specified
monitor. It will interact with the 'tag' consequence if it is also
specified for the given client. This behaviour is documented in
doc/herbstluftwm.txt, so I will not go into it here.
---
 NEWS                 |  1 +
 doc/herbstluftwm.txt |  7 +++++++
 src/clientlist.c     |  9 +++++++++
 src/rules.c          | 11 +++++++++++
 src/rules.h          |  1 +
 5 files changed, 29 insertions(+)

diff --git a/NEWS b/NEWS
index 35fc160..4f1a3b7 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,7 @@ Current git version
     * add completion to the mousebind command
     * add mouse function call to call commands on mouse button press
     * add setting update_dragged_clients
+    * new rule consequence: monitor
 
 Release 0.5.3 on 2013-12-24
 ---------------------------
diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
index 8137dda..c973c2e 100644
--- a/doc/herbstluftwm.txt
+++ b/doc/herbstluftwm.txt
@@ -1120,6 +1120,13 @@ Each 'CONSEQUENCE' consists of a 'NAME'='VALUE' pair. Valid 'NAMES' are:
 +tag+::
     moves the client to tag 'VALUE'.
 
++monitor+::
+    moves the client to the tag on monitor 'VALUE'. If the tag consequence was
+    also specified, move the client to that tag, then display that tag on
+    monitor 'VALUE'. In the case where the tag consequence is also specified, if
+    either of the tag or monitor values do not refer to an actual monitor or
+    tag, hlwm will behave as if that consequence was not set.
+
 +focus+::
     decides whether the client gets the input focus on his tag.  The default is
     *off*. 'VALUE' can be *on*, *off* or *toggle*.
diff --git a/src/clientlist.c b/src/clientlist.c
index a6d2821..56721f2 100644
--- a/src/clientlist.c
+++ b/src/clientlist.c
@@ -245,6 +245,15 @@ HSClient* manage_client(Window win) {
     if (changes.tag_name) {
         client->tag = find_tag(changes.tag_name->str);
     }
+    if (changes.monitor_name) {
+        HSMonitor *monitor = string_to_monitor(changes.monitor_name->str);
+        if (monitor) {
+            // a valid tag was not already found, use the target monitor's tag
+            if (!client->tag) { client->tag = monitor->tag; }
+            // a tag was already found, display it on the target monitor
+            else { monitor_set_tag(monitor, client->tag); }
+        }
+    }
 
     // Reuse the keymask string
     client->keymask = changes.keymask;
diff --git a/src/rules.c b/src/rules.c
index 46defad..3800ee2 100644
--- a/src/rules.c
+++ b/src/rules.c
@@ -64,6 +64,7 @@ DECLARE_CONSEQUENCE(consequence_ewmhrequests);
 DECLARE_CONSEQUENCE(consequence_ewmhnotify);
 DECLARE_CONSEQUENCE(consequence_hook);
 DECLARE_CONSEQUENCE(consequence_keymask);
+DECLARE_CONSEQUENCE(consequence_monitor);
 
 /// GLOBALS ///
 
@@ -93,6 +94,7 @@ static HSConsequenceType g_consequence_types[] = {
     { "ewmhnotify",     consequence_ewmhnotify      },
     { "hook",           consequence_hook            },
     { "keymask",        consequence_keymask         },
+    { "monitor",        consequence_monitor         },
 };
 
 static GQueue g_rules = G_QUEUE_INIT; // a list of HSRule* elements
@@ -832,3 +834,12 @@ void consequence_keymask(HSConsequence* cons,
         changes->keymask = g_string_new(cons->value.str);
     }
 }
+
+void consequence_monitor(HSConsequence* cons, HSClient* client,
+                            HSClientChanges* changes) {
+    if (changes->monitor_name) {
+        g_string_assign(changes->monitor_name, cons->value.str);
+    } else {
+        changes->monitor_name = g_string_new(cons->value.str);
+    }
+}
diff --git a/src/rules.h b/src/rules.h
index 07a6584..b7f1202 100644
--- a/src/rules.h
+++ b/src/rules.h
@@ -57,6 +57,7 @@ typedef struct {
 
 typedef struct {
     GString*        tag_name;
+    GString*        monitor_name;
     GString*        tree_index;
     bool            focus; // if client should get focus
     bool            switchtag; // if the tag may be switched for focusing it
-- 
1.9.0




More information about the hlwm mailing list