mage icon indicating copy to clipboard operation
mage copied to clipboard

Scale interface on Hi-DPI

Open mattiasb opened this issue 10 years ago • 18 comments

XMage is really tiny on my shiny Hi-DPI screen on Linux (Fedora 22). It would be great if XMage scaled its interface on Hi-DPI screens (like the rest of my apps do).

mattiasb avatar May 14 '15 23:05 mattiasb

+1, this problem occurs on my Yoga 2 Pro running Windows 8 as well. It'd be awesome to be able to play on that thing instead of just my Windows desktop (since it's currently unplayable on my Linux desktop as well).

skeet70 avatar May 16 '15 22:05 skeet70

AFAIK XMage's client is made with the Swing framework, which does not support Hi-DPI (see here, here for examples). The whole client would have to be remade in JavaFX to allow this.

ghost avatar May 19 '15 02:05 ghost

That blows. Can't find anything about upcoming support for swing and scaling either. For those who are in my particular situation, setting the resolution to half the maximum and the scaling to 100% makes Xmage usable.

skeet70 avatar May 23 '15 17:05 skeet70

Looks like Linux behaviour with Swing is just really awful. I'm on ElementaryOS and the client window originally opens cut off on the right side. I have to scoot it up and over to the left, then resize to achieve the desired size.

Juicebox360 avatar Sep 15 '15 07:09 Juicebox360

This is supposed to be supported in JDK9 according to JEP-263.

I tested switching out the Nimbus look-and-feel for the GTK+ one and can confirm that the scaling looks semi-reasonable but there were a bunch of bugs (the game panel wouldn't work for example).

mattiasb avatar Sep 18 '16 19:09 mattiasb

Display scaling can be enabled for Windows 10 as follows:

  1. Install xmage in the usual way. I'm using a "C:\temp\xmage" directory in this example.

  2. Create a "javaw.exe.manifest" file and place it next to javaw.exe in the bundled JRE install (for example, at "C:\temp\xmage\java\jre1.8.0_131\bin") with the following contents:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<description>javaw</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
  <security>
    <requestedPrivileges>
      <requestedExecutionLevel xmlns:ms_asmv3="urn:schemas-microsoft-com:asm.v3"
        level="asInvoker"
        ms_asmv3:uiAccess="false">
      </requestedExecutionLevel>
    </requestedPrivileges>
  </security>
</trustInfo>
<asmv3:application>
  <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
    <ms_windowsSettings:dpiAware xmlns:ms_windowsSettings="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</ms_windowsSettings:dpiAware>
  </asmv3:windowsSettings>
</asmv3:application>
</assembly>
  1. Run regedit.exe and create a DWORD Value named "PreferExternalManifest" under "Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide". Set the value to 1.
  2. Create a modified version of startClient.bat with the following contents (for example, at "C:\temp\xmage\xmage\mage-client"):
@ECHO OFF
set JAVA_HOME=C:\temp\xmage\java\jre1.8.0_131\bin
set CLASSPATH=%JAVA_HOME%/bin;%CLASSPATH%
set PATH=%JAVA_HOME%/bin;%PATH%
start %JAVA_HOME%\javaw.exe -Xms256m -Xmx512m -XX:MaxPermSize=384m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -jar .\lib\mage-client-1.4.26.jar
  1. Run this version of startClient.bat to launch the client.

(These instructions are based on https://github.com/magarena/magarena/issues/795)

magreenblatt avatar Nov 02 '17 17:11 magreenblatt

I've been searching for a solution for a while now and can only add to the above that no combination of the following options works on linux:

GDK_SCALE=2
GDK_DPI_SCALE=2
-Dsun.java2d.uiScale=2
-Dsun.java2d.dpiaware=false

Apparently the only real solution in this case is to switch to jdk9 or use run_scaled, albeit it looks a bit pixelated.

derlhurgoyf avatar Aug 07 '19 20:08 derlhurgoyf

Apparently the only real solution in this case is to switch to jdk9 or use run_scaled, albeit it looks a bit pixelated.

Is this a future fix or is there a functional solution here? If it's the latter, could you provide some additional details?

fearphage avatar May 17 '20 14:05 fearphage

@fearphage Instead of running xmage with a version 8 jdk, use version 9 or newer. I just tried with jdk 11, works fine. To enable scaling, add this parameter to the command line: -Dsun.java2d.uiScale=2

sweber83 avatar Aug 08 '20 23:08 sweber83

@sweber83 can you give some details how you did that? What is your start command? Does everything just work?

derlhurgoyf avatar Aug 08 '20 23:08 derlhurgoyf

@derlhurgoyf Here is the command I use to start xmage:

java -Xms1G -Xmx2G -Dsun.java2d.xrender=true -Dsun.java2d.uiScale=2 -jar mage-client/lib/mage-client-1.4.44.jar

I left out the exact paths to java & the .jar file, because those will probably differ on your system. The exact version of the jdk I use is openjdk version "11.0.7" So far I did not experience any problems.

sweber83 avatar Aug 09 '20 14:08 sweber83

@sweber83 can you make example screenshots with and without that command? If it's really good then it must be added to launcher/client settings.

JayDi85 avatar Aug 09 '20 16:08 JayDi85

@JayDi85 I made two screenshots, which show the difference. xmage_lodpi xmage_hidpi

I see an issues with changing the launcher settings. As far as I know, the launcher installs its own jdk, which is a version 8 jdk, iirc. So that would first have to be changed to use a version 9 or newer jdk, otherwise the -Dsun.java2d.uiScale=2 command line switch does nothing. I don't use the launcher myself, because I prefer to use the package manager of my OS, which is NixOS.

sweber83 avatar Aug 09 '20 23:08 sweber83

Would be great if we could respect the pixel density. I opened a pull request for Cockatrice and it didn't take much to scale all images at 2x the size on high dpi displays. Is it similarly straightforward with the framework that xmage uses? https://github.com/Cockatrice/Cockatrice/commit/5652b56b459e559862ea00bc1ee2cccb4351986a

That would be a good start.

johtso avatar Dec 03 '21 22:12 johtso

Another possible solution, compatible with java 8:

  • open launcher folder\java\javaxxx\bin folder
  • right click on javaw.exe file and choose properties
  • click on “Compatibility” - “Override high DPI scaling behavior” and choose System;
  • now you can run it by launcher in hidpi upscale mode;

P.S. If not helps then set same settings for java.exe file too.

JayDi85 avatar Mar 24 '24 13:03 JayDi85

Question - I run xmage on different monitors (two different TVs with vastly different scaling and sometimes just the laptop monitor). (I am reluctant to try these solutions in case it makes xmage unplayable on my laptop screen (when I don't have external TV available for a monitor.)

Is there a solution that will enable different scaling on the different monitors? Or perhaps I could create different shortcuts and thus run the one appropriate for the monitor I was using that day?

tiera3 avatar Mar 24 '24 21:03 tiera3

For windows you can make multiple links to javaw.exe or java.exe files and setup each link with different params and compatibility settings:

  • right click on java.exe file and create link/shortcut, give it a name;
  • move link to launcher or any other folder;
  • open property of the link;
  • change working directory to mage/mage-client;
  • change params to params from a launcher settings like (java.exe -jar jarfilename.jar params) — you can look in run scripts from mage/mage-client folder for examples. But don’t store anything inside mage folder - it will be deleted on update. Store all custom files in launcher folder instead;
  • change compatible mode;
  • repeat with another links;
  • it must allow to run multiple clients with diff settings at the same time.

As additional you can load some registry settings by command line, see here for paths and tools (but you can run only one client that way):

  • see details about registry structure: https://github.com/magefree/mage/issues/4461#issuecomment-361108597
  • run client on one desktop and setup fonts, sizes and other gui settings by xmage’s Preferences dialog;
  • run regexit and export gui settings to file;
  • edit that file by text edit, make sure it contains line for GUI only;
  • make cmd file in launcher folder like: run-on-tv.cmd with content:
reg import config-tv.reg
tv.lnk
  • that cmd file will preload tv settings and run tv link/shortcut with predefined scale settings;

JayDi85 avatar Mar 24 '24 22:03 JayDi85

Some usefull info from 664ac24dfd3629c1f929908d6f9d37b3626822fc

Possible use cases with DPI problems:

  • 1 - Normal mode, user setup DPI settings by OS (example: 120%):

    • DPI - bigger, resolution - lower
    • GUI components: safe to use screen coordinates and sizes
    • GUI graphics: must use better images quality to fix pixelated drawing on big DPI values
    • bug: pixelated images and text (possible fix: use smooth rendering hints on final stage with card image)
  • 2 - Java 9+ gui scale mode by -Dsun.java2d.uiScale=2

    • TODO: test with java 9 scale command line params, see here https://github.com/magefree/mage/issues/969#issuecomment-671055642 looks like it works for linux systems only (can't reproduce it with Windows)
  • 3 - Windows compatibility mode with Override high DPI scaling behavior to System, see here https://github.com/magefree/mage/issues/969#issuecomment-2016809163

    • work with increased DPI settings or HiDPI monitors (?)
    • DPI - same (native?), resolution - lower
    • GUI components: safe to use screen coordinates and sizes
    • GUI graphics: safe to use default images - Windows uses smooth scaling for it, so no pixelated drawing
    • bug: smoothed images and text (nothing to fix?)

Current xmage problems with enabled HiDPI settings by OS -- pixelated images for mana icons, cards, texts, etc. It can be "fixed" manually by windows compatibility settings (see option 3 above) or by improved rendering code with smooth hints. The last one must be used as priority (see example code from ce439d7fcf943c07e4b5a6cab5013f6f56ce79b1).

P.S. Modes example. Maybe x2-x4 scale can be potentially good for HiDPI monitors. Need more research. shot_240814_203629

JayDi85 avatar Aug 14 '24 16:08 JayDi85