2023-04-28 21:41:41 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2025-07-28 01:02:01 -04:00
|
|
|
#include "window-rules.h"
|
2023-04-28 21:41:41 +01:00
|
|
|
#include <assert.h>
|
2023-05-09 21:20:05 +01:00
|
|
|
#include <stdbool.h>
|
2023-04-28 21:41:41 +01:00
|
|
|
#include <strings.h>
|
|
|
|
|
#include "action.h"
|
|
|
|
|
#include "config/rcxml.h"
|
|
|
|
|
#include "labwc.h"
|
|
|
|
|
#include "view.h"
|
|
|
|
|
|
2023-06-07 21:44:38 +01:00
|
|
|
static bool
|
2024-04-20 07:58:08 +02:00
|
|
|
other_instances_exist(struct view *self, struct view_query *query)
|
2023-06-07 21:44:38 +01:00
|
|
|
{
|
2026-03-19 12:05:43 -04:00
|
|
|
struct wl_list *views = &server.views;
|
2023-06-07 21:44:38 +01:00
|
|
|
struct view *view;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(view, views, link) {
|
2024-04-20 07:58:08 +02:00
|
|
|
if (view != self && view_matches_query(view, query)) {
|
2024-04-19 20:15:49 +02:00
|
|
|
return true;
|
2023-06-07 21:44:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-09 21:20:05 +01:00
|
|
|
static bool
|
|
|
|
|
view_matches_criteria(struct window_rule *rule, struct view *view)
|
|
|
|
|
{
|
2024-10-31 09:59:22 -04:00
|
|
|
struct view_query query = {
|
|
|
|
|
.identifier = rule->identifier,
|
|
|
|
|
.title = rule->title,
|
|
|
|
|
.window_type = rule->window_type,
|
|
|
|
|
.sandbox_engine = rule->sandbox_engine,
|
|
|
|
|
.sandbox_app_id = rule->sandbox_app_id,
|
2025-08-25 18:54:22 +09:00
|
|
|
/* Must be synced with view_query_create() */
|
2024-10-31 09:59:22 -04:00
|
|
|
.maximized = VIEW_AXIS_INVALID,
|
2025-08-25 18:54:22 +09:00
|
|
|
.decoration = LAB_SSD_MODE_INVALID,
|
2024-10-31 09:59:22 -04:00
|
|
|
};
|
2024-04-20 07:58:08 +02:00
|
|
|
|
|
|
|
|
if (rule->match_once && other_instances_exist(view, &query)) {
|
2023-05-09 21:20:05 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2024-10-31 09:59:22 -04:00
|
|
|
|
2024-04-20 07:58:08 +02:00
|
|
|
return view_matches_query(view, &query);
|
2023-05-09 21:20:05 +01:00
|
|
|
}
|
|
|
|
|
|
2023-04-28 21:41:41 +01:00
|
|
|
void
|
|
|
|
|
window_rules_apply(struct view *view, enum window_rule_event event)
|
|
|
|
|
{
|
|
|
|
|
struct window_rule *rule;
|
|
|
|
|
wl_list_for_each(rule, &rc.window_rules, link) {
|
2023-05-09 21:20:05 +01:00
|
|
|
if (rule->event != event) {
|
2023-04-28 21:41:41 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2023-05-09 21:20:05 +01:00
|
|
|
if (view_matches_criteria(rule, view)) {
|
tree-wide: auto-replace of (struct server *)
#!/bin/bash
read -r -d '' EXPRS << EOF
s/xwayland->server/xwayland->svr/g;
s/\t*struct server \*server;\n//g;
s/\t*struct server \*server =.*?;\n//gs;
s/\t*.* = ([a-z_]*->)*server[;,]\n//g;
s/\{\n\n/\{\n/g;
s/\n\n+/\n\n/g;
s/\(\s*struct server \*server\)/(void)/g;
s/\(\s*struct server \*server,\s*/(/g;
s/,\s*struct server \*server\)/)/g;
s/,\s*struct server \*server,\s*/, /g;
s/\(\s*([a-z_]*->)*server\)/()/g;
s/\(\s*([a-z_]*->)*server,\s*/(/g;
s/,\s*([a-z_]*->)*server\)/)/g;
s/,\s*([a-z_]*->)*server,\s*/, /g;
s/([a-z_]*->)*server->/g_server./g;
s/xwayland->svr/xwayland->server/g;
EOF
find src include \( -name \*.c -o -name \*.h \) -exec \
perl -0777 -i -pe "$EXPRS" \{\} \;
2026-02-23 11:56:39 -05:00
|
|
|
actions_run(view, &rule->actions, NULL);
|
2023-04-28 21:41:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum property
|
|
|
|
|
window_rules_get_property(struct view *view, const char *property)
|
|
|
|
|
{
|
|
|
|
|
assert(property);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We iterate in reverse here because later items in list have higher
|
|
|
|
|
* priority. For example, in the config below we want the return value
|
|
|
|
|
* for foot's "serverDecoration" property to be "default".
|
|
|
|
|
*
|
|
|
|
|
* <windowRules>
|
|
|
|
|
* <windowRule identifier="*" serverDecoration="no"/>
|
|
|
|
|
* <windowRule identifier="foot" serverDecoration="default"/>
|
|
|
|
|
* </windowRules>
|
|
|
|
|
*/
|
|
|
|
|
struct window_rule *rule;
|
|
|
|
|
wl_list_for_each_reverse(rule, &rc.window_rules, link) {
|
|
|
|
|
/*
|
|
|
|
|
* Only return if property != LAB_PROP_UNSPECIFIED otherwise a
|
|
|
|
|
* <windowRule> which does not set a particular property
|
|
|
|
|
* attribute would still return here if that property was asked
|
|
|
|
|
* for.
|
|
|
|
|
*/
|
2023-05-09 21:20:05 +01:00
|
|
|
if (view_matches_criteria(rule, view)) {
|
2023-05-20 10:20:36 +01:00
|
|
|
if (rule->server_decoration
|
|
|
|
|
&& !strcasecmp(property, "serverDecoration")) {
|
|
|
|
|
return rule->server_decoration;
|
|
|
|
|
}
|
|
|
|
|
if (rule->skip_taskbar
|
|
|
|
|
&& !strcasecmp(property, "skipTaskbar")) {
|
|
|
|
|
return rule->skip_taskbar;
|
|
|
|
|
}
|
|
|
|
|
if (rule->skip_window_switcher
|
|
|
|
|
&& !strcasecmp(property, "skipWindowSwitcher")) {
|
|
|
|
|
return rule->skip_window_switcher;
|
2023-04-28 21:41:41 +01:00
|
|
|
}
|
2023-09-03 14:01:40 +02:00
|
|
|
if (rule->ignore_focus_request
|
|
|
|
|
&& !strcasecmp(property, "ignoreFocusRequest")) {
|
|
|
|
|
return rule->ignore_focus_request;
|
|
|
|
|
}
|
2024-04-13 20:36:09 +02:00
|
|
|
if (rule->ignore_configure_request
|
|
|
|
|
&& !strcasecmp(property, "ignoreConfigureRequest")) {
|
|
|
|
|
return rule->ignore_configure_request;
|
|
|
|
|
}
|
2023-11-09 21:44:51 +00:00
|
|
|
if (rule->fixed_position
|
|
|
|
|
&& !strcasecmp(property, "fixedPosition")) {
|
|
|
|
|
return rule->fixed_position;
|
|
|
|
|
}
|
2025-06-15 20:21:15 +02:00
|
|
|
if (rule->icon_prefer_client
|
|
|
|
|
&& !strcasecmp(property, "iconPreferClient")) {
|
|
|
|
|
return rule->icon_prefer_client;
|
|
|
|
|
}
|
2026-03-12 13:08:18 +01:00
|
|
|
if (rule->allow_always_on_top
|
|
|
|
|
&& !strcasecmp(property, "allowAlwaysOnTop")) {
|
|
|
|
|
return rule->allow_always_on_top;
|
|
|
|
|
}
|
2023-04-28 21:41:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return LAB_PROP_UNSPECIFIED;
|
|
|
|
|
}
|