gdk/wayland: Add an API to inhibit and uninhibit idle

This uses the idle-inhibit protocol from wayland-protocols, to attach an
inhibitor to the GdkSurface.  The inhibit function can be called as many
times as the user wants, but the uninhibit function MUST be called as
many times to unset the idle inhibition.

This has been tested on Sway.
This commit is contained in:
Emmanuel Gil Peyrot 2020-07-14 21:18:03 +02:00
parent 38cce2bb18
commit 74a4432688
5 changed files with 48 additions and 0 deletions

View File

@ -544,6 +544,12 @@ gdk_registry_handle_global (void *data,
gdk_wayland_display_init_xdg_output (display_wayland);
_gdk_wayland_display_async_roundtrip (display_wayland);
}
else if (strcmp(interface, "zwp_idle_inhibit_manager_v1") == 0)
{
display_wayland->idle_inhibit_manager =
wl_registry_bind (display_wayland->wl_registry, id,
&zwp_idle_inhibit_manager_v1_interface, 1);
}
g_hash_table_insert (display_wayland->known_globals,
GUINT_TO_POINTER (id), g_strdup (interface));

View File

@ -35,6 +35,7 @@
#include <gdk/wayland/keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h>
#include <gdk/wayland/server-decoration-client-protocol.h>
#include <gdk/wayland/xdg-output-unstable-v1-client-protocol.h>
#include <gdk/wayland/idle-inhibit-unstable-v1-client-protocol.h>
#include <glib.h>
#include <gdk/gdkkeys.h>
@ -109,6 +110,7 @@ struct _GdkWaylandDisplay
struct zwp_keyboard_shortcuts_inhibit_manager_v1 *keyboard_shortcuts_inhibit;
struct org_kde_kwin_server_decoration_manager *server_decoration_manager;
struct zxdg_output_manager_v1 *xdg_output_manager;
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager;
GList *async_roundtrips;

View File

@ -191,6 +191,9 @@ struct _GdkWaylandSurface
struct zxdg_imported_v1 *imported_transient_for;
GHashTable *shortcuts_inhibitors;
struct zwp_idle_inhibitor_v1 *idle_inhibitor;
size_t idle_inhibitor_refcount;
};
struct _GdkWaylandSurfaceClass
@ -1984,6 +1987,39 @@ gdk_wayland_surface_announce_csd (GdkSurface *surface)
ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_CLIENT);
}
gboolean
gdk_wayland_surface_inhibit_idle (GdkSurface *surface)
{
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (gdk_surface_get_display (surface));
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
if (!display_wayland->idle_inhibit_manager)
return false;
if (!impl->idle_inhibitor)
{
g_assert (impl->idle_inhibitor_refcount == 0);
impl->idle_inhibitor =
zwp_idle_inhibit_manager_v1_create_inhibitor (display_wayland->idle_inhibit_manager,
impl->display_server.wl_surface);
}
++impl->idle_inhibitor_refcount;
return true;
}
void
gdk_wayland_surface_uninhibit_idle (GdkSurface *surface)
{
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
g_assert (impl->idle_inhibitor && impl->idle_inhibitor_refcount > 0);
if (--impl->idle_inhibitor_refcount == 0)
{
zwp_idle_inhibitor_v1_destroy (impl->idle_inhibitor);
impl->idle_inhibitor = NULL;
}
}
static void
calculate_popup_rect (GdkSurface *surface,
GdkPopupLayout *layout,

View File

@ -80,6 +80,9 @@ void gdk_wayland_surface_set_application_id (GdkSurface *sur
void gdk_wayland_surface_announce_csd (GdkSurface *surface);
gboolean gdk_wayland_surface_inhibit_idle (GdkSurface *surface);
void gdk_wayland_surface_uninhibit_idle (GdkSurface *surface);
G_END_DECLS
#endif /* __GDK_WAYLAND_SURFACE_H__ */

View File

@ -54,6 +54,7 @@ proto_sources = [
['keyboard-shortcuts-inhibit', 'unstable', 'v1', ],
['server-decoration', 'private' ],
['xdg-output', 'unstable', 'v1', ],
['idle-inhibit', 'unstable', 'v1', ],
]
gdk_wayland_gen_headers = []