Merge pull request #1574 from acrisci/config-refactor

Command criteria
This commit is contained in:
emersion 2018-01-22 01:16:23 +01:00 committed by GitHub
commit 0c58673c6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 840 additions and 52 deletions

View file

@ -350,6 +350,14 @@ struct sway_config {
list_t *command_policies;
list_t *feature_policies;
list_t *ipc_policies;
// Context for command handlers
struct {
struct input_config *input_config;
struct seat_config *seat_config;
struct sway_seat *seat;
swayc_t *current_container;
} handler_context;
};
void pid_workspace_add(struct pid_workspace *pw);
@ -375,6 +383,9 @@ bool read_config(FILE *file, struct sway_config *config);
* Free config struct
*/
void free_config(struct sway_config *config);
void config_clear_handler_context(struct sway_config *config);
void free_sway_variable(struct sway_variable *var);
/**
* Does variable replacement for a string based on the config's currently loaded variables.

View file

@ -145,4 +145,6 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type);
swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy);
void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data);
#endif

42
include/sway/criteria.h Normal file
View file

@ -0,0 +1,42 @@
#ifndef _SWAY_CRITERIA_H
#define _SWAY_CRITERIA_H
#include "container.h"
#include "list.h"
/**
* Maps criteria (as a list of criteria tokens) to a command list.
*
* A list of tokens together represent a single criteria string (e.g.
* '[class="abc" title="xyz"]' becomes two criteria tokens).
*
* for_window: Views matching all criteria will have the bound command list
* executed on them.
*
* Set via `for_window <criteria> <cmd list>`.
*/
struct criteria {
list_t *tokens; // struct crit_token, contains compiled regex.
char *crit_raw; // entire criteria string (for logging)
char *cmdlist;
};
int criteria_cmp(const void *item, const void *data);
void free_criteria(struct criteria *crit);
// Pouplate list with crit_tokens extracted from criteria string, returns error
// string or NULL if successful.
char *extract_crit_tokens(list_t *tokens, const char *criteria);
// Returns list of criteria that match given container. These criteria have
// been set with `for_window` commands and have an associated cmdlist.
list_t *criteria_for(swayc_t *cont);
// Returns a list of all containers that match the given list of tokens.
list_t *container_for_crit_tokens(list_t *tokens);
// Returns true if any criteria in the given list matches this container
bool criteria_any(swayc_t *cont, list_t *criteria);
#endif

View file

@ -5,9 +5,6 @@
#include "sway/config.h"
#include "list.h"
extern struct input_config *current_input_config;
extern struct seat_config *current_seat_config;
/**
* The global singleton input manager
* TODO: make me not a global
@ -46,4 +43,7 @@ void sway_input_manager_apply_input_config(struct sway_input_manager *input,
void sway_input_manager_apply_seat_config(struct sway_input_manager *input,
struct seat_config *seat_config);
struct sway_seat *sway_input_manager_get_default_seat(
struct sway_input_manager *input);
#endif

View file

@ -92,10 +92,27 @@ struct sway_view {
void (*set_position)(struct sway_view *view,
double ox, double oy);
void (*set_activated)(struct sway_view *view, bool activated);
void (*close)(struct sway_view *view);
} iface;
// only used for unmanaged views (shell specific)
struct wl_list unmanaged_view_link; // sway_root::unmanaged views
};
const char *view_get_title(struct sway_view *view);
const char *view_get_app_id(struct sway_view *view);
const char *view_get_class(struct sway_view *view);
const char *view_get_instance(struct sway_view *view);
void view_set_size(struct sway_view *view, int width, int height);
void view_set_position(struct sway_view *view, double ox, double oy);
void view_set_activated(struct sway_view *view, bool activated);
void view_close(struct sway_view *view);
#endif