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
31 changes: 31 additions & 0 deletions src/main/java/net/vulkanmod/mixin/wayland/KeyboardHandlerM.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.vulkanmod.mixin.wayland;

import net.minecraft.client.KeyboardHandler;
import net.minecraft.client.input.CharacterEvent;
import net.vulkanmod.config.Platform;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(KeyboardHandler.class)
public class KeyboardHandlerM {

/**
* Ensures Ctrl-based shortcuts work correctly.
*
* On native Wayland (i.e. not XWayland), GLFW fires both a key event and a char callback event
* when a Ctrl+key combination is pressed, because the compositor delivers the unmodified
* character as a separate char event regardless of held modifiers. This causes both the
* shortcut action and a character insertion to happen simultaneously (e.g. Ctrl+v pastes and appends 'v').
*
* This mixin cancels that char event if the Ctrl modifier is set, thus fixing the issue.
*/
@Inject(method = "charTyped", at = @At("HEAD"), cancellable = true)
private void cancelCtrlCharTyped(long window, CharacterEvent event, CallbackInfo ci) {
if (Platform.isWayLand() && (event.modifiers() & GLFW.GLFW_MOD_CONTROL) != 0) {
ci.cancel();
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/vulkanmod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"vertex.VertexMultiConsumersM$SheetDecalM",

"wayland.InputConstantsM",
"wayland.KeyboardHandlerM",
"wayland.MinecraftMixin",

"texture.mip.MipmapGeneratorM",
Expand Down