2018-01-20 22:21:45 +01:00
|
|
|
#ifndef _SWAY_CRITERIA_H
|
|
|
|
#define _SWAY_CRITERIA_H
|
|
|
|
|
2022-03-12 14:02:32 +01:00
|
|
|
#define PCRE2_CODE_UNIT_WIDTH 8
|
|
|
|
#include <pcre2.h>
|
2018-07-25 13:32:20 +02:00
|
|
|
#include "config.h"
|
2018-01-20 22:21:45 +01:00
|
|
|
#include "list.h"
|
2018-05-13 00:16:36 +02:00
|
|
|
#include "tree/view.h"
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
enum criteria_type {
|
2018-08-12 01:38:19 +02:00
|
|
|
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,
|
2018-05-13 00:16:36 +02:00
|
|
|
};
|
2018-05-12 14:52:54 +02:00
|
|
|
|
2019-10-11 04:44:56 +02:00
|
|
|
enum pattern_type {
|
2022-03-12 14:02:32 +01:00
|
|
|
PATTERN_PCRE2,
|
2019-10-11 04:44:56 +02:00
|
|
|
PATTERN_FOCUSED,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pattern {
|
|
|
|
enum pattern_type match_type;
|
2022-03-12 14:02:32 +01:00
|
|
|
pcre2_code *regex;
|
2019-10-11 04:44:56 +02:00
|
|
|
};
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
struct criteria {
|
|
|
|
enum criteria_type type;
|
|
|
|
char *raw; // entire criteria string (for logging)
|
2018-01-20 22:21:45 +01:00
|
|
|
char *cmdlist;
|
2018-05-13 00:16:36 +02:00
|
|
|
char *target; // workspace or output name for `assign` criteria
|
|
|
|
|
2019-10-11 04:44:56 +02:00
|
|
|
struct pattern *title;
|
|
|
|
struct pattern *shell;
|
|
|
|
struct pattern *app_id;
|
|
|
|
struct pattern *con_mark;
|
2018-05-13 00:16:36 +02:00
|
|
|
uint32_t con_id; // internal ID
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2019-10-11 04:44:56 +02:00
|
|
|
struct pattern *class;
|
2018-05-13 00:16:36 +02:00
|
|
|
uint32_t id; // X11 window ID
|
2019-10-11 04:44:56 +02:00
|
|
|
struct pattern *instance;
|
|
|
|
struct pattern *window_role;
|
2018-09-03 11:13:50 +02:00
|
|
|
enum atom_name window_type;
|
2018-07-24 23:37:41 +02:00
|
|
|
#endif
|
2023-09-02 06:28:09 +02:00
|
|
|
bool all;
|
2018-05-13 00:16:36 +02:00
|
|
|
bool floating;
|
|
|
|
bool tiling;
|
|
|
|
char urgent; // 'l' for latest or 'o' for oldest
|
2019-10-11 04:44:56 +02:00
|
|
|
struct pattern *workspace;
|
2019-10-02 09:36:52 +02:00
|
|
|
pid_t pid;
|
2018-01-20 22:21:45 +01:00
|
|
|
};
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
bool criteria_is_empty(struct criteria *criteria);
|
2019-07-26 21:30:04 +02:00
|
|
|
bool criteria_is_equal(struct criteria *left, struct criteria *right);
|
|
|
|
|
|
|
|
bool criteria_already_exists(struct criteria *criteria);
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
void criteria_destroy(struct criteria *criteria);
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
/**
|
2020-01-26 10:27:52 +01:00
|
|
|
* Compile a list of containers matching the given criteria.
|
2018-05-13 00:16:36 +02:00
|
|
|
*/
|
2020-01-26 10:27:52 +01:00
|
|
|
list_t *criteria_get_containers(struct criteria *criteria);
|
2018-01-20 22:21:45 +01:00
|
|
|
|
|
|
|
#endif
|