Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: use the release point for tray mode selection

Ilyac01a3f8c631d
diff --git a/apps/desktop-gpui/src/tray.rs b/apps/desktop-gpui/src/tray.rs
index 07759f849..233c67147 100644
--- a/apps/desktop-gpui/src/tray.rs
+++ b/apps/desktop-gpui/src/tray.rs
@@ -989,7 +989,8 @@ mod mac {
use objc2_foundation::{MainThreadMarker, NSData, NSRunLoop, NSString, NSTimer};
use super::mac_mode_picker::{
- append_mode_picker, clear_hover, clear_hover_unless, install_key_hook, stop_flash,
+ append_mode_picker, clear_hover, clear_hover_unless, hover_from_pointer, install_key_hook,
+ stop_flash,
};
use super::{
Accelerator, Entry, PREVIOUS_SYMBOL, PreviousItem, STOP_ICON, TrayItem,
@@ -1078,6 +1079,7 @@ mod mac {
fn menu_will_open(&self, _menu: &NSMenu) {
MENU_OPEN.with(|o| o.set(true));
clear_hover();
+ hover_from_pointer();
start_option_tracking();
}
diff --git a/apps/desktop-gpui/src/tray/mac_mode_picker.rs b/apps/desktop-gpui/src/tray/mac_mode_picker.rs
index 84458af3b..912fb3e51 100644
--- a/apps/desktop-gpui/src/tray/mac_mode_picker.rs
+++ b/apps/desktop-gpui/src/tray/mac_mode_picker.rs
@@ -99,7 +99,6 @@ impl PillAccessibilityElement {
struct PickerIvars {
selected: Cell<usize>,
focused: Cell<Option<usize>>,
- pressed: Cell<Option<usize>>,
flash: Cell<bool>,
/// `actions` index of the first pill; pill `i` posts `tag_base + i`.
tag_base: isize,
@@ -177,16 +176,13 @@ define_class!(
}
#[unsafe(method(mouseDown:))]
- fn mouse_down(&self, event: &NSEvent) {
- // Only remember the press. The selection and the commit happen
- // together on mouse-up, so a release that never reaches this view
- // cannot leave the picker showing an unapplied mode.
- self.ivars().pressed.set(self.pill_at(event));
- }
+ fn mouse_down(&self, _event: &NSEvent) {}
#[unsafe(method(mouseUp:))]
- fn mouse_up(&self, _event: &NSEvent) {
- if let Some(i) = self.ivars().pressed.take() {
+ fn mouse_up(&self, event: &NSEvent) {
+ // The release point chooses the pill; a release outside the menu
+ // changes nothing, so the shown and applied modes stay in sync.
+ if let Some(i) = self.pill_at(event) {
self.choose(i);
}
}
@@ -204,7 +200,6 @@ impl ModePickerView {
let this = mtm.alloc::<Self>().set_ivars(PickerIvars {
selected: Cell::new(selected),
focused: Cell::new(None),
- pressed: Cell::new(None),
flash: Cell::new(false),
tag_base,
capsule: RefCell::new(None),
@@ -319,7 +314,10 @@ impl ModePickerView {
}
fn pill_at(&self, event: &NSEvent) -> Option<usize> {
- let p = self.convertPoint_fromView(event.locationInWindow(), None);
+ self.pill_at_point(self.convertPoint_fromView(event.locationInWindow(), None))
+ }
+
+ fn pill_at_point(&self, p: NSPoint) -> Option<usize> {
(0..PICKER_MODES.len()).find(|&i| {
let r = self.pill_rect(i);
p.x >= r.origin.x - PILL_GAP / 2.0
@@ -329,6 +327,18 @@ impl ModePickerView {
})
}
+ fn hover_from_pointer(&self) {
+ let Some(window) = self.window() else {
+ return;
+ };
+ let point = self.convertPoint_fromView(window.mouseLocationOutsideOfEventStream(), None);
+ let hit = self.pill_at_point(point);
+ if self.ivars().focused.get() != hit {
+ self.ivars().focused.set(hit);
+ self.refresh();
+ }
+ }
+
// -- state -> visuals --------------------------------------------------
/// Layers and icons for the current state, then the text.
@@ -553,6 +563,14 @@ pub(super) fn clear_hover() {
});
}
+pub(super) fn hover_from_pointer() {
+ PICKER.with(|p| {
+ if let Some((_, view)) = p.borrow().as_ref() {
+ view.hover_from_pointer();
+ }
+ });
+}
+
pub(super) fn stop_flash() {
FLASH_TIMER.with(|slot| {
if let Some(timer) = slot.borrow_mut().take() {
diff --git a/apps/desktop-gpui/src/updates.rs b/apps/desktop-gpui/src/updates.rs
index cf24d93b6..5936d4fd7 100644
--- a/apps/desktop-gpui/src/updates.rs
+++ b/apps/desktop-gpui/src/updates.rs
@@ -283,11 +283,12 @@ fn harness_update_version() -> Option<Version> {
#[cfg(debug_assertions)]
fn simulate_update(version: Version, cx: &mut App) {
+ tracing::info!(%version, "CAP_GPUI_AUTO_UPDATE: simulating update");
+ set_status(UpdateStatus::Checking, cx);
cx.spawn(async move |cx| {
cx.background_executor()
- .timer(Duration::from_millis(400))
+ .timer(Duration::from_millis(600))
.await;
- cx.update(|cx| set_status(UpdateStatus::Checking, cx));
for step in 0..=10u8 {
cx.background_executor()
.timer(Duration::from_millis(120))
@@ -302,7 +303,10 @@ fn simulate_update(version: Version, cx: &mut App) {
);
});
}
- cx.update(|cx| set_status(UpdateStatus::Ready { version }, cx));
+ cx.update(|cx| {
+ tracing::info!(%version, "CAP_GPUI_AUTO_UPDATE: ready");
+ set_status(UpdateStatus::Ready { version }, cx);
+ });
})
.detach();
}
@@ -324,6 +328,10 @@ pub(crate) fn schedule_startup_check(cx: &mut App) {
simulate_update(version, cx);
return;
}
+ #[cfg(not(debug_assertions))]
+ if std::env::var_os("CAP_GPUI_AUTO_UPDATE").is_some() {
+ tracing::warn!("CAP_GPUI_AUTO_UPDATE is ignored in release builds");
+ }
cx.spawn(async move |cx| {
let mut channel = cx