]> git.lizzy.rs Git - bspwm.git/commitdiff
New message: 'list_rules'
authorBastien Dejean <nihilhill@gmail.com>
Tue, 25 Dec 2012 18:03:35 +0000 (19:03 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Tue, 25 Dec 2012 18:03:35 +0000 (19:03 +0100)
README.md
bspwm.1
bspwm.c
bspwm.h
messages.c
rules.c
rules.h
types.c
types.h

index 9b87a754ed42b7b1ec2dd5b7702012de79061269..9e8683b3f62b594d2809dc1ce634e7db39f48fed 100644 (file)
--- a/README.md
+++ b/README.md
@@ -95,6 +95,9 @@ The following messages are handled:
     list_windows
         Return the list of managed windows (i.e. their identifiers).
 
+    list_rules
+        Return the list of rules.
+
     presel left|right|up|down [SPLIT_RATIO]
         Switch to manual mode and select the splitting direction.
 
diff --git a/bspwm.1 b/bspwm.1
index 6d0369d2217a512f4da66e744caf5e397c79a6d9..c2bc7a8f486413b9d648b1d393b9dcabc2422ef4 100644 (file)
--- a/bspwm.1
+++ b/bspwm.1
@@ -116,6 +116,9 @@ Perform a dump of each monitor.
 .BI list_windows
 Return the list of managed windows (i.e. their identifiers).
 .TP
+.BI list_rules
+Return the list of rules.
+.TP
 .BI presel " left|right|up|down [SPLIT_RATIO]"
 Switch to manual mode and select the splitting direction.
 .TP
diff --git a/bspwm.c b/bspwm.c
index ea3b0ecd468d583fba5437e32d1a45d89e298d60..9b410cdf178acdf2ba742e2e664b8db40af716e2 100644 (file)
--- a/bspwm.c
+++ b/bspwm.c
@@ -97,7 +97,7 @@ void setup(void)
 
     xcb_ewmh_set_supported(ewmh, default_screen, LENGTH(net_atoms), net_atoms);
 
-    monitor_uid = desktop_uid = client_uid = 0;
+    monitor_uid = desktop_uid = client_uid = rule_uid = 0;
     mon = last_mon = mon_head = mon_tail = NULL;
 
     bool xinerama_is_active = false;
@@ -133,7 +133,7 @@ void setup(void)
     ewmh_update_number_of_desktops();
     ewmh_update_desktop_names();
     ewmh_update_current_desktop();
-    rule_head = make_rule();
+    rule_head = rule_tail = NULL;
     frozen_pointer = make_pointer_state();
     get_pointer_position(&pointer_position);
     last_entered = XCB_NONE;
diff --git a/bspwm.h b/bspwm.h
index e7f685e2cd1203f3332daca786a1b87b9473fba4..e348d132f44442cfab0e6caa5f6e3f3c5644450a 100644 (file)
--- a/bspwm.h
+++ b/bspwm.h
@@ -14,6 +14,7 @@ unsigned int num_monitors;
 unsigned int monitor_uid;
 unsigned int desktop_uid;
 unsigned int client_uid;
+unsigned int rule_uid;
 xcb_screen_t *screen;
 uint8_t root_depth;
 FILE *status_fifo;
@@ -25,6 +26,7 @@ monitor_t *last_mon;
 monitor_t *mon_head;
 monitor_t *mon_tail;
 rule_t *rule_head;
+rule_t *rule_tail;
 pointer_state_t *frozen_pointer;
 xcb_point_t pointer_position;
 xcb_window_t last_entered;
index d41127ae433f2fda3447ba199d5a607af31781c5..feff8f66a9988026a77988ddeac5bb5e7ebcab2c 100644 (file)
@@ -10,6 +10,7 @@
 #include "helpers.h"
 #include "window.h"
 #include "tree.h"
+#include "rules.h"
 
 void process_message(char *msg, char *rsp)
 {
@@ -52,6 +53,9 @@ void process_message(char *msg, char *rsp)
     } else if (strcmp(cmd, "list_windows") == 0) {
         list_windows(rsp);
         return;
+    } else if (strcmp(cmd, "list_rules") == 0) {
+        list_rules(rsp);
+        return;
     } else if (strcmp(cmd, "close") == 0) {
         window_close(mon->desk->focus);
         return;
@@ -304,8 +308,7 @@ void process_message(char *msg, char *rsp)
                 }
                 arg = strtok(NULL, TOK_SEP);
             }
-            rule->next = rule_head;
-            rule_head = rule;
+            add_rule(rule);
         }
         return;
     } else if (strcmp(cmd, "alternate") == 0) {
diff --git a/rules.c b/rules.c
index 6feb17fac22adad72ae13a8b300f88be9e89b04e..82b99b5e3fff7720686306154133ee9e1c392973 100644 (file)
--- a/rules.c
+++ b/rules.c
@@ -7,6 +7,17 @@
 #include "ewmh.h"
 #include "rules.h"
 
+void add_rule(rule_t *r)
+{
+    if (rule_head == NULL) {
+        rule_head = rule_tail = r;
+    } else {
+        rule_tail->next = r;
+        r->prev = rule_tail;
+        rule_tail = r;
+    }
+}
+
 bool is_match(rule_t *r, xcb_window_t win)
 {
     xcb_icccm_get_wm_class_reply_t reply; 
@@ -80,3 +91,13 @@ void handle_rules(xcb_window_t win, monitor_t **m, desktop_t **d, bool *floating
         rule = rule->next;
     }
 }
+
+void list_rules(char *rsp)
+{
+    char line[MAXLEN];
+
+    for (rule_t *r = rule_head; r != NULL; r = r->next) {
+        snprintf(line, sizeof(line), "%03X %s %s %s\n", r->uid, r->cause.name, (r->effect.desktop != NULL ? r->effect.desktop->name : "\b"), (r->effect.floating ? "floating" : "\b"));
+        strncat(rsp, line, REMLEN(rsp));
+    }
+}
diff --git a/rules.h b/rules.h
index f09d21bc8962c19cbf4735e98ffe5c6da8a45909..27b718469718c966142c2602922dccea0bb03964 100644 (file)
--- a/rules.h
+++ b/rules.h
@@ -1,7 +1,9 @@
 #ifndef _RULES_H
 #define _RULES_H
 
+void add_rule(rule_t *);
 bool is_match(rule_t *, xcb_window_t);
 void handle_rules(xcb_window_t, monitor_t **, desktop_t **, bool *, bool *, bool *, bool *, bool *);
+void list_rules(char *);
 
 #endif
diff --git a/types.c b/types.c
index 7e5df6786ae6e98cdfefabd47ea3588194ffe30c..1454710f95625bc284d93b22226c8a598d9764e5 100644 (file)
--- a/types.c
+++ b/types.c
@@ -58,6 +58,7 @@ client_t *make_client(xcb_window_t win)
 rule_t *make_rule(void)
 {
     rule_t *r = malloc(sizeof(rule_t));
+    r->uid = ++rule_uid;
     r->effect.floating = false;
     r->effect.monitor = NULL;
     r->effect.desktop = NULL;
diff --git a/types.h b/types.h
index fb9a22043e35cdab67fa8a669ee292f8f497374b..8bc07ed359d9d9e3f663ce9ed79df99107e71354 100644 (file)
--- a/types.h
+++ b/types.h
@@ -161,8 +161,10 @@ typedef struct {
 
 typedef struct rule_t rule_t;
 struct rule_t {
+    unsigned int uid;
     rule_cause_t cause;
     rule_effect_t effect;
+    rule_t *prev;
     rule_t *next;
 };