{
            {
                let widgets = widgets.clone();
                let server_entry = server_entry.clone();
                let server_addr_fallback = Rc::clone(&server_addr);
                let power_tx = power_tx.clone();
                let power_request_in_flight = Rc::clone(&power_request_in_flight);
                let power_auto_button = widgets.power_auto_button.clone();
                let widgets_handle = widgets.clone();
                power_auto_button.connect_clicked(move |_| {
                    if power_request_in_flight.replace(true) {
                        return;
                    }
                    let server_addr =
                        selected_server_addr(&server_entry, server_addr_fallback.as_ref());
                    widgets_handle
                        .status_label
                        .set_text("Returning capture feeds to automatic mode...");
                    request_capture_power_command(
                        power_tx.clone(),
                        server_addr,
                        CapturePowerCommand::Auto,
                    );
                });
            }

            {
                let server_entry = server_entry.clone();
                let server_addr_fallback = Rc::clone(&server_addr);
                let power_tx = power_tx.clone();
                let power_request_in_flight = Rc::clone(&power_request_in_flight);
                let power_on_button = widgets.power_on_button.clone();
                let widgets_handle = widgets.clone();
                power_on_button.connect_clicked(move |_| {
                    if power_request_in_flight.replace(true) {
                        return;
                    }
                    let server_addr =
                        selected_server_addr(&server_entry, server_addr_fallback.as_ref());
                    widgets_handle
                        .status_label
                        .set_text("Forcing capture feeds on for staging...");
                    request_capture_power_command(
                        power_tx.clone(),
                        server_addr,
                        CapturePowerCommand::ForceOn,
                    );
                });
            }

            {
                let server_entry = server_entry.clone();
                let server_addr_fallback = Rc::clone(&server_addr);
                let power_tx = power_tx.clone();
                let power_request_in_flight = Rc::clone(&power_request_in_flight);
                let power_off_button = widgets.power_off_button.clone();
                let widgets_handle = widgets.clone();
                power_off_button.connect_clicked(move |_| {
                    if power_request_in_flight.replace(true) {
                        return;
                    }
                    let server_addr =
                        selected_server_addr(&server_entry, server_addr_fallback.as_ref());
                    widgets_handle
                        .status_label
                        .set_text("Forcing capture feeds off for staging...");
                    request_capture_power_command(
                        power_tx.clone(),
                        server_addr,
                        CapturePowerCommand::ForceOff,
                    );
                });
            }

            for monitor_id in 0..2 {
                let app = app.clone();
                let preview = preview.clone();
                let state = Rc::clone(&state);
                let child_proc = Rc::clone(&child_proc);
                let popouts = Rc::clone(&popouts);
                let widgets = widgets.clone();
                let action_button = widgets.display_panes[monitor_id].action_button.clone();
                action_button.connect_clicked(move |_| {
                    let Some(preview) = preview.as_ref() else {
                        widgets
                            .status_label
                            .set_text("Preview is unavailable for breakout windows.");
                        return;
                    };
                    let surface = {
                        let state = state.borrow();
                        state.display_surface(monitor_id)
                    };
                    match surface {
                        DisplaySurface::Preview => {
                            open_popout_window(
                                &app,
                                preview,
                                &state,
                                &child_proc,
                                &popouts,
                                &widgets,
                                monitor_id,
                            );
                            widgets.status_label.set_text(&format!(
                                "{} moved into its own window.",
                                widgets.display_panes[monitor_id].title
                            ));
                        }
                        DisplaySurface::Window => {
                            dock_display_to_preview(
                                &state,
                                &child_proc,
                                &popouts,
                                &widgets,
                                monitor_id,
                            );
                            widgets.status_label.set_text(&format!(
                                "{} returned to the launcher preview.",
                                widgets.display_panes[monitor_id].title
                            ));
                        }
                    }
                });
            }

            {
                let state = Rc::clone(&state);
                let child_proc = Rc::clone(&child_proc);
                let widgets = widgets.clone();
                let input_toggle_control_path = Rc::clone(&input_toggle_control_path);
                let key_controller = gtk::EventControllerKey::new();
                key_controller.connect_key_pressed(move |_, key, _, _| {
                    if !state.borrow().swap_key_binding {
                        return glib::Propagation::Proceed;
                    }

                    let Some(swap_key) = capture_swap_key(key) else {
                        widgets.status_label.set_text(
                            "That key is not a good swap shortcut. Try a letter, digit, function key, or navigation key.",
                        );
                        refresh_launcher_ui(
                            &widgets,
                            &state.borrow(),
                            child_proc.borrow().is_some(),
                        );
                        return glib::Propagation::Stop;
                    };

                    let relay_live = child_proc.borrow().is_some() || state.borrow().remote_active;
                    {
                        let mut state = state.borrow_mut();
                        state.complete_swap_key_binding(swap_key.clone());
                    }
                    let status_message = if relay_live {
                        match write_input_toggle_key_request(
                            input_toggle_control_path.as_path(),
                            &swap_key,
                        ) {
                            Ok(()) => format!(
                                "Swap key set to {} and applied to the live relay.",
                                toggle_key_label(&swap_key)
                            ),
                            Err(err) => format!(
                                "Swap key set to {}, but Lesavka could not push it live: {err}",
                                toggle_key_label(&swap_key)
                            ),
                        }
                    } else {
                        format!(
                            "Swap key set to {}. The next relay launch will use it.",
                            toggle_key_label(&swap_key)
                        )
                    };
                    widgets.status_label.set_text(&status_message);
                    refresh_launcher_ui(&widgets, &state.borrow(), child_proc.borrow().is_some());
                    glib::Propagation::Stop
                });
                window.add_controller(key_controller);
            }
}
