commit 9e70081
Michael Forney
·
2020-10-22 20:47:24 +0000 UTC
parent fad61ad
xdg_shell: Add and populate xdg_positioner fields
1 files changed,
+45,
-6
+45,
-6
1@@ -41,7 +41,13 @@ struct xdg_surface {
2 };
3
4 struct xdg_positioner {
5- struct wl_resource *resource;
6+ int32_t width, height;
7+ int32_t anchor_x, anchor_y;
8+ int32_t anchor_width, anchor_height;
9+ enum xdg_positioner_anchor anchor;
10+ enum xdg_positioner_gravity gravity;
11+ enum xdg_positioner_constraint_adjustment constraint;
12+ int32_t offset_x, offset_y;
13 };
14
15 struct xdg_toplevel {
16@@ -63,31 +69,62 @@ destroy_positioner(struct wl_resource *resource)
17 static void
18 set_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height)
19 {
20+ struct xdg_positioner *positioner = wl_resource_get_user_data(resource);
21+
22+ if (width <= 0 || height <= 0) {
23+ wl_resource_post_error(resource, XDG_POSITIONER_ERROR_INVALID_INPUT, "invalid size");
24+ return;
25+ }
26+ positioner->width = width;
27+ positioner->height = height;
28 }
29
30 static void
31 set_anchor_rect(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height)
32 {
33+ struct xdg_positioner *positioner = wl_resource_get_user_data(resource);
34+
35+ if (width <= 0 || height <= 0) {
36+ wl_resource_post_error(resource, XDG_POSITIONER_ERROR_INVALID_INPUT, "invalid anchor size");
37+ return;
38+ }
39+ positioner->anchor_x = x;
40+ positioner->anchor_y = y;
41+ positioner->anchor_width = width;
42+ positioner->anchor_height = height;
43 }
44
45 static void
46 set_anchor(struct wl_client *client, struct wl_resource *resource, uint32_t anchor)
47 {
48+ struct xdg_positioner *positioner = wl_resource_get_user_data(resource);
49+
50+ positioner->anchor = anchor;
51 }
52
53 static void
54 set_gravity(struct wl_client *client, struct wl_resource *resource, uint32_t gravity)
55 {
56+ struct xdg_positioner *positioner = wl_resource_get_user_data(resource);
57+
58+ positioner->gravity = gravity;
59 }
60
61 static void
62-set_constraint_adjustment(struct wl_client *client, struct wl_resource *resource, uint32_t adjustment)
63+set_constraint_adjustment(struct wl_client *client, struct wl_resource *resource, uint32_t constraint)
64 {
65+ struct xdg_positioner *positioner = wl_resource_get_user_data(resource);
66+
67+ positioner->constraint = constraint;
68 }
69
70 static void
71 set_offset(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y)
72 {
73+ struct xdg_positioner *positioner = wl_resource_get_user_data(resource);
74+
75+ positioner->offset_x = x;
76+ positioner->offset_y = y;
77 }
78
79 static const struct xdg_positioner_interface positioner_impl = {
80@@ -465,16 +502,18 @@ static void
81 create_positioner(struct wl_client *client, struct wl_resource *resource, uint32_t id)
82 {
83 struct xdg_positioner *positioner;
84+ struct wl_resource *positioner_resource;
85 uint32_t version;
86
87- positioner = malloc(sizeof(*positioner));
88+ positioner = calloc(1, sizeof(*positioner));
89 if (!positioner)
90 goto error0;
91+
92 version = wl_resource_get_version(resource);
93- positioner->resource = wl_resource_create(client, &xdg_positioner_interface, version, id);
94- if (!positioner->resource)
95+ positioner_resource = wl_resource_create(client, &xdg_positioner_interface, version, id);
96+ if (!positioner_resource)
97 goto error1;
98- wl_resource_set_implementation(positioner->resource, &positioner_impl, positioner, &destroy_positioner);
99+ wl_resource_set_implementation(positioner_resource, &positioner_impl, positioner, &destroy_positioner);
100 return;
101
102 error1: