]> git.mdlowis.com Git - proto/labwc.git/commitdiff
query: reuse query logic for window rules
authorTobias Bengfort <tobias.bengfort@posteo.de>
Sat, 20 Apr 2024 05:58:08 +0000 (07:58 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 18 May 2024 19:04:08 +0000 (20:04 +0100)
src/window-rules.c

index b6b299954935ea73f676f4f8f4014bdbca8a8d78..95d0a1ddb588f3fe7de221c90630bc92e85977bb 100644 (file)
 #include "window-rules.h"
 
 static bool
-matches_criteria(struct window_rule *rule, struct view *view)
-{
-       const char *id = view_get_string_prop(view, "app_id");
-       const char *title = view_get_string_prop(view, "title");
-
-       if (rule->identifier) {
-               if (!id || !match_glob(rule->identifier, id)) {
-                       return false;
-               }
-       }
-       if (rule->title) {
-               if (!title || !match_glob(rule->title, title)) {
-                       return false;
-               }
-       }
-       if (rule->window_type >= 0) {
-               if (!view_contains_window_type(view, rule->window_type)) {
-                       return false;
-               }
-       }
-       return true;
-}
-
-static bool
-other_instances_exist(struct window_rule *rule, struct view *self)
+other_instances_exist(struct view *self, struct view_query *query)
 {
        struct wl_list *views = &self->server->views;
        struct view *view;
 
        wl_list_for_each(view, views, link) {
-               if (view != self && matches_criteria(rule, view)) {
+               if (view != self && view_matches_query(view, query)) {
                        return true;
                }
        }
@@ -54,10 +30,15 @@ other_instances_exist(struct window_rule *rule, struct view *self)
 static bool
 view_matches_criteria(struct window_rule *rule, struct view *view)
 {
-       if (rule->match_once && other_instances_exist(rule, view)) {
+       struct view_query query = {0};
+       query.identifier = rule->identifier;
+       query.title = rule->title;
+       query.window_type = rule->window_type;
+
+       if (rule->match_once && other_instances_exist(view, &query)) {
                return false;
        }
-       return matches_criteria(rule, view);
+       return view_matches_query(view, &query);
 }
 
 void