1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-19 18:57:59 +03:00

integrated-title-bar: Use snap layouts for any maximize button

This commit is contained in:
YuraIz 2022-11-18 00:04:37 +03:00 committed by Wez Furlong
parent eab21a669d
commit bcd1b03569
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
3 changed files with 22 additions and 40 deletions

View File

@ -526,6 +526,11 @@ impl super::TermWindow {
TabBarItem::None | TabBarItem::LeftStatus | TabBarItem::RightStatus => { TabBarItem::None | TabBarItem::LeftStatus | TabBarItem::RightStatus => {
context.set_window_drag_position(event.screen_coords); context.set_window_drag_position(event.screen_coords);
} }
TabBarItem::WindowButton(window::IntegratedTitleButton::Maximize) => {
if let Some(ref window) = self.window {
window.hover_maximize_button();
}
}
TabBarItem::WindowButton(_) TabBarItem::WindowButton(_)
| TabBarItem::Tab { .. } | TabBarItem::Tab { .. }
| TabBarItem::NewTabButton { .. } => {} | TabBarItem::NewTabButton { .. } => {}

View File

@ -256,6 +256,9 @@ pub trait WindowOps {
/// Resize the inner or client area of the window /// Resize the inner or client area of the window
fn set_inner_size(&self, width: usize, height: usize); fn set_inner_size(&self, width: usize, height: usize);
/// Use for windows snap layouts
fn hover_maximize_button(&self) {}
/// Requests the windowing system to start a window drag. /// Requests the windowing system to start a window drag.
/// ///
/// This is only implemented on backends that handle /// This is only implemented on backends that handle

View File

@ -2,8 +2,7 @@ use super::*;
use crate::connection::ConnectionOps; use crate::connection::ConnectionOps;
use crate::parameters::{self, Parameters}; use crate::parameters::{self, Parameters};
use crate::{ use crate::{
Appearance, Clipboard, DeadKeyStatus, Dimensions, Handled, IntegratedTitleButton, Appearance, Clipboard, DeadKeyStatus, Dimensions, Handled, KeyCode, KeyEvent, Modifiers,
IntegratedTitleButtonAlignment, IntegratedTitleButtonStyle, KeyCode, KeyEvent, Modifiers,
MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, Point, RawKeyEvent, Rect, MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, Point, RawKeyEvent, Rect,
RequestedWindowGeometry, ResolvedGeometry, ScreenPoint, ULength, WindowDecorations, RequestedWindowGeometry, ResolvedGeometry, ScreenPoint, ULength, WindowDecorations,
WindowEvent, WindowEventSender, WindowOps, WindowState, WindowEvent, WindowEventSender, WindowOps, WindowState,
@ -862,6 +861,12 @@ impl WindowOps for Window {
}); });
} }
fn hover_maximize_button(&self) {
unsafe {
MAXBTN_HOVERED = true;
}
}
fn set_window_position(&self, coords: ScreenPoint) { fn set_window_position(&self, coords: ScreenPoint) {
Connection::with_window_inner(self.0, move |inner| { Connection::with_window_inner(self.0, move |inner| {
inner.set_window_position(coords); inner.set_window_position(coords);
@ -1083,6 +1088,8 @@ unsafe fn wm_nccalcsize(hwnd: HWND, _msg: UINT, wparam: WPARAM, lparam: LPARAM)
Some(0) Some(0)
} }
static mut MAXBTN_HOVERED: bool = false;
unsafe fn wm_nchittest(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option<LRESULT> { unsafe fn wm_nchittest(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option<LRESULT> {
let inner = rc_from_hwnd(hwnd)?; let inner = rc_from_hwnd(hwnd)?;
let inner = inner.borrow_mut(); let inner = inner.borrow_mut();
@ -1160,29 +1167,10 @@ unsafe fn wm_nchittest(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) ->
} }
} }
// When you can predict maximize button position let use_snap_layouts = !*IS_WIN10;
let use_snap_layouts = !*IS_WIN10 if use_snap_layouts && MAXBTN_HOVERED {
&& inner.config.window_decorations == WindowDecorations::INTEGRATED_BUTTONS MAXBTN_HOVERED = false;
&& inner.config.integrated_title_button_style == IntegratedTitleButtonStyle::Windows return Some(HTMAXBUTTON);
&& inner.config.integrated_title_button_alignment == IntegratedTitleButtonAlignment::Right
&& matches!(
&inner.config.integrated_title_buttons[..],
&[.., IntegratedTitleButton::Maximize, _]
)
&& inner.config.use_fancy_tab_bar;
if use_snap_layouts {
let scale = GetDpiForWindow(inner.hwnd.0) as f64 / 96.0;
let button_height = (30.0 * scale) as isize;
if cursor_point.y >= client_rect.top as isize
&& cursor_point.y < client_rect.top as isize + button_height
{
let btn_width = (45.0 * scale) as isize;
let maximize_btn_pos = (client_rect.right as isize).saturating_sub(btn_width * 2);
if cursor_point.x >= maximize_btn_pos && cursor_point.x < maximize_btn_pos + btn_width {
return Some(HTMAXBUTTON);
}
}
} }
Some(HTCLIENT) Some(HTCLIENT)
@ -2697,21 +2685,7 @@ unsafe fn do_wnd_proc(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) ->
msg, msg,
WM_NCMOUSEMOVE | WM_NCMOUSELEAVE | WM_NCLBUTTONDOWN | WM_NCLBUTTONDBLCLK WM_NCMOUSEMOVE | WM_NCMOUSELEAVE | WM_NCLBUTTONDOWN | WM_NCLBUTTONDBLCLK
) { ) {
let inner = rc_from_hwnd(hwnd)?; let use_snap_layouts = !*IS_WIN10;
let inner = inner.borrow();
// When you can predict maximize button position
let use_snap_layouts = !*IS_WIN10
&& inner.config.window_decorations == WindowDecorations::INTEGRATED_BUTTONS
&& inner.config.integrated_title_button_style
== IntegratedTitleButtonStyle::Windows
&& inner.config.integrated_title_button_alignment
== IntegratedTitleButtonAlignment::Right
&& matches!(
&inner.config.integrated_title_buttons[..],
&[.., IntegratedTitleButton::Maximize, _]
)
&& inner.config.use_fancy_tab_bar;
std::mem::drop(inner);
if use_snap_layouts { if use_snap_layouts {
return match msg { return match msg {
WM_NCMOUSEMOVE => nc_mouse_move(hwnd, msg, wparam, lparam), WM_NCMOUSEMOVE => nc_mouse_move(hwnd, msg, wparam, lparam),