mirror of
https://github.com/NickHu/sway
synced 2024-12-28 22:23:30 +01:00
3b0c26d149
The criteria struct now uses properties for each token type rather than the list_t list of tokens. The reason for this is that different token types have different data types: pcre, string and number to name a few. This solution should be more flexible moving forward. A bonus of this is that criteria is now easier to understand when looking at the struct definition. The criteria parser has been rewritten because the previous one didn't support valueless pairs (eg. [class="foo" floating]). Criteria now has types. Types at the moment are CT_COMMAND, CT_ASSIGN_WORKSPACE and CT_ASSIGN_OUTPUT. i3 uses types as well. Previously the assign command was creating a criteria with 'move to workspace <name>' as its command, but this caused the window to appear briefly on the focused workspace before being moved to the assigned workspace. It now creates the view directly in the assigned workspace. Each view will only execute a given criteria once. This is achieved by storing a list of executed criteria in the view. This is the same strategy used by i3. Escaping now works properly. Previously you could do things like [class="Fire\"fox"] and the stored value would be 'Fire\"fox', but it should be (and now is) 'Fire"fox'. The public functions in criteria.c are now all prefixed with criteria_. Xwayland views now listen to the set_title, set_class and set_window_type events and criteria will be run when these happen. XDG shell has none of these events so it continues to update the title in handle_commit. Each view type's get_prop function has been split into get_string_prop and get_int_prop because some properties like the X11 window ID and window type are numeric. The following new criteria tokens are now supported: * id (X11 window ID) * instance * tiling * workspace
61 lines
1.5 KiB
C
61 lines
1.5 KiB
C
#ifndef _SWAY_CRITERIA_H
|
|
#define _SWAY_CRITERIA_H
|
|
|
|
#include <pcre.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,
|
|
};
|
|
|
|
struct criteria {
|
|
enum criteria_type type;
|
|
char *raw; // entire criteria string (for logging)
|
|
char *cmdlist;
|
|
char *target; // workspace or output name for `assign` criteria
|
|
|
|
pcre *title;
|
|
pcre *app_id;
|
|
pcre *class;
|
|
pcre *instance;
|
|
pcre *con_mark;
|
|
uint32_t con_id; // internal ID
|
|
uint32_t id; // X11 window ID
|
|
pcre *window_role;
|
|
uint32_t window_type;
|
|
bool floating;
|
|
bool tiling;
|
|
char urgent; // 'l' for latest or 'o' for oldest
|
|
char *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
|