summaryrefslogtreecommitdiff
path: root/tests/x11/test_state.c
blob: abdda95202798ecebc7eb946c468376c664bf828 (plain)
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
/* Supply native window-state properties without requiring an X server. */
#define XGetWindowProperty state_property
#include "../../src/platform/x11/window.c"
#undef XGetWindowProperty

static Atom properties[3];
static unsigned long property_count;
static int notifications;
static uint32_t reported_state;

int state_property(Display *display, Window window, Atom property,
        long offset, long length, Bool delete_property, Atom type,
        Atom *actual, int *format, unsigned long *count, unsigned long *left,
        unsigned char **data)
{
    assert(display && window == 42 && property == 10);
    assert(!offset && length >= 3 && !delete_property && type == XA_ATOM);
    *actual = XA_ATOM;
    *format = 32;
    *count = property_count;
    *left = 0;
    *data = NULL;
    if (property_count) {
        *data = malloc(property_count * sizeof(*properties));
        assert(*data);
        memcpy(*data, properties, property_count * sizeof(*properties));
    }
    return Success;
}

static void state_changed(struct yasl_surface *surface, uint32_t state, void *ud)
{
    (void)ud;
    assert(yasl_surface_state(surface) == state);
    reported_state = state;
    notifications++;
}

int main(void)
{
    struct x11_display display = {.base.ops = &yasl_x11_backend,
        .net_state = 10, .fullscreen = 20, .maximized_h = 21, .maximized_v = 22};
    display.native = (Display *)&display;
    struct x11_surface surface = {.base = {.display = &display.base,
        .state = YASL_STATE_ACTIVATED}, .window = 42};
    set_callbacks(&surface.base, &(struct yasl_window_cbs){.state = state_changed}, NULL);

    properties[0] = display.fullscreen;
    property_count = 1;
    update_state(&surface);
    assert(notifications == 1);
    assert(reported_state == (YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED));
    update_state(&surface);
    assert(notifications == 1);

    /* Both maximized axes are required; activation survives property changes. */
    properties[0] = display.maximized_h;
    update_state(&surface);
    assert(notifications == 2 && reported_state == YASL_STATE_ACTIVATED);
    properties[1] = display.maximized_v;
    property_count = 2;
    update_state(&surface);
    assert(notifications == 3);
    assert(reported_state == (YASL_STATE_MAXIMIZED | YASL_STATE_ACTIVATED));
    properties[2] = display.fullscreen;
    property_count = 3;
    update_state(&surface);
    assert(notifications == 4);
    assert(reported_state == (YASL_STATE_FULLSCREEN | YASL_STATE_MAXIMIZED | YASL_STATE_ACTIVATED));

    property_count = 0;
    update_state(&surface);
    assert(notifications == 5 && reported_state == YASL_STATE_ACTIVATED);
    update_state(&surface);
    assert(notifications == 5);
    return 0;
}