core: send mouse hover point

This commit is contained in:
Mitchell Hashimoto
2023-11-29 14:39:50 -08:00
parent 3a599ec7df
commit 8fcf3f08dd
3 changed files with 27 additions and 11 deletions

View File

@ -138,6 +138,9 @@ const Mouse = struct {
/// True if the mouse is hidden /// True if the mouse is hidden
hidden: bool = false, hidden: bool = false,
/// True if the mouse position is currently over a link.
over_link: bool = false,
}; };
/// The configuration that a surface has, this is copied from the main /// The configuration that a surface has, this is copied from the main
@ -2059,18 +2062,21 @@ pub fn cursorPosCallback(
// Always show the mouse again if it is hidden // Always show the mouse again if it is hidden
if (self.mouse.hidden) self.showMouse(); if (self.mouse.hidden) self.showMouse();
// The mouse position in the viewport
const pos_vp = self.posToViewport(pos.x, pos.y);
// We are reading/writing state for the remainder // We are reading/writing state for the remainder
self.renderer_state.mutex.lock(); self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock(); defer self.renderer_state.mutex.unlock();
// Update our mouse state
self.renderer_state.mouse.point = pos_vp;
// If we have an inspector, we need to always record position information // If we have an inspector, we need to always record position information
if (self.inspector) |insp| { if (self.inspector) |insp| {
insp.mouse.last_xpos = pos.x; insp.mouse.last_xpos = pos.x;
insp.mouse.last_ypos = pos.y; insp.mouse.last_ypos = pos.y;
insp.mouse.last_point = pos_vp.toScreen(&self.io.terminal.screen);
const point = self.posToViewport(pos.x, pos.y);
insp.mouse.last_point = point.toScreen(&self.io.terminal.screen);
try self.queueRender(); try self.queueRender();
} }
@ -2115,8 +2121,7 @@ pub fn cursorPosCallback(
} }
// Convert to points // Convert to points
const viewport_point = self.posToViewport(pos.x, pos.y); const screen_point = pos_vp.toScreen(&self.io.terminal.screen);
const screen_point = viewport_point.toScreen(&self.io.terminal.screen);
// Handle dragging depending on click count // Handle dragging depending on click count
switch (self.mouse.left_click_count) { switch (self.mouse.left_click_count) {
@ -2130,12 +2135,14 @@ pub fn cursorPosCallback(
} }
// Handle link hovering // Handle link hovering
// TODO: update render state with mouse pos
// TODO: unsure if resetting cursor logic is correct
if (try self.linkAtPos(pos)) |_| { if (try self.linkAtPos(pos)) |_| {
self.mouse.over_link = true;
try self.rt_surface.setMouseShape(.pointer); try self.rt_surface.setMouseShape(.pointer);
} else { try self.queueRender();
} else if (self.mouse.over_link) {
self.mouse.over_link = false;
try self.rt_surface.setMouseShape(self.io.terminal.mouse_shape); try self.rt_surface.setMouseShape(self.io.terminal.mouse_shape);
try self.queueRender();
} }
} }

View File

@ -566,6 +566,7 @@ pub fn updateFrame(
bg: terminal.color.RGB, bg: terminal.color.RGB,
selection: ?terminal.Selection, selection: ?terminal.Selection,
screen: terminal.Screen, screen: terminal.Screen,
mouse: renderer.State.Mouse,
preedit: ?renderer.State.Preedit, preedit: ?renderer.State.Preedit,
cursor_style: ?renderer.CursorStyle, cursor_style: ?renderer.CursorStyle,
}; };
@ -633,6 +634,7 @@ pub fn updateFrame(
.bg = self.background_color, .bg = self.background_color,
.selection = selection, .selection = selection,
.screen = screen_copy, .screen = screen_copy,
.mouse = state.mouse,
.preedit = if (cursor_style != null) state.preedit else null, .preedit = if (cursor_style != null) state.preedit else null,
.cursor_style = cursor_style, .cursor_style = cursor_style,
}; };
@ -643,6 +645,7 @@ pub fn updateFrame(
try self.rebuildCells( try self.rebuildCells(
critical.selection, critical.selection,
&critical.screen, &critical.screen,
critical.mouse,
critical.preedit, critical.preedit,
critical.cursor_style, critical.cursor_style,
); );
@ -1365,6 +1368,7 @@ fn rebuildCells(
self: *Metal, self: *Metal,
term_selection: ?terminal.Selection, term_selection: ?terminal.Selection,
screen: *terminal.Screen, screen: *terminal.Screen,
mouse: renderer.State.Mouse,
preedit: ?renderer.State.Preedit, preedit: ?renderer.State.Preedit,
cursor_style_: ?renderer.CursorStyle, cursor_style_: ?renderer.CursorStyle,
) !void { ) !void {
@ -1391,7 +1395,7 @@ fn rebuildCells(
var link_match_set = try self.config.links.matchSet( var link_match_set = try self.config.links.matchSet(
arena_alloc, arena_alloc,
screen, screen,
.{}, // TODO: mouse hover point mouse.point orelse .{},
); );
// Determine our x/y range for preedit. We don't want to render anything // Determine our x/y range for preedit. We don't want to render anything

View File

@ -29,7 +29,12 @@ preedit: ?Preedit = null,
/// need about the mouse. /// need about the mouse.
mouse: Mouse = .{}, mouse: Mouse = .{},
pub const Mouse = struct {}; pub const Mouse = struct {
/// The point on the viewport where the mouse currently is. We use
/// viewport points to avoid the complexity of mapping the mouse to
/// the renderer state.
point: ?terminal.point.Viewport = null,
};
/// The pre-edit state. See Surface.preeditCallback for more information. /// The pre-edit state. See Surface.preeditCallback for more information.
pub const Preedit = struct { pub const Preedit = struct {