weston/0001-simple-touch-Add-maximized-fullscreen: Add maximized/fullscreen for simpl...
[AGL/meta-agl.git] / meta-agl-core / recipes-graphics / wayland / weston / 0001-simple-touch-Add-maximized-fullscreen-states.patch
1 From 666300564093838c7d6a723fbce7e3b1a719e873 Mon Sep 17 00:00:00 2001
2 From: Marius Vlad <marius.vlad@collabora.com>
3 Date: Thu, 22 Dec 2022 18:27:14 +0200
4 Subject: [PATCH 1/3] simple-touch: Add maximized/fullscreen states
5
6 Helpful to have other states like maximized or fullscreen for
7 the simple-touch client.
8
9 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
10 ---
11  clients/simple-touch.c | 55 ++++++++++++++++++++++++++++++++++++------
12  1 file changed, 48 insertions(+), 7 deletions(-)
13
14 diff --git a/clients/simple-touch.c b/clients/simple-touch.c
15 index 6559aa24d..e32013161 100644
16 --- a/clients/simple-touch.c
17 +++ b/clients/simple-touch.c
18 @@ -64,9 +64,13 @@ struct touch {
19         struct xdg_toplevel *xdg_toplevel;
20         struct buffer *buffer;
21         int width, height;
22 +       int init_width, init_height;
23         bool running;
24         bool wait_for_configure;
25 +       bool needs_buffer_update;
26         bool has_argb;
27 +       bool maximized;
28 +       bool fullscreen;
29  };
30  
31  static struct buffer *
32 @@ -111,7 +115,7 @@ create_shm_buffer(struct touch *touch)
33  }
34  
35  static void
36 -initial_redraw(void *data)
37 +redraw(void *data)
38  {
39         struct touch *touch = data;
40         struct buffer *buffer = NULL;
41 @@ -119,6 +123,9 @@ initial_redraw(void *data)
42         buffer = create_shm_buffer(touch);
43         assert(buffer);
44  
45 +       if (touch->buffer)
46 +               free(touch->buffer);
47 +
48         touch->buffer = buffer;
49  
50         /* paint the "work-area" */
51 @@ -283,9 +290,10 @@ handle_xdg_surface_configure(void *data, struct xdg_surface *surface,
52  
53         xdg_surface_ack_configure(surface, serial);
54  
55 -       if (touch->wait_for_configure) {
56 -               initial_redraw(touch);
57 +       if (touch->wait_for_configure || touch->needs_buffer_update) {
58 +               redraw(touch);
59                 touch->wait_for_configure = false;
60 +               touch->needs_buffer_update = false;
61         }
62  }
63  
64 @@ -340,9 +348,40 @@ static const struct wl_registry_listener registry_listener = {
65  
66  static void
67  handle_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel,
68 -                             int32_t width, int32_t height,
69 -                             struct wl_array *state)
70 +                         int32_t width, int32_t height, struct wl_array *states)
71  {
72 +       struct touch *touch = data;
73 +       uint32_t *p;
74 +
75 +       touch->fullscreen = false;
76 +       touch->maximized = false;
77 +
78 +       wl_array_for_each(p, states) {
79 +               uint32_t state = *p;
80 +               switch (state) {
81 +               case XDG_TOPLEVEL_STATE_FULLSCREEN:
82 +                       touch->fullscreen = true;
83 +                       break;
84 +               case XDG_TOPLEVEL_STATE_MAXIMIZED:
85 +                       touch->maximized = true;
86 +                       break;
87 +               }
88 +       }
89 +
90 +       if (width > 0 && height > 0) {
91 +               if (!touch->fullscreen && !touch->maximized) {
92 +                       touch->init_width = width;
93 +                       touch->init_width = height;
94 +               }
95 +               touch->width = width;
96 +               touch->height = height;
97 +       } else if (!touch->fullscreen && !touch->maximized) {
98 +               touch->width = touch->init_width;
99 +               touch->height = touch->init_height;
100 +
101 +       }
102 +
103 +       touch->needs_buffer_update = true;
104  }
105  
106  static void
107 @@ -371,6 +410,7 @@ touch_create(int width, int height)
108         assert(touch->display);
109  
110         touch->has_argb = false;
111 +       touch->buffer = NULL;
112         touch->registry = wl_display_get_registry(touch->display);
113         wl_registry_add_listener(touch->registry, &registry_listener, touch);
114         wl_display_dispatch(touch->display);
115 @@ -386,8 +426,8 @@ touch_create(int width, int height)
116                 exit(1);
117         }
118  
119 -       touch->width = width;
120 -       touch->height = height;
121 +       touch->init_width = width;
122 +       touch->init_height = height;
123         touch->surface = wl_compositor_create_surface(touch->compositor);
124  
125         touch->xdg_surface =
126 @@ -403,6 +443,7 @@ touch_create(int width, int height)
127         xdg_toplevel_set_title(touch->xdg_toplevel, "simple-touch");
128         xdg_toplevel_set_app_id(touch->xdg_toplevel, "simple-touch");
129         touch->wait_for_configure = true;
130 +       touch->needs_buffer_update = false;
131         wl_surface_commit(touch->surface);
132  
133         touch->running = true;
134 -- 
135 2.35.1
136