Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: refine tray picker fill, spacing, and flash

Ilya0003a1a88eef
diff --git a/apps/desktop-gpui/src/tray.rs b/apps/desktop-gpui/src/tray.rs
index 0d0cefd5c..ed8fa30dc 100644
--- a/apps/desktop-gpui/src/tray.rs
+++ b/apps/desktop-gpui/src/tray.rs
@@ -181,9 +181,9 @@ const ROW_ICON_SOURCES: &[(&str, &[u8])] = &[
/// `Entry::Item`'s `icon` size, and the raster size of every row glyph.
const ROW_ICON_SIZE: u32 = 32;
-/// The mode picker draws its icons at `SYMBOL_SIZE` points; rasterise at 4x so
-/// the downsample stays sharp on Retina displays.
-const PICKER_ICON_SIZE: u32 = 128;
+/// The mode picker draws its icons at 17 points. Rasterise at exactly 2x so
+/// the image maps 1:1 to device pixels on a Retina display.
+const PICKER_ICON_SIZE: u32 = 34;
/// An SVG rendered to a `size`×`size` PNG, scaled to fit and centred -- the
/// conversion `cap_mode_icon_png` makes at 90 for the palette, shared with the
@@ -576,10 +576,7 @@ pub fn build_menu(mode: Mode, previous: &[PreviousItem], version: &str) -> Vec<E
for target in [TargetType::Display, TargetType::Window, TargetType::Area] {
entries.push(capture_entry(target, mode));
}
- // macOS keeps the row in the menu and removes/inserts it in place; the
- // other platforms rebuild on a mode change and only need it in recording
- // modes. Keeping it on macOS also lets a dynamic mode switch add it back.
- if cfg!(target_os = "macos") || mode != Mode::Screenshot {
+ if mode != Mode::Screenshot {
entries.push(Entry::icon_item(
tr::tray::take_screenshot(),
TrayItem::TakeScreenshot,
@@ -1036,10 +1033,6 @@ mod mac {
static OPTION_HELD: Cell<bool> = const { Cell::new(false) };
static CURRENT_MODE: Cell<Option<Mode>> = const { Cell::new(None) };
static ROWS: RefCell<Vec<ActionRow>> = const { RefCell::new(Vec::new()) };
- static TAKE_SCREENSHOT: RefCell<Option<Retained<NSMenuItem>>> =
- const { RefCell::new(None) };
- static TAKE_SCREENSHOT_ANCHOR: RefCell<Option<Retained<NSMenuItem>>> =
- const { RefCell::new(None) };
static STATUS_ITEM: RefCell<Option<Retained<NSStatusItem>>> = const { RefCell::new(None) };
}
@@ -1345,9 +1338,6 @@ mod mac {
MainThreadMarker::new().expect("tray menu construction must run on the main thread");
menu.removeAllItems();
ROWS.with(|rows| rows.borrow_mut().clear());
- TAKE_SCREENSHOT.with(|item| *item.borrow_mut() = None);
- TAKE_SCREENSHOT_ANCHOR.with(|item| *item.borrow_mut() = None);
- let mut last_capture = None;
for entry in entries {
if let Entry::ModePicker { mode } = entry {
@@ -1389,24 +1379,11 @@ mod mac {
screenshot_accelerator,
});
});
- last_capture = Some(menu_item.clone());
menu.addItem(&menu_item);
continue;
}
let menu_item = build_ns_item(entry, target, actions, mtm);
- if matches!(
- entry,
- Entry::Item {
- item: Some(TrayItem::TakeScreenshot),
- ..
- }
- ) {
- TAKE_SCREENSHOT.with(|item| *item.borrow_mut() = Some(menu_item.clone()));
- TAKE_SCREENSHOT_ANCHOR.with(|anchor| {
- *anchor.borrow_mut() = last_capture.clone();
- });
- }
menu.addItem(&menu_item);
}
}
@@ -1480,35 +1457,6 @@ mod mac {
set_row_image(&row.item, item);
}
});
- TAKE_SCREENSHOT.with(|slot| {
- let slot = slot.borrow();
- let Some(item) = slot.as_ref() else {
- return;
- };
- TAKE_SCREENSHOT_ANCHOR.with(|anchor| {
- let anchor = anchor.borrow();
- let menu = unsafe { item.menu() }
- .or_else(|| anchor.as_ref().and_then(|item| unsafe { item.menu() }));
- let Some(menu) = menu else {
- return;
- };
- let index = menu.indexOfItem(item);
- if mode == Mode::Screenshot {
- if index >= 0 {
- menu.removeItemAtIndex(index);
- }
- return;
- }
- if index < 0 {
- let at = anchor
- .as_ref()
- .map(|item| menu.indexOfItem(item))
- .filter(|index| *index >= 0)
- .map_or(menu.numberOfItems(), |index| index + 1);
- menu.insertItem_atIndex(item, at);
- }
- });
- });
}
fn set_key_equivalent(item: &NSMenuItem, accelerator: Option<Accelerator>) {
@@ -2261,9 +2209,7 @@ mod tests {
"Screenshot Window",
]
);
- if !cfg!(target_os = "macos") {
- assert!(!titles.iter().any(|title| title == "Take a Screenshot"));
- }
+ assert!(!titles.iter().any(|title| title == "Take a Screenshot"));
}
#[test]
@@ -2445,13 +2391,7 @@ mod tests {
};
assert!(has(Mode::Studio));
assert!(has(Mode::Instant));
- if cfg!(target_os = "macos") {
- // Kept in the model and removed from the live menu in screenshot
- // mode, so it can be inserted again when the mode changes.
- assert!(has(Mode::Screenshot));
- } else {
- assert!(!has(Mode::Screenshot));
- }
+ assert!(!has(Mode::Screenshot));
}
#[test]
diff --git a/apps/desktop-gpui/src/tray/mac_mode_picker.rs b/apps/desktop-gpui/src/tray/mac_mode_picker.rs
index fe686a06e..b109cb1b5 100644
--- a/apps/desktop-gpui/src/tray/mac_mode_picker.rs
+++ b/apps/desktop-gpui/src/tray/mac_mode_picker.rs
@@ -17,8 +17,7 @@ use objc2_app_kit::{
NSEventTrackingRunLoopMode, NSEventType, NSFont, NSFontAttributeName, NSFontManager,
NSFontTraitMask, NSFontWeightSemibold, NSForegroundColorAttributeName, NSImage, NSImageScaling,
NSImageView, NSMenu, NSMenuItem, NSStringDrawing, NSTrackingArea, NSTrackingAreaOptions,
- NSView, NSVisualEffectBlendingMode, NSVisualEffectMaterial, NSVisualEffectState,
- NSVisualEffectView,
+ NSView,
};
use objc2_foundation::{
MainThreadMarker, NSData, NSDictionary, NSPoint, NSRect, NSRunLoop, NSSize, NSString, NSTimer,
@@ -47,8 +46,8 @@ const PILL_W: f64 = 38.0;
const PILL_H: f64 = 29.0;
const PILL_GAP: f64 = 4.0;
const CAPSULE_PAD: f64 = 3.0;
-const RIGHT_INSET: f64 = 30.0;
-const TITLE_INSET: f64 = 17.0;
+const RIGHT_INSET: f64 = 10.0;
+const TITLE_INSET: f64 = 10.0;
const LINE_GAP: f64 = 2.0;
const SYMBOL_SIZE: f64 = 17.0;
const PILL_RADIUS: f64 = 14.0;
@@ -70,7 +69,6 @@ struct PickerIvars {
tag_base: isize,
capsule: RefCell<Option<Retained<CALayer>>>,
pills: RefCell<Vec<Retained<CALayer>>>,
- selection: RefCell<Option<Retained<NSVisualEffectView>>>,
icons: RefCell<Vec<Retained<NSImageView>>>,
}
@@ -155,7 +153,6 @@ impl ModePickerView {
tag_base,
capsule: RefCell::new(None),
pills: RefCell::new(Vec::new()),
- selection: RefCell::new(None),
icons: RefCell::new(Vec::new()),
});
let frame = NSRect::new(NSPoint::new(0.0, 0.0), NSSize::new(PICKER_W, PICKER_H));
@@ -179,18 +176,6 @@ impl ModePickerView {
.push(make_layer(PILL_RADIUS));
}
- let selection = NSVisualEffectView::new(mtm);
- selection.setMaterial(NSVisualEffectMaterial::Selection);
- selection.setBlendingMode(NSVisualEffectBlendingMode::WithinWindow);
- selection.setState(NSVisualEffectState::Active);
- selection.setWantsLayer(true);
- if let Some(layer) = selection.layer() {
- layer.setCornerCurve(unsafe { kCACornerCurveContinuous });
- layer.setCornerRadius(PILL_RADIUS);
- }
- this.addSubview(&selection);
- *this.ivars().selection.borrow_mut() = Some(selection);
-
for (mode, _) in PICKER_MODES.iter() {
let view = NSImageView::new(mtm);
if let Some(bytes) = mode_picker_icon(*mode)
@@ -302,16 +287,15 @@ impl ModePickerView {
let white = NSColor::whiteColor();
let flash = self.ivars().flash.get();
let icons = self.ivars().icons.borrow();
- if let Some(selection) = self.ivars().selection.borrow().as_ref() {
- let r = self.pill_rect(selected);
- selection.setFrame(r);
- selection.setHidden(flash);
- }
for (i, pill) in self.ivars().pills.borrow().iter().enumerate() {
let is_sel = i == selected;
let is_hover = focused == Some(i) && !is_sel;
- let fill = if is_sel && flash {
- accent.clone()
+ let fill = if is_sel {
+ if flash {
+ accent.clone()
+ } else {
+ white.colorWithAlphaComponent(0.95)
+ }
} else if is_hover {
label.colorWithAlphaComponent(0.14)
} else {
@@ -353,17 +337,8 @@ impl ModePickerView {
.convertFont_toHaveTrait(&sub_font, NSFontTraitMask::ItalicFontMask);
}
- let flash = self.ivars().flash.get();
- let label = if flash {
- NSColor::controlAccentColor()
- } else {
- NSColor::labelColor()
- };
- let secondary = if flash {
- NSColor::controlAccentColor()
- } else {
- NSColor::secondaryLabelColor()
- };
+ let label = NSColor::labelColor();
+ let secondary = NSColor::secondaryLabelColor();
let title = NSString::from_str(PICKER_TITLE);
let subtitle = NSString::from_str(mode_name(PICKER_MODES[shown].0));
let title_attrs = NSDictionary::from_slices(