Skip to content

Commit

Permalink
fixed keybind issue with linux/x11 MeteorDevelopment#4581 (MeteorDeve…
Browse files Browse the repository at this point in the history
  • Loading branch information
19MisterX98 authored Jun 21, 2024
1 parent 5b15560 commit 74b80cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public abstract class KeyboardMixin {
@Inject(method = "onKey", at = @At("HEAD"), cancellable = true)
public void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo info) {
if (key != GLFW.GLFW_KEY_UNKNOWN) {
// on Linux/X11 the modifier is not active when the key is pressed and still active when the key is released
// https://github.com/glfw/glfw/issues/1630
if (action == GLFW.GLFW_PRESS) {
modifiers |= Input.getModifier(key);
} else if (action == GLFW.GLFW_RELEASE) {
modifiers &= ~Input.getModifier(key);
}

if (client.currentScreen instanceof WidgetScreen && action == GLFW.GLFW_REPEAT) {
((WidgetScreen) client.currentScreen).keyRepeated(key, modifiers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ public static void setCursorStyle(CursorStyle style) {
lastCursorStyle = style;
}
}

public static int getModifier(int key) {
return switch (key) {
case GLFW.GLFW_KEY_LEFT_SHIFT, GLFW.GLFW_KEY_RIGHT_SHIFT -> GLFW.GLFW_MOD_SHIFT;
case GLFW.GLFW_KEY_LEFT_CONTROL, GLFW.GLFW_KEY_RIGHT_CONTROL -> GLFW.GLFW_MOD_CONTROL;
case GLFW.GLFW_KEY_LEFT_ALT, GLFW.GLFW_KEY_RIGHT_ALT -> GLFW.GLFW_MOD_ALT;
case GLFW.GLFW_KEY_LEFT_SUPER, GLFW.GLFW_KEY_RIGHT_SUPER -> GLFW.GLFW_MOD_SUPER;
default -> 0;
};
}
}

0 comments on commit 74b80cf

Please sign in to comment.