-
Notifications
You must be signed in to change notification settings - Fork 310
Expand file tree
/
Copy pathWindowMixin.java
More file actions
227 lines (186 loc) · 7.48 KB
/
WindowMixin.java
File metadata and controls
227 lines (186 loc) · 7.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package net.vulkanmod.mixin.window;
import com.mojang.blaze3d.TracyFrameCapture;
import com.mojang.blaze3d.platform.*;
import com.mojang.blaze3d.systems.RenderSystem;
import net.vulkanmod.Initializer;
import net.vulkanmod.config.Config;
import net.vulkanmod.config.Platform;
import net.vulkanmod.config.video.VideoModeManager;
import net.vulkanmod.config.option.Options;
import net.vulkanmod.config.video.VideoModeSet;
import net.vulkanmod.config.video.WindowMode;
import net.vulkanmod.vulkan.Renderer;
import net.vulkanmod.vulkan.VRenderSystem;
import net.vulkanmod.vulkan.Vulkan;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import static org.lwjgl.glfw.GLFW.*;
@Mixin(Window.class)
public abstract class WindowMixin {
@Final @Shadow private long handle;
@Shadow private boolean vsync;
@Shadow private boolean fullscreen;
@Shadow @Final private static Logger LOGGER;
@Shadow private int windowedX;
@Shadow private int windowedY;
@Shadow private int windowedWidth;
@Shadow private int windowedHeight;
@Shadow private int x;
@Shadow private int y;
@Shadow private int width;
@Shadow private int height;
@Shadow private int framebufferWidth;
@Shadow private int framebufferHeight;
@Shadow public abstract int getWidth();
@Shadow public abstract int getHeight();
@Shadow protected abstract void updateFullscreen(boolean bl, @Nullable TracyFrameCapture tracyFrameCapture);
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwWindowHint(II)V"))
private void redirect(int hint, int value) { }
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwCreateWindow(IILjava/lang/CharSequence;JJ)J"))
private void vulkanHint(WindowEventHandler windowEventHandler, ScreenManager screenManager, DisplayData displayData, String string, String string2, CallbackInfo ci) {
GLFW.glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
// Enable 32bit P3 wide color gamut on macOS
if (Platform.isMacOS()) {
GLFW.glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE);
GLFW.glfwWindowHint(GLFW_RED_BITS, 10);
GLFW.glfwWindowHint(GLFW_GREEN_BITS, 10);
GLFW.glfwWindowHint(GLFW_BLUE_BITS, 10);
GLFW.glfwWindowHint(GLFW_ALPHA_BITS, 2);
}
//Fix Gnome Client-Side Decorators
boolean b = (Platform.isGnome() | Platform.isWeston() | Platform.isGeneric()) && Platform.isWayLand();
GLFW.glfwWindowHint(GLFW_DECORATED, (b ? GLFW_FALSE : GLFW_TRUE));
}
@Inject(method = "<init>", at = @At(value = "RETURN"))
private void getHandle(WindowEventHandler windowEventHandler, ScreenManager screenManager, DisplayData displayData, String string, String string2, CallbackInfo ci) {
VRenderSystem.setWindow(this.handle);
}
/**
* @author
*/
@Overwrite
public void updateVsync(boolean vsync) {
this.vsync = vsync;
Vulkan.setVsync(vsync);
}
/**
* @author
*/
@Overwrite
public void toggleFullScreen() {
this.fullscreen = !this.fullscreen;
Options.fullscreenDirty = true;
}
/**
* @author
*/
@Overwrite
public void updateDisplay(@Nullable TracyFrameCapture tracyFrameCapture) {
RenderSystem.flipFrame((Window) ((Object)this), tracyFrameCapture);
if (Options.fullscreenDirty) {
Options.fullscreenDirty = false;
this.updateFullscreen(this.vsync, tracyFrameCapture);
}
}
private boolean wasOnFullscreen = false;
/**
* @author
*/
@Overwrite
private void setMode() {
Config config = Initializer.CONFIG;
long monitor = GLFW.glfwGetPrimaryMonitor();
if (this.fullscreen) {
{
VideoModeSet.VideoMode videoMode = config.videoMode;
boolean supported;
VideoModeSet set = VideoModeManager.getFromVideoMode(videoMode);
if (set != null) {
supported = set.hasRefreshRate(videoMode.refreshRate);
}
else {
supported = false;
}
if(!supported) {
LOGGER.error("Resolution not supported, using first available as fallback");
videoMode = VideoModeManager.getFirstAvailable().getVideoMode();
}
if (!this.wasOnFullscreen) {
this.windowedX = this.x;
this.windowedY = this.y;
this.windowedWidth = this.width;
this.windowedHeight = this.height;
}
this.x = 0;
this.y = 0;
this.width = videoMode.width;
this.height = videoMode.height;
GLFW.glfwSetWindowMonitor(this.handle, monitor, this.x, this.y, this.width, this.height, videoMode.refreshRate);
this.wasOnFullscreen = true;
}
}
else if (config.windowMode == WindowMode.WINDOWED_FULLSCREEN.mode) {
VideoModeSet.VideoMode videoMode = VideoModeManager.getOsVideoMode();
if (!this.wasOnFullscreen) {
this.windowedX = this.x;
this.windowedY = this.y;
this.windowedWidth = this.width;
this.windowedHeight = this.height;
}
int width = videoMode.width;
int height = videoMode.height;
GLFW.glfwSetWindowAttrib(this.handle, GLFW_DECORATED, GLFW_FALSE);
GLFW.glfwSetWindowMonitor(this.handle, 0L, 0, 0, width, height, -1);
this.width = width;
this.height = height;
this.wasOnFullscreen = true;
} else {
this.x = this.windowedX;
this.y = this.windowedY;
this.width = this.windowedWidth;
this.height = this.windowedHeight;
GLFW.glfwSetWindowMonitor(this.handle, 0L, this.x, this.y, this.width, this.height, -1);
GLFW.glfwSetWindowAttrib(this.handle, GLFW_DECORATED, GLFW_TRUE);
this.wasOnFullscreen = false;
}
}
/**
* @author
* @reason
*/
@Overwrite
private void onFramebufferResize(long window, int width, int height) {
if (window == this.handle) {
int prevWidth = this.getWidth();
int prevHeight = this.getHeight();
if(width > 0 && height > 0) {
this.framebufferWidth = width;
this.framebufferHeight = height;
// if (this.framebufferWidth != prevWidth || this.framebufferHeight != prevHeight) {
// this.eventHandler.resizeDisplay();
// }
Renderer.scheduleSwapChainUpdate();
}
}
}
/**
* @author
* @reason
*/
@Overwrite
private void onResize(long window, int width, int height) {
this.width = width;
this.height = height;
if(width > 0 && height > 0)
Renderer.scheduleSwapChainUpdate();
}
}