summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Preisinger <alexander.preisinger@gmail.com>2013-07-18 17:35:28 +0200
committerAlexander Preisinger <alexander.preisinger@gmail.com>2013-07-18 17:52:56 +0200
commit3dc063a3308e2f3e2a1a94f2a6b1c58e64a757bb (patch)
tree9a3fdfb642e6df9128a8a041def4991861321b68
parentc5b76714a0c9d57521b08e135f4f3c4e35c8b245 (diff)
downloadmpv-3dc063a3308e2f3e2a1a94f2a6b1c58e64a757bb.tar.bz2
mpv-3dc063a3308e2f3e2a1a94f2a6b1c58e64a757bb.tar.xz
wayland: use a unified struct for the state
This commit removes the pointer to the single different structures for input and window and puts them as anonymous structures inside the wayland_state structure. This has the disadvantage of passing the substructure to the listeners, but the advantage is that we don't have to allocate them and check for NULL pointers. This makes it more reliable and easier to follow.
-rw-r--r--video/out/gl_wayland.c37
-rw-r--r--video/out/wayland_common.c436
-rw-r--r--video/out/wayland_common.h107
3 files changed, 283 insertions, 297 deletions
diff --git a/video/out/gl_wayland.c b/video/out/gl_wayland.c
index cb5cba0758..ad97d0b27e 100644
--- a/video/out/gl_wayland.c
+++ b/video/out/gl_wayland.c
@@ -44,7 +44,6 @@ static void egl_resize_func(struct vo_wayland_state *wl,
int32_t height,
void *user_data)
{
- struct vo_wayland_window *w = wl->window;
struct egl_context *ctx = user_data;
int32_t minimum_size = 150;
int32_t x, y;
@@ -55,8 +54,8 @@ static void egl_resize_func(struct vo_wayland_state *wl,
/* get the real window size of the window */
wl_egl_window_get_attached_size(ctx->egl_window,
- &w->width,
- &w->height);
+ &wl->window.width,
+ &wl->window.height);
if (width < minimum_size)
width = minimum_size;
@@ -68,7 +67,7 @@ static void egl_resize_func(struct vo_wayland_state *wl,
switch (edges) {
case WL_SHELL_SURFACE_RESIZE_TOP:
case WL_SHELL_SURFACE_RESIZE_BOTTOM:
- width = w->aspect * height;
+ width = wl->window.aspect * height;
break;
case WL_SHELL_SURFACE_RESIZE_LEFT:
case WL_SHELL_SURFACE_RESIZE_RIGHT:
@@ -76,31 +75,31 @@ static void egl_resize_func(struct vo_wayland_state *wl,
case WL_SHELL_SURFACE_RESIZE_TOP_RIGHT:
case WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT:
case WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT:
- height = (1 / w->aspect) * width;
+ height = (1 / wl->window.aspect) * width;
break;
default:
- if (w->aspect < temp_aspect)
- width = w->aspect * height;
+ if (wl->window.aspect < temp_aspect)
+ width = wl->window.aspect * height;
else
- height = (1 / w->aspect) * width;
+ height = (1 / wl->window.aspect) * width;
break;
}
if (edges & WL_SHELL_SURFACE_RESIZE_LEFT)
- x = w->width - width;
+ x = wl->window.width - width;
else
x = 0;
if (edges & WL_SHELL_SURFACE_RESIZE_TOP)
- y = w->height - height;
+ y = wl->window.height - height;
else
y = 0;
wl_egl_window_resize(ctx->egl_window, width, height, x, y);
- w->width = width;
- w->height = height;
+ wl->window.width = width;
+ wl->window.height = height;
/* set size for mplayer */
wl->vo->dwidth = width;
@@ -117,7 +116,7 @@ static bool egl_create_context(struct vo_wayland_state *wl,
GL *gl = ctx->gl;
const char *eglstr = "";
- if (!(egl_ctx->egl.dpy = eglGetDisplay(wl->display->display)))
+ if (!(egl_ctx->egl.dpy = eglGetDisplay(wl->display.display)))
return false;
EGLint config_attribs[] = {
@@ -174,9 +173,9 @@ static void egl_create_window(struct vo_wayland_state *wl,
uint32_t width,
uint32_t height)
{
- egl_ctx->egl_window = wl_egl_window_create(wl->window->surface,
- wl->window->width,
- wl->window->height);
+ egl_ctx->egl_window = wl_egl_window_create(wl->window.surface,
+ wl->window.width,
+ wl->window.height);
egl_ctx->egl_surface = eglCreateWindowSurface(egl_ctx->egl.dpy,
egl_ctx->egl.conf,
@@ -188,7 +187,7 @@ static void egl_create_window(struct vo_wayland_state *wl,
egl_ctx->egl_surface,
egl_ctx->egl.ctx);
- wl_display_dispatch_pending(wl->display->display);
+ wl_display_dispatch_pending(wl->display.display);
}
@@ -202,8 +201,8 @@ static bool config_window_wayland(struct MPGLContext *ctx,
bool enable_alpha = !!(flags & VOFLAG_ALPHA);
bool ret = false;
- wl->window->resize_func = egl_resize_func;
- wl->window->resize_func_data = (void*) egl_ctx;
+ wl->window.resize_func = egl_resize_func;
+ wl->window.resize_func_data = (void*) egl_ctx;
if (!vo_wayland_config(ctx->vo, d_width, d_height, flags))
return false;
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index e15b0c6f2f..9396c69c07 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -65,9 +65,56 @@ static void resize_window(struct vo_wayland_state *wl,
static void vo_wayland_fullscreen (struct vo *vo);
-/*** wayland interface ***/
+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},
+
+ {0, 0}
+};
+
-/* SHELL SURFACE LISTENER */
+/** Wayland listeners **/
static void ssurface_handle_ping(void *data,
struct wl_shell_surface *shell_surface,
uint32_t serial)
@@ -96,7 +143,6 @@ const struct wl_shell_surface_listener shell_surface_listener = {
ssurface_handle_popup_done
};
-/* OUTPUT LISTENER */
static void output_handle_geometry(void *data,
struct wl_output *wl_output,
int32_t x,
@@ -145,55 +191,6 @@ const struct wl_output_listener output_listener = {
output_handle_mode
};
-/* KEY LOOKUP */
-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},
-
- {0, 0}
-};
-
/* KEYBOARD LISTENER */
static void keyboard_handle_keymap(void *data,
struct wl_keyboard *wl_keyboard,
@@ -201,10 +198,10 @@ static void keyboard_handle_keymap(void *data,
int32_t fd,
uint32_t size)
{
- struct vo_wayland_input *input;
+ struct vo_wayland_state *wl = data;
char *map_str;
- if(!data || format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
+ if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
close(fd);
return;
}
@@ -215,23 +212,25 @@ static void keyboard_handle_keymap(void *data,
return;
}
- input = ((struct vo_wayland_state *) data)->input;
- input->xkb.keymap = xkb_keymap_new_from_buffer(input->xkb.context,
- map_str, size, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
+ wl->input.xkb.keymap = xkb_keymap_new_from_buffer(wl->input.xkb.context,
+ map_str,
+ size,
+ XKB_KEYMAP_FORMAT_TEXT_V1,
+ 0);
munmap(map_str, size);
close(fd);
- if (!input->xkb.keymap) {
+ if (!wl->input.xkb.keymap) {
mp_msg(MSGT_VO, MSGL_ERR, "[wayland] failed to compile keymap.\n");
return;
}
- input->xkb.state = xkb_state_new(input->xkb.keymap);
- if (!input->xkb.state) {
+ wl->input.xkb.state = xkb_state_new(wl->input.xkb.keymap);
+ if (!wl->input.xkb.state) {
mp_msg(MSGT_VO, MSGL_ERR, "[wayland] failed to create XKB state.\n");
- xkb_map_unref(input->xkb.keymap);
- input->xkb.keymap = NULL;
+ xkb_map_unref(wl->input.xkb.keymap);
+ wl->input.xkb.keymap = NULL;
return;
}
}
@@ -259,7 +258,6 @@ static void keyboard_handle_key(void *data,
uint32_t state)
{
struct vo_wayland_state *wl = data;
- struct vo_wayland_input *input = wl->input;
uint32_t code, num_syms;
int mpkey;
@@ -267,7 +265,7 @@ static void keyboard_handle_key(void *data,
xkb_keysym_t sym;
code = key + 8;
- num_syms = xkb_key_get_syms(input->xkb.state, code, &syms);
+ num_syms = xkb_key_get_syms(wl->input.xkb.state, code, &syms);
sym = XKB_KEY_NoSymbol;
if (num_syms == 1)
@@ -289,10 +287,13 @@ static void keyboard_handle_modifiers(void *data,
uint32_t mods_locked,
uint32_t group)
{
- struct vo_wayland_input *input = ((struct vo_wayland_state *) data)->input;
+ struct vo_wayland_state *wl = data;
- xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
- mods_locked, 0, 0, group);
+ xkb_state_update_mask(wl->input.xkb.state,
+ mods_depressed,
+ mods_latched,
+ mods_locked,
+ 0, 0, group);
}
const struct wl_keyboard_listener keyboard_listener = {
@@ -312,10 +313,9 @@ static void pointer_handle_enter(void *data,
wl_fixed_t sy_w)
{
struct vo_wayland_state *wl = data;
- struct vo_wayland_display * display = wl->display;
- display->cursor.serial = serial;
- display->cursor.pointer = pointer;
+ wl->cursor.serial = serial;
+ wl->cursor.pointer = pointer;
/* Release the left button on pointer enter again
* because after moving the shell surface no release event is sent */
@@ -340,7 +340,7 @@ static void pointer_handle_motion(void *data,
{
struct vo_wayland_state *wl = data;
- wl->display->cursor.pointer = pointer;
+ wl->cursor.pointer = pointer;
vo_mouse_movement(wl->vo, wl_fixed_to_int(sx_w),
wl_fixed_to_int(sy_w));
@@ -356,11 +356,11 @@ static void pointer_handle_button(void *data,
struct vo_wayland_state *wl = data;
mp_input_put_key(wl->vo->input_ctx, MP_MOUSE_BTN0 + (button - BTN_LEFT) |
- ((state == WL_POINTER_BUTTON_STATE_PRESSED)
- ? MP_KEY_STATE_DOWN : MP_KEY_STATE_UP));
+ ((state == WL_POINTER_BUTTON_STATE_PRESSED)
+ ? MP_KEY_STATE_DOWN : MP_KEY_STATE_UP));
if ((button == BTN_LEFT) && (state == WL_POINTER_BUTTON_STATE_PRESSED))
- wl_shell_surface_move(wl->window->shell_surface, wl->input->seat, serial);
+ wl_shell_surface_move(wl->window.shell_surface, wl->input.seat, serial);
}
static void pointer_handle_axis(void *data,
@@ -393,23 +393,23 @@ static void seat_handle_capabilities(void *data,
{
struct vo_wayland_state *wl = data;
- if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !wl->input->keyboard) {
- wl->input->keyboard = wl_seat_get_keyboard(seat);
- wl_keyboard_set_user_data(wl->input->keyboard, wl);
- wl_keyboard_add_listener(wl->input->keyboard, &keyboard_listener, wl);
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !wl->input.keyboard) {
+ wl->input.keyboard = wl_seat_get_keyboard(seat);
+ wl_keyboard_set_user_data(wl->input.keyboard, wl);
+ wl_keyboard_add_listener(wl->input.keyboard, &keyboard_listener, wl);
}
- else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && wl->input->keyboard) {
- wl_keyboard_destroy(wl->input->keyboard);
- wl->input->keyboard = NULL;
+ else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && wl->input.keyboard) {
+ wl_keyboard_destroy(wl->input.keyboard);
+ wl->input.keyboard = NULL;
}
- if ((caps & WL_SEAT_CAPABILITY_POINTER) && !wl->input->pointer) {
- wl->input->pointer = wl_seat_get_pointer(seat);
- wl_pointer_set_user_data(wl->input->pointer, wl);
- wl_pointer_add_listener(wl->input->pointer, &pointer_listener, wl);
+ if ((caps & WL_SEAT_CAPABILITY_POINTER) && !wl->input.pointer) {
+ wl->input.pointer = wl_seat_get_pointer(seat);
+ wl_pointer_set_user_data(wl->input.pointer, wl);
+ wl_pointer_add_listener(wl->input.pointer, &pointer_listener, wl);
}
- else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && wl->input->pointer) {
- wl_pointer_destroy(wl->input->pointer);
- wl->input->pointer = NULL;
+ else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && wl->input.pointer) {
+ wl_pointer_destroy(wl->input.pointer);
+ wl->input.pointer = NULL;
}
}
@@ -422,8 +422,8 @@ static void shm_handle_format(void *data,
struct wl_shm *wl_shm,
uint32_t format)
{
- struct vo_wayland_display *d = data;
- d->formats |= (1 << format);
+ struct vo_wayland_state *wl = data;
+ wl->display.formats |= (1 << format);
}
const struct wl_shm_listener shm_listener = {
@@ -437,50 +437,45 @@ static void registry_handle_global (void *data,
uint32_t version)
{
struct vo_wayland_state *wl = data;
- struct vo_wayland_display *d = wl->display;
+ struct wl_registry *reg = wl->display.registry;
if (strcmp(interface, "wl_compositor") == 0) {
- d->compositor = wl_registry_bind(d->registry, id,
- &wl_compositor_interface, 1);
+ wl->display.compositor = wl_registry_bind(reg, id,
+ &wl_compositor_interface, 1);
}
else if (strcmp(interface, "wl_shell") == 0) {
- d->shell = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
+ wl->display.shell = wl_registry_bind(reg, id, &wl_shell_interface, 1);
}
else if (strcmp(interface, "wl_shm") == 0) {
- d->cursor.shm = wl_registry_bind(d->registry, id, &wl_shm_interface, 1);
- d->cursor.theme = wl_cursor_theme_load(NULL, 32, d->cursor.shm);
- d->cursor.default_cursor = wl_cursor_theme_get_cursor(d->cursor.theme,
+ wl->cursor.shm = wl_registry_bind(reg, id, &wl_shm_interface, 1);
+ wl->cursor.theme = wl_cursor_theme_load(NULL, 32, wl->cursor.shm);
+ wl->cursor.default_cursor = wl_cursor_theme_get_cursor(wl->cursor.theme,
"left_ptr");
- wl_shm_add_listener(d->cursor.shm, &shm_listener, d);
+ wl_shm_add_listener(wl->cursor.shm, &shm_listener, wl);
}
else if (strcmp(interface, "wl_output") == 0) {
- struct vo_wayland_output *output = talloc_zero(d,
- struct vo_wayland_output);
+ struct vo_wayland_output *output =
+ talloc_zero(wl, struct vo_wayland_output);
+
output->id = id;
- output->output = wl_registry_bind(d->registry,
- id,
- &wl_output_interface,
- 1);
+ output->output = wl_registry_bind(reg, id, &wl_output_interface, 1);
wl_output_add_listener(output->output, &output_listener, output);
- wl_list_insert(&d->output_list, &output->link);
+ wl_list_insert(&wl->display.output_list, &output->link);
}
else if (strcmp(interface, "wl_seat") == 0) {
- wl->input->seat = wl_registry_bind(d->registry,
- id,
- &wl_seat_interface,
- 1);
+ wl->input.seat = wl_registry_bind(reg, id, &wl_seat_interface, 1);
- wl_seat_add_listener(wl->input->seat, &seat_listener, wl);
+ wl_seat_add_listener(wl->input.seat, &seat_listener, wl);
}
}
@@ -518,31 +513,29 @@ static int lookupkey(int key)
static void hide_cursor (struct vo_wayland_state *wl)
{
- struct vo_wayland_display *display = wl->display;
- if (!display->cursor.pointer)
+ if (!wl->cursor.pointer)
return;
- wl_pointer_set_cursor(display->cursor.pointer, display->cursor.serial,
- NULL, 0, 0);
+ wl_pointer_set_cursor(wl->cursor.pointer, wl->cursor.serial, NULL, 0, 0);
}
static void show_cursor (struct vo_wayland_state *wl)
{
- struct vo_wayland_display *display = wl->display;
- if (!display->cursor.pointer)
+ if (!wl->cursor.pointer)
return;
- struct wl_buffer *buffer;
- struct wl_cursor_image *image;
+ struct wl_cursor_image *image = wl->cursor.default_cursor->images[0];
+ struct wl_buffer *buffer = wl_cursor_image_get_buffer(image);
- image = display->cursor.default_cursor->images[0];
- buffer = wl_cursor_image_get_buffer(image);
- wl_pointer_set_cursor(display->cursor.pointer, display->cursor.serial,
- display->cursor.surface, image->hotspot_x, image->hotspot_y);
- wl_surface_attach(display->cursor.surface, buffer, 0, 0);
- wl_surface_damage(display->cursor.surface, 0, 0,
- image->width, image->height);
- wl_surface_commit(display->cursor.surface);
+ 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);
}
static void resize_window(struct vo_wayland_state *wl,
@@ -550,10 +543,10 @@ static void resize_window(struct vo_wayland_state *wl,
int32_t width,
int32_t height)
{
- struct vo_wayland_window *w = wl->window;
- if (w->resize_func && w->resize_func_data) {
- w->resize_func(wl, edges, width, height, w->resize_func_data);
- w->events |= VO_EVENT_RESIZE;
+ if (wl->window.resize_func && wl->window.resize_func_data) {
+ wl->window.resize_func(wl, edges, width, height,
+ wl->window.resize_func_data);
+ wl->window.events |= VO_EVENT_RESIZE;
}
else
mp_msg(MSGT_VO, MSGL_WARN, "[wayland] No resizing possible!\n");
@@ -562,104 +555,101 @@ static void resize_window(struct vo_wayland_state *wl,
static bool create_display (struct vo_wayland_state *wl)
{
- struct vo_wayland_display *d = wl->display;
-
- if (d)
- return true;
-
- d = talloc_zero(wl, struct vo_wayland_display);
- d->display = wl_display_connect(NULL);
-
- wl_list_init(&d->output_list);
+ wl->display.display = wl_display_connect(NULL);
- if (!d->display)
+ if (!wl->display.display)
return false;
- wl->display = d;
- d->registry = wl_display_get_registry(d->display);
- wl_registry_add_listener(d->registry, &registry_listener, wl);
+ wl_list_init(&wl->display.output_list);
+ wl->display.registry = wl_display_get_registry(wl->display.display);
+ wl_registry_add_listener(wl->display.registry, &registry_listener, wl);
- wl_display_dispatch(d->display);
+ wl_display_dispatch(wl->display.display);
- d->cursor.surface =
- wl_compositor_create_surface(d->compositor);
-
- d->display_fd = wl_display_get_fd(d->display);
+ wl->display.display_fd = wl_display_get_fd(wl->display.display);
return true;
}
static void destroy_display (struct vo_wayland_state *wl)
{
+ if (wl->display.shell)
+ wl_shell_destroy(wl->display.shell);
- if (wl->display->cursor.theme)
- wl_cursor_theme_destroy(wl->display->cursor.theme);
-
- if (wl->display->cursor.surface)
- wl_surface_destroy(wl->display->cursor.surface);
-
- if (wl->display->shell)
- wl_shell_destroy(wl->display->shell);
-
- if (wl->display->compositor)
- wl_compositor_destroy(wl->display->compositor);
+ if (wl->display.compositor)
+ wl_compositor_destroy(wl->display.compositor);
- wl_registry_destroy(wl->display->registry);
- wl_display_flush(wl->display->display);
- wl_display_disconnect(wl->display->display);
+ wl_registry_destroy(wl->display.registry);
+ wl_display_flush(wl->display.display);
+ wl_display_disconnect(wl->display.display);
}
-static void create_window (struct vo_wayland_state *wl)
+static bool create_window (struct vo_wayland_state *wl)
{
- if (wl->window)
- return;
+ wl->window.surface = wl_compositor_create_surface(wl->display.compositor);
+ wl->window.shell_surface = wl_shell_get_shell_surface(wl->display.shell,
+ wl->window.surface);
- wl->window = talloc_zero(wl, struct vo_wayland_window);
+ if (!wl->window.shell_surface)
+ return false;
- wl->window->surface = wl_compositor_create_surface(wl->display->compositor);
- wl->window->shell_surface = wl_shell_get_shell_surface(wl->display->shell,
- wl->window->surface);
+ wl_shell_surface_add_listener(wl->window.shell_surface,
+ &shell_surface_listener, wl);
- if (wl->window->shell_surface)
- wl_shell_surface_add_listener(wl->window->shell_surface,
- &shell_surface_listener, wl);
+ wl_shell_surface_set_toplevel(wl->window.shell_surface);
+ wl_shell_surface_set_class(wl->window.shell_surface, "mpv");
- wl_shell_surface_set_toplevel(wl->window->shell_surface);
- wl_shell_surface_set_class(wl->window->shell_surface, "mpv");
+ return true;
}
static void destroy_window (struct vo_wayland_state *wl)
{
- wl_shell_surface_destroy(wl->window->shell_surface);
- wl_surface_destroy(wl->window->surface);
+ wl_shell_surface_destroy(wl->window.shell_surface);
+ wl_surface_destroy(wl->window.surface);
}
-static void create_input (struct vo_wayland_state *wl)
+static bool create_cursor (struct vo_wayland_state *wl)
{
- if (wl->input)
- return;
+ wl->cursor.surface =
+ wl_compositor_create_surface(wl->display.compositor);
- wl->input = talloc_zero(wl, struct vo_wayland_input);
+ return wl->cursor.surface != NULL;
+}
+
+static void destroy_cursor (struct vo_wayland_state *wl)
+{
+ if (wl->cursor.theme)
+ wl_cursor_theme_destroy(wl->cursor.theme);
+
+ if (wl->cursor.surface)
+ wl_surface_destroy(wl->cursor.surface);
+}
+
+static bool create_input (struct vo_wayland_state *wl)
+{
+ wl->input.xkb.context = xkb_context_new(0);
- wl->input->xkb.context = xkb_context_new(0);
- if (wl->input->xkb.context == NULL) {
+ if (!wl->input.xkb.context) {
mp_msg(MSGT_VO, MSGL_ERR, "[wayland] failed to initialize input.\n");
- return;
+ return false;
}
+
+ return true;
}
+
static void destroy_input (struct vo_wayland_state *wl)
{
- if (wl->input->keyboard)
- wl_keyboard_destroy(wl->input->keyboard);
+ if (wl->input.keyboard)
+ wl_keyboard_destroy(wl->input.keyboard);
- if (wl->input->pointer)
- wl_pointer_destroy(wl->input->pointer);
+ if (wl->input.pointer)
+ wl_pointer_destroy(wl->input.pointer);
- if (wl->input->seat)
- wl_seat_destroy(wl->input->seat);
+ if (wl->input.seat)
+ wl_seat_destroy(wl->input.seat);
- xkb_context_unref(wl->input->xkb.context);
+ xkb_context_unref(wl->input.xkb.context);
}
/*** mplayer2 interface ***/
@@ -670,25 +660,27 @@ int vo_wayland_init (struct vo *vo)
struct vo_wayland_state *wl = vo->wayland;
wl->vo = vo;
- create_input(wl);
-
- if (!create_display(wl)) {
+ if (!create_input(wl)
+ || !create_display(wl)
+ || !create_window(wl)
+ || !create_cursor(wl))
+ {
mp_msg(MSGT_VO, MSGL_ERR, "[wayland] failed to initialize display.\n");
return false;
}
- vo->event_fd = wl->display->display_fd;
+ vo->event_fd = wl->display.display_fd;
- create_window(wl);
return true;
}
void vo_wayland_uninit (struct vo *vo)
{
struct vo_wayland_state *wl = vo->wayland;
- destroy_input(wl);
+ destroy_cursor(wl);
destroy_window(wl);
destroy_display(wl);
+ destroy_input(wl);
talloc_free(wl);
vo->wayland = NULL;
}
@@ -717,36 +709,36 @@ static void vo_wayland_border (struct vo *vo)
static void vo_wayland_fullscreen (struct vo *vo)
{
struct vo_wayland_state *wl = vo->wayland;
- if (!wl->window || !wl->display->shell)
+ if (!wl->display.shell)
return;
- struct wl_output *fs_output = wl->display->fs_output;
+ struct wl_output *fs_output = wl->display.fs_output;
if (vo->opts->fullscreen) {
- wl->window->p_width = wl->window->width;
- wl->window->p_height = wl->window->height;
- wl_shell_surface_set_fullscreen(wl->window->shell_surface,
+ wl->window.p_width = wl->window.width;
+ wl->window.p_height = wl->window.height;
+ wl_shell_surface_set_fullscreen(wl->window.shell_surface,
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
0, fs_output);
}
else {
- wl_shell_surface_set_toplevel(wl->window->shell_surface);
- resize_window(wl, 0, wl->window->p_width, wl->window->p_height);
+ wl_shell_surface_set_toplevel(wl->window.shell_surface);
+ resize_window(wl, 0, wl->window.p_width, wl->window.p_height);
}
}
static int vo_wayland_check_events (struct vo *vo)
{
struct vo_wayland_state *wl = vo->wayland;
- struct wl_display *dp = wl->display->display;
+ struct wl_display *dp = wl->display.display;
int ret;
wl_display_dispatch_pending(dp);
wl_display_flush(dp);
struct pollfd fd = {
- wl->display->display_fd,
+ wl->display.display_fd,
POLLIN | POLLOUT | POLLERR | POLLHUP,
0
};
@@ -765,8 +757,8 @@ static int vo_wayland_check_events (struct vo *vo)
wl_display_flush(dp);
}
- ret = wl->window->events;
- wl->window->events = 0;
+ ret = wl->window.events;
+ wl->window.events = 0;
return ret;
}
@@ -777,7 +769,7 @@ static void vo_wayland_update_screeninfo (struct vo *vo)
struct mp_vo_opts *opts = vo->opts;
bool mode_received = false;
- wl_display_roundtrip(wl->display->display);
+ wl_display_roundtrip(wl->display.display);
vo->xinerama_x = vo->xinerama_y = 0;
@@ -787,7 +779,7 @@ static void vo_wayland_update_screeninfo (struct vo *vo)
struct vo_wayland_output *first_output = NULL;
struct vo_wayland_output *fsscreen_output = NULL;
- wl_list_for_each_reverse(output, &wl->display->output_list, link) {
+ wl_list_for_each_reverse(output, &wl->display.output_list, link) {
if (!output || !output->width)
continue;
@@ -808,12 +800,12 @@ static void vo_wayland_update_screeninfo (struct vo *vo)
}
if (fsscreen_output) {
- wl->display->fs_output = fsscreen_output->output;
+ wl->display.fs_output = fsscreen_output->output;
opts->screenwidth = fsscreen_output->width;
opts->screenheight = fsscreen_output->height;
}
else {
- wl->display->fs_output = NULL; /* current output is always 0 */
+ wl->display.fs_output = NULL; /* current output is always 0 */
if (first_output) {
opts->screenwidth = first_output->width;
@@ -827,7 +819,7 @@ static void vo_wayland_update_screeninfo (struct vo *vo)
int vo_wayland_control (struct vo *vo, int *events, int request, void *arg)
{
struct vo_wayland_state *wl = vo->wayland;
- wl_display_dispatch_pending(wl->display->display);
+ wl_display_dispatch_pending(wl->display.display);
switch (request) {
case VOCTRL_CHECK_EVENTS:
@@ -849,17 +841,17 @@ int vo_wayland_control (struct vo *vo, int *events, int request, void *arg)
return VO_TRUE;
case VOCTRL_SET_CURSOR_VISIBILITY:
if (*(bool *)arg) {
- if (!wl->display->cursor.visible)
+ if (!wl->cursor.visible)
show_cursor(wl);
}
else {
- if (wl->display->cursor.visible)
+ if (wl->cursor.visible)
hide_cursor(wl);
}
- wl->display->cursor.visible = *(bool *)arg;
+ wl->cursor.visible = *(bool *)arg;
return VO_TRUE;
case VOCTRL_UPDATE_WINDOW_TITLE:
- wl_shell_surface_set_title(wl->window->shell_surface, (char *) arg);
+ wl_shell_surface_set_title(wl->window.shell_surface, (char *) arg);
return VO_TRUE;
}
return VO_NOTIMPL;
@@ -868,13 +860,13 @@ int vo_wayland_control (struct vo *vo, int *events, int request, void *arg)
bool vo_wayland_config (struct vo *vo, uint32_t d_width,
uint32_t d_height, uint32_t flags)
{
- struct vo_wayland_window *w = vo->wayland->window;
+ struct vo_wayland_state *wl = vo->wayland;
- w->width = d_width;
- w->height = d_height;
- w->p_width = d_width;
- w->p_height = d_height;
- w->aspect = w->width / (float) MPMAX(w->height, 1);
+ wl->window.width = d_width;
+ wl->window.height = d_height;
+ wl->window.p_width = d_width;
+ wl->window.p_height = d_height;
+ wl->window.aspect = wl->window.width / (float) MPMAX(wl->window.height, 1);
vo_wayland_fullscreen(vo);
diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h
index 955a67b20e..6b39e982aa 100644
--- a/video/out/wayland_common.h
+++ b/video/out/wayland_common.h
@@ -30,8 +30,6 @@
#include "config.h"
struct vo;
-struct vo_wayland_state;
-
struct vo_wayland_output {
uint32_t id; /* unique name */
@@ -42,11 +40,48 @@ struct vo_wayland_output {
struct wl_list link;
};
-struct vo_wayland_display {
- struct wl_display *display;
- struct wl_registry *registry;
- struct wl_compositor *compositor;
- struct wl_shell *shell;
+
+struct vo_wayland_state {
+ struct vo *vo;
+
+ struct {
+ int fd;
+ struct wl_display *display;
+ struct wl_registry *registry;
+ struct wl_compositor *compositor;
+ struct wl_shell *shell;
+
+ struct wl_list output_list;
+ struct wl_output *fs_output; /* fullscreen output */
+ int output_mode_received;
+
+ int display_fd;
+
+ uint32_t formats;
+ } display;
+
+ struct {
+ int32_t width;
+ int32_t height;
+ int32_t p_width; // previous sizes for leaving fullscreen
+ int32_t p_height;
+ float aspect;
+
+ struct wl_surface *surface;
+ struct wl_shell_surface *shell_surface;
+ int events; /* mplayer events (VO_EVENT_RESIZE) */
+
+ /* Because the egl windows have a special resize windw function we have to
+ * register it first before doing any resizing.
+ * This makes us independet from the output driver */
+ void (*resize_func) (struct vo_wayland_state *wl,
+ uint32_t edges,
+ int32_t width,
+ int32_t height,
+ void *user_data);
+
+ void *resize_func_data;
+ } window;
struct {
struct wl_shm *shm;
@@ -60,57 +95,17 @@ struct vo_wayland_display {
uint32_t serial;
} cursor;
- int display_fd;
-
- struct wl_list output_list;
- struct wl_output *fs_output; /* fullscreen output */
- int output_mode_received;
-
- uint32_t formats;
-};
-
-struct vo_wayland_window {
- int32_t width;
- int32_t height;
- int32_t p_width;
- int32_t p_height;
- float aspect;
-
- struct wl_surface *surface;
- struct wl_shell_surface *shell_surface;
-
- int events; /* mplayer events (VO_EVENT_RESIZE) */
-
- /* Because the egl windows have a special resize windw function we have to
- * register it first before doing any resizing.
- * This makes us independet from the output driver */
- void (*resize_func) (struct vo_wayland_state *wl,
- uint32_t edges,
- int32_t width,
- int32_t height,
- void *user_data);
-
- void *resize_func_data;
-};
-
-struct vo_wayland_input {
- struct wl_seat *seat;
- struct wl_keyboard *keyboard;
- struct wl_pointer *pointer;
-
struct {
- struct xkb_context *context;
- struct xkb_keymap *keymap;
- struct xkb_state *state;
- } xkb;
-};
-
-struct vo_wayland_state {
- struct vo *vo;
+ struct wl_seat *seat;
+ struct wl_keyboard *keyboard;
+ struct wl_pointer *pointer;
- struct vo_wayland_display *display;
- struct vo_wayland_window *window;
- struct vo_wayland_input *input;
+ struct {
+ struct xkb_context *context;
+ struct xkb_keymap *keymap;
+ struct xkb_state *state;
+ } xkb;
+ } input;
};
int vo_wayland_init(struct vo *vo);