Skip to content
Open
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
25 changes: 21 additions & 4 deletions src/main/java/net/notcoded/wayfix/mixin/MonitorFixWindowMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static net.notcoded.wayfix.WayFix.isWayland;

import java.util.ArrayList;
import java.util.Collections;

@Mixin(Window.class)
@Mixin(value = Window.class, priority = 500)
public abstract class MonitorFixWindowMixin {

@Shadow protected abstract void onWindowPosChanged(long window, int x, int y);
@Shadow protected abstract void onWindowSizeChanged(long window, int width, int height);

@Shadow @Final private long handle;

Expand Down Expand Up @@ -50,8 +53,6 @@ private Monitor fixWrongMonitor(MonitorTracker instance, Window window) {
}
}



if(monitorID <= 0 || instance.getMonitor(monitorID) == null) {
WayFix.LOGGER.warn("Error occurred while trying to set monitor.");
WayFix.LOGGER.warn("Using primary monitor instead.");
Expand All @@ -61,7 +62,6 @@ private Monitor fixWrongMonitor(MonitorTracker instance, Window window) {
return instance.getMonitor(monitorID);
}


// KDE Plasma ONLY
@Inject(method = "updateWindowRegion", at = @At("HEAD"))
private void fixWrongMonitor(CallbackInfo ci) {
Expand All @@ -72,4 +72,21 @@ private void fixWrongMonitor(CallbackInfo ci) {

onWindowPosChanged(this.handle, pos[0], pos[1]);
}

// Wayland fractional scaling fix: MC and mods (e.g. CWB) write physical monitor
// dimensions to window.width/height, but GLFW cursor coords use logical (surface)
// coords. Reconcile every frame by querying GLFW for the actual logical size.
@Inject(method = "swapBuffers", at = @At("HEAD"))
private void wayfix$reconcileWindowSize(CallbackInfo ci) {
if (!isWayland()) return;

int[] w = new int[1];
int[] h = new int[1];
GLFW.glfwGetWindowSize(this.handle, w, h);

Window self = (Window)(Object)this;
if (w[0] > 0 && h[0] > 0 && (self.getWidth() != w[0] || self.getHeight() != h[0])) {
onWindowSizeChanged(this.handle, w[0], h[0]);
}
}
}