diff options
-rw-r--r-- | include/sway/tree/view.h | 31 | ||||
-rw-r--r-- | sway/desktop/wl_shell.c | 18 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 15 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 17 | ||||
-rw-r--r-- | sway/tree/view.c | 36 |
5 files changed, 63 insertions, 54 deletions
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 82a5541b..c68739d6 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h | |||
@@ -66,10 +66,23 @@ enum sway_view_prop { | |||
66 | VIEW_PROP_INSTANCE, | 66 | VIEW_PROP_INSTANCE, |
67 | }; | 67 | }; |
68 | 68 | ||
69 | struct sway_view_impl { | ||
70 | const char *(*get_prop)(struct sway_view *view, | ||
71 | enum sway_view_prop prop); | ||
72 | void (*set_size)(struct sway_view *view, | ||
73 | int width, int height); | ||
74 | void (*set_position)(struct sway_view *view, | ||
75 | double ox, double oy); | ||
76 | void (*set_activated)(struct sway_view *view, bool activated); | ||
77 | void (*close)(struct sway_view *view); | ||
78 | }; | ||
79 | |||
69 | struct sway_view { | 80 | struct sway_view { |
70 | enum sway_view_type type; | 81 | enum sway_view_type type; |
71 | struct sway_container *swayc; | 82 | const struct sway_view_impl *impl; |
72 | struct wlr_surface *surface; | 83 | |
84 | struct sway_container *swayc; // NULL for unmanaged views | ||
85 | struct wlr_surface *surface; // NULL for unmapped views | ||
73 | int width, height; | 86 | int width, height; |
74 | 87 | ||
75 | union { | 88 | union { |
@@ -84,22 +97,12 @@ struct sway_view { | |||
84 | struct sway_wl_shell_surface *sway_wl_shell_surface; | 97 | struct sway_wl_shell_surface *sway_wl_shell_surface; |
85 | }; | 98 | }; |
86 | 99 | ||
87 | struct { | ||
88 | const char *(*get_prop)(struct sway_view *view, | ||
89 | enum sway_view_prop prop); | ||
90 | void (*set_size)(struct sway_view *view, | ||
91 | int width, int height); | ||
92 | void (*set_position)(struct sway_view *view, | ||
93 | double ox, double oy); | ||
94 | void (*set_activated)(struct sway_view *view, bool activated); | ||
95 | void (*close)(struct sway_view *view); | ||
96 | } iface; | ||
97 | |||
98 | // only used for unmanaged views (shell specific) | 100 | // only used for unmanaged views (shell specific) |
99 | struct wl_list unmanaged_view_link; // sway_root::unmanaged_views | 101 | struct wl_list unmanaged_view_link; // sway_root::unmanaged_views |
100 | }; | 102 | }; |
101 | 103 | ||
102 | struct sway_view *view_create(enum sway_view_type type); | 104 | struct sway_view *view_create(enum sway_view_type type, |
105 | const struct sway_view_impl *impl); | ||
103 | 106 | ||
104 | void view_destroy(struct sway_view *view); | 107 | void view_destroy(struct sway_view *view); |
105 | 108 | ||
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index ab969b17..e0909a03 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c | |||
@@ -47,10 +47,6 @@ static void set_position(struct sway_view *view, double ox, double oy) { | |||
47 | view->swayc->y = oy; | 47 | view->swayc->y = oy; |
48 | } | 48 | } |
49 | 49 | ||
50 | static void set_activated(struct sway_view *view, bool activated) { | ||
51 | // no way to activate wl_shell | ||
52 | } | ||
53 | |||
54 | static void close(struct sway_view *view) { | 50 | static void close(struct sway_view *view) { |
55 | if (!assert_wl_shell(view)) { | 51 | if (!assert_wl_shell(view)) { |
56 | return; | 52 | return; |
@@ -59,6 +55,13 @@ static void close(struct sway_view *view) { | |||
59 | wl_client_destroy(view->wlr_wl_shell_surface->client); | 55 | wl_client_destroy(view->wlr_wl_shell_surface->client); |
60 | } | 56 | } |
61 | 57 | ||
58 | static const struct sway_view_impl view_impl = { | ||
59 | .get_prop = get_prop, | ||
60 | .set_size = set_size, | ||
61 | .set_position = set_position, | ||
62 | .close = close, | ||
63 | }; | ||
64 | |||
62 | static void handle_commit(struct wl_listener *listener, void *data) { | 65 | static void handle_commit(struct wl_listener *listener, void *data) { |
63 | struct sway_wl_shell_surface *sway_surface = | 66 | struct sway_wl_shell_surface *sway_surface = |
64 | wl_container_of(listener, sway_surface, commit); | 67 | wl_container_of(listener, sway_surface, commit); |
@@ -101,15 +104,10 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { | |||
101 | return; | 104 | return; |
102 | } | 105 | } |
103 | 106 | ||
104 | struct sway_view *view = view_create(SWAY_WL_SHELL_VIEW); | 107 | struct sway_view *view = view_create(SWAY_WL_SHELL_VIEW, &view_impl); |
105 | if (!sway_assert(view, "Failed to allocate view")) { | 108 | if (!sway_assert(view, "Failed to allocate view")) { |
106 | return; | 109 | return; |
107 | } | 110 | } |
108 | view->iface.get_prop = get_prop; | ||
109 | view->iface.set_size = set_size; | ||
110 | view->iface.set_position = set_position; | ||
111 | view->iface.set_activated = set_activated; | ||
112 | view->iface.close = close; | ||
113 | view->wlr_wl_shell_surface = shell_surface; | 111 | view->wlr_wl_shell_surface = shell_surface; |
114 | view->sway_wl_shell_surface = sway_surface; | 112 | view->sway_wl_shell_surface = sway_surface; |
115 | sway_surface->view = view; | 113 | sway_surface->view = view; |
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 77a35b13..c1adc7fe 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -67,6 +67,14 @@ static void close(struct sway_view *view) { | |||
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | static const struct sway_view_impl view_impl = { | ||
71 | .get_prop = get_prop, | ||
72 | .set_size = set_size, | ||
73 | .set_position = set_position, | ||
74 | .set_activated = set_activated, | ||
75 | .close = close, | ||
76 | }; | ||
77 | |||
70 | static void handle_commit(struct wl_listener *listener, void *data) { | 78 | static void handle_commit(struct wl_listener *listener, void *data) { |
71 | struct sway_xdg_surface_v6 *sway_surface = | 79 | struct sway_xdg_surface_v6 *sway_surface = |
72 | wl_container_of(listener, sway_surface, commit); | 80 | wl_container_of(listener, sway_surface, commit); |
@@ -124,15 +132,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { | |||
124 | return; | 132 | return; |
125 | } | 133 | } |
126 | 134 | ||
127 | struct sway_view *view = view_create(SWAY_XDG_SHELL_V6_VIEW); | 135 | struct sway_view *view = view_create(SWAY_XDG_SHELL_V6_VIEW, &view_impl); |
128 | if (!sway_assert(view, "Failed to allocate view")) { | 136 | if (!sway_assert(view, "Failed to allocate view")) { |
129 | return; | 137 | return; |
130 | } | 138 | } |
131 | view->iface.get_prop = get_prop; | ||
132 | view->iface.set_size = set_size; | ||
133 | view->iface.set_position = set_position; | ||
134 | view->iface.set_activated = set_activated; | ||
135 | view->iface.close = close; | ||
136 | view->wlr_xdg_surface_v6 = xdg_surface; | 139 | view->wlr_xdg_surface_v6 = xdg_surface; |
137 | view->sway_xdg_surface_v6 = sway_surface; | 140 | view->sway_xdg_surface_v6 = sway_surface; |
138 | sway_surface->view = view; | 141 | sway_surface->view = view; |
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index e1c2ad08..93c78228 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -81,13 +81,21 @@ static void set_activated(struct sway_view *view, bool activated) { | |||
81 | wlr_xwayland_surface_activate(surface, activated); | 81 | wlr_xwayland_surface_activate(surface, activated); |
82 | } | 82 | } |
83 | 83 | ||
84 | static void close_view(struct sway_view *view) { | 84 | static void _close(struct sway_view *view) { |
85 | if (!assert_xwayland(view)) { | 85 | if (!assert_xwayland(view)) { |
86 | return; | 86 | return; |
87 | } | 87 | } |
88 | wlr_xwayland_surface_close(view->wlr_xwayland_surface); | 88 | wlr_xwayland_surface_close(view->wlr_xwayland_surface); |
89 | } | 89 | } |
90 | 90 | ||
91 | static const struct sway_view_impl view_impl = { | ||
92 | .get_prop = get_prop, | ||
93 | .set_size = set_size, | ||
94 | .set_position = set_position, | ||
95 | .set_activated = set_activated, | ||
96 | .close = _close, | ||
97 | }; | ||
98 | |||
91 | static void handle_commit(struct wl_listener *listener, void *data) { | 99 | static void handle_commit(struct wl_listener *listener, void *data) { |
92 | struct sway_xwayland_surface *sway_surface = | 100 | struct sway_xwayland_surface *sway_surface = |
93 | wl_container_of(listener, sway_surface, commit); | 101 | wl_container_of(listener, sway_surface, commit); |
@@ -159,15 +167,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { | |||
159 | return; | 167 | return; |
160 | } | 168 | } |
161 | 169 | ||
162 | struct sway_view *view = view_create(SWAY_XWAYLAND_VIEW); | 170 | struct sway_view *view = view_create(SWAY_XWAYLAND_VIEW, &view_impl); |
163 | if (!sway_assert(view, "Failed to allocate view")) { | 171 | if (!sway_assert(view, "Failed to allocate view")) { |
164 | return; | 172 | return; |
165 | } | 173 | } |
166 | view->iface.get_prop = get_prop; | ||
167 | view->iface.set_size = set_size; | ||
168 | view->iface.set_position = set_position; | ||
169 | view->iface.set_activated = set_activated; | ||
170 | view->iface.close = close_view; | ||
171 | view->wlr_xwayland_surface = xsurface; | 174 | view->wlr_xwayland_surface = xsurface; |
172 | view->sway_xwayland_surface = sway_surface; | 175 | view->sway_xwayland_surface = sway_surface; |
173 | sway_surface->view = view; | 176 | sway_surface->view = view; |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 2950812a..d7a52e19 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -7,12 +7,14 @@ | |||
7 | #include "sway/tree/layout.h" | 7 | #include "sway/tree/layout.h" |
8 | #include "sway/tree/view.h" | 8 | #include "sway/tree/view.h" |
9 | 9 | ||
10 | struct sway_view *view_create(enum sway_view_type type) { | 10 | struct sway_view *view_create(enum sway_view_type type, |
11 | const struct sway_view_impl *impl) { | ||
11 | struct sway_view *view = calloc(1, sizeof(struct sway_view)); | 12 | struct sway_view *view = calloc(1, sizeof(struct sway_view)); |
12 | if (view == NULL) { | 13 | if (view == NULL) { |
13 | return NULL; | 14 | return NULL; |
14 | } | 15 | } |
15 | view->type = type; | 16 | view->type = type; |
17 | view->impl = impl; | ||
16 | wl_list_init(&view->unmanaged_view_link); | 18 | wl_list_init(&view->unmanaged_view_link); |
17 | return view; | 19 | return view; |
18 | } | 20 | } |
@@ -33,29 +35,29 @@ void view_destroy(struct sway_view *view) { | |||
33 | } | 35 | } |
34 | 36 | ||
35 | const char *view_get_title(struct sway_view *view) { | 37 | const char *view_get_title(struct sway_view *view) { |
36 | if (view->iface.get_prop) { | 38 | if (view->impl->get_prop) { |
37 | return view->iface.get_prop(view, VIEW_PROP_TITLE); | 39 | return view->impl->get_prop(view, VIEW_PROP_TITLE); |
38 | } | 40 | } |
39 | return NULL; | 41 | return NULL; |
40 | } | 42 | } |
41 | 43 | ||
42 | const char *view_get_app_id(struct sway_view *view) { | 44 | const char *view_get_app_id(struct sway_view *view) { |
43 | if (view->iface.get_prop) { | 45 | if (view->impl->get_prop) { |
44 | return view->iface.get_prop(view, VIEW_PROP_APP_ID); | 46 | return view->impl->get_prop(view, VIEW_PROP_APP_ID); |
45 | } | 47 | } |
46 | return NULL; | 48 | return NULL; |
47 | } | 49 | } |
48 | 50 | ||
49 | const char *view_get_class(struct sway_view *view) { | 51 | const char *view_get_class(struct sway_view *view) { |
50 | if (view->iface.get_prop) { | 52 | if (view->impl->get_prop) { |
51 | return view->iface.get_prop(view, VIEW_PROP_CLASS); | 53 | return view->impl->get_prop(view, VIEW_PROP_CLASS); |
52 | } | 54 | } |
53 | return NULL; | 55 | return NULL; |
54 | } | 56 | } |
55 | 57 | ||
56 | const char *view_get_instance(struct sway_view *view) { | 58 | const char *view_get_instance(struct sway_view *view) { |
57 | if (view->iface.get_prop) { | 59 | if (view->impl->get_prop) { |
58 | return view->iface.get_prop(view, VIEW_PROP_INSTANCE); | 60 | return view->impl->get_prop(view, VIEW_PROP_INSTANCE); |
59 | } | 61 | } |
60 | return NULL; | 62 | return NULL; |
61 | } | 63 | } |
@@ -86,41 +88,41 @@ static void view_update_outputs(struct sway_view *view, | |||
86 | } | 88 | } |
87 | 89 | ||
88 | void view_set_size(struct sway_view *view, int width, int height) { | 90 | void view_set_size(struct sway_view *view, int width, int height) { |
89 | if (view->iface.set_size) { | 91 | if (view->impl->set_size) { |
90 | struct wlr_box box = { | 92 | struct wlr_box box = { |
91 | .x = view->swayc->x, | 93 | .x = view->swayc->x, |
92 | .y = view->swayc->y, | 94 | .y = view->swayc->y, |
93 | .width = view->width, | 95 | .width = view->width, |
94 | .height = view->height, | 96 | .height = view->height, |
95 | }; | 97 | }; |
96 | view->iface.set_size(view, width, height); | 98 | view->impl->set_size(view, width, height); |
97 | view_update_outputs(view, &box); | 99 | view_update_outputs(view, &box); |
98 | } | 100 | } |
99 | } | 101 | } |
100 | 102 | ||
101 | // TODO make view coordinates in layout coordinates | 103 | // TODO make view coordinates in layout coordinates |
102 | void view_set_position(struct sway_view *view, double ox, double oy) { | 104 | void view_set_position(struct sway_view *view, double ox, double oy) { |
103 | if (view->iface.set_position) { | 105 | if (view->impl->set_position) { |
104 | struct wlr_box box = { | 106 | struct wlr_box box = { |
105 | .x = view->swayc->x, | 107 | .x = view->swayc->x, |
106 | .y = view->swayc->y, | 108 | .y = view->swayc->y, |
107 | .width = view->width, | 109 | .width = view->width, |
108 | .height = view->height, | 110 | .height = view->height, |
109 | }; | 111 | }; |
110 | view->iface.set_position(view, ox, oy); | 112 | view->impl->set_position(view, ox, oy); |
111 | view_update_outputs(view, &box); | 113 | view_update_outputs(view, &box); |
112 | } | 114 | } |
113 | } | 115 | } |
114 | 116 | ||
115 | void view_set_activated(struct sway_view *view, bool activated) { | 117 | void view_set_activated(struct sway_view *view, bool activated) { |
116 | if (view->iface.set_activated) { | 118 | if (view->impl->set_activated) { |
117 | view->iface.set_activated(view, activated); | 119 | view->impl->set_activated(view, activated); |
118 | } | 120 | } |
119 | } | 121 | } |
120 | 122 | ||
121 | void view_close(struct sway_view *view) { | 123 | void view_close(struct sway_view *view) { |
122 | if (view->iface.close) { | 124 | if (view->impl->close) { |
123 | view->iface.close(view); | 125 | view->impl->close(view); |
124 | } | 126 | } |
125 | } | 127 | } |
126 | 128 | ||