mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: mouse scroll events
This commit is contained in:
@ -231,6 +231,7 @@ void ghostty_surface_key(ghostty_surface_t, ghostty_input_action_e, ghostty_inpu
|
||||
void ghostty_surface_char(ghostty_surface_t, uint32_t);
|
||||
void ghostty_surface_mouse_button(ghostty_surface_t, ghostty_input_mouse_state_e, ghostty_input_mouse_button_e, ghostty_input_mods_e);
|
||||
void ghostty_surface_mouse_pos(ghostty_surface_t, double, double);
|
||||
void ghostty_surface_mouse_scroll(ghostty_surface_t, double, double);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -329,6 +329,19 @@ class TerminalSurfaceView_Real: NSView, NSTextInputClient, ObservableObject {
|
||||
self.mouseMoved(with: event)
|
||||
}
|
||||
|
||||
override func scrollWheel(with event: NSEvent) {
|
||||
guard let surface = self.surface else { return }
|
||||
|
||||
var x = event.scrollingDeltaX
|
||||
var y = event.scrollingDeltaY
|
||||
if event.hasPreciseScrollingDeltas {
|
||||
x *= 0.1
|
||||
y *= 0.1
|
||||
}
|
||||
|
||||
ghostty_surface_mouse_scroll(surface, x, y)
|
||||
}
|
||||
|
||||
override func keyDown(with event: NSEvent) {
|
||||
guard let surface = self.surface else { return }
|
||||
let key = Self.keycodes[event.keyCode] ?? GHOSTTY_KEY_INVALID
|
||||
|
@ -458,4 +458,8 @@ pub const CAPI = struct {
|
||||
export fn ghostty_surface_mouse_pos(win: *Window, x: f64, y: f64) void {
|
||||
win.window.cursorPosCallback(x, y);
|
||||
}
|
||||
|
||||
export fn ghostty_surface_mouse_scroll(win: *Window, x: f64, y: f64) void {
|
||||
win.window.scrollCallback(x, y);
|
||||
}
|
||||
};
|
||||
|
@ -175,6 +175,13 @@ pub const Window = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn scrollCallback(self: *const Window, xoff: f64, yoff: f64) void {
|
||||
self.core_win.scrollCallback(xoff, yoff) catch |err| {
|
||||
log.err("error in scroll callback err={}", .{err});
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
pub fn cursorPosCallback(self: *Window, x: f64, y: f64) void {
|
||||
// Convert our unscaled x/y to scaled.
|
||||
self.cursor_pos = self.core_win.window.cursorPosToPixels(.{
|
||||
|
Reference in New Issue
Block a user