Merge pull request #7655 from Sunderland93/master

[Wayland] Implement idle-inhibit support
This commit is contained in:
Twinaphex 2018-11-26 19:25:46 +01:00 committed by GitHub
commit 7a174d290e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 27 deletions

View File

@ -865,7 +865,8 @@ endif
ifeq ($(HAVE_WAYLAND), 1)
OBJ += gfx/drivers_context/wayland_ctx.o \
input/drivers/wayland_input.o \
gfx/common/wayland/xdg-shell.o
gfx/common/wayland/xdg-shell.o \
gfx/common/wayland/idle-inhibit-unstable-v1.o
ifeq ($(HAVE_EGL), 1)
LIBS += $(EGL_LIBS)
endif

View File

@ -9,4 +9,8 @@ fi
#Generate xdg-shell header and .c files
$WAYSCAN client-header $WAYLAND_PROTOS/stable/xdg-shell/xdg-shell.xml $OUTPUT/xdg-shell.h
$WAYSCAN private-code $WAYLAND_PROTOS/stable/xdg-shell/xdg-shell.xml $OUTPUT/xdg-shell.c
$WAYSCAN code $WAYLAND_PROTOS/stable/xdg-shell/xdg-shell.xml $OUTPUT/xdg-shell.c
#Generate idle-inhibit header and .c files
$WAYSCAN client-header $WAYLAND_PROTOS/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml $OUTPUT/idle-inhibit-unstable-v1.h
$WAYSCAN code $WAYLAND_PROTOS/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml $OUTPUT/idle-inhibit-unstable-v1.c

View File

@ -42,15 +42,14 @@
#include "../common/gl_common.h"
#endif
#ifdef HAVE_DBUS
#include "../common/dbus_common.h"
#endif
#include "../common/wayland_common.h"
#include "../../frontend/frontend_driver.h"
#include "../../input/input_driver.h"
#include "../../input/input_keymaps.h"
/* Generated from idle-inhibit-unstable-v1.xml */
#include "../common/wayland/idle-inhibit-unstable-v1.h"
/* Generated from xdg-shell.xml */
#include "../common/wayland/xdg-shell.h"
@ -93,6 +92,8 @@ typedef struct gfx_ctx_wayland_data
struct wl_touch *wl_touch;
struct wl_seat *seat;
struct wl_shm *shm;
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager;
struct zwp_idle_inhibitor_v1 *idle_inhibitor;
int swap_interval;
bool core_hw_context_enable;
@ -684,6 +685,9 @@ static void registry_handle_global(void *data, struct wl_registry *reg,
wl->seat = (struct wl_seat*)wl_registry_bind(reg, id, &wl_seat_interface, 2);
wl_seat_add_listener(wl->seat, &seat_listener, wl);
}
else if (string_is_equal(interface, "zwp_idle_inhibit_manager_v1"))
wl->idle_inhibit_manager = (struct zwp_idle_inhibit_manager_v1*)wl_registry_bind(
reg, id, &zwp_idle_inhibit_manager_v1_interface, 1);
}
static void registry_handle_global_remove(void *data,
@ -766,6 +770,10 @@ static void gfx_ctx_wl_destroy_resources(gfx_ctx_wayland_data_t *wl)
xdg_surface_destroy(wl->xdg_surface);
if (wl->surface)
wl_surface_destroy(wl->surface);
if (wl->idle_inhibit_manager)
zwp_idle_inhibit_manager_v1_destroy(wl->idle_inhibit_manager);
if (wl->idle_inhibitor)
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
if (wl->input.dpy)
{
@ -786,10 +794,6 @@ static void gfx_ctx_wl_destroy_resources(gfx_ctx_wayland_data_t *wl)
wl->width = 0;
wl->height = 0;
#ifdef HAVE_DBUS
dbus_screensaver_uninhibit();
dbus_close_connection();
#endif
}
void flush_wayland_fd(void *data)
@ -1073,6 +1077,11 @@ static void *gfx_ctx_wl_init(video_frame_info_t *video_info, void *video_driver)
goto error;
}
if (!wl->idle_inhibit_manager)
{
RARCH_WARN("[Wayland]: Compositor doesn't support zwp_idle_inhibit_manager_v1 protocol!\n");
}
wl->input.fd = wl_display_get_fd(wl->input.dpy);
switch (wl_api)
@ -1124,10 +1133,6 @@ static void *gfx_ctx_wl_init(video_frame_info_t *video_info, void *video_driver)
flush_wayland_fd(&wl->input);
#ifdef HAVE_DBUS
dbus_ensure_connection();
#endif
return wl;
error:
@ -1406,16 +1411,25 @@ static bool gfx_ctx_wl_has_focus(void *data)
return wl->input.keyboard_focus;
}
static bool gfx_ctx_wl_suppress_screensaver(void *data, bool enable)
static bool gfx_ctx_wl_suppress_screensaver(void *data, bool state)
{
(void)data;
(void)enable;
(void)data;
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
#ifdef HAVE_DBUS
return dbus_suspend_screensaver(enable);
#endif
return true;
if (!wl->idle_inhibit_manager)
return false;
if (state == (!!wl->idle_inhibitor))
return true;
if (state) {
RARCH_LOG("[Wayland]: Enabling idle inhibitor\n");
struct zwp_idle_inhibit_manager_v1 *mgr = wl->idle_inhibit_manager;
wl->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(mgr, wl->surface);
} else {
RARCH_LOG("[Wayland]: Disabling the idle inhibitor\n");
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
wl->idle_inhibitor = NULL;
}
return true;
}
static bool gfx_ctx_wl_has_windowed(void *data)

View File

@ -455,9 +455,9 @@ check_pkgconf V4L2 libv4l2
check_pkgconf FREETYPE freetype2
check_pkgconf X11 x11
check_pkgconf XCB xcb
check_pkgconf WAYLAND wayland-egl 1.15
check_pkgconf WAYLAND_CURSOR wayland-cursor 1.15
check_pkgconf WAYLAND_PROTOS wayland-protocols 1.15
check_pkgconf WAYLAND wayland-egl 1.14
check_pkgconf WAYLAND_CURSOR wayland-cursor 1.14
check_pkgconf WAYLAND_PROTOS wayland-protocols 1.13
check_pkgconf XKBCOMMON xkbcommon 0.3.2
check_pkgconf DBUS dbus-1
check_pkgconf XEXT xext
@ -474,7 +474,7 @@ check_val '' XEXT -lXext
check_val '' XF86VM -lXxf86vm
if [ "$HAVE_WAYLAND_PROTOS" = yes ] && [ "$HAVE_WAYLAND" = yes ]; then
check_pkgconf WAYLAND_SCANNER wayland-scanner 1.15
check_pkgconf WAYLAND_SCANNER wayland-scanner 1.13
./gfx/common/wayland/generate_wayland_protos.sh
else
die : 'Notice: wayland-egl or wayland-protocols not present. Skiping Wayland code paths.'