1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 21:32:13 +03:00

window: add cursors for resizing up/down left/right

Change the cursor to an appropriate one of these when hoving
over and dragging a split.

Fix an issue where we wouldn't always change the cursor when
hovering over a split when multiple splits are present.
This commit is contained in:
Wez Furlong 2020-10-22 09:23:05 -07:00
parent b0fdd15d35
commit f12df0be9b
6 changed files with 37 additions and 15 deletions

View File

@ -3303,7 +3303,7 @@ impl TermWindow {
event: &MouseEvent,
context: &dyn WindowOps,
) {
let mut on_split = false;
let mut on_split = None;
if y >= 0 {
let y = y as usize;
@ -3311,24 +3311,30 @@ impl TermWindow {
on_split = match split.direction {
SplitDirection::Horizontal => {
if x == split.left && y >= split.top && y <= split.top + split.size {
true
Some(SplitDirection::Horizontal)
} else {
false
None
}
}
SplitDirection::Vertical => {
if y == split.top && x >= split.left && x <= split.left + split.size {
true
Some(SplitDirection::Vertical)
} else {
false
None
}
}
};
if on_split && event.kind == WMEK::Press(MousePress::Left) {
context.set_cursor(Some(MouseCursor::Hand));
self.split_drag_start.replace(split);
return;
if on_split.is_some() {
if event.kind == WMEK::Press(MousePress::Left) {
context.set_cursor(on_split.map(|d| match d {
SplitDirection::Horizontal => MouseCursor::SizeLeftRight,
SplitDirection::Vertical => MouseCursor::SizeUpDown,
}));
self.split_drag_start.replace(split);
return;
}
break;
}
}
}
@ -3396,12 +3402,18 @@ impl TermWindow {
}
};
context.set_cursor(Some(if on_split || self.current_highlight.is_some() {
// When hovering over a hyperlink, show an appropriate
// mouse cursor to give the cue that it is clickable
MouseCursor::Hand
} else {
MouseCursor::Text
context.set_cursor(Some(match on_split {
Some(SplitDirection::Horizontal) => MouseCursor::SizeLeftRight,
Some(SplitDirection::Vertical) => MouseCursor::SizeUpDown,
None => {
if self.current_highlight.is_some() {
// When hovering over a hyperlink, show an appropriate
// mouse cursor to give the cue that it is clickable
MouseCursor::Hand
} else {
MouseCursor::Text
}
}
}));
let event_trigger_type = match &event.kind {

View File

@ -105,6 +105,8 @@ pub enum MouseCursor {
Arrow,
Hand,
Text,
SizeUpDown,
SizeLeftRight,
}
#[allow(unused_variables)]

View File

@ -653,6 +653,8 @@ impl WindowOpsMut for WindowInner {
MouseCursor::Arrow => msg_send![ns_cursor_cls, arrowCursor],
MouseCursor::Text => msg_send![ns_cursor_cls, IBeamCursor],
MouseCursor::Hand => msg_send![ns_cursor_cls, pointingHandCursor],
MouseCursor::SizeUpDown => msg_send![ns_cursor_cls, resizeUpDown],
MouseCursor::SizeLeftRight => msg_send![ns_cursor_cls, resizeLeftRight],
};
let () = msg_send![instance, set];
}

View File

@ -929,6 +929,8 @@ impl WindowOpsMut for WaylandWindowInner {
let cursor = match cursor {
Some(MouseCursor::Arrow) => "arrow",
Some(MouseCursor::Hand) => "hand",
Some(MouseCursor::SizeUpDown) => "ns-resize",
Some(MouseCursor::SizeLeftRight) => "ew-resize",
Some(MouseCursor::Text) => "text",
None => return,
};

View File

@ -885,6 +885,8 @@ fn apply_mouse_cursor(cursor: Option<MouseCursor>) {
MouseCursor::Arrow => IDC_ARROW,
MouseCursor::Hand => IDC_HAND,
MouseCursor::Text => IDC_IBEAM,
MouseCursor::SizeUpDown => IDC_SIZENS,
MouseCursor::SizeLeftRight => IDC_SIZEWE,
},
));
},

View File

@ -288,6 +288,8 @@ impl XWindowInner {
MouseCursor::Arrow => 132,
MouseCursor::Hand => 58,
MouseCursor::Text => 152,
MouseCursor::SizeUpDown => 116,
MouseCursor::SizeLeftRight => 108,
};
let cursor_id: xcb::ffi::xcb_cursor_t = conn.generate_id();