diff options
Diffstat (limited to 'sway/desktop/output.c')
-rw-r--r-- | sway/desktop/output.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 7eb48bdf..ad843b31 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -72,8 +72,7 @@ static void output_frame_view(swayc_t *view, void *data) { | |||
72 | } | 72 | } |
73 | 73 | ||
74 | static void output_frame_notify(struct wl_listener *listener, void *data) { | 74 | static void output_frame_notify(struct wl_listener *listener, void *data) { |
75 | struct sway_output *soutput = wl_container_of( | 75 | struct sway_output *soutput = wl_container_of(listener, soutput, frame); |
76 | listener, soutput, frame); | ||
77 | struct wlr_output *wlr_output = data; | 76 | struct wlr_output *wlr_output = data; |
78 | struct sway_server *server = soutput->server; | 77 | struct sway_server *server = soutput->server; |
79 | 78 | ||
@@ -92,40 +91,51 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { | |||
92 | soutput->last_frame = now; | 91 | soutput->last_frame = now; |
93 | } | 92 | } |
94 | 93 | ||
95 | static void output_resolution_notify(struct wl_listener *listener, void *data) { | ||
96 | struct sway_output *soutput = wl_container_of( | ||
97 | listener, soutput, resolution); | ||
98 | arrange_windows(soutput->swayc, -1, -1); | ||
99 | } | ||
100 | |||
101 | void output_add_notify(struct wl_listener *listener, void *data) { | 94 | void output_add_notify(struct wl_listener *listener, void *data) { |
102 | struct sway_server *server = wl_container_of(listener, server, output_add); | 95 | struct sway_server *server = wl_container_of(listener, server, output_add); |
103 | struct wlr_output *wlr_output = data; | 96 | struct wlr_output *wlr_output = data; |
104 | sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); | 97 | sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); |
105 | 98 | ||
106 | struct sway_output *output = calloc(1, sizeof(struct sway_output)); | 99 | struct sway_output *output = calloc(1, sizeof(struct sway_output)); |
100 | if (!output) { | ||
101 | return; | ||
102 | } | ||
107 | output->wlr_output = wlr_output; | 103 | output->wlr_output = wlr_output; |
108 | output->server = server; | 104 | output->server = server; |
109 | output->swayc = new_output(output); | ||
110 | 105 | ||
111 | if (wl_list_length(&wlr_output->modes) > 0) { | 106 | if (!wl_list_empty(&wlr_output->modes)) { |
112 | struct wlr_output_mode *mode = NULL; | 107 | struct wlr_output_mode *mode = |
113 | mode = wl_container_of((&wlr_output->modes)->prev, mode, link); | 108 | wl_container_of(wlr_output->modes.prev, mode, link); |
114 | wlr_output_set_mode(wlr_output, mode); | 109 | wlr_output_set_mode(wlr_output, mode); |
115 | } | 110 | } |
116 | 111 | ||
112 | output->swayc = new_output(output); | ||
113 | if (!output->swayc) { | ||
114 | free(output); | ||
115 | return; | ||
116 | } | ||
117 | |||
117 | output->frame.notify = output_frame_notify; | 118 | output->frame.notify = output_frame_notify; |
118 | wl_signal_add(&wlr_output->events.frame, &output->frame); | 119 | wl_signal_add(&wlr_output->events.frame, &output->frame); |
119 | |||
120 | output->resolution.notify = output_resolution_notify; | ||
121 | wl_signal_add(&wlr_output->events.resolution, &output->resolution); | ||
122 | |||
123 | arrange_windows(output->swayc, -1, -1); | ||
124 | } | 120 | } |
125 | 121 | ||
126 | void output_remove_notify(struct wl_listener *listener, void *data) { | 122 | void output_remove_notify(struct wl_listener *listener, void *data) { |
127 | struct sway_server *server = wl_container_of(listener, server, output_remove); | 123 | struct sway_server *server = wl_container_of(listener, server, output_remove); |
128 | struct wlr_output *wlr_output = data; | 124 | struct wlr_output *wlr_output = data; |
129 | sway_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); | 125 | sway_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); |
130 | // TODO | 126 | |
127 | swayc_t *output_container = NULL; | ||
128 | for (int i = 0 ; i < root_container.children->length; ++i) { | ||
129 | swayc_t *child = root_container.children->items[i]; | ||
130 | if (child->type == C_OUTPUT && | ||
131 | child->sway_output->wlr_output == wlr_output) { | ||
132 | output_container = child; | ||
133 | break; | ||
134 | } | ||
135 | } | ||
136 | if (!output_container) { | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | destroy_output(output_container); | ||
131 | } | 141 | } |