1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*
* Copyright (C) 2022 Purism SPC
* SPDX-License-Identifier: GPL-3.0-or-later
* Author: Guido Günther <agx@sigxcpu.org>
*/
#include "testlib-layer-shell.h"
#include <wayland-client-protocol.h>
#define HEIGHT 350
#define FOLDED 50
typedef struct _DragTestSimple {
bool found_folded;
bool found_margin;
} DragTestSimple;
static bool
drag_test_done (DragTestSimple *drag_test)
{
return (drag_test->found_folded == true &&
drag_test->found_margin == true);
}
static void
drag_test_simple_handle_drag_end (void *data,
struct zphoc_draggable_layer_surface_v1 *drag_surface,
uint32_t state)
{
DragTestSimple *drag_test = data;
g_debug ("State: %d", state);
if (state == ZPHOC_DRAGGABLE_LAYER_SURFACE_V1_DRAG_END_STATE_FOLDED)
drag_test->found_folded = true;
}
static void
drag_test_simple_handle_dragged (void *data,
struct zphoc_draggable_layer_surface_v1 *drag_surface,
int32_t margin)
{
DragTestSimple *drag_test = data;
/* Just some random value mid way */
if (ABS (margin) > HEIGHT / 2)
drag_test->found_margin = true;
}
const struct zphoc_draggable_layer_surface_v1_listener drag_surface_listener = {
.drag_end = drag_test_simple_handle_drag_end,
.dragged = drag_test_simple_handle_dragged,
};
static gboolean
test_client_layer_shell_effects_drag_surface_simple (PhocTestClientGlobals *globals, gpointer data)
{
PhocTestLayerSurface *ls_green;
static struct zphoc_draggable_layer_surface_v1 *drag_surface;
DragTestSimple drag_test = { 0 };
ls_green = phoc_test_layer_surface_new (globals, 0, HEIGHT, 0xFF00FF00,
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT,
HEIGHT);
g_assert_nonnull (ls_green);
phoc_assert_screenshot (globals, "test-layer-shell-effects-1.png");
drag_surface = zphoc_layer_shell_effects_v1_get_draggable_layer_surface (
globals->layer_shell_effects, ls_green->layer_surface);
g_assert_nonnull (drag_surface);
zphoc_draggable_layer_surface_v1_add_listener (drag_surface, &drag_surface_listener, &drag_test);
zphoc_draggable_layer_surface_v1_set_margins (drag_surface, -(HEIGHT - FOLDED), 0);
zphoc_draggable_layer_surface_v1_set_threshold (drag_surface, wl_fixed_from_double (0.5));
zphoc_draggable_layer_surface_v1_set_exclusive (drag_surface, FOLDED);
zphoc_draggable_layer_surface_v1_set_state (drag_surface,
ZPHOC_DRAGGABLE_LAYER_SURFACE_V1_DRAG_END_STATE_FOLDED);
wl_surface_commit (ls_green->wl_surface);
wl_display_dispatch (globals->display);
wl_display_roundtrip (globals->display);
while (wl_display_dispatch (globals->display) != -1 && !drag_test_done (&drag_test)) {
/* Main loop */
}
phoc_assert_screenshot (globals, "test-layer-shell-effects-2.png");
phoc_test_layer_surface_free (ls_green);
phoc_assert_screenshot (globals, "empty.png");
return TRUE;
}
static gboolean
test_client_layer_shell_effects_alpha_surface_simple (PhocTestClientGlobals *globals, gpointer data)
{
PhocTestLayerSurface *ls_green;
static struct zphoc_alpha_layer_surface_v1 *alpha_surf;
ls_green = phoc_test_layer_surface_new (globals, 0, HEIGHT, 0xFF00FF00,
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT,
HEIGHT);
g_assert_nonnull (ls_green);
phoc_assert_screenshot (globals, "test-layer-shell-effects-alpha-1.png");
alpha_surf = zphoc_layer_shell_effects_v1_get_alpha_layer_surface (
globals->layer_shell_effects, ls_green->layer_surface);
g_assert_nonnull (alpha_surf);
zphoc_alpha_layer_surface_v1_set_alpha (alpha_surf, wl_fixed_from_double (0.5));
wl_surface_commit (ls_green->wl_surface);
wl_display_roundtrip (globals->display);
phoc_assert_screenshot (globals, "test-layer-shell-effects-alpha-2.png");
phoc_test_layer_surface_free (ls_green);
phoc_assert_screenshot (globals, "empty.png");
return TRUE;
}
#undef HEIGHT
#define HEIGHT 200
#define WIDTH 100
static gboolean
test_client_layer_shell_effects_stack_surface_simple (PhocTestClientGlobals *globals, gpointer data)
{
PhocTestLayerSurface *ls_green, *ls_red;
static struct zphoc_stacked_layer_surface_v1 *stacked_surf;
ls_green = phoc_test_layer_surface_new (globals, WIDTH, HEIGHT, 0xFF00FF00,
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP, 0);
g_assert_nonnull (ls_green);
phoc_assert_screenshot (globals, "test-layer-shell-anchor-1.png");
ls_red = phoc_test_layer_surface_new (globals, WIDTH * 2, HEIGHT * 2, 0xFFFF0000,
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, 0);
g_assert_nonnull (ls_red);
phoc_assert_screenshot (globals, "test-layer-shell-anchor-2.png");
stacked_surf = zphoc_layer_shell_effects_v1_get_stacked_layer_surface (
globals->layer_shell_effects, ls_green->layer_surface);
g_assert_nonnull (stacked_surf);
zphoc_stacked_layer_surface_v1_stack_below (stacked_surf, ls_red->layer_surface);
wl_surface_commit (ls_green->wl_surface);
wl_display_roundtrip (globals->display);
phoc_test_layer_surface_free (ls_green);
phoc_test_layer_surface_free (ls_red);
phoc_assert_screenshot (globals, "empty.png");
return TRUE;
}
static void
test_layer_shell_effects_drag_surface_simple (void)
{
PhocTestClientIface iface = { .client_run = test_client_layer_shell_effects_drag_surface_simple };
phoc_test_client_run (TEST_PHOC_CLIENT_TIMEOUT, &iface, NULL);
}
static void
test_layer_shell_effects_alpha_surface_simple (void)
{
PhocTestClientIface iface = { .client_run = test_client_layer_shell_effects_alpha_surface_simple };
phoc_test_client_run (TEST_PHOC_CLIENT_TIMEOUT, &iface, NULL);
}
static void
test_layer_shell_effects_stack_surface_simple (void)
{
PhocTestClientIface iface = { .client_run = test_client_layer_shell_effects_stack_surface_simple };
phoc_test_client_run (TEST_PHOC_CLIENT_TIMEOUT, &iface, NULL);
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
PHOC_TEST_ADD ("/phoc/layer-shell-effects/drag-surface/simple",
test_layer_shell_effects_drag_surface_simple);
PHOC_TEST_ADD ("/phoc/layer-shell-effects/alpha-surface/simple",
test_layer_shell_effects_alpha_surface_simple);
PHOC_TEST_ADD ("/phoc/layer-shell-effects/bind-surface/simple",
test_layer_shell_effects_stack_surface_simple);
return g_test_run ();
}
|