feat(settings): appearance section with color schemes and app icon
- Settings > Appearance and accessibility (Teams nav position), Rusty-only rows - Color scheme: registry of ColorScheme tables (Rusty Teams, Teams dark from Fluent teamsDarkTheme), switches live - App icon: Rusty Teams / Microsoft Teams (Teams favicon as shipped), title bar, window (WM_SETICON, X11 _NET_WM_ICON) and tray switch at runtime - Both stored locally in store meta appearance.settings, not in the Teams account - Nav groups scroll so About stays pinned at 640x480 with the extra section - Deviation: Teams' own Theme dropdown (light/dark/high contrast) not built, dark only Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -0,0 +1,151 @@
1
use store::Store;
2
3
use crate::theme::{self, ColorScheme};
4
5
const META_KEY: &str = "appearance.settings";
6
const COLOR_SCHEME_KEY: &str = "color_scheme";
7
const APP_ICON_KEY: &str = "app_icon";
8
const RUSTY_TEAMS_ICON_PNG: &[u8] = include_bytes!("../../app/assets/icon/teams-fast-256.png");
9
const MICROSOFT_TEAMS_ICON_PNG: &[u8] =
10
include_bytes!("../../app/assets/icon/microsoft-teams-256.png");
11
12
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
13
pub enum AppIcon {
14
#[default]
15
RustyTeams,
16
MicrosoftTeams,
17
}
18
19
impl AppIcon {
20
pub const ALL: [AppIcon; 2] = [AppIcon::RustyTeams, AppIcon::MicrosoftTeams];
21
22
pub fn key(self) -> &'static str {
23
match self {
24
AppIcon::RustyTeams => "rusty-teams",
25
AppIcon::MicrosoftTeams => "microsoft-teams",
26
}
27
}
28
29
pub fn from_key(key: &str) -> Option<AppIcon> {
30
AppIcon::ALL.into_iter().find(|icon| icon.key() == key)
31
}
32
33
pub fn label(self) -> &'static str {
34
match self {
35
AppIcon::RustyTeams => "Rusty Teams",
36
AppIcon::MicrosoftTeams => "Microsoft Teams",
37
}
38
}
39
40
pub fn png(self) -> &'static [u8] {
41
match self {
42
AppIcon::RustyTeams => RUSTY_TEAMS_ICON_PNG,
43
AppIcon::MicrosoftTeams => MICROSOFT_TEAMS_ICON_PNG,
44
}
45
}
46
}
47
48
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
49
pub struct AppearanceSettings {
50
pub color_scheme: &'static ColorScheme,
51
pub app_icon: AppIcon,
52
}
53
54
impl Default for AppearanceSettings {
55
fn default() -> Self {
56
AppearanceSettings {
57
color_scheme: theme::default_scheme(),
58
app_icon: AppIcon::default(),
59
}
60
}
61
}
62
63
pub fn load(store: &Store) -> AppearanceSettings {
64
store
65
.meta(META_KEY)
66
.ok()
67
.flatten()
68
.map(|text| parse(&text))
69
.unwrap_or_default()
70
}
71
72
pub fn save(store: &Store, settings: &AppearanceSettings) {
73
let _ = store.set_meta(META_KEY, &serialize(settings));
74
}
75
76
fn serialize(settings: &AppearanceSettings) -> String {
77
format!(
78
"{COLOR_SCHEME_KEY}={}\n{APP_ICON_KEY}={}",
79
settings.color_scheme.id,
80
settings.app_icon.key()
81
)
82
}
83
84
fn parse(text: &str) -> AppearanceSettings {
85
let mut settings = AppearanceSettings::default();
86
for line in text.lines() {
87
match line.split_once('=') {
88
Some((COLOR_SCHEME_KEY, value)) => {
89
if let Some(scheme) = theme::scheme_by_id(value) {
90
settings.color_scheme = scheme;
91
}
92
}
93
Some((APP_ICON_KEY, value)) => {
94
if let Some(icon) = AppIcon::from_key(value) {
95
settings.app_icon = icon;
96
}
97
}
98
_ => {}
99
}
100
}
101
settings
102
}
103
104
#[cfg(test)]
105
mod tests {
106
use super::*;
107
108
#[test]
109
fn defaults_are_the_rusty_teams_look() {
110
let settings = AppearanceSettings::default();
111
assert_eq!(settings.color_scheme.id, "rusty-teams");
112
assert_eq!(settings.app_icon, AppIcon::RustyTeams);
113
}
114
115
#[test]
116
fn round_trips_every_field() {
117
let settings = AppearanceSettings {
118
color_scheme: theme::SCHEMES[1],
119
app_icon: AppIcon::MicrosoftTeams,
120
};
121
assert_eq!(parse(&serialize(&settings)), settings);
122
}
123
124
#[test]
125
fn unknown_values_fall_back_to_defaults() {
126
assert_eq!(parse(""), AppearanceSettings::default());
127
assert_eq!(
128
parse("color_scheme=solarized\napp_icon=clippy\njunk"),
129
AppearanceSettings::default()
130
);
131
}
132
133
#[test]
134
fn persists_in_store() {
135
let store = Store::open_in_memory().unwrap();
136
assert_eq!(load(&store), AppearanceSettings::default());
137
let changed = AppearanceSettings {
138
color_scheme: theme::scheme_by_id("teams").unwrap(),
139
app_icon: AppIcon::MicrosoftTeams,
140
};
141
save(&store, &changed);
142
assert_eq!(load(&store), changed);
143
}
144
145
#[test]
146
fn both_icons_are_png() {
147
for icon in AppIcon::ALL {
148
assert!(icon.png().starts_with(b"\x89PNG"), "{}", icon.key());
149
}
150
}
151
}
@@ -0,0 +1,151 @@1
use store::Store;2
3
use crate::theme::{self, ColorScheme};4
5
const META_KEY: &str = "appearance.settings";6
const COLOR_SCHEME_KEY: &str = "color_scheme";7
const APP_ICON_KEY: &str = "app_icon";8
const RUSTY_TEAMS_ICON_PNG: &[u8] = include_bytes!("../../app/assets/icon/teams-fast-256.png");9
const MICROSOFT_TEAMS_ICON_PNG: &[u8] =10
include_bytes!("../../app/assets/icon/microsoft-teams-256.png");11
12
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]13
pub enum AppIcon {14
#[default]15
RustyTeams,16
MicrosoftTeams,17
}18
19
impl AppIcon {20
pub const ALL: [AppIcon; 2] = [AppIcon::RustyTeams, AppIcon::MicrosoftTeams];21
22
pub fn key(self) -> &'static str {23
match self {24
AppIcon::RustyTeams => "rusty-teams",25
AppIcon::MicrosoftTeams => "microsoft-teams",26
}27
}28
29
pub fn from_key(key: &str) -> Option<AppIcon> {30
AppIcon::ALL.into_iter().find(|icon| icon.key() == key)31
}32
33
pub fn label(self) -> &'static str {34
match self {35
AppIcon::RustyTeams => "Rusty Teams",36
AppIcon::MicrosoftTeams => "Microsoft Teams",37
}38
}39
40
pub fn png(self) -> &'static [u8] {41
match self {42
AppIcon::RustyTeams => RUSTY_TEAMS_ICON_PNG,43
AppIcon::MicrosoftTeams => MICROSOFT_TEAMS_ICON_PNG,44
}45
}46
}47
48
#[derive(Debug, Clone, Copy, PartialEq, Eq)]49
pub struct AppearanceSettings {50
pub color_scheme: &'static ColorScheme,51
pub app_icon: AppIcon,52
}53
54
impl Default for AppearanceSettings {55
fn default() -> Self {56
AppearanceSettings {57
color_scheme: theme::default_scheme(),58
app_icon: AppIcon::default(),59
}60
}61
}62
63
pub fn load(store: &Store) -> AppearanceSettings {64
store65
.meta(META_KEY)66
.ok()67
.flatten()68
.map(|text| parse(&text))69
.unwrap_or_default()70
}71
72
pub fn save(store: &Store, settings: &AppearanceSettings) {73
let _ = store.set_meta(META_KEY, &serialize(settings));74
}75
76
fn serialize(settings: &AppearanceSettings) -> String {77
format!(78
"{COLOR_SCHEME_KEY}={}\n{APP_ICON_KEY}={}",79
settings.color_scheme.id,80
settings.app_icon.key()81
)82
}83
84
fn parse(text: &str) -> AppearanceSettings {85
let mut settings = AppearanceSettings::default();86
for line in text.lines() {87
match line.split_once('=') {88
Some((COLOR_SCHEME_KEY, value)) => {89
if let Some(scheme) = theme::scheme_by_id(value) {90
settings.color_scheme = scheme;91
}92
}93
Some((APP_ICON_KEY, value)) => {94
if let Some(icon) = AppIcon::from_key(value) {95
settings.app_icon = icon;96
}97
}98
_ => {}99
}100
}101
settings102
}103
104
#[cfg(test)]105
mod tests {106
use super::*;107
108
#[test]109
fn defaults_are_the_rusty_teams_look() {110
let settings = AppearanceSettings::default();111
assert_eq!(settings.color_scheme.id, "rusty-teams");112
assert_eq!(settings.app_icon, AppIcon::RustyTeams);113
}114
115
#[test]116
fn round_trips_every_field() {117
let settings = AppearanceSettings {118
color_scheme: theme::SCHEMES[1],119
app_icon: AppIcon::MicrosoftTeams,120
};121
assert_eq!(parse(&serialize(&settings)), settings);122
}123
124
#[test]125
fn unknown_values_fall_back_to_defaults() {126
assert_eq!(parse(""), AppearanceSettings::default());127
assert_eq!(128
parse("color_scheme=solarized\napp_icon=clippy\njunk"),129
AppearanceSettings::default()130
);131
}132
133
#[test]134
fn persists_in_store() {135
let store = Store::open_in_memory().unwrap();136
assert_eq!(load(&store), AppearanceSettings::default());137
let changed = AppearanceSettings {138
color_scheme: theme::scheme_by_id("teams").unwrap(),139
app_icon: AppIcon::MicrosoftTeams,140
};141
save(&store, &changed);142
assert_eq!(load(&store), changed);143
}144
145
#[test]146
fn both_icons_are_png() {147
for icon in AppIcon::ALL {148
assert!(icon.png().starts_with(b"\x89PNG"), "{}", icon.key());149
}150
}151
}@@ -1,4 +1,5 @@
1
1
pub mod agent_api;
2
pub mod appearance;
2
3
pub mod agents;
3
4
pub mod assets;
4
5
pub mod avatar_image;
@@ -1,4 +1,5 @@1
pub mod agent_api;1
pub mod agent_api;2
pub mod appearance;2
pub mod agents;3
pub mod agents;3
pub mod assets;4
pub mod assets;4
pub mod avatar_image;5
pub mod avatar_image;@@ -42,6 +42,14 @@ pub fn make_window_click_through(window: &Window) {
42
42
#[cfg(not(target_os = "linux"))]
43
43
pub fn make_window_click_through(_window: &Window) {}
44
44
45
#[cfg(target_os = "linux")]
46
pub fn set_window_icon(window: &Window, png: &[u8]) {
47
super::x11_input::set_window_icon(window, png);
48
}
49
50
#[cfg(not(target_os = "linux"))]
51
pub fn set_window_icon(_window: &Window, _png: &[u8]) {}
52
45
53
pub fn window_minimized(_handle: NativeHandle) -> bool {
46
54
false
47
55
}
@@ -77,10 +85,12 @@ pub fn play_mp3_until(_bytes: Vec<u8>, _looped: bool, _stop: Arc<AtomicBool>) {}
77
85
pub struct Tray;
78
86
79
87
impl Tray {
80
pub fn new(_sound_on: bool, _do_not_disturb: bool) -> Option<Self> {
88
pub fn new(_sound_on: bool, _do_not_disturb: bool, _icon_png: &[u8]) -> Option<Self> {
81
89
None
82
90
}
83
91
92
pub fn set_app_icon(&mut self, _icon_png: &[u8], _mention: bool) {}
93
84
94
pub fn poll(&self) -> Vec<TrayCommand> {
85
95
Vec::new()
86
96
}
@@ -42,6 +42,14 @@ pub fn make_window_click_through(window: &Window) {42
#[cfg(not(target_os = "linux"))]42
#[cfg(not(target_os = "linux"))]43
pub fn make_window_click_through(_window: &Window) {}43
pub fn make_window_click_through(_window: &Window) {}44
44
45
#[cfg(target_os = "linux")]46
pub fn set_window_icon(window: &Window, png: &[u8]) {47
super::x11_input::set_window_icon(window, png);48
}49
50
#[cfg(not(target_os = "linux"))]51
pub fn set_window_icon(_window: &Window, _png: &[u8]) {}52
45
pub fn window_minimized(_handle: NativeHandle) -> bool {53
pub fn window_minimized(_handle: NativeHandle) -> bool {46
false54
false47
}55
}@@ -77,10 +85,12 @@ pub fn play_mp3_until(_bytes: Vec<u8>, _looped: bool, _stop: Arc<AtomicBool>) {}77
pub struct Tray;85
pub struct Tray;78
86
79
impl Tray {87
impl Tray {80
pub fn new(_sound_on: bool, _do_not_disturb: bool) -> Option<Self> {88
pub fn new(_sound_on: bool, _do_not_disturb: bool, _icon_png: &[u8]) -> Option<Self> {81
None89
None82
}90
}83
91
92
pub fn set_app_icon(&mut self, _icon_png: &[u8], _mention: bool) {}93
84
pub fn poll(&self) -> Vec<TrayCommand> {94
pub fn poll(&self) -> Vec<TrayCommand> {85
Vec::new()95
Vec::new()86
}96
}@@ -9,7 +9,7 @@ use gpui_kit::Window;
9
9
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
10
10
use tray_icon::menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem};
11
11
use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};
12
use windows::Win32::Foundation::{COLORREF, HWND, POINT, RECT};
12
use windows::Win32::Foundation::{COLORREF, HWND, LPARAM, POINT, RECT, WPARAM};
13
13
use windows::Win32::Graphics::Dwm::{
14
14
DWMWA_BORDER_COLOR, DWMWA_CLOAKED, DWMWA_COLOR_NONE, DWMWA_EXTENDED_FRAME_BOUNDS,
15
15
DWMWA_WINDOW_CORNER_PREFERENCE, DWMWCP_DONOTROUND, DwmGetWindowAttribute,
@@ -29,13 +29,13 @@ use windows::Win32::UI::Shell::{
29
29
use windows::Win32::UI::WindowsAndMessaging::{
30
30
CreateIconIndirect, DestroyIcon, FLASHW_STOP, FLASHW_TIMERNOFG, FLASHW_TRAY, FLASHWINFO,
31
31
FlashWindowEx, GW_HWNDPREV, GWL_EXSTYLE, GWL_STYLE, GetWindow, GetWindowLongPtrW,
32
GetWindowRect, HICON, HWND_NOTOPMOST, HWND_TOPMOST, ICONINFO, IsIconic, IsWindowVisible,
33
LWA_ALPHA, SPI_GETCLIENTAREAANIMATION, SW_HIDE, SW_RESTORE, SW_SHOW, SW_SHOWNOACTIVATE,
34
SWP_FRAMECHANGED, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE, SWP_NOZORDER,
35
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow, SetLayeredWindowAttributes,
36
SetWindowDisplayAffinity, SetWindowLongPtrW, SetWindowPos, ShowWindow, SystemParametersInfoW,
37
WDA_EXCLUDEFROMCAPTURE, WS_CAPTION, WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOPMOST,
38
WS_EX_TRANSPARENT, WS_POPUP, WS_THICKFRAME,
32
GetWindowRect, HICON, HWND_NOTOPMOST, HWND_TOPMOST, ICON_BIG, ICON_SMALL, ICONINFO, IsIconic,
33
IsWindowVisible, LWA_ALPHA, SPI_GETCLIENTAREAANIMATION, SW_HIDE, SW_RESTORE, SW_SHOW,
34
SW_SHOWNOACTIVATE, SWP_FRAMECHANGED, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,
35
SWP_NOZORDER, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SendMessageW, SetForegroundWindow,
36
SetLayeredWindowAttributes, SetWindowDisplayAffinity, SetWindowLongPtrW, SetWindowPos,
37
ShowWindow, SystemParametersInfoW, WDA_EXCLUDEFROMCAPTURE, WM_SETICON, WS_CAPTION,
38
WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOPMOST, WS_EX_TRANSPARENT, WS_POPUP, WS_THICKFRAME,
39
39
};
40
40
use windows::core::{BOOL, PCWSTR, w};
41
41
@@ -44,8 +44,9 @@ use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};
44
44
use crate::notify::badge::{BADGE_SIZE, Badge, render_badge};
45
45
46
46
const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");
47
const TRAY_ICON_PNG: &[u8] = include_bytes!("../../../../app/assets/icon/teams-fast-256.png");
48
47
const TRAY_ICON_SIZE: u32 = 32;
48
const WINDOW_ICON_SIZE: f32 = 32.;
49
const WINDOW_SMALL_ICON_SIZE: f32 = 16.;
49
50
const TRAY_DOT_RADIUS: f32 = 6.;
50
51
const BASE_DPI: f32 = 96.;
51
52
const RING_POLL: Duration = Duration::from_millis(20);
@@ -490,16 +491,19 @@ pub fn set_badge(handle: NativeHandle, badge: Option<&Badge>) {
490
491
}
491
492
492
493
unsafe fn icon_from_badge(badge: &Badge) -> Option<HICON> {
493
let pixels = render_badge(badge);
494
unsafe { icon_from_bgra(&render_badge(badge), BADGE_SIZE) }
495
}
496
497
unsafe fn icon_from_bgra(pixels: &[u8], size: u32) -> Option<HICON> {
494
498
unsafe {
495
499
let color = CreateBitmap(
496
BADGE_SIZE as i32,
497
BADGE_SIZE as i32,
500
size as i32,
501
size as i32,
498
502
1,
499
503
32,
500
504
Some(pixels.as_ptr() as *const c_void),
501
505
);
502
let mask = CreateBitmap(BADGE_SIZE as i32, BADGE_SIZE as i32, 1, 1, None);
506
let mask = CreateBitmap(size as i32, size as i32, 1, 1, None);
503
507
let info = ICONINFO {
504
508
fIcon: BOOL(1),
505
509
xHotspot: 0,
@@ -514,6 +518,44 @@ unsafe fn icon_from_badge(badge: &Badge) -> Option<HICON> {
514
518
}
515
519
}
516
520
521
pub fn set_window_icon(window: &Window, png: &[u8]) {
522
let Some(handle) = native_handle(window) else {
523
return;
524
};
525
let Ok(decoded) = image::load_from_memory(png) else {
526
return;
527
};
528
let dpi = unsafe { GetDpiForWindow(hwnd(handle)) };
529
let scale = if dpi == 0 { 1. } else { dpi as f32 / BASE_DPI };
530
for (kind, base_size) in [
531
(ICON_BIG, WINDOW_ICON_SIZE),
532
(ICON_SMALL, WINDOW_SMALL_ICON_SIZE),
533
] {
534
let size = (base_size * scale).round() as u32;
535
let mut pixels = decoded
536
.resize_exact(size, size, image::imageops::FilterType::Lanczos3)
537
.to_rgba8()
538
.into_raw();
539
for pixel in pixels.chunks_exact_mut(4) {
540
pixel.swap(0, 2);
541
}
542
unsafe {
543
let Some(icon) = icon_from_bgra(&pixels, size) else {
544
continue;
545
};
546
let previous = SendMessageW(
547
hwnd(handle),
548
WM_SETICON,
549
Some(WPARAM(kind as usize)),
550
Some(LPARAM(icon.0 as isize)),
551
);
552
if previous.0 != 0 {
553
let _ = DestroyIcon(HICON(previous.0 as *mut c_void));
554
}
555
}
556
}
557
}
558
517
559
pub fn play_mp3_until(bytes: Vec<u8>, looped: bool, stop: Arc<AtomicBool>) {
518
560
std::thread::spawn(move || {
519
561
let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
@@ -577,8 +619,8 @@ pub struct Tray {
577
619
}
578
620
579
621
impl Tray {
580
pub fn new(sound_on: bool, do_not_disturb: bool) -> Option<Self> {
581
let (plain, with_dot) = tray_icons()?;
622
pub fn new(sound_on: bool, do_not_disturb: bool, icon_png: &[u8]) -> Option<Self> {
623
let (plain, with_dot) = tray_icons(icon_png)?;
582
624
let open = MenuItem::with_id(ID_OPEN, "Open", true, None);
583
625
let sound = CheckMenuItem::with_id(ID_SOUND, "Mute sound", true, !sound_on, None);
584
626
let dnd = CheckMenuItem::with_id(
@@ -643,6 +685,16 @@ impl Tray {
643
685
commands
644
686
}
645
687
688
pub fn set_app_icon(&mut self, icon_png: &[u8], mention: bool) {
689
let Some((plain, with_dot)) = tray_icons(icon_png) else {
690
return;
691
};
692
self.plain = plain;
693
self.with_dot = with_dot;
694
let icon = if mention { &self.with_dot } else { &self.plain };
695
let _ = self.icon.set_icon(Some(icon.clone()));
696
}
697
646
698
pub fn sync(&self, sound_on: bool, do_not_disturb: bool, mention: bool) {
647
699
self.sound.set_checked(!sound_on);
648
700
self.do_not_disturb.set_checked(do_not_disturb);
@@ -651,8 +703,8 @@ impl Tray {
651
703
}
652
704
}
653
705
654
fn tray_icons() -> Option<(Icon, Icon)> {
655
let decoded = image::load_from_memory(TRAY_ICON_PNG).ok()?;
706
fn tray_icons(icon_png: &[u8]) -> Option<(Icon, Icon)> {
707
let decoded = image::load_from_memory(icon_png).ok()?;
656
708
let resized = decoded
657
709
.resize_exact(
658
710
TRAY_ICON_SIZE,
@@ -9,7 +9,7 @@ use gpui_kit::Window;9
use raw_window_handle::{HasWindowHandle, RawWindowHandle};9
use raw_window_handle::{HasWindowHandle, RawWindowHandle};10
use tray_icon::menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem};10
use tray_icon::menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem};11
use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};11
use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};12
use windows::Win32::Foundation::{COLORREF, HWND, POINT, RECT};12
use windows::Win32::Foundation::{COLORREF, HWND, LPARAM, POINT, RECT, WPARAM};13
use windows::Win32::Graphics::Dwm::{13
use windows::Win32::Graphics::Dwm::{14
DWMWA_BORDER_COLOR, DWMWA_CLOAKED, DWMWA_COLOR_NONE, DWMWA_EXTENDED_FRAME_BOUNDS,14
DWMWA_BORDER_COLOR, DWMWA_CLOAKED, DWMWA_COLOR_NONE, DWMWA_EXTENDED_FRAME_BOUNDS,15
DWMWA_WINDOW_CORNER_PREFERENCE, DWMWCP_DONOTROUND, DwmGetWindowAttribute,15
DWMWA_WINDOW_CORNER_PREFERENCE, DWMWCP_DONOTROUND, DwmGetWindowAttribute,@@ -29,13 +29,13 @@ use windows::Win32::UI::Shell::{29
use windows::Win32::UI::WindowsAndMessaging::{29
use windows::Win32::UI::WindowsAndMessaging::{30
CreateIconIndirect, DestroyIcon, FLASHW_STOP, FLASHW_TIMERNOFG, FLASHW_TRAY, FLASHWINFO,30
CreateIconIndirect, DestroyIcon, FLASHW_STOP, FLASHW_TIMERNOFG, FLASHW_TRAY, FLASHWINFO,31
FlashWindowEx, GW_HWNDPREV, GWL_EXSTYLE, GWL_STYLE, GetWindow, GetWindowLongPtrW,31
FlashWindowEx, GW_HWNDPREV, GWL_EXSTYLE, GWL_STYLE, GetWindow, GetWindowLongPtrW,32
GetWindowRect, HICON, HWND_NOTOPMOST, HWND_TOPMOST, ICONINFO, IsIconic, IsWindowVisible,32
GetWindowRect, HICON, HWND_NOTOPMOST, HWND_TOPMOST, ICON_BIG, ICON_SMALL, ICONINFO, IsIconic,33
LWA_ALPHA, SPI_GETCLIENTAREAANIMATION, SW_HIDE, SW_RESTORE, SW_SHOW, SW_SHOWNOACTIVATE,33
IsWindowVisible, LWA_ALPHA, SPI_GETCLIENTAREAANIMATION, SW_HIDE, SW_RESTORE, SW_SHOW,34
SWP_FRAMECHANGED, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE, SWP_NOZORDER,34
SW_SHOWNOACTIVATE, SWP_FRAMECHANGED, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,35
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow, SetLayeredWindowAttributes,35
SWP_NOZORDER, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SendMessageW, SetForegroundWindow,36
SetWindowDisplayAffinity, SetWindowLongPtrW, SetWindowPos, ShowWindow, SystemParametersInfoW,36
SetLayeredWindowAttributes, SetWindowDisplayAffinity, SetWindowLongPtrW, SetWindowPos,37
WDA_EXCLUDEFROMCAPTURE, WS_CAPTION, WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOPMOST,37
ShowWindow, SystemParametersInfoW, WDA_EXCLUDEFROMCAPTURE, WM_SETICON, WS_CAPTION,38
WS_EX_TRANSPARENT, WS_POPUP, WS_THICKFRAME,38
WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOPMOST, WS_EX_TRANSPARENT, WS_POPUP, WS_THICKFRAME,39
};39
};40
use windows::core::{BOOL, PCWSTR, w};40
use windows::core::{BOOL, PCWSTR, w};41
41
@@ -44,8 +44,9 @@ use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};44
use crate::notify::badge::{BADGE_SIZE, Badge, render_badge};44
use crate::notify::badge::{BADGE_SIZE, Badge, render_badge};45
45
46
const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");46
const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");47
const TRAY_ICON_PNG: &[u8] = include_bytes!("../../../../app/assets/icon/teams-fast-256.png");48
const TRAY_ICON_SIZE: u32 = 32;47
const TRAY_ICON_SIZE: u32 = 32;48
const WINDOW_ICON_SIZE: f32 = 32.;49
const WINDOW_SMALL_ICON_SIZE: f32 = 16.;49
const TRAY_DOT_RADIUS: f32 = 6.;50
const TRAY_DOT_RADIUS: f32 = 6.;50
const BASE_DPI: f32 = 96.;51
const BASE_DPI: f32 = 96.;51
const RING_POLL: Duration = Duration::from_millis(20);52
const RING_POLL: Duration = Duration::from_millis(20);@@ -490,16 +491,19 @@ pub fn set_badge(handle: NativeHandle, badge: Option<&Badge>) {490
}491
}491
492
492
unsafe fn icon_from_badge(badge: &Badge) -> Option<HICON> {493
unsafe fn icon_from_badge(badge: &Badge) -> Option<HICON> {493
let pixels = render_badge(badge);494
unsafe { icon_from_bgra(&render_badge(badge), BADGE_SIZE) }495
}496
497
unsafe fn icon_from_bgra(pixels: &[u8], size: u32) -> Option<HICON> {494
unsafe {498
unsafe {495
let color = CreateBitmap(499
let color = CreateBitmap(496
BADGE_SIZE as i32,500
size as i32,497
BADGE_SIZE as i32,501
size as i32,498
1,502
1,499
32,503
32,500
Some(pixels.as_ptr() as *const c_void),504
Some(pixels.as_ptr() as *const c_void),501
);505
);502
let mask = CreateBitmap(BADGE_SIZE as i32, BADGE_SIZE as i32, 1, 1, None);506
let mask = CreateBitmap(size as i32, size as i32, 1, 1, None);503
let info = ICONINFO {507
let info = ICONINFO {504
fIcon: BOOL(1),508
fIcon: BOOL(1),505
xHotspot: 0,509
xHotspot: 0,@@ -514,6 +518,44 @@ unsafe fn icon_from_badge(badge: &Badge) -> Option<HICON> {514
}518
}515
}519
}516
520
521
pub fn set_window_icon(window: &Window, png: &[u8]) {522
let Some(handle) = native_handle(window) else {523
return;524
};525
let Ok(decoded) = image::load_from_memory(png) else {526
return;527
};528
let dpi = unsafe { GetDpiForWindow(hwnd(handle)) };529
let scale = if dpi == 0 { 1. } else { dpi as f32 / BASE_DPI };530
for (kind, base_size) in [531
(ICON_BIG, WINDOW_ICON_SIZE),532
(ICON_SMALL, WINDOW_SMALL_ICON_SIZE),533
] {534
let size = (base_size * scale).round() as u32;535
let mut pixels = decoded536
.resize_exact(size, size, image::imageops::FilterType::Lanczos3)537
.to_rgba8()538
.into_raw();539
for pixel in pixels.chunks_exact_mut(4) {540
pixel.swap(0, 2);541
}542
unsafe {543
let Some(icon) = icon_from_bgra(&pixels, size) else {544
continue;545
};546
let previous = SendMessageW(547
hwnd(handle),548
WM_SETICON,549
Some(WPARAM(kind as usize)),550
Some(LPARAM(icon.0 as isize)),551
);552
if previous.0 != 0 {553
let _ = DestroyIcon(HICON(previous.0 as *mut c_void));554
}555
}556
}557
}558
517
pub fn play_mp3_until(bytes: Vec<u8>, looped: bool, stop: Arc<AtomicBool>) {559
pub fn play_mp3_until(bytes: Vec<u8>, looped: bool, stop: Arc<AtomicBool>) {518
std::thread::spawn(move || {560
std::thread::spawn(move || {519
let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {561
let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {@@ -577,8 +619,8 @@ pub struct Tray {577
}619
}578
620
579
impl Tray {621
impl Tray {580
pub fn new(sound_on: bool, do_not_disturb: bool) -> Option<Self> {622
pub fn new(sound_on: bool, do_not_disturb: bool, icon_png: &[u8]) -> Option<Self> {581
let (plain, with_dot) = tray_icons()?;623
let (plain, with_dot) = tray_icons(icon_png)?;582
let open = MenuItem::with_id(ID_OPEN, "Open", true, None);624
let open = MenuItem::with_id(ID_OPEN, "Open", true, None);583
let sound = CheckMenuItem::with_id(ID_SOUND, "Mute sound", true, !sound_on, None);625
let sound = CheckMenuItem::with_id(ID_SOUND, "Mute sound", true, !sound_on, None);584
let dnd = CheckMenuItem::with_id(626
let dnd = CheckMenuItem::with_id(@@ -643,6 +685,16 @@ impl Tray {643
commands685
commands644
}686
}645
687
688
pub fn set_app_icon(&mut self, icon_png: &[u8], mention: bool) {689
let Some((plain, with_dot)) = tray_icons(icon_png) else {690
return;691
};692
self.plain = plain;693
self.with_dot = with_dot;694
let icon = if mention { &self.with_dot } else { &self.plain };695
let _ = self.icon.set_icon(Some(icon.clone()));696
}697
646
pub fn sync(&self, sound_on: bool, do_not_disturb: bool, mention: bool) {698
pub fn sync(&self, sound_on: bool, do_not_disturb: bool, mention: bool) {647
self.sound.set_checked(!sound_on);699
self.sound.set_checked(!sound_on);648
self.do_not_disturb.set_checked(do_not_disturb);700
self.do_not_disturb.set_checked(do_not_disturb);@@ -651,8 +703,8 @@ impl Tray {651
}703
}652
}704
}653
705
654
fn tray_icons() -> Option<(Icon, Icon)> {706
fn tray_icons(icon_png: &[u8]) -> Option<(Icon, Icon)> {655
let decoded = image::load_from_memory(TRAY_ICON_PNG).ok()?;707
let decoded = image::load_from_memory(icon_png).ok()?;656
let resized = decoded708
let resized = decoded657
.resize_exact(709
.resize_exact(658
TRAY_ICON_SIZE,710
TRAY_ICON_SIZE,@@ -1,8 +1,12 @@
1
1
use gpui_kit::Window;
2
2
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
3
use x11rb::connection::Connection as _;
3
4
use x11rb::protocol::shape::{ConnectionExt as _, SK, SO};
4
use x11rb::protocol::xproto::ClipOrdering;
5
use x11rb::protocol::xproto::{AtomEnum, ClipOrdering, ConnectionExt as _, PropMode};
5
6
use x11rb::rust_connection::RustConnection;
7
use x11rb::wrapper::ConnectionExt as _;
8
9
const WINDOW_ICON_SIZES: [u32; 3] = [32, 64, 128];
6
10
7
11
fn x11_window_id(window: &Window) -> Option<u32> {
8
12
match HasWindowHandle::window_handle(window).ok()?.as_raw() {
@@ -26,6 +30,42 @@ pub fn make_input_transparent(window: &Window) {
26
30
}
27
31
}
28
32
33
pub fn window_icon_property(png: &[u8]) -> Option<Vec<u32>> {
34
let decoded = image::load_from_memory(png).ok()?;
35
let mut property = Vec::new();
36
for size in WINDOW_ICON_SIZES {
37
let resized = decoded
38
.resize_exact(size, size, image::imageops::FilterType::Lanczos3)
39
.to_rgba8();
40
property.extend([size, size]);
41
property.extend(resized.pixels().map(|pixel| {
42
let [red, green, blue, alpha] = pixel.0;
43
u32::from_le_bytes([blue, green, red, alpha])
44
}));
45
}
46
Some(property)
47
}
48
49
pub fn write_window_icon(
50
display: Option<&str>,
51
window: u32,
52
property: &[u32],
53
) -> Result<(), Box<dyn std::error::Error>> {
54
let (connection, _) = RustConnection::connect(display)?;
55
let atom = connection.intern_atom(false, b"_NET_WM_ICON")?.reply()?.atom;
56
connection
57
.change_property32(PropMode::REPLACE, window, atom, AtomEnum::CARDINAL, property)?
58
.check()?;
59
connection.flush()?;
60
Ok(())
61
}
62
63
pub fn set_window_icon(window: &Window, png: &[u8]) {
64
if let (Some(id), Some(property)) = (x11_window_id(window), window_icon_property(png)) {
65
let _ = write_window_icon(None, id, &property);
66
}
67
}
68
29
69
#[cfg(test)]
30
70
mod tests {
31
71
use std::io::{BufRead, BufReader};
@@ -34,7 +74,7 @@ mod tests {
34
74
use std::time::Duration;
35
75
36
76
use x11rb::connection::Connection;
37
use x11rb::protocol::xproto::{ConnectionExt as _, CreateWindowAux, WindowClass};
77
use x11rb::protocol::xproto::{CreateWindowAux, WindowClass};
38
78
use x11rb::COPY_DEPTH_FROM_PARENT;
39
79
40
80
use super::*;
@@ -90,4 +130,41 @@ mod tests {
90
130
let after = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();
91
131
assert!(after.rectangles.is_empty());
92
132
}
133
134
#[test]
135
fn the_window_icon_property_holds_every_size_in_argb() {
136
let png = crate::appearance::AppIcon::MicrosoftTeams.png();
137
let property = window_icon_property(png).unwrap();
138
let expected: usize = WINDOW_ICON_SIZES
139
.iter()
140
.map(|size| 2 + (size * size) as usize)
141
.sum();
142
assert_eq!(property.len(), expected);
143
assert_eq!(&property[..2], &[32, 32]);
144
assert!(window_icon_property(b"not a png").is_none());
145
}
146
147
#[test]
148
fn the_window_icon_lands_in_net_wm_icon() {
149
let Some((_server, display)) = start_server() else {
150
return;
151
};
152
let (connection, screen_number) = RustConnection::connect(Some(&display)).unwrap();
153
let root = connection.setup().roots[screen_number].root;
154
let window = connection.generate_id().unwrap();
155
connection
156
.create_window(COPY_DEPTH_FROM_PARENT, window, root, 0, 0, 100, 100, 0, WindowClass::INPUT_OUTPUT, 0, &CreateWindowAux::new())
157
.unwrap();
158
connection.flush().unwrap();
159
let property = window_icon_property(crate::appearance::AppIcon::RustyTeams.png()).unwrap();
160
write_window_icon(Some(&display), window, &property).unwrap();
161
let atom = connection.intern_atom(false, b"_NET_WM_ICON").unwrap().reply().unwrap().atom;
162
let reply = connection
163
.get_property(false, window, atom, AtomEnum::CARDINAL, 0, u32::MAX)
164
.unwrap()
165
.reply()
166
.unwrap();
167
let stored: Vec<u32> = reply.value32().unwrap().collect();
168
assert_eq!(stored, property);
169
}
93
170
}
@@ -1,8 +1,12 @@1
use gpui_kit::Window;1
use gpui_kit::Window;2
use raw_window_handle::{HasWindowHandle, RawWindowHandle};2
use raw_window_handle::{HasWindowHandle, RawWindowHandle};3
use x11rb::connection::Connection as _;3
use x11rb::protocol::shape::{ConnectionExt as _, SK, SO};4
use x11rb::protocol::shape::{ConnectionExt as _, SK, SO};4
use x11rb::protocol::xproto::ClipOrdering;5
use x11rb::protocol::xproto::{AtomEnum, ClipOrdering, ConnectionExt as _, PropMode};5
use x11rb::rust_connection::RustConnection;6
use x11rb::rust_connection::RustConnection;7
use x11rb::wrapper::ConnectionExt as _;8
9
const WINDOW_ICON_SIZES: [u32; 3] = [32, 64, 128];6
10
7
fn x11_window_id(window: &Window) -> Option<u32> {11
fn x11_window_id(window: &Window) -> Option<u32> {8
match HasWindowHandle::window_handle(window).ok()?.as_raw() {12
match HasWindowHandle::window_handle(window).ok()?.as_raw() {@@ -26,6 +30,42 @@ pub fn make_input_transparent(window: &Window) {26
}30
}27
}31
}28
32
33
pub fn window_icon_property(png: &[u8]) -> Option<Vec<u32>> {34
let decoded = image::load_from_memory(png).ok()?;35
let mut property = Vec::new();36
for size in WINDOW_ICON_SIZES {37
let resized = decoded38
.resize_exact(size, size, image::imageops::FilterType::Lanczos3)39
.to_rgba8();40
property.extend([size, size]);41
property.extend(resized.pixels().map(|pixel| {42
let [red, green, blue, alpha] = pixel.0;43
u32::from_le_bytes([blue, green, red, alpha])44
}));45
}46
Some(property)47
}48
49
pub fn write_window_icon(50
display: Option<&str>,51
window: u32,52
property: &[u32],53
) -> Result<(), Box<dyn std::error::Error>> {54
let (connection, _) = RustConnection::connect(display)?;55
let atom = connection.intern_atom(false, b"_NET_WM_ICON")?.reply()?.atom;56
connection57
.change_property32(PropMode::REPLACE, window, atom, AtomEnum::CARDINAL, property)?58
.check()?;59
connection.flush()?;60
Ok(())61
}62
63
pub fn set_window_icon(window: &Window, png: &[u8]) {64
if let (Some(id), Some(property)) = (x11_window_id(window), window_icon_property(png)) {65
let _ = write_window_icon(None, id, &property);66
}67
}68
29
#[cfg(test)]69
#[cfg(test)]30
mod tests {70
mod tests {31
use std::io::{BufRead, BufReader};71
use std::io::{BufRead, BufReader};@@ -34,7 +74,7 @@ mod tests {34
use std::time::Duration;74
use std::time::Duration;35
75
36
use x11rb::connection::Connection;76
use x11rb::connection::Connection;37
use x11rb::protocol::xproto::{ConnectionExt as _, CreateWindowAux, WindowClass};77
use x11rb::protocol::xproto::{CreateWindowAux, WindowClass};38
use x11rb::COPY_DEPTH_FROM_PARENT;78
use x11rb::COPY_DEPTH_FROM_PARENT;39
79
40
use super::*;80
use super::*;@@ -90,4 +130,41 @@ mod tests {90
let after = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();130
let after = connection.shape_get_rectangles(window, SK::INPUT).unwrap().reply().unwrap();91
assert!(after.rectangles.is_empty());131
assert!(after.rectangles.is_empty());92
}132
}133
134
#[test]135
fn the_window_icon_property_holds_every_size_in_argb() {136
let png = crate::appearance::AppIcon::MicrosoftTeams.png();137
let property = window_icon_property(png).unwrap();138
let expected: usize = WINDOW_ICON_SIZES139
.iter()140
.map(|size| 2 + (size * size) as usize)141
.sum();142
assert_eq!(property.len(), expected);143
assert_eq!(&property[..2], &[32, 32]);144
assert!(window_icon_property(b"not a png").is_none());145
}146
147
#[test]148
fn the_window_icon_lands_in_net_wm_icon() {149
let Some((_server, display)) = start_server() else {150
return;151
};152
let (connection, screen_number) = RustConnection::connect(Some(&display)).unwrap();153
let root = connection.setup().roots[screen_number].root;154
let window = connection.generate_id().unwrap();155
connection156
.create_window(COPY_DEPTH_FROM_PARENT, window, root, 0, 0, 100, 100, 0, WindowClass::INPUT_OUTPUT, 0, &CreateWindowAux::new())157
.unwrap();158
connection.flush().unwrap();159
let property = window_icon_property(crate::appearance::AppIcon::RustyTeams.png()).unwrap();160
write_window_icon(Some(&display), window, &property).unwrap();161
let atom = connection.intern_atom(false, b"_NET_WM_ICON").unwrap().reply().unwrap().atom;162
let reply = connection163
.get_property(false, window, atom, AtomEnum::CARDINAL, 0, u32::MAX)164
.unwrap()165
.reply()166
.unwrap();167
let stored: Vec<u32> = reply.value32().unwrap().collect();168
assert_eq!(stored, property);169
}93
}170
}@@ -4,6 +4,13 @@ use gpui_kit::component::elevation::{self, Elevation, ElevationTokens};
4
4
use gpui_kit::component::{Theme, ThemeMode};
5
5
use gpui_kit::*;
6
6
7
mod schemes;
8
9
pub use schemes::{
10
ColorScheme, SCHEMES, active_scheme as scheme, default_scheme, scheme_by_id, set_active_scheme,
11
set_thread_scheme,
12
};
13
7
14
const FONT_FAMILY: &str = "Google Sans Flex";
8
15
const MONO_FAMILIES: [&str; 2] = ["Cascadia Code", "Consolas"];
9
16
const BASE_FONT_SIZE: f32 = 14.;
@@ -14,36 +21,7 @@ const FONT_FILES: [&[u8]; 4] = [
14
21
include_bytes!("../../app/assets/fonts/GoogleSansFlex-Italic.ttf"),
15
22
];
16
23
17
pub const BACKGROUND: u32 = 0x0f0f10;
18
const SURFACE: u32 = 0x161617;
19
const SURFACE_RAISED: u32 = 0x232325;
20
const ROW_HOVER: u32 = 0x1c1c1e;
21
const POPUP: u32 = 0x2c2c2f;
22
const POPUP_HOVER: u32 = 0x38383c;
23
const POPUP_NESTED: u32 = 0x3a3a3e;
24
const POPUP_NESTED_HOVER: u32 = 0x47474c;
25
const REPLY_SURFACE: u32 = 0x19191b;
26
const BORDER: u32 = 0x262628;
27
const BORDER_STRONG: u32 = 0x3f3f42;
28
const FOREGROUND: u32 = 0xf4f4f5;
29
const TEXT_STRONG: u32 = 0xe4e4e7;
30
const TEXT_SOFT: u32 = 0xd4d4d8;
31
const TEXT_MUTED: u32 = 0xa1a1a6;
32
const TEXT_FAINT: u32 = 0x8e8e93;
33
const ACCENT: u32 = 0xce6a3b;
34
const ACCENT_TEXT: u32 = 0xe08a5c;
35
const ACCENT_SOFT: u32 = 0xf5c4a5;
36
const ACCENT_STRONG: u32 = 0xa84f27;
37
const BUBBLE_OWN: u32 = 0x4f2a1b;
38
const BUBBLE_OTHER: u32 = 0x232325;
39
const REACTION_ON_OWN: u32 = 0x6b3a26;
40
24
const WHITE: u32 = 0xffffff;
41
const MENTION_BACKGROUND: u32 = 0x3a2a23;
42
const MENTION_BACKGROUND_OWN: u32 = 0x3b1d11;
43
const OWN_META: u32 = 0xc9a28c;
44
const OWN_READ: u32 = 0xf5c4a5;
45
const DROP_BACKGROUND: u32 = 0xce6a3b14;
46
const SELECTION: u32 = 0xce6a3b66;
47
25
const CODE_SURFACE: u32 = 0x0000003d;
48
26
const CODE_HEADER_BORDER: u32 = 0xffffff0f;
49
27
const INLINE_CODE_FILL: u32 = 0xffffff14;
@@ -51,21 +29,7 @@ const INLINE_CODE_FILL_OWN: u32 = 0x0000003d;
51
29
const QUOTE_FILL: u32 = 0x00000052;
52
30
const INLINE_CODE_BORDER: u32 = 0xffffff1a;
53
31
const TABLE_HEADER: u32 = 0xffffff0d;
54
const RULE_OWN: u32 = 0x6a3a25;
55
const BADGE_MUTED: u32 = 0x3f3f42;
56
const TOAST_MENTION: u32 = 0x2e1d15;
57
const GREEN: u32 = 0x22c55e;
58
const RED: u32 = 0xef4444;
59
const CLOSE_BUTTON_HOVER: u32 = 0xc42b1c;
60
const CLOSE_BUTTON_PRESSED: u32 = 0xb5271a;
61
32
const CLOSE_BUTTON_ICON: u32 = 0xffffff;
62
const RED_SOFT: u32 = 0xf87171;
63
const RED_TINT: u32 = 0xfca5a5;
64
const AMBER: u32 = 0xfbbf24;
65
const OUT_OF_OFFICE: u32 = 0xc239b3;
66
const MEETING_AVATAR: u32 = 0x4f52b2;
67
const BOT_AVATAR: u32 = 0x3a96dd;
68
const AVATAR_PALETTE: [u32; 6] = [0x9a4a22, 0x44606e, 0x8a3434, 0x4f6a3c, 0x6a4f7a, 0x2f6b63];
69
33
70
34
pub fn color(hex: u32) -> Hsla {
71
35
rgb(hex).into()
@@ -98,65 +62,65 @@ pub fn apply(cx: &mut App) {
98
62
}
99
63
theme.radius_lg = px(10.);
100
64
let colors = &mut theme.colors;
101
colors.background = color(BACKGROUND);
102
colors.foreground = color(FOREGROUND);
103
colors.border = color(BORDER);
104
colors.muted = color(BORDER);
105
colors.muted_foreground = color(TEXT_MUTED);
106
colors.sidebar = color(SURFACE);
107
colors.sidebar_foreground = color(FOREGROUND);
108
colors.sidebar_border = color(BORDER);
109
colors.sidebar_accent = color(POPUP_HOVER);
110
colors.sidebar_accent_foreground = color(FOREGROUND);
111
colors.sidebar_primary = color(ACCENT);
112
colors.popover = color(POPUP);
113
colors.popover_foreground = color(FOREGROUND);
114
colors.accent = color(SURFACE_RAISED);
115
colors.accent_foreground = color(FOREGROUND);
116
colors.secondary = color(SURFACE_RAISED);
117
colors.secondary_hover = color(BORDER_STRONG);
118
colors.secondary_active = color(BORDER_STRONG);
119
colors.secondary_foreground = color(FOREGROUND);
120
colors.primary = color(ACCENT);
121
colors.primary_hover = color(ACCENT_TEXT);
122
colors.primary_active = color(ACCENT_STRONG);
123
colors.primary_foreground = color(BACKGROUND);
124
colors.link = color(ACCENT_TEXT);
125
colors.link_hover = color(ACCENT_SOFT);
126
colors.link_active = color(ACCENT_STRONG);
127
colors.ring = color(ACCENT);
128
colors.caret = color(ACCENT);
129
colors.input = color(BORDER_STRONG);
130
colors.selection = color_with_alpha(SELECTION);
131
colors.title_bar = color(BACKGROUND);
132
colors.title_bar_border = color(BORDER);
133
colors.status_bar = color(BACKGROUND);
134
colors.status_bar_border = color(BORDER);
135
colors.success = color(GREEN);
136
colors.warning = color(AMBER);
137
colors.danger = color(CLOSE_BUTTON_HOVER);
138
colors.danger_active = color(CLOSE_BUTTON_PRESSED);
65
colors.background = color(scheme().background);
66
colors.foreground = color(scheme().foreground);
67
colors.border = color(scheme().border);
68
colors.muted = color(scheme().border);
69
colors.muted_foreground = color(scheme().text_muted);
70
colors.sidebar = color(scheme().surface);
71
colors.sidebar_foreground = color(scheme().foreground);
72
colors.sidebar_border = color(scheme().border);
73
colors.sidebar_accent = color(scheme().popup_hover);
74
colors.sidebar_accent_foreground = color(scheme().foreground);
75
colors.sidebar_primary = color(scheme().accent);
76
colors.popover = color(scheme().popup);
77
colors.popover_foreground = color(scheme().foreground);
78
colors.accent = color(scheme().surface_raised);
79
colors.accent_foreground = color(scheme().foreground);
80
colors.secondary = color(scheme().surface_raised);
81
colors.secondary_hover = color(scheme().border_strong);
82
colors.secondary_active = color(scheme().border_strong);
83
colors.secondary_foreground = color(scheme().foreground);
84
colors.primary = color(scheme().accent);
85
colors.primary_hover = color(scheme().accent_text);
86
colors.primary_active = color(scheme().accent_strong);
87
colors.primary_foreground = color(scheme().on_accent);
88
colors.link = color(scheme().accent_text);
89
colors.link_hover = color(scheme().accent_soft);
90
colors.link_active = color(scheme().accent_strong);
91
colors.ring = color(scheme().accent);
92
colors.caret = color(scheme().accent);
93
colors.input = color(scheme().border_strong);
94
colors.selection = color_with_alpha(scheme().selection);
95
colors.title_bar = color(scheme().background);
96
colors.title_bar_border = color(scheme().border);
97
colors.status_bar = color(scheme().background);
98
colors.status_bar_border = color(scheme().border);
99
colors.success = color(scheme().green);
100
colors.warning = color(scheme().amber);
101
colors.danger = color(scheme().close_button_hover);
102
colors.danger_active = color(scheme().close_button_pressed);
139
103
colors.danger_foreground = color(CLOSE_BUTTON_ICON);
140
colors.drop_target = color_with_alpha(DROP_BACKGROUND);
141
colors.window_border = color(BORDER);
142
colors.scrollbar_thumb = color(BORDER_STRONG);
143
colors.scrollbar_thumb_hover = color(TEXT_FAINT);
144
colors.list = color(BACKGROUND);
145
colors.list_hover = color(ROW_HOVER);
146
colors.list_active = color(SURFACE_RAISED);
104
colors.drop_target = color_with_alpha(scheme().drop_background);
105
colors.window_border = color(scheme().border);
106
colors.scrollbar_thumb = color(scheme().border_strong);
107
colors.scrollbar_thumb_hover = color(scheme().text_faint);
108
colors.list = color(scheme().background);
109
colors.list_hover = color(scheme().row_hover);
110
colors.list_active = color(scheme().surface_raised);
147
111
});
148
112
cx.set_global(elevation_tokens());
149
113
}
150
114
151
115
fn elevation_tokens() -> ElevationTokens {
152
116
let flyout = Elevation {
153
fill: color(POPUP),
154
hover: color(POPUP_HOVER),
117
fill: color(scheme().popup),
118
hover: color(scheme().popup_hover),
155
119
shadow: elevation::shadow16(),
156
120
};
157
121
let nested_flyout = Elevation {
158
fill: color(POPUP_NESTED),
159
hover: color(POPUP_NESTED_HOVER),
122
fill: color(scheme().popup_nested),
123
hover: color(scheme().popup_nested_hover),
160
124
shadow: elevation::shadow16(),
161
125
};
162
126
ElevationTokens {
@@ -185,7 +149,7 @@ pub fn toast_shadow() -> Vec<BoxShadow> {
185
149
}
186
150
187
151
pub fn popup_nested() -> Hsla {
188
color(POPUP_NESTED)
152
color(scheme().popup_nested)
189
153
}
190
154
191
155
pub trait ElevatedSurface: Styled + Sized {
@@ -213,91 +177,95 @@ pub fn font_family() -> SharedString {
213
177
}
214
178
215
179
pub fn background() -> Hsla {
216
color(BACKGROUND)
180
color(scheme().background)
181
}
182
183
pub fn background_hex() -> u32 {
184
scheme().background
217
185
}
218
186
219
187
pub fn toast_mention_fill() -> Hsla {
220
color(TOAST_MENTION)
188
color(scheme().toast_mention)
221
189
}
222
190
223
191
pub fn surface() -> Hsla {
224
color(SURFACE)
192
color(scheme().surface)
225
193
}
226
194
227
195
pub fn surface_raised() -> Hsla {
228
color(SURFACE_RAISED)
196
color(scheme().surface_raised)
229
197
}
230
198
231
199
pub fn row_hover() -> Hsla {
232
color(ROW_HOVER)
200
color(scheme().row_hover)
233
201
}
234
202
235
203
pub fn popup() -> Hsla {
236
color(POPUP)
204
color(scheme().popup)
237
205
}
238
206
239
207
pub fn popup_hover() -> Hsla {
240
color(POPUP_HOVER)
208
color(scheme().popup_hover)
241
209
}
242
210
243
211
pub fn reply_surface() -> Hsla {
244
color(REPLY_SURFACE)
212
color(scheme().reply_surface)
245
213
}
246
214
247
215
pub fn border() -> Hsla {
248
color(BORDER)
216
color(scheme().border)
249
217
}
250
218
251
219
pub fn border_strong() -> Hsla {
252
color(BORDER_STRONG)
220
color(scheme().border_strong)
253
221
}
254
222
255
223
pub fn text() -> Hsla {
256
color(FOREGROUND)
224
color(scheme().foreground)
257
225
}
258
226
259
227
pub fn text_strong() -> Hsla {
260
color(TEXT_STRONG)
228
color(scheme().text_strong)
261
229
}
262
230
263
231
pub fn text_soft() -> Hsla {
264
color(TEXT_SOFT)
232
color(scheme().text_soft)
265
233
}
266
234
267
235
pub fn text_muted() -> Hsla {
268
color(TEXT_MUTED)
236
color(scheme().text_muted)
269
237
}
270
238
271
239
pub fn text_faint() -> Hsla {
272
color(TEXT_FAINT)
240
color(scheme().text_faint)
273
241
}
274
242
275
243
pub fn accent() -> Hsla {
276
color(ACCENT)
244
color(scheme().accent)
277
245
}
278
246
279
247
pub fn accent_text() -> Hsla {
280
color(ACCENT_TEXT)
248
color(scheme().accent_text)
281
249
}
282
250
283
251
pub fn accent_soft() -> Hsla {
284
color(ACCENT_SOFT)
252
color(scheme().accent_soft)
285
253
}
286
254
287
255
pub fn on_accent() -> Hsla {
288
color(BACKGROUND)
256
color(scheme().on_accent)
289
257
}
290
258
291
259
pub fn bubble_own() -> Hsla {
292
color(BUBBLE_OWN)
260
color(scheme().bubble_own)
293
261
}
294
262
295
263
pub fn bubble_other() -> Hsla {
296
color(BUBBLE_OTHER)
264
color(scheme().bubble_other)
297
265
}
298
266
299
267
pub fn reaction_on_own() -> Hsla {
300
color(REACTION_ON_OWN)
268
color(scheme().reaction_on_own)
301
269
}
302
270
303
271
pub fn white() -> Hsla {
@@ -306,26 +274,26 @@ pub fn white() -> Hsla {
306
274
307
275
pub fn mention_background(own: bool) -> Hsla {
308
276
color(if own {
309
MENTION_BACKGROUND_OWN
277
scheme().mention_background_own
310
278
} else {
311
MENTION_BACKGROUND
279
scheme().mention_background
312
280
})
313
281
}
314
282
315
283
pub fn own_meta() -> Hsla {
316
color(OWN_META)
284
color(scheme().own_meta)
317
285
}
318
286
319
287
pub fn own_read() -> Hsla {
320
color(OWN_READ)
288
color(scheme().own_read)
321
289
}
322
290
323
291
pub fn mention_text() -> Hsla {
324
color(ACCENT_SOFT)
292
color(scheme().accent_soft)
325
293
}
326
294
327
295
pub fn drop_background() -> Hsla {
328
color_with_alpha(DROP_BACKGROUND)
296
color_with_alpha(scheme().drop_background)
329
297
}
330
298
331
299
pub fn code_surface() -> Hsla {
@@ -358,59 +326,62 @@ pub fn table_header() -> Hsla {
358
326
359
327
pub fn rule(own: bool) -> Hsla {
360
328
if own {
361
color(RULE_OWN)
329
color(scheme().rule_own)
362
330
} else {
363
331
border_strong()
364
332
}
365
333
}
366
334
367
335
pub fn badge_muted() -> Hsla {
368
color(BADGE_MUTED)
336
color(scheme().badge_muted)
369
337
}
370
338
371
339
pub fn green() -> Hsla {
372
color(GREEN)
340
color(scheme().green)
373
341
}
374
342
375
343
pub fn red() -> Hsla {
376
color(RED)
344
color(scheme().red)
377
345
}
378
346
379
347
pub fn red_soft() -> Hsla {
380
color(RED_SOFT)
348
color(scheme().red_soft)
381
349
}
382
350
383
351
pub fn red_tint() -> Hsla {
384
color(RED_TINT)
352
color(scheme().red_tint)
385
353
}
386
354
387
355
pub fn amber() -> Hsla {
388
color(AMBER)
356
color(scheme().amber)
389
357
}
390
358
391
359
pub fn out_of_office() -> Hsla {
392
color(OUT_OF_OFFICE)
360
color(scheme().out_of_office)
393
361
}
394
362
395
363
pub fn meeting_avatar() -> Hsla {
396
color(MEETING_AVATAR)
364
color(scheme().meeting_avatar)
397
365
}
398
366
399
367
pub fn bot_avatar() -> Hsla {
400
color(BOT_AVATAR)
368
color(scheme().bot_avatar)
401
369
}
402
370
403
371
pub fn avatar_color(index: usize) -> Hsla {
404
color(AVATAR_PALETTE[index % AVATAR_PALETTE.len()])
372
let palette = scheme().avatar_palette;
373
color(palette[index % palette.len()])
405
374
}
406
375
407
376
pub fn avatar_palette_len() -> usize {
408
AVATAR_PALETTE.len()
377
scheme().avatar_palette.len()
409
378
}
410
379
411
380
#[cfg(test)]
412
381
mod tests {
413
use super::{POPUP, POPUP_HOVER, POPUP_NESTED, avatar_color, avatar_palette_len, color, elevation_tokens};
382
use super::{
383
SCHEMES, avatar_color, avatar_palette_len, color, elevation_tokens, set_thread_scheme,
384
};
414
385
415
386
#[test]
416
387
fn avatar_colors_wrap_around_the_palette() {
@@ -420,14 +391,18 @@ mod tests {
420
391
421
392
#[test]
422
393
fn flyout_over_a_dialog_takes_a_lighter_fill_than_the_dialog() {
423
let tokens = elevation_tokens();
424
assert_eq!(tokens.dialog.fill, color(POPUP));
425
assert_eq!(tokens.flyout_at(0).fill, color(POPUP));
426
let nested = tokens.flyout_at(1);
427
assert_eq!(nested.fill, color(POPUP_NESTED));
428
assert!(nested.fill.l > tokens.dialog.fill.l);
429
assert!(nested.hover.l > nested.fill.l);
430
assert_ne!(nested.fill, color(POPUP_HOVER));
394
for scheme in SCHEMES {
395
set_thread_scheme(Some(scheme.id));
396
let tokens = elevation_tokens();
397
assert_eq!(tokens.dialog.fill, color(scheme.popup));
398
assert_eq!(tokens.flyout_at(0).fill, color(scheme.popup));
399
let nested = tokens.flyout_at(1);
400
assert_eq!(nested.fill, color(scheme.popup_nested));
401
assert!(nested.fill.l > tokens.dialog.fill.l);
402
assert!(nested.hover.l > nested.fill.l);
403
assert_ne!(nested.fill, color(scheme.popup_hover));
404
}
405
set_thread_scheme(None);
431
406
}
432
407
433
408
#[test]
@@ -4,6 +4,13 @@ use gpui_kit::component::elevation::{self, Elevation, ElevationTokens};4
use gpui_kit::component::{Theme, ThemeMode};4
use gpui_kit::component::{Theme, ThemeMode};5
use gpui_kit::*;5
use gpui_kit::*;6
6
7
mod schemes;8
9
pub use schemes::{10
ColorScheme, SCHEMES, active_scheme as scheme, default_scheme, scheme_by_id, set_active_scheme,11
set_thread_scheme,12
};13
7
const FONT_FAMILY: &str = "Google Sans Flex";14
const FONT_FAMILY: &str = "Google Sans Flex";8
const MONO_FAMILIES: [&str; 2] = ["Cascadia Code", "Consolas"];15
const MONO_FAMILIES: [&str; 2] = ["Cascadia Code", "Consolas"];9
const BASE_FONT_SIZE: f32 = 14.;16
const BASE_FONT_SIZE: f32 = 14.;@@ -14,36 +21,7 @@ const FONT_FILES: [&[u8]; 4] = [14
include_bytes!("../../app/assets/fonts/GoogleSansFlex-Italic.ttf"),21
include_bytes!("../../app/assets/fonts/GoogleSansFlex-Italic.ttf"),15
];22
];16
23
17
pub const BACKGROUND: u32 = 0x0f0f10;18
const SURFACE: u32 = 0x161617;19
const SURFACE_RAISED: u32 = 0x232325;20
const ROW_HOVER: u32 = 0x1c1c1e;21
const POPUP: u32 = 0x2c2c2f;22
const POPUP_HOVER: u32 = 0x38383c;23
const POPUP_NESTED: u32 = 0x3a3a3e;24
const POPUP_NESTED_HOVER: u32 = 0x47474c;25
const REPLY_SURFACE: u32 = 0x19191b;26
const BORDER: u32 = 0x262628;27
const BORDER_STRONG: u32 = 0x3f3f42;28
const FOREGROUND: u32 = 0xf4f4f5;29
const TEXT_STRONG: u32 = 0xe4e4e7;30
const TEXT_SOFT: u32 = 0xd4d4d8;31
const TEXT_MUTED: u32 = 0xa1a1a6;32
const TEXT_FAINT: u32 = 0x8e8e93;33
const ACCENT: u32 = 0xce6a3b;34
const ACCENT_TEXT: u32 = 0xe08a5c;35
const ACCENT_SOFT: u32 = 0xf5c4a5;36
const ACCENT_STRONG: u32 = 0xa84f27;37
const BUBBLE_OWN: u32 = 0x4f2a1b;38
const BUBBLE_OTHER: u32 = 0x232325;39
const REACTION_ON_OWN: u32 = 0x6b3a26;40
const WHITE: u32 = 0xffffff;24
const WHITE: u32 = 0xffffff;41
const MENTION_BACKGROUND: u32 = 0x3a2a23;42
const MENTION_BACKGROUND_OWN: u32 = 0x3b1d11;43
const OWN_META: u32 = 0xc9a28c;44
const OWN_READ: u32 = 0xf5c4a5;45
const DROP_BACKGROUND: u32 = 0xce6a3b14;46
const SELECTION: u32 = 0xce6a3b66;47
const CODE_SURFACE: u32 = 0x0000003d;25
const CODE_SURFACE: u32 = 0x0000003d;48
const CODE_HEADER_BORDER: u32 = 0xffffff0f;26
const CODE_HEADER_BORDER: u32 = 0xffffff0f;49
const INLINE_CODE_FILL: u32 = 0xffffff14;27
const INLINE_CODE_FILL: u32 = 0xffffff14;@@ -51,21 +29,7 @@ const INLINE_CODE_FILL_OWN: u32 = 0x0000003d;51
const QUOTE_FILL: u32 = 0x00000052;29
const QUOTE_FILL: u32 = 0x00000052;52
const INLINE_CODE_BORDER: u32 = 0xffffff1a;30
const INLINE_CODE_BORDER: u32 = 0xffffff1a;53
const TABLE_HEADER: u32 = 0xffffff0d;31
const TABLE_HEADER: u32 = 0xffffff0d;54
const RULE_OWN: u32 = 0x6a3a25;55
const BADGE_MUTED: u32 = 0x3f3f42;56
const TOAST_MENTION: u32 = 0x2e1d15;57
const GREEN: u32 = 0x22c55e;58
const RED: u32 = 0xef4444;59
const CLOSE_BUTTON_HOVER: u32 = 0xc42b1c;60
const CLOSE_BUTTON_PRESSED: u32 = 0xb5271a;61
const CLOSE_BUTTON_ICON: u32 = 0xffffff;32
const CLOSE_BUTTON_ICON: u32 = 0xffffff;62
const RED_SOFT: u32 = 0xf87171;63
const RED_TINT: u32 = 0xfca5a5;64
const AMBER: u32 = 0xfbbf24;65
const OUT_OF_OFFICE: u32 = 0xc239b3;66
const MEETING_AVATAR: u32 = 0x4f52b2;67
const BOT_AVATAR: u32 = 0x3a96dd;68
const AVATAR_PALETTE: [u32; 6] = [0x9a4a22, 0x44606e, 0x8a3434, 0x4f6a3c, 0x6a4f7a, 0x2f6b63];69
33
70
pub fn color(hex: u32) -> Hsla {34
pub fn color(hex: u32) -> Hsla {71
rgb(hex).into()35
rgb(hex).into()@@ -98,65 +62,65 @@ pub fn apply(cx: &mut App) {98
}62
}99
theme.radius_lg = px(10.);63
theme.radius_lg = px(10.);100
let colors = &mut theme.colors;64
let colors = &mut theme.colors;101
colors.background = color(BACKGROUND);65
colors.background = color(scheme().background);102
colors.foreground = color(FOREGROUND);66
colors.foreground = color(scheme().foreground);103
colors.border = color(BORDER);67
colors.border = color(scheme().border);104
colors.muted = color(BORDER);68
colors.muted = color(scheme().border);105
colors.muted_foreground = color(TEXT_MUTED);69
colors.muted_foreground = color(scheme().text_muted);106
colors.sidebar = color(SURFACE);70
colors.sidebar = color(scheme().surface);107
colors.sidebar_foreground = color(FOREGROUND);71
colors.sidebar_foreground = color(scheme().foreground);108
colors.sidebar_border = color(BORDER);72
colors.sidebar_border = color(scheme().border);109
colors.sidebar_accent = color(POPUP_HOVER);73
colors.sidebar_accent = color(scheme().popup_hover);110
colors.sidebar_accent_foreground = color(FOREGROUND);74
colors.sidebar_accent_foreground = color(scheme().foreground);111
colors.sidebar_primary = color(ACCENT);75
colors.sidebar_primary = color(scheme().accent);112
colors.popover = color(POPUP);76
colors.popover = color(scheme().popup);113
colors.popover_foreground = color(FOREGROUND);77
colors.popover_foreground = color(scheme().foreground);114
colors.accent = color(SURFACE_RAISED);78
colors.accent = color(scheme().surface_raised);115
colors.accent_foreground = color(FOREGROUND);79
colors.accent_foreground = color(scheme().foreground);116
colors.secondary = color(SURFACE_RAISED);80
colors.secondary = color(scheme().surface_raised);117
colors.secondary_hover = color(BORDER_STRONG);81
colors.secondary_hover = color(scheme().border_strong);118
colors.secondary_active = color(BORDER_STRONG);82
colors.secondary_active = color(scheme().border_strong);119
colors.secondary_foreground = color(FOREGROUND);83
colors.secondary_foreground = color(scheme().foreground);120
colors.primary = color(ACCENT);84
colors.primary = color(scheme().accent);121
colors.primary_hover = color(ACCENT_TEXT);85
colors.primary_hover = color(scheme().accent_text);122
colors.primary_active = color(ACCENT_STRONG);86
colors.primary_active = color(scheme().accent_strong);123
colors.primary_foreground = color(BACKGROUND);87
colors.primary_foreground = color(scheme().on_accent);124
colors.link = color(ACCENT_TEXT);88
colors.link = color(scheme().accent_text);125
colors.link_hover = color(ACCENT_SOFT);89
colors.link_hover = color(scheme().accent_soft);126
colors.link_active = color(ACCENT_STRONG);90
colors.link_active = color(scheme().accent_strong);127
colors.ring = color(ACCENT);91
colors.ring = color(scheme().accent);128
colors.caret = color(ACCENT);92
colors.caret = color(scheme().accent);129
colors.input = color(BORDER_STRONG);93
colors.input = color(scheme().border_strong);130
colors.selection = color_with_alpha(SELECTION);94
colors.selection = color_with_alpha(scheme().selection);131
colors.title_bar = color(BACKGROUND);95
colors.title_bar = color(scheme().background);132
colors.title_bar_border = color(BORDER);96
colors.title_bar_border = color(scheme().border);133
colors.status_bar = color(BACKGROUND);97
colors.status_bar = color(scheme().background);134
colors.status_bar_border = color(BORDER);98
colors.status_bar_border = color(scheme().border);135
colors.success = color(GREEN);99
colors.success = color(scheme().green);136
colors.warning = color(AMBER);100
colors.warning = color(scheme().amber);137
colors.danger = color(CLOSE_BUTTON_HOVER);101
colors.danger = color(scheme().close_button_hover);138
colors.danger_active = color(CLOSE_BUTTON_PRESSED);102
colors.danger_active = color(scheme().close_button_pressed);139
colors.danger_foreground = color(CLOSE_BUTTON_ICON);103
colors.danger_foreground = color(CLOSE_BUTTON_ICON);140
colors.drop_target = color_with_alpha(DROP_BACKGROUND);104
colors.drop_target = color_with_alpha(scheme().drop_background);141
colors.window_border = color(BORDER);105
colors.window_border = color(scheme().border);142
colors.scrollbar_thumb = color(BORDER_STRONG);106
colors.scrollbar_thumb = color(scheme().border_strong);143
colors.scrollbar_thumb_hover = color(TEXT_FAINT);107
colors.scrollbar_thumb_hover = color(scheme().text_faint);144
colors.list = color(BACKGROUND);108
colors.list = color(scheme().background);145
colors.list_hover = color(ROW_HOVER);109
colors.list_hover = color(scheme().row_hover);146
colors.list_active = color(SURFACE_RAISED);110
colors.list_active = color(scheme().surface_raised);147
});111
});148
cx.set_global(elevation_tokens());112
cx.set_global(elevation_tokens());149
}113
}150
114
151
fn elevation_tokens() -> ElevationTokens {115
fn elevation_tokens() -> ElevationTokens {152
let flyout = Elevation {116
let flyout = Elevation {153
fill: color(POPUP),117
fill: color(scheme().popup),154
hover: color(POPUP_HOVER),118
hover: color(scheme().popup_hover),155
shadow: elevation::shadow16(),119
shadow: elevation::shadow16(),156
};120
};157
let nested_flyout = Elevation {121
let nested_flyout = Elevation {158
fill: color(POPUP_NESTED),122
fill: color(scheme().popup_nested),159
hover: color(POPUP_NESTED_HOVER),123
hover: color(scheme().popup_nested_hover),160
shadow: elevation::shadow16(),124
shadow: elevation::shadow16(),161
};125
};162
ElevationTokens {126
ElevationTokens {@@ -185,7 +149,7 @@ pub fn toast_shadow() -> Vec<BoxShadow> {185
}149
}186
150
187
pub fn popup_nested() -> Hsla {151
pub fn popup_nested() -> Hsla {188
color(POPUP_NESTED)152
color(scheme().popup_nested)189
}153
}190
154
191
pub trait ElevatedSurface: Styled + Sized {155
pub trait ElevatedSurface: Styled + Sized {@@ -213,91 +177,95 @@ pub fn font_family() -> SharedString {213
}177
}214
178
215
pub fn background() -> Hsla {179
pub fn background() -> Hsla {216
color(BACKGROUND)180
color(scheme().background)181
}182
183
pub fn background_hex() -> u32 {184
scheme().background217
}185
}218
186
219
pub fn toast_mention_fill() -> Hsla {187
pub fn toast_mention_fill() -> Hsla {220
color(TOAST_MENTION)188
color(scheme().toast_mention)221
}189
}222
190
223
pub fn surface() -> Hsla {191
pub fn surface() -> Hsla {224
color(SURFACE)192
color(scheme().surface)225
}193
}226
194
227
pub fn surface_raised() -> Hsla {195
pub fn surface_raised() -> Hsla {228
color(SURFACE_RAISED)196
color(scheme().surface_raised)229
}197
}230
198
231
pub fn row_hover() -> Hsla {199
pub fn row_hover() -> Hsla {232
color(ROW_HOVER)200
color(scheme().row_hover)233
}201
}234
202
235
pub fn popup() -> Hsla {203
pub fn popup() -> Hsla {236
color(POPUP)204
color(scheme().popup)237
}205
}238
206
239
pub fn popup_hover() -> Hsla {207
pub fn popup_hover() -> Hsla {240
color(POPUP_HOVER)208
color(scheme().popup_hover)241
}209
}242
210
243
pub fn reply_surface() -> Hsla {211
pub fn reply_surface() -> Hsla {244
color(REPLY_SURFACE)212
color(scheme().reply_surface)245
}213
}246
214
247
pub fn border() -> Hsla {215
pub fn border() -> Hsla {248
color(BORDER)216
color(scheme().border)249
}217
}250
218
251
pub fn border_strong() -> Hsla {219
pub fn border_strong() -> Hsla {252
color(BORDER_STRONG)220
color(scheme().border_strong)253
}221
}254
222
255
pub fn text() -> Hsla {223
pub fn text() -> Hsla {256
color(FOREGROUND)224
color(scheme().foreground)257
}225
}258
226
259
pub fn text_strong() -> Hsla {227
pub fn text_strong() -> Hsla {260
color(TEXT_STRONG)228
color(scheme().text_strong)261
}229
}262
230
263
pub fn text_soft() -> Hsla {231
pub fn text_soft() -> Hsla {264
color(TEXT_SOFT)232
color(scheme().text_soft)265
}233
}266
234
267
pub fn text_muted() -> Hsla {235
pub fn text_muted() -> Hsla {268
color(TEXT_MUTED)236
color(scheme().text_muted)269
}237
}270
238
271
pub fn text_faint() -> Hsla {239
pub fn text_faint() -> Hsla {272
color(TEXT_FAINT)240
color(scheme().text_faint)273
}241
}274
242
275
pub fn accent() -> Hsla {243
pub fn accent() -> Hsla {276
color(ACCENT)244
color(scheme().accent)277
}245
}278
246
279
pub fn accent_text() -> Hsla {247
pub fn accent_text() -> Hsla {280
color(ACCENT_TEXT)248
color(scheme().accent_text)281
}249
}282
250
283
pub fn accent_soft() -> Hsla {251
pub fn accent_soft() -> Hsla {284
color(ACCENT_SOFT)252
color(scheme().accent_soft)285
}253
}286
254
287
pub fn on_accent() -> Hsla {255
pub fn on_accent() -> Hsla {288
color(BACKGROUND)256
color(scheme().on_accent)289
}257
}290
258
291
pub fn bubble_own() -> Hsla {259
pub fn bubble_own() -> Hsla {292
color(BUBBLE_OWN)260
color(scheme().bubble_own)293
}261
}294
262
295
pub fn bubble_other() -> Hsla {263
pub fn bubble_other() -> Hsla {296
color(BUBBLE_OTHER)264
color(scheme().bubble_other)297
}265
}298
266
299
pub fn reaction_on_own() -> Hsla {267
pub fn reaction_on_own() -> Hsla {300
color(REACTION_ON_OWN)268
color(scheme().reaction_on_own)301
}269
}302
270
303
pub fn white() -> Hsla {271
pub fn white() -> Hsla {@@ -306,26 +274,26 @@ pub fn white() -> Hsla {306
274
307
pub fn mention_background(own: bool) -> Hsla {275
pub fn mention_background(own: bool) -> Hsla {308
color(if own {276
color(if own {309
MENTION_BACKGROUND_OWN277
scheme().mention_background_own310
} else {278
} else {311
MENTION_BACKGROUND279
scheme().mention_background312
})280
})313
}281
}314
282
315
pub fn own_meta() -> Hsla {283
pub fn own_meta() -> Hsla {316
color(OWN_META)284
color(scheme().own_meta)317
}285
}318
286
319
pub fn own_read() -> Hsla {287
pub fn own_read() -> Hsla {320
color(OWN_READ)288
color(scheme().own_read)321
}289
}322
290
323
pub fn mention_text() -> Hsla {291
pub fn mention_text() -> Hsla {324
color(ACCENT_SOFT)292
color(scheme().accent_soft)325
}293
}326
294
327
pub fn drop_background() -> Hsla {295
pub fn drop_background() -> Hsla {328
color_with_alpha(DROP_BACKGROUND)296
color_with_alpha(scheme().drop_background)329
}297
}330
298
331
pub fn code_surface() -> Hsla {299
pub fn code_surface() -> Hsla {@@ -358,59 +326,62 @@ pub fn table_header() -> Hsla {358
326
359
pub fn rule(own: bool) -> Hsla {327
pub fn rule(own: bool) -> Hsla {360
if own {328
if own {361
color(RULE_OWN)329
color(scheme().rule_own)362
} else {330
} else {363
border_strong()331
border_strong()364
}332
}365
}333
}366
334
367
pub fn badge_muted() -> Hsla {335
pub fn badge_muted() -> Hsla {368
color(BADGE_MUTED)336
color(scheme().badge_muted)369
}337
}370
338
371
pub fn green() -> Hsla {339
pub fn green() -> Hsla {372
color(GREEN)340
color(scheme().green)373
}341
}374
342
375
pub fn red() -> Hsla {343
pub fn red() -> Hsla {376
color(RED)344
color(scheme().red)377
}345
}378
346
379
pub fn red_soft() -> Hsla {347
pub fn red_soft() -> Hsla {380
color(RED_SOFT)348
color(scheme().red_soft)381
}349
}382
350
383
pub fn red_tint() -> Hsla {351
pub fn red_tint() -> Hsla {384
color(RED_TINT)352
color(scheme().red_tint)385
}353
}386
354
387
pub fn amber() -> Hsla {355
pub fn amber() -> Hsla {388
color(AMBER)356
color(scheme().amber)389
}357
}390
358
391
pub fn out_of_office() -> Hsla {359
pub fn out_of_office() -> Hsla {392
color(OUT_OF_OFFICE)360
color(scheme().out_of_office)393
}361
}394
362
395
pub fn meeting_avatar() -> Hsla {363
pub fn meeting_avatar() -> Hsla {396
color(MEETING_AVATAR)364
color(scheme().meeting_avatar)397
}365
}398
366
399
pub fn bot_avatar() -> Hsla {367
pub fn bot_avatar() -> Hsla {400
color(BOT_AVATAR)368
color(scheme().bot_avatar)401
}369
}402
370
403
pub fn avatar_color(index: usize) -> Hsla {371
pub fn avatar_color(index: usize) -> Hsla {404
color(AVATAR_PALETTE[index % AVATAR_PALETTE.len()])372
let palette = scheme().avatar_palette;373
color(palette[index % palette.len()])405
}374
}406
375
407
pub fn avatar_palette_len() -> usize {376
pub fn avatar_palette_len() -> usize {408
AVATAR_PALETTE.len()377
scheme().avatar_palette.len()409
}378
}410
379
411
#[cfg(test)]380
#[cfg(test)]412
mod tests {381
mod tests {413
use super::{POPUP, POPUP_HOVER, POPUP_NESTED, avatar_color, avatar_palette_len, color, elevation_tokens};382
use super::{383
SCHEMES, avatar_color, avatar_palette_len, color, elevation_tokens, set_thread_scheme,384
};414
385
415
#[test]386
#[test]416
fn avatar_colors_wrap_around_the_palette() {387
fn avatar_colors_wrap_around_the_palette() {@@ -420,14 +391,18 @@ mod tests {420
391
421
#[test]392
#[test]422
fn flyout_over_a_dialog_takes_a_lighter_fill_than_the_dialog() {393
fn flyout_over_a_dialog_takes_a_lighter_fill_than_the_dialog() {423
let tokens = elevation_tokens();394
for scheme in SCHEMES {424
assert_eq!(tokens.dialog.fill, color(POPUP));395
set_thread_scheme(Some(scheme.id));425
assert_eq!(tokens.flyout_at(0).fill, color(POPUP));396
let tokens = elevation_tokens();426
let nested = tokens.flyout_at(1);397
assert_eq!(tokens.dialog.fill, color(scheme.popup));427
assert_eq!(nested.fill, color(POPUP_NESTED));398
assert_eq!(tokens.flyout_at(0).fill, color(scheme.popup));428
assert!(nested.fill.l > tokens.dialog.fill.l);399
let nested = tokens.flyout_at(1);429
assert!(nested.hover.l > nested.fill.l);400
assert_eq!(nested.fill, color(scheme.popup_nested));430
assert_ne!(nested.fill, color(POPUP_HOVER));401
assert!(nested.fill.l > tokens.dialog.fill.l);402
assert!(nested.hover.l > nested.fill.l);403
assert_ne!(nested.fill, color(scheme.popup_hover));404
}405
set_thread_scheme(None);431
}406
}432
407
433
#[test]408
#[test]@@ -0,0 +1,252 @@
1
use std::cell::Cell;
2
use std::sync::atomic::{AtomicUsize, Ordering};
3
4
#[derive(Debug, PartialEq, Eq)]
5
pub struct ColorScheme {
6
pub id: &'static str,
7
pub name: &'static str,
8
pub background: u32,
9
pub surface: u32,
10
pub surface_raised: u32,
11
pub row_hover: u32,
12
pub popup: u32,
13
pub popup_hover: u32,
14
pub popup_nested: u32,
15
pub popup_nested_hover: u32,
16
pub reply_surface: u32,
17
pub border: u32,
18
pub border_strong: u32,
19
pub foreground: u32,
20
pub text_strong: u32,
21
pub text_soft: u32,
22
pub text_muted: u32,
23
pub text_faint: u32,
24
pub accent: u32,
25
pub accent_text: u32,
26
pub accent_soft: u32,
27
pub accent_strong: u32,
28
pub on_accent: u32,
29
pub bubble_own: u32,
30
pub bubble_other: u32,
31
pub reaction_on_own: u32,
32
pub mention_background: u32,
33
pub mention_background_own: u32,
34
pub own_meta: u32,
35
pub own_read: u32,
36
pub drop_background: u32,
37
pub selection: u32,
38
pub rule_own: u32,
39
pub badge_muted: u32,
40
pub toast_mention: u32,
41
pub green: u32,
42
pub red: u32,
43
pub red_soft: u32,
44
pub red_tint: u32,
45
pub amber: u32,
46
pub out_of_office: u32,
47
pub close_button_hover: u32,
48
pub close_button_pressed: u32,
49
pub meeting_avatar: u32,
50
pub bot_avatar: u32,
51
pub avatar_palette: [u32; 6],
52
}
53
54
pub const RUSTY_TEAMS: ColorScheme = ColorScheme {
55
id: "rusty-teams",
56
name: "Rusty Teams",
57
background: 0x0f0f10,
58
surface: 0x161617,
59
surface_raised: 0x232325,
60
row_hover: 0x1c1c1e,
61
popup: 0x2c2c2f,
62
popup_hover: 0x38383c,
63
popup_nested: 0x3a3a3e,
64
popup_nested_hover: 0x47474c,
65
reply_surface: 0x19191b,
66
border: 0x262628,
67
border_strong: 0x3f3f42,
68
foreground: 0xf4f4f5,
69
text_strong: 0xe4e4e7,
70
text_soft: 0xd4d4d8,
71
text_muted: 0xa1a1a6,
72
text_faint: 0x8e8e93,
73
accent: 0xce6a3b,
74
accent_text: 0xe08a5c,
75
accent_soft: 0xf5c4a5,
76
accent_strong: 0xa84f27,
77
on_accent: 0x0f0f10,
78
bubble_own: 0x4f2a1b,
79
bubble_other: 0x232325,
80
reaction_on_own: 0x6b3a26,
81
mention_background: 0x3a2a23,
82
mention_background_own: 0x3b1d11,
83
own_meta: 0xc9a28c,
84
own_read: 0xf5c4a5,
85
drop_background: 0xce6a3b14,
86
selection: 0xce6a3b66,
87
rule_own: 0x6a3a25,
88
badge_muted: 0x3f3f42,
89
toast_mention: 0x2e1d15,
90
green: 0x22c55e,
91
red: 0xef4444,
92
red_soft: 0xf87171,
93
red_tint: 0xfca5a5,
94
amber: 0xfbbf24,
95
out_of_office: 0xc239b3,
96
close_button_hover: 0xc42b1c,
97
close_button_pressed: 0xb5271a,
98
meeting_avatar: 0x4f52b2,
99
bot_avatar: 0x3a96dd,
100
avatar_palette: [0x9a4a22, 0x44606e, 0x8a3434, 0x4f6a3c, 0x6a4f7a, 0x2f6b63],
101
};
102
103
pub const TEAMS: ColorScheme = ColorScheme {
104
id: "teams",
105
name: "Teams",
106
background: 0x0a0a0a,
107
surface: 0x1f1f1f,
108
surface_raised: 0x2e2e2e,
109
row_hover: 0x292929,
110
popup: 0x333333,
111
popup_hover: 0x3d3d3d,
112
popup_nested: 0x424242,
113
popup_nested_hover: 0x4d4d4d,
114
reply_surface: 0x242424,
115
border: 0x333333,
116
border_strong: 0x3d3d3d,
117
foreground: 0xffffff,
118
text_strong: 0xe0e0e0,
119
text_soft: 0xd6d6d6,
120
text_muted: 0xadadad,
121
text_faint: 0x999999,
122
accent: 0x5b5fc7,
123
accent_text: 0x7f85f5,
124
accent_soft: 0xaab1fa,
125
accent_strong: 0x444791,
126
on_accent: 0xffffff,
127
bubble_own: 0x2f2f4a,
128
bubble_other: 0x292929,
129
reaction_on_own: 0x383966,
130
mention_background: 0x2f2f4a,
131
mention_background_own: 0x3d3e78,
132
own_meta: 0xadadad,
133
own_read: 0xaab1fa,
134
drop_background: 0x5b5fc714,
135
selection: 0x5b5fc766,
136
rule_own: 0x444791,
137
badge_muted: 0x3d3d3d,
138
toast_mention: 0x2f2f4a,
139
green: 0x92c353,
140
red: 0xc4314b,
141
red_soft: 0xe37d80,
142
red_tint: 0xf1bbbc,
143
amber: 0xffaa44,
144
out_of_office: 0xc239b3,
145
close_button_hover: 0xc4314b,
146
close_button_pressed: 0xa72037,
147
meeting_avatar: 0x4f52b2,
148
bot_avatar: 0x3a96dd,
149
avatar_palette: [0x9a4a22, 0x44606e, 0x8a3434, 0x4f6a3c, 0x6a4f7a, 0x2f6b63],
150
};
151
152
pub const SCHEMES: [&ColorScheme; 2] = [&RUSTY_TEAMS, &TEAMS];
153
154
static ACTIVE_SCHEME: AtomicUsize = AtomicUsize::new(0);
155
156
thread_local! {
157
static THREAD_SCHEME: Cell<Option<usize>> = const { Cell::new(None) };
158
}
159
160
pub fn default_scheme() -> &'static ColorScheme {
161
SCHEMES[0]
162
}
163
164
pub fn scheme_by_id(id: &str) -> Option<&'static ColorScheme> {
165
SCHEMES.into_iter().find(|scheme| scheme.id == id)
166
}
167
168
fn position(id: &str) -> usize {
169
SCHEMES
170
.iter()
171
.position(|scheme| scheme.id == id)
172
.unwrap_or(0)
173
}
174
175
pub fn active_scheme() -> &'static ColorScheme {
176
let index = THREAD_SCHEME
177
.with(Cell::get)
178
.unwrap_or_else(|| ACTIVE_SCHEME.load(Ordering::Relaxed));
179
SCHEMES[index.min(SCHEMES.len() - 1)]
180
}
181
182
pub fn set_active_scheme(id: &str) {
183
ACTIVE_SCHEME.store(position(id), Ordering::Relaxed);
184
}
185
186
pub fn set_thread_scheme(id: Option<&str>) {
187
THREAD_SCHEME.with(|cell| cell.set(id.map(position)));
188
}
189
190
#[cfg(test)]
191
mod tests {
192
use std::collections::HashSet;
193
194
use super::*;
195
196
#[test]
197
fn scheme_ids_and_names_are_unique() {
198
let ids: HashSet<_> = SCHEMES.iter().map(|scheme| scheme.id).collect();
199
let names: HashSet<_> = SCHEMES.iter().map(|scheme| scheme.name).collect();
200
assert_eq!(ids.len(), SCHEMES.len());
201
assert_eq!(names.len(), SCHEMES.len());
202
}
203
204
#[test]
205
fn rusty_teams_is_the_default() {
206
assert_eq!(default_scheme().id, "rusty-teams");
207
assert_eq!(scheme_by_id("teams"), Some(&TEAMS));
208
assert_eq!(scheme_by_id("solarized"), None);
209
}
210
211
#[test]
212
fn teams_scheme_uses_the_teams_dark_brand_ramp() {
213
assert_eq!(TEAMS.accent_text, 0x7f85f5);
214
assert_eq!(TEAMS.bubble_own, 0x2f2f4a);
215
assert_eq!(TEAMS.surface, 0x1f1f1f);
216
}
217
218
#[test]
219
fn every_scheme_layers_its_surfaces_from_dark_to_light() {
220
for scheme in SCHEMES {
221
let layers = [
222
scheme.background,
223
scheme.surface,
224
scheme.reply_surface,
225
scheme.row_hover,
226
scheme.surface_raised,
227
scheme.popup,
228
scheme.popup_hover,
229
];
230
assert!(
231
layers.windows(2).all(|pair| pair[0] < pair[1]),
232
"{} surfaces are not ordered dark to light",
233
scheme.id
234
);
235
assert!(scheme.popup_nested > scheme.popup, "{}", scheme.id);
236
assert!(
237
scheme.popup_nested_hover > scheme.popup_nested,
238
"{}",
239
scheme.id
240
);
241
}
242
}
243
244
#[test]
245
fn a_thread_override_wins_over_the_process_scheme() {
246
set_thread_scheme(Some("teams"));
247
assert_eq!(active_scheme().id, "teams");
248
set_thread_scheme(Some("unknown"));
249
assert_eq!(active_scheme().id, "rusty-teams");
250
set_thread_scheme(None);
251
}
252
}
@@ -0,0 +1,252 @@1
use std::cell::Cell;2
use std::sync::atomic::{AtomicUsize, Ordering};3
4
#[derive(Debug, PartialEq, Eq)]5
pub struct ColorScheme {6
pub id: &'static str,7
pub name: &'static str,8
pub background: u32,9
pub surface: u32,10
pub surface_raised: u32,11
pub row_hover: u32,12
pub popup: u32,13
pub popup_hover: u32,14
pub popup_nested: u32,15
pub popup_nested_hover: u32,16
pub reply_surface: u32,17
pub border: u32,18
pub border_strong: u32,19
pub foreground: u32,20
pub text_strong: u32,21
pub text_soft: u32,22
pub text_muted: u32,23
pub text_faint: u32,24
pub accent: u32,25
pub accent_text: u32,26
pub accent_soft: u32,27
pub accent_strong: u32,28
pub on_accent: u32,29
pub bubble_own: u32,30
pub bubble_other: u32,31
pub reaction_on_own: u32,32
pub mention_background: u32,33
pub mention_background_own: u32,34
pub own_meta: u32,35
pub own_read: u32,36
pub drop_background: u32,37
pub selection: u32,38
pub rule_own: u32,39
pub badge_muted: u32,40
pub toast_mention: u32,41
pub green: u32,42
pub red: u32,43
pub red_soft: u32,44
pub red_tint: u32,45
pub amber: u32,46
pub out_of_office: u32,47
pub close_button_hover: u32,48
pub close_button_pressed: u32,49
pub meeting_avatar: u32,50
pub bot_avatar: u32,51
pub avatar_palette: [u32; 6],52
}53
54
pub const RUSTY_TEAMS: ColorScheme = ColorScheme {55
id: "rusty-teams",56
name: "Rusty Teams",57
background: 0x0f0f10,58
surface: 0x161617,59
surface_raised: 0x232325,60
row_hover: 0x1c1c1e,61
popup: 0x2c2c2f,62
popup_hover: 0x38383c,63
popup_nested: 0x3a3a3e,64
popup_nested_hover: 0x47474c,65
reply_surface: 0x19191b,66
border: 0x262628,67
border_strong: 0x3f3f42,68
foreground: 0xf4f4f5,69
text_strong: 0xe4e4e7,70
text_soft: 0xd4d4d8,71
text_muted: 0xa1a1a6,72
text_faint: 0x8e8e93,73
accent: 0xce6a3b,74
accent_text: 0xe08a5c,75
accent_soft: 0xf5c4a5,76
accent_strong: 0xa84f27,77
on_accent: 0x0f0f10,78
bubble_own: 0x4f2a1b,79
bubble_other: 0x232325,80
reaction_on_own: 0x6b3a26,81
mention_background: 0x3a2a23,82
mention_background_own: 0x3b1d11,83
own_meta: 0xc9a28c,84
own_read: 0xf5c4a5,85
drop_background: 0xce6a3b14,86
selection: 0xce6a3b66,87
rule_own: 0x6a3a25,88
badge_muted: 0x3f3f42,89
toast_mention: 0x2e1d15,90
green: 0x22c55e,91
red: 0xef4444,92
red_soft: 0xf87171,93
red_tint: 0xfca5a5,94
amber: 0xfbbf24,95
out_of_office: 0xc239b3,96
close_button_hover: 0xc42b1c,97
close_button_pressed: 0xb5271a,98
meeting_avatar: 0x4f52b2,99
bot_avatar: 0x3a96dd,100
avatar_palette: [0x9a4a22, 0x44606e, 0x8a3434, 0x4f6a3c, 0x6a4f7a, 0x2f6b63],101
};102
103
pub const TEAMS: ColorScheme = ColorScheme {104
id: "teams",105
name: "Teams",106
background: 0x0a0a0a,107
surface: 0x1f1f1f,108
surface_raised: 0x2e2e2e,109
row_hover: 0x292929,110
popup: 0x333333,111
popup_hover: 0x3d3d3d,112
popup_nested: 0x424242,113
popup_nested_hover: 0x4d4d4d,114
reply_surface: 0x242424,115
border: 0x333333,116
border_strong: 0x3d3d3d,117
foreground: 0xffffff,118
text_strong: 0xe0e0e0,119
text_soft: 0xd6d6d6,120
text_muted: 0xadadad,121
text_faint: 0x999999,122
accent: 0x5b5fc7,123
accent_text: 0x7f85f5,124
accent_soft: 0xaab1fa,125
accent_strong: 0x444791,126
on_accent: 0xffffff,127
bubble_own: 0x2f2f4a,128
bubble_other: 0x292929,129
reaction_on_own: 0x383966,130
mention_background: 0x2f2f4a,131
mention_background_own: 0x3d3e78,132
own_meta: 0xadadad,133
own_read: 0xaab1fa,134
drop_background: 0x5b5fc714,135
selection: 0x5b5fc766,136
rule_own: 0x444791,137
badge_muted: 0x3d3d3d,138
toast_mention: 0x2f2f4a,139
green: 0x92c353,140
red: 0xc4314b,141
red_soft: 0xe37d80,142
red_tint: 0xf1bbbc,143
amber: 0xffaa44,144
out_of_office: 0xc239b3,145
close_button_hover: 0xc4314b,146
close_button_pressed: 0xa72037,147
meeting_avatar: 0x4f52b2,148
bot_avatar: 0x3a96dd,149
avatar_palette: [0x9a4a22, 0x44606e, 0x8a3434, 0x4f6a3c, 0x6a4f7a, 0x2f6b63],150
};151
152
pub const SCHEMES: [&ColorScheme; 2] = [&RUSTY_TEAMS, &TEAMS];153
154
static ACTIVE_SCHEME: AtomicUsize = AtomicUsize::new(0);155
156
thread_local! {157
static THREAD_SCHEME: Cell<Option<usize>> = const { Cell::new(None) };158
}159
160
pub fn default_scheme() -> &'static ColorScheme {161
SCHEMES[0]162
}163
164
pub fn scheme_by_id(id: &str) -> Option<&'static ColorScheme> {165
SCHEMES.into_iter().find(|scheme| scheme.id == id)166
}167
168
fn position(id: &str) -> usize {169
SCHEMES170
.iter()171
.position(|scheme| scheme.id == id)172
.unwrap_or(0)173
}174
175
pub fn active_scheme() -> &'static ColorScheme {176
let index = THREAD_SCHEME177
.with(Cell::get)178
.unwrap_or_else(|| ACTIVE_SCHEME.load(Ordering::Relaxed));179
SCHEMES[index.min(SCHEMES.len() - 1)]180
}181
182
pub fn set_active_scheme(id: &str) {183
ACTIVE_SCHEME.store(position(id), Ordering::Relaxed);184
}185
186
pub fn set_thread_scheme(id: Option<&str>) {187
THREAD_SCHEME.with(|cell| cell.set(id.map(position)));188
}189
190
#[cfg(test)]191
mod tests {192
use std::collections::HashSet;193
194
use super::*;195
196
#[test]197
fn scheme_ids_and_names_are_unique() {198
let ids: HashSet<_> = SCHEMES.iter().map(|scheme| scheme.id).collect();199
let names: HashSet<_> = SCHEMES.iter().map(|scheme| scheme.name).collect();200
assert_eq!(ids.len(), SCHEMES.len());201
assert_eq!(names.len(), SCHEMES.len());202
}203
204
#[test]205
fn rusty_teams_is_the_default() {206
assert_eq!(default_scheme().id, "rusty-teams");207
assert_eq!(scheme_by_id("teams"), Some(&TEAMS));208
assert_eq!(scheme_by_id("solarized"), None);209
}210
211
#[test]212
fn teams_scheme_uses_the_teams_dark_brand_ramp() {213
assert_eq!(TEAMS.accent_text, 0x7f85f5);214
assert_eq!(TEAMS.bubble_own, 0x2f2f4a);215
assert_eq!(TEAMS.surface, 0x1f1f1f);216
}217
218
#[test]219
fn every_scheme_layers_its_surfaces_from_dark_to_light() {220
for scheme in SCHEMES {221
let layers = [222
scheme.background,223
scheme.surface,224
scheme.reply_surface,225
scheme.row_hover,226
scheme.surface_raised,227
scheme.popup,228
scheme.popup_hover,229
];230
assert!(231
layers.windows(2).all(|pair| pair[0] < pair[1]),232
"{} surfaces are not ordered dark to light",233
scheme.id234
);235
assert!(scheme.popup_nested > scheme.popup, "{}", scheme.id);236
assert!(237
scheme.popup_nested_hover > scheme.popup_nested,238
"{}",239
scheme.id240
);241
}242
}243
244
#[test]245
fn a_thread_override_wins_over_the_process_scheme() {246
set_thread_scheme(Some("teams"));247
assert_eq!(active_scheme().id, "teams");248
set_thread_scheme(Some("unknown"));249
assert_eq!(active_scheme().id, "rusty-teams");250
set_thread_scheme(None);251
}252
}@@ -45,7 +45,7 @@ pub mod typing;
45
45
46
46
pub use app_ui_kit::render;
47
47
pub use app_base::{
48
APP_NAME, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,
48
APP_NAME, appearance, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,
49
49
demo_input_cards, demo_library, demo_recap, diagnostics, downloads, format, frame_log, fuzzy,
50
50
emoticons, image_clipboard, image_view_math, inline_image, presence_link, read_state, recap, remote_image, runtime, schedule_time,
51
51
single_instance, stickers, theme, translation, updater, user_activity,
@@ -45,7 +45,7 @@ pub mod typing;45
45
46
pub use app_ui_kit::render;46
pub use app_ui_kit::render;47
pub use app_base::{47
pub use app_base::{48
APP_NAME, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,48
APP_NAME, appearance, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,49
demo_input_cards, demo_library, demo_recap, diagnostics, downloads, format, frame_log, fuzzy,49
demo_input_cards, demo_library, demo_recap, diagnostics, downloads, format, frame_log, fuzzy,50
emoticons, image_clipboard, image_view_math, inline_image, presence_link, read_state, recap, remote_image, runtime, schedule_time,50
emoticons, image_clipboard, image_view_math, inline_image, presence_link, read_state, recap, remote_image, runtime, schedule_time,51
single_instance, stickers, theme, translation, updater, user_activity,51
single_instance, stickers, theme, translation, updater, user_activity,@@ -6,6 +6,7 @@ use crate::app_state::{AppEvent, AppState};
6
6
pub enum SettingsSection {
7
7
General,
8
8
Notifications,
9
Appearance,
9
10
Chats,
10
11
Calls,
11
12
Devices,
@@ -6,6 +6,7 @@ use crate::app_state::{AppEvent, AppState};6
pub enum SettingsSection {6
pub enum SettingsSection {7
General,7
General,8
Notifications,8
Notifications,9
Appearance,9
Chats,10
Chats,10
Calls,11
Calls,11
Devices,12
Devices,@@ -56,7 +56,7 @@ async fn run(
56
56
};
57
57
let page_html = HostPage {
58
58
task_url: &dialog.url,
59
background: theme::BACKGROUND,
59
background: theme::background_hex(),
60
60
token_acquirer_script: &session::token_acquirer_script(),
61
61
}
62
62
.html();
@@ -64,7 +64,7 @@ async fn run(
64
64
title: dialog.title.clone(),
65
65
width: dialog.width,
66
66
height: dialog.height,
67
background: theme::BACKGROUND,
67
background: theme::background_hex(),
68
68
owner,
69
69
page_url: sdk::host_page_url(),
70
70
page_html,
@@ -56,7 +56,7 @@ async fn run(56
};56
};57
let page_html = HostPage {57
let page_html = HostPage {58
task_url: &dialog.url,58
task_url: &dialog.url,59
background: theme::BACKGROUND,59
background: theme::background_hex(),60
token_acquirer_script: &session::token_acquirer_script(),60
token_acquirer_script: &session::token_acquirer_script(),61
}61
}62
.html();62
.html();@@ -64,7 +64,7 @@ async fn run(64
title: dialog.title.clone(),64
title: dialog.title.clone(),65
width: dialog.width,65
width: dialog.width,66
height: dialog.height,66
height: dialog.height,67
background: theme::BACKGROUND,67
background: theme::background_hex(),68
owner,68
owner,69
page_url: sdk::host_page_url(),69
page_url: sdk::host_page_url(),70
page_html,70
page_html,The contents of this binary file are not shown.
@@ -0,0 +1,76 @@
1
use gpui_kit::*;
2
use store::Store;
3
4
use crate::appearance::{self, AppIcon, AppearanceSettings};
5
use crate::theme::{self, ColorScheme};
6
7
#[derive(Default)]
8
pub struct ActiveAppearance {
9
settings: AppearanceSettings,
10
}
11
12
impl Global for ActiveAppearance {}
13
14
pub fn install(store: &Store, cx: &mut App) {
15
let settings = appearance::load(store);
16
theme::set_active_scheme(settings.color_scheme.id);
17
cx.set_global(ActiveAppearance { settings });
18
}
19
20
pub fn current(cx: &App) -> AppearanceSettings {
21
cx.try_global::<ActiveAppearance>()
22
.map(|active| active.settings)
23
.unwrap_or_default()
24
}
25
26
pub fn set_color_scheme(scheme: &'static ColorScheme, store: &Store, cx: &mut App) {
27
let settings = AppearanceSettings {
28
color_scheme: scheme,
29
..current(cx)
30
};
31
appearance::save(store, &settings);
32
theme::set_active_scheme(scheme.id);
33
theme::apply(cx);
34
cx.set_global(ActiveAppearance { settings });
35
cx.refresh_windows();
36
}
37
38
pub fn set_app_icon(icon: AppIcon, store: &Store, cx: &mut App) {
39
let settings = AppearanceSettings {
40
app_icon: icon,
41
..current(cx)
42
};
43
appearance::save(store, &settings);
44
cx.set_global(ActiveAppearance { settings });
45
cx.refresh_windows();
46
}
47
48
#[cfg(test)]
49
mod tests {
50
use gpui_kit::TestAppContext;
51
use store::Store;
52
53
use super::{current, install, set_app_icon, set_color_scheme};
54
use crate::appearance::{self, AppIcon, AppearanceSettings};
55
use crate::theme;
56
57
#[gpui_kit::test]
58
fn switching_saves_and_applies_live(cx: &mut TestAppContext) {
59
let store = Store::open_in_memory().expect("in-memory store");
60
cx.update(|cx| {
61
gpui_kit::init(cx);
62
install(&store, cx);
63
theme::set_thread_scheme(None);
64
assert_eq!(current(cx), AppearanceSettings::default());
65
let teams = theme::scheme_by_id("teams").expect("teams scheme");
66
set_color_scheme(teams, &store, cx);
67
set_app_icon(AppIcon::MicrosoftTeams, &store, cx);
68
assert_eq!(theme::scheme().id, "teams");
69
assert_eq!(theme::accent(), theme::color(teams.accent));
70
assert_eq!(appearance::load(&store), current(cx));
71
assert_eq!(current(cx).app_icon, AppIcon::MicrosoftTeams);
72
set_color_scheme(theme::default_scheme(), &store, cx);
73
assert_eq!(theme::scheme().id, "rusty-teams");
74
});
75
}
76
}
@@ -0,0 +1,76 @@1
use gpui_kit::*;2
use store::Store;3
4
use crate::appearance::{self, AppIcon, AppearanceSettings};5
use crate::theme::{self, ColorScheme};6
7
#[derive(Default)]8
pub struct ActiveAppearance {9
settings: AppearanceSettings,10
}11
12
impl Global for ActiveAppearance {}13
14
pub fn install(store: &Store, cx: &mut App) {15
let settings = appearance::load(store);16
theme::set_active_scheme(settings.color_scheme.id);17
cx.set_global(ActiveAppearance { settings });18
}19
20
pub fn current(cx: &App) -> AppearanceSettings {21
cx.try_global::<ActiveAppearance>()22
.map(|active| active.settings)23
.unwrap_or_default()24
}25
26
pub fn set_color_scheme(scheme: &'static ColorScheme, store: &Store, cx: &mut App) {27
let settings = AppearanceSettings {28
color_scheme: scheme,29
..current(cx)30
};31
appearance::save(store, &settings);32
theme::set_active_scheme(scheme.id);33
theme::apply(cx);34
cx.set_global(ActiveAppearance { settings });35
cx.refresh_windows();36
}37
38
pub fn set_app_icon(icon: AppIcon, store: &Store, cx: &mut App) {39
let settings = AppearanceSettings {40
app_icon: icon,41
..current(cx)42
};43
appearance::save(store, &settings);44
cx.set_global(ActiveAppearance { settings });45
cx.refresh_windows();46
}47
48
#[cfg(test)]49
mod tests {50
use gpui_kit::TestAppContext;51
use store::Store;52
53
use super::{current, install, set_app_icon, set_color_scheme};54
use crate::appearance::{self, AppIcon, AppearanceSettings};55
use crate::theme;56
57
#[gpui_kit::test]58
fn switching_saves_and_applies_live(cx: &mut TestAppContext) {59
let store = Store::open_in_memory().expect("in-memory store");60
cx.update(|cx| {61
gpui_kit::init(cx);62
install(&store, cx);63
theme::set_thread_scheme(None);64
assert_eq!(current(cx), AppearanceSettings::default());65
let teams = theme::scheme_by_id("teams").expect("teams scheme");66
set_color_scheme(teams, &store, cx);67
set_app_icon(AppIcon::MicrosoftTeams, &store, cx);68
assert_eq!(theme::scheme().id, "teams");69
assert_eq!(theme::accent(), theme::color(teams.accent));70
assert_eq!(appearance::load(&store), current(cx));71
assert_eq!(current(cx).app_icon, AppIcon::MicrosoftTeams);72
set_color_scheme(theme::default_scheme(), &store, cx);73
assert_eq!(theme::scheme().id, "rusty-teams");74
});75
}76
}@@ -289,9 +289,10 @@ mod frames {
289
289
SettingsSection::Agents,
290
290
"Agents pages carry their own PAGE_PADDING side inset, the body narrows its side padding to keep the text edge",
291
291
)];
292
const SETTINGS_SECTIONS: [SettingsSection; 8] = [
292
const SETTINGS_SECTIONS: [SettingsSection; 9] = [
293
293
SettingsSection::General,
294
294
SettingsSection::Notifications,
295
SettingsSection::Appearance,
295
296
SettingsSection::Chats,
296
297
SettingsSection::Calls,
297
298
SettingsSection::Devices,
@@ -1005,6 +1006,17 @@ mod frames {
1005
1006
1006
1007
#[gpui_kit::test]
1007
1008
fn settings_dialog_keeps_its_inset_at_every_size(cx: &mut TestAppContext) {
1009
check_settings_dialog(cx, &SETTINGS_SECTIONS);
1010
}
1011
1012
#[gpui_kit::test]
1013
fn settings_dialog_keeps_its_inset_in_the_teams_scheme(cx: &mut TestAppContext) {
1014
crate::theme::set_thread_scheme(Some("teams"));
1015
check_settings_dialog(cx, &[SettingsSection::Appearance, SettingsSection::General]);
1016
crate::theme::set_thread_scheme(None);
1017
}
1018
1019
fn check_settings_dialog(cx: &mut TestAppContext, sections: &[SettingsSection]) {
1008
1020
let (handle, state) = mount_with(cx, true);
1009
1021
let mut visual = VisualTestContext::from_window(handle, cx);
1010
1022
for (width, height) in SIZES.into_iter().chain([(960., 640.)]) {
@@ -1014,7 +1026,7 @@ mod frames {
1014
1026
size: size(px(width), px(height)),
1015
1027
};
1016
1028
let inset = metrics(width, height).inset;
1017
for section in SETTINGS_SECTIONS {
1029
for §ion in sections {
1018
1030
visual
1019
1031
.update(|_, cx| state.update(cx, |state, cx| state.open_settings(section, cx)));
1020
1032
let tags = collect(&mut visual, Some(SETTINGS_TAGS[0]));
@@ -289,9 +289,10 @@ mod frames {289
SettingsSection::Agents,289
SettingsSection::Agents,290
"Agents pages carry their own PAGE_PADDING side inset, the body narrows its side padding to keep the text edge",290
"Agents pages carry their own PAGE_PADDING side inset, the body narrows its side padding to keep the text edge",291
)];291
)];292
const SETTINGS_SECTIONS: [SettingsSection; 8] = [292
const SETTINGS_SECTIONS: [SettingsSection; 9] = [293
SettingsSection::General,293
SettingsSection::General,294
SettingsSection::Notifications,294
SettingsSection::Notifications,295
SettingsSection::Appearance,295
SettingsSection::Chats,296
SettingsSection::Chats,296
SettingsSection::Calls,297
SettingsSection::Calls,297
SettingsSection::Devices,298
SettingsSection::Devices,@@ -1005,6 +1006,17 @@ mod frames {1005
1006
1006
#[gpui_kit::test]1007
#[gpui_kit::test]1007
fn settings_dialog_keeps_its_inset_at_every_size(cx: &mut TestAppContext) {1008
fn settings_dialog_keeps_its_inset_at_every_size(cx: &mut TestAppContext) {1009
check_settings_dialog(cx, &SETTINGS_SECTIONS);1010
}1011
1012
#[gpui_kit::test]1013
fn settings_dialog_keeps_its_inset_in_the_teams_scheme(cx: &mut TestAppContext) {1014
crate::theme::set_thread_scheme(Some("teams"));1015
check_settings_dialog(cx, &[SettingsSection::Appearance, SettingsSection::General]);1016
crate::theme::set_thread_scheme(None);1017
}1018
1019
fn check_settings_dialog(cx: &mut TestAppContext, sections: &[SettingsSection]) {1008
let (handle, state) = mount_with(cx, true);1020
let (handle, state) = mount_with(cx, true);1009
let mut visual = VisualTestContext::from_window(handle, cx);1021
let mut visual = VisualTestContext::from_window(handle, cx);1010
for (width, height) in SIZES.into_iter().chain([(960., 640.)]) {1022
for (width, height) in SIZES.into_iter().chain([(960., 640.)]) {@@ -1014,7 +1026,7 @@ mod frames {1014
size: size(px(width), px(height)),1026
size: size(px(width), px(height)),1015
};1027
};1016
let inset = metrics(width, height).inset;1028
let inset = metrics(width, height).inset;1017
for section in SETTINGS_SECTIONS {1029
for §ion in sections {1018
visual1030
visual1019
.update(|_, cx| state.update(cx, |state, cx| state.open_settings(section, cx)));1031
.update(|_, cx| state.update(cx, |state, cx| state.open_settings(section, cx)));1020
let tags = collect(&mut visual, Some(SETTINGS_TAGS[0]));1032
let tags = collect(&mut visual, Some(SETTINGS_TAGS[0]));@@ -3,6 +3,7 @@
3
3
windows_subsystem = "windows"
4
4
)]
5
5
6
mod active_appearance;
6
7
pub mod agents;
7
8
pub mod call;
8
9
#[cfg(test)]
@@ -190,6 +191,7 @@ fn main() {
190
191
})
191
192
.detach();
192
193
theme::load_fonts(cx);
194
active_appearance::install(&store, cx);
193
195
theme::apply(cx);
194
196
bind_keys(cx);
195
197
let state = cx.new(|_| {
@@ -3,6 +3,7 @@3
windows_subsystem = "windows"3
windows_subsystem = "windows"4
)]4
)]5
5
6
mod active_appearance;6
pub mod agents;7
pub mod agents;7
pub mod call;8
pub mod call;8
#[cfg(test)]9
#[cfg(test)]@@ -190,6 +191,7 @@ fn main() {190
})191
})191
.detach();192
.detach();192
theme::load_fonts(cx);193
theme::load_fonts(cx);194
active_appearance::install(&store, cx);193
theme::apply(cx);195
theme::apply(cx);194
bind_keys(cx);196
bind_keys(cx);195
let state = cx.new(|_| {197
let state = cx.new(|_| {@@ -24,9 +24,11 @@ use super::stack::{
24
24
use super::taskbar::taskbar_badge_count;
25
25
use super::text::describe;
26
26
use super::toast::{PillView, ToastView};
27
use crate::active_appearance::{self, ActiveAppearance};
27
28
use crate::activity::ActivityCenter;
28
29
use crate::agents::{AgentRun, AgentRunsEvent, RunState};
29
30
use crate::app_state::{AppEvent, AppState, selection_for};
31
use crate::appearance::AppIcon;
30
32
use crate::call::DemoScene;
31
33
use crate::data::{self, Directory, PresenceKind};
32
34
use crate::runtime;
@@ -88,10 +90,12 @@ pub struct NotificationCenter {
88
90
hover_hold: bool,
89
91
unread_mentions: HashSet<String>,
90
92
tray: Option<Tray>,
93
app_icon: AppIcon,
91
94
shown_badge: Option<Badge>,
92
95
animations: bool,
93
96
_subscription: Subscription,
94
97
_activity_observation: Subscription,
98
_appearance_observation: Subscription,
95
99
_agent_subscription: Option<Subscription>,
96
100
}
97
101
@@ -103,11 +107,20 @@ impl NotificationCenter {
103
107
cx: &mut Context<Self>,
104
108
) -> Self {
105
109
let settings = settings::load(&app.read(cx).store);
110
let app_icon = active_appearance::current(cx).app_icon;
106
111
let tray = if app.read(cx).mode.demo {
107
112
None
108
113
} else {
109
Tray::new(settings.sounds.notification_sound, settings.do_not_disturb)
114
Tray::new(
115
settings.sounds.notification_sound,
116
settings.do_not_disturb,
117
app_icon.png(),
118
)
110
119
};
120
platform::set_window_icon(window, app_icon.png());
121
let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {
122
this.apply_app_icon(active_appearance::current(cx).app_icon, cx)
123
});
111
124
let subscription = cx.subscribe(&app, |this, _, event: &AppEvent, cx| {
112
125
this.on_app_event(event, cx);
113
126
});
@@ -142,12 +155,14 @@ impl NotificationCenter {
142
155
hover_hold: false,
143
156
unread_mentions: HashSet::new(),
144
157
tray,
158
app_icon,
145
159
shown_badge: None,
146
160
animations: platform::animations_enabled(),
147
161
app,
148
162
activity,
149
163
_subscription: subscription,
150
164
_activity_observation: activity_observation,
165
_appearance_observation: appearance_observation,
151
166
_agent_subscription: agent_subscription,
152
167
};
153
168
cx.spawn(async move |this, cx| {
@@ -903,6 +918,20 @@ impl NotificationCenter {
903
918
.ok();
904
919
}
905
920
921
fn apply_app_icon(&mut self, icon: AppIcon, cx: &mut Context<Self>) {
922
if icon == self.app_icon {
923
return;
924
}
925
self.app_icon = icon;
926
let mention = !self.unread_mentions.is_empty();
927
if let Some(tray) = &mut self.tray {
928
tray.set_app_icon(icon.png(), mention);
929
}
930
let _ = self.main_window.update(cx, |_, window, _| {
931
platform::set_window_icon(window, icon.png())
932
});
933
}
934
906
935
fn sync_tray(&self) {
907
936
if let Some(tray) = &self.tray {
908
937
tray.sync(
@@ -24,9 +24,11 @@ use super::stack::{24
use super::taskbar::taskbar_badge_count;24
use super::taskbar::taskbar_badge_count;25
use super::text::describe;25
use super::text::describe;26
use super::toast::{PillView, ToastView};26
use super::toast::{PillView, ToastView};27
use crate::active_appearance::{self, ActiveAppearance};27
use crate::activity::ActivityCenter;28
use crate::activity::ActivityCenter;28
use crate::agents::{AgentRun, AgentRunsEvent, RunState};29
use crate::agents::{AgentRun, AgentRunsEvent, RunState};29
use crate::app_state::{AppEvent, AppState, selection_for};30
use crate::app_state::{AppEvent, AppState, selection_for};31
use crate::appearance::AppIcon;30
use crate::call::DemoScene;32
use crate::call::DemoScene;31
use crate::data::{self, Directory, PresenceKind};33
use crate::data::{self, Directory, PresenceKind};32
use crate::runtime;34
use crate::runtime;@@ -88,10 +90,12 @@ pub struct NotificationCenter {88
hover_hold: bool,90
hover_hold: bool,89
unread_mentions: HashSet<String>,91
unread_mentions: HashSet<String>,90
tray: Option<Tray>,92
tray: Option<Tray>,93
app_icon: AppIcon,91
shown_badge: Option<Badge>,94
shown_badge: Option<Badge>,92
animations: bool,95
animations: bool,93
_subscription: Subscription,96
_subscription: Subscription,94
_activity_observation: Subscription,97
_activity_observation: Subscription,98
_appearance_observation: Subscription,95
_agent_subscription: Option<Subscription>,99
_agent_subscription: Option<Subscription>,96
}100
}97
101
@@ -103,11 +107,20 @@ impl NotificationCenter {103
cx: &mut Context<Self>,107
cx: &mut Context<Self>,104
) -> Self {108
) -> Self {105
let settings = settings::load(&app.read(cx).store);109
let settings = settings::load(&app.read(cx).store);110
let app_icon = active_appearance::current(cx).app_icon;106
let tray = if app.read(cx).mode.demo {111
let tray = if app.read(cx).mode.demo {107
None112
None108
} else {113
} else {109
Tray::new(settings.sounds.notification_sound, settings.do_not_disturb)114
Tray::new(115
settings.sounds.notification_sound,116
settings.do_not_disturb,117
app_icon.png(),118
)110
};119
};120
platform::set_window_icon(window, app_icon.png());121
let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {122
this.apply_app_icon(active_appearance::current(cx).app_icon, cx)123
});111
let subscription = cx.subscribe(&app, |this, _, event: &AppEvent, cx| {124
let subscription = cx.subscribe(&app, |this, _, event: &AppEvent, cx| {112
this.on_app_event(event, cx);125
this.on_app_event(event, cx);113
});126
});@@ -142,12 +155,14 @@ impl NotificationCenter {142
hover_hold: false,155
hover_hold: false,143
unread_mentions: HashSet::new(),156
unread_mentions: HashSet::new(),144
tray,157
tray,158
app_icon,145
shown_badge: None,159
shown_badge: None,146
animations: platform::animations_enabled(),160
animations: platform::animations_enabled(),147
app,161
app,148
activity,162
activity,149
_subscription: subscription,163
_subscription: subscription,150
_activity_observation: activity_observation,164
_activity_observation: activity_observation,165
_appearance_observation: appearance_observation,151
_agent_subscription: agent_subscription,166
_agent_subscription: agent_subscription,152
};167
};153
cx.spawn(async move |this, cx| {168
cx.spawn(async move |this, cx| {@@ -903,6 +918,20 @@ impl NotificationCenter {903
.ok();918
.ok();904
}919
}905
920
921
fn apply_app_icon(&mut self, icon: AppIcon, cx: &mut Context<Self>) {922
if icon == self.app_icon {923
return;924
}925
self.app_icon = icon;926
let mention = !self.unread_mentions.is_empty();927
if let Some(tray) = &mut self.tray {928
tray.set_app_icon(icon.png(), mention);929
}930
let _ = self.main_window.update(cx, |_, window, _| {931
platform::set_window_icon(window, icon.png())932
});933
}934
906
fn sync_tray(&self) {935
fn sync_tray(&self) {907
if let Some(tray) = &self.tray {936
if let Some(tray) = &self.tray {908
tray.sync(937
tray.sync(@@ -0,0 +1,199 @@
1
use gpui_kit::component::{h_flex, v_flex};
2
use gpui_kit::prelude::FluentBuilder as _;
3
use gpui_kit::*;
4
5
use super::rows::{ROW_INSET, caption, titled};
6
use crate::active_appearance;
7
use crate::app_state::AppState;
8
use crate::appearance::AppIcon;
9
use crate::theme::{self, ColorScheme};
10
use crate::views::title_bar::app_icon_image;
11
12
const TILE_WIDTH: f32 = 168.;
13
const TILE_PADDING: f32 = 8.;
14
const TILE_GAP: f32 = 12.;
15
const TILE_RADIUS: f32 = 12.;
16
const PREVIEW_HEIGHT: f32 = 96.;
17
const PREVIEW_RADIUS: f32 = TILE_RADIUS - TILE_PADDING;
18
const PREVIEW_ICON_SIZE: f32 = 48.;
19
const RADIO_SIZE: f32 = 16.;
20
const RADIO_DOT_SIZE: f32 = 8.;
21
const COLOR_SCHEME_DETAIL: &str = "The colors to use for Rusty Teams";
22
#[cfg(windows)]
23
const APP_ICON_DETAIL: &str =
24
"Shown in the title bar, taskbar and tray. Pinned shortcuts keep the icon of the .exe";
25
#[cfg(not(windows))]
26
const APP_ICON_DETAIL: &str = "Shown in the title bar, taskbar and tray";
27
28
pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
29
let current = active_appearance::current(cx);
30
let scheme_tiles = theme::SCHEMES.into_iter().map(|scheme| {
31
let app = app.clone();
32
tile(
33
SharedString::from(format!("settings-color-scheme-{}", scheme.id)),
34
scheme.name,
35
scheme.id == current.color_scheme.id,
36
scheme_preview(scheme),
37
)
38
.on_click(move |_, _, cx| {
39
let store = app.read(cx).store.clone();
40
active_appearance::set_color_scheme(scheme, &store, cx);
41
})
42
});
43
let icon_tiles = AppIcon::ALL.into_iter().map(|icon| {
44
let app = app.clone();
45
tile(
46
SharedString::from(format!("settings-app-icon-{}", icon.key())),
47
icon.label(),
48
icon == current.app_icon,
49
icon_preview(icon),
50
)
51
.on_click(move |_, _, cx| {
52
let store = app.read(cx).store.clone();
53
active_appearance::set_app_icon(icon, &store, cx);
54
})
55
});
56
v_flex()
57
.w_full()
58
.child(caption("THEME"))
59
.child(choice_group(
60
"Color scheme",
61
COLOR_SCHEME_DETAIL,
62
scheme_tiles,
63
))
64
.child(caption("APP ICON"))
65
.child(choice_group("App icon", APP_ICON_DETAIL, icon_tiles))
66
}
67
68
fn choice_group(
69
title: &'static str,
70
detail: &'static str,
71
tiles: impl Iterator<Item = Stateful<Div>>,
72
) -> Div {
73
v_flex()
74
.w_full()
75
.px(px(ROW_INSET))
76
.py(px(12.))
77
.gap(px(12.))
78
.child(titled(title, detail, theme::text_muted()))
79
.child(
80
h_flex()
81
.w_full()
82
.flex_wrap()
83
.gap(px(TILE_GAP))
84
.children(tiles),
85
)
86
}
87
88
fn tile(id: SharedString, label: &'static str, selected: bool, preview: Div) -> Stateful<Div> {
89
v_flex()
90
.id(id)
91
.w(px(TILE_WIDTH))
92
.flex_none()
93
.p(px(TILE_PADDING))
94
.gap(px(TILE_PADDING))
95
.rounded(px(TILE_RADIUS))
96
.bg(theme::surface_raised())
97
.cursor_pointer()
98
.hover(|tile| tile.bg(theme::popup_hover()))
99
.child(preview)
100
.child(
101
h_flex()
102
.w_full()
103
.px(px(TILE_PADDING / 2.))
104
.pb(px(TILE_PADDING / 2.))
105
.items_center()
106
.justify_between()
107
.child(
108
div()
109
.text_size(px(14.))
110
.line_height(px(20.))
111
.text_color(theme::text())
112
.child(label),
113
)
114
.child(radio(selected)),
115
)
116
}
117
118
fn radio(selected: bool) -> Div {
119
div()
120
.size(px(RADIO_SIZE))
121
.flex_none()
122
.flex()
123
.items_center()
124
.justify_center()
125
.rounded_full()
126
.border_1()
127
.border_color(if selected {
128
theme::accent()
129
} else {
130
theme::text_muted()
131
})
132
.when(selected, |radio| {
133
radio.child(
134
div()
135
.size(px(RADIO_DOT_SIZE))
136
.rounded_full()
137
.bg(theme::accent()),
138
)
139
})
140
}
141
142
fn preview_frame(background: Hsla) -> Div {
143
div()
144
.w_full()
145
.h(px(PREVIEW_HEIGHT))
146
.rounded(px(PREVIEW_RADIUS))
147
.overflow_hidden()
148
.bg(background)
149
}
150
151
fn scheme_preview(scheme: &ColorScheme) -> Div {
152
let fill = |hex: u32| theme::color(hex);
153
let bubble = |hex: u32, width: f32| div().w(px(width)).h(px(12.)).rounded(px(6.)).bg(fill(hex));
154
preview_frame(fill(scheme.background)).child(
155
h_flex()
156
.size_full()
157
.p(px(6.))
158
.gap(px(6.))
159
.child(
160
v_flex()
161
.w(px(14.))
162
.h_full()
163
.gap(px(4.))
164
.items_center()
165
.child(
166
div()
167
.size(px(10.))
168
.rounded(px(3.))
169
.bg(fill(scheme.surface_raised)),
170
)
171
.child(div().size(px(10.)).rounded(px(3.)).bg(fill(scheme.accent))),
172
)
173
.child(
174
v_flex()
175
.flex_1()
176
.h_full()
177
.p(px(8.))
178
.gap(px(6.))
179
.rounded(px(6.))
180
.bg(fill(scheme.surface))
181
.child(h_flex().child(bubble(scheme.bubble_other, 64.)))
182
.child(h_flex().justify_end().child(bubble(scheme.bubble_own, 52.)))
183
.child(h_flex().child(bubble(scheme.bubble_other, 40.)))
184
.child(
185
h_flex()
186
.justify_end()
187
.child(div().size(px(12.)).rounded_full().bg(fill(scheme.accent))),
188
),
189
),
190
)
191
}
192
193
fn icon_preview(icon: AppIcon) -> Div {
194
preview_frame(theme::background())
195
.flex()
196
.items_center()
197
.justify_center()
198
.child(img(app_icon_image(icon)).size(px(PREVIEW_ICON_SIZE)))
199
}
@@ -0,0 +1,199 @@1
use gpui_kit::component::{h_flex, v_flex};2
use gpui_kit::prelude::FluentBuilder as _;3
use gpui_kit::*;4
5
use super::rows::{ROW_INSET, caption, titled};6
use crate::active_appearance;7
use crate::app_state::AppState;8
use crate::appearance::AppIcon;9
use crate::theme::{self, ColorScheme};10
use crate::views::title_bar::app_icon_image;11
12
const TILE_WIDTH: f32 = 168.;13
const TILE_PADDING: f32 = 8.;14
const TILE_GAP: f32 = 12.;15
const TILE_RADIUS: f32 = 12.;16
const PREVIEW_HEIGHT: f32 = 96.;17
const PREVIEW_RADIUS: f32 = TILE_RADIUS - TILE_PADDING;18
const PREVIEW_ICON_SIZE: f32 = 48.;19
const RADIO_SIZE: f32 = 16.;20
const RADIO_DOT_SIZE: f32 = 8.;21
const COLOR_SCHEME_DETAIL: &str = "The colors to use for Rusty Teams";22
#[cfg(windows)]23
const APP_ICON_DETAIL: &str =24
"Shown in the title bar, taskbar and tray. Pinned shortcuts keep the icon of the .exe";25
#[cfg(not(windows))]26
const APP_ICON_DETAIL: &str = "Shown in the title bar, taskbar and tray";27
28
pub fn render(app: &Entity<AppState>, cx: &App) -> Div {29
let current = active_appearance::current(cx);30
let scheme_tiles = theme::SCHEMES.into_iter().map(|scheme| {31
let app = app.clone();32
tile(33
SharedString::from(format!("settings-color-scheme-{}", scheme.id)),34
scheme.name,35
scheme.id == current.color_scheme.id,36
scheme_preview(scheme),37
)38
.on_click(move |_, _, cx| {39
let store = app.read(cx).store.clone();40
active_appearance::set_color_scheme(scheme, &store, cx);41
})42
});43
let icon_tiles = AppIcon::ALL.into_iter().map(|icon| {44
let app = app.clone();45
tile(46
SharedString::from(format!("settings-app-icon-{}", icon.key())),47
icon.label(),48
icon == current.app_icon,49
icon_preview(icon),50
)51
.on_click(move |_, _, cx| {52
let store = app.read(cx).store.clone();53
active_appearance::set_app_icon(icon, &store, cx);54
})55
});56
v_flex()57
.w_full()58
.child(caption("THEME"))59
.child(choice_group(60
"Color scheme",61
COLOR_SCHEME_DETAIL,62
scheme_tiles,63
))64
.child(caption("APP ICON"))65
.child(choice_group("App icon", APP_ICON_DETAIL, icon_tiles))66
}67
68
fn choice_group(69
title: &'static str,70
detail: &'static str,71
tiles: impl Iterator<Item = Stateful<Div>>,72
) -> Div {73
v_flex()74
.w_full()75
.px(px(ROW_INSET))76
.py(px(12.))77
.gap(px(12.))78
.child(titled(title, detail, theme::text_muted()))79
.child(80
h_flex()81
.w_full()82
.flex_wrap()83
.gap(px(TILE_GAP))84
.children(tiles),85
)86
}87
88
fn tile(id: SharedString, label: &'static str, selected: bool, preview: Div) -> Stateful<Div> {89
v_flex()90
.id(id)91
.w(px(TILE_WIDTH))92
.flex_none()93
.p(px(TILE_PADDING))94
.gap(px(TILE_PADDING))95
.rounded(px(TILE_RADIUS))96
.bg(theme::surface_raised())97
.cursor_pointer()98
.hover(|tile| tile.bg(theme::popup_hover()))99
.child(preview)100
.child(101
h_flex()102
.w_full()103
.px(px(TILE_PADDING / 2.))104
.pb(px(TILE_PADDING / 2.))105
.items_center()106
.justify_between()107
.child(108
div()109
.text_size(px(14.))110
.line_height(px(20.))111
.text_color(theme::text())112
.child(label),113
)114
.child(radio(selected)),115
)116
}117
118
fn radio(selected: bool) -> Div {119
div()120
.size(px(RADIO_SIZE))121
.flex_none()122
.flex()123
.items_center()124
.justify_center()125
.rounded_full()126
.border_1()127
.border_color(if selected {128
theme::accent()129
} else {130
theme::text_muted()131
})132
.when(selected, |radio| {133
radio.child(134
div()135
.size(px(RADIO_DOT_SIZE))136
.rounded_full()137
.bg(theme::accent()),138
)139
})140
}141
142
fn preview_frame(background: Hsla) -> Div {143
div()144
.w_full()145
.h(px(PREVIEW_HEIGHT))146
.rounded(px(PREVIEW_RADIUS))147
.overflow_hidden()148
.bg(background)149
}150
151
fn scheme_preview(scheme: &ColorScheme) -> Div {152
let fill = |hex: u32| theme::color(hex);153
let bubble = |hex: u32, width: f32| div().w(px(width)).h(px(12.)).rounded(px(6.)).bg(fill(hex));154
preview_frame(fill(scheme.background)).child(155
h_flex()156
.size_full()157
.p(px(6.))158
.gap(px(6.))159
.child(160
v_flex()161
.w(px(14.))162
.h_full()163
.gap(px(4.))164
.items_center()165
.child(166
div()167
.size(px(10.))168
.rounded(px(3.))169
.bg(fill(scheme.surface_raised)),170
)171
.child(div().size(px(10.)).rounded(px(3.)).bg(fill(scheme.accent))),172
)173
.child(174
v_flex()175
.flex_1()176
.h_full()177
.p(px(8.))178
.gap(px(6.))179
.rounded(px(6.))180
.bg(fill(scheme.surface))181
.child(h_flex().child(bubble(scheme.bubble_other, 64.)))182
.child(h_flex().justify_end().child(bubble(scheme.bubble_own, 52.)))183
.child(h_flex().child(bubble(scheme.bubble_other, 40.)))184
.child(185
h_flex()186
.justify_end()187
.child(div().size(px(12.)).rounded_full().bg(fill(scheme.accent))),188
),189
),190
)191
}192
193
fn icon_preview(icon: AppIcon) -> Div {194
preview_frame(theme::background())195
.flex()196
.items_center()197
.justify_center()198
.child(img(app_icon_image(icon)).size(px(PREVIEW_ICON_SIZE)))199
}@@ -7,7 +7,7 @@ use super::devices::DevicesView;
7
7
use super::mcp::McpView;
8
8
use super::nav::{NavLayout, label, render_nav};
9
9
use super::rows::ROW_INSET;
10
use super::{about, calls, chats, general, notifications};
10
use super::{about, appearance, calls, chats, general, notifications};
11
11
use crate::agents::AgentsSettings;
12
12
use crate::app_state::AppState;
13
13
use crate::notify::NotificationCenter;
@@ -135,6 +135,7 @@ impl SettingsDialog {
135
135
SettingsSection::Notifications => {
136
136
notifications::render(&self.center, cx).into_any_element()
137
137
}
138
SettingsSection::Appearance => appearance::render(&self.app, cx).into_any_element(),
138
139
SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),
139
140
SettingsSection::Calls => calls::render(&self.center, cx).into_any_element(),
140
141
SettingsSection::Devices => self
@@ -7,7 +7,7 @@ use super::devices::DevicesView;7
use super::mcp::McpView;7
use super::mcp::McpView;8
use super::nav::{NavLayout, label, render_nav};8
use super::nav::{NavLayout, label, render_nav};9
use super::rows::ROW_INSET;9
use super::rows::ROW_INSET;10
use super::{about, calls, chats, general, notifications};10
use super::{about, appearance, calls, chats, general, notifications};11
use crate::agents::AgentsSettings;11
use crate::agents::AgentsSettings;12
use crate::app_state::AppState;12
use crate::app_state::AppState;13
use crate::notify::NotificationCenter;13
use crate::notify::NotificationCenter;@@ -135,6 +135,7 @@ impl SettingsDialog {135
SettingsSection::Notifications => {135
SettingsSection::Notifications => {136
notifications::render(&self.center, cx).into_any_element()136
notifications::render(&self.center, cx).into_any_element()137
}137
}138
SettingsSection::Appearance => appearance::render(&self.app, cx).into_any_element(),138
SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),139
SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),139
SettingsSection::Calls => calls::render(&self.center, cx).into_any_element(),140
SettingsSection::Calls => calls::render(&self.center, cx).into_any_element(),140
SettingsSection::Devices => self141
SettingsSection::Devices => self@@ -1,4 +1,5 @@
1
1
mod about;
2
mod appearance;
2
3
mod calls;
3
4
mod chats;
4
5
mod devices;
@@ -1,4 +1,5 @@1
mod about;1
mod about;2
mod appearance;2
mod calls;3
mod calls;3
mod chats;4
mod chats;4
mod devices;5
mod devices;@@ -885,6 +885,7 @@ impl Render for AppShell {
885
885
)
886
886
});
887
887
let title_bar = render_title_bar(
888
crate::active_appearance::current(cx).app_icon,
888
889
mode_label(state.mode),
889
890
update_button(
890
891
&self.update,
@@ -885,6 +885,7 @@ impl Render for AppShell {885
)885
)886
});886
});887
let title_bar = render_title_bar(887
let title_bar = render_title_bar(888
crate::active_appearance::current(cx).app_icon,888
mode_label(state.mode),889
mode_label(state.mode),889
update_button(890
update_button(890
&self.update,891
&self.update,@@ -7,6 +7,7 @@ use gpui_kit::*;
7
7
8
8
use super::widgets::icon;
9
9
use crate::app_state::Mode;
10
use crate::appearance::AppIcon;
10
11
use crate::theme;
11
12
use crate::updater::UpdateStatus;
12
13
@@ -15,11 +16,16 @@ const SEARCH_WIDTH: f32 = 380.;
15
16
const SEARCH_HINT: &str = "Search chats, people and channels";
16
17
const SHORTCUT_HINT: &str = "Ctrl K";
17
18
const APP_ICON_SIZE: f32 = 18.;
18
const APP_ICON_PNG: &[u8] = include_bytes!("../../assets/icon/teams-fast-256.png");
19
19
20
fn app_icon() -> Arc<Image> {
21
static ICON: OnceLock<Arc<Image>> = OnceLock::new();
22
ICON.get_or_init(|| Arc::new(Image::from_bytes(ImageFormat::Png, APP_ICON_PNG.to_vec())))
20
pub fn app_icon_image(app_icon: AppIcon) -> Arc<Image> {
21
static IMAGES: [OnceLock<Arc<Image>>; AppIcon::ALL.len()] =
22
[const { OnceLock::new() }; AppIcon::ALL.len()];
23
let index = AppIcon::ALL
24
.iter()
25
.position(|candidate| *candidate == app_icon)
26
.unwrap_or(0);
27
IMAGES[index]
28
.get_or_init(|| Arc::new(Image::from_bytes(ImageFormat::Png, app_icon.png().to_vec())))
23
29
.clone()
24
30
}
25
31
@@ -89,6 +95,7 @@ pub fn update_button(
89
95
}
90
96
91
97
pub fn render_title_bar(
98
app_icon: AppIcon,
92
99
mode_label: Option<&'static str>,
93
100
update: Option<AnyElement>,
94
101
own: Option<AnyElement>,
@@ -130,7 +137,11 @@ pub fn render_title_bar(
130
137
.h_full()
131
138
.gap(px(12.))
132
139
.items_center()
133
.child(img(app_icon()).size(px(APP_ICON_SIZE)).flex_none())
140
.child(
141
img(app_icon_image(app_icon))
142
.size(px(APP_ICON_SIZE))
143
.flex_none(),
144
)
134
145
.child(
135
146
div()
136
147
.text_size(px(13.))
@@ -7,6 +7,7 @@ use gpui_kit::*;7
7
8
use super::widgets::icon;8
use super::widgets::icon;9
use crate::app_state::Mode;9
use crate::app_state::Mode;10
use crate::appearance::AppIcon;10
use crate::theme;11
use crate::theme;11
use crate::updater::UpdateStatus;12
use crate::updater::UpdateStatus;12
13
@@ -15,11 +16,16 @@ const SEARCH_WIDTH: f32 = 380.;15
const SEARCH_HINT: &str = "Search chats, people and channels";16
const SEARCH_HINT: &str = "Search chats, people and channels";16
const SHORTCUT_HINT: &str = "Ctrl K";17
const SHORTCUT_HINT: &str = "Ctrl K";17
const APP_ICON_SIZE: f32 = 18.;18
const APP_ICON_SIZE: f32 = 18.;18
const APP_ICON_PNG: &[u8] = include_bytes!("../../assets/icon/teams-fast-256.png");19
19
20
fn app_icon() -> Arc<Image> {20
pub fn app_icon_image(app_icon: AppIcon) -> Arc<Image> {21
static ICON: OnceLock<Arc<Image>> = OnceLock::new();21
static IMAGES: [OnceLock<Arc<Image>>; AppIcon::ALL.len()] =22
ICON.get_or_init(|| Arc::new(Image::from_bytes(ImageFormat::Png, APP_ICON_PNG.to_vec())))22
[const { OnceLock::new() }; AppIcon::ALL.len()];23
let index = AppIcon::ALL24
.iter()25
.position(|candidate| *candidate == app_icon)26
.unwrap_or(0);27
IMAGES[index]28
.get_or_init(|| Arc::new(Image::from_bytes(ImageFormat::Png, app_icon.png().to_vec())))23
.clone()29
.clone()24
}30
}25
31
@@ -89,6 +95,7 @@ pub fn update_button(89
}95
}90
96
91
pub fn render_title_bar(97
pub fn render_title_bar(98
app_icon: AppIcon,92
mode_label: Option<&'static str>,99
mode_label: Option<&'static str>,93
update: Option<AnyElement>,100
update: Option<AnyElement>,94
own: Option<AnyElement>,101
own: Option<AnyElement>,@@ -130,7 +137,11 @@ pub fn render_title_bar(130
.h_full()137
.h_full()131
.gap(px(12.))138
.gap(px(12.))132
.items_center()139
.items_center()133
.child(img(app_icon()).size(px(APP_ICON_SIZE)).flex_none())140
.child(141
img(app_icon_image(app_icon))142
.size(px(APP_ICON_SIZE))143
.flex_none(),144
)134
.child(145
.child(135
div()146
div()136
.text_size(px(13.))147
.text_size(px(13.))