Skip to content

Commit 6653b6d

Browse files
madcodelifeFrGoIs
authored andcommitted
gpui: Support disabling window resizing and minimizing (zed-industries#36859)
Add support to disable both window resizing and minimizing. | | macOS | Windows | | - | - | - | | **Unresizable** | <img width="412" height="440" alt="SCR-20250822-qpea" src="https://github.com/user-attachments/assets/d6d45510-dc4b-436f-a9fa-ce9cb0b0c411" /> | <img width="276" height="298" alt="2025-08-22 110757" src="https://github.com/user-attachments/assets/9deff498-e903-4173-9c26-072dd9409fc1" /> | | **Unminimizable** | <img width="412" height="440" alt="SCR-20250822-qpfl" src="https://github.com/user-attachments/assets/e1d5f9eb-6de5-4908-8b52-38ccb2e65689" /> | <img width="276" height="298" alt="2025-08-22 110814" src="https://github.com/user-attachments/assets/da94b006-3544-4274-8b02-1cab7ca8dd70" /> | Release Notes: - N/A
1 parent b2e5f2e commit 6653b6d

File tree

9 files changed

+77
-8
lines changed

9 files changed

+77
-8
lines changed

crates/agent_ui/src/ui/agent_notification.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl AgentNotification {
6262
app_id: Some(app_id.to_owned()),
6363
window_min_size: None,
6464
window_decorations: Some(WindowDecorations::Client),
65+
..Default::default()
6566
}
6667
}
6768
}

crates/collab_ui/src/collab_ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ fn notification_window_options(
6666
app_id: Some(app_id.to_owned()),
6767
window_min_size: None,
6868
window_decorations: Some(WindowDecorations::Client),
69+
..Default::default()
6970
}
7071
}

crates/gpui/examples/window.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,36 @@ impl Render for WindowDemo {
152152
)
153153
.unwrap();
154154
}))
155+
.child(button("Unresizable", move |_, cx| {
156+
cx.open_window(
157+
WindowOptions {
158+
is_resizable: false,
159+
window_bounds: Some(window_bounds),
160+
..Default::default()
161+
},
162+
|_, cx| {
163+
cx.new(|_| SubWindow {
164+
custom_titlebar: false,
165+
})
166+
},
167+
)
168+
.unwrap();
169+
}))
170+
.child(button("Unminimizable", move |_, cx| {
171+
cx.open_window(
172+
WindowOptions {
173+
is_minimizable: false,
174+
window_bounds: Some(window_bounds),
175+
..Default::default()
176+
},
177+
|_, cx| {
178+
cx.new(|_| SubWindow {
179+
custom_titlebar: false,
180+
})
181+
},
182+
)
183+
.unwrap();
184+
}))
155185
.child(button("Hide Application", |window, cx| {
156186
cx.hide();
157187

crates/gpui/examples/window_positioning.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ fn build_window_options(display_id: DisplayId, bounds: Bounds<Pixels>) -> Window
6262
app_id: None,
6363
window_min_size: None,
6464
window_decorations: None,
65+
..Default::default()
6566
}
6667
}
6768

crates/gpui/src/platform.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,12 @@ pub struct WindowOptions {
10911091
/// Whether the window should be movable by the user
10921092
pub is_movable: bool,
10931093

1094+
/// Whether the window should be resizable by the user
1095+
pub is_resizable: bool,
1096+
1097+
/// Whether the window should be minimized by the user
1098+
pub is_minimizable: bool,
1099+
10941100
/// The display to create the window on, if this is None,
10951101
/// the window will be created on the main display
10961102
pub display_id: Option<DisplayId>,
@@ -1133,6 +1139,14 @@ pub(crate) struct WindowParams {
11331139
#[cfg_attr(any(target_os = "linux", target_os = "freebsd"), allow(dead_code))]
11341140
pub is_movable: bool,
11351141

1142+
/// Whether the window should be resizable by the user
1143+
#[cfg_attr(any(target_os = "linux", target_os = "freebsd"), allow(dead_code))]
1144+
pub is_resizable: bool,
1145+
1146+
/// Whether the window should be minimized by the user
1147+
#[cfg_attr(any(target_os = "linux", target_os = "freebsd"), allow(dead_code))]
1148+
pub is_minimizable: bool,
1149+
11361150
#[cfg_attr(
11371151
any(target_os = "linux", target_os = "freebsd", target_os = "windows"),
11381152
allow(dead_code)
@@ -1191,6 +1205,8 @@ impl Default for WindowOptions {
11911205
show: true,
11921206
kind: WindowKind::Normal,
11931207
is_movable: true,
1208+
is_resizable: true,
1209+
is_minimizable: true,
11941210
display_id: None,
11951211
window_background: WindowBackgroundAppearance::default(),
11961212
app_id: None,

crates/gpui/src/platform/mac/window.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ impl MacWindow {
530530
titlebar,
531531
kind,
532532
is_movable,
533+
is_resizable,
534+
is_minimizable,
533535
focus,
534536
show,
535537
display_id,
@@ -545,10 +547,16 @@ impl MacWindow {
545547

546548
let mut style_mask;
547549
if let Some(titlebar) = titlebar.as_ref() {
548-
style_mask = NSWindowStyleMask::NSClosableWindowMask
549-
| NSWindowStyleMask::NSMiniaturizableWindowMask
550-
| NSWindowStyleMask::NSResizableWindowMask
551-
| NSWindowStyleMask::NSTitledWindowMask;
550+
style_mask =
551+
NSWindowStyleMask::NSClosableWindowMask | NSWindowStyleMask::NSTitledWindowMask;
552+
553+
if is_resizable {
554+
style_mask |= NSWindowStyleMask::NSResizableWindowMask;
555+
}
556+
557+
if is_minimizable {
558+
style_mask |= NSWindowStyleMask::NSMiniaturizableWindowMask;
559+
}
552560

553561
if titlebar.appears_transparent {
554562
style_mask |= NSWindowStyleMask::NSFullSizeContentViewWindowMask;

crates/gpui/src/platform/windows/window.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,17 @@ impl WindowsWindow {
382382
let (mut dwexstyle, dwstyle) = if params.kind == WindowKind::PopUp {
383383
(WS_EX_TOOLWINDOW, WINDOW_STYLE(0x0))
384384
} else {
385-
(
386-
WS_EX_APPWINDOW,
387-
WS_THICKFRAME | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
388-
)
385+
let mut dwstyle = WS_SYSMENU;
386+
387+
if params.is_resizable {
388+
dwstyle |= WS_THICKFRAME | WS_MAXIMIZEBOX;
389+
}
390+
391+
if params.is_minimizable {
392+
dwstyle |= WS_MINIMIZEBOX;
393+
}
394+
395+
(WS_EX_APPWINDOW, dwstyle)
389396
};
390397
if !disable_direct_composition {
391398
dwexstyle |= WS_EX_NOREDIRECTIONBITMAP;

crates/gpui/src/window.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,8 @@ impl Window {
939939
show,
940940
kind,
941941
is_movable,
942+
is_resizable,
943+
is_minimizable,
942944
display_id,
943945
window_background,
944946
app_id,
@@ -956,6 +958,8 @@ impl Window {
956958
titlebar,
957959
kind,
958960
is_movable,
961+
is_resizable,
962+
is_minimizable,
959963
focus,
960964
show,
961965
display_id,

crates/zed/src/zed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ pub fn build_window_options(display_uuid: Option<Uuid>, cx: &mut App) -> WindowO
301301
width: px(360.0),
302302
height: px(240.0),
303303
}),
304+
..Default::default()
304305
}
305306
}
306307

0 commit comments

Comments
 (0)