gpui: Support window resizing for PlatformWindow (#27477)
Support resizing windows to a specified size. ## macOS https://github.com/user-attachments/assets/8c639bc2-ee5f-4adc-a850-576dac939574 ## Wayland [wayland.webm](https://github.com/user-attachments/assets/3d593604-83b4-488f-8f63-1cf4c0c0cb9a) ## X11 [x11.webm](https://github.com/user-attachments/assets/ce8fa62e-fb74-4641-abe8-70574011e630) ## Windows https://github.com/user-attachments/assets/abb03e48-f82a-4d62-90b3-2598a4866c3f Release Notes: - N/A
This commit is contained in:
@@ -797,6 +797,25 @@ impl PlatformWindow for WaylandWindow {
|
||||
self.borrow().bounds.size
|
||||
}
|
||||
|
||||
fn resize(&mut self, size: Size<Pixels>) {
|
||||
let state = self.borrow();
|
||||
let state_ptr = self.0.clone();
|
||||
let dp_size = size.to_device_pixels(self.scale_factor());
|
||||
|
||||
state.xdg_surface.set_window_geometry(
|
||||
state.bounds.origin.x.0 as i32,
|
||||
state.bounds.origin.y.0 as i32,
|
||||
dp_size.width.0,
|
||||
dp_size.height.0,
|
||||
);
|
||||
|
||||
state
|
||||
.globals
|
||||
.executor
|
||||
.spawn(async move { state_ptr.resize(size) })
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn scale_factor(&self) -> f32 {
|
||||
self.borrow().scale
|
||||
}
|
||||
|
||||
@@ -1143,6 +1143,30 @@ impl PlatformWindow for X11Window {
|
||||
.map(|size| size.div(state.scale_factor))
|
||||
}
|
||||
|
||||
fn resize(&mut self, size: Size<Pixels>) {
|
||||
let state = self.0.state.borrow();
|
||||
let size = size.to_device_pixels(state.scale_factor);
|
||||
let width = size.width.0 as u32;
|
||||
let height = size.height.0 as u32;
|
||||
|
||||
check_reply(
|
||||
|| {
|
||||
format!(
|
||||
"X11 ConfigureWindow failed. width: {}, height: {}",
|
||||
width, height
|
||||
)
|
||||
},
|
||||
self.0.xcb.configure_window(
|
||||
self.0.x_window,
|
||||
&xproto::ConfigureWindowAux::new()
|
||||
.width(width)
|
||||
.height(height),
|
||||
),
|
||||
)
|
||||
.log_err();
|
||||
self.flush().log_err();
|
||||
}
|
||||
|
||||
fn scale_factor(&self) -> f32 {
|
||||
self.0.state.borrow().scale_factor
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user