aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/view.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-03-31 17:49:40 -0400
committerLibravatar emersion <contact@emersion.fr>2018-03-31 17:49:40 -0400
commitb2c2ee693b6f1cdaeb204a1469c0fa1b775a498c (patch)
tree1fd4a806d0ab7ba780d5fb93acb741b9b1dc3f85 /sway/tree/view.c
parentMerge pull request #1684 from swaywm/follow-warp (diff)
downloadsway-b2c2ee693b6f1cdaeb204a1469c0fa1b775a498c.tar.gz
sway-b2c2ee693b6f1cdaeb204a1469c0fa1b775a498c.tar.zst
sway-b2c2ee693b6f1cdaeb204a1469c0fa1b775a498c.zip
Introduce common functions to create, map, unmap, destroy views
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r--sway/tree/view.c125
1 files changed, 101 insertions, 24 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c
index b7d1a41b..2950812a 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -1,3 +1,4 @@
1#include <stdlib.h>
1#include <wayland-server.h> 2#include <wayland-server.h>
2#include <wlr/types/wlr_output_layout.h> 3#include <wlr/types/wlr_output_layout.h>
3#include "log.h" 4#include "log.h"
@@ -6,6 +7,31 @@
6#include "sway/tree/layout.h" 7#include "sway/tree/layout.h"
7#include "sway/tree/view.h" 8#include "sway/tree/view.h"
8 9
10struct sway_view *view_create(enum sway_view_type type) {
11 struct sway_view *view = calloc(1, sizeof(struct sway_view));
12 if (view == NULL) {
13 return NULL;
14 }
15 view->type = type;
16 wl_list_init(&view->unmanaged_view_link);
17 return view;
18}
19
20void view_destroy(struct sway_view *view) {
21 if (view == NULL) {
22 return;
23 }
24
25 if (view->surface != NULL) {
26 view_unmap(view);
27 }
28 if (view->swayc != NULL) {
29 container_view_destroy(view->swayc);
30 }
31
32 free(view);
33}
34
9const char *view_get_title(struct sway_view *view) { 35const char *view_get_title(struct sway_view *view) {
10 if (view->iface.get_prop) { 36 if (view->iface.get_prop) {
11 return view->iface.get_prop(view, VIEW_PROP_TITLE); 37 return view->iface.get_prop(view, VIEW_PROP_TITLE);
@@ -34,6 +60,31 @@ const char *view_get_instance(struct sway_view *view) {
34 return NULL; 60 return NULL;
35} 61}
36 62
63static void view_update_outputs(struct sway_view *view,
64 const struct wlr_box *before) {
65 struct wlr_output_layout *output_layout =
66 root_container.sway_root->output_layout;
67 struct wlr_box box = {
68 .x = view->swayc->x,
69 .y = view->swayc->y,
70 .width = view->width,
71 .height = view->height,
72 };
73 struct wlr_output_layout_output *layout_output;
74 wl_list_for_each(layout_output, &output_layout->outputs, link) {
75 bool intersected = before != NULL && wlr_output_layout_intersects(
76 output_layout, layout_output->output, before);
77 bool intersects = wlr_output_layout_intersects(output_layout,
78 layout_output->output, &box);
79 if (intersected && !intersects) {
80 wlr_surface_send_leave(view->surface, layout_output->output);
81 }
82 if (!intersected && intersects) {
83 wlr_surface_send_enter(view->surface, layout_output->output);
84 }
85 }
86}
87
37void view_set_size(struct sway_view *view, int width, int height) { 88void view_set_size(struct sway_view *view, int width, int height) {
38 if (view->iface.set_size) { 89 if (view->iface.set_size) {
39 struct wlr_box box = { 90 struct wlr_box box = {
@@ -73,30 +124,6 @@ void view_close(struct sway_view *view) {
73 } 124 }
74} 125}
75 126
76void view_update_outputs(struct sway_view *view, const struct wlr_box *before) {
77 struct wlr_output_layout *output_layout =
78 root_container.sway_root->output_layout;
79 struct wlr_box box = {
80 .x = view->swayc->x,
81 .y = view->swayc->y,
82 .width = view->width,
83 .height = view->height,
84 };
85 struct wlr_output_layout_output *layout_output;
86 wl_list_for_each(layout_output, &output_layout->outputs, link) {
87 bool intersected = before != NULL && wlr_output_layout_intersects(
88 output_layout, layout_output->output, before);
89 bool intersects = wlr_output_layout_intersects(output_layout,
90 layout_output->output, &box);
91 if (intersected && !intersects) {
92 wlr_surface_send_leave(view->surface, layout_output->output);
93 }
94 if (!intersected && intersects) {
95 wlr_surface_send_enter(view->surface, layout_output->output);
96 }
97 }
98}
99
100struct sway_container *container_view_destroy(struct sway_container *view) { 127struct sway_container *container_view_destroy(struct sway_container *view) {
101 if (!view) { 128 if (!view) {
102 return NULL; 129 return NULL;
@@ -107,6 +134,56 @@ struct sway_container *container_view_destroy(struct sway_container *view) {
107 return parent; 134 return parent;
108} 135}
109 136
137void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
138 if (!sway_assert(view->surface == NULL, "cannot map mapped view")) {
139 return;
140 }
141
142 struct sway_seat *seat = input_manager_current_seat(input_manager);
143 struct sway_container *focus = sway_seat_get_focus_inactive(seat,
144 &root_container);
145 struct sway_container *cont = container_view_create(focus, view);
146
147 view->surface = wlr_surface;
148 view->swayc = cont;
149
150 arrange_windows(cont->parent, -1, -1);
151 sway_input_manager_set_focus(input_manager, cont);
152
153 view_damage_whole(view);
154}
155
156void view_map_unmanaged(struct sway_view *view,
157 struct wlr_surface *wlr_surface) {
158 if (!sway_assert(view->surface == NULL, "cannot map mapped view")) {
159 return;
160 }
161
162 view->surface = wlr_surface;
163 view->swayc = NULL;
164
165 wl_list_insert(&root_container.sway_root->unmanaged_views,
166 &view->unmanaged_view_link);
167
168 view_damage_whole(view);
169}
170
171void view_unmap(struct sway_view *view) {
172 if (!sway_assert(view->surface != NULL, "cannot unmap unmapped view")) {
173 return;
174 }
175
176 view_damage_whole(view);
177
178 wl_list_remove(&view->unmanaged_view_link);
179 wl_list_init(&view->unmanaged_view_link);
180
181 container_view_destroy(view->swayc);
182
183 view->swayc = NULL;
184 view->surface = NULL;
185}
186
110void view_damage_whole(struct sway_view *view) { 187void view_damage_whole(struct sway_view *view) {
111 struct sway_container *cont = NULL; 188 struct sway_container *cont = NULL;
112 for (int i = 0; i < root_container.children->length; ++i) { 189 for (int i = 0; i < root_container.children->length; ++i) {