1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 13:52:55 +03:00

integrated-title-bar: Improve windows support

This commit is contained in:
YuraIz 2022-11-17 23:23:21 +03:00 committed by Wez Furlong
parent 01aeb506c0
commit eab21a669d
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
4 changed files with 43 additions and 41 deletions

View File

@ -383,7 +383,6 @@ impl TabBarState {
#[cfg(not(target_os = "macos"))]
if use_integrated_title_buttons
&& config.integrated_title_button_alignment == IntegratedTitleButtonAlignment::Left
&& !cfg!(widnows)
{
Self::integrated_title_buttons(mouse_x, &mut x, config, &mut items, &mut line, &colors);
}

View File

@ -290,9 +290,6 @@ fn window_button_element(
use window::IntegratedTitleButtonStyle as Style;
use IntegratedTitleButton as Button;
#[cfg(windows)]
let style = Style::Windows;
let poly = match style {
Style::Windows => {
use window_buttons::windows::{CLOSE, HIDE, MAXIMIZE, RESTORE};
@ -1109,7 +1106,6 @@ impl super::TermWindow {
TabBarItem::WindowButton(_) => {
if self.config.integrated_title_button_alignment
== IntegratedTitleButtonAlignment::Left
&& cfg!(not(windows))
{
left_eles.push(item_to_elem(item))
} else {
@ -1202,7 +1198,7 @@ impl super::TermWindow {
== window::WindowDecorations::INTEGRATED_BUTTONS
&& (self.config.integrated_title_button_alignment
== IntegratedTitleButtonAlignment::Left
|| (cfg!(target_os = "macos")) && cfg!(not(windows)));
|| (cfg!(target_os = "macos")));
let left_padding = if window_buttons_at_left {
if cfg!(target_os = "macos") {

View File

@ -1465,7 +1465,7 @@ pub enum IntegratedTitleButtonAlignment {
Left,
}
#[derive(Debug, Default, FromDynamic, ToDynamic, Clone, Copy)]
#[derive(Debug, Default, FromDynamic, ToDynamic, PartialEq, Eq, Clone, Copy)]
pub enum IntegratedTitleButtonStyle {
#[default]
Windows,

View File

@ -2,7 +2,8 @@ use super::*;
use crate::connection::ConnectionOps;
use crate::parameters::{self, Parameters};
use crate::{
Appearance, Clipboard, DeadKeyStatus, Dimensions, Handled, KeyCode, KeyEvent, Modifiers,
Appearance, Clipboard, DeadKeyStatus, Dimensions, Handled, IntegratedTitleButton,
IntegratedTitleButtonAlignment, IntegratedTitleButtonStyle, KeyCode, KeyEvent, Modifiers,
MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, Point, RawKeyEvent, Rect,
RequestedWindowGeometry, ResolvedGeometry, ScreenPoint, ULength, WindowDecorations,
WindowEvent, WindowEventSender, WindowOps, WindowState,
@ -1037,8 +1038,11 @@ unsafe fn wm_nccalcsize(hwnd: HWND, _msg: UINT, wparam: WPARAM, lparam: LPARAM)
let inner = rc_from_hwnd(hwnd)?;
let inner = inner.borrow_mut();
if !(wparam == 1 && (inner.config.window_decorations == WindowDecorations::RESIZE)
|| (inner.config.window_decorations == WindowDecorations::INTEGRATED_BUTTONS))
if !(wparam == 1
&& (matches!(
inner.config.window_decorations,
WindowDecorations::RESIZE | WindowDecorations::INTEGRATED_BUTTONS
)))
{
return None;
}
@ -1079,22 +1083,6 @@ unsafe fn wm_nccalcsize(hwnd: HWND, _msg: UINT, wparam: WPARAM, lparam: LPARAM)
Some(0)
}
unsafe fn maximize_button_coords(
hwnd: HWND,
) -> euclid::Point2D<isize, wezterm_input_types::PixelUnit> {
let mut client_rect = RECT::default();
GetClientRect(hwnd, &mut client_rect);
let scale = GetDpiForWindow(hwnd) as f64 / 96.0;
let mut coords = mouse_coords(0);
coords.x = client_rect.right as isize - (60.0 * scale) as isize;
coords.y = 5;
coords
}
unsafe fn wm_nchittest(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option<LRESULT> {
let inner = rc_from_hwnd(hwnd)?;
let inner = inner.borrow_mut();
@ -1172,9 +1160,18 @@ unsafe fn wm_nchittest(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) ->
}
}
if inner.config.window_decorations == WindowDecorations::INTEGRATED_BUTTONS
&& inner.config.use_fancy_tab_bar
{
// 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;
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
@ -1484,6 +1481,12 @@ fn mouse_coords(lparam: LPARAM) -> Point {
Point::new(point.x as _, point.y as _)
}
fn nc_mouse_coords(hwnd: HWND, lparam: LPARAM) -> Point {
let point = MAKEPOINTS(lparam as _);
let point = ScreenPoint::new(point.x as _, point.y as _);
screen_to_client(hwnd, point)
}
fn screen_to_client(hwnd: HWND, point: ScreenPoint) -> Point {
let mut point = POINT {
x: point.x.try_into().unwrap(),
@ -1561,7 +1564,7 @@ unsafe fn nc_mouse_button(
hwnd: HWND,
msg: UINT,
wparam: WPARAM,
_lparam: LPARAM,
lparam: LPARAM,
) -> Option<LRESULT> {
let inner = rc_from_hwnd(hwnd)?;
// To support dragging the window, capture when the left
@ -1580,7 +1583,7 @@ unsafe fn nc_mouse_button(
}
let (modifiers, mouse_buttons) = mods_and_buttons(0);
let coords = maximize_button_coords(hwnd);
let coords = nc_mouse_coords(hwnd, lparam);
let event = MouseEvent {
kind: match msg {
@ -1630,12 +1633,7 @@ unsafe fn mouse_move(hwnd: HWND, _msg: UINT, wparam: WPARAM, lparam: LPARAM) ->
Some(0)
}
unsafe fn nc_mouse_move(
hwnd: HWND,
_msg: UINT,
wparam: WPARAM,
_lparam: LPARAM,
) -> Option<LRESULT> {
unsafe fn nc_mouse_move(hwnd: HWND, _msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option<LRESULT> {
let inner = rc_from_hwnd(hwnd)?;
let mut inner = inner.borrow_mut();
@ -1657,7 +1655,7 @@ unsafe fn nc_mouse_move(
}
let (modifiers, mouse_buttons) = mods_and_buttons(0);
let coords = maximize_button_coords(hwnd);
let coords = nc_mouse_coords(hwnd, lparam);
let event = MouseEvent {
kind: MouseEventKind::Move,
@ -2701,11 +2699,20 @@ unsafe fn do_wnd_proc(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) ->
) {
let inner = rc_from_hwnd(hwnd)?;
let inner = inner.borrow();
let use_shap_layouts = inner.config.window_decorations
== WindowDecorations::INTEGRATED_BUTTONS
// 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_shap_layouts {
if use_snap_layouts {
return match msg {
WM_NCMOUSEMOVE => nc_mouse_move(hwnd, msg, wparam, lparam),
WM_NCMOUSELEAVE => mouse_leave(hwnd, msg, wparam, lparam),