AtlatestRepositorysigil-ui
1
/* Scroll frame metadata must survive fractional detents and source changes. */2
#include <assert.h>3
#include "../../native/wayland.c"4
#include "standalone-protocols.h"6
static Event *finish_frame(Wl *window)7
{8
int before = window->count;9
ptr_frame(window, NULL);10
assert(window->count == before + 1);11
return &window->queue[(window->head + before) % QUEUE];12
}14
static Event *wheel_frame(Wl *window, uint32_t axis, int32_t value)15
{16
ptr_axis_source(window, NULL, WL_POINTER_AXIS_SOURCE_WHEEL);17
ptr_axis_value120(window, NULL, axis, value);18
return finish_frame(window);19
}21
static void test_whole_steps(void)22
{23
Wl window = {0};24
Event *event = wheel_frame(&window, WL_POINTER_AXIS_VERTICAL_SCROLL, 120);25
assert(event->v[3] == 1 && event->v[8] == 120);26
event = wheel_frame(&window, WL_POINTER_AXIS_HORIZONTAL_SCROLL, -240);27
assert(event->v[2] == -2 && event->v[7] == -240);28
for (int quarter = 1; quarter <= 4; quarter++) {29
event = wheel_frame(&window, WL_POINTER_AXIS_VERTICAL_SCROLL, 30);30
assert(event->v[3] == (quarter == 4 ? 1 : 0));31
assert(event->v[8] == 30);32
}33
for (int quarter = 1; quarter <= 4; quarter++) {34
event = wheel_frame(&window, WL_POINTER_AXIS_HORIZONTAL_SCROLL, -30);35
assert(event->v[2] == (quarter == 4 ? -1 : 0));36
}37
assert(window.scroll_remainder_x == 0 && window.scroll_remainder_y == 0);39
/* Older seats still use axis_discrete and have no value120 data. */40
ptr_axis_discrete(&window, NULL, WL_POINTER_AXIS_VERTICAL_SCROLL, 1);41
event = finish_frame(&window);42
assert(event->v[3] == 1 && event->v[7] == 0 && event->v[8] == 0);43
}45
static void test_remainder_resets(void)46
{47
Wl window = {0};48
wheel_frame(&window, WL_POINTER_AXIS_VERTICAL_SCROLL, 90);49
Event *event = wheel_frame(&window, WL_POINTER_AXIS_VERTICAL_SCROLL, -30);50
assert(event->v[3] == 0 && window.scroll_remainder_y == -30);51
event = wheel_frame(&window, WL_POINTER_AXIS_VERTICAL_SCROLL, -90);52
assert(event->v[3] == -1 && window.scroll_remainder_y == 0);54
wheel_frame(&window, WL_POINTER_AXIS_VERTICAL_SCROLL, 30);55
wheel_frame(&window, WL_POINTER_AXIS_HORIZONTAL_SCROLL, 90);56
ptr_axis_stop(&window, NULL, 0, WL_POINTER_AXIS_VERTICAL_SCROLL);57
event = finish_frame(&window);58
assert(event->v[9] == 2 && window.scroll_remainder_y == 0);59
assert(window.scroll_remainder_x == 90);60
event = wheel_frame(&window, WL_POINTER_AXIS_VERTICAL_SCROLL, 90);61
assert(event->v[3] == 0);62
event = wheel_frame(&window, WL_POINTER_AXIS_HORIZONTAL_SCROLL, 30);63
assert(event->v[2] == 1);64
wheel_frame(&window, WL_POINTER_AXIS_HORIZONTAL_SCROLL, 30);66
/* A source-only frame clears transient metadata and both remainders. */67
int count = window.count;68
ptr_axis_source(&window, NULL, WL_POINTER_AXIS_SOURCE_FINGER);69
ptr_frame(&window, NULL);70
assert(window.count == count && window.scroll_source == 0);71
assert(window.scroll_remainder_x == 0 && window.scroll_remainder_y == 0);72
event = wheel_frame(&window, WL_POINTER_AXIS_VERTICAL_SCROLL, 30);73
assert(event->v[3] == 0 && window.scroll_remainder_y == 30);74
/* Repeating the same source must not discard an unfinished detent. */75
ptr_axis_source(&window, NULL, WL_POINTER_AXIS_SOURCE_WHEEL);76
ptr_frame(&window, NULL);77
event = wheel_frame(&window, WL_POINTER_AXIS_VERTICAL_SCROLL, 90);78
assert(event->v[3] == 1);80
ptr_axis_source(&window, NULL, WL_POINTER_AXIS_SOURCE_FINGER);81
ptr_frame(&window, NULL);82
window.scroll_y = wl_fixed_from_int(1);83
window.scroll_pending = 1;84
event = finish_frame(&window);85
assert(event->v[6] == 0 && event->v[7] == 0 && event->v[8] == 0);86
}88
int main(void)89
{90
test_whole_steps();91
test_remainder_resets();92
/* The getter checks that a surface has a connection, but never uses93
* that connection. No protocol operation runs in this mock fixture. */94
Wl window = {.service_thread = pthread_self(),95
.display = (struct wl_display *)(uintptr_t)1};96
ptr_axis_source(&window, NULL, WL_POINTER_AXIS_SOURCE_WHEEL);97
ptr_axis_value120(&window, NULL, WL_POINTER_AXIS_VERTICAL_SCROLL, 30);98
window.scroll_y = wl_fixed_from_double(2.5);99
flush_scroll(&window);100
assert(window.count == 1);101
Event *event = &window.queue[0];102
assert(event->type == UI_SCROLL);103
assert(event->v[1] == wl_fixed_from_double(2.5));104
assert(event->v[3] == 0);105
assert(event->v[6] == WL_POINTER_AXIS_SOURCE_WHEEL + 1);106
assert(event->v[8] == 30);107
assert(window.scroll_source == 0 && window.value120_y == 0);109
ptr_axis_source(&window, NULL, WL_POINTER_AXIS_SOURCE_FINGER);110
window.scroll_y = wl_fixed_from_double(1.25);111
window.scroll_pending = 1;112
flush_scroll(&window);113
event = &window.queue[1];114
assert(event->v[6] == WL_POINTER_AXIS_SOURCE_FINGER + 1);115
assert(event->v[7] == 0 && event->v[8] == 0);117
ptr_axis_stop(&window, NULL, 0, WL_POINTER_AXIS_VERTICAL_SCROLL);118
flush_scroll(&window);119
event = &window.queue[2];120
assert(event->v[0] == 0 && event->v[1] == 0);121
assert(event->v[6] == 0 && event->v[9] == 2);122
assert(window.scroll_stops == 0);124
ptr_axis_source(&window, NULL, WL_POINTER_AXIS_SOURCE_WHEEL_TILT);125
ptr_axis_value120(&window, NULL, WL_POINTER_AXIS_HORIZONTAL_SCROLL, -30);126
ptr_axis_value120(&window, NULL, WL_POINTER_AXIS_HORIZONTAL_SCROLL, -30);127
ptr_axis_stop(&window, NULL, 0, WL_POINTER_AXIS_HORIZONTAL_SCROLL);128
flush_scroll(&window);129
event = &window.queue[3];130
assert(event->v[6] == WL_POINTER_AXIS_SOURCE_WHEEL_TILT + 1);131
assert(event->v[7] == -60 && event->v[9] == 1);132
assert(window.scroll_remainder_x == 0);133
assert(window.count == 4);134
flush_scroll(&window);135
assert(window.count == 4);136
SigilVM *vm = sigil_vm_create();137
assert(vm);138
sigil__register_sigil_ui_wayland(vm);139
Value extended = sigil_eval_string(vm, "(make-vector 11 0)");140
assert(!sigil_error_message(vm) && sigil_is_vector(extended));141
Value arguments[] = {142
sigil_make_foreign(vm, wl_tag, &window, NULL, sizeof window), extended143
};144
assert(sigil_as_fixnum(native_wl_next_event(vm, 2, arguments)) == UI_SCROLL);145
assert(sigil_as_fixnum(sigil_vector_ref(extended, 7)) == WL_POINTER_AXIS_SOURCE_WHEEL + 1);146
assert(sigil_as_fixnum(sigil_vector_ref(extended, 9)) == 30);147
Value legacy = sigil_eval_string(vm, "(make-vector 8 0)");148
arguments[1] = legacy;149
assert(sigil_as_fixnum(native_wl_next_event(vm, 2, arguments)) == UI_SCROLL);150
assert(sigil_as_fixnum(sigil_vector_ref(legacy, 2)) == wl_fixed_from_double(1.25));151
assert(!sigil_error_message(vm));152
sigil_vm_destroy(vm);153
puts("PASS: whole wheel steps, fractional frames, reversal/source/stop resets, legacy vectors and metadata");154
return 0;155
}