From 6adf19fedaa51315f98737c600872a62f068b883 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Wed, 26 Jul 2023 02:35:37 +0200 Subject: [PATCH] [wip] feature: Allow blocking wayland protocols Missing: - [ ] docs (including it only applying to new windows after --reconfigure) - [ ] discuss config naming and format --- include/config/rcxml.h | 6 ++++++ src/config/rcxml.c | 29 +++++++++++++++++++++++++++++ src/server.c | 8 ++++++++ 3 files changed, 43 insertions(+) diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 88a2ee0f..8e14a250 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -31,6 +31,11 @@ struct window_switcher_field { struct wl_list link; /* struct rcxml.window_switcher.fields */ }; +struct blocked_protocol { + struct wl_list link; /* struct rcxml.blocked_protocols */ + char *interface_name; +}; + struct rcxml { char *config_dir; @@ -94,6 +99,7 @@ struct rcxml { } window_switcher; struct wl_list window_rules; /* struct window_rule.link */ + struct wl_list blocked_protocols; /* struct blocked_protocol.link */ }; extern struct rcxml rc; diff --git a/src/config/rcxml.c b/src/config/rcxml.c index f0af0b51..2bad6665 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -37,6 +37,7 @@ static bool in_mousebind; static bool in_libinput_category; static bool in_window_switcher_field; static bool in_window_rules; +static bool in_blocked_protocols; static struct usable_area_override *current_usable_area_override; static struct keybind *current_keybind; @@ -166,6 +167,16 @@ fill_window_rule(char *nodename, char *content) } } +static void +fill_blocked_protocols(char *nodename, char *content) +{ + if (!strcasecmp(nodename, "name.interface.blockedProtocols")) { + struct blocked_protocol *proto = znew(*proto); + proto->interface_name = xstrdup(content); + wl_list_append(&rc.blocked_protocols, &proto->link); + } +} + static void fill_window_switcher_field(char *nodename, char *content) { @@ -536,6 +547,10 @@ entry(xmlNode *node, char *nodename, char *content) fill_window_rule(nodename, content); return; } + if (in_blocked_protocols) { + fill_blocked_protocols(nodename, content); + return; + } /* handle nodes without content, e.g. */ if (!strcmp(nodename, "default.keyboard")) { @@ -736,6 +751,12 @@ xml_tree_walk(xmlNode *node) in_window_rules = false; continue; } + if (!strcasecmp((char *)n->name, "blockedProtocols")) { + in_blocked_protocols = true; + traverse(n); + in_blocked_protocols = false; + continue; + } traverse(n); } } @@ -776,6 +797,7 @@ rcxml_init(void) wl_list_init(&rc.regions); wl_list_init(&rc.window_switcher.fields); wl_list_init(&rc.window_rules); + wl_list_init(&rc.blocked_protocols); } has_run = true; @@ -1318,6 +1340,13 @@ rcxml_finish(void) rule_destroy(rule); } + struct blocked_protocol *proto, *proto_tmp; + wl_list_for_each_safe(proto, proto_tmp, &rc.blocked_protocols, link) { + wl_list_remove(&proto->link); + zfree(proto->interface_name); + zfree(proto); + } + /* Reset state vars for starting fresh when Reload is triggered */ current_usable_area_override = NULL; current_keybind = NULL; diff --git a/src/server.c b/src/server.c index c781f53d..620c7fb9 100644 --- a/src/server.c +++ b/src/server.c @@ -180,7 +180,15 @@ server_global_filter(const struct wl_client *client, const struct wl_global *glo } } #endif + struct blocked_protocol *proto; + wl_list_for_each(proto, &rc.blocked_protocols, link) { + if (!strcmp(iface->name, proto->interface_name)) { + wlr_log(WLR_INFO, "blocking protocol %s", proto->interface_name); + return false; + } + } + wlr_log(WLR_DEBUG, "protocol not blocked: %s", iface->name); return true; }