feat: add windowrule option indleinhibit_when_focus

This commit is contained in:
DreamMaoMao 2026-03-03 13:23:15 +08:00
parent 9aa2d3cd33
commit 1e1d41e626
2 changed files with 51 additions and 5 deletions

View file

@ -78,6 +78,7 @@ typedef struct {
int32_t ignore_maximize; int32_t ignore_maximize;
int32_t ignore_minimize; int32_t ignore_minimize;
int32_t isnosizehint; int32_t isnosizehint;
int32_t indleinhibit_when_focus;
const char *monitor; const char *monitor;
int32_t offsetx; int32_t offsetx;
int32_t offsety; int32_t offsety;
@ -2022,6 +2023,7 @@ bool parse_option(Config *config, char *key, char *value) {
rule->ignore_maximize = -1; rule->ignore_maximize = -1;
rule->ignore_minimize = -1; rule->ignore_minimize = -1;
rule->isnosizehint = -1; rule->isnosizehint = -1;
rule->indleinhibit_when_focus = -1;
rule->isterm = -1; rule->isterm = -1;
rule->allow_csd = -1; rule->allow_csd = -1;
rule->force_maximize = -1; rule->force_maximize = -1;
@ -2132,6 +2134,8 @@ bool parse_option(Config *config, char *key, char *value) {
rule->ignore_minimize = atoi(val); rule->ignore_minimize = atoi(val);
} else if (strcmp(key, "isnosizehint") == 0) { } else if (strcmp(key, "isnosizehint") == 0) {
rule->isnosizehint = atoi(val); rule->isnosizehint = atoi(val);
} else if (strcmp(key, "indleinhibit_when_focus") == 0) {
rule->indleinhibit_when_focus = atoi(val);
} else if (strcmp(key, "isterm") == 0) { } else if (strcmp(key, "isterm") == 0) {
rule->isterm = atoi(val); rule->isterm = atoi(val);
} else if (strcmp(key, "allow_csd") == 0) { } else if (strcmp(key, "allow_csd") == 0) {
@ -3672,11 +3676,12 @@ void reapply_cursor_style(void) {
wlr_cursor_set_xcursor(cursor, cursor_mgr, "left_ptr"); wlr_cursor_set_xcursor(cursor, cursor_mgr, "left_ptr");
hide_cursor_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy), hide_cursor_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy),
hidecursor, cursor); hidecursor, cursor);
if (cursor_hidden) { if (cursor_hidden) {
wlr_cursor_unset_image(cursor); wlr_cursor_unset_image(cursor);
} else { } else {
wl_event_source_timer_update(hide_cursor_source, cursor_hide_timeout * 1000); wl_event_source_timer_update(hide_cursor_source,
cursor_hide_timeout * 1000);
} }
} }

View file

@ -347,7 +347,7 @@ struct Client {
struct wlr_foreign_toplevel_handle_v1 *foreign_toplevel; struct wlr_foreign_toplevel_handle_v1 *foreign_toplevel;
int32_t isfloating, isurgent, isfullscreen, isfakefullscreen, int32_t isfloating, isurgent, isfullscreen, isfakefullscreen,
need_float_size_reduce, isminimized, isoverlay, isnosizehint, need_float_size_reduce, isminimized, isoverlay, isnosizehint,
ignore_maximize, ignore_minimize; ignore_maximize, ignore_minimize, indleinhibit_when_focus;
int32_t ismaximizescreen; int32_t ismaximizescreen;
int32_t overview_backup_bw; int32_t overview_backup_bw;
int32_t fullscreen_backup_x, fullscreen_backup_y, fullscreen_backup_w, int32_t fullscreen_backup_x, fullscreen_backup_y, fullscreen_backup_w,
@ -802,6 +802,8 @@ static Monitor *get_monitor_nearest_to(int32_t lx, int32_t ly);
static bool match_monitor_spec(char *spec, Monitor *m); static bool match_monitor_spec(char *spec, Monitor *m);
static void last_cursor_surface_destroy(struct wl_listener *listener, static void last_cursor_surface_destroy(struct wl_listener *listener,
void *data); void *data);
static int32_t keep_idle_inhibit(void *data);
static void check_keep_idle_inhibit(Client *c);
#include "data/static_keymap.h" #include "data/static_keymap.h"
#include "dispatch/bind_declare.h" #include "dispatch/bind_declare.h"
@ -899,6 +901,7 @@ struct dvec2 *baked_points_opafadein;
struct dvec2 *baked_points_opafadeout; struct dvec2 *baked_points_opafadeout;
static struct wl_event_source *hide_cursor_source; static struct wl_event_source *hide_cursor_source;
static struct wl_event_source *keep_idle_inhibit_source;
static bool cursor_hidden = false; static bool cursor_hidden = false;
static bool tag_combo = false; static bool tag_combo = false;
static const char *cli_config_path = NULL; static const char *cli_config_path = NULL;
@ -1335,6 +1338,7 @@ static void apply_rule_properties(Client *c, const ConfigWinRule *r) {
APPLY_INT_PROP(c, r, ignore_maximize); APPLY_INT_PROP(c, r, ignore_maximize);
APPLY_INT_PROP(c, r, ignore_minimize); APPLY_INT_PROP(c, r, ignore_minimize);
APPLY_INT_PROP(c, r, isnosizehint); APPLY_INT_PROP(c, r, isnosizehint);
APPLY_INT_PROP(c, r, indleinhibit_when_focus);
APPLY_INT_PROP(c, r, isunglobal); APPLY_INT_PROP(c, r, isunglobal);
APPLY_INT_PROP(c, r, noblur); APPLY_INT_PROP(c, r, noblur);
APPLY_INT_PROP(c, r, allow_shortcuts_inhibit); APPLY_INT_PROP(c, r, allow_shortcuts_inhibit);
@ -3482,6 +3486,8 @@ void focusclient(Client *c, int32_t lift) {
selmon->sel = c; selmon->sel = c;
c->isfocusing = true; c->isfocusing = true;
check_keep_idle_inhibit(c);
if (last_focus_client && !last_focus_client->iskilling && if (last_focus_client && !last_focus_client->iskilling &&
last_focus_client != c) { last_focus_client != c) {
last_focus_client->isfocusing = false; last_focus_client->isfocusing = false;
@ -4029,6 +4035,7 @@ void init_client_properties(Client *c) {
c->force_tiled_state = 1; c->force_tiled_state = 1;
c->force_tearing = 0; c->force_tearing = 0;
c->allow_shortcuts_inhibit = SHORTCUTS_INHIBIT_ENABLE; c->allow_shortcuts_inhibit = SHORTCUTS_INHIBIT_ENABLE;
c->indleinhibit_when_focus = 0;
c->scroller_proportion_single = 0.0f; c->scroller_proportion_single = 0.0f;
c->float_geom.width = 0; c->float_geom.width = 0;
c->float_geom.height = 0; c->float_geom.height = 0;
@ -5564,6 +5571,9 @@ void setup(void) {
idle_inhibit_mgr = wlr_idle_inhibit_v1_create(dpy); idle_inhibit_mgr = wlr_idle_inhibit_v1_create(dpy);
wl_signal_add(&idle_inhibit_mgr->events.new_inhibitor, &new_idle_inhibitor); wl_signal_add(&idle_inhibit_mgr->events.new_inhibitor, &new_idle_inhibitor);
keep_idle_inhibit_source = wl_event_loop_add_timer(
wl_display_get_event_loop(dpy), keep_idle_inhibit, NULL);
layer_shell = wlr_layer_shell_v1_create(dpy, 4); layer_shell = wlr_layer_shell_v1_create(dpy, 4);
wl_signal_add(&layer_shell->events.new_surface, &new_layer_surface); wl_signal_add(&layer_shell->events.new_surface, &new_layer_surface);
@ -5632,7 +5642,7 @@ void setup(void) {
wl_signal_add(&cursor_shape_mgr->events.request_set_shape, wl_signal_add(&cursor_shape_mgr->events.request_set_shape,
&request_set_cursor_shape); &request_set_cursor_shape);
hide_cursor_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy), hide_cursor_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy),
hidecursor, cursor); hidecursor, cursor);
/* /*
* Configures a seat, which is a single "seat" at which a user sits and * Configures a seat, which is a single "seat" at which a user sits and
* operates the computer. This conceptually includes up to one keyboard, * operates the computer. This conceptually includes up to one keyboard,
@ -5851,7 +5861,8 @@ void overview_restore(Client *c, const Arg *arg) {
} }
void handlecursoractivity(void) { void handlecursoractivity(void) {
wl_event_source_timer_update(hide_cursor_source, cursor_hide_timeout * 1000); wl_event_source_timer_update(hide_cursor_source,
cursor_hide_timeout * 1000);
if (!cursor_hidden) if (!cursor_hidden)
return; return;
@ -5872,6 +5883,36 @@ int32_t hidecursor(void *data) {
return 1; return 1;
} }
void check_keep_idle_inhibit(Client *c) {
if (c && c->indleinhibit_when_focus && keep_idle_inhibit_source) {
wl_event_source_timer_update(keep_idle_inhibit_source, 1000);
}
}
int32_t keep_idle_inhibit(void *data) {
if (!idle_inhibit_mgr) {
wl_event_source_timer_update(keep_idle_inhibit_source, 0);
return 1;
}
if (session && !session->active) {
wl_event_source_timer_update(keep_idle_inhibit_source, 0);
return 1;
}
if (!selmon || !selmon->sel || !selmon->sel->indleinhibit_when_focus) {
wl_event_source_timer_update(keep_idle_inhibit_source, 0);
return 1;
}
if (seat && idle_notifier) {
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
wl_event_source_timer_update(keep_idle_inhibit_source, 1000);
}
return 1;
}
void unlocksession(struct wl_listener *listener, void *data) { void unlocksession(struct wl_listener *listener, void *data) {
SessionLock *lock = wl_container_of(listener, lock, unlock); SessionLock *lock = wl_container_of(listener, lock, unlock);
destroylock(lock, 1); destroylock(lock, 1);