aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/criteria.c204
-rw-r--r--sway/tree/view.c7
2 files changed, 42 insertions, 169 deletions
diff --git a/sway/criteria.c b/sway/criteria.c
index 294b2922..7da790e6 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -190,128 +190,19 @@ static bool generate_regex(pcre **regex, char *value) {
return true;
}
-enum criteria_token {
- T_APP_ID,
- T_CLASS,
- T_CON_ID,
- T_CON_MARK,
- T_FLOATING,
- T_ID,
- T_INSTANCE,
- T_TILING,
- T_TITLE,
- T_URGENT,
- T_WINDOW_ROLE,
- T_WINDOW_TYPE,
- T_WORKSPACE,
-
- T_INVALID,
-};
-
-static enum criteria_token token_from_name(char *name) {
- if (strcmp(name, "app_id") == 0) {
- return T_APP_ID;
- } else if (strcmp(name, "class") == 0) {
- return T_CLASS;
- } else if (strcmp(name, "con_id") == 0) {
- return T_CON_ID;
- } else if (strcmp(name, "con_mark") == 0) {
- return T_CON_MARK;
- } else if (strcmp(name, "id") == 0) {
- return T_ID;
- } else if (strcmp(name, "instance") == 0) {
- return T_INSTANCE;
- } else if (strcmp(name, "title") == 0) {
- return T_TITLE;
- } else if (strcmp(name, "urgent") == 0) {
- return T_URGENT;
- } else if (strcmp(name, "window_role") == 0) {
- return T_WINDOW_ROLE;
- } else if (strcmp(name, "window_type") == 0) {
- return T_WINDOW_TYPE;
- } else if (strcmp(name, "workspace") == 0) {
- return T_WORKSPACE;
- }
- return T_INVALID;
-}
-
-/**
- * Get a property of the focused view.
- *
- * Note that we are taking the focused view at the time of criteria parsing, not
- * at the time of execution. This is because __focused__ only makes sense when
- * using criteria via IPC. Using __focused__ in config is not useful because
- * criteria is only executed once per view.
- */
-static char *get_focused_prop(enum criteria_token token) {
- struct sway_seat *seat = input_manager_current_seat(input_manager);
- struct sway_container *focus = seat_get_focus(seat);
-
- if (!focus || focus->type != C_VIEW) {
- return NULL;
- }
- struct sway_view *view = focus->sway_view;
- const char *value = NULL;
-
- switch (token) {
- case T_APP_ID:
- value = view_get_app_id(view);
- break;
- case T_CLASS:
- value = view_get_class(view);
- break;
- case T_INSTANCE:
- value = view_get_instance(view);
- break;
- case T_TITLE:
- value = view_get_class(view);
- break;
- case T_WINDOW_ROLE:
- value = view_get_class(view);
- break;
- case T_WORKSPACE:
- {
- struct sway_container *ws = container_parent(focus, C_WORKSPACE);
- if (ws) {
- value = ws->name;
- }
- }
- break;
- case T_CON_ID: // These do not support __focused__
- case T_CON_MARK:
- case T_FLOATING:
- case T_ID:
- case T_TILING:
- case T_URGENT:
- case T_WINDOW_TYPE:
- case T_INVALID:
- break;
- }
- if (value) {
- return strdup(value);
- }
- return NULL;
-}
-
static bool parse_token(struct criteria *criteria, char *name, char *value) {
- enum criteria_token token = token_from_name(name);
- if (token == T_INVALID) {
- const char *fmt = "Token '%s' is not recognized";
- int len = strlen(fmt) + strlen(name) - 1;
- error = malloc(len);
- snprintf(error, len, fmt, name);
- return false;
- }
-
- char *effective_value = NULL;
- if (value && strcmp(value, "__focused__") == 0) {
- effective_value = get_focused_prop(token);
- } else if (value) {
- effective_value = strdup(value);
- }
-
// Require value, unless token is floating or tiled
- if (!effective_value && token != T_FLOATING && token != T_TILING) {
+ if (!value && (strcmp(name, "title") == 0
+ || strcmp(name, "app_id") == 0
+ || strcmp(name, "class") == 0
+ || strcmp(name, "instance") == 0
+ || strcmp(name, "con_id") == 0
+ || strcmp(name, "con_mark") == 0
+ || strcmp(name, "window_role") == 0
+ || strcmp(name, "window_type") == 0
+ || strcmp(name, "id") == 0
+ || strcmp(name, "urgent") == 0
+ || strcmp(name, "workspace") == 0)) {
const char *fmt = "Token '%s' requires a value";
int len = strlen(fmt) + strlen(name) - 1;
error = malloc(len);
@@ -319,64 +210,53 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) {
return false;
}
- char *endptr = NULL;
- switch (token) {
- case T_TITLE:
- generate_regex(&criteria->title, effective_value);
- break;
- case T_APP_ID:
- generate_regex(&criteria->app_id, effective_value);
- break;
- case T_CLASS:
- generate_regex(&criteria->class, effective_value);
- break;
- case T_INSTANCE:
- generate_regex(&criteria->instance, effective_value);
- break;
- case T_CON_ID:
- criteria->con_id = strtoul(effective_value, &endptr, 10);
+ if (strcmp(name, "title") == 0) {
+ generate_regex(&criteria->title, value);
+ } else if (strcmp(name, "app_id") == 0) {
+ generate_regex(&criteria->app_id, value);
+ } else if (strcmp(name, "class") == 0) {
+ generate_regex(&criteria->class, value);
+ } else if (strcmp(name, "instance") == 0) {
+ generate_regex(&criteria->instance, value);
+ } else if (strcmp(name, "con_id") == 0) {
+ char *endptr;
+ criteria->con_id = strtoul(value, &endptr, 10);
if (*endptr != 0) {
error = strdup("The value for 'con_id' should be numeric");
}
- break;
- case T_CON_MARK:
- generate_regex(&criteria->con_mark, effective_value);
- break;
- case T_WINDOW_ROLE:
- generate_regex(&criteria->window_role, effective_value);
- break;
- case T_WINDOW_TYPE:
+ } else if (strcmp(name, "con_mark") == 0) {
+ generate_regex(&criteria->con_mark, value);
+ } else if (strcmp(name, "window_role") == 0) {
+ generate_regex(&criteria->window_role, value);
+ } else if (strcmp(name, "window_type") == 0) {
// TODO: This is a string but will be stored as an enum or integer
- break;
- case T_ID:
- criteria->id = strtoul(effective_value, &endptr, 10);
+ } else if (strcmp(name, "id") == 0) {
+ char *endptr;
+ criteria->id = strtoul(value, &endptr, 10);
if (*endptr != 0) {
error = strdup("The value for 'id' should be numeric");
}
- break;
- case T_FLOATING:
+ } else if (strcmp(name, "floating") == 0) {
criteria->floating = true;
- break;
- case T_TILING:
+ } else if (strcmp(name, "tiling") == 0) {
criteria->tiling = true;
- break;
- case T_URGENT:
- if (strcmp(effective_value, "latest") == 0) {
+ } else if (strcmp(name, "urgent") == 0) {
+ if (strcmp(value, "latest") == 0) {
criteria->urgent = 'l';
- } else if (strcmp(effective_value, "oldest") == 0) {
+ } else if (strcmp(value, "oldest") == 0) {
criteria->urgent = 'o';
} else {
error =
strdup("The value for 'urgent' must be 'latest' or 'oldest'");
}
- break;
- case T_WORKSPACE:
- criteria->workspace = strdup(effective_value);
- break;
- case T_INVALID:
- break;
+ } else if (strcmp(name, "workspace") == 0) {
+ criteria->workspace = strdup(value);
+ } else {
+ const char *fmt = "Token '%s' is not recognized";
+ int len = strlen(fmt) + strlen(name) - 1;
+ error = malloc(len);
+ snprintf(error, len, fmt, name);
}
- free(effective_value);
if (error) {
return false;
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 3b3b6eaf..7431ac06 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -79,13 +79,6 @@ uint32_t view_get_x11_window_id(struct sway_view *view) {
return 0;
}
-const char *view_get_window_role(struct sway_view *view) {
- if (view->impl->get_string_prop) {
- return view->impl->get_string_prop(view, VIEW_PROP_WINDOW_ROLE);
- }
- return NULL;
-}
-
uint32_t view_get_window_type(struct sway_view *view) {
if (view->impl->get_int_prop) {
return view->impl->get_int_prop(view, VIEW_PROP_WINDOW_TYPE);