Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

please note this is testing compatibility for windows and linux, need to test on real machine

RoversX9a9448c675d1
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index f6658553..4d485050 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -12,8 +12,8 @@ use crate::termwindow::{
TermWindowNotif, UIItem, UIItemType, TMB,
};
use ::window::{
- ContextMenuItem, MouseButtons as WMB, MouseCursor, MouseEvent, MouseEventKind as WMEK,
- MousePress, WindowOps, WindowState,
+ ContextMenuItem, IntegratedTitleButtonStyle, MouseButtons as WMB, MouseCursor, MouseEvent,
+ MouseEventKind as WMEK, MousePress, WindowDecorations, WindowOps, WindowState,
};
use config::keyassignment::{
ClipboardPasteSource, KeyAssignment, MouseEventTrigger, PaneDirection, SpawnCommand,
@@ -116,13 +116,28 @@ impl super::TermWindow {
}
pub(super) fn window_tab_trailing_action_reserved_width(&self) -> usize {
- if self.right_sidebar_width() > 0 {
+ let sidebar_actions_width = if self.right_sidebar_width() > 0 {
WINDOW_TAB_ACTION_RESERVED_WIDTH
} else {
WINDOW_TAB_ACTION_RESERVED_WIDTH
+ WINDOW_TAB_LEADING_ACTION_BUTTON_SIZE
+ WINDOW_TAB_LEADING_ACTION_GAP
- }
+ };
+
+ sidebar_actions_width
+ + if self
+ .config
+ .window_decorations
+ .contains(WindowDecorations::INTEGRATED_BUTTONS)
+ && self.config.integrated_title_button_style
+ != IntegratedTitleButtonStyle::MacOsNative
+ {
+ self.config.integrated_title_buttons.len()
+ * (WINDOW_TAB_LEADING_ACTION_BUTTON_SIZE + WINDOW_TAB_LEADING_ACTION_GAP / 2)
+ + WINDOW_TAB_LEADING_ACTION_GAP
+ } else {
+ 0
+ }
}
pub(super) fn pane_nav_tab_left_inset(&self, pane_left: usize) -> usize {
diff --git a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
index 04f14072..92cb0229 100644
--- a/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
+++ b/wezterm-gui/src/termwindow/render/fancy_tab_bar.rs
@@ -23,6 +23,7 @@ use wezterm_font::LoadedFont;
use wezterm_term::Line;
use window::color::LinearRgba;
use window::WindowOps;
+use window::{IntegratedTitleButton, IntegratedTitleButtonStyle, WindowDecorations, WindowState};
const WINDOW_TAB_INSET: usize = 8;
const WINDOW_TAB_ICON_GAP: usize = 8;
@@ -240,8 +241,23 @@ impl crate::TermWindow {
}
}
+ let mut action_right = row_right.saturating_sub(WINDOW_TAB_INSET + 2);
+ if self.fancy_tab_bar_shows_window_buttons() {
+ action_right = self.paint_window_tab_window_buttons(
+ layers,
+ &mut ui_items,
+ action_right,
+ content_row_y,
+ content_row_height,
+ button_size,
+ icon_size,
+ foreground,
+ muted_fg,
+ )?;
+ }
+
if self.right_sidebar_width() > 0 {
- let new_button_x = row_right.saturating_sub(WINDOW_TAB_INSET + button_size + 2);
+ let new_button_x = action_right.saturating_sub(button_size);
self.paint_window_tab_new_button(
layers,
&mut ui_items,
@@ -254,8 +270,7 @@ impl crate::TermWindow {
muted_fg,
)?;
} else {
- let right_sidebar_toggle_x =
- row_right.saturating_sub(WINDOW_TAB_INSET + button_size + 2);
+ let right_sidebar_toggle_x = action_right.saturating_sub(button_size);
let new_button_x =
right_sidebar_toggle_x.saturating_sub(WINDOW_TAB_LEADING_ACTION_GAP + button_size);
self.paint_window_tab_new_button(
@@ -285,6 +300,14 @@ impl crate::TermWindow {
Ok(ui_items)
}
+ fn fancy_tab_bar_shows_window_buttons(&self) -> bool {
+ self.config
+ .window_decorations
+ .contains(WindowDecorations::INTEGRATED_BUTTONS)
+ && self.config.integrated_title_button_style != IntegratedTitleButtonStyle::MacOsNative
+ && !self.config.integrated_title_buttons.is_empty()
+ }
+
#[allow(clippy::too_many_arguments)]
fn paint_window_tab_leading_actions(
&self,
@@ -408,6 +431,136 @@ impl crate::TermWindow {
)
}
+ #[allow(clippy::too_many_arguments)]
+ fn paint_window_tab_window_buttons(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ ui_items: &mut Vec<UIItem>,
+ mut action_right: usize,
+ row_y: usize,
+ row_height: usize,
+ button_size: usize,
+ icon_size: usize,
+ foreground: LinearRgba,
+ muted_fg: LinearRgba,
+ ) -> anyhow::Result<usize> {
+ let gap = WINDOW_TAB_LEADING_ACTION_GAP / 2;
+ for button in self.config.integrated_title_buttons.iter().rev() {
+ action_right = action_right.saturating_sub(button_size);
+ self.paint_window_tab_window_button(
+ layers,
+ ui_items,
+ *button,
+ action_right,
+ row_y,
+ row_height,
+ button_size,
+ icon_size,
+ foreground,
+ muted_fg,
+ )?;
+ action_right = action_right.saturating_sub(gap);
+ }
+
+ Ok(action_right.saturating_sub(WINDOW_TAB_LEADING_ACTION_GAP / 2))
+ }
+
+ #[allow(clippy::too_many_arguments)]
+ fn paint_window_tab_window_button(
+ &self,
+ layers: &mut TripleLayerQuadAllocator,
+ ui_items: &mut Vec<UIItem>,
+ button: IntegratedTitleButton,
+ button_x: usize,
+ row_y: usize,
+ row_height: usize,
+ button_size: usize,
+ icon_size: usize,
+ foreground: LinearRgba,
+ muted_fg: LinearRgba,
+ ) -> anyhow::Result<()> {
+ let button_y = row_y + (row_height.saturating_sub(button_size) / 2);
+ let hovered = self.is_pointer_over_ui_rect(button_x, button_y, button_size, button_size);
+ let pressed = hovered
+ && self.is_pointer_pressing_ui_rect(button_x, button_y, button_size, button_size);
+ let press_inset = if pressed { 1 } else { 0 };
+ let visual_size = button_size.saturating_sub(press_inset * 2);
+ let close_button = button == IntegratedTitleButton::Close;
+
+ if hovered {
+ let chrome = UiPalette::for_appearance(crate::native_settings::effective_appearance());
+ let fill = if close_button {
+ let mut red = LinearRgba::with_srgba(232, 17, 35, 255);
+ if pressed {
+ red.3 = 0.82;
+ }
+ red
+ } else if pressed {
+ chrome.control_pressed_bg
+ } else {
+ chrome.control_hover_bg
+ };
+ let border = if close_button {
+ LinearRgba::TRANSPARENT
+ } else {
+ foreground.mul_alpha(if pressed { 0.52 } else { 0.38 })
+ };
+ self.fill_rounded_rectangle_with_border(
+ layers,
+ 1,
+ euclid::rect(
+ (button_x + press_inset) as f32,
+ (button_y + press_inset) as f32,
+ visual_size as f32,
+ visual_size as f32,
+ ),
+ fill,
+ border,
+ WINDOW_TAB_ADD_BUTTON_RADIUS,
+ ICON_BUTTON_BORDER_WIDTH,
+ )
+ .context("window tab title button hover")?;
+ }
+
+ ui_items.push(UIItem {
+ x: button_x,
+ y: button_y,
+ width: button_size,
+ height: button_size,
+ item_type: UIItemType::TabBar(TabBarItem::WindowButton(button)),
+ });
+
+ let maximized = self
+ .window_state
+ .intersects(WindowState::MAXIMIZED | WindowState::FULL_SCREEN);
+ let icon = match button {
+ IntegratedTitleButton::Hide => SvgIcon::Minus,
+ IntegratedTitleButton::Maximize if maximized => SvgIcon::Minimize2,
+ IntegratedTitleButton::Maximize => SvgIcon::Maximize2,
+ IntegratedTitleButton::Close => SvgIcon::X,
+ };
+ let icon_size = if pressed {
+ icon_size.saturating_sub(1).max(1)
+ } else {
+ icon_size
+ };
+ let icon_color = if close_button && hovered {
+ LinearRgba(1.0, 1.0, 1.0, 1.0)
+ } else if hovered {
+ foreground
+ } else {
+ muted_fg
+ };
+ self.paint_fancy_tab_icon(
+ layers,
+ icon,
+ button_x + press_inset + (visual_size.saturating_sub(icon_size) / 2),
+ button_y + press_inset + (visual_size.saturating_sub(icon_size) / 2),
+ icon_size,
+ icon_color,
+ )
+ }
+
#[allow(clippy::too_many_arguments)]
fn paint_window_tab(
&self,
diff --git a/wezterm-gui/src/termwindow/ui/platform_chrome.rs b/wezterm-gui/src/termwindow/ui/platform_chrome.rs
index 09f070dc..d829e750 100644
--- a/wezterm-gui/src/termwindow/ui/platform_chrome.rs
+++ b/wezterm-gui/src/termwindow/ui/platform_chrome.rs
@@ -1,8 +1,9 @@
use crate::termwindow::ui::tokens::{
MACOS_TITLEBAR_CONTENT_TOP_INSET, MACOS_TRAFFIC_LIGHT_CLEARANCE_WIDTH,
MACOS_WINDOW_TAB_RESERVED_ACTION_SLOTS, WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_SIZE,
- WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_X, WINDOW_TAB_LEADING_ACTION_BUTTON_SIZE,
- WINDOW_TAB_LEADING_ACTION_GAP,
+ WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_X, WINDOW_TAB_FULLSCREEN_SIDEBAR_ICON_SIZE,
+ WINDOW_TAB_LEADING_ACTION_BUTTON_SIZE, WINDOW_TAB_LEADING_ACTION_GAP,
+ WINDOW_TAB_LEADING_ACTION_ICON_SIZE,
};
use window::{
IntegratedTitleButtonAlignment, IntegratedTitleButtonStyle, WindowDecorations, WindowState,
@@ -130,5 +131,25 @@ pub fn workspace_sidebar_content_top(
}
pub fn workspace_sidebar_shows_toolbar(window_state: WindowState) -> bool {
+ window_state.contains(WindowState::FULL_SCREEN) || !cfg!(target_os = "macos")
+}
+
+pub fn workspace_sidebar_toolbar_uses_fullscreen_style(window_state: WindowState) -> bool {
window_state.contains(WindowState::FULL_SCREEN)
}
+
+pub fn workspace_sidebar_toolbar_button_size(window_state: WindowState) -> usize {
+ if workspace_sidebar_toolbar_uses_fullscreen_style(window_state) {
+ WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_SIZE
+ } else {
+ WINDOW_TAB_LEADING_ACTION_BUTTON_SIZE
+ }
+}
+
+pub fn workspace_sidebar_toolbar_icon_size(window_state: WindowState) -> usize {
+ if workspace_sidebar_toolbar_uses_fullscreen_style(window_state) {
+ WINDOW_TAB_FULLSCREEN_SIDEBAR_ICON_SIZE
+ } else {
+ WINDOW_TAB_LEADING_ACTION_ICON_SIZE
+ }
+}
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index f6c51f02..5b2607fc 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -11,8 +11,7 @@ use crate::termwindow::ui::tokens::{
CAPSULE_BORDER_WIDTH, SIDEBAR_ICON_GAP, SIDEBAR_INSET, SIDEBAR_MAX_WIDTH, SIDEBAR_MIN_WIDTH,
SIDEBAR_RESIZE_HANDLE_WIDTH, SIDEBAR_ROW_GAP, SIDEBAR_ROW_RADIUS, SIDEBAR_WIDTH_CELLS,
WINDOW_TAB_FULLSCREEN_NEW_SESSION_EXTRA_HEIGHT, WINDOW_TAB_FULLSCREEN_NEW_SESSION_Y_OFFSET,
- WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_SIZE, WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_X,
- WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_Y_OFFSET, WINDOW_TAB_FULLSCREEN_SIDEBAR_ICON_SIZE,
+ WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_X, WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_Y_OFFSET,
};
use crate::termwindow::{UIItem, UIItemType};
use crate::ui::UiPalette;
@@ -378,19 +377,22 @@ impl crate::TermWindow {
.min(settings_footer_y.max(panel_y));
let show_sidebar_toolbar =
platform_chrome::workspace_sidebar_shows_toolbar(self.window_state);
+ let sidebar_toolbar_uses_fullscreen_style =
+ platform_chrome::workspace_sidebar_toolbar_uses_fullscreen_style(self.window_state);
let row_height =
(ui_cell_height.max(icon_size) + SIDEBAR_INSET).max(SESSION_ROW_MIN_HEIGHT);
let mut y = self.workspace_sidebar_content_top(panel_y);
if show_sidebar_toolbar {
- y += WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_SIZE + SIDEBAR_INSET;
+ y += platform_chrome::workspace_sidebar_toolbar_button_size(self.window_state)
+ + SIDEBAR_INSET;
}
let top_action_height = row_height.min(48).max(ui_cell_height + SIDEBAR_INSET)
- + if show_sidebar_toolbar {
+ + if sidebar_toolbar_uses_fullscreen_style {
WINDOW_TAB_FULLSCREEN_NEW_SESSION_EXTRA_HEIGHT
} else {
0
};
- let top_action_y_offset = if show_sidebar_toolbar {
+ let top_action_y_offset = if sidebar_toolbar_uses_fullscreen_style {
WINDOW_TAB_FULLSCREEN_NEW_SESSION_Y_OFFSET
} else {
0
@@ -644,11 +646,25 @@ impl crate::TermWindow {
let button_size = (header_icon_size + 8).clamp(32, 40);
let header_y = self.workspace_sidebar_content_top(panel_y);
let show_sidebar_toolbar = layout.show_sidebar_toolbar;
- let sidebar_toggle_size = WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_SIZE;
- let sidebar_toggle_x = panel_x + WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_X;
- let sidebar_toggle_y = header_y + WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_Y_OFFSET;
+ let sidebar_toolbar_uses_fullscreen_style =
+ platform_chrome::workspace_sidebar_toolbar_uses_fullscreen_style(self.window_state);
+ let sidebar_toggle_size =
+ platform_chrome::workspace_sidebar_toolbar_button_size(self.window_state);
+ let sidebar_toggle_x = panel_x
+ + if sidebar_toolbar_uses_fullscreen_style {
+ WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_X
+ } else {
+ SIDEBAR_INSET
+ };
+ let sidebar_toggle_y = header_y
+ + if sidebar_toolbar_uses_fullscreen_style {
+ WINDOW_TAB_FULLSCREEN_SIDEBAR_BUTTON_Y_OFFSET
+ } else {
+ 0
+ };
let sidebar_toggle_icon_size =
- WINDOW_TAB_FULLSCREEN_SIDEBAR_ICON_SIZE.min(sidebar_toggle_size.saturating_sub(2));
+ platform_chrome::workspace_sidebar_toolbar_icon_size(self.window_state)
+ .min(sidebar_toggle_size.saturating_sub(2));
if show_sidebar_toolbar {
let toggle_hovered = self.is_pointer_over_ui_rect(
sidebar_toggle_x,
diff --git a/wezterm-input-types/src/lib.rs b/wezterm-input-types/src/lib.rs
index 2253dec4..b6fcab74 100644
--- a/wezterm-input-types/src/lib.rs
+++ b/wezterm-input-types/src/lib.rs
@@ -2141,7 +2141,11 @@ impl TryFrom<String> for WindowDecorations {
impl Default for WindowDecorations {
fn default() -> Self {
- WindowDecorations::TITLE | WindowDecorations::RESIZE
+ if cfg!(target_os = "macos") {
+ WindowDecorations::TITLE | WindowDecorations::RESIZE
+ } else {
+ WindowDecorations::RESIZE | WindowDecorations::INTEGRATED_BUTTONS
+ }
}
}
diff --git a/window/Cargo.toml b/window/Cargo.toml
index 523daef2..773ddc78 100644
--- a/window/Cargo.toml
+++ b/window/Cargo.toml
@@ -52,11 +52,15 @@ wezterm-input-types.workspace = true
clipboard-win.workspace = true
shared_library.workspace = true
winapi = { workspace=true, features = [
+ "combaseapi",
"dwmapi",
"handleapi",
"imm",
"libloaderapi",
+ "objbase",
"shellscalingapi",
+ "shobjidl",
+ "shobjidl_core",
"synchapi",
"sysinfoapi",
"winerror",
diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs
index ff969660..e9a43b97 100644
--- a/window/src/os/wayland/window.rs
+++ b/window/src/os/wayland/window.rs
@@ -249,6 +249,8 @@ impl WaylandWindow {
let decor_mode = if decorations == WindowDecorations::NONE {
None
+ } else if decorations.contains(WindowDecorations::INTEGRATED_BUTTONS) {
+ Some(DecorationMode::Client)
} else if decorations == WindowDecorations::default() {
Some(DecorationMode::Server)
} else {
diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs
index 179c0d17..a037e9e1 100644
--- a/window/src/os/windows/window.rs
+++ b/window/src/os/windows/window.rs
@@ -35,11 +35,20 @@ use wezterm_input_types::KeyboardLedStatus;
use winapi::shared::minwindef::*;
use winapi::shared::ntdef::*;
use winapi::shared::windef::*;
-use winapi::shared::winerror::S_OK;
+use winapi::shared::winerror::{
+ ERROR_CANCELLED, FAILED, HRESULT_FROM_WIN32, RPC_E_CHANGED_MODE, S_FALSE, S_OK,
+};
+use winapi::shared::wtypesbase::CLSCTX_INPROC_SERVER;
+use winapi::um::combaseapi::{CoCreateInstance, CoInitializeEx, CoTaskMemFree, CoUninitialize};
use winapi::um::imm::*;
use winapi::um::libloaderapi::GetModuleHandleW;
+use winapi::um::objbase::{COINIT_APARTMENTTHREADED, COINIT_DISABLE_OLE1DDE};
use winapi::um::shellapi::{DragAcceptFiles, DragFinish, DragQueryFileW, HDROP};
use winapi::um::shellscalingapi::{GetDpiForMonitor, MDT_EFFECTIVE_DPI};
+use winapi::um::shobjidl::{
+ IFileOpenDialog, FOS_FORCEFILESYSTEM, FOS_NOCHANGEDIR, FOS_PATHMUSTEXIST, FOS_PICKFOLDERS,
+};
+use winapi::um::shobjidl_core::{CLSID_FileOpenDialog, IShellItem, SIGDN_FILESYSPATH};
use winapi::um::sysinfoapi::{GetTickCount, GetVersionExW};
use winapi::um::uxtheme::{
CloseThemeData, GetThemeFont, GetThemeSysFont, OpenThemeData, SetWindowTheme,
@@ -47,6 +56,7 @@ use winapi::um::uxtheme::{
use winapi::um::wingdi::{LOGFONTW, MAKEPOINTS};
use winapi::um::winnt::OSVERSIONINFOW;
use winapi::um::winuser::*;
+use winapi::Interface;
use windows::UI::Color as WUIColor;
use windows::UI::ViewManagement::{UIColorType, UISettings};
use winreg::enums::HKEY_CURRENT_USER;
@@ -140,6 +150,116 @@ fn rect_width(r: &RECT) -> i32 {
r.right - r.left
}
+fn hresult_to_result(hr: HRESULT, context: &str) -> anyhow::Result<()> {
+ if FAILED(hr) {
+ anyhow::bail!("{context} failed with HRESULT {:#x}", hr as u32);
+ }
+ Ok(())
+}
+
+fn wide_null(s: &str) -> Vec<u16> {
+ s.encode_utf16().chain(std::iter::once(0)).collect()
+}
+
+unsafe fn pathbuf_from_shell_string(raw_path: LPWSTR) -> Option<PathBuf> {
+ if raw_path.is_null() {
+ return None;
+ }
+
+ let mut len = 0;
+ while *raw_path.add(len) != 0 {
+ len += 1;
+ }
+
+ let path = OsString::from_wide(std::slice::from_raw_parts(raw_path, len));
+ Some(PathBuf::from(path))
+}
+
+unsafe fn pick_folder_dialog(hwnd: HWND) -> anyhow::Result<Option<PathBuf>> {
+ let coinit = CoInitializeEx(
+ null_mut(),
+ COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE,
+ );
+ let should_uninitialize = coinit == S_OK || coinit == S_FALSE;
+ if FAILED(coinit) && coinit != RPC_E_CHANGED_MODE {
+ hresult_to_result(coinit, "CoInitializeEx")?;
+ }
+
+ let result = (|| {
+ let mut dialog: *mut IFileOpenDialog = null_mut();
+ hresult_to_result(
+ CoCreateInstance(
+ &CLSID_FileOpenDialog,
+ null_mut(),
+ CLSCTX_INPROC_SERVER,
+ &IFileOpenDialog::uuidof(),
+ &mut dialog as *mut _ as *mut _,
+ ),
+ "CoCreateInstance(FileOpenDialog)",
+ )?;
+
+ let title = wide_null("Open Project");
+ let open = wide_null("Open");
+ let mut selected_path = None;
+ let mut result_item: *mut IShellItem = null_mut();
+ let mut raw_path: LPWSTR = null_mut();
+
+ let dialog_result = (|| {
+ let mut options = std::mem::zeroed();
+ hresult_to_result(
+ (*dialog).GetOptions(&mut options),
+ "IFileDialog::GetOptions",
+ )?;
+ let options = std::mem::transmute(
+ options as u32
+ | FOS_PICKFOLDERS as u32
+ | FOS_FORCEFILESYSTEM as u32
+ | FOS_PATHMUSTEXIST as u32
+ | FOS_NOCHANGEDIR as u32,
+ );
+ hresult_to_result((*dialog).SetOptions(options), "IFileDialog::SetOptions")?;
+ hresult_to_result((*dialog).SetTitle(title.as_ptr()), "IFileDialog::SetTitle")?;
+ hresult_to_result(
+ (*dialog).SetOkButtonLabel(open.as_ptr()),
+ "IFileDialog::SetOkButtonLabel",
+ )?;
+
+ let show_result = (*dialog).Show(hwnd);
+ if show_result == HRESULT_FROM_WIN32(ERROR_CANCELLED) {
+ return Ok(());
+ }
+ hresult_to_result(show_result, "IFileDialog::Show")?;
+
+ hresult_to_result(
+ (*dialog).GetResult(&mut result_item),
+ "IFileDialog::GetResult",
+ )?;
+ hresult_to_result(
+ (*result_item).GetDisplayName(SIGDN_FILESYSPATH, &mut raw_path),
+ "IShellItem::GetDisplayName",
+ )?;
+ selected_path = pathbuf_from_shell_string(raw_path);
+ Ok(())
+ })();
+
+ if !raw_path.is_null() {
+ CoTaskMemFree(raw_path as *mut _);
+ }
+ if !result_item.is_null() {
+ (*result_item).Release();
+ }
+ (*dialog).Release();
+
+ dialog_result.map(|_| selected_path)
+ })();
+
+ if should_uninitialize {
+ CoUninitialize();
+ }
+
+ result
+}
+
fn rect_height(r: &RECT) -> i32 {
r.bottom - r.top
}
@@ -388,7 +508,10 @@ fn apply_decoration_immediate(hwnd: HWND, decorations: WindowDecorations) {
}
fn decorations_to_style(decorations: WindowDecorations) -> u32 {
- if decorations == WindowDecorations::RESIZE {
+ if decorations == WindowDecorations::RESIZE
+ || decorations == (WindowDecorations::RESIZE | WindowDecorations::INTEGRATED_BUTTONS)
+ || decorations == WindowDecorations::INTEGRATED_BUTTONS
+ {
WS_OVERLAPPEDWINDOW
} else if decorations == WindowDecorations::TITLE {
WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
@@ -861,6 +984,19 @@ impl WindowOps for Window {
});
}
+ fn pick_folder_async(&self, callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>) {
+ let path = unsafe {
+ match pick_folder_dialog(self.0 .0) {
+ Ok(path) => path,
+ Err(err) => {
+ log::warn!("failed to show folder picker: {err:#}");
+ None
+ }
+ }
+ };
+ callback(path);
+ }
+
fn invalidate(&self) {
let hwnd = self.0 .0;
log::trace!("WindowOps::invalidate calling InvalidateRect");
diff --git a/window/src/os/x_and_wayland.rs b/window/src/os/x_and_wayland.rs
index b66d18d8..e7a1fed8 100644
--- a/window/src/os/x_and_wayland.rs
+++ b/window/src/os/x_and_wayland.rs
@@ -19,6 +19,7 @@ use raw_window_handle::{
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, WindowHandle,
};
use std::any::Any;
+use std::path::PathBuf;
use std::rc::Rc;
use wezterm_font::FontConfiguration;
@@ -306,6 +307,10 @@ impl WindowOps for Window {
}
}
+ fn pick_folder_async(&self, callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>) {
+ crate::os::xdg_desktop_portal::pick_folder_async(callback);
+ }
+
fn invalidate(&self) {
match self {
Self::X11(x) => x.invalidate(),
diff --git a/window/src/os/xdg_desktop_portal.rs b/window/src/os/xdg_desktop_portal.rs
index 0709efec..b2a4c9f5 100644
--- a/window/src/os/xdg_desktop_portal.rs
+++ b/window/src/os/xdg_desktop_portal.rs
@@ -7,10 +7,12 @@ use anyhow::Context;
use futures_lite::future::FutureExt;
use futures_util::stream::StreamExt;
use std::collections::HashMap;
+use std::path::PathBuf;
use std::sync::Mutex;
use std::time::Instant;
+use url::Url;
use zbus::proxy;
-use zvariant::OwnedValue;
+use zvariant::{OwnedObjectPath, OwnedValue, Value};
#[proxy(
interface = "org.freedesktop.portal.Settings",
@@ -29,6 +31,29 @@ trait PortalSettings {
fn SettingChanged(&self, namespace: &str, key: &str, value: OwnedValue) -> zbus::Result<()>;
}
+#[proxy(
+ interface = "org.freedesktop.portal.FileChooser",
+ default_service = "org.freedesktop.portal.Desktop",
+ default_path = "/org/freedesktop/portal/desktop"
+)]
+trait PortalFileChooser {
+ fn OpenFile(
+ &self,
+ parent_window: &str,
+ title: &str,
+ options: HashMap<&str, Value<'_>>,
+ ) -> zbus::Result<OwnedObjectPath>;
+}
+
+#[proxy(
+ interface = "org.freedesktop.portal.Request",
+ default_service = "org.freedesktop.portal.Desktop"
+)]
+trait PortalRequest {
+ #[zbus(signal)]
+ fn Response(&self, response: u32, results: HashMap<String, OwnedValue>) -> zbus::Result<()>;
+}
+
#[derive(PartialEq)]
enum CachedAppearance {
/// Never tried to determine appearance
@@ -139,6 +164,88 @@ pub async fn get_appearance() -> anyhow::Result<Option<Appearance>> {
}
}
+fn first_file_uri_to_path(
+ results: &HashMap<String, OwnedValue>,
+) -> anyhow::Result<Option<PathBuf>> {
+ let Some(uris) = results.get("uris") else {
+ return Ok(None);
+ };
+ let uris = Vec::<String>::try_from(
+ uris.try_clone()
+ .context("clone portal returned uris value")?,
+ )
+ .map_err(|err| anyhow::anyhow!("portal returned invalid uris: {err:#?}"))?;
+ let Some(uri) = uris.first() else {
+ return Ok(None);
+ };
+ let url = Url::parse(uri).with_context(|| format!("parsing portal uri {uri:?}"))?;
+ url.to_file_path()
+ .map(Some)
+ .map_err(|()| anyhow::anyhow!("portal uri is not a file path: {uri:?}"))
+}
+
+pub async fn pick_folder() -> anyhow::Result<Option<PathBuf>> {
+ let connection = zbus::ConnectionBuilder::session()?.build().await?;
+ let proxy = PortalFileChooserProxy::new(&connection)
+ .await
+ .context("make file chooser proxy")?;
+
+ let mut options = HashMap::new();
+ options.insert("directory", Value::from(true));
+ options.insert("modal", Value::from(true));
+
+ let handle = proxy
+ .OpenFile("", "Open Project", options)
+ .or(async {
+ async_io::Timer::after(std::time::Duration::from_secs(1)).await;
+ Err(std::io::Error::new(
+ std::io::ErrorKind::TimedOut,
+ "Timed out opening xdg-desktop-portal folder picker",
+ )
+ .into())
+ })
+ .await
+ .context("Opening xdg-desktop-portal folder picker")?;
+
+ let request = PortalRequestProxy::builder(&connection)
+ .path(handle)?
+ .build()
+ .await
+ .context("make portal request proxy")?;
+ let mut stream = request
+ .receive_Response()
+ .await
+ .context("subscribe to portal request response")?;
+ let signal = stream
+ .next()
+ .or(async {
+ async_io::Timer::after(std::time::Duration::from_secs(60)).await;
+ None
+ })
+ .await
+ .ok_or_else(|| anyhow::anyhow!("Timed out waiting for folder picker response"))?;
+ let args = signal.args().context("decode folder picker response")?;
+ if args.response != 0 {
+ return Ok(None);
+ }
+
+ first_file_uri_to_path(&args.results)
+}
+
+pub fn pick_folder_async(callback: Box<dyn FnOnce(Option<PathBuf>) + 'static>) {
+ promise::spawn::spawn(async move {
+ let path = match pick_folder().await {
+ Ok(path) => path,
+ Err(err) => {
+ log::warn!("failed to show xdg-desktop-portal folder picker: {err:#}");
+ None
+ }
+ };
+ callback(path);
+ })
+ .detach();
+}
+
pub async fn run_signal_loop(stream: &mut SettingChangedStream<'_>) -> Result<(), anyhow::Error> {
// query appearance again as it might have changed without us knowing
if let Ok(value) =