From ebad5ca50e11fc9d3fbbab397888d0944a825bb7 Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Thu, 17 Jul 2025 06:36:02 +0530 Subject: [PATCH] =?UTF-8?q?linux:=20Fix=20buttons=20clicks=20wouldn?= =?UTF-8?q?=E2=80=99t=20work=20on=20startup=20until=20clicked=20on=20cente?= =?UTF-8?q?r=20pane=20(#34590)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #31805 This is an issue with Linux currently that `window.focus` is `None` upon startup in both X11 and Wayland. Specifically, the order in which [this](https://github.com/zed-industries/zed/blob/8d05a3d389b6a1caa80bb18f26c3dac0c26debcb/crates/gpui/src/window.rs#L3116) and [this](https://github.com/zed-industries/zed/blob/8d05a3d389b6a1caa80bb18f26c3dac0c26debcb/crates/gpui/src/app.rs#L956) are executed varies between Linux and macOS. That is, one tries to remove (blur) focus from a window, while other checks window focus to put that focus id to a frame. In macOS, blur happens afterwards setting focus on a frame, but in Linux, the inverse of it happens, leading to `window.focus` to `None`. For the time being, we handle all visible buttons to take care of this **focus can be `None`** case, and make it work anyway. But, we should look at the deeper issue mentioned above with GPUI. Created new issue to track that https://github.com/zed-industries/zed/issues/34591. Release Notes: - Fixed an issue where button clicks wouldn’t work on startup until clicked on the center pane on Linux. --- crates/title_bar/src/title_bar.rs | 9 +++++---- crates/workspace/src/dock.rs | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/title_bar/src/title_bar.rs b/crates/title_bar/src/title_bar.rs index 453bb54db8..977b5c3ecd 100644 --- a/crates/title_bar/src/title_bar.rs +++ b/crates/title_bar/src/title_bar.rs @@ -22,9 +22,9 @@ use auto_update::AutoUpdateStatus; use call::ActiveCall; use client::{Client, UserStore}; use gpui::{ - Action, AnyElement, App, Context, Corner, Element, Entity, InteractiveElement, IntoElement, - MouseButton, ParentElement, Render, StatefulInteractiveElement, Styled, Subscription, - WeakEntity, Window, actions, div, + Action, AnyElement, App, Context, Corner, Element, Entity, Focusable, InteractiveElement, + IntoElement, MouseButton, ParentElement, Render, StatefulInteractiveElement, Styled, + Subscription, WeakEntity, Window, actions, div, }; use onboarding_banner::OnboardingBanner; use project::Project; @@ -504,7 +504,8 @@ impl TitleBar { ) }) .on_click(move |_, window, cx| { - let _ = workspace.update(cx, |_this, cx| { + let _ = workspace.update(cx, |this, cx| { + window.focus(&this.active_pane().focus_handle(cx)); window.dispatch_action(zed_actions::git::Branch.boxed_clone(), cx); }); }) diff --git a/crates/workspace/src/dock.rs b/crates/workspace/src/dock.rs index c8301dcf35..4e39c2d182 100644 --- a/crates/workspace/src/dock.rs +++ b/crates/workspace/src/dock.rs @@ -873,6 +873,8 @@ impl Render for PanelButtons { (action, icon_tooltip.into()) }; + let focus_handle = dock.focus_handle(cx); + Some( right_click_menu(name) .menu(move |window, cx| { @@ -909,6 +911,7 @@ impl Render for PanelButtons { .on_click({ let action = action.boxed_clone(); move |_, window, cx| { + window.focus(&focus_handle); window.dispatch_action(action.boxed_clone(), cx) } })