Skip to content

Commit

Permalink
Test GLMakie getting scale factor from GLFW in HiDPI context (on X11)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmert committed Jan 18, 2023
1 parent 562e187 commit ef1c698
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/glmakie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev
- run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev xsettingsd x11-xserver-utils
- name: Install Julia dependencies
shell: julia --project=monorepo {0}
run: |
Expand Down
50 changes: 48 additions & 2 deletions GLMakie/test/unit_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,59 @@ end
@test screen.px_per_unit[] == 1
save(file, fig)
img = load(file)
@test size(img) == (400, 400)
@test size(img) == (W, H)

# save with a different resolution
save(file, fig, px_per_unit = 2)
img = load(file)
@test size(img) == (800, 800)
@test size(img) == (2W, 2H)
# writing to file should not effect the visible figure
@test_broken screen.px_per_unit[] == 1
end

if Sys.islinux()
# Test that GLMakie is correctly getting the default scale factor from X11 in a
# HiDPI environment.

checkcmd = `which xrdb` & `which xsettingsd`
checkcmd = pipeline(ignorestatus(checkcmd), stdout = devnull, stderr = devnull)
hasxrdb = success(run(checkcmd))

# Only continue if running within an Xvfb environment where the setting is
# empty by default. Overriding during a user's session could be problematic
# (i.e. if running interactively rather than in CI).
inxvfb = hasxrdb ? isempty(readchomp(`xrdb -get Xft.dpi`)) : false

if hasxrdb && inxvfb
# GLFW looks for Xft.dpi resource setting. Spawn a temporary xsettingsd daemon
# to be the X resource manager
xsettingsd = run(pipeline(`xsettingsd -c /dev/null`), wait = false)
try
# Then set the DPI to 192, i.e. 2 times the default of 96dpi
run(pipeline(`echo "Xft.dpi: 192"`, `xrdb -merge`))

# Print out the automatically-determined scale factor from the GLScreen
jlscript = raw"""
using GLMakie
fig, ax, pl = scatter(1:2, 3:4)
screen = display(GLMakie.Screen(visible = false), fig)
print(Int(screen.scalefactor[]))
"""
cmd = ```
$(Base.julia_cmd())
--project=$(Base.active_project())
--eval $jlscript
```
scalefactor = readchomp(cmd)
@test scalefactor == "2"
finally
# cleanup: kill the daemon before continuing with more tests
kill(xsettingsd)
end
else
@test_broken hasxrdb && inxvfb
end
else
@test_broken Sys.islinux()
end
end

0 comments on commit ef1c698

Please sign in to comment.