Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idle_inhibit: Session lock and unmapped surface fixes #8175

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions sway/desktop/idle_inhibit_v1.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/types/wlr_session_lock_v1.h>
#include "log.h"
#include "sway/desktop/idle_inhibit_v1.h"
#include "sway/input/seat.h"
Expand Down Expand Up @@ -103,11 +104,34 @@ void sway_idle_inhibit_v1_user_inhibitor_destroy(
}

bool sway_idle_inhibit_v1_is_active(struct sway_idle_inhibitor_v1 *inhibitor) {
if (server.session_lock.lock) {
// A session lock is active. In this case, only application inhibitors
// on the session lock surface can have any effect.
if (inhibitor->mode != INHIBIT_IDLE_APPLICATION) {
return false;
}
struct wlr_surface *wlr_surface = inhibitor->wlr_inhibitor->surface;
if (!wlr_session_lock_surface_v1_try_from_wlr_surface(wlr_surface)) {
return false;
}
return wlr_surface->mapped;
}

switch (inhibitor->mode) {
case INHIBIT_IDLE_APPLICATION:;
// If there is no view associated with the inhibitor, assume visible
struct sway_view *view = view_from_wlr_surface(inhibitor->wlr_inhibitor->surface);
return !view || !view->container || view_is_visible(view);
struct wlr_surface *wlr_surface = inhibitor->wlr_inhibitor->surface;
struct wlr_layer_surface_v1 *layer_surface =
wlr_layer_surface_v1_try_from_wlr_surface(wlr_surface);
if (layer_surface) {
// Layer surfaces can be occluded but are always on screen after
// they have been mapped.
return layer_surface->output && layer_surface->output->enabled &&
wlr_surface->mapped;
}

// If there is no view associated with the inhibitor, assume invisible
struct sway_view *view = view_from_wlr_surface(wlr_surface);
return view && view->container && view_is_visible(view);
case INHIBIT_IDLE_FOCUS:;
struct sway_seat *seat = NULL;
wl_list_for_each(seat, &server.input->seats, link) {
Expand Down
7 changes: 7 additions & 0 deletions sway/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ static void handle_unlock(struct wl_listener *listener, void *data) {
struct sway_output *output = root->outputs->items[i];
arrange_layers(output);
}

// Views are now visible, so check if we need to activate inhibition again.
sway_idle_inhibit_v1_check_active();
}

static void handle_abandon(struct wl_listener *listener, void *data) {
Expand Down Expand Up @@ -302,6 +305,10 @@ static void handle_session_lock(struct wl_listener *listener, void *data) {

wlr_session_lock_v1_send_locked(lock);
server.session_lock.lock = sway_lock;

// The lock screen covers everything, so check if any active inhibition got
// deactivated due to lost visibility.
sway_idle_inhibit_v1_check_active();
}

static void handle_session_lock_destroy(struct wl_listener *listener, void *data) {
Expand Down
4 changes: 4 additions & 0 deletions sway/tree/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
}

bool view_inhibit_idle(struct sway_view *view) {
if (server.session_lock.lock) {
return false;
}

struct sway_idle_inhibitor_v1 *user_inhibitor =
sway_idle_inhibit_v1_user_inhibitor_for_view(view);

Expand Down