Skip to repository content217 lines · 8.8 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T03:55:46.619Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
workspace_settings.rs
1use std::{num::NonZeroUsize, time::Duration};
2
3use crate::DockPosition;
4use collections::HashMap;
5use gpui::{App, Subscription};
6use serde::Deserialize;
7pub use settings::{
8 AutosaveSetting, BottomDockLayout, EncodingDisplayOptions, InactiveOpacity,
9 PaneSplitDirectionHorizontal, PaneSplitDirectionVertical, RegisterSetting,
10 RestoreOnStartupBehavior, Settings,
11};
12use settings::{CommandAliasTarget, SettingsStore};
13
14#[derive(RegisterSetting)]
15pub struct WorkspaceSettings {
16 pub active_pane_modifiers: ActivePanelModifiers,
17 pub bottom_dock_layout: settings::BottomDockLayout,
18 pub pane_split_direction_horizontal: settings::PaneSplitDirectionHorizontal,
19 pub pane_split_direction_vertical: settings::PaneSplitDirectionVertical,
20 pub centered_layout: settings::CenteredLayoutSettings,
21 pub confirm_quit: bool,
22 pub show_call_status_icon: bool,
23 pub autosave: AutosaveSetting,
24 pub restore_on_startup: settings::RestoreOnStartupBehavior,
25 pub cli_default_open_behavior: settings::CliDefaultOpenBehavior,
26 pub default_open_behavior: settings::DefaultOpenBehavior,
27 pub restore_on_file_reopen: bool,
28 pub drop_target_size: f32,
29 pub use_system_path_prompts: bool,
30 pub use_system_prompts: bool,
31 pub accessible_mode: bool,
32 pub command_aliases: HashMap<String, CommandAliasTarget>,
33 pub max_tabs: Option<NonZeroUsize>,
34 pub when_closing_with_no_tabs: settings::CloseWindowWhenNoItems,
35 pub on_last_window_closed: settings::OnLastWindowClosed,
36 pub text_rendering_mode: settings::TextRenderingMode,
37 pub resize_all_panels_in_dock: Vec<DockPosition>,
38 pub close_on_file_delete: bool,
39 pub close_panel_on_toggle: bool,
40 pub use_system_window_tabs: bool,
41 pub zoomed_padding: bool,
42 pub window_decorations: settings::WindowDecorations,
43 pub focus_follows_mouse: FocusFollowsMouse,
44}
45
46#[derive(Copy, Clone, Deserialize)]
47pub struct FocusFollowsMouse {
48 pub enabled: bool,
49 pub debounce: Duration,
50}
51
52#[derive(Copy, Clone, PartialEq, Debug, Default)]
53pub struct ActivePanelModifiers {
54 /// Size of the border surrounding the active pane.
55 /// When set to 0, the active pane doesn't have any border.
56 /// The border is drawn inset.
57 ///
58 /// Default: `0.0`
59 // TODO: make this not an option, it is never None
60 pub border_size: Option<f32>,
61 /// Opacity of inactive panels.
62 /// When set to 1.0, the inactive panes have the same opacity as the active one.
63 /// If set to 0, the inactive panes content will not be visible at all.
64 /// Values are clamped to the [0.0, 1.0] range.
65 ///
66 /// Default: `1.0`
67 // TODO: make this not an option, it is never None
68 pub inactive_opacity: Option<InactiveOpacity>,
69}
70
71#[derive(Deserialize, RegisterSetting)]
72pub struct TabBarSettings {
73 pub show: bool,
74 pub show_nav_history_buttons: bool,
75 pub show_tab_bar_buttons: bool,
76 pub show_pinned_tabs_in_separate_row: bool,
77}
78
79impl Settings for WorkspaceSettings {
80 fn from_settings(content: &settings::SettingsContent) -> Self {
81 let workspace = &content.workspace;
82 Self {
83 active_pane_modifiers: ActivePanelModifiers {
84 border_size: Some(
85 workspace
86 .active_pane_modifiers
87 .unwrap()
88 .border_size
89 .unwrap(),
90 ),
91 inactive_opacity: Some(
92 workspace
93 .active_pane_modifiers
94 .unwrap()
95 .inactive_opacity
96 .unwrap(),
97 ),
98 },
99 bottom_dock_layout: workspace.bottom_dock_layout.unwrap(),
100 pane_split_direction_horizontal: workspace.pane_split_direction_horizontal.unwrap(),
101 pane_split_direction_vertical: workspace.pane_split_direction_vertical.unwrap(),
102 centered_layout: workspace.centered_layout.unwrap(),
103 confirm_quit: workspace.confirm_quit.unwrap(),
104 show_call_status_icon: workspace.show_call_status_icon.unwrap(),
105 autosave: workspace.autosave.unwrap(),
106 restore_on_startup: workspace.restore_on_startup.unwrap(),
107 cli_default_open_behavior: workspace.cli_default_open_behavior.unwrap(),
108 default_open_behavior: workspace.default_open_behavior.unwrap(),
109 restore_on_file_reopen: workspace.restore_on_file_reopen.unwrap(),
110 drop_target_size: workspace.drop_target_size.unwrap(),
111 use_system_path_prompts: workspace.use_system_path_prompts.unwrap(),
112 use_system_prompts: workspace.use_system_prompts.unwrap(),
113 accessible_mode: workspace.accessible_mode.unwrap(),
114 command_aliases: workspace.command_aliases.clone(),
115 max_tabs: workspace.max_tabs,
116 when_closing_with_no_tabs: workspace.when_closing_with_no_tabs.unwrap(),
117 on_last_window_closed: workspace.on_last_window_closed.unwrap(),
118 text_rendering_mode: workspace.text_rendering_mode.unwrap(),
119 resize_all_panels_in_dock: workspace
120 .resize_all_panels_in_dock
121 .clone()
122 .unwrap()
123 .into_iter()
124 .map(Into::into)
125 .collect(),
126 close_on_file_delete: workspace.close_on_file_delete.unwrap(),
127 close_panel_on_toggle: workspace.close_panel_on_toggle.unwrap(),
128 use_system_window_tabs: workspace.use_system_window_tabs.unwrap(),
129 zoomed_padding: workspace.zoomed_padding.unwrap(),
130 window_decorations: workspace.window_decorations.unwrap(),
131 focus_follows_mouse: FocusFollowsMouse {
132 enabled: workspace
133 .focus_follows_mouse
134 .unwrap()
135 .enabled
136 .unwrap_or(false),
137 debounce: Duration::from_millis(
138 workspace
139 .focus_follows_mouse
140 .unwrap()
141 .debounce_ms
142 .unwrap_or(250),
143 ),
144 },
145 }
146 }
147}
148
149/// Provides convenient access to whether "accessible mode" is enabled, mirroring
150/// [`theme::ActiveTheme`] for the active theme. Import this trait to call
151/// `cx.accessible_mode()`.
152pub trait AccessibleMode {
153 /// Returns whether accessible mode is enabled.
154 fn accessible_mode(&self) -> bool;
155}
156
157impl AccessibleMode for App {
158 fn accessible_mode(&self) -> bool {
159 WorkspaceSettings::get_global(self).accessible_mode
160 }
161}
162
163/// Observes changes to the accessible-mode setting, invoking `callback` with the
164/// new value whenever it changes. Mirrors the common
165/// `cx.observe_global::<SettingsStore>` pattern, but only fires when the value
166/// actually changes. The returned [`Subscription`] must be retained for the
167/// callback to keep firing.
168pub fn observe_accessible_mode(
169 cx: &mut App,
170 mut callback: impl FnMut(bool, &mut App) + 'static,
171) -> Subscription {
172 let mut last = cx.accessible_mode();
173 cx.observe_global::<SettingsStore>(move |cx| {
174 let current = cx.accessible_mode();
175 if current != last {
176 last = current;
177 callback(current, cx);
178 }
179 })
180}
181
182impl Settings for TabBarSettings {
183 fn from_settings(content: &settings::SettingsContent) -> Self {
184 let tab_bar = content.tab_bar.clone().unwrap();
185 TabBarSettings {
186 show: tab_bar.show.unwrap(),
187 show_nav_history_buttons: tab_bar.show_nav_history_buttons.unwrap(),
188 show_tab_bar_buttons: tab_bar.show_tab_bar_buttons.unwrap(),
189 show_pinned_tabs_in_separate_row: tab_bar.show_pinned_tabs_in_separate_row.unwrap(),
190 }
191 }
192}
193
194#[derive(Deserialize, RegisterSetting)]
195pub struct StatusBarSettings {
196 pub show: bool,
197 pub show_active_file: bool,
198 pub active_language_button: bool,
199 pub cursor_position_button: bool,
200 pub line_endings_button: bool,
201 pub active_encoding_button: EncodingDisplayOptions,
202}
203
204impl Settings for StatusBarSettings {
205 fn from_settings(content: &settings::SettingsContent) -> Self {
206 let status_bar = content.status_bar.clone().unwrap();
207 StatusBarSettings {
208 show: status_bar.show.unwrap(),
209 show_active_file: status_bar.show_active_file.unwrap(),
210 active_language_button: status_bar.active_language_button.unwrap(),
211 cursor_position_button: status_bar.cursor_position_button.unwrap(),
212 line_endings_button: status_bar.line_endings_button.unwrap(),
213 active_encoding_button: status_bar.active_encoding_button.unwrap(),
214 }
215 }
216}
217