Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/agent_ui/src/agent_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2567,11 +2567,13 @@ impl AgentPanel {
let settings = AgentSettings::get_global(cx);
match settings.notify_when_agent_waiting {
NotifyWhenAgentWaiting::PrimaryScreen => {
window.request_attention();
if let Some(primary) = cx.primary_display() {
self.pop_up_terminal_notification(terminal_id, &title, primary, window, cx);
}
}
NotifyWhenAgentWaiting::AllScreens => {
window.request_attention();
for screen in cx.displays() {
self.pop_up_terminal_notification(terminal_id, &title, screen, window, cx);
}
Expand Down
2 changes: 2 additions & 0 deletions crates/agent_ui/src/conversation_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,7 @@ impl ConversationView {

match settings.notify_when_agent_waiting {
NotifyWhenAgentWaiting::PrimaryScreen => {
window.request_attention();
if let Some(primary) = cx.primary_display() {
self.pop_up(
icon,
Expand All @@ -2699,6 +2700,7 @@ impl ConversationView {
}
}
NotifyWhenAgentWaiting::AllScreens => {
window.request_attention();
let caption = caption.into();
for screen in cx.displays() {
self.pop_up(
Expand Down
2 changes: 2 additions & 0 deletions crates/gpui/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ pub trait PlatformWindow: HasWindowHandle + HasDisplayHandle {
answers: &[PromptButton],
) -> Option<oneshot::Receiver<usize>>;
fn activate(&self);
/// Requests that the operating system draw attention to this window.
fn request_attention(&self) {}
fn is_active(&self) -> bool;
fn is_hovered(&self) -> bool;
fn background_appearance(&self) -> WindowBackgroundAppearance;
Expand Down
5 changes: 5 additions & 0 deletions crates/gpui/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5086,6 +5086,11 @@ impl Window {
self.platform_window.activate();
}

/// Requests that the operating system draw attention to this window.
pub fn request_attention(&self) {
self.platform_window.request_attention();
}

/// Minimize the current window at the platform level.
pub fn minimize_window(&self) {
self.platform_window.minimize();
Expand Down
2 changes: 2 additions & 0 deletions crates/gpui_linux/src/linux/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,8 @@ impl PlatformWindow for WaylandWindow {
}
}

fn request_attention(&self) {}

fn is_active(&self) -> bool {
self.borrow().active
}
Expand Down
29 changes: 28 additions & 1 deletion crates/gpui_linux/src/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use x11rb::{
connection::Connection,
cookie::{Cookie, VoidCookie},
errors::ConnectionError,
properties::WmSizeHints,
properties::{WmHints, WmSizeHints},
protocol::{
sync,
xinput::{self, ConnectionExt as _},
Expand Down Expand Up @@ -1482,6 +1482,33 @@ impl PlatformWindow for X11Window {
xcb_flush(&self.0.xcb);
}

fn request_attention(&self) {
if self.is_active() {
return;
}

let mut hints = WmHints::new();
match WmHints::get(&*self.0.xcb, self.0.x_window) {
Ok(cookie) => match cookie.reply() {
Ok(Some(existing_hints)) => hints = existing_hints,
Ok(None) => {}
Err(error) => {
log::debug!("failed to read X11 WM_HINTS before setting urgency: {error}")
}
},
Err(error) => {
log::debug!("failed to request X11 WM_HINTS before setting urgency: {error}")
}
}
hints.urgent = true;
check_reply(
|| "X11 ChangeProperty for WM_HINTS urgency failed.",
hints.set(&*self.0.xcb, self.0.x_window),
)
.log_err();
xcb_flush(&self.0.xcb);
}

fn is_active(&self) -> bool {
self.0.state.borrow().active
}
Expand Down
22 changes: 19 additions & 3 deletions crates/gpui_macos/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use block::ConcreteBlock;
use cocoa::{
appkit::{
NSAppKitVersionNumber, NSAppKitVersionNumber12_0, NSApplication, NSBackingStoreBuffered,
NSColor, NSEvent, NSEventModifierFlags, NSFilenamesPboardType, NSPasteboard, NSScreen,
NSView, NSViewHeightSizable, NSViewWidthSizable, NSVisualEffectMaterial,
NSVisualEffectState, NSVisualEffectView, NSWindow, NSWindowButton,
NSColor, NSEvent, NSEventModifierFlags, NSFilenamesPboardType, NSPasteboard,
NSRequestUserAttentionType, NSScreen, NSView, NSViewHeightSizable, NSViewWidthSizable,
NSVisualEffectMaterial, NSVisualEffectState, NSVisualEffectView, NSWindow, NSWindowButton,
NSWindowCollectionBehavior, NSWindowOcclusionState, NSWindowOrderingMode,
NSWindowStyleMask, NSWindowTitleVisibility,
},
Expand Down Expand Up @@ -1367,6 +1367,22 @@ impl PlatformWindow for MacWindow {
.detach();
}

fn request_attention(&self) {
if self.is_active() {
return;
}

let executor = self.0.lock().foreground_executor.clone();
executor
.spawn(async move {
unsafe {
let app = NSApplication::sharedApplication(nil);
app.requestUserAttention_(NSRequestUserAttentionType::NSInformationalRequest);
}
})
.detach();
}

fn is_active(&self) -> bool {
unsafe { self.0.lock().native_window.isKeyWindow() == YES }
}
Expand Down
21 changes: 21 additions & 0 deletions crates/gpui_windows/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,27 @@ impl PlatformWindow for WindowsWindow {
.detach();
}

fn request_attention(&self) {
if self.is_active() {
return;
}

let hwnd = self.0.hwnd;
self.0
.executor
.spawn(async move {
let info = FLASHWINFO {
cbSize: std::mem::size_of::<FLASHWINFO>() as u32,
hwnd,
dwFlags: FLASHW_ALL | FLASHW_TIMERNOFG,
uCount: 0,
dwTimeout: 0,
};
unsafe { FlashWindowEx(&info).ok().log_err() };
})
.detach();
}

fn is_active(&self) -> bool {
self.0.hwnd == unsafe { GetActiveWindow() }
}
Expand Down
Loading