@@ -1169,12 +1169,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
11691169 container_destroy (output -> swayc );
11701170 }
11711171
1172- if (& output -> link ) {
1173- wl_list_remove (& output -> link );
1174- wl_list_remove (& output -> destroy .link );
1175- output -> wlr_output = NULL ;
1176- free (output );
1177- }
1172+ wl_list_remove (& output -> link );
1173+ wl_list_remove (& output -> destroy .link );
1174+ output -> wlr_output -> data = NULL ;
1175+ free (output );
11781176}
11791177
11801178static void handle_mode (struct wl_listener * listener , void * data ) {
@@ -1212,10 +1210,13 @@ void handle_new_output(struct wl_listener *listener, void *data) {
12121210 output -> wlr_output = wlr_output ;
12131211 wlr_output -> data = output ;
12141212 output -> server = server ;
1215- wl_list_insert (& root_container .sway_root -> outputs , & output -> link );
1216-
12171213 output -> damage = wlr_output_damage_create (wlr_output );
12181214
1215+ wl_signal_add (& wlr_output -> events .destroy , & output -> destroy );
1216+ output -> destroy .notify = handle_destroy ;
1217+
1218+ wl_list_insert (& root_container .sway_root -> outputs , & output -> link );
1219+
12191220 if (!wl_list_empty (& wlr_output -> modes )) {
12201221 struct wlr_output_mode * mode =
12211222 wl_container_of (wlr_output -> modes .prev , mode , link );
@@ -1228,6 +1229,10 @@ void handle_new_output(struct wl_listener *listener, void *data) {
12281229void output_enable (struct sway_output * output ) {
12291230 struct wlr_output * wlr_output = output -> wlr_output ;
12301231
1232+ if (!sway_assert (output -> swayc == NULL , "output is already enabled" )) {
1233+ return ;
1234+ }
1235+
12311236 output -> swayc = output_create (output );
12321237 if (!output -> swayc ) {
12331238 // Output is disabled
@@ -1241,8 +1246,6 @@ void output_enable(struct sway_output *output) {
12411246
12421247 input_manager_configure_xcursor (input_manager );
12431248
1244- wl_signal_add (& wlr_output -> events .destroy , & output -> destroy );
1245- output -> destroy .notify = handle_destroy ;
12461249 wl_signal_add (& wlr_output -> events .mode , & output -> mode );
12471250 output -> mode .notify = handle_mode ;
12481251 wl_signal_add (& wlr_output -> events .transform , & output -> transform );
0 commit comments