diff options
author | emersion <contact@emersion.fr> | 2018-04-05 11:38:14 -0400 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-04-05 11:40:39 -0400 |
commit | dcd15a2d3dd93e057fe702238eb21dd70331b44f (patch) | |
tree | d3fb74ee77369ad52edeba7bac1f3ada907d3099 /sway/desktop/xdg_shell_v6.c | |
parent | Error handling in swaylock daemonize() (diff) | |
download | sway-dcd15a2d3dd93e057fe702238eb21dd70331b44f.tar.gz sway-dcd15a2d3dd93e057fe702238eb21dd70331b44f.tar.zst sway-dcd15a2d3dd93e057fe702238eb21dd70331b44f.zip |
Implement shell views
Diffstat (limited to 'sway/desktop/xdg_shell_v6.c')
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 110 |
1 files changed, 60 insertions, 50 deletions
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 5cdb8f9f..7b9d5fb7 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -11,13 +11,17 @@ | |||
11 | #include "sway/input/input-manager.h" | 11 | #include "sway/input/input-manager.h" |
12 | #include "log.h" | 12 | #include "log.h" |
13 | 13 | ||
14 | static bool assert_xdg(struct sway_view *view) { | 14 | static struct sway_xdg_shell_v6_view *xdg_shell_v6_view_from_view( |
15 | return sway_assert(view->type == SWAY_VIEW_XDG_SHELL_V6, | 15 | struct sway_view *view) { |
16 | "Expected xdg shell v6 view!"); | 16 | if (!sway_assert(view->type == SWAY_VIEW_XDG_SHELL_V6, |
17 | "Expected xdg_shell_v6 view")) { | ||
18 | return NULL; | ||
19 | } | ||
20 | return (struct sway_xdg_shell_v6_view *)view; | ||
17 | } | 21 | } |
18 | 22 | ||
19 | static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) { | 23 | static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) { |
20 | if (!assert_xdg(view)) { | 24 | if (xdg_shell_v6_view_from_view(view) == NULL) { |
21 | return NULL; | 25 | return NULL; |
22 | } | 26 | } |
23 | switch (prop) { | 27 | switch (prop) { |
@@ -32,18 +36,20 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) { | |||
32 | 36 | ||
33 | static void configure(struct sway_view *view, double ox, double oy, int width, | 37 | static void configure(struct sway_view *view, double ox, double oy, int width, |
34 | int height) { | 38 | int height) { |
35 | if (!assert_xdg(view)) { | 39 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = |
40 | xdg_shell_v6_view_from_view(view); | ||
41 | if (xdg_shell_v6_view == NULL) { | ||
36 | return; | 42 | return; |
37 | } | 43 | } |
38 | 44 | ||
39 | view_update_position(view, ox, oy); | 45 | view_update_position(view, ox, oy); |
40 | view->sway_xdg_surface_v6->pending_width = width; | 46 | xdg_shell_v6_view->pending_width = width; |
41 | view->sway_xdg_surface_v6->pending_height = height; | 47 | xdg_shell_v6_view->pending_height = height; |
42 | wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height); | 48 | wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height); |
43 | } | 49 | } |
44 | 50 | ||
45 | static void set_activated(struct sway_view *view, bool activated) { | 51 | static void set_activated(struct sway_view *view, bool activated) { |
46 | if (!assert_xdg(view)) { | 52 | if (xdg_shell_v6_view_from_view(view) == NULL) { |
47 | return; | 53 | return; |
48 | } | 54 | } |
49 | struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6; | 55 | struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6; |
@@ -53,7 +59,7 @@ static void set_activated(struct sway_view *view, bool activated) { | |||
53 | } | 59 | } |
54 | 60 | ||
55 | static void _close(struct sway_view *view) { | 61 | static void _close(struct sway_view *view) { |
56 | if (!assert_xdg(view)) { | 62 | if (xdg_shell_v6_view_from_view(view) == NULL) { |
57 | return; | 63 | return; |
58 | } | 64 | } |
59 | struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6; | 65 | struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6; |
@@ -62,6 +68,19 @@ static void _close(struct sway_view *view) { | |||
62 | } | 68 | } |
63 | } | 69 | } |
64 | 70 | ||
71 | static void destroy(struct sway_view *view) { | ||
72 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = | ||
73 | xdg_shell_v6_view_from_view(view); | ||
74 | if (xdg_shell_v6_view == NULL) { | ||
75 | return; | ||
76 | } | ||
77 | wl_list_remove(&xdg_shell_v6_view->commit.link); | ||
78 | wl_list_remove(&xdg_shell_v6_view->destroy.link); | ||
79 | wl_list_remove(&xdg_shell_v6_view->map.link); | ||
80 | wl_list_remove(&xdg_shell_v6_view->unmap.link); | ||
81 | free(xdg_shell_v6_view); | ||
82 | } | ||
83 | |||
65 | static const struct sway_view_impl view_impl = { | 84 | static const struct sway_view_impl view_impl = { |
66 | .get_prop = get_prop, | 85 | .get_prop = get_prop, |
67 | .configure = configure, | 86 | .configure = configure, |
@@ -70,83 +89,74 @@ static const struct sway_view_impl view_impl = { | |||
70 | }; | 89 | }; |
71 | 90 | ||
72 | static void handle_commit(struct wl_listener *listener, void *data) { | 91 | static void handle_commit(struct wl_listener *listener, void *data) { |
73 | struct sway_xdg_surface_v6 *sway_surface = | 92 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = |
74 | wl_container_of(listener, sway_surface, commit); | 93 | wl_container_of(listener, xdg_shell_v6_view, commit); |
75 | struct sway_view *view = sway_surface->view; | 94 | struct sway_view *view = &xdg_shell_v6_view->view; |
76 | // NOTE: We intentionally discard the view's desired width here | 95 | // NOTE: We intentionally discard the view's desired width here |
77 | // TODO: Store this for restoration when moving to floating plane | 96 | // TODO: Store this for restoration when moving to floating plane |
78 | // TODO: Let floating views do whatever | 97 | // TODO: Let floating views do whatever |
79 | view_update_size(view, sway_surface->pending_width, | 98 | view_update_size(view, xdg_shell_v6_view->pending_width, |
80 | sway_surface->pending_height); | 99 | xdg_shell_v6_view->pending_height); |
81 | view_damage_from(view); | 100 | view_damage_from(view); |
82 | } | 101 | } |
83 | 102 | ||
84 | static void handle_unmap(struct wl_listener *listener, void *data) { | 103 | static void handle_unmap(struct wl_listener *listener, void *data) { |
85 | struct sway_xdg_surface_v6 *sway_surface = | 104 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = |
86 | wl_container_of(listener, sway_surface, unmap); | 105 | wl_container_of(listener, xdg_shell_v6_view, unmap); |
87 | view_unmap(sway_surface->view); | 106 | view_unmap(&xdg_shell_v6_view->view); |
88 | } | 107 | } |
89 | 108 | ||
90 | static void handle_map(struct wl_listener *listener, void *data) { | 109 | static void handle_map(struct wl_listener *listener, void *data) { |
91 | struct sway_xdg_surface_v6 *sway_surface = | 110 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = |
92 | wl_container_of(listener, sway_surface, map); | 111 | wl_container_of(listener, xdg_shell_v6_view, map); |
93 | struct sway_view *view = sway_surface->view; | 112 | struct sway_view *view = &xdg_shell_v6_view->view; |
94 | view_map(view, view->wlr_xdg_surface_v6->surface); | 113 | view_map(view, view->wlr_xdg_surface_v6->surface); |
95 | } | 114 | } |
96 | 115 | ||
97 | static void handle_destroy(struct wl_listener *listener, void *data) { | 116 | static void handle_destroy(struct wl_listener *listener, void *data) { |
98 | struct sway_xdg_surface_v6 *sway_xdg_surface = | 117 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = |
99 | wl_container_of(listener, sway_xdg_surface, destroy); | 118 | wl_container_of(listener, xdg_shell_v6_view, destroy); |
100 | wl_list_remove(&sway_xdg_surface->commit.link); | 119 | view_destroy(&xdg_shell_v6_view->view); |
101 | wl_list_remove(&sway_xdg_surface->destroy.link); | ||
102 | wl_list_remove(&sway_xdg_surface->map.link); | ||
103 | wl_list_remove(&sway_xdg_surface->unmap.link); | ||
104 | view_destroy(sway_xdg_surface->view); | ||
105 | free(sway_xdg_surface); | ||
106 | } | 120 | } |
107 | 121 | ||
108 | void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { | 122 | void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { |
109 | struct sway_server *server = wl_container_of( | 123 | struct sway_server *server = wl_container_of(listener, server, |
110 | listener, server, xdg_shell_v6_surface); | 124 | xdg_shell_v6_surface); |
111 | struct wlr_xdg_surface_v6 *xdg_surface = data; | 125 | struct wlr_xdg_surface_v6 *xdg_surface = data; |
112 | 126 | ||
113 | if (xdg_surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { | 127 | if (xdg_surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { |
114 | // TODO: popups | 128 | wlr_log(L_DEBUG, "New xdg_shell_v6 popup"); |
115 | return; | 129 | return; |
116 | } | 130 | } |
117 | 131 | ||
118 | wlr_log(L_DEBUG, "New xdg_shell_v6 toplevel title='%s' app_id='%s'", | 132 | wlr_log(L_DEBUG, "New xdg_shell_v6 toplevel title='%s' app_id='%s'", |
119 | xdg_surface->toplevel->title, xdg_surface->toplevel->app_id); | 133 | xdg_surface->toplevel->title, xdg_surface->toplevel->app_id); |
120 | wlr_xdg_surface_v6_ping(xdg_surface); | 134 | wlr_xdg_surface_v6_ping(xdg_surface); |
121 | wlr_xdg_toplevel_v6_set_maximized(xdg_surface, true); | 135 | wlr_xdg_toplevel_v6_set_maximized(xdg_surface, true); |
122 | 136 | ||
123 | struct sway_xdg_surface_v6 *sway_surface = | 137 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = |
124 | calloc(1, sizeof(struct sway_xdg_surface_v6)); | 138 | calloc(1, sizeof(struct sway_xdg_shell_v6_view)); |
125 | if (!sway_assert(sway_surface, "Failed to allocate surface!")) { | 139 | if (!sway_assert(xdg_shell_v6_view, "Failed to allocate view")) { |
126 | return; | 140 | return; |
127 | } | 141 | } |
128 | 142 | ||
129 | struct sway_view *view = view_create(SWAY_VIEW_XDG_SHELL_V6, &view_impl); | 143 | view_init(&xdg_shell_v6_view->view, SWAY_VIEW_XDG_SHELL_V6, &view_impl); |
130 | if (!sway_assert(view, "Failed to allocate view")) { | 144 | xdg_shell_v6_view->view.wlr_xdg_surface_v6 = xdg_surface; |
131 | return; | ||
132 | } | ||
133 | view->wlr_xdg_surface_v6 = xdg_surface; | ||
134 | view->sway_xdg_surface_v6 = sway_surface; | ||
135 | sway_surface->view = view; | ||
136 | 145 | ||
137 | // TODO: | 146 | // TODO: |
138 | // - Look up pid and open on appropriate workspace | 147 | // - Look up pid and open on appropriate workspace |
139 | // - Criteria | 148 | // - Criteria |
140 | 149 | ||
141 | sway_surface->commit.notify = handle_commit; | 150 | xdg_shell_v6_view->commit.notify = handle_commit; |
142 | wl_signal_add(&xdg_surface->surface->events.commit, &sway_surface->commit); | 151 | wl_signal_add(&xdg_surface->surface->events.commit, |
152 | &xdg_shell_v6_view->commit); | ||
143 | 153 | ||
144 | sway_surface->map.notify = handle_map; | 154 | xdg_shell_v6_view->map.notify = handle_map; |
145 | wl_signal_add(&xdg_surface->events.map, &sway_surface->map); | 155 | wl_signal_add(&xdg_surface->events.map, &xdg_shell_v6_view->map); |
146 | 156 | ||
147 | sway_surface->unmap.notify = handle_unmap; | 157 | xdg_shell_v6_view->unmap.notify = handle_unmap; |
148 | wl_signal_add(&xdg_surface->events.unmap, &sway_surface->unmap); | 158 | wl_signal_add(&xdg_surface->events.unmap, &xdg_shell_v6_view->unmap); |
149 | 159 | ||
150 | sway_surface->destroy.notify = handle_destroy; | 160 | xdg_shell_v6_view->destroy.notify = handle_destroy; |
151 | wl_signal_add(&xdg_surface->events.destroy, &sway_surface->destroy); | 161 | wl_signal_add(&xdg_surface->events.destroy, &xdg_shell_v6_view->destroy); |
152 | } | 162 | } |