@@ -74,11 +74,16 @@ void wlm_mirror_init(ctx_t * ctx) {
7474
7575 ctx -> mirror .initialized = true;
7676
77+ // TODO: use wlm_mirror_target_parse
78+ // TODO: make wlm_mirror_target_parse implement finding output (or toplevel?) by region
79+ // TODO: only find and create target in a single place! (other place is opt parse)
7780 // finding target output
78- if (!wlm_opt_find_output (ctx , & ctx -> mirror .current_target , & ctx -> mirror .current_region )) {
81+ output_list_node_t * target_output = NULL ;
82+ if (!wlm_opt_find_output (ctx , & target_output , & ctx -> mirror .current_region )) {
7983 wlm_log_error ("mirror::init(): failed to find output\n" );
8084 wlm_exit_fail (ctx );
8185 }
86+ ctx -> mirror .current_target = wlm_mirror_target_create_output (ctx , target_output );
8287
8388 // update window title
8489 wlm_mirror_update_title (ctx );
@@ -201,7 +206,7 @@ void wlm_mirror_backend_init(ctx_t * ctx) {
201206void wlm_mirror_output_removed (ctx_t * ctx , output_list_node_t * node ) {
202207 if (!ctx -> mirror .initialized ) return ;
203208 if (ctx -> mirror .current_target == NULL ) return ;
204- if (ctx -> mirror .current_target != node ) return ;
209+ if (wlm_mirror_target_get_output_node ( ctx -> mirror .current_target ) != node ) return ;
205210
206211 wlm_log_error ("mirror::output_removed(): output disappeared, closing\n" );
207212 wlm_exit_fail (ctx );
@@ -228,14 +233,26 @@ static size_t specifier_str(ctx_t * ctx, char *dst, int n, specifier_t specifier
228233}
229234
230235static int format_title (ctx_t * ctx , char * * dst , char * fmt ) {
236+ uint32_t target_width = 0 ;
237+ uint32_t target_height = 0 ;
238+ const char * target_name = "" ;
239+
240+ // TODO: support for other target types
241+ output_list_node_t * output_node = wlm_mirror_target_get_output_node (ctx -> mirror .current_target );
242+ if (output_node != NULL ) {
243+ target_width = output_node -> width ;
244+ target_height = output_node -> height ;
245+ target_name = output_node -> name ;
246+ }
247+
231248 specifier_t replacements [] = {
232249 {"{x}" , 'd' , {.d = ctx -> mirror .current_region .x }},
233250 {"{y}" , 'd' , {.d = ctx -> mirror .current_region .y }},
234251 {"{width}" , 'd' , {.d = ctx -> mirror .current_region .width }},
235252 {"{height}" , 'd' , {.d = ctx -> mirror .current_region .height }},
236- {"{target_width}" , 'd' , {.d = ctx -> mirror . current_target -> width }},
237- {"{target_height}" , 'd' , {.d = ctx -> mirror . current_target -> height }},
238- {"{target_output}" , 's' , {.s = ctx -> mirror . current_target -> name }}
253+ {"{target_width}" , 'd' , {.d = target_width }},
254+ {"{target_height}" , 'd' , {.d = target_height }},
255+ {"{target_output}" , 's' , {.s = target_name }}
239256 };
240257
241258 size_t length = strlen (fmt );
@@ -321,6 +338,7 @@ void wlm_mirror_cleanup(ctx_t * ctx) {
321338
322339 wlm_log_debug (ctx , "mirror::cleanup(): destroying mirror objects\n" );
323340
341+ if (ctx -> mirror .current_target != NULL ) wlm_mirror_target_destroy (ctx -> mirror .current_target );
324342 if (ctx -> mirror .backend != NULL ) ctx -> mirror .backend -> do_cleanup (ctx );
325343 if (ctx -> mirror .frame_callback != NULL ) wl_callback_destroy (ctx -> mirror .frame_callback );
326344
0 commit comments