/*
* This file is part of mpv video player.
*
* mpv is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* mpv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <limits.h>
#include <poll.h>
#include <unistd.h>
#include <linux/input.h>
#include <time.h>
#include "common/msg.h"
#include "options/m_config.h"
#include "input/input.h"
#include "input/keycodes.h"
#include "osdep/io.h"
#include "osdep/timer.h"
#include "win_state.h"
#include "wayland_common.h"
// Generated from xdg-shell.xml
#include "video/out/wayland/xdg-shell.h"
// Generated from idle-inhibit-unstable-v1.xml
#include "video/out/wayland/idle-inhibit-v1.h"
// Generated from xdg-decoration-unstable-v1.xml
#include "video/out/wayland/xdg-decoration-v1.h"
// Generated from presentation-time.xml
#include "video/out/wayland/presentation-time.h"
#define OPT_BASE_STRUCT struct wayland_opts
const struct m_sub_options wayland_conf = {
.opts = (const struct m_option[]) {
OPT_INTRANGE("wayland-frame-wait-offset", frame_offset, 0, -500, 3000),
OPT_FLAG("wayland-disable-vsync", disable_vsync, 0),
{0},
},
.size = sizeof(struct wayland_opts),
.defaults = &(struct wayland_opts) {
.frame_offset = 1000,
.disable_vsync = false,
},
};
static void xdg_wm_base_ping(void *data, struct xdg_wm_base *wm_base, uint32_t serial)
{
xdg_wm_base_pong(wm_base, serial);
}
static const struct xdg_wm_base_listener xdg_wm_base_listener = {
xdg_wm_base_ping,
};
static int spawn_cursor(struct vo_wayland_state *wl)
{
if (wl->allocated_cursor_scale == wl->scaling) /* Reuse if size is identical */
return 0;
else if (wl->cursor_theme)
wl_cursor_theme_destroy(wl->cursor_theme);
const char *size_str = getenv("XCURSOR_SIZE");
int size = 32;
if (size_str != NULL) {
errno = 0;
char *end;
long size_long = strtol(size_str, &end, 10);
if (!*end && !errno && size_long > 0 && size_long <= INT_MAX)
size = (int)size_long;
}
wl->cursor_theme = wl_cursor_theme_load(NULL, size*wl->scaling, wl->shm);
if (!wl->cursor_theme) {
MP_ERR(wl, "Unable to load cursor theme!\n");
return 1;
}
wl->default_cursor = wl_cursor_theme_get_cursor(wl->cursor_theme, "left_ptr");
if (!wl->default_cursor) {
MP_ERR(wl, "Unable to load cursor theme!\n");
return 1;
}
wl->allocated_cursor_scale = wl->scaling;
return 0;
}
static int set_cursor_visibility(struct vo_wayland_state *wl, bool on)
{
if (!wl->pointer)
return VO_NOTAVAIL;
wl->cursor_visible = on;
if (on) {
if (spawn_cursor(wl))
return VO_FALSE;
struct wl_cursor_image *img = wl->default_cursor->images[0];
struct wl_buffer *buffer = wl_cursor_image_get_buffer(img);
if (!buffer)
return VO_FALSE;
wl_pointer_set_cursor(wl->pointer, wl->pointer_id, wl->cursor_surface,
img->hotspot_x/wl->scaling, img->hotspot_y/wl->scaling);
wl_surface_set_buffer_scale(wl->cursor_surface, wl->scaling);
wl_surface_attach(wl->cursor_surface, buffer, 0, 0);
wl_surface_damage(wl->cursor_surface, 0, 0, img->width, img->height);
wl_surface_commit(wl->cursor_surface);
} else {
wl_pointer_set_cursor(wl->pointer, wl->pointer_id, NULL, 0, 0);
}
return VO_TRUE;
}
stati
|