-
Notifications
You must be signed in to change notification settings - Fork 690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for mouse button 8/9 (128, 129) #2425
Comments
If anyone wants to hop on this, this is extremely contributor friendly, probably only a 1 line fix per button. But I want to make sure we get the button codes correct so my only request is to cross compare to the output of other terminals. (Be careful about reading the source because many terminals are GPL licensed, so I try to write scripts to see the output and just figure out their behavior) |
I can only test macOS but I can send a PR and maybe get some help/someone to test linux? |
nvm... I'm in over my head (knowing neither zig nor swift) I tried iff --git a/src/Surface.zig b/src/Surface.zig
index ef0a6bfa..7c68c34b 100644
--- a/src/Surface.zig
+++ b/src/Surface.zig
@@ -2343,6 +2343,8 @@ fn mouseReport(
.five => 65,
.six => 66,
.seven => 67,
+ .eight => 128,
+ .nine => 129,
else => return, // unsupported
};
} but that does nothing, and I can't figure out where six/seven are handled, only seeing GHOSTTY_MOUSE_LEFT, |
I guessed the But I got increasingly confused trying to pass those buttons from the macos and glfw app to the surface. In the macos app the otherMouseDown event has a buttonNumber property, the back and forwards buttons are mapped to 3 and 4. In glfw i noticed the back/forwards buttons were reporting the same events as scrolling up and down. So I changed that enum switch to map .four to .eight, .five to .nine, etc. This produces the same control sequences as Kitty (for button 8/9), but I have no idea how to deal with the rest. diff --git a/include/ghostty.h b/include/ghostty.h
index 0f4c65f5..1b7d05b3 100644
--- a/include/ghostty.h
+++ b/include/ghostty.h
@@ -60,6 +60,14 @@ typedef enum {
GHOSTTY_MOUSE_LEFT,
GHOSTTY_MOUSE_RIGHT,
GHOSTTY_MOUSE_MIDDLE,
+ GHOSTTY_MOUSE_FOUR,
+ GHOSTTY_MOUSE_FIVE,
+ GHOSTTY_MOUSE_SIX,
+ GHOSTTY_MOUSE_SEVEN,
+ GHOSTTY_MOUSE_EIGHT,
+ GHOSTTY_MOUSE_NINE,
+ GHOSTTY_MOUSE_TEN,
+ GHOSTTY_MOUSE_ELEVEN,
} ghostty_input_mouse_button_e;
typedef enum {
diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift
index 872ce17e..9d83f2df 100644
--- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift
+++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift
@@ -459,16 +459,34 @@ extension Ghostty {
override func otherMouseDown(with event: NSEvent) {
guard let surface = self.surface else { return }
- guard event.buttonNumber == 2 else { return }
+
+ let mouseButton = switch event.buttonNumber {
+ case 2: GHOSTTY_MOUSE_MIDDLE
+ case 3: GHOSTTY_MOUSE_EIGHT
+ case 4: GHOSTTY_MOUSE_NINE
+ default: GHOSTTY_MOUSE_UNKNOWN
+ }
+
+ guard mouseButton != GHOSTTY_MOUSE_UNKNOWN else { return }
+
let mods = Ghostty.ghosttyMods(event.modifierFlags)
- ghostty_surface_mouse_button(surface, GHOSTTY_MOUSE_PRESS, GHOSTTY_MOUSE_MIDDLE, mods)
+ ghostty_surface_mouse_button(surface, GHOSTTY_MOUSE_PRESS, mouseButton, mods)
}
override func otherMouseUp(with event: NSEvent) {
guard let surface = self.surface else { return }
- guard event.buttonNumber == 2 else { return }
+
+ let mouseButton = switch event.buttonNumber {
+ case 2: GHOSTTY_MOUSE_MIDDLE
+ case 3: GHOSTTY_MOUSE_EIGHT
+ case 4: GHOSTTY_MOUSE_NINE
+ default: GHOSTTY_MOUSE_UNKNOWN
+ }
+
+ guard mouseButton != GHOSTTY_MOUSE_UNKNOWN else { return }
+
let mods = Ghostty.ghosttyMods(event.modifierFlags)
- ghostty_surface_mouse_button(surface, GHOSTTY_MOUSE_RELEASE, GHOSTTY_MOUSE_MIDDLE, mods)
+ ghostty_surface_mouse_button(surface, GHOSTTY_MOUSE_RELEASE, mouseButton, mods)
}
diff --git a/src/Surface.zig b/src/Surface.zig
index bd5073e3..0a765276 100644
--- a/src/Surface.zig
+++ b/src/Surface.zig
@@ -2395,6 +2395,8 @@ fn mouseReport(
.five => 65,
.six => 66,
.seven => 67,
+ .eight => 128,
+ .nine => 129,
else => return, // unsupported
};
}
diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig
index 668dd914..ac8b046f 100644
--- a/src/apprt/glfw.zig
+++ b/src/apprt/glfw.zig
@@ -1132,11 +1132,11 @@ pub const Surface = struct {
.left => .left,
.right => .right,
.middle => .middle,
- .four => .four,
- .five => .five,
- .six => .six,
- .seven => .seven,
- .eight => .eight,
+ .four => .eight,
+ .five => .nine,
+ .six => .ten,
+ .seven => .eleven,
+ .eight => unreachable, //???
};
const action: input.MouseButtonState = switch (glfw_action) {
.press => .press, |
I was trying to imply that given four, five etc already work fine, but not sure how, that GHOSTTY_MOUSE_FOUR... wouldn't be necessary |
Similar to #2423 but with left/right mouswheel buttons,
kitty shows them as 128,129
Originally posted by @ldemailly in #2424 (comment)
The text was updated successfully, but these errors were encountered: