Compare commits

...

8 Commits

Author SHA1 Message Date
Kenny Levinsen
6a447fb02e
Merge 1a1bc78ce5 into d417a8fcd0 2024-11-04 02:25:56 +01:00
Simon Ser
d417a8fcd0 release.sh: read meson-rewrite output from stdout
Since version 1.6, Meson now uses stdout:
3f4957c713
2024-10-31 10:31:38 +01:00
Kenny Levinsen
f38719f575 desktop/output: Add missing output config allocation checks 2024-10-30 19:56:07 -04:00
Kenny Levinsen
1e53007bc3 desktop/output: Store output config on request_state
An output backend might request any change to an output state at any
time, although currently only this is currently only used for changing
window size on the wayland and x11 backend.

Applying the configuration directly means that the current output state
becomes inconsistent with the configured state, which can cause the new
state to be reverted later if apply_stored_output_configs is called.

Before 4f9ce4675c. the output geometry would be updated by
arrange_outputs, but this is only done by the modeset logic now,
resulting in the stored geometry never being updated on wayland backend
window resize. This was not discovered as the stored geometry is not
used particularly often.

Solve both by storing a new output configuration and relying on the
modeset logic to apply a new state.

Fixes: 4f9ce4675c ("tree/arrange: Remove redundant output geometry update")
2024-10-30 19:56:07 -04:00
Kenny Levinsen
1a1bc78ce5 idle_inhibit: Check if layer surface output is enabled
While we we cannot easily check for true visibility of layer surfaces as
easily as for views, we can check at least check that the output
associated with the surface is enabled.
2024-07-10 22:11:51 +02:00
Kenny Levinsen
444017fdac idle_inhibit: Assume view is invisible by default
We have historically considered surfaces without a view visible. This
made sense in case of layer surfaces which do not have a view, but it
also allows unmapped surfaces to act as global inhibitors irrespective
of the current view state, which is not the intention fo the protocol.

As we now explicitly handle layer surfaces, assume that views are only
visible if they can be found and their visibility checked.
2024-07-10 22:11:51 +02:00
Kenny Levinsen
6ccfa7a80b idle_inhibit: Explicitly handle layer surfaces
Layer surfaces do not have a view, and while they can be occluded they
are always visible on their associated output - assuming it is enabled.
2024-07-10 22:11:51 +02:00
Kenny Levinsen
0668c0a3e8 idle_inhibit: Ignore inhibitors when locked
When a session is locked, no views are visible and there is no way to
interact with the user session. This means that all inhibitors based on
visibility - with the exception being inhibitors on the session lock
surfaces themselves - become inert, allowing the session to go idle.

The only inhibitor type on normal views that one could argue should
remain active is INHIBIT_IDLE_OPEN, but for now we disable all view
inhibitors regardless of type.
2024-07-10 22:11:51 +02:00
5 changed files with 95 additions and 16 deletions

View File

@ -1,7 +1,7 @@
#!/bin/sh -eu
prev=$(git describe --tags --abbrev=0)
next=$(meson rewrite kwargs info project / 2>&1 >/dev/null | jq -r '.kwargs["project#/"].version')
next=$(meson rewrite kwargs info project / | jq -r '.kwargs["project#/"].version')
case "$next" in
*-dev)

View File

@ -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"
@ -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) {

View File

@ -457,19 +457,47 @@ static void handle_request_state(struct wl_listener *listener, void *data) {
struct sway_output *output =
wl_container_of(listener, output, request_state);
const struct wlr_output_event_request_state *event = data;
const struct wlr_output_state *state = event->state;
uint32_t committed = event->state->committed;
wlr_output_commit_state(output->wlr_output, event->state);
// Store the requested changes so that the active configuration is
// consistent with the current state, and to avoid duplicate logic to apply
// the changes.
struct output_config *oc = new_output_config(output->wlr_output->name);
if (!oc) {
sway_log(SWAY_ERROR, "Allocation failed");
return;
}
if (committed & (
WLR_OUTPUT_STATE_MODE |
WLR_OUTPUT_STATE_TRANSFORM |
WLR_OUTPUT_STATE_SCALE)) {
arrange_layers(output);
arrange_output(output);
transaction_commit_dirty();
int committed = state->committed;
if (committed & WLR_OUTPUT_STATE_MODE) {
if (state->mode != NULL) {
oc->width = state->mode->width;
oc->height = state->mode->height;
oc->refresh_rate = state->mode->refresh / 1000.f;
} else {
oc->width = state->custom_mode.width;
oc->height = state->custom_mode.height;
oc->refresh_rate = state->custom_mode.refresh / 1000.f;
}
committed &= ~WLR_OUTPUT_STATE_MODE;
}
if (committed & WLR_OUTPUT_STATE_SCALE) {
oc->scale = state->scale;
committed &= ~WLR_OUTPUT_STATE_SCALE;
}
if (committed & WLR_OUTPUT_STATE_TRANSFORM) {
oc->transform = state->transform;
committed &= ~WLR_OUTPUT_STATE_TRANSFORM;
}
update_output_manager_config(output->server);
// We do not expect or support any other changes here
assert(committed == 0);
store_output_config(oc);
apply_stored_output_configs();
if (server.delayed_modeset != NULL) {
wl_event_source_remove(server.delayed_modeset);
server.delayed_modeset = NULL;
}
}
@ -554,6 +582,10 @@ void handle_new_output(struct wl_listener *listener, void *data) {
static struct output_config *output_config_for_config_head(
struct wlr_output_configuration_head_v1 *config_head) {
struct output_config *oc = new_output_config(config_head->state.output->name);
if (!oc) {
return NULL;
}
oc->enabled = config_head->state.enabled;
if (!oc->enabled) {
return oc;
@ -584,7 +616,8 @@ static void output_manager_apply(struct sway_server *server,
size_t configs_len = config->output_configs->length + wl_list_length(&cfg->heads);
struct output_config **configs = calloc(configs_len, sizeof(*configs));
if (!configs) {
goto done;
sway_log(SWAY_ERROR, "Allocation failed");
goto error;
}
size_t start_new_configs = config->output_configs->length;
for (size_t idx = 0; idx < start_new_configs; idx++) {
@ -597,6 +630,10 @@ static void output_manager_apply(struct sway_server *server,
// Generate the configuration and store it as a temporary
// config. We keep a record of it so we can remove it later.
struct output_config *oc = output_config_for_config_head(config_head);
if (!oc) {
sway_log(SWAY_ERROR, "Allocation failed");
goto error_config;
}
configs[config_idx++] = oc;
}
@ -604,6 +641,8 @@ static void output_manager_apply(struct sway_server *server,
// if any output configured for enablement fails to be enabled, even if it
// was not part of the config heads we were asked to configure.
ok = apply_output_configs(configs, configs_len, test_only, false);
error_config:
for (size_t idx = start_new_configs; idx < configs_len; idx++) {
struct output_config *cfg = configs[idx];
if (!test_only && ok) {
@ -614,7 +653,7 @@ static void output_manager_apply(struct sway_server *server,
}
free(configs);
done:
error:
if (ok) {
wlr_output_configuration_v1_send_succeeded(cfg);
if (server->delayed_modeset != NULL) {
@ -649,6 +688,11 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener,
struct sway_output *output = event->output->data;
struct output_config *oc = new_output_config(output->wlr_output->name);
if (!oc) {
sway_log(SWAY_ERROR, "Allocation failed");
return;
}
switch (event->mode) {
case ZWLR_OUTPUT_POWER_V1_MODE_OFF:
oc->power = 0;

View File

@ -234,6 +234,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) {
@ -297,6 +300,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) {

View File

@ -188,6 +188,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);