summaryrefslogtreecommitdiffstats
path: root/sway/desktop/xdg_shell_v6.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/desktop/xdg_shell_v6.c')
-rw-r--r--sway/desktop/xdg_shell_v6.c67
1 files changed, 24 insertions, 43 deletions
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index cffe83fb..49305b39 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -30,23 +30,18 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) {
30 } 30 }
31} 31}
32 32
33static void set_size(struct sway_view *view, int width, int height) { 33static void configure(struct sway_view *view, double ox, double oy, int width,
34 int height) {
34 if (!assert_xdg(view)) { 35 if (!assert_xdg(view)) {
35 return; 36 return;
36 } 37 }
38
39 view_update_position(view, ox, oy);
37 view->sway_xdg_surface_v6->pending_width = width; 40 view->sway_xdg_surface_v6->pending_width = width;
38 view->sway_xdg_surface_v6->pending_height = height; 41 view->sway_xdg_surface_v6->pending_height = height;
39 wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height); 42 wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height);
40} 43}
41 44
42static void set_position(struct sway_view *view, double ox, double oy) {
43 if (!assert_xdg(view)) {
44 return;
45 }
46 view->swayc->x = ox;
47 view->swayc->y = oy;
48}
49
50static void set_activated(struct sway_view *view, bool activated) { 45static void set_activated(struct sway_view *view, bool activated) {
51 if (!assert_xdg(view)) { 46 if (!assert_xdg(view)) {
52 return; 47 return;
@@ -57,7 +52,7 @@ static void set_activated(struct sway_view *view, bool activated) {
57 } 52 }
58} 53}
59 54
60static void close(struct sway_view *view) { 55static void _close(struct sway_view *view) {
61 if (!assert_xdg(view)) { 56 if (!assert_xdg(view)) {
62 return; 57 return;
63 } 58 }
@@ -67,6 +62,13 @@ static void close(struct sway_view *view) {
67 } 62 }
68} 63}
69 64
65static const struct sway_view_impl view_impl = {
66 .get_prop = get_prop,
67 .configure = configure,
68 .set_activated = set_activated,
69 .close = _close,
70};
71
70static void handle_commit(struct wl_listener *listener, void *data) { 72static void handle_commit(struct wl_listener *listener, void *data) {
71 struct sway_xdg_surface_v6 *sway_surface = 73 struct sway_xdg_surface_v6 *sway_surface =
72 wl_container_of(listener, sway_surface, commit); 74 wl_container_of(listener, sway_surface, commit);
@@ -74,37 +76,22 @@ static void handle_commit(struct wl_listener *listener, void *data) {
74 // NOTE: We intentionally discard the view's desired width here 76 // NOTE: We intentionally discard the view's desired width here
75 // TODO: Store this for restoration when moving to floating plane 77 // TODO: Store this for restoration when moving to floating plane
76 // TODO: Let floating views do whatever 78 // TODO: Let floating views do whatever
77 view->width = sway_surface->pending_width; 79 view_update_size(view, sway_surface->pending_width,
78 view->height = sway_surface->pending_height; 80 sway_surface->pending_height);
79 view_damage_from(view); 81 view_damage_from(view);
80} 82}
81 83
82static void handle_unmap(struct wl_listener *listener, void *data) { 84static void handle_unmap(struct wl_listener *listener, void *data) {
83 struct sway_xdg_surface_v6 *sway_surface = 85 struct sway_xdg_surface_v6 *sway_surface =
84 wl_container_of(listener, sway_surface, unmap); 86 wl_container_of(listener, sway_surface, unmap);
85 view_damage_whole(sway_surface->view); 87 view_unmap(sway_surface->view);
86 container_view_destroy(sway_surface->view->swayc);
87 sway_surface->view->swayc = NULL;
88 sway_surface->view->surface = NULL;
89} 88}
90 89
91static void handle_map(struct wl_listener *listener, void *data) { 90static void handle_map(struct wl_listener *listener, void *data) {
92 struct sway_xdg_surface_v6 *sway_surface = 91 struct sway_xdg_surface_v6 *sway_surface =
93 wl_container_of(listener, sway_surface, map); 92 wl_container_of(listener, sway_surface, map);
94 struct sway_view *view = sway_surface->view; 93 struct sway_view *view = sway_surface->view;
95 94 view_map(view, view->wlr_xdg_surface_v6->surface);
96 sway_surface->view->surface = view->wlr_xdg_surface_v6->surface;
97
98 container_view_destroy(view->swayc);
99
100 struct sway_seat *seat = input_manager_current_seat(input_manager);
101 struct sway_container *focus = seat_get_focus_inactive(seat, &root_container);
102 struct sway_container *cont = container_view_create(focus, view);
103 view->swayc = cont;
104 arrange_windows(cont->parent, -1, -1);
105 input_manager_set_focus(input_manager, cont);
106
107 view_damage_whole(sway_surface->view);
108} 95}
109 96
110static void handle_destroy(struct wl_listener *listener, void *data) { 97static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -112,8 +99,9 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
112 wl_container_of(listener, sway_xdg_surface, destroy); 99 wl_container_of(listener, sway_xdg_surface, destroy);
113 wl_list_remove(&sway_xdg_surface->commit.link); 100 wl_list_remove(&sway_xdg_surface->commit.link);
114 wl_list_remove(&sway_xdg_surface->destroy.link); 101 wl_list_remove(&sway_xdg_surface->destroy.link);
115 container_view_destroy(sway_xdg_surface->view->swayc); 102 wl_list_remove(&sway_xdg_surface->map.link);
116 free(sway_xdg_surface->view); 103 wl_list_remove(&sway_xdg_surface->unmap.link);
104 view_destroy(sway_xdg_surface->view);
117 free(sway_xdg_surface); 105 free(sway_xdg_surface);
118} 106}
119 107
@@ -138,23 +126,16 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
138 return; 126 return;
139 } 127 }
140 128
141 struct sway_view *sway_view = calloc(1, sizeof(struct sway_view)); 129 struct sway_view *view = view_create(SWAY_XDG_SHELL_V6_VIEW, &view_impl);
142 if (!sway_assert(sway_view, "Failed to allocate view!")) { 130 if (!sway_assert(view, "Failed to allocate view")) {
143 return; 131 return;
144 } 132 }
145 sway_view->type = SWAY_XDG_SHELL_V6_VIEW; 133 view->wlr_xdg_surface_v6 = xdg_surface;
146 sway_view->iface.get_prop = get_prop; 134 view->sway_xdg_surface_v6 = sway_surface;
147 sway_view->iface.set_size = set_size; 135 sway_surface->view = view;
148 sway_view->iface.set_position = set_position;
149 sway_view->iface.set_activated = set_activated;
150 sway_view->iface.close = close;
151 sway_view->wlr_xdg_surface_v6 = xdg_surface;
152 sway_view->sway_xdg_surface_v6 = sway_surface;
153 sway_surface->view = sway_view;
154 136
155 // TODO: 137 // TODO:
156 // - Look up pid and open on appropriate workspace 138 // - Look up pid and open on appropriate workspace
157 // - Set new view to maximized so it behaves nicely
158 // - Criteria 139 // - Criteria
159 140
160 sway_surface->commit.notify = handle_commit; 141 sway_surface->commit.notify = handle_commit;