1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-26 14:54:16 +03:00

Refactor set_resize_increment() args into struct

This commit is contained in:
Jeffrey Knockel 2024-01-23 17:29:36 -05:00 committed by Wez Furlong
parent 46732d049a
commit f204f0f1a9
7 changed files with 56 additions and 47 deletions

View File

@ -842,10 +842,10 @@ impl TermWindow {
};
myself.config_subscription.replace(config_subscription);
if config.use_resize_increments {
window.set_resize_increments(
myself.render_metrics.cell_size.width as u16,
myself.render_metrics.cell_size.height as u16,
);
window.set_resize_increments(ResizeIncrement {
x: myself.render_metrics.cell_size.width as u16,
y: myself.render_metrics.cell_size.height as u16,
});
}
if let Some(gl) = gl {

View File

@ -1,5 +1,5 @@
use crate::utilsprites::RenderMetrics;
use ::window::{Dimensions, Window, WindowOps, WindowState};
use ::window::{Dimensions, ResizeIncrement, Window, WindowOps, WindowState};
use config::{ConfigHandle, DimensionContext};
use mux::Mux;
use std::rc::Rc;
@ -101,18 +101,14 @@ impl super::TermWindow {
}
}
window.set_resize_increments(
if self.config.use_resize_increments {
self.render_metrics.cell_size.width as u16
} else {
1
},
if self.config.use_resize_increments {
self.render_metrics.cell_size.height as u16
} else {
1
},
);
window.set_resize_increments(if self.config.use_resize_increments {
ResizeIncrement {
x: self.render_metrics.cell_size.width as u16,
y: self.render_metrics.cell_size.height as u16,
}
} else {
ResizeIncrement::disabled()
});
if let Err(err) = self.recreate_texture_atlas(None) {
log::error!("recreate_texture_atlas: {:#}", err);

View File

@ -330,7 +330,7 @@ pub trait WindowOps {
/// the x and y values specified.
/// This may not be supported or respected by the desktop
/// environment.
fn set_resize_increments(&self, _x: u16, _y: u16) {}
fn set_resize_increments(&self, _incr: ResizeIncrement) {}
fn get_os_parameters(
&self,
@ -359,3 +359,16 @@ pub struct ResolvedGeometry {
pub width: usize,
pub height: usize,
}
#[derive(Debug, Clone, Copy)]
pub struct ResizeIncrement {
pub x: u16,
pub y: u16,
}
impl ResizeIncrement {
/// Use this as a readable shorthand for disabling the feature
pub fn disabled() -> Self {
Self { x: 1, y: 1 }
}
}

View File

@ -10,8 +10,8 @@ use crate::parameters::{Border, Parameters, TitleBar};
use crate::{
Clipboard, Connection, DeadKeyStatus, Dimensions, Handled, KeyCode, KeyEvent, Modifiers,
MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, Point, RawKeyEvent, Rect,
RequestedWindowGeometry, ResolvedGeometry, ScreenPoint, Size, ULength, WindowDecorations,
WindowEvent, WindowEventSender, WindowOps, WindowState,
RequestedWindowGeometry, ResizeIncrement, ResolvedGeometry, ScreenPoint, Size, ULength,
WindowDecorations, WindowEvent, WindowEventSender, WindowOps, WindowState,
};
use anyhow::{anyhow, bail, ensure};
use async_trait::async_trait;
@ -827,9 +827,9 @@ impl WindowOps for Window {
});
}
fn set_resize_increments(&self, x: u16, y: u16) {
fn set_resize_increments(&self, incr: ResizeIncrement) {
Connection::with_window_inner(self.id, move |inner| {
inner.set_resize_increments(x, y);
inner.set_resize_increments(incr);
Ok(())
});
}
@ -1256,10 +1256,10 @@ impl WindowInner {
}
}
fn set_resize_increments(&self, x: u16, y: u16) {
fn set_resize_increments(&self, incr: ResizeIncrement) {
unsafe {
self.window
.setResizeIncrements_(NSSize::new(x.into(), y.into()));
.setResizeIncrements_(NSSize::new(incr.x.into(), incr.y.into()));
}
}

View File

@ -7,8 +7,8 @@ use crate::os::wayland::wl_id;
use crate::os::x11::keyboard::KeyboardWithFallback;
use crate::{
Appearance, Clipboard, Connection, Dimensions, MouseCursor, Point, Rect,
RequestedWindowGeometry, ResolvedGeometry, ScreenPoint, Window, WindowEvent, WindowEventSender,
WindowKeyEvent, WindowOps, WindowState,
RequestedWindowGeometry, ResizeIncrement, ResolvedGeometry, ScreenPoint, Window, WindowEvent,
WindowEventSender, WindowKeyEvent, WindowOps, WindowState,
};
use anyhow::{anyhow, bail, Context};
use async_io::Timer;
@ -133,7 +133,7 @@ pub struct WaylandWindowInner {
copy_and_paste: Arc<Mutex<CopyAndPaste>>,
window: Option<toolkit::window::Window<ConceptFrame>>,
dimensions: Dimensions,
resize_increments: Option<(u16, u16)>,
resize_increments: Option<ResizeIncrement>,
window_state: WindowState,
last_mouse_coords: Point,
mouse_buttons: MouseButtons,
@ -668,9 +668,9 @@ impl WaylandWindowInner {
let mut pixel_height = self.surface_to_pixels(h.try_into().unwrap());
if self.window_state.can_resize() {
if let Some((x, y)) = self.resize_increments {
let desired_pixel_width = pixel_width - (pixel_width % x as i32);
let desired_pixel_height = pixel_height - (pixel_height % y as i32);
if let Some(incr) = self.resize_increments {
let desired_pixel_width = pixel_width - (pixel_width % incr.x as i32);
let desired_pixel_height = pixel_height - (pixel_height % incr.y as i32);
w = self.pixels_to_surface(desired_pixel_width) as u32;
h = self.pixels_to_surface(desired_pixel_height) as u32;
pixel_width = self.surface_to_pixels(w.try_into().unwrap());
@ -995,9 +995,9 @@ impl WindowOps for WaylandWindow {
});
}
fn set_resize_increments(&self, x: u16, y: u16) {
fn set_resize_increments(&self, incr: ResizeIncrement) {
WaylandConnection::with_window_inner(self.0, move |inner| {
Ok(inner.set_resize_increments(x, y))
Ok(inner.set_resize_increments(incr))
});
}
@ -1229,8 +1229,8 @@ impl WaylandWindowInner {
self.title = Some(title);
}
fn set_resize_increments(&mut self, x: u16, y: u16) {
self.resize_increments = Some((x, y));
fn set_resize_increments(&mut self, incr: ResizeIncrement) {
self.resize_increments = Some(incr);
}
fn config_did_change(&mut self, config: &ConfigHandle) {

View File

@ -4,9 +4,9 @@ use crate::connection::ConnectionOps;
use crate::os::{xkeysyms, Connection, Window};
use crate::{
Appearance, Clipboard, DeadKeyStatus, Dimensions, MouseButtons, MouseCursor, MouseEvent,
MouseEventKind, MousePress, Point, Rect, RequestedWindowGeometry, ResolvedGeometry,
ScreenPoint, ScreenRect, WindowDecorations, WindowEvent, WindowEventSender, WindowOps,
WindowState,
MouseEventKind, MousePress, Point, Rect, RequestedWindowGeometry, ResizeIncrement,
ResolvedGeometry, ScreenPoint, ScreenRect, WindowDecorations, WindowEvent, WindowEventSender,
WindowOps, WindowState,
};
use anyhow::{anyhow, Context as _};
use async_trait::async_trait;
@ -1563,7 +1563,7 @@ impl XWindowInner {
});
}
fn set_resize_increments(&mut self, x: u16, y: u16) -> anyhow::Result<()> {
fn set_resize_increments(&mut self, incr: ResizeIncrement) -> anyhow::Result<()> {
use xcb_util::*;
let hints = xcb_size_hints_t {
flags: XCB_ICCCM_SIZE_HINT_P_RESIZE_INC,
@ -1575,8 +1575,8 @@ impl XWindowInner {
min_height: 0,
max_width: 0,
max_height: 0,
width_inc: x.into(),
height_inc: y.into(),
width_inc: incr.x.into(),
height_inc: incr.y.into(),
min_aspect_num: 0,
min_aspect_den: 0,
max_aspect_num: 0,
@ -1787,9 +1787,9 @@ impl WindowOps for XWindow {
});
}
fn set_resize_increments(&self, x: u16, y: u16) {
fn set_resize_increments(&self, incr: ResizeIncrement) {
XConnection::with_window_inner(self.0, move |inner| {
if let Err(err) = inner.set_resize_increments(x, y) {
if let Err(err) = inner.set_resize_increments(incr) {
log::error!("set_resize_increments failed: {:#}", err);
}
Ok(())

View File

@ -9,8 +9,8 @@ use crate::os::x11::connection::XConnection;
use crate::os::x11::window::XWindow;
use crate::screen::Screens;
use crate::{
Appearance, Clipboard, MouseCursor, Rect, RequestedWindowGeometry, ScreenPoint, WindowEvent,
WindowOps,
Appearance, Clipboard, MouseCursor, Rect, RequestedWindowGeometry, ResizeIncrement,
ScreenPoint, WindowEvent, WindowOps,
};
use async_trait::async_trait;
use config::ConfigHandle;
@ -314,11 +314,11 @@ impl WindowOps for Window {
}
}
fn set_resize_increments(&self, x: u16, y: u16) {
fn set_resize_increments(&self, incr: ResizeIncrement) {
match self {
Self::X11(x11) => x11.set_resize_increments(x, y),
Self::X11(x11) => x11.set_resize_increments(incr),
#[cfg(feature = "wayland")]
Self::Wayland(w) => w.set_resize_increments(x, y),
Self::Wayland(w) => w.set_resize_increments(incr),
}
}