2013-02-28 18:55:02 +00:00
|
|
|
/*
|
2013-09-09 16:37:33 +00:00
|
|
|
* This file is part of mpv video player.
|
2013-02-28 18:55:02 +00:00
|
|
|
* Copyright © 2008 Kristian Høgsberg
|
|
|
|
* Copyright © 2012-2013 Collabora, Ltd.
|
2013-09-09 16:37:33 +00:00
|
|
|
* Copyright © 2013 Alexander Preisinger <alexander.preisinger@gmail.com>
|
2013-02-28 18:55:02 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* 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.
|
2013-02-28 18:55:02 +00:00
|
|
|
*
|
2013-09-09 16:37:33 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2013-02-28 18:55:02 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-02-28 18:55:02 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2013-02-28 18:55:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <assert.h>
|
2013-05-01 13:41:33 +00:00
|
|
|
#include <poll.h>
|
2013-02-28 18:55:02 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2013-02-28 18:55:02 +00:00
|
|
|
|
|
|
|
#include "wayland_common.h"
|
|
|
|
|
|
|
|
#include "vo.h"
|
2014-05-06 21:16:18 +00:00
|
|
|
#include "win_state.h"
|
2016-07-21 11:25:30 +00:00
|
|
|
#include "osdep/io.h"
|
2013-02-28 18:55:02 +00:00
|
|
|
#include "osdep/timer.h"
|
|
|
|
|
2013-12-17 00:23:09 +00:00
|
|
|
#include "input/input.h"
|
2014-01-04 15:59:22 +00:00
|
|
|
#include "input/event.h"
|
2013-12-17 00:23:09 +00:00
|
|
|
#include "input/keycodes.h"
|
2013-02-28 18:55:02 +00:00
|
|
|
|
|
|
|
static int lookupkey(int key);
|
|
|
|
|
2013-03-22 18:37:28 +00:00
|
|
|
static void hide_cursor(struct vo_wayland_state * wl);
|
|
|
|
static void show_cursor(struct vo_wayland_state * wl);
|
2014-08-06 10:41:33 +00:00
|
|
|
static void window_move(struct vo_wayland_state * wl, uint32_t serial);
|
|
|
|
static void window_set_title(struct vo_wayland_state * wl, const char *title);
|
2014-05-14 18:29:08 +00:00
|
|
|
static void schedule_resize(struct vo_wayland_state *wl,
|
|
|
|
uint32_t edges,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static void vo_wayland_fullscreen(struct vo *vo);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2015-03-22 00:47:27 +00:00
|
|
|
static const struct wl_callback_listener frame_listener;
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
static const struct mp_keymap keymap[] = {
|
|
|
|
// special keys
|
|
|
|
{XKB_KEY_Pause, MP_KEY_PAUSE}, {XKB_KEY_Escape, MP_KEY_ESC},
|
|
|
|
{XKB_KEY_BackSpace, MP_KEY_BS}, {XKB_KEY_Tab, MP_KEY_TAB},
|
|
|
|
{XKB_KEY_Return, MP_KEY_ENTER}, {XKB_KEY_Menu, MP_KEY_MENU},
|
|
|
|
{XKB_KEY_Print, MP_KEY_PRINT},
|
|
|
|
|
|
|
|
// cursor keys
|
|
|
|
{XKB_KEY_Left, MP_KEY_LEFT}, {XKB_KEY_Right, MP_KEY_RIGHT},
|
|
|
|
{XKB_KEY_Up, MP_KEY_UP}, {XKB_KEY_Down, MP_KEY_DOWN},
|
|
|
|
|
|
|
|
// navigation block
|
|
|
|
{XKB_KEY_Insert, MP_KEY_INSERT}, {XKB_KEY_Delete, MP_KEY_DELETE},
|
|
|
|
{XKB_KEY_Home, MP_KEY_HOME}, {XKB_KEY_End, MP_KEY_END},
|
|
|
|
{XKB_KEY_Page_Up, MP_KEY_PAGE_UP}, {XKB_KEY_Page_Down, MP_KEY_PAGE_DOWN},
|
|
|
|
|
|
|
|
// F-keys
|
|
|
|
{XKB_KEY_F1, MP_KEY_F+1}, {XKB_KEY_F2, MP_KEY_F+2},
|
|
|
|
{XKB_KEY_F3, MP_KEY_F+3}, {XKB_KEY_F4, MP_KEY_F+4},
|
|
|
|
{XKB_KEY_F5, MP_KEY_F+5}, {XKB_KEY_F6, MP_KEY_F+6},
|
|
|
|
{XKB_KEY_F7, MP_KEY_F+7}, {XKB_KEY_F8, MP_KEY_F+8},
|
|
|
|
{XKB_KEY_F9, MP_KEY_F+9}, {XKB_KEY_F10, MP_KEY_F+10},
|
|
|
|
{XKB_KEY_F11, MP_KEY_F+11}, {XKB_KEY_F12, MP_KEY_F+12},
|
|
|
|
|
|
|
|
// numpad independent of numlock
|
|
|
|
{XKB_KEY_KP_Subtract, '-'}, {XKB_KEY_KP_Add, '+'},
|
|
|
|
{XKB_KEY_KP_Multiply, '*'}, {XKB_KEY_KP_Divide, '/'},
|
|
|
|
{XKB_KEY_KP_Enter, MP_KEY_KPENTER},
|
|
|
|
|
|
|
|
// numpad with numlock
|
|
|
|
{XKB_KEY_KP_0, MP_KEY_KP0}, {XKB_KEY_KP_1, MP_KEY_KP1},
|
|
|
|
{XKB_KEY_KP_2, MP_KEY_KP2}, {XKB_KEY_KP_3, MP_KEY_KP3},
|
|
|
|
{XKB_KEY_KP_4, MP_KEY_KP4}, {XKB_KEY_KP_5, MP_KEY_KP5},
|
|
|
|
{XKB_KEY_KP_6, MP_KEY_KP6}, {XKB_KEY_KP_7, MP_KEY_KP7},
|
|
|
|
{XKB_KEY_KP_8, MP_KEY_KP8}, {XKB_KEY_KP_9, MP_KEY_KP9},
|
|
|
|
{XKB_KEY_KP_Decimal, MP_KEY_KPDEC}, {XKB_KEY_KP_Separator, MP_KEY_KPDEC},
|
|
|
|
|
|
|
|
// numpad without numlock
|
|
|
|
{XKB_KEY_KP_Insert, MP_KEY_KPINS}, {XKB_KEY_KP_End, MP_KEY_KP1},
|
|
|
|
{XKB_KEY_KP_Down, MP_KEY_KP2}, {XKB_KEY_KP_Page_Down, MP_KEY_KP3},
|
|
|
|
{XKB_KEY_KP_Left, MP_KEY_KP4}, {XKB_KEY_KP_Begin, MP_KEY_KP5},
|
|
|
|
{XKB_KEY_KP_Right, MP_KEY_KP6}, {XKB_KEY_KP_Home, MP_KEY_KP7},
|
|
|
|
{XKB_KEY_KP_Up, MP_KEY_KP8}, {XKB_KEY_KP_Page_Up, MP_KEY_KP9},
|
|
|
|
{XKB_KEY_KP_Delete, MP_KEY_KPDEL},
|
|
|
|
|
2014-11-29 17:38:24 +00:00
|
|
|
// "Multimedia keyboard" keys
|
|
|
|
{XKB_KEY_XF86MenuKB, MP_KEY_MENU},
|
|
|
|
{XKB_KEY_XF86AudioPlay, MP_KEY_PLAY}, {XKB_KEY_XF86AudioPause, MP_KEY_PAUSE},
|
|
|
|
{XKB_KEY_XF86AudioStop, MP_KEY_STOP},
|
|
|
|
{XKB_KEY_XF86AudioPrev, MP_KEY_PREV}, {XKB_KEY_XF86AudioNext, MP_KEY_NEXT},
|
|
|
|
{XKB_KEY_XF86AudioRewind, MP_KEY_REWIND},
|
|
|
|
{XKB_KEY_XF86AudioForward, MP_KEY_FORWARD},
|
|
|
|
{XKB_KEY_XF86AudioMute, MP_KEY_MUTE},
|
|
|
|
{XKB_KEY_XF86AudioLowerVolume, MP_KEY_VOLUME_DOWN},
|
|
|
|
{XKB_KEY_XF86AudioRaiseVolume, MP_KEY_VOLUME_UP},
|
|
|
|
{XKB_KEY_XF86HomePage, MP_KEY_HOMEPAGE}, {XKB_KEY_XF86WWW, MP_KEY_WWW},
|
|
|
|
{XKB_KEY_XF86Mail, MP_KEY_MAIL}, {XKB_KEY_XF86Favorites, MP_KEY_FAVORITES},
|
|
|
|
{XKB_KEY_XF86Search, MP_KEY_SEARCH}, {XKB_KEY_XF86Sleep, MP_KEY_SLEEP},
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
/** Wayland listeners **/
|
2013-12-04 19:21:15 +00:00
|
|
|
|
2013-02-28 18:55:02 +00:00
|
|
|
static void ssurface_handle_ping(void *data,
|
|
|
|
struct wl_shell_surface *shell_surface,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
wl_shell_surface_pong(shell_surface, serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ssurface_handle_configure(void *data,
|
|
|
|
struct wl_shell_surface *shell_surface,
|
|
|
|
uint32_t edges,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
2016-07-29 22:02:32 +00:00
|
|
|
float win_aspect = wl->window.aspect;
|
2016-08-29 12:20:35 +00:00
|
|
|
if (!width || !height)
|
|
|
|
return;
|
2016-07-29 22:02:32 +00:00
|
|
|
if (!wl->window.is_fullscreen)
|
|
|
|
width = win_aspect * height;
|
2014-05-14 18:29:08 +00:00
|
|
|
schedule_resize(wl, edges, width, height);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ssurface_handle_popup_done(void *data,
|
|
|
|
struct wl_shell_surface *shell_surface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-08 15:15:26 +00:00
|
|
|
static const struct wl_shell_surface_listener shell_surface_listener = {
|
2013-02-28 18:55:02 +00:00
|
|
|
ssurface_handle_ping,
|
|
|
|
ssurface_handle_configure,
|
|
|
|
ssurface_handle_popup_done
|
|
|
|
};
|
|
|
|
|
|
|
|
static void output_handle_geometry(void *data,
|
|
|
|
struct wl_output *wl_output,
|
|
|
|
int32_t x,
|
|
|
|
int32_t y,
|
|
|
|
int32_t physical_width,
|
|
|
|
int32_t physical_height,
|
|
|
|
int32_t subpixel,
|
|
|
|
const char *make,
|
|
|
|
const char *model,
|
|
|
|
int32_t transform)
|
|
|
|
{
|
2014-09-03 19:30:19 +00:00
|
|
|
struct vo_wayland_output *output = data;
|
|
|
|
output->make = make;
|
|
|
|
output->model = model;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void output_handle_mode(void *data,
|
|
|
|
struct wl_output *wl_output,
|
|
|
|
uint32_t flags,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height,
|
|
|
|
int32_t refresh)
|
|
|
|
{
|
2013-05-02 18:56:59 +00:00
|
|
|
struct vo_wayland_output *output = data;
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2014-09-03 19:14:37 +00:00
|
|
|
// only save current mode
|
|
|
|
if (!output || !(flags & WL_OUTPUT_MODE_CURRENT))
|
2013-05-02 18:56:59 +00:00
|
|
|
return;
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-05-02 18:56:59 +00:00
|
|
|
output->width = width;
|
|
|
|
output->height = height;
|
|
|
|
output->flags = flags;
|
2014-08-18 20:00:39 +00:00
|
|
|
output->refresh_rate = refresh;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 17:34:31 +00:00
|
|
|
static void output_handle_done(void* data, struct wl_output *wl_output)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void output_handle_scale(void* data, struct wl_output *wl_output,
|
|
|
|
int32_t factor)
|
|
|
|
{
|
|
|
|
struct vo_wayland_output *output = data;
|
|
|
|
output->scale = factor;
|
|
|
|
}
|
|
|
|
|
2014-01-08 15:15:26 +00:00
|
|
|
static const struct wl_output_listener output_listener = {
|
2013-02-28 18:55:02 +00:00
|
|
|
output_handle_geometry,
|
2016-05-30 17:34:31 +00:00
|
|
|
output_handle_mode,
|
|
|
|
output_handle_done,
|
|
|
|
output_handle_scale
|
2013-02-28 18:55:02 +00:00
|
|
|
};
|
|
|
|
|
2014-08-18 20:00:39 +00:00
|
|
|
|
|
|
|
/* SURFACE LISTENER */
|
|
|
|
|
|
|
|
static void surface_handle_enter(void *data,
|
|
|
|
struct wl_surface *wl_surface,
|
|
|
|
struct wl_output *output)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
wl->display.current_output = NULL;
|
|
|
|
|
|
|
|
struct vo_wayland_output *o;
|
|
|
|
wl_list_for_each(o, &wl->display.output_list, link) {
|
|
|
|
if (o->output == output) {
|
|
|
|
wl->display.current_output = o;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-05-30 23:38:55 +00:00
|
|
|
|
2016-07-21 11:25:30 +00:00
|
|
|
wl->window.events |= VO_EVENT_WIN_STATE | VO_EVENT_RESIZE;
|
2014-08-18 20:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void surface_handle_leave(void *data,
|
|
|
|
struct wl_surface *wl_surface,
|
|
|
|
struct wl_output *output)
|
|
|
|
{
|
|
|
|
// window can be displayed at 2 output, but we only use the most recently
|
|
|
|
// entered and discard the previous one even if a part of the window is
|
|
|
|
// still visible on the previous entered output.
|
|
|
|
// Don't bother with a "leave" logic
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_surface_listener surface_listener = {
|
|
|
|
surface_handle_enter,
|
|
|
|
surface_handle_leave
|
|
|
|
};
|
|
|
|
|
2013-02-28 18:55:02 +00:00
|
|
|
/* KEYBOARD LISTENER */
|
|
|
|
static void keyboard_handle_keymap(void *data,
|
|
|
|
struct wl_keyboard *wl_keyboard,
|
|
|
|
uint32_t format,
|
|
|
|
int32_t fd,
|
|
|
|
uint32_t size)
|
|
|
|
{
|
2013-07-18 15:35:28 +00:00
|
|
|
struct vo_wayland_state *wl = data;
|
2013-02-28 18:55:02 +00:00
|
|
|
char *map_str;
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
|
2013-02-28 18:55:02 +00:00
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
|
|
|
if (map_str == MAP_FAILED) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-12 23:02:01 +00:00
|
|
|
wl->input.xkb.keymap = xkb_keymap_new_from_string(wl->input.xkb.context,
|
2013-07-18 15:35:28 +00:00
|
|
|
map_str,
|
|
|
|
XKB_KEYMAP_FORMAT_TEXT_V1,
|
|
|
|
0);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
|
|
|
munmap(map_str, size);
|
|
|
|
close(fd);
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
if (!wl->input.xkb.keymap) {
|
2013-09-12 14:29:13 +00:00
|
|
|
MP_ERR(wl, "failed to compile keymap\n");
|
2013-02-28 18:55:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->input.xkb.state = xkb_state_new(wl->input.xkb.keymap);
|
|
|
|
if (!wl->input.xkb.state) {
|
2013-09-12 14:29:13 +00:00
|
|
|
MP_ERR(wl, "failed to create XKB state\n");
|
2014-08-20 15:16:18 +00:00
|
|
|
xkb_keymap_unref(wl->input.xkb.keymap);
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->input.xkb.keymap = NULL;
|
2013-02-28 18:55:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void keyboard_handle_enter(void *data,
|
|
|
|
struct wl_keyboard *wl_keyboard,
|
|
|
|
uint32_t serial,
|
|
|
|
struct wl_surface *surface,
|
|
|
|
struct wl_array *keys)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void keyboard_handle_leave(void *data,
|
|
|
|
struct wl_keyboard *wl_keyboard,
|
|
|
|
uint32_t serial,
|
|
|
|
struct wl_surface *surface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void keyboard_handle_key(void *data,
|
|
|
|
struct wl_keyboard *wl_keyboard,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t time,
|
|
|
|
uint32_t key,
|
|
|
|
uint32_t state)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
|
2015-01-12 15:41:00 +00:00
|
|
|
uint32_t code = code = key + 8;
|
|
|
|
xkb_keysym_t sym = xkb_state_key_get_one_sym(wl->input.xkb.state, code);
|
|
|
|
|
|
|
|
int mpmod = state == WL_KEYBOARD_KEY_STATE_PRESSED ? MP_KEY_STATE_DOWN
|
|
|
|
: MP_KEY_STATE_UP;
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2015-01-12 15:41:00 +00:00
|
|
|
static const char *mod_names[] = {XKB_MOD_NAME_SHIFT, XKB_MOD_NAME_CTRL,
|
|
|
|
XKB_MOD_NAME_ALT, XKB_MOD_NAME_LOGO, 0};
|
|
|
|
static int mods[] = {MP_KEY_MODIFIER_SHIFT, MP_KEY_MODIFIER_CTRL,
|
|
|
|
MP_KEY_MODIFIER_ALT, MP_KEY_MODIFIER_META, 0};
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2015-01-12 15:41:00 +00:00
|
|
|
for (int n = 0; mods[n]; n++) {
|
|
|
|
xkb_mod_index_t index =
|
|
|
|
xkb_keymap_mod_get_index(wl->input.xkb.keymap, mod_names[n]);
|
|
|
|
if (!xkb_state_mod_index_is_consumed(wl->input.xkb.state, code, index)
|
|
|
|
&& xkb_state_mod_index_is_active(wl->input.xkb.state, index,
|
|
|
|
XKB_STATE_MODS_DEPRESSED))
|
|
|
|
mpmod |= mods[n];
|
|
|
|
}
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2015-01-12 15:41:00 +00:00
|
|
|
int mpkey = lookupkey(sym);
|
|
|
|
if (mpkey) {
|
|
|
|
mp_input_put_key(wl->vo->input_ctx, mpkey | mpmod);
|
|
|
|
} else {
|
|
|
|
char s[80];
|
|
|
|
if (xkb_keysym_to_utf8(sym, s, sizeof(s)) > 0)
|
|
|
|
mp_input_put_key_utf8(wl->vo->input_ctx, mpmod, bstr0(s));
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void keyboard_handle_modifiers(void *data,
|
|
|
|
struct wl_keyboard *wl_keyboard,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t mods_depressed,
|
|
|
|
uint32_t mods_latched,
|
|
|
|
uint32_t mods_locked,
|
|
|
|
uint32_t group)
|
|
|
|
{
|
2013-07-18 15:35:28 +00:00
|
|
|
struct vo_wayland_state *wl = data;
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
xkb_state_update_mask(wl->input.xkb.state,
|
|
|
|
mods_depressed,
|
|
|
|
mods_latched,
|
|
|
|
mods_locked,
|
|
|
|
0, 0, group);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 15:38:24 +00:00
|
|
|
static void keyboard_handle_repeat_info(void *data,
|
|
|
|
struct wl_keyboard *wl_keyboard,
|
|
|
|
int32_t rate,
|
|
|
|
int32_t delay)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
if (wl->vo->opts->native_keyrepeat) {
|
|
|
|
if (rate < 0 || delay < 0) {
|
|
|
|
MP_WARN(wl, "Invalid rate or delay values sent by compositor\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mp_input_set_repeat_info(wl->vo->input_ctx, rate, delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-08 15:15:26 +00:00
|
|
|
static const struct wl_keyboard_listener keyboard_listener = {
|
2013-02-28 18:55:02 +00:00
|
|
|
keyboard_handle_keymap,
|
|
|
|
keyboard_handle_enter,
|
|
|
|
keyboard_handle_leave,
|
|
|
|
keyboard_handle_key,
|
2014-09-19 15:38:24 +00:00
|
|
|
keyboard_handle_modifiers,
|
|
|
|
keyboard_handle_repeat_info
|
2013-02-28 18:55:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* POINTER LISTENER */
|
|
|
|
static void pointer_handle_enter(void *data,
|
|
|
|
struct wl_pointer *pointer,
|
|
|
|
uint32_t serial,
|
|
|
|
struct wl_surface *surface,
|
|
|
|
wl_fixed_t sx_w,
|
|
|
|
wl_fixed_t sy_w)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->cursor.serial = serial;
|
|
|
|
wl->cursor.pointer = pointer;
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-09-24 16:53:19 +00:00
|
|
|
/* Release the left button on pointer enter again
|
|
|
|
* because after moving the shell surface no release event is sent */
|
2015-02-17 05:50:57 +00:00
|
|
|
mp_input_put_key(wl->vo->input_ctx, MP_KEY_MOUSE_ENTER);
|
input: use mnemonic names for mouse buttons
mpv's mouse button numbering is based on X11 button numbering, which
allows for an arbitrary number of buttons and includes mouse wheel input
as buttons 3-6. This button numbering was used throughout the codebase
and exposed in input.conf, and it was difficult to remember which
physical button each number actually referred to and which referred to
the scroll wheel.
In practice, PC mice only have between two and five buttons and one or
two scroll wheel axes, which are more or less in the same location and
have more or less the same function. This allows us to use names to
refer to the buttons instead of numbers, which makes input.conf syntax a
lot easier to remember. It also makes the syntax robust to changes in
mpv's underlying numbering. The old MOUSE_BTNx names are still
understood as deprecated aliases of the named buttons.
This changes both the input.conf syntax and the MP_MOUSE_BTNx symbols in
the codebase, since I think both would benefit from using names over
numbers, especially since some platforms don't use X11 button numbering
and handle different mouse buttons in different windowing system events.
This also makes the names shorter, since otherwise they would be pretty
long, and it removes the high-numbered MOUSE_BTNx_DBL names, since they
weren't used.
Names are the same as used in Qt:
https://doc.qt.io/qt-5/qt.html#MouseButton-enum
2017-08-08 11:34:38 +00:00
|
|
|
mp_input_put_key(wl->vo->input_ctx, MP_MBTN_LEFT | MP_KEY_STATE_UP);
|
2013-05-19 11:04:59 +00:00
|
|
|
show_cursor(wl);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pointer_handle_leave(void *data,
|
|
|
|
struct wl_pointer *pointer,
|
|
|
|
uint32_t serial,
|
|
|
|
struct wl_surface *surface)
|
|
|
|
{
|
2013-07-02 15:31:43 +00:00
|
|
|
struct vo_wayland_state *wl = data;
|
2013-07-02 16:56:50 +00:00
|
|
|
mp_input_put_key(wl->vo->input_ctx, MP_KEY_MOUSE_LEAVE);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pointer_handle_motion(void *data,
|
|
|
|
struct wl_pointer *pointer,
|
|
|
|
uint32_t time,
|
|
|
|
wl_fixed_t sx_w,
|
|
|
|
wl_fixed_t sy_w)
|
|
|
|
{
|
2016-05-30 17:34:31 +00:00
|
|
|
int32_t scale = 1;
|
2013-02-28 18:55:02 +00:00
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
|
2016-05-30 17:34:31 +00:00
|
|
|
if (wl->display.current_output)
|
|
|
|
scale = wl->display.current_output->scale;
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->cursor.pointer = pointer;
|
2016-05-30 17:34:31 +00:00
|
|
|
wl->window.mouse_x = scale*wl_fixed_to_int(sx_w);
|
|
|
|
wl->window.mouse_y = scale*wl_fixed_to_int(sy_w);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2014-07-27 19:53:29 +00:00
|
|
|
mp_input_set_mouse_pos(wl->vo->input_ctx, wl->window.mouse_x,
|
|
|
|
wl->window.mouse_y);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pointer_handle_button(void *data,
|
|
|
|
struct wl_pointer *pointer,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t time,
|
|
|
|
uint32_t button,
|
|
|
|
uint32_t state)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
|
2017-03-17 06:25:32 +00:00
|
|
|
state = state == WL_POINTER_BUTTON_STATE_PRESSED ? MP_KEY_STATE_DOWN
|
|
|
|
: MP_KEY_STATE_UP;
|
|
|
|
|
input: use mnemonic names for mouse buttons
mpv's mouse button numbering is based on X11 button numbering, which
allows for an arbitrary number of buttons and includes mouse wheel input
as buttons 3-6. This button numbering was used throughout the codebase
and exposed in input.conf, and it was difficult to remember which
physical button each number actually referred to and which referred to
the scroll wheel.
In practice, PC mice only have between two and five buttons and one or
two scroll wheel axes, which are more or less in the same location and
have more or less the same function. This allows us to use names to
refer to the buttons instead of numbers, which makes input.conf syntax a
lot easier to remember. It also makes the syntax robust to changes in
mpv's underlying numbering. The old MOUSE_BTNx names are still
understood as deprecated aliases of the named buttons.
This changes both the input.conf syntax and the MP_MOUSE_BTNx symbols in
the codebase, since I think both would benefit from using names over
numbers, especially since some platforms don't use X11 button numbering
and handle different mouse buttons in different windowing system events.
This also makes the names shorter, since otherwise they would be pretty
long, and it removes the high-numbered MOUSE_BTNx_DBL names, since they
weren't used.
Names are the same as used in Qt:
https://doc.qt.io/qt-5/qt.html#MouseButton-enum
2017-08-08 11:34:38 +00:00
|
|
|
button = button == BTN_LEFT ? MP_MBTN_LEFT :
|
|
|
|
button == BTN_MIDDLE ? MP_MBTN_MID : MP_MBTN_RIGHT;
|
2017-03-17 06:25:32 +00:00
|
|
|
|
|
|
|
mp_input_put_key(wl->vo->input_ctx, button | state);
|
2013-09-24 16:53:24 +00:00
|
|
|
|
2013-10-25 08:27:58 +00:00
|
|
|
if (!mp_input_test_dragging(wl->vo->input_ctx, wl->window.mouse_x, wl->window.mouse_y) &&
|
input: use mnemonic names for mouse buttons
mpv's mouse button numbering is based on X11 button numbering, which
allows for an arbitrary number of buttons and includes mouse wheel input
as buttons 3-6. This button numbering was used throughout the codebase
and exposed in input.conf, and it was difficult to remember which
physical button each number actually referred to and which referred to
the scroll wheel.
In practice, PC mice only have between two and five buttons and one or
two scroll wheel axes, which are more or less in the same location and
have more or less the same function. This allows us to use names to
refer to the buttons instead of numbers, which makes input.conf syntax a
lot easier to remember. It also makes the syntax robust to changes in
mpv's underlying numbering. The old MOUSE_BTNx names are still
understood as deprecated aliases of the named buttons.
This changes both the input.conf syntax and the MP_MOUSE_BTNx symbols in
the codebase, since I think both would benefit from using names over
numbers, especially since some platforms don't use X11 button numbering
and handle different mouse buttons in different windowing system events.
This also makes the names shorter, since otherwise they would be pretty
long, and it removes the high-numbered MOUSE_BTNx_DBL names, since they
weren't used.
Names are the same as used in Qt:
https://doc.qt.io/qt-5/qt.html#MouseButton-enum
2017-08-08 11:34:38 +00:00
|
|
|
(button == MP_MBTN_LEFT) && (state == MP_KEY_STATE_DOWN))
|
2014-08-06 10:41:33 +00:00
|
|
|
window_move(wl, serial);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pointer_handle_axis(void *data,
|
|
|
|
struct wl_pointer *pointer,
|
|
|
|
uint32_t time,
|
|
|
|
uint32_t axis,
|
|
|
|
wl_fixed_t value)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
|
2013-07-25 16:16:08 +00:00
|
|
|
// value is 10.00 on a normal mouse wheel
|
|
|
|
// scale it down to 1.00 for multipliying it with the commands
|
2013-02-28 18:55:02 +00:00
|
|
|
if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
|
|
|
|
if (value > 0)
|
2017-09-02 14:00:52 +00:00
|
|
|
mp_input_put_wheel(wl->vo->input_ctx, MP_WHEEL_DOWN,
|
2013-07-25 16:16:08 +00:00
|
|
|
wl_fixed_to_double(value)*0.1);
|
2013-02-28 18:55:02 +00:00
|
|
|
if (value < 0)
|
2017-09-02 14:00:52 +00:00
|
|
|
mp_input_put_wheel(wl->vo->input_ctx, MP_WHEEL_UP,
|
2013-07-25 16:16:08 +00:00
|
|
|
wl_fixed_to_double(value)*-0.1);
|
|
|
|
}
|
|
|
|
else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
|
|
|
|
if (value > 0)
|
2017-09-02 14:00:52 +00:00
|
|
|
mp_input_put_wheel(wl->vo->input_ctx, MP_WHEEL_RIGHT,
|
2013-07-25 16:16:08 +00:00
|
|
|
wl_fixed_to_double(value)*0.1);
|
|
|
|
if (value < 0)
|
2017-09-02 14:00:52 +00:00
|
|
|
mp_input_put_wheel(wl->vo->input_ctx, MP_WHEEL_LEFT,
|
2013-07-25 16:16:08 +00:00
|
|
|
wl_fixed_to_double(value)*-0.1);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_pointer_listener pointer_listener = {
|
|
|
|
pointer_handle_enter,
|
|
|
|
pointer_handle_leave,
|
|
|
|
pointer_handle_motion,
|
|
|
|
pointer_handle_button,
|
|
|
|
pointer_handle_axis,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void seat_handle_capabilities(void *data,
|
|
|
|
struct wl_seat *seat,
|
|
|
|
enum wl_seat_capability caps)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !wl->input.keyboard) {
|
|
|
|
wl->input.keyboard = wl_seat_get_keyboard(seat);
|
|
|
|
wl_keyboard_add_listener(wl->input.keyboard, &keyboard_listener, wl);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
2013-07-18 15:35:28 +00:00
|
|
|
else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && wl->input.keyboard) {
|
|
|
|
wl_keyboard_destroy(wl->input.keyboard);
|
|
|
|
wl->input.keyboard = NULL;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
2013-07-18 15:35:28 +00:00
|
|
|
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !wl->input.pointer) {
|
|
|
|
wl->input.pointer = wl_seat_get_pointer(seat);
|
|
|
|
wl_pointer_add_listener(wl->input.pointer, &pointer_listener, wl);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
2013-07-18 15:35:28 +00:00
|
|
|
else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && wl->input.pointer) {
|
|
|
|
wl_pointer_destroy(wl->input.pointer);
|
|
|
|
wl->input.pointer = NULL;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-19 15:38:24 +00:00
|
|
|
static void seat_handle_name(void *data,
|
|
|
|
struct wl_seat *seat,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
MP_VERBOSE(wl, "Seat \"%s\" connected\n", name);
|
|
|
|
}
|
|
|
|
|
2013-02-28 18:55:02 +00:00
|
|
|
static const struct wl_seat_listener seat_listener = {
|
|
|
|
seat_handle_capabilities,
|
2014-09-19 15:38:24 +00:00
|
|
|
seat_handle_name,
|
2013-02-28 18:55:02 +00:00
|
|
|
};
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static void registry_handle_global(void *data, struct wl_registry *reg,
|
|
|
|
uint32_t id, const char *interface,
|
|
|
|
uint32_t version)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
|
|
|
|
if (strcmp(interface, "wl_compositor") == 0) {
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->display.compositor = wl_registry_bind(reg, id,
|
2016-05-30 17:34:31 +00:00
|
|
|
&wl_compositor_interface,
|
|
|
|
MPMIN(3, version));
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (strcmp(interface, "wl_shell") == 0) {
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->display.shell = wl_registry_bind(reg, id, &wl_shell_interface, 1);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (strcmp(interface, "wl_shm") == 0) {
|
|
|
|
|
2013-08-19 12:07:17 +00:00
|
|
|
wl->display.shm = wl_registry_bind(reg, id, &wl_shm_interface, 1);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (strcmp(interface, "wl_output") == 0) {
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
struct vo_wayland_output *output =
|
|
|
|
talloc_zero(wl, struct vo_wayland_output);
|
|
|
|
|
2013-02-28 18:55:02 +00:00
|
|
|
output->id = id;
|
2016-05-30 17:34:31 +00:00
|
|
|
output->scale = 1;
|
|
|
|
output->output = wl_registry_bind(reg, id, &wl_output_interface,
|
|
|
|
MPMIN(2, version));
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-05-02 18:56:59 +00:00
|
|
|
wl_output_add_listener(output->output, &output_listener, output);
|
2013-07-18 15:35:28 +00:00
|
|
|
wl_list_insert(&wl->display.output_list, &output->link);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (strcmp(interface, "wl_seat") == 0) {
|
|
|
|
|
2014-09-19 15:38:24 +00:00
|
|
|
wl->input.seat = wl_registry_bind(reg, id, &wl_seat_interface, 4);
|
2013-07-18 15:35:28 +00:00
|
|
|
wl_seat_add_listener(wl->input.seat, &seat_listener, wl);
|
2014-01-04 12:48:50 +00:00
|
|
|
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
2014-01-28 12:07:00 +00:00
|
|
|
|
|
|
|
else if (strcmp(interface, "wl_subcompositor") == 0) {
|
|
|
|
|
|
|
|
wl->display.subcomp = wl_registry_bind(reg, id,
|
|
|
|
&wl_subcompositor_interface, 1);
|
|
|
|
}
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static void registry_handle_global_remove(void *data,
|
|
|
|
struct wl_registry *registry,
|
|
|
|
uint32_t id)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_registry_listener registry_listener = {
|
|
|
|
registry_handle_global,
|
|
|
|
registry_handle_global_remove
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*** internal functions ***/
|
|
|
|
|
|
|
|
static int lookupkey(int key)
|
|
|
|
{
|
2014-06-10 21:56:05 +00:00
|
|
|
const char *passthrough_keys = " -+*/<>`~!@#$%^&()_{}:;\"\',.?\\|=[]";
|
2013-02-28 18:55:02 +00:00
|
|
|
|
|
|
|
int mpkey = 0;
|
|
|
|
if ((key >= 'a' && key <= 'z') ||
|
|
|
|
(key >= 'A' && key <= 'Z') ||
|
|
|
|
(key >= '0' && key <= '9') ||
|
|
|
|
(key > 0 && key < 256 && strchr(passthrough_keys, key)))
|
|
|
|
mpkey = key;
|
|
|
|
|
|
|
|
if (!mpkey)
|
|
|
|
mpkey = lookup_keymap_table(keymap, key);
|
|
|
|
|
|
|
|
return mpkey;
|
|
|
|
}
|
|
|
|
|
2013-03-22 18:37:28 +00:00
|
|
|
static void hide_cursor (struct vo_wayland_state *wl)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
2013-07-18 15:35:28 +00:00
|
|
|
if (!wl->cursor.pointer)
|
2013-02-28 18:55:02 +00:00
|
|
|
return;
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
wl_pointer_set_cursor(wl->cursor.pointer, wl->cursor.serial, NULL, 0, 0);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2013-03-22 18:37:28 +00:00
|
|
|
static void show_cursor (struct vo_wayland_state *wl)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
2013-07-18 15:35:28 +00:00
|
|
|
if (!wl->cursor.pointer)
|
2013-02-28 18:55:02 +00:00
|
|
|
return;
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
struct wl_cursor_image *image = wl->cursor.default_cursor->images[0];
|
|
|
|
struct wl_buffer *buffer = wl_cursor_image_get_buffer(image);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
wl_pointer_set_cursor(wl->cursor.pointer,
|
|
|
|
wl->cursor.serial,
|
|
|
|
wl->cursor.surface,
|
|
|
|
image->hotspot_x,
|
|
|
|
image->hotspot_y);
|
|
|
|
|
|
|
|
wl_surface_attach(wl->cursor.surface, buffer, 0, 0);
|
|
|
|
wl_surface_damage(wl->cursor.surface, 0, 0, image->width, image->height);
|
|
|
|
wl_surface_commit(wl->cursor.surface);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 10:41:33 +00:00
|
|
|
static void window_move(struct vo_wayland_state *wl, uint32_t serial)
|
|
|
|
{
|
|
|
|
if (wl->display.shell)
|
|
|
|
wl_shell_surface_move(wl->window.shell_surface, wl->input.seat, serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void window_set_toplevel(struct vo_wayland_state *wl)
|
|
|
|
{
|
|
|
|
if (wl->display.shell)
|
|
|
|
wl_shell_surface_set_toplevel(wl->window.shell_surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void window_set_title(struct vo_wayland_state *wl, const char *title)
|
|
|
|
{
|
|
|
|
if (wl->display.shell)
|
|
|
|
wl_shell_surface_set_title(wl->window.shell_surface, title);
|
|
|
|
}
|
|
|
|
|
2014-05-14 18:29:08 +00:00
|
|
|
static void schedule_resize(struct vo_wayland_state *wl,
|
|
|
|
uint32_t edges,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height)
|
2013-05-07 18:51:09 +00:00
|
|
|
{
|
2013-08-23 09:29:09 +00:00
|
|
|
int32_t minimum_size = 150;
|
|
|
|
int32_t x, y;
|
2015-01-12 14:16:11 +00:00
|
|
|
float win_aspect = wl->window.aspect;
|
|
|
|
if (win_aspect <= 0)
|
|
|
|
win_aspect = 1;
|
2013-08-23 09:29:09 +00:00
|
|
|
|
2014-05-14 18:29:08 +00:00
|
|
|
MP_DBG(wl, "schedule resize: %dx%d\n", width, height);
|
2014-01-07 20:12:24 +00:00
|
|
|
|
2016-07-29 03:10:05 +00:00
|
|
|
width = MPMAX(minimum_size, width);
|
|
|
|
height = MPMAX(minimum_size, height);
|
|
|
|
if (wl->display.current_output) {
|
|
|
|
int scale = wl->display.current_output->scale;
|
|
|
|
width = MPMIN(width, wl->display.current_output->width /scale);
|
|
|
|
height = MPMIN(height, wl->display.current_output->height/scale);
|
|
|
|
}
|
2013-08-23 09:29:09 +00:00
|
|
|
|
2016-12-20 15:18:45 +00:00
|
|
|
// don't keep the aspect ratio in fullscreen mode because the compositor
|
|
|
|
// shows the desktop in the border regions if the video does not have the same
|
|
|
|
// aspect ratio as the screen
|
2014-01-02 19:30:21 +00:00
|
|
|
/* if only the height is changed we have to calculate the width
|
|
|
|
* in any other case we calculate the height */
|
|
|
|
switch (edges) {
|
|
|
|
case WL_SHELL_SURFACE_RESIZE_TOP:
|
|
|
|
case WL_SHELL_SURFACE_RESIZE_BOTTOM:
|
2015-01-12 14:16:11 +00:00
|
|
|
width = win_aspect * height;
|
2014-01-02 19:30:21 +00:00
|
|
|
break;
|
|
|
|
case WL_SHELL_SURFACE_RESIZE_LEFT:
|
|
|
|
case WL_SHELL_SURFACE_RESIZE_RIGHT:
|
|
|
|
case WL_SHELL_SURFACE_RESIZE_TOP_LEFT: // just a preference
|
|
|
|
case WL_SHELL_SURFACE_RESIZE_TOP_RIGHT:
|
|
|
|
case WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT:
|
|
|
|
case WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT:
|
2015-01-12 14:16:11 +00:00
|
|
|
height = (1 / win_aspect) * width;
|
2014-01-02 19:30:21 +00:00
|
|
|
break;
|
2013-05-07 18:51:09 +00:00
|
|
|
}
|
2013-08-23 09:29:09 +00:00
|
|
|
|
|
|
|
if (edges & WL_SHELL_SURFACE_RESIZE_LEFT)
|
|
|
|
x = wl->window.width - width;
|
|
|
|
else
|
|
|
|
x = 0;
|
|
|
|
|
|
|
|
if (edges & WL_SHELL_SURFACE_RESIZE_TOP)
|
|
|
|
y = wl->window.height - height;
|
2013-05-07 18:51:09 +00:00
|
|
|
else
|
2013-08-23 09:29:09 +00:00
|
|
|
y = 0;
|
|
|
|
|
|
|
|
wl->window.sh_width = width;
|
|
|
|
wl->window.sh_height = height;
|
|
|
|
wl->window.sh_x = x;
|
|
|
|
wl->window.sh_y = y;
|
2016-07-30 10:53:44 +00:00
|
|
|
wl->window.events |= VO_EVENT_RESIZE;
|
2013-05-07 18:51:09 +00:00
|
|
|
}
|
|
|
|
|
2015-03-22 00:47:27 +00:00
|
|
|
static void frame_callback(void *data,
|
|
|
|
struct wl_callback *callback,
|
|
|
|
uint32_t time)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = data;
|
|
|
|
|
2015-08-19 19:41:26 +00:00
|
|
|
if (wl->frame.function)
|
|
|
|
wl->frame.function(wl->frame.data, time);
|
|
|
|
|
2015-03-22 00:47:27 +00:00
|
|
|
if (callback)
|
|
|
|
wl_callback_destroy(callback);
|
|
|
|
|
|
|
|
wl->frame.callback = wl_surface_frame(wl->window.video_surface);
|
|
|
|
|
|
|
|
if (!wl->frame.callback) {
|
|
|
|
MP_ERR(wl, "wl_surface_frame failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_callback_add_listener(wl->frame.callback, &frame_listener, wl);
|
2015-08-19 19:41:26 +00:00
|
|
|
wl_surface_commit(wl->window.video_surface);
|
2015-03-22 00:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener frame_listener = {
|
|
|
|
frame_callback
|
|
|
|
};
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static bool create_display(struct vo_wayland_state *wl)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
2014-01-07 00:06:28 +00:00
|
|
|
if (wl->vo->probing && !getenv("XDG_RUNTIME_DIR"))
|
|
|
|
return false;
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->display.display = wl_display_connect(NULL);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-09-10 15:52:29 +00:00
|
|
|
if (!wl->display.display) {
|
2013-09-10 16:33:43 +00:00
|
|
|
MP_MSG(wl, wl->vo->probing ? MSGL_V : MSGL_ERR,
|
|
|
|
"failed to connect to a wayland server: "
|
|
|
|
"check if a wayland compositor is running\n");
|
|
|
|
|
2013-02-28 18:55:02 +00:00
|
|
|
return false;
|
2013-09-10 15:52:29 +00:00
|
|
|
}
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->display.registry = wl_display_get_registry(wl->display.display);
|
|
|
|
wl_registry_add_listener(wl->display.registry, ®istry_listener, wl);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2014-08-18 20:00:39 +00:00
|
|
|
wl_display_roundtrip(wl->display.display);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->display.display_fd = wl_display_get_fd(wl->display.display);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static void destroy_display(struct vo_wayland_state *wl)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
2014-01-08 21:16:41 +00:00
|
|
|
struct vo_wayland_output *output = NULL;
|
|
|
|
struct vo_wayland_output *tmp = NULL;
|
2014-01-08 19:58:32 +00:00
|
|
|
|
2014-01-08 21:16:41 +00:00
|
|
|
wl_list_for_each_safe(output, tmp, &wl->display.output_list, link) {
|
2014-01-08 19:58:32 +00:00
|
|
|
if (output && output->output) {
|
|
|
|
wl_output_destroy(output->output);
|
|
|
|
output->output = NULL;
|
2014-01-08 21:16:41 +00:00
|
|
|
wl_list_remove(&output->link);
|
2014-01-08 19:58:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wl->display.shm)
|
|
|
|
wl_shm_destroy(wl->display.shm);
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
if (wl->display.shell)
|
|
|
|
wl_shell_destroy(wl->display.shell);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2014-06-15 12:46:27 +00:00
|
|
|
if (wl->display.subcomp)
|
|
|
|
wl_subcompositor_destroy(wl->display.subcomp);
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
if (wl->display.compositor)
|
|
|
|
wl_compositor_destroy(wl->display.compositor);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2014-01-06 23:59:25 +00:00
|
|
|
if (wl->display.registry)
|
|
|
|
wl_registry_destroy(wl->display.registry);
|
2014-01-08 19:58:32 +00:00
|
|
|
|
2014-01-06 23:59:25 +00:00
|
|
|
if (wl->display.display) {
|
|
|
|
wl_display_flush(wl->display.display);
|
|
|
|
wl_display_disconnect(wl->display.display);
|
|
|
|
}
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static bool create_window(struct vo_wayland_state *wl)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
2014-01-28 12:07:00 +00:00
|
|
|
wl->window.video_surface =
|
|
|
|
wl_compositor_create_surface(wl->display.compositor);
|
|
|
|
|
2014-08-18 20:00:39 +00:00
|
|
|
wl_surface_add_listener(wl->window.video_surface,
|
|
|
|
&surface_listener, wl);
|
|
|
|
|
2014-08-06 10:41:33 +00:00
|
|
|
if (wl->display.shell) {
|
|
|
|
wl->window.shell_surface = wl_shell_get_shell_surface(wl->display.shell,
|
|
|
|
wl->window.video_surface);
|
|
|
|
|
|
|
|
if (!wl->window.shell_surface) {
|
|
|
|
MP_ERR(wl, "creating shell surface failed\n");
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2014-08-06 10:41:33 +00:00
|
|
|
wl_shell_surface_add_listener(wl->window.shell_surface,
|
|
|
|
&shell_surface_listener, wl);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2014-08-06 10:41:33 +00:00
|
|
|
wl_shell_surface_set_toplevel(wl->window.shell_surface);
|
|
|
|
wl_shell_surface_set_class(wl->window.shell_surface, "mpv");
|
|
|
|
}
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
return true;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static void destroy_window(struct vo_wayland_state *wl)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
2014-01-06 23:59:25 +00:00
|
|
|
if (wl->window.shell_surface)
|
|
|
|
wl_shell_surface_destroy(wl->window.shell_surface);
|
2014-01-08 19:58:32 +00:00
|
|
|
|
2014-01-28 12:07:00 +00:00
|
|
|
if (wl->window.video_surface)
|
|
|
|
wl_surface_destroy(wl->window.video_surface);
|
2015-03-22 00:47:27 +00:00
|
|
|
|
|
|
|
if (wl->frame.callback)
|
|
|
|
wl_callback_destroy(wl->frame.callback);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static bool create_cursor(struct vo_wayland_state *wl)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
2013-09-10 15:52:29 +00:00
|
|
|
if (!wl->display.shm) {
|
|
|
|
MP_ERR(wl->vo, "no shm interface available\n");
|
2013-08-19 12:07:17 +00:00
|
|
|
return false;
|
2013-09-10 15:52:29 +00:00
|
|
|
}
|
2013-08-19 12:07:17 +00:00
|
|
|
|
2014-08-13 20:32:22 +00:00
|
|
|
wl->cursor.surface =
|
|
|
|
wl_compositor_create_surface(wl->display.compositor);
|
2014-08-06 10:41:33 +00:00
|
|
|
|
2014-08-13 20:32:22 +00:00
|
|
|
if (!wl->cursor.surface)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wl->cursor.theme = wl_cursor_theme_load(NULL, 32, wl->display.shm);
|
|
|
|
wl->cursor.default_cursor = wl_cursor_theme_get_cursor(wl->cursor.theme,
|
|
|
|
"left_ptr");
|
2013-08-19 12:07:17 +00:00
|
|
|
|
|
|
|
return true;
|
2013-07-18 15:35:28 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static void destroy_cursor(struct vo_wayland_state *wl)
|
2013-07-18 15:35:28 +00:00
|
|
|
{
|
|
|
|
if (wl->cursor.theme)
|
|
|
|
wl_cursor_theme_destroy(wl->cursor.theme);
|
|
|
|
|
|
|
|
if (wl->cursor.surface)
|
|
|
|
wl_surface_destroy(wl->cursor.surface);
|
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static bool create_input(struct vo_wayland_state *wl)
|
2013-07-18 15:35:28 +00:00
|
|
|
{
|
|
|
|
wl->input.xkb.context = xkb_context_new(0);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
if (!wl->input.xkb.context) {
|
2013-09-12 14:29:13 +00:00
|
|
|
MP_ERR(wl, "failed to initialize input: check xkbcommon\n");
|
2013-07-18 15:35:28 +00:00
|
|
|
return false;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
2013-07-18 15:35:28 +00:00
|
|
|
|
|
|
|
return true;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static void destroy_input(struct vo_wayland_state *wl)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
2013-08-26 16:35:57 +00:00
|
|
|
if (wl->input.keyboard) {
|
2013-07-18 15:35:28 +00:00
|
|
|
wl_keyboard_destroy(wl->input.keyboard);
|
2014-08-20 15:16:18 +00:00
|
|
|
xkb_keymap_unref(wl->input.xkb.keymap);
|
2013-08-26 16:35:57 +00:00
|
|
|
xkb_state_unref(wl->input.xkb.state);
|
|
|
|
}
|
2014-01-08 19:58:32 +00:00
|
|
|
|
2014-01-06 23:59:25 +00:00
|
|
|
if (wl->input.xkb.context)
|
|
|
|
xkb_context_unref(wl->input.xkb.context);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
if (wl->input.pointer)
|
|
|
|
wl_pointer_destroy(wl->input.pointer);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
if (wl->input.seat)
|
|
|
|
wl_seat_destroy(wl->input.seat);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** mplayer2 interface ***/
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
int vo_wayland_init(struct vo *vo)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
|
|
|
vo->wayland = talloc_zero(NULL, struct vo_wayland_state);
|
|
|
|
struct vo_wayland_state *wl = vo->wayland;
|
2016-07-21 13:14:37 +00:00
|
|
|
*wl = (struct vo_wayland_state){
|
|
|
|
.vo = vo,
|
|
|
|
.log = mp_log_new(wl, vo->log, "wayland"),
|
|
|
|
.wakeup_pipe = {-1, -1},
|
|
|
|
};
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2014-01-08 20:49:18 +00:00
|
|
|
wl_list_init(&wl->display.output_list);
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
if (!create_input(wl)
|
|
|
|
|| !create_display(wl)
|
|
|
|
|| !create_window(wl)
|
|
|
|
|| !create_cursor(wl))
|
|
|
|
{
|
2014-01-06 23:59:25 +00:00
|
|
|
vo_wayland_uninit(vo);
|
2013-02-28 18:55:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-03 19:30:19 +00:00
|
|
|
// create_display's roundtrip only adds the interfaces
|
|
|
|
// the second roundtrip receives output modes, geometry and more ...
|
|
|
|
wl_display_roundtrip(wl->display.display);
|
|
|
|
|
|
|
|
struct vo_wayland_output *o = NULL;
|
|
|
|
wl_list_for_each(o, &wl->display.output_list, link) {
|
|
|
|
MP_VERBOSE(wl, "output received:\n"
|
|
|
|
"\tvendor: %s\n"
|
|
|
|
"\tmodel: %s\n"
|
|
|
|
"\tw: %d, h: %d\n"
|
2016-05-30 17:34:31 +00:00
|
|
|
"\tscale: %d\n"
|
2016-05-30 23:38:55 +00:00
|
|
|
"\tHz: %f\n",
|
2014-09-03 19:30:19 +00:00
|
|
|
o->make, o->model,
|
2016-05-30 17:34:31 +00:00
|
|
|
o->width, o->height, o->scale,
|
2016-05-30 23:38:55 +00:00
|
|
|
o->refresh_rate / 1000.0f);
|
2014-09-03 19:30:19 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 11:25:30 +00:00
|
|
|
mp_make_wakeup_pipe(wl->wakeup_pipe);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-05-16 14:43:34 +00:00
|
|
|
return true;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
void vo_wayland_uninit(struct vo *vo)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = vo->wayland;
|
2013-07-18 15:35:28 +00:00
|
|
|
destroy_cursor(wl);
|
2013-02-28 18:55:02 +00:00
|
|
|
destroy_window(wl);
|
2013-07-18 15:35:28 +00:00
|
|
|
destroy_input(wl);
|
2016-11-27 02:01:14 +00:00
|
|
|
destroy_display(wl);
|
2016-07-21 11:25:30 +00:00
|
|
|
for (int n = 0; n < 2; n++)
|
|
|
|
close(wl->wakeup_pipe[n]);
|
2013-02-28 18:55:02 +00:00
|
|
|
talloc_free(wl);
|
|
|
|
vo->wayland = NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static void vo_wayland_ontop(struct vo *vo)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
2014-01-07 20:12:24 +00:00
|
|
|
struct vo_wayland_state *wl = vo->wayland;
|
2016-08-30 21:52:16 +00:00
|
|
|
if (!vo->opts->ontop)
|
|
|
|
return;
|
2014-01-07 20:12:24 +00:00
|
|
|
MP_DBG(wl, "going ontop\n");
|
2014-08-06 10:41:33 +00:00
|
|
|
window_set_toplevel(wl);
|
2016-03-19 03:19:14 +00:00
|
|
|
schedule_resize(wl, 0, wl->window.width, wl->window.height);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
static void vo_wayland_fullscreen(struct vo *vo)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = vo->wayland;
|
2014-01-04 12:57:47 +00:00
|
|
|
if (!wl->display.shell)
|
2013-02-28 18:55:02 +00:00
|
|
|
return;
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
struct wl_output *fs_output = wl->display.fs_output;
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2013-07-18 12:05:39 +00:00
|
|
|
if (vo->opts->fullscreen) {
|
2013-09-12 14:38:44 +00:00
|
|
|
MP_DBG(wl, "going fullscreen\n");
|
2013-10-25 08:22:40 +00:00
|
|
|
wl->window.is_fullscreen = true;
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->window.p_width = wl->window.width;
|
|
|
|
wl->window.p_height = wl->window.height;
|
2016-08-01 20:08:20 +00:00
|
|
|
if (wl->display.current_output)
|
|
|
|
schedule_resize(wl, 0, wl->display.current_output->width,
|
|
|
|
wl->display.current_output->height);
|
2013-07-18 15:35:28 +00:00
|
|
|
wl_shell_surface_set_fullscreen(wl->window.shell_surface,
|
2013-07-16 14:51:27 +00:00
|
|
|
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
|
2013-02-28 18:55:02 +00:00
|
|
|
0, fs_output);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2013-09-12 14:38:44 +00:00
|
|
|
MP_DBG(wl, "leaving fullscreen\n");
|
2013-10-25 08:22:40 +00:00
|
|
|
wl->window.is_fullscreen = false;
|
2014-08-06 10:41:33 +00:00
|
|
|
window_set_toplevel(wl);
|
2016-03-19 03:19:14 +00:00
|
|
|
schedule_resize(wl, 0, wl->window.p_width, wl->window.p_height);
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 21:16:18 +00:00
|
|
|
static void vo_wayland_update_screeninfo(struct vo *vo, struct mp_rect *screenrc)
|
2013-02-28 18:55:02 +00:00
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = vo->wayland;
|
2013-03-04 21:41:27 +00:00
|
|
|
struct mp_vo_opts *opts = vo->opts;
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2014-05-06 21:16:18 +00:00
|
|
|
*screenrc = (struct mp_rect){0};
|
2013-02-28 18:55:02 +00:00
|
|
|
|
|
|
|
int screen_id = 0;
|
|
|
|
|
|
|
|
struct vo_wayland_output *output;
|
|
|
|
struct vo_wayland_output *first_output = NULL;
|
|
|
|
struct vo_wayland_output *fsscreen_output = NULL;
|
|
|
|
|
2014-08-18 20:00:39 +00:00
|
|
|
if (opts->fsscreen_id >= 0) {
|
|
|
|
wl_list_for_each_reverse(output, &wl->display.output_list, link) {
|
|
|
|
if (!output || !output->width)
|
|
|
|
continue;
|
2013-05-02 18:56:59 +00:00
|
|
|
|
2014-08-18 20:00:39 +00:00
|
|
|
if (opts->fsscreen_id == screen_id)
|
|
|
|
fsscreen_output = output;
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2014-08-18 20:00:39 +00:00
|
|
|
screen_id++;
|
|
|
|
}
|
2013-05-02 18:56:59 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 18:55:02 +00:00
|
|
|
if (fsscreen_output) {
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->display.fs_output = fsscreen_output->output;
|
2014-05-06 21:16:18 +00:00
|
|
|
screenrc->x1 = fsscreen_output->width;
|
|
|
|
screenrc->y1 = fsscreen_output->height;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->display.fs_output = NULL; /* current output is always 0 */
|
2013-02-28 18:55:02 +00:00
|
|
|
|
|
|
|
if (first_output) {
|
2014-08-18 20:00:39 +00:00
|
|
|
screenrc->x1 = wl->display.current_output->width;
|
|
|
|
screenrc->y1 = wl->display.current_output->height;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-19 03:19:14 +00:00
|
|
|
|
|
|
|
wl->window.fs_width = screenrc->x1;
|
|
|
|
wl->window.fs_height = screenrc->y1;
|
2013-02-28 18:55:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
|
2013-05-15 16:17:18 +00:00
|
|
|
{
|
2013-05-19 11:04:59 +00:00
|
|
|
struct vo_wayland_state *wl = vo->wayland;
|
2013-07-18 15:35:28 +00:00
|
|
|
wl_display_dispatch_pending(wl->display.display);
|
2013-05-19 11:04:59 +00:00
|
|
|
|
2013-05-15 16:17:18 +00:00
|
|
|
switch (request) {
|
|
|
|
case VOCTRL_CHECK_EVENTS:
|
2016-07-23 23:40:26 +00:00
|
|
|
*events |= wl->window.events;
|
2016-07-30 10:53:44 +00:00
|
|
|
wl->window.events = 0;
|
2013-05-15 16:17:18 +00:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_FULLSCREEN:
|
|
|
|
vo_wayland_fullscreen(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_ONTOP:
|
|
|
|
vo_wayland_ontop(vo);
|
|
|
|
return VO_TRUE;
|
2014-09-04 20:53:50 +00:00
|
|
|
case VOCTRL_GET_UNFS_WINDOW_SIZE: {
|
2016-07-31 21:41:24 +00:00
|
|
|
int *s = arg, scale = 1;
|
|
|
|
if (wl->display.current_output)
|
|
|
|
scale = wl->display.current_output->scale;
|
|
|
|
s[0] = scale*wl->window.width;
|
|
|
|
s[1] = scale*wl->window.height;
|
2013-11-12 20:02:49 +00:00
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2014-09-04 20:53:50 +00:00
|
|
|
case VOCTRL_SET_UNFS_WINDOW_SIZE: {
|
2013-11-12 20:02:49 +00:00
|
|
|
int *s = arg;
|
|
|
|
if (!wl->window.is_fullscreen)
|
2014-05-14 18:29:08 +00:00
|
|
|
schedule_resize(wl, 0, s[0], s[1]);
|
2013-11-12 20:02:49 +00:00
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2013-05-19 11:04:59 +00:00
|
|
|
case VOCTRL_SET_CURSOR_VISIBILITY:
|
|
|
|
if (*(bool *)arg) {
|
2013-07-18 15:35:28 +00:00
|
|
|
if (!wl->cursor.visible)
|
2013-05-19 11:04:59 +00:00
|
|
|
show_cursor(wl);
|
|
|
|
}
|
|
|
|
else {
|
2013-07-18 15:35:28 +00:00
|
|
|
if (wl->cursor.visible)
|
2013-05-19 11:04:59 +00:00
|
|
|
hide_cursor(wl);
|
|
|
|
}
|
2013-07-18 15:35:28 +00:00
|
|
|
wl->cursor.visible = *(bool *)arg;
|
2013-05-19 11:04:59 +00:00
|
|
|
return VO_TRUE;
|
2013-06-16 07:34:31 +00:00
|
|
|
case VOCTRL_UPDATE_WINDOW_TITLE:
|
2014-08-06 10:41:33 +00:00
|
|
|
window_set_title(wl, (char*) arg);
|
2013-06-16 07:34:31 +00:00
|
|
|
return VO_TRUE;
|
2014-08-18 20:00:39 +00:00
|
|
|
case VOCTRL_GET_DISPLAY_FPS: {
|
|
|
|
if (!wl->display.current_output)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// refresh rate is stored in milli-Hertz (mHz)
|
2016-05-30 23:38:55 +00:00
|
|
|
double fps = wl->display.current_output->refresh_rate / 1000.0f;
|
2014-08-18 20:00:39 +00:00
|
|
|
*(double*) arg = fps;
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2013-05-15 16:17:18 +00:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|
2013-05-16 14:43:34 +00:00
|
|
|
|
2016-07-21 12:28:58 +00:00
|
|
|
bool vo_wayland_config(struct vo *vo)
|
2013-05-16 14:43:34 +00:00
|
|
|
{
|
2013-07-18 15:35:28 +00:00
|
|
|
struct vo_wayland_state *wl = vo->wayland;
|
2013-05-16 14:43:34 +00:00
|
|
|
|
2014-05-06 21:16:18 +00:00
|
|
|
struct mp_rect screenrc;
|
|
|
|
vo_wayland_update_screeninfo(vo, &screenrc);
|
|
|
|
|
|
|
|
struct vo_win_geometry geo;
|
|
|
|
vo_calc_window_geometry(vo, &screenrc, &geo);
|
|
|
|
vo_apply_window_geometry(vo, &geo);
|
|
|
|
|
|
|
|
wl->window.p_width = vo->dwidth;
|
|
|
|
wl->window.p_height = vo->dheight;
|
|
|
|
wl->window.aspect = vo->dwidth / (float) MPMAX(vo->dheight, 1);
|
2013-07-16 15:52:57 +00:00
|
|
|
|
2015-10-01 20:57:02 +00:00
|
|
|
wl->window.width = vo->dwidth;
|
|
|
|
wl->window.height = vo->dheight;
|
|
|
|
vo_wayland_fullscreen(vo);
|
2013-05-16 14:43:34 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-19 19:41:26 +00:00
|
|
|
|
|
|
|
void vo_wayland_request_frame(struct vo *vo, void *data, vo_wayland_frame_cb cb)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = vo->wayland;
|
|
|
|
wl->frame.data = data;
|
|
|
|
wl->frame.function = cb;
|
|
|
|
MP_DBG(wl, "restart frame callback\n");
|
|
|
|
frame_callback(wl, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2016-07-21 11:25:30 +00:00
|
|
|
void vo_wayland_wakeup(struct vo *vo)
|
2015-08-19 19:41:26 +00:00
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = vo->wayland;
|
2016-07-21 11:25:30 +00:00
|
|
|
(void)write(wl->wakeup_pipe[1], &(char){0}, 1);
|
|
|
|
}
|
2015-08-19 19:41:26 +00:00
|
|
|
|
2016-07-21 11:25:30 +00:00
|
|
|
void vo_wayland_wait_events(struct vo *vo, int64_t until_time_us)
|
|
|
|
{
|
|
|
|
struct vo_wayland_state *wl = vo->wayland;
|
|
|
|
struct wl_display *dp = wl->display.display;
|
2015-08-19 19:41:26 +00:00
|
|
|
|
2016-07-21 11:25:30 +00:00
|
|
|
struct pollfd fds[2] = {
|
|
|
|
{.fd = wl->display.display_fd, .events = POLLIN },
|
|
|
|
{.fd = wl->wakeup_pipe[0], .events = POLLIN },
|
|
|
|
};
|
2015-08-19 19:41:26 +00:00
|
|
|
|
2016-07-21 11:25:30 +00:00
|
|
|
int64_t wait_us = until_time_us - mp_time_us();
|
2016-08-26 18:22:33 +00:00
|
|
|
int timeout_ms = MPCLAMP((wait_us + 999) / 1000, 0, 10000);
|
2015-08-19 19:41:26 +00:00
|
|
|
|
2016-07-29 01:30:07 +00:00
|
|
|
wl_display_dispatch_pending(dp);
|
|
|
|
wl_display_flush(dp);
|
|
|
|
|
2016-07-21 11:25:30 +00:00
|
|
|
poll(fds, 2, timeout_ms);
|
2015-08-19 19:41:26 +00:00
|
|
|
|
2016-07-29 01:30:07 +00:00
|
|
|
if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
|
2016-07-21 11:25:30 +00:00
|
|
|
MP_FATAL(wl, "error occurred on the display fd: "
|
|
|
|
"closing file descriptor\n");
|
|
|
|
close(wl->display.display_fd);
|
|
|
|
mp_input_put_key(vo->input_ctx, MP_KEY_CLOSE_WIN);
|
|
|
|
}
|
2016-07-29 01:30:07 +00:00
|
|
|
|
|
|
|
if (fds[0].revents & POLLIN)
|
|
|
|
wl_display_dispatch(dp);
|
|
|
|
|
|
|
|
if (fds[1].revents & POLLIN)
|
|
|
|
mp_flush_wakeup_pipe(wl->wakeup_pipe[0]);
|
2015-08-19 19:41:26 +00:00
|
|
|
}
|