criteria: Add idle inhibitor criteria

Add a criterion that matches idle inhibitors in all their various states
and types. Add call sites at creation and destruction, either via the
protocol or due to command call. This allows to trigger actions based on
idle inhibitor state changes on windows.

Example config combined with keyboard shortcuts inhibitor criterion:

for_window [shortcuts_inhibitor=inactive] title_format !-%title
for_window [shortcuts_inhibitor=active] title_format !+%title
for_window [idle_inhibitor=active] title_format ^%title
for_window [idle_inhibitor=none shortcuts_inhibitor=absent] title_format %title

Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
This commit is contained in:
Michael Weiser 2020-03-22 20:10:25 +01:00
parent 726d187d3c
commit 37235b7131
8 changed files with 158 additions and 6 deletions

View file

@ -24,6 +24,18 @@ struct pattern {
pcre *regex;
};
enum criteria_idle_inhibitor {
// implicit: C_IDLE_INHIBITOR_UNSPEC = 0,
C_IDLE_INHIBITOR_NONE = 1,
C_IDLE_INHIBITOR_APPLICATION,
C_IDLE_INHIBITOR_USER,
C_IDLE_INHIBITOR_FOCUS,
C_IDLE_INHIBITOR_FULLSCREEN,
C_IDLE_INHIBITOR_OPEN,
C_IDLE_INHIBITOR_VISIBLE,
C_IDLE_INHIBITOR_ACTIVE,
};
struct criteria {
enum criteria_type type;
char *raw; // entire criteria string (for logging)
@ -47,6 +59,7 @@ struct criteria {
char urgent; // 'l' for latest or 'o' for oldest
struct pattern *workspace;
pid_t pid;
enum criteria_idle_inhibitor idle_inhibitor;
};
bool criteria_is_empty(struct criteria *criteria);

View file

@ -29,12 +29,18 @@ struct sway_idle_inhibitor_v1 {
struct wl_listener destroy;
};
bool sway_idle_inhibit_v1_inhibitor_check_active(
struct sway_idle_inhibitor_v1 *inhibitor);
void sway_idle_inhibit_v1_check_active(
struct sway_idle_inhibit_manager_v1 *manager);
void sway_idle_inhibit_v1_user_inhibitor_register(struct sway_view *view,
enum sway_idle_inhibit_mode mode);
struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_inhibitor_for_view(
struct sway_view *view);
struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_user_inhibitor_for_view(
struct sway_view *view);

View file

@ -341,4 +341,9 @@ void view_save_buffer(struct sway_view *view);
bool view_is_transient_for(struct sway_view *child, struct sway_view *ancestor);
void view_schedule_criteria_execution_from_wlr_surface(
struct wlr_surface *wlr_surface);
void view_schedule_criteria_execution_from_view(struct sway_view *view);
#endif