This repository was archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm_tools: sommelier: allow inhibit sleep on idle
Implement zwp_idle_inhibit_manager_v1[1]. This is a simple pass-through implementation to the host. At present, garcon and concierge already support this feature by implementing dbus org.freedesktop.ScreenSaver[2], but mpv refuses to use this[3]. [1]: https://wayland.app/protocols/idle-inhibit-unstable-v1 [2]: https://people.freedesktop.org/~hadess/idle-inhibition-spec/re01.html [3]: mpv-player/mpv#9275 (comment) BUG=None TEST=`meson test`, `mpv -v --frames=0 <some_video_source> | grep zwp_idle_inhibit_manager_v1`, manually tested with mpv Change-Id: I521ededd5f5c5f96165c04abc47e6aa85153ba8f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/4864538 Reviewed-by: Nic Hollingum <[email protected]> Tested-by: Fabian Bieler <[email protected]> Commit-Queue: Fabian Bieler <[email protected]> Reviewed-by: Chloe Pelling <[email protected]>
- Loading branch information
1 parent
9e0e1d5
commit 89002b8
Showing
7 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<protocol name="idle_inhibit_unstable_v1"> | ||
|
||
<copyright> | ||
Copyright © 2015 Samsung Electronics Co., Ltd | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice (including the next | ||
paragraph) shall be included in all copies or substantial portions of the | ||
Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
</copyright> | ||
|
||
<interface name="zwp_idle_inhibit_manager_v1" version="1"> | ||
<description summary="control behavior when display idles"> | ||
This interface permits inhibiting the idle behavior such as screen | ||
blanking, locking, and screensaving. The client binds the idle manager | ||
globally, then creates idle-inhibitor objects for each surface. | ||
|
||
Warning! The protocol described in this file is experimental and | ||
backward incompatible changes may be made. Backward compatible changes | ||
may be added together with the corresponding interface version bump. | ||
Backward incompatible changes are done by bumping the version number in | ||
the protocol and interface names and resetting the interface version. | ||
Once the protocol is to be declared stable, the 'z' prefix and the | ||
version number in the protocol and interface names are removed and the | ||
interface version number is reset. | ||
</description> | ||
|
||
<request name="destroy" type="destructor"> | ||
<description summary="destroy the idle inhibitor object"> | ||
Destroy the inhibit manager. | ||
</description> | ||
</request> | ||
|
||
<request name="create_inhibitor"> | ||
<description summary="create a new inhibitor object"> | ||
Create a new inhibitor object associated with the given surface. | ||
</description> | ||
<arg name="id" type="new_id" interface="zwp_idle_inhibitor_v1"/> | ||
<arg name="surface" type="object" interface="wl_surface" | ||
summary="the surface that inhibits the idle behavior"/> | ||
</request> | ||
|
||
</interface> | ||
|
||
<interface name="zwp_idle_inhibitor_v1" version="1"> | ||
<description summary="context object for inhibiting idle behavior"> | ||
An idle inhibitor prevents the output that the associated surface is | ||
visible on from being set to a state where it is not visually usable due | ||
to lack of user interaction (e.g. blanked, dimmed, locked, set to power | ||
save, etc.) Any screensaver processes are also blocked from displaying. | ||
|
||
If the surface is destroyed, unmapped, becomes occluded, loses | ||
visibility, or otherwise becomes not visually relevant for the user, the | ||
idle inhibitor will not be honored by the compositor; if the surface | ||
subsequently regains visibility the inhibitor takes effect once again. | ||
Likewise, the inhibitor isn't honored if the system was already idled at | ||
the time the inhibitor was established, although if the system later | ||
de-idles and re-idles the inhibitor will take effect. | ||
</description> | ||
|
||
<request name="destroy" type="destructor"> | ||
<description summary="destroy the idle inhibitor object"> | ||
Remove the inhibitor effect from the associated wl_surface. | ||
</description> | ||
</request> | ||
|
||
</interface> | ||
</protocol> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Copyright 2023 The ChromiumOS Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "sommelier.h" // NOLINT(build/include_directory) | ||
|
||
#include <assert.h> | ||
#include <math.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/mman.h> | ||
#include <unistd.h> | ||
#include <wayland-client.h> | ||
#include <wayland-server-core.h> | ||
#include <wayland-util.h> | ||
|
||
#include "idle-inhibit-unstable-v1-client-protocol.h" // NOLINT(build/include_directory) | ||
#include "idle-inhibit-unstable-v1-server-protocol.h" // NOLINT(build/include_directory) | ||
|
||
struct sl_host_idle_inhibit_manager { | ||
struct sl_context* ctx; | ||
struct wl_resource* resource; | ||
struct zwp_idle_inhibit_manager_v1* proxy; | ||
}; | ||
|
||
struct sl_host_idle_inhibitor { | ||
struct sl_context* ctx; | ||
struct wl_resource* resource; | ||
struct zwp_idle_inhibitor_v1* proxy; | ||
}; | ||
|
||
static void sl_destroy_host_idle_inhibitor(struct wl_resource* resource) { | ||
struct sl_host_idle_inhibitor* host = | ||
static_cast<sl_host_idle_inhibitor*>(wl_resource_get_user_data(resource)); | ||
|
||
zwp_idle_inhibitor_v1_destroy(host->proxy); | ||
wl_resource_set_user_data(resource, nullptr); | ||
delete host; | ||
} | ||
|
||
static void sl_idle_inhibit_destroy(struct wl_client* client, | ||
struct wl_resource* resource) { | ||
wl_resource_destroy(resource); | ||
} | ||
|
||
static struct zwp_idle_inhibitor_v1_interface sl_idle_inhibit_implementation = { | ||
sl_idle_inhibit_destroy, | ||
}; | ||
|
||
static void sl_destroy_host_idle_inhibit_manager(struct wl_resource* resource) { | ||
struct sl_host_idle_inhibit_manager* host = | ||
static_cast<sl_host_idle_inhibit_manager*>( | ||
wl_resource_get_user_data(resource)); | ||
|
||
zwp_idle_inhibit_manager_v1_destroy(host->proxy); | ||
wl_resource_set_user_data(resource, nullptr); | ||
delete host; | ||
} | ||
|
||
static void sl_idle_inhibit_manager_destroy(struct wl_client* client, | ||
struct wl_resource* resource) { | ||
wl_resource_destroy(resource); | ||
} | ||
|
||
static void sl_idle_inhibit_manager_create_inhibitor( | ||
struct wl_client* client, | ||
struct wl_resource* resource, | ||
uint32_t id, | ||
struct wl_resource* surface) { | ||
struct sl_host_idle_inhibit_manager* host = | ||
static_cast<sl_host_idle_inhibit_manager*>( | ||
wl_resource_get_user_data(resource)); | ||
struct sl_host_surface* host_surface = | ||
static_cast<sl_host_surface*>(wl_resource_get_user_data(surface)); | ||
struct wl_resource* idle_inhibit_resource = | ||
wl_resource_create(client, &zwp_idle_inhibitor_v1_interface, 1, id); | ||
struct sl_host_idle_inhibitor* idle_inhibitor_host = | ||
new sl_host_idle_inhibitor(); | ||
idle_inhibitor_host->resource = idle_inhibit_resource; | ||
idle_inhibitor_host->ctx = host->ctx; | ||
idle_inhibitor_host->proxy = zwp_idle_inhibit_manager_v1_create_inhibitor( | ||
host->proxy, host_surface->proxy); | ||
wl_resource_set_implementation( | ||
idle_inhibit_resource, &sl_idle_inhibit_implementation, | ||
idle_inhibitor_host, sl_destroy_host_idle_inhibitor); | ||
} | ||
|
||
static struct zwp_idle_inhibit_manager_v1_interface | ||
sl_idle_inhibit_manager_implementation = { | ||
sl_idle_inhibit_manager_destroy, | ||
sl_idle_inhibit_manager_create_inhibitor, | ||
}; | ||
|
||
static void sl_bind_host_idle_inhibit_manager(struct wl_client* client, | ||
void* data, | ||
uint32_t version, | ||
uint32_t id) { | ||
struct sl_context* ctx = (struct sl_context*)data; | ||
struct sl_idle_inhibit_manager* idle_inhibit_manager = | ||
ctx->idle_inhibit_manager; | ||
struct sl_host_idle_inhibit_manager* host = | ||
new sl_host_idle_inhibit_manager(); | ||
host->ctx = ctx; | ||
host->resource = | ||
wl_resource_create(client, &zwp_idle_inhibit_manager_v1_interface, 1, id); | ||
wl_resource_set_implementation(host->resource, | ||
&sl_idle_inhibit_manager_implementation, host, | ||
sl_destroy_host_idle_inhibit_manager); | ||
host->proxy = static_cast<zwp_idle_inhibit_manager_v1*>(wl_registry_bind( | ||
wl_display_get_registry(ctx->display), idle_inhibit_manager->id, | ||
&zwp_idle_inhibit_manager_v1_interface, | ||
wl_resource_get_version(host->resource))); | ||
zwp_idle_inhibit_manager_v1_set_user_data(host->proxy, host); | ||
} | ||
|
||
struct sl_global* sl_idle_inhibit_manager_global_create( | ||
struct sl_context* ctx) { | ||
return sl_global_create(ctx, &zwp_idle_inhibit_manager_v1_interface, 1, ctx, | ||
sl_bind_host_idle_inhibit_manager); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters