Fix scaling issues on Linux
This commit is contained in:
4 files changed
+119
-26
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package com.loomcom.symon.ui;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class X11ResourceReader {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(X11ResourceReader.class.getName());
|
||||
|
||||
|
||||
public interface X11 extends Library {
|
||||
X11 INSTANCE = Native.load("X11", X11.class);
|
||||
|
||||
Pointer XOpenDisplay(String display);
|
||||
Pointer XResourceManagerString(Pointer display);
|
||||
void XCloseDisplay(Pointer display);
|
||||
}
|
||||
|
||||
public static Double readXftDpiScale() {
|
||||
Pointer display = null;
|
||||
try {
|
||||
display = X11.INSTANCE.XOpenDisplay(null);
|
||||
if (display == null) {
|
||||
return null; // não conseguimos ligar ao X server (ex: Wayland puro sem XWayland)
|
||||
}
|
||||
|
||||
Pointer resourceString = X11.INSTANCE.XResourceManagerString(display);
|
||||
if (resourceString == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String resources = resourceString.getString(0);
|
||||
for (String line : resources.split("\n")) {
|
||||
if (line.startsWith("Xft.dpi:")) {
|
||||
int dpi = Integer.parseInt(line.split(":")[1].trim());
|
||||
return Math.round((dpi / 96.0) * 4) / 4.0;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (UnsatisfiedLinkError | Exception e) {
|
||||
logger.debug("Could not read X11 resource manager (libX11 unavailable?)", e);
|
||||
return null;
|
||||
} finally {
|
||||
if (display != null) {
|
||||
X11.INSTANCE.XCloseDisplay(display);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user