feat: add windowrule option indleinhibit_when_focus

This commit is contained in:
DreamMaoMao 2026-03-03 13:23:15 +08:00
parent 9732aa23bf
commit 2868f07179
2 changed files with 51 additions and 5 deletions

View file

@ -78,6 +78,7 @@ typedef struct {
int32_t ignore_maximize;
int32_t ignore_minimize;
int32_t isnosizehint;
int32_t indleinhibit_when_focus;
const char *monitor;
int32_t offsetx;
int32_t offsety;
@ -1946,6 +1947,7 @@ bool parse_option(Config *config, char *key, char *value) {
rule->ignore_maximize = -1;
rule->ignore_minimize = -1;
rule->isnosizehint = -1;
rule->indleinhibit_when_focus = -1;
rule->isterm = -1;
rule->allow_csd = -1;
rule->force_maximize = -1;
@ -2055,6 +2057,8 @@ bool parse_option(Config *config, char *key, char *value) {
rule->ignore_minimize = atoi(val);
} else if (strcmp(key, "isnosizehint") == 0) {
rule->isnosizehint = atoi(val);
} else if (strcmp(key, "indleinhibit_when_focus") == 0) {
rule->indleinhibit_when_focus = atoi(val);
} else if (strcmp(key, "isterm") == 0) {
rule->isterm = atoi(val);
} else if (strcmp(key, "allow_csd") == 0) {
@ -3528,11 +3532,12 @@ void reapply_cursor_style(void) {
wlr_cursor_set_xcursor(cursor, cursor_mgr, "left_ptr");
hide_cursor_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy),
hidecursor, cursor);
hidecursor, cursor);
if (cursor_hidden) {
wlr_cursor_unset_image(cursor);
} 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

@ -349,7 +349,7 @@ struct Client {
struct wlr_foreign_toplevel_handle_v1 *foreign_toplevel;
int32_t isfloating, isurgent, isfullscreen, isfakefullscreen,
need_float_size_reduce, isminimized, isoverlay, isnosizehint,
ignore_maximize, ignore_minimize;
ignore_maximize, ignore_minimize, indleinhibit_when_focus;
int32_t ismaximizescreen;
int32_t overview_backup_bw;
int32_t fullscreen_backup_x, fullscreen_backup_y, fullscreen_backup_w,
@ -816,6 +816,8 @@ static Monitor *get_monitor_nearest_to(int32_t lx, int32_t ly);
static bool match_monitor_spec(char *spec, Monitor *m);
static void last_cursor_surface_destroy(struct wl_listener *listener,
void *data);
static int32_t keep_idle_inhibit(void *data);
static void check_keep_idle_inhibit(Client *c);
#include "data/static_keymap.h"
#include "dispatch/bind_declare.h"
@ -919,6 +921,7 @@ struct dvec2 *baked_points_opafadein;
struct dvec2 *baked_points_opafadeout;
static struct wl_event_source *hide_cursor_source;
static struct wl_event_source *keep_idle_inhibit_source;
static bool cursor_hidden = false;
static bool tag_combo = false;
static const char *cli_config_path = NULL;
@ -1358,6 +1361,7 @@ static void apply_rule_properties(Client *c, const ConfigWinRule *r) {
APPLY_INT_PROP(c, r, ignore_maximize);
APPLY_INT_PROP(c, r, ignore_minimize);
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, allow_shortcuts_inhibit);
@ -3437,6 +3441,8 @@ void focusclient(Client *c, int32_t lift) {
selmon->sel = c;
c->isfocusing = true;
check_keep_idle_inhibit(c);
if (last_focus_client && !last_focus_client->iskilling &&
last_focus_client != c) {
last_focus_client->isfocusing = false;
@ -3953,6 +3959,7 @@ void init_client_properties(Client *c) {
c->force_tiled_state = 1;
c->force_tearing = 0;
c->allow_shortcuts_inhibit = SHORTCUTS_INHIBIT_ENABLE;
c->indleinhibit_when_focus = 0;
c->scroller_proportion_single = 0.0f;
c->float_geom.width = 0;
c->float_geom.height = 0;
@ -5576,6 +5583,9 @@ void setup(void) {
idle_inhibit_mgr = wlr_idle_inhibit_v1_create(dpy);
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);
wl_signal_add(&layer_shell->events.new_surface, &new_layer_surface);
@ -5644,7 +5654,7 @@ void setup(void) {
wl_signal_add(&cursor_shape_mgr->events.request_set_shape,
&request_set_cursor_shape);
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
* operates the computer. This conceptually includes up to one keyboard,
@ -5858,7 +5868,8 @@ void overview_restore(Client *c, const Arg *arg) {
}
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)
return;
@ -5879,6 +5890,36 @@ int32_t hidecursor(void *data) {
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) {
SessionLock *lock = wl_container_of(listener, lock, unlock);
destroylock(lock, 1);