mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
mouse button callbacks returns bool for consumption
This commit is contained in:
@ -533,7 +533,7 @@ ghostty_input_mods_e ghostty_surface_key_translation_mods(ghostty_surface_t,
|
|||||||
ghostty_input_mods_e);
|
ghostty_input_mods_e);
|
||||||
void ghostty_surface_key(ghostty_surface_t, ghostty_input_key_s);
|
void ghostty_surface_key(ghostty_surface_t, ghostty_input_key_s);
|
||||||
void ghostty_surface_text(ghostty_surface_t, const char*, uintptr_t);
|
void ghostty_surface_text(ghostty_surface_t, const char*, uintptr_t);
|
||||||
void ghostty_surface_mouse_button(ghostty_surface_t,
|
bool ghostty_surface_mouse_button(ghostty_surface_t,
|
||||||
ghostty_input_mouse_state_e,
|
ghostty_input_mouse_state_e,
|
||||||
ghostty_input_mouse_button_e,
|
ghostty_input_mouse_button_e,
|
||||||
ghostty_input_mods_e);
|
ghostty_input_mods_e);
|
||||||
|
@ -471,15 +471,39 @@ extension Ghostty {
|
|||||||
|
|
||||||
|
|
||||||
override func rightMouseDown(with event: NSEvent) {
|
override func rightMouseDown(with event: NSEvent) {
|
||||||
guard let surface = self.surface else { return }
|
guard let surface = self.surface else { return super.rightMouseDown(with: event) }
|
||||||
|
|
||||||
let mods = Ghostty.ghosttyMods(event.modifierFlags)
|
let mods = Ghostty.ghosttyMods(event.modifierFlags)
|
||||||
ghostty_surface_mouse_button(surface, GHOSTTY_MOUSE_PRESS, GHOSTTY_MOUSE_RIGHT, mods)
|
if (ghostty_surface_mouse_button(
|
||||||
|
surface,
|
||||||
|
GHOSTTY_MOUSE_PRESS,
|
||||||
|
GHOSTTY_MOUSE_RIGHT,
|
||||||
|
mods
|
||||||
|
)) {
|
||||||
|
// Consumed
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mouse event not consumed
|
||||||
|
super.rightMouseDown(with: event)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func rightMouseUp(with event: NSEvent) {
|
override func rightMouseUp(with event: NSEvent) {
|
||||||
guard let surface = self.surface else { return }
|
guard let surface = self.surface else { return super.rightMouseUp(with: event) }
|
||||||
|
|
||||||
let mods = Ghostty.ghosttyMods(event.modifierFlags)
|
let mods = Ghostty.ghosttyMods(event.modifierFlags)
|
||||||
ghostty_surface_mouse_button(surface, GHOSTTY_MOUSE_RELEASE, GHOSTTY_MOUSE_RIGHT, mods)
|
if (ghostty_surface_mouse_button(
|
||||||
|
surface,
|
||||||
|
GHOSTTY_MOUSE_RELEASE,
|
||||||
|
GHOSTTY_MOUSE_RIGHT,
|
||||||
|
mods
|
||||||
|
)) {
|
||||||
|
// Handled
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mouse event not consumed
|
||||||
|
super.rightMouseUp(with: event)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func mouseMoved(with event: NSEvent) {
|
override func mouseMoved(with event: NSEvent) {
|
||||||
@ -842,6 +866,11 @@ extension Ghostty {
|
|||||||
ghostty_surface_key(surface, key_ev)
|
ghostty_surface_key(surface, key_ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func menu(for event: NSEvent) -> NSMenu? {
|
||||||
|
Ghostty.logger.warning("menu: event!")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Menu Handlers
|
// MARK: Menu Handlers
|
||||||
|
|
||||||
|
@ -2129,12 +2129,15 @@ fn mouseShiftCapture(self: *const Surface, lock: bool) bool {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called for mouse button press/release events. This will return true
|
||||||
|
/// if the mouse event was consumed in some way (i.e. the program is capturing
|
||||||
|
/// mouse events). If the event was not consumed, then false is returned.
|
||||||
pub fn mouseButtonCallback(
|
pub fn mouseButtonCallback(
|
||||||
self: *Surface,
|
self: *Surface,
|
||||||
action: input.MouseButtonState,
|
action: input.MouseButtonState,
|
||||||
button: input.MouseButton,
|
button: input.MouseButton,
|
||||||
mods: input.Mods,
|
mods: input.Mods,
|
||||||
) !void {
|
) !bool {
|
||||||
// log.debug("mouse action={} button={} mods={}", .{ action, button, mods });
|
// log.debug("mouse action={} button={} mods={}", .{ action, button, mods });
|
||||||
|
|
||||||
// If we have an inspector, we always queue a render
|
// If we have an inspector, we always queue a render
|
||||||
@ -2155,7 +2158,7 @@ pub fn mouseButtonCallback(
|
|||||||
const screen = &self.renderer_state.terminal.screen;
|
const screen = &self.renderer_state.terminal.screen;
|
||||||
const p = screen.pages.pin(.{ .viewport = point }) orelse {
|
const p = screen.pages.pin(.{ .viewport = point }) orelse {
|
||||||
log.warn("failed to get pin for clicked point", .{});
|
log.warn("failed to get pin for clicked point", .{});
|
||||||
return;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
insp.cell.select(
|
insp.cell.select(
|
||||||
@ -2166,7 +2169,7 @@ pub fn mouseButtonCallback(
|
|||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error selecting cell for inspector err={}", .{err});
|
log.warn("error selecting cell for inspector err={}", .{err});
|
||||||
};
|
};
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2205,7 +2208,7 @@ pub fn mouseButtonCallback(
|
|||||||
if (selection) {
|
if (selection) {
|
||||||
const pos = try self.rt_surface.getCursorPos();
|
const pos = try self.rt_surface.getCursorPos();
|
||||||
try self.cursorPosCallback(pos);
|
try self.cursorPosCallback(pos);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2216,7 +2219,7 @@ pub fn mouseButtonCallback(
|
|||||||
if (button == .left and action == .release and self.mouse.over_link) {
|
if (button == .left and action == .release and self.mouse.over_link) {
|
||||||
const pos = try self.rt_surface.getCursorPos();
|
const pos = try self.rt_surface.getCursorPos();
|
||||||
if (self.processLinks(pos)) |processed| {
|
if (self.processLinks(pos)) |processed| {
|
||||||
if (processed) return;
|
if (processed) return true;
|
||||||
} else |err| {
|
} else |err| {
|
||||||
log.warn("error processing links err={}", .{err});
|
log.warn("error processing links err={}", .{err});
|
||||||
}
|
}
|
||||||
@ -2257,7 +2260,7 @@ pub fn mouseButtonCallback(
|
|||||||
|
|
||||||
// If we're doing mouse reporting, we do not support any other
|
// If we're doing mouse reporting, we do not support any other
|
||||||
// selection or highlighting.
|
// selection or highlighting.
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2269,7 +2272,7 @@ pub fn mouseButtonCallback(
|
|||||||
self.renderer_state.mutex.lock();
|
self.renderer_state.mutex.lock();
|
||||||
defer self.renderer_state.mutex.unlock();
|
defer self.renderer_state.mutex.unlock();
|
||||||
try self.clickMoveCursor(pin.*);
|
try self.clickMoveCursor(pin.*);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For left button clicks we always record some information for
|
// For left button clicks we always record some information for
|
||||||
@ -2398,6 +2401,8 @@ pub fn mouseButtonCallback(
|
|||||||
try self.startClipboardRequest(clipboard, .{ .paste = {} });
|
try self.startClipboardRequest(clipboard, .{ .paste = {} });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs the "click-to-move" logic to move the cursor to the given
|
/// Performs the "click-to-move" logic to move the cursor to the given
|
||||||
|
@ -710,10 +710,10 @@ pub const Surface = struct {
|
|||||||
action: input.MouseButtonState,
|
action: input.MouseButtonState,
|
||||||
button: input.MouseButton,
|
button: input.MouseButton,
|
||||||
mods: input.Mods,
|
mods: input.Mods,
|
||||||
) void {
|
) bool {
|
||||||
self.core_surface.mouseButtonCallback(action, button, mods) catch |err| {
|
return self.core_surface.mouseButtonCallback(action, button, mods) catch |err| {
|
||||||
log.err("error in mouse button callback err={}", .{err});
|
log.err("error in mouse button callback err={}", .{err});
|
||||||
return;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1638,8 +1638,8 @@ pub const CAPI = struct {
|
|||||||
action: input.MouseButtonState,
|
action: input.MouseButtonState,
|
||||||
button: input.MouseButton,
|
button: input.MouseButton,
|
||||||
mods: c_int,
|
mods: c_int,
|
||||||
) void {
|
) bool {
|
||||||
surface.mouseButtonCallback(
|
return surface.mouseButtonCallback(
|
||||||
action,
|
action,
|
||||||
button,
|
button,
|
||||||
@bitCast(@as(
|
@bitCast(@as(
|
||||||
|
@ -1048,7 +1048,7 @@ pub const Surface = struct {
|
|||||||
else => unreachable,
|
else => unreachable,
|
||||||
};
|
};
|
||||||
|
|
||||||
core_win.mouseButtonCallback(action, button, mods) catch |err| {
|
_ = core_win.mouseButtonCallback(action, button, mods) catch |err| {
|
||||||
log.err("error in scroll callback err={}", .{err});
|
log.err("error in scroll callback err={}", .{err});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user