clients: Port simple-shm and simple-egl to xdg-shell

dev
Kristian Høgsberg 11 years ago
parent 9679cf9ba2
commit dfaf65ba16
  1. 7
      Makefile.am
  2. 85
      clients/simple-egl.c
  3. 71
      clients/simple-shm.c

@ -382,6 +382,8 @@ demo_clients += \
weston_simple_shm_SOURCES = \ weston_simple_shm_SOURCES = \
clients/simple-shm.c \ clients/simple-shm.c \
protocol/xdg-shell-protocol.c \
protocol/xdg-shell-client-protocol.h \
shared/os-compatibility.c \ shared/os-compatibility.c \
shared/os-compatibility.h shared/os-compatibility.h
weston_simple_shm_CFLAGS = $(AM_CFLAGS) $(SIMPLE_CLIENT_CFLAGS) weston_simple_shm_CFLAGS = $(AM_CFLAGS) $(SIMPLE_CLIENT_CFLAGS)
@ -404,7 +406,10 @@ endif
if BUILD_SIMPLE_EGL_CLIENTS if BUILD_SIMPLE_EGL_CLIENTS
demo_clients += weston-simple-egl demo_clients += weston-simple-egl
weston_simple_egl_SOURCES = clients/simple-egl.c weston_simple_egl_SOURCES = \
clients/simple-egl.c \
protocol/xdg-shell-protocol.c \
protocol/xdg-shell-client-protocol.h
weston_simple_egl_CFLAGS = $(AM_CFLAGS) $(SIMPLE_EGL_CLIENT_CFLAGS) weston_simple_egl_CFLAGS = $(AM_CFLAGS) $(SIMPLE_EGL_CLIENT_CFLAGS)
weston_simple_egl_LDADD = $(SIMPLE_EGL_CLIENT_LIBS) -lm weston_simple_egl_LDADD = $(SIMPLE_EGL_CLIENT_LIBS) -lm
endif endif

@ -38,6 +38,8 @@
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include "xdg-shell-client-protocol.h"
#ifndef EGL_EXT_swap_buffers_with_damage #ifndef EGL_EXT_swap_buffers_with_damage
#define EGL_EXT_swap_buffers_with_damage 1 #define EGL_EXT_swap_buffers_with_damage 1
typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC)(EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects); typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC)(EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
@ -55,7 +57,7 @@ struct display {
struct wl_display *display; struct wl_display *display;
struct wl_registry *registry; struct wl_registry *registry;
struct wl_compositor *compositor; struct wl_compositor *compositor;
struct wl_shell *shell; struct xdg_shell *shell;
struct wl_seat *seat; struct wl_seat *seat;
struct wl_pointer *pointer; struct wl_pointer *pointer;
struct wl_touch *touch; struct wl_touch *touch;
@ -90,7 +92,7 @@ struct window {
uint32_t benchmark_time, frames; uint32_t benchmark_time, frames;
struct wl_egl_window *native; struct wl_egl_window *native;
struct wl_surface *surface; struct wl_surface *surface;
struct wl_shell_surface *shell_surface; struct xdg_surface *xdg_surface;
EGLSurface egl_surface; EGLSurface egl_surface;
struct wl_callback *callback; struct wl_callback *callback;
int fullscreen, configured, opaque, buffer_size, frame_sync; int fullscreen, configured, opaque, buffer_size, frame_sync;
@ -263,15 +265,15 @@ init_gl(struct window *window)
} }
static void static void
handle_ping(void *data, struct wl_shell_surface *shell_surface, handle_surface_ping(void *data,
uint32_t serial) struct xdg_surface *xdg_surface, uint32_t serial)
{ {
wl_shell_surface_pong(shell_surface, serial); xdg_surface_pong(xdg_surface, serial);
} }
static void static void
handle_configure(void *data, struct wl_shell_surface *shell_surface, handle_surface_configure(void *data, struct xdg_surface *surface,
uint32_t edges, int32_t width, int32_t height) int32_t width, int32_t height)
{ {
struct window *window = data; struct window *window = data;
@ -286,14 +288,44 @@ handle_configure(void *data, struct wl_shell_surface *shell_surface,
} }
static void static void
handle_popup_done(void *data, struct wl_shell_surface *shell_surface) handle_surface_request_set_maximized(void *data, struct xdg_surface *xdg_surface)
{
}
static void
handle_surface_request_unset_maximized(void *data, struct xdg_surface *xdg_surface)
{
}
static void
handle_surface_request_set_fullscreen(void *data, struct xdg_surface *xdg_surface)
{
}
static void
handle_surface_request_unset_fullscreen(void *data, struct xdg_surface *xdg_surface)
{
}
static void
handle_surface_focused_set(void *data, struct xdg_surface *xdg_surface)
{
}
static void
handle_surface_focused_unset(void *data, struct xdg_surface *xdg_surface)
{ {
} }
static const struct wl_shell_surface_listener shell_surface_listener = { static const struct xdg_surface_listener xdg_surface_listener = {
handle_ping, handle_surface_ping,
handle_configure, handle_surface_configure,
handle_popup_done handle_surface_request_set_maximized,
handle_surface_request_unset_maximized,
handle_surface_request_set_fullscreen,
handle_surface_request_unset_fullscreen,
handle_surface_focused_set,
handle_surface_focused_unset,
}; };
static void static void
@ -319,17 +351,15 @@ set_fullscreen(struct window *window, int fullscreen)
window->configured = 0; window->configured = 0;
if (fullscreen) { if (fullscreen) {
wl_shell_surface_set_fullscreen(window->shell_surface, xdg_surface_set_fullscreen(window->xdg_surface);
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
0, NULL);
callback = wl_display_sync(window->display->display); callback = wl_display_sync(window->display->display);
wl_callback_add_listener(callback, wl_callback_add_listener(callback,
&configure_callback_listener, &configure_callback_listener,
window); window);
} else { } else {
wl_shell_surface_set_toplevel(window->shell_surface); xdg_surface_unset_fullscreen(window->xdg_surface);
handle_configure(window, window->shell_surface, 0, handle_surface_configure(window, window->xdg_surface,
window->window_size.width, window->window_size.width,
window->window_size.height); window->window_size.height);
window->configured = 1; window->configured = 1;
@ -343,11 +373,11 @@ create_surface(struct window *window)
EGLBoolean ret; EGLBoolean ret;
window->surface = wl_compositor_create_surface(display->compositor); window->surface = wl_compositor_create_surface(display->compositor);
window->shell_surface = wl_shell_get_shell_surface(display->shell, window->xdg_surface = xdg_shell_get_xdg_surface(display->shell,
window->surface); window->surface);
wl_shell_surface_add_listener(window->shell_surface, xdg_surface_add_listener(window->xdg_surface,
&shell_surface_listener, window); &xdg_surface_listener, window);
window->native = window->native =
wl_egl_window_create(window->surface, wl_egl_window_create(window->surface,
@ -358,7 +388,7 @@ create_surface(struct window *window)
display->egl.conf, display->egl.conf,
window->native, NULL); window->native, NULL);
wl_shell_surface_set_title(window->shell_surface, "simple-egl"); xdg_surface_set_title(window->xdg_surface, "simple-egl");
ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface, ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface,
window->egl_surface, window->display->egl.ctx); window->egl_surface, window->display->egl.ctx);
@ -381,7 +411,7 @@ destroy_surface(struct window *window)
eglDestroySurface(window->display->egl.dpy, window->egl_surface); eglDestroySurface(window->display->egl.dpy, window->egl_surface);
wl_egl_window_destroy(window->native); wl_egl_window_destroy(window->native);
wl_shell_surface_destroy(window->shell_surface); xdg_surface_destroy(window->xdg_surface);
wl_surface_destroy(window->surface); wl_surface_destroy(window->surface);
if (window->callback) if (window->callback)
@ -543,7 +573,7 @@ pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
struct display *display = data; struct display *display = data;
if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED)
wl_shell_surface_move(display->window->shell_surface, xdg_surface_move(display->window->xdg_surface,
display->seat, serial); display->seat, serial);
} }
@ -568,7 +598,7 @@ touch_handle_down(void *data, struct wl_touch *wl_touch,
{ {
struct display *d = (struct display *)data; struct display *d = (struct display *)data;
wl_shell_surface_move(d->window->shell_surface, d->seat, serial); xdg_surface_move(d->window->xdg_surface, d->seat, serial);
} }
static void static void
@ -695,9 +725,10 @@ registry_handle_global(void *data, struct wl_registry *registry,
d->compositor = d->compositor =
wl_registry_bind(registry, name, wl_registry_bind(registry, name,
&wl_compositor_interface, 1); &wl_compositor_interface, 1);
} else if (strcmp(interface, "wl_shell") == 0) { } else if (strcmp(interface, "xdg_shell") == 0) {
d->shell = wl_registry_bind(registry, name, d->shell = wl_registry_bind(registry, name,
&wl_shell_interface, 1); &xdg_shell_interface, 1);
xdg_shell_use_unstable_version(d->shell, 1);
} else if (strcmp(interface, "wl_seat") == 0) { } else if (strcmp(interface, "wl_seat") == 0) {
d->seat = wl_registry_bind(registry, name, d->seat = wl_registry_bind(registry, name,
&wl_seat_interface, 1); &wl_seat_interface, 1);
@ -813,7 +844,7 @@ main(int argc, char **argv)
wl_cursor_theme_destroy(display.cursor_theme); wl_cursor_theme_destroy(display.cursor_theme);
if (display.shell) if (display.shell)
wl_shell_destroy(display.shell); xdg_shell_destroy(display.shell);
if (display.compositor) if (display.compositor)
wl_compositor_destroy(display.compositor); wl_compositor_destroy(display.compositor);

@ -34,12 +34,13 @@
#include <wayland-client.h> #include <wayland-client.h>
#include "../shared/os-compatibility.h" #include "../shared/os-compatibility.h"
#include "xdg-shell-client-protocol.h"
struct display { struct display {
struct wl_display *display; struct wl_display *display;
struct wl_registry *registry; struct wl_registry *registry;
struct wl_compositor *compositor; struct wl_compositor *compositor;
struct wl_shell *shell; struct xdg_shell *shell;
struct wl_shm *shm; struct wl_shm *shm;
uint32_t formats; uint32_t formats;
}; };
@ -54,7 +55,7 @@ struct window {
struct display *display; struct display *display;
int width, height; int width, height;
struct wl_surface *surface; struct wl_surface *surface;
struct wl_shell_surface *shell_surface; struct xdg_surface *xdg_surface;
struct buffer buffers[2]; struct buffer buffers[2];
struct buffer *prev_buffer; struct buffer *prev_buffer;
struct wl_callback *callback; struct wl_callback *callback;
@ -111,27 +112,56 @@ create_shm_buffer(struct display *display, struct buffer *buffer,
} }
static void static void
handle_ping(void *data, struct wl_shell_surface *shell_surface, handle_ping(void *data, struct xdg_surface *surface, uint32_t serial)
uint32_t serial)
{ {
wl_shell_surface_pong(shell_surface, serial); xdg_surface_pong(surface, serial);
} }
static void static void
handle_configure(void *data, struct wl_shell_surface *shell_surface, handle_configure(void *data, struct xdg_surface *surface,
uint32_t edges, int32_t width, int32_t height) int32_t width, int32_t height)
{ {
} }
static void static void
handle_popup_done(void *data, struct wl_shell_surface *shell_surface) handle_request_set_maximized(void *data, struct xdg_surface *xdg_surface)
{ {
} }
static const struct wl_shell_surface_listener shell_surface_listener = { static void
handle_request_unset_maximized(void *data, struct xdg_surface *xdg_surface)
{
}
static void
handle_request_set_fullscreen(void *data, struct xdg_surface *xdg_surface)
{
}
static void
handle_request_unset_fullscreen(void *data, struct xdg_surface *xdg_surface)
{
}
static void
handle_focused_set(void *data, struct xdg_surface *xdg_surface)
{
}
static void
handle_focused_unset(void *data, struct xdg_surface *xdg_surface)
{
}
static const struct xdg_surface_listener xdg_surface_listener = {
handle_ping, handle_ping,
handle_configure, handle_configure,
handle_popup_done handle_request_set_maximized,
handle_request_unset_maximized,
handle_request_set_fullscreen,
handle_request_unset_fullscreen,
handle_focused_set,
handle_focused_unset,
}; };
static struct window * static struct window *
@ -148,16 +178,14 @@ create_window(struct display *display, int width, int height)
window->width = width; window->width = width;
window->height = height; window->height = height;
window->surface = wl_compositor_create_surface(display->compositor); window->surface = wl_compositor_create_surface(display->compositor);
window->shell_surface = wl_shell_get_shell_surface(display->shell, window->xdg_surface = xdg_shell_get_xdg_surface(display->shell,
window->surface); window->surface);
if (window->shell_surface) if (window->xdg_surface)
wl_shell_surface_add_listener(window->shell_surface, xdg_surface_add_listener(window->xdg_surface,
&shell_surface_listener, window); &xdg_surface_listener, window);
wl_shell_surface_set_title(window->shell_surface, "simple-shm");
wl_shell_surface_set_toplevel(window->shell_surface); xdg_surface_set_title(window->xdg_surface, "simple-shm");
return window; return window;
} }
@ -173,7 +201,7 @@ destroy_window(struct window *window)
if (window->buffers[1].buffer) if (window->buffers[1].buffer)
wl_buffer_destroy(window->buffers[1].buffer); wl_buffer_destroy(window->buffers[1].buffer);
wl_shell_surface_destroy(window->shell_surface); xdg_surface_destroy(window->xdg_surface);
wl_surface_destroy(window->surface); wl_surface_destroy(window->surface);
free(window); free(window);
} }
@ -310,9 +338,10 @@ registry_handle_global(void *data, struct wl_registry *registry,
d->compositor = d->compositor =
wl_registry_bind(registry, wl_registry_bind(registry,
id, &wl_compositor_interface, 1); id, &wl_compositor_interface, 1);
} else if (strcmp(interface, "wl_shell") == 0) { } else if (strcmp(interface, "xdg_shell") == 0) {
d->shell = wl_registry_bind(registry, d->shell = wl_registry_bind(registry,
id, &wl_shell_interface, 1); id, &xdg_shell_interface, 1);
xdg_shell_use_unstable_version(d->shell, 1);
} else if (strcmp(interface, "wl_shm") == 0) { } else if (strcmp(interface, "wl_shm") == 0) {
d->shm = wl_registry_bind(registry, d->shm = wl_registry_bind(registry,
id, &wl_shm_interface, 1); id, &wl_shm_interface, 1);
@ -373,7 +402,7 @@ destroy_display(struct display *display)
wl_shm_destroy(display->shm); wl_shm_destroy(display->shm);
if (display->shell) if (display->shell)
wl_shell_destroy(display->shell); xdg_shell_destroy(display->shell);
if (display->compositor) if (display->compositor)
wl_compositor_destroy(display->compositor); wl_compositor_destroy(display->compositor);

Loading…
Cancel
Save