swayfx/include/sway/criteria.h
Brian Ashworth 7d2076cbff criteria: fix __focused__ when no focus or unset
This fixes the behavior of `__focused__` when there is no focused view
to match i3's behavior of successfully matching no views instead of
returning an error of a missing value. It also applies the same logic
when a token is not applicable (or unset) for a view such as `app_id`
for a focused xwayland view or `class` for a focused xdg-shell view.

This adds an `autofail` boolean to `struct criteria`. If it is set to
`true`, then `criteria_matches_view` will immediately bail out as a
no match. If `autofail` is set, the criteria will also not be
considered empty by `criteria_is_empty`.

To set this new `autofail` property, `get_focused_prop` will now take
in a boolean pointer of the same name. If `__focused__` is supported
for the token and there is no focused view or the focused view does not
have a value for the token, then the boolean will be set to true. In
`parse_token`, the boolean value will be checked and if set to true,
then `criteria->autofail` will be set to true and `parse_token` will
bail successfully. Tokens will still be parsed to make sure the whole
criteria is syntactically valid, which is also why
`&criteria->autofail` is not passed to `get_focused_prop` and a local
boolean is declared in `parse_token`.
2019-03-23 09:53:23 +02:00

69 lines
1.7 KiB
C

#ifndef _SWAY_CRITERIA_H
#define _SWAY_CRITERIA_H
#include <pcre.h>
#include "config.h"
#include "list.h"
#include "tree/view.h"
enum criteria_type {
CT_COMMAND = 1 << 0,
CT_ASSIGN_OUTPUT = 1 << 1,
CT_ASSIGN_WORKSPACE = 1 << 2,
CT_ASSIGN_WORKSPACE_NUMBER = 1 << 3,
CT_NO_FOCUS = 1 << 4,
};
struct criteria {
enum criteria_type type;
char *raw; // entire criteria string (for logging)
char *cmdlist;
char *target; // workspace or output name for `assign` criteria
bool autofail; // __focused__ while no focus or n/a for focused view
pcre *title;
pcre *shell;
pcre *app_id;
pcre *con_mark;
uint32_t con_id; // internal ID
#if HAVE_XWAYLAND
pcre *class;
uint32_t id; // X11 window ID
pcre *instance;
pcre *window_role;
enum atom_name window_type;
#endif
bool floating;
bool tiling;
char urgent; // 'l' for latest or 'o' for oldest
pcre *workspace;
};
bool criteria_is_empty(struct criteria *criteria);
void criteria_destroy(struct criteria *criteria);
/**
* Generate a criteria struct from a raw criteria string such as
* [class="foo" instance="bar"] (brackets inclusive).
*
* The error argument is expected to be an address of a null pointer. If an
* error is encountered, the function will return NULL and the pointer will be
* changed to point to the error string. This string should be freed afterwards.
*/
struct criteria *criteria_parse(char *raw, char **error);
/**
* Compile a list of criterias matching the given view.
*
* Criteria types can be bitwise ORed.
*/
list_t *criteria_for_view(struct sway_view *view, enum criteria_type types);
/**
* Compile a list of views matching the given criteria.
*/
list_t *criteria_get_views(struct criteria *criteria);
#endif