query: additional condition options

This commit is contained in:
Orfeas 2024-10-18 02:07:52 +03:00
parent a567b4dc3b
commit 0dce8202ce
3 changed files with 120 additions and 6 deletions

View file

@ -290,6 +290,16 @@ struct view_query {
int window_type; int window_type;
char *sandbox_engine; char *sandbox_engine;
char *sandbox_app_id; char *sandbox_app_id;
int shaded;
int maximized;
int maximizedvertical;
int maximizedhorizontal;
int iconified;
int focused;
int omnipresent;
enum view_edge tiled;
char *tiled_region;
char *desktop;
}; };
struct xdg_toplevel_view { struct xdg_toplevel_view {

View file

@ -473,7 +473,28 @@ fill_action_query(char *nodename, char *content, struct action *action)
current_view_query->sandbox_engine = xstrdup(content); current_view_query->sandbox_engine = xstrdup(content);
} else if (!strcasecmp(nodename, "sandboxAppId")) { } else if (!strcasecmp(nodename, "sandboxAppId")) {
current_view_query->sandbox_app_id = xstrdup(content); current_view_query->sandbox_app_id = xstrdup(content);
} else if (!strcasecmp(nodename, "shaded")) {
current_view_query->shaded = parse_bool(content, -1);
} else if (!strcasecmp(nodename, "maximized")) {
current_view_query->maximized = parse_bool(content, -1);
} else if (!strcasecmp(nodename, "maximizedhorizontal")) {
current_view_query->maximizedhorizontal = parse_bool(content, -1);
} else if (!strcasecmp(nodename, "maximizedvertical")) {
current_view_query->maximizedvertical = parse_bool(content, -1);
} else if (!strcasecmp(nodename, "iconified")) {
current_view_query->iconified = parse_bool(content, -1);
} else if (!strcasecmp(nodename, "focused")) {
current_view_query->focused = parse_bool(content, -1);
} else if (!strcasecmp(nodename, "omnipresent")) {
current_view_query->omnipresent = parse_bool(content, -1);
} else if (!strcasecmp(nodename, "tiled")) {
current_view_query->tiled = view_edge_parse(content);
} else if (!strcasecmp(nodename, "tiled_region")) {
current_view_query->tiled_region = xstrdup(content);
} else if (!strcasecmp(nodename, "desktop")) {
current_view_query->desktop = xstrdup(content);
} }
} }
static void static void

View file

@ -8,6 +8,7 @@
#include "common/macros.h" #include "common/macros.h"
#include "common/match.h" #include "common/match.h"
#include "common/mem.h" #include "common/mem.h"
#include "common/parse-bool.h"
#include "common/scene-helpers.h" #include "common/scene-helpers.h"
#include "input/keyboard.h" #include "input/keyboard.h"
#include "labwc.h" #include "labwc.h"
@ -22,6 +23,7 @@
#include "ssd.h" #include "ssd.h"
#include "view.h" #include "view.h"
#include "window-rules.h" #include "window-rules.h"
#include "wlr/util/log.h"
#include "workspaces.h" #include "workspaces.h"
#include "xwayland.h" #include "xwayland.h"
@ -68,7 +70,16 @@ struct view_query *
view_query_create(void) view_query_create(void)
{ {
struct view_query *query = znew(*query); struct view_query *query = znew(*query);
query->window_type = -1; *query = (struct view_query) {
.window_type = -1,
.shaded = -1,
.maximized = -1,
.maximizedhorizontal = -1,
.maximizedvertical = -1,
.iconified = -1,
.focused = -1,
.omnipresent = -1,
};
return query; return query;
} }
@ -76,11 +87,13 @@ void
view_query_free(struct view_query *query) view_query_free(struct view_query *query)
{ {
wl_list_remove(&query->link); wl_list_remove(&query->link);
free(query->identifier); zfree(query->identifier);
free(query->title); zfree(query->title);
free(query->sandbox_engine); zfree(query->sandbox_engine);
free(query->sandbox_app_id); zfree(query->sandbox_app_id);
free(query); zfree(query->tiled_region);
zfree(query->desktop);
zfree(query);
} }
bool bool
@ -122,6 +135,76 @@ view_matches_query(struct view *view, struct view_query *query)
&& match_glob(query->sandbox_app_id, security_context->app_id); && match_glob(query->sandbox_app_id, security_context->app_id);
} }
if (match && query->shaded >= 0) {
empty = false;
match &= (view->shaded == query->shaded);
wlr_log(WLR_DEBUG, "shaded: %d\n", match);
}
wlr_log(WLR_DEBUG, "view->maximized: %d\n", view->maximized);
if (match && query->maximized >= 0) {
empty = false;
match &= (query->maximized == (view->maximized == VIEW_AXIS_BOTH));
wlr_log(WLR_DEBUG, "maximized: %d\n", match);
}
if (match && query->maximizedhorizontal >= 0) {
empty = false;
match &= (query->maximizedhorizontal == ((view->maximized & VIEW_AXIS_HORIZONTAL) != 0));
wlr_log(WLR_DEBUG, "maximizedhorizontal: %d\n", match);
}
if (match && query->maximizedvertical >= 0) {
empty = false;
match &= (query->maximizedvertical == ((view->maximized & VIEW_AXIS_VERTICAL) != 0));
wlr_log(WLR_DEBUG, "maximizedvertical: %d\n", match);
}
if (match && query->iconified >= 0) {
empty = false;
match &= (view->minimized == query->iconified);
wlr_log(WLR_DEBUG, "iconified: %d\n", match);
}
if (match && query->focused >= 0) {
empty = false;
match &= (query->focused == (view->server->active_view == view));
wlr_log(WLR_DEBUG, "focused: %d\n", match);
}
if (match && query->omnipresent >= 0) {
empty = false;
match &= (query->omnipresent == (view->visible_on_all_workspaces == query->omnipresent));
wlr_log(WLR_DEBUG, "omnipresent: %d\n", match);
}
if (match && query->tiled != VIEW_EDGE_INVALID) {
empty = false;
match &= (query->tiled == view->tiled);
wlr_log(WLR_DEBUG, "tiled: %d\n", match);
}
if (match && query->tiled_region && view->tiled_region) {
empty = false;
match &= !strcasecmp(query->tiled_region, view->tiled_region->name);
wlr_log(WLR_DEBUG, "tiled_region: %d\n", match);
}
if (match && query->desktop) {
empty = false;
if (!strcasecmp(query->desktop, "current")) {
match &= !strcasecmp(view->workspace->name, view->server->workspaces.current->name);
} else if (!strcasecmp(query->desktop, "other")) {
match &= strcasecmp(view->workspace->name, view->server->workspaces.current->name);
} else {
wlr_log(WLR_DEBUG, "view->workspace->name: %s\n", view->workspace->name);
match &= !strcasecmp(view->workspace->name, query->desktop);
}
wlr_log(WLR_DEBUG, "desktop: %d\n", match);
}
return !empty && match; return !empty && match;
} }