From 6b2d8152ca1271159e60506e79d951869a7724b8 Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Tue, 25 Dec 2012 19:03:35 +0100 Subject: [PATCH] New message: 'list_rules' --- README.md | 3 +++ bspwm.1 | 3 +++ bspwm.c | 4 ++-- bspwm.h | 2 ++ messages.c | 7 +++++-- rules.c | 21 +++++++++++++++++++++ rules.h | 2 ++ types.c | 1 + types.h | 2 ++ 9 files changed, 41 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9b87a75..9e8683b 100644 --- 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 6d0369d..c2bc7a8 100644 --- 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 ea3b0ec..9b410cd 100644 --- 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 e7f685e..e348d13 100644 --- 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; diff --git a/messages.c b/messages.c index d41127a..feff8f6 100644 --- a/messages.c +++ b/messages.c @@ -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 6feb17f..82b99b5 100644 --- 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 f09d21b..27b7184 100644 --- 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 7e5df67..1454710 100644 --- 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 fb9a220..8bc07ed 100644 --- 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; }; -- 2.44.0