1 #include <hikari/decoration.h>
2
3 #include <hikari/memory.h>
4
5 static void
set_mode(struct hikari_decoration * decoration)6 set_mode(struct hikari_decoration *decoration)
7 {
8 wlr_xdg_toplevel_decoration_v1_set_mode(
9 decoration->decoration, WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
10 }
11
12 static void
request_mode_handler(struct wl_listener * listener,void * data)13 request_mode_handler(struct wl_listener *listener, void *data)
14 {
15 struct hikari_decoration *decoration =
16 wl_container_of(listener, decoration, request_mode);
17
18 set_mode(decoration);
19 }
20
21 static void
destroy_handler(struct wl_listener * listener,void * data)22 destroy_handler(struct wl_listener *listener, void *data)
23 {
24 struct hikari_decoration *decoration =
25 wl_container_of(listener, decoration, destroy);
26
27 wl_list_remove(&decoration->request_mode.link);
28 wl_list_remove(&decoration->destroy.link);
29
30 hikari_free(decoration);
31 }
32
33 void
hikari_decoration_init(struct hikari_decoration * decoration,struct wlr_xdg_toplevel_decoration_v1 * wlr_decoration)34 hikari_decoration_init(struct hikari_decoration *decoration,
35 struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration)
36 {
37 decoration->decoration = wlr_decoration;
38
39 wl_signal_add(
40 &wlr_decoration->events.request_mode, &decoration->request_mode);
41 decoration->request_mode.notify = request_mode_handler;
42
43 wl_signal_add(&wlr_decoration->events.destroy, &decoration->destroy);
44 decoration->destroy.notify = destroy_handler;
45
46 set_mode(decoration);
47 }
48