diff options
author | emersion <contact@emersion.fr> | 2018-03-31 18:07:44 -0400 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-03-31 18:07:44 -0400 |
commit | 1d68f9ecca8870f2f2a6823072c77657436b123a (patch) | |
tree | d66fbfa54f5c20f77c640bb695e43c02f2364bc3 /sway/tree/view.c | |
parent | Introduce common functions to create, map, unmap, destroy views (diff) | |
download | sway-1d68f9ecca8870f2f2a6823072c77657436b123a.tar.gz sway-1d68f9ecca8870f2f2a6823072c77657436b123a.tar.zst sway-1d68f9ecca8870f2f2a6823072c77657436b123a.zip |
Add sway_view_impl
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r-- | sway/tree/view.c | 36 |
1 files changed, 19 insertions, 17 deletions
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 | ||