diff --git a/assets/ArkPetsConfigDefault.json b/assets/ArkPetsConfigDefault.json
index d9677978..2d6970f7 100644
--- a/assets/ArkPetsConfigDefault.json
+++ b/assets/ArkPetsConfigDefault.json
@@ -33,5 +33,6 @@
"transition_duration":0.3,
"transition_type":"EASE_OUT_CUBIC",
"window_style_toolwindow":true,
- "window_style_topmost":true
+ "window_style_topmost":true,
+ "window_system":"AUTO"
}
\ No newline at end of file
diff --git a/assets/UI/SettingsModule.fxml b/assets/UI/SettingsModule.fxml
index 08992c70..6910c8a9 100644
--- a/assets/UI/SettingsModule.fxml
+++ b/assets/UI/SettingsModule.fxml
@@ -116,6 +116,11 @@
+
+
+
+
+
diff --git a/core/src/cn/harryh/arkpets/ArkConfig.java b/core/src/cn/harryh/arkpets/ArkConfig.java
index aea4c781..0df5d7e5 100644
--- a/core/src/cn/harryh/arkpets/ArkConfig.java
+++ b/core/src/cn/harryh/arkpets/ArkConfig.java
@@ -3,6 +3,7 @@
*/
package cn.harryh.arkpets;
+import cn.harryh.arkpets.platform.WindowSystem;
import cn.harryh.arkpets.transitions.EasingFunction;
import cn.harryh.arkpets.utils.IOUtils.FileUtil;
import cn.harryh.arkpets.utils.Logger;
@@ -100,6 +101,8 @@ public class ArkConfig implements Serializable {
public boolean window_style_toolwindow;
/** @since ArkPets 3.2 */ @JSONField(defaultValue = "true")
public boolean window_style_topmost;
+ /** @since ArkPets 4.0 */ @JSONField(defaultValue = "AUTO")
+ public String window_system;
private ArkConfig() {
}
@@ -175,6 +178,17 @@ public static EasingFunction getEasingFunctionFrom(String string) {
}
}
+ /** @see WindowSystem
+ */
+ public static WindowSystem getWindowSystemFrom(String string) {
+ try {
+ return WindowSystem.valueOf(string);
+ } catch (IllegalArgumentException e) {
+ Logger.warn("Config", "Invalid window system, using auto detect");
+ return WindowSystem.AUTO;
+ }
+ }
+
/** @see com.badlogic.gdx.graphics.Color
*/
public static Color getGdxColorFrom(String string) {
diff --git a/core/src/cn/harryh/arkpets/concurrent/ProcessPool.java b/core/src/cn/harryh/arkpets/concurrent/ProcessPool.java
index f5018b42..7cced10b 100644
--- a/core/src/cn/harryh/arkpets/concurrent/ProcessPool.java
+++ b/core/src/cn/harryh/arkpets/concurrent/ProcessPool.java
@@ -6,6 +6,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.*;
@@ -67,6 +68,8 @@ public Future submit(Class> clazz, List jvmArgs, List env = builder.environment();
+ env.remove("GDK_BACKEND");
Process process = builder.inheritIO().start();
int exitValue = process.waitFor();
return new ProcessResult(exitValue, process.pid());
diff --git a/core/src/cn/harryh/arkpets/platform/NullHWndCtrl.java b/core/src/cn/harryh/arkpets/platform/NullHWndCtrl.java
index b191f343..5226562d 100644
--- a/core/src/cn/harryh/arkpets/platform/NullHWndCtrl.java
+++ b/core/src/cn/harryh/arkpets/platform/NullHWndCtrl.java
@@ -4,11 +4,27 @@
package cn.harryh.arkpets.platform;
+import com.badlogic.gdx.Gdx;
+
+
public class NullHWndCtrl extends HWndCtrl {
+ private static boolean startupFind;
+ private int lastw, lasth;
+
public NullHWndCtrl() {
super("", new WindowRect());
}
+ public static NullHWndCtrl find(String className, String windowName) {
+ if (windowName.equals("ArkPets")) {
+ if (!NullHWndCtrl.startupFind) {
+ NullHWndCtrl.startupFind = true;
+ return null;
+ }
+ }
+ return new NullHWndCtrl();
+ }
+
@Override
public boolean isForeground() {
return false;
@@ -35,6 +51,11 @@ public void setForeground() {
@Override
public void setWindowPosition(HWndCtrl insertAfter, int x, int y, int w, int h) {
+ if (lasth != h || lastw != w) {
+ lasth = h;
+ lastw = w;
+ Gdx.graphics.setWindowedMode(w, h);
+ }
}
@Override
diff --git a/core/src/cn/harryh/arkpets/platform/WindowSystem.java b/core/src/cn/harryh/arkpets/platform/WindowSystem.java
index abfa11c6..5966ad22 100644
--- a/core/src/cn/harryh/arkpets/platform/WindowSystem.java
+++ b/core/src/cn/harryh/arkpets/platform/WindowSystem.java
@@ -41,10 +41,24 @@ public static WindowSystem detectWindowSystem() {
}
/** Initializes the platform window system.
+ * @param platform WindowSystem to initialize.
*/
- public static void init() {
- PLATFORM = detectWindowSystem();
+ public static void init(WindowSystem platform) {
+ PLATFORM = platform;
+ if (PLATFORM == WindowSystem.AUTO){
+ PLATFORM = detectWindowSystem();
+ }
Logger.info("System", "Using " + PLATFORM.toString() + " Window System");
+ switch (PLATFORM) {
+ // TODO
+ }
+ }
+
+ /** Get current WindowSystem.
+ * @return The current WindowSystem.
+ */
+ public static WindowSystem getWindowSystem() {
+ return PLATFORM;
}
/** Finds a window.
@@ -58,7 +72,7 @@ public static HWndCtrl findWindow(String className, String windowText) {
return User32HWndCtrl.find(className, windowText);
}
default -> {
- return new NullHWndCtrl();
+ return NullHWndCtrl.find(className, windowText);
}
}
}
@@ -97,4 +111,23 @@ public static HWndCtrl getTopmostWindow() {
public static void free() {
// TODO
}
+
+ /** Return current WindowSystem should enable resize.
+ */
+ public static boolean needResize() {
+ switch (PLATFORM) {
+ case X11, MUTTER, KWIN -> {
+ return true;
+ }
+ default -> {
+ return false;
+ }
+ }
+ }
+
+ /** Return current WindowSystem should enable decoration.
+ */
+ public static boolean needDecorated() {
+ return PLATFORM == NULL;
+ }
}
diff --git a/desktop/src/cn/harryh/arkpets/EmbeddedLauncher.java b/desktop/src/cn/harryh/arkpets/EmbeddedLauncher.java
index 70776e5d..588eeea6 100644
--- a/desktop/src/cn/harryh/arkpets/EmbeddedLauncher.java
+++ b/desktop/src/cn/harryh/arkpets/EmbeddedLauncher.java
@@ -32,7 +32,7 @@ public static void main (String[] args) {
ArgPending.argCache = args;
// Logger
Logger.initialize(LogConfig.logCorePath, LogConfig.logCoreMaxKeep);
- ArkConfig appConfig = Objects.requireNonNull(ArkConfig.getConfig());
+ ArkConfig appConfig = Objects.requireNonNull(ArkConfig.getConfig(), "ArkConfig returns a null instance, please check the config file.");
try {
Logger.setLevel(appConfig.logging_level);
} catch (Exception ignored) {
@@ -82,16 +82,16 @@ protected void process(String command, String addition) {
Logger.info("System", "Entering the app of EmbeddedLauncher");
Logger.info("System", "ArkPets version is " + appVersion);
Logger.debug("System", "Default charset is " + Charset.defaultCharset());
-
+ WindowSystem windowSystem = ArkConfig.getWindowSystemFrom(appConfig.window_system);
try {
- WindowSystem.init();
+ WindowSystem.init(windowSystem);
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
// Configure FPS
config.setForegroundFPS(fpsDefault);
config.setIdleFPS(fpsDefault);
// Configure window layout
- config.setDecorated(false);
- config.setResizable(false);
+ config.setDecorated(WindowSystem.needDecorated());
+ config.setResizable(WindowSystem.needResize());
config.setWindowedMode(coreWidthDefault, coreHeightDefault);
config.setWindowPosition(0, 0);
// Configure window title
diff --git a/desktop/src/cn/harryh/arkpets/controllers/SettingsModule.java b/desktop/src/cn/harryh/arkpets/controllers/SettingsModule.java
index 19d1e61f..24cdce29 100644
--- a/desktop/src/cn/harryh/arkpets/controllers/SettingsModule.java
+++ b/desktop/src/cn/harryh/arkpets/controllers/SettingsModule.java
@@ -9,10 +9,12 @@
import cn.harryh.arkpets.guitasks.CheckAppUpdateTask;
import cn.harryh.arkpets.guitasks.GuiTask;
import cn.harryh.arkpets.platform.StartupConfig;
+import cn.harryh.arkpets.platform.WindowSystem;
import cn.harryh.arkpets.utils.*;
import cn.harryh.arkpets.utils.GuiComponents.*;
import com.badlogic.gdx.graphics.Color;
import com.jfoenix.controls.*;
+import com.sun.jna.Platform;
import javafx.concurrent.ScheduledService;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
@@ -25,6 +27,7 @@
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -92,6 +95,10 @@ public final class SettingsModule implements Controller {
@FXML
private JFXButton configWindowToolwindowHelp;
+ @FXML
+ private JFXComboBox> configWindowSystem;
+ @FXML
+ private JFXButton configWindowSystemHelp;
@FXML
private Label aboutQueryUpdate;
@FXML
@@ -350,6 +357,62 @@ public String getContent() {
};
}
};
+
+ NamedItem[] items = (NamedItem[]) getWindowSystemItems().toArray();
+ new ComboBoxSetup<>(configWindowSystem).setItems(items)
+ .selectValue(app.config.window_system, app.config.window_system)
+ .setOnNonNullValueUpdated((observable, oldValue, newValue) -> {
+ app.config.window_system = newValue.value();
+ app.config.save();
+ });
+ new HelpHandbookEntrance(app.body, configWindowSystemHelp) {
+ @Override
+ public Handbook getHandbook() {
+ return new ControlHelpHandbook((Labeled) configWindowSystem.getParent().getChildrenUnmodifiable().get(0)) {
+ @Override
+ public String getContent() {
+ return getWindowSystemInfo();
+ }
+ };
+ }
+ };
+ }
+
+ private static ArrayList> getWindowSystemItems() {
+ ArrayList> windowSystemItems = new ArrayList<>();
+ windowSystemItems.add(new NamedItem<>("自动", WindowSystem.AUTO.name()));
+ if (Platform.isWindows()) {
+ windowSystemItems.add(new NamedItem<>("User32", WindowSystem.USER32.name()));
+ }
+ if (Platform.isLinux()) {
+ windowSystemItems.add(new NamedItem<>("X11", WindowSystem.X11.name()));
+ windowSystemItems.add(new NamedItem<>("Mutter", WindowSystem.MUTTER.name()));
+ windowSystemItems.add(new NamedItem<>("KWin", WindowSystem.KWIN.name()));
+ }
+ if (Platform.isMac()) {
+ windowSystemItems.add(new NamedItem<>("Quartz", WindowSystem.QUARTZ.name()));
+ }
+ windowSystemItems.add(new NamedItem<>("NULL", WindowSystem.NULL.name()));
+ return windowSystemItems;
+ }
+
+ private static String getWindowSystemInfo() {
+ String content = "不同平台对于窗口查询、操作有不同的 API,除非你遇到了桌宠窗口的问题,否则通常不需要更改。以下是对 API 的简单介绍:\n";
+ if (Platform.isWindows()) {
+ content += "User32 —— Windows 窗口系统。\n";
+ }
+ if (Platform.isLinux()) {
+ content += """
+ Mutter —— GNOME 环境,需要安装集成扩展。
+ KWin —— KDE 环境,需要安装集成插件。
+ X11 —— 通用 X11 环境支持,适用于 Xfce,Mate,LXDE 等环境。
+ """;
+ }
+ if (Platform.isMac()) {
+ content += "Quartz —— MacOS Quartz 窗口系统。\n";
+ }
+ content += "NULL —— 空实现,桌宠不会有任何窗口交互。";
+ return content;
}
private void initAbout() {