mirror of
https://github.com/brl/mutter.git
synced 2025-02-27 18:24:10 +00:00
tests/wayland/xdg-toplevel-bounds: Port to WaylandDisplay
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2416>
This commit is contained in:
parent
2c2aa7acc3
commit
9b97c9b4d4
@ -150,8 +150,17 @@ handle_registry_global (void *user_data,
|
|||||||
}
|
}
|
||||||
else if (strcmp (interface, "xdg_wm_base") == 0)
|
else if (strcmp (interface, "xdg_wm_base") == 0)
|
||||||
{
|
{
|
||||||
|
int xdg_wm_base_version = 1;
|
||||||
|
|
||||||
|
if (display->capabilities &
|
||||||
|
WAYLAND_DISPLAY_CAPABILITY_XDG_SHELL_V4)
|
||||||
|
xdg_wm_base_version = 4;
|
||||||
|
|
||||||
|
g_assert_cmpint (version, >=, xdg_wm_base_version);
|
||||||
|
|
||||||
display->xdg_wm_base = wl_registry_bind (registry, id,
|
display->xdg_wm_base = wl_registry_bind (registry, id,
|
||||||
&xdg_wm_base_interface, 1);
|
&xdg_wm_base_interface,
|
||||||
|
xdg_wm_base_version);
|
||||||
xdg_wm_base_add_listener (display->xdg_wm_base, &xdg_wm_base_listener,
|
xdg_wm_base_add_listener (display->xdg_wm_base, &xdg_wm_base_listener,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ typedef enum _WaylandDisplayCapabilities
|
|||||||
{
|
{
|
||||||
WAYLAND_DISPLAY_CAPABILITY_NONE = 0,
|
WAYLAND_DISPLAY_CAPABILITY_NONE = 0,
|
||||||
WAYLAND_DISPLAY_CAPABILITY_TEST_DRIVER = 1 << 0,
|
WAYLAND_DISPLAY_CAPABILITY_TEST_DRIVER = 1 << 0,
|
||||||
|
WAYLAND_DISPLAY_CAPABILITY_XDG_SHELL_V4 = 1 << 1,
|
||||||
} WaylandDisplayCapabilities;
|
} WaylandDisplayCapabilities;
|
||||||
|
|
||||||
typedef struct _WaylandDisplay
|
typedef struct _WaylandDisplay
|
||||||
|
@ -24,9 +24,6 @@
|
|||||||
|
|
||||||
#include "wayland-test-client-utils.h"
|
#include "wayland-test-client-utils.h"
|
||||||
|
|
||||||
#include "test-driver-client-protocol.h"
|
|
||||||
#include "xdg-shell-client-protocol.h"
|
|
||||||
|
|
||||||
typedef enum _State
|
typedef enum _State
|
||||||
{
|
{
|
||||||
STATE_INIT = 0,
|
STATE_INIT = 0,
|
||||||
@ -34,12 +31,7 @@ typedef enum _State
|
|||||||
STATE_WAIT_FOR_FRAME_1,
|
STATE_WAIT_FOR_FRAME_1,
|
||||||
} State;
|
} State;
|
||||||
|
|
||||||
static struct wl_display *display;
|
static WaylandDisplay *display;
|
||||||
static struct wl_registry *registry;
|
|
||||||
static struct wl_compositor *compositor;
|
|
||||||
static struct xdg_wm_base *xdg_wm_base;
|
|
||||||
static struct wl_shm *shm;
|
|
||||||
static struct test_driver *test_driver;
|
|
||||||
|
|
||||||
static struct wl_surface *surface;
|
static struct wl_surface *surface;
|
||||||
static struct xdg_surface *xdg_surface;
|
static struct xdg_surface *xdg_surface;
|
||||||
@ -104,7 +96,7 @@ create_shm_buffer (int width,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pool = wl_shm_create_pool (shm, fd, size);
|
pool = wl_shm_create_pool (display->shm, fd, size);
|
||||||
buffer = wl_shm_pool_create_buffer (pool, 0,
|
buffer = wl_shm_pool_create_buffer (pool, 0,
|
||||||
width, height,
|
width, height,
|
||||||
stride,
|
stride,
|
||||||
@ -202,7 +194,7 @@ handle_frame_callback (void *data,
|
|||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case STATE_WAIT_FOR_FRAME_1:
|
case STATE_WAIT_FOR_FRAME_1:
|
||||||
test_driver_sync_point (test_driver, 1, NULL);
|
test_driver_sync_point (display->test_driver, 1, NULL);
|
||||||
break;
|
break;
|
||||||
case STATE_INIT:
|
case STATE_INIT:
|
||||||
case STATE_WAIT_FOR_CONFIGURE_1:
|
case STATE_WAIT_FOR_CONFIGURE_1:
|
||||||
@ -239,7 +231,7 @@ handle_xdg_surface_configure (void *data,
|
|||||||
frame_callback = wl_surface_frame (surface);
|
frame_callback = wl_surface_frame (surface);
|
||||||
wl_callback_add_listener (frame_callback, &frame_listener, NULL);
|
wl_callback_add_listener (frame_callback, &frame_listener, NULL);
|
||||||
wl_surface_commit (surface);
|
wl_surface_commit (surface);
|
||||||
wl_display_flush (display);
|
wl_display_flush (display->display);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct xdg_surface_listener xdg_surface_listener = {
|
static const struct xdg_surface_listener xdg_surface_listener = {
|
||||||
@ -247,97 +239,24 @@ static const struct xdg_surface_listener xdg_surface_listener = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_xdg_wm_base_ping (void *data,
|
on_sync_event (WaylandDisplay *display,
|
||||||
struct xdg_wm_base *xdg_wm_base,
|
uint32_t serial)
|
||||||
uint32_t serial)
|
|
||||||
{
|
|
||||||
xdg_wm_base_pong (xdg_wm_base, serial);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct xdg_wm_base_listener xdg_wm_base_listener = {
|
|
||||||
handle_xdg_wm_base_ping,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
test_driver_handle_sync_event (void *data,
|
|
||||||
struct test_driver *test_driver,
|
|
||||||
uint32_t serial)
|
|
||||||
{
|
{
|
||||||
g_assert (serial == 0);
|
g_assert (serial == 0);
|
||||||
|
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct test_driver_listener test_driver_listener = {
|
|
||||||
test_driver_handle_sync_event,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
handle_registry_global (void *data,
|
|
||||||
struct wl_registry *registry,
|
|
||||||
uint32_t id,
|
|
||||||
const char *interface,
|
|
||||||
uint32_t version)
|
|
||||||
{
|
|
||||||
if (strcmp (interface, "wl_compositor") == 0)
|
|
||||||
{
|
|
||||||
compositor = wl_registry_bind (registry, id, &wl_compositor_interface, 1);
|
|
||||||
}
|
|
||||||
else if (strcmp (interface, "xdg_wm_base") == 0)
|
|
||||||
{
|
|
||||||
xdg_wm_base = wl_registry_bind (registry, id,
|
|
||||||
&xdg_wm_base_interface, 4);
|
|
||||||
xdg_wm_base_add_listener (xdg_wm_base, &xdg_wm_base_listener, NULL);
|
|
||||||
}
|
|
||||||
else if (strcmp (interface, "wl_shm") == 0)
|
|
||||||
{
|
|
||||||
shm = wl_registry_bind (registry,
|
|
||||||
id, &wl_shm_interface, 1);
|
|
||||||
}
|
|
||||||
else if (strcmp (interface, "test_driver") == 0)
|
|
||||||
{
|
|
||||||
test_driver = wl_registry_bind (registry, id, &test_driver_interface, 1);
|
|
||||||
test_driver_add_listener (test_driver, &test_driver_listener, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
handle_registry_global_remove (void *data,
|
|
||||||
struct wl_registry *registry,
|
|
||||||
uint32_t name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct wl_registry_listener registry_listener = {
|
|
||||||
handle_registry_global,
|
|
||||||
handle_registry_global_remove
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
display = wl_display_connect (NULL);
|
display = wayland_display_new (WAYLAND_DISPLAY_CAPABILITY_TEST_DRIVER |
|
||||||
registry = wl_display_get_registry (display);
|
WAYLAND_DISPLAY_CAPABILITY_XDG_SHELL_V4);
|
||||||
wl_registry_add_listener (registry, ®istry_listener, NULL);
|
g_signal_connect (display, "sync-event", G_CALLBACK (on_sync_event), NULL);
|
||||||
wl_display_roundtrip (display);
|
|
||||||
|
|
||||||
if (!shm)
|
surface = wl_compositor_create_surface (display->compositor);
|
||||||
{
|
xdg_surface = xdg_wm_base_get_xdg_surface (display->xdg_wm_base, surface);
|
||||||
fprintf (stderr, "No wl_shm global\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!xdg_wm_base)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "No xdg_wm_base global\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
wl_display_roundtrip (display);
|
|
||||||
|
|
||||||
surface = wl_compositor_create_surface (compositor);
|
|
||||||
xdg_surface = xdg_wm_base_get_xdg_surface (xdg_wm_base, surface);
|
|
||||||
xdg_surface_add_listener (xdg_surface, &xdg_surface_listener, NULL);
|
xdg_surface_add_listener (xdg_surface, &xdg_surface_listener, NULL);
|
||||||
xdg_toplevel = xdg_surface_get_toplevel (xdg_surface);
|
xdg_toplevel = xdg_surface_get_toplevel (xdg_surface);
|
||||||
xdg_toplevel_add_listener (xdg_toplevel, &xdg_toplevel_listener, NULL);
|
xdg_toplevel_add_listener (xdg_toplevel, &xdg_toplevel_listener, NULL);
|
||||||
@ -350,7 +269,7 @@ main (int argc,
|
|||||||
running = TRUE;
|
running = TRUE;
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
if (wl_display_dispatch (display) == -1)
|
if (wl_display_dispatch (display->display) == -1)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user