Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
}
}