opt: only set on_demand layer focus when it request in init_commit

This commit is contained in:
DreamMaoMao 2026-03-02 00:42:07 +08:00
parent 576e669ee4
commit 96cc712e48

View file

@ -1715,6 +1715,7 @@ void focuslayer(LayerSurface *l) {
void reset_exclusive_layer(Monitor *m) { void reset_exclusive_layer(Monitor *m) {
LayerSurface *l = NULL; LayerSurface *l = NULL;
int32_t i; int32_t i;
bool neet_change_focus_to_client = false;
uint32_t layers_above_shell[] = { uint32_t layers_above_shell[] = {
ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
ZWLR_LAYER_SHELL_V1_LAYER_TOP, ZWLR_LAYER_SHELL_V1_LAYER_TOP,
@ -1728,13 +1729,19 @@ void reset_exclusive_layer(Monitor *m) {
wl_list_for_each_reverse(l, &m->layers[layers_above_shell[i]], link) { wl_list_for_each_reverse(l, &m->layers[layers_above_shell[i]], link) {
if (l == exclusive_focus && if (l == exclusive_focus &&
l->layer_surface->current.keyboard_interactive != l->layer_surface->current.keyboard_interactive !=
ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE) ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE) {
exclusive_focus = NULL; exclusive_focus = NULL;
neet_change_focus_to_client = true;
}
if (l->layer_surface->current.keyboard_interactive == if (l->layer_surface->current.keyboard_interactive ==
ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE && ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE &&
l->layer_surface->surface == l->layer_surface->surface ==
seat->keyboard_state.focused_surface) seat->keyboard_state.focused_surface) {
focusclient(focustop(selmon), 1); neet_change_focus_to_client = true;
}
if (locked || if (locked ||
l->layer_surface->current.keyboard_interactive != l->layer_surface->current.keyboard_interactive !=
@ -1747,6 +1754,10 @@ void reset_exclusive_layer(Monitor *m) {
return; return;
} }
} }
if (neet_change_focus_to_client) {
focusclient(focustop(selmon), 1);
}
} }
void arrangelayers(Monitor *m) { void arrangelayers(Monitor *m) {
@ -2361,13 +2372,6 @@ void maplayersurfacenotify(struct wl_listener *listener, void *data) {
} }
// 刷新布局让窗口能感应到exclude_zone变化以及设置独占表面 // 刷新布局让窗口能感应到exclude_zone变化以及设置独占表面
arrangelayers(l->mon); arrangelayers(l->mon);
// 按需交互layer需要像正常窗口一样抢占非独占layer的焦点
if (!exclusive_focus &&
l->layer_surface->current.keyboard_interactive ==
ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
focuslayer(l);
}
} }
void commitlayersurfacenotify(struct wl_listener *listener, void *data) { void commitlayersurfacenotify(struct wl_listener *listener, void *data) {
@ -2388,6 +2392,12 @@ void commitlayersurfacenotify(struct wl_listener *listener, void *data) {
arrangelayers(l->mon); arrangelayers(l->mon);
l->layer_surface->current = old_state; l->layer_surface->current = old_state;
// 按需交互layer只在map之前设置焦点
if (!exclusive_focus &&
l->layer_surface->current.keyboard_interactive ==
ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
focuslayer(l);
}
return; return;
} }
@ -2417,11 +2427,6 @@ void commitlayersurfacenotify(struct wl_listener *listener, void *data) {
layer_set_pending_state(l); layer_set_pending_state(l);
} }
if (layer_surface == exclusive_focus &&
layer_surface->current.keyboard_interactive !=
ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE)
exclusive_focus = NULL;
if (layer_surface->current.committed == 0 && if (layer_surface->current.committed == 0 &&
l->mapped == layer_surface->surface->mapped) l->mapped == layer_surface->surface->mapped)
return; return;
@ -3290,7 +3295,6 @@ void destroylocksurface(struct wl_listener *listener, void *data) {
if (lock_surface->surface != seat->keyboard_state.focused_surface) { if (lock_surface->surface != seat->keyboard_state.focused_surface) {
if (exclusive_focus && !locked) { if (exclusive_focus && !locked) {
exclusive_focus = NULL;
reset_exclusive_layer(m); reset_exclusive_layer(m);
} }
return; return;
@ -3300,7 +3304,6 @@ void destroylocksurface(struct wl_listener *listener, void *data) {
surface = wl_container_of(cur_lock->surfaces.next, surface, link); surface = wl_container_of(cur_lock->surfaces.next, surface, link);
client_notify_enter(surface->surface, wlr_seat_get_keyboard(seat)); client_notify_enter(surface->surface, wlr_seat_get_keyboard(seat));
} else if (!locked) { } else if (!locked) {
exclusive_focus = NULL;
reset_exclusive_layer(selmon); reset_exclusive_layer(selmon);
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
} else { } else {