summaryrefslogtreecommitdiffstats
path: root/sway/desktop/wl_shell.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/desktop/wl_shell.c')
-rw-r--r--sway/desktop/wl_shell.c79
1 files changed, 43 insertions, 36 deletions
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c
index a470674d..5955fa9d 100644
--- a/sway/desktop/wl_shell.c
+++ b/sway/desktop/wl_shell.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
14static bool assert_wl_shell(struct sway_view *view) { 14static struct sway_wl_shell_view *wl_shell_view_from_view(
15 return sway_assert(view->type == SWAY_VIEW_WL_SHELL, 15 struct sway_view *view) {
16 "Expecting wl_shell view!"); 16 if (!sway_assert(view->type == SWAY_VIEW_WL_SHELL,
17 "Expected wl_shell view")) {
18 return NULL;
19 }
20 return (struct sway_wl_shell_view *)view;
17} 21}
18 22
19static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) { 23static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) {
20 if (!assert_wl_shell(view)) { 24 if (wl_shell_view_from_view(view) == NULL) {
21 return NULL; 25 return NULL;
22 } 26 }
23 switch (prop) { 27 switch (prop) {
@@ -32,23 +36,34 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) {
32 36
33static void configure(struct sway_view *view, double ox, double oy, int width, 37static void configure(struct sway_view *view, double ox, double oy, int width,
34 int height) { 38 int height) {
35 if (!assert_wl_shell(view)) { 39 struct sway_wl_shell_view *wl_shell_view = wl_shell_view_from_view(view);
40 if (wl_shell_view == NULL) {
36 return; 41 return;
37 } 42 }
38 view_update_position(view, ox, oy); 43 view_update_position(view, ox, oy);
39 view->sway_wl_shell_surface->pending_width = width; 44 wl_shell_view->pending_width = width;
40 view->sway_wl_shell_surface->pending_height = height; 45 wl_shell_view->pending_height = height;
41 wlr_wl_shell_surface_configure(view->wlr_wl_shell_surface, 0, width, height); 46 wlr_wl_shell_surface_configure(view->wlr_wl_shell_surface, 0, width, height);
42} 47}
43 48
44static void _close(struct sway_view *view) { 49static void _close(struct sway_view *view) {
45 if (!assert_wl_shell(view)) { 50 if (wl_shell_view_from_view(view) == NULL) {
46 return; 51 return;
47 } 52 }
48 53
49 wl_client_destroy(view->wlr_wl_shell_surface->client); 54 wl_client_destroy(view->wlr_wl_shell_surface->client);
50} 55}
51 56
57static void destroy(struct sway_view *view) {
58 struct sway_wl_shell_view *wl_shell_view = wl_shell_view_from_view(view);
59 if (wl_shell_view == NULL) {
60 return;
61 }
62 wl_list_remove(&wl_shell_view->commit.link);
63 wl_list_remove(&wl_shell_view->destroy.link);
64 free(wl_shell_view);
65}
66
52static const struct sway_view_impl view_impl = { 67static const struct sway_view_impl view_impl = {
53 .get_prop = get_prop, 68 .get_prop = get_prop,
54 .configure = configure, 69 .configure = configure,
@@ -56,23 +71,20 @@ static const struct sway_view_impl view_impl = {
56}; 71};
57 72
58static void handle_commit(struct wl_listener *listener, void *data) { 73static void handle_commit(struct wl_listener *listener, void *data) {
59 struct sway_wl_shell_surface *sway_surface = 74 struct sway_wl_shell_view *wl_shell_view =
60 wl_container_of(listener, sway_surface, commit); 75 wl_container_of(listener, wl_shell_view, commit);
61 struct sway_view *view = sway_surface->view; 76 struct sway_view *view = &wl_shell_view->view;
62 // NOTE: We intentionally discard the view's desired width here 77 // NOTE: We intentionally discard the view's desired width here
63 // TODO: Let floating views do whatever 78 // TODO: Let floating views do whatever
64 view_update_size(view, sway_surface->pending_width, 79 view_update_size(view, wl_shell_view->pending_width,
65 sway_surface->pending_height); 80 wl_shell_view->pending_height);
66 view_damage_from(view); 81 view_damage_from(view);
67} 82}
68 83
69static void handle_destroy(struct wl_listener *listener, void *data) { 84static void handle_destroy(struct wl_listener *listener, void *data) {
70 struct sway_wl_shell_surface *sway_surface = 85 struct sway_wl_shell_view *wl_shell_view =
71 wl_container_of(listener, sway_surface, destroy); 86 wl_container_of(listener, wl_shell_view, destroy);
72 wl_list_remove(&sway_surface->commit.link); 87 view_destroy(&wl_shell_view->view);
73 wl_list_remove(&sway_surface->destroy.link);
74 view_destroy(sway_surface->view);
75 free(sway_surface);
76} 88}
77 89
78void handle_wl_shell_surface(struct wl_listener *listener, void *data) { 90void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
@@ -82,42 +94,37 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
82 94
83 if (shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP) { 95 if (shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP) {
84 // popups don't get views 96 // popups don't get views
97 wlr_log(L_DEBUG, "New wl_shell popup");
85 return; 98 return;
86 } 99 }
87 100
88 // TODO make transient windows floating 101 // TODO: make transient windows floating
89 102
90 wlr_log(L_DEBUG, "New wl_shell toplevel title='%s' app_id='%s'", 103 wlr_log(L_DEBUG, "New wl_shell toplevel title='%s' app_id='%s'",
91 shell_surface->title, shell_surface->class); 104 shell_surface->title, shell_surface->class);
92 wlr_wl_shell_surface_ping(shell_surface); 105 wlr_wl_shell_surface_ping(shell_surface);
93 106
94 struct sway_wl_shell_surface *sway_surface = 107 struct sway_wl_shell_view *wl_shell_view =
95 calloc(1, sizeof(struct sway_wl_shell_surface)); 108 calloc(1, sizeof(struct sway_wl_shell_view));
96 if (!sway_assert(sway_surface, "Failed to allocate surface!")) { 109 if (!sway_assert(wl_shell_view, "Failed to allocate view")) {
97 return; 110 return;
98 } 111 }
99 112
100 struct sway_view *view = view_create(SWAY_VIEW_WL_SHELL, &view_impl); 113 view_init(&wl_shell_view->view, SWAY_VIEW_WL_SHELL, &view_impl);
101 if (!sway_assert(view, "Failed to allocate view")) { 114 wl_shell_view->view.wlr_wl_shell_surface = shell_surface;
102 return;
103 }
104 view->wlr_wl_shell_surface = shell_surface;
105 view->sway_wl_shell_surface = sway_surface;
106 sway_surface->view = view;
107 115
108 // TODO: 116 // TODO:
109 // - Wire up listeners 117 // - Wire up listeners
110 // - Handle popups
111 // - Look up pid and open on appropriate workspace 118 // - Look up pid and open on appropriate workspace
112 // - Set new view to maximized so it behaves nicely 119 // - Set new view to maximized so it behaves nicely
113 // - Criteria 120 // - Criteria
114 121
115 sway_surface->commit.notify = handle_commit; 122 wl_shell_view->commit.notify = handle_commit;
116 wl_signal_add(&shell_surface->surface->events.commit, 123 wl_signal_add(&shell_surface->surface->events.commit,
117 &sway_surface->commit); 124 &wl_shell_view->commit);
118 125
119 sway_surface->destroy.notify = handle_destroy; 126 wl_shell_view->destroy.notify = handle_destroy;
120 wl_signal_add(&shell_surface->events.destroy, &sway_surface->destroy); 127 wl_signal_add(&shell_surface->events.destroy, &wl_shell_view->destroy);
121 128
122 view_map(view, shell_surface->surface); 129 view_map(&wl_shell_view->view, shell_surface->surface);
123} 130}