Use the glfw 3.3 content scale API to get DPI on X11/wayland
This commit is contained in:
parent
39bc0cd8c5
commit
b4d824e165
@ -14,8 +14,8 @@ from time import monotonic
|
|||||||
|
|
||||||
from .constants import isosx, iswayland, selection_clipboard_funcs, x11_display
|
from .constants import isosx, iswayland, selection_clipboard_funcs, x11_display
|
||||||
from .fast_data_types import (
|
from .fast_data_types import (
|
||||||
GLSL_VERSION, glfw_get_physical_dpi, redirect_std_streams,
|
GLSL_VERSION, glfw_get_physical_dpi, glfw_primary_monitor_content_scale,
|
||||||
wcwidth as wcwidth_impl
|
redirect_std_streams, wcwidth as wcwidth_impl
|
||||||
)
|
)
|
||||||
from .rgb import Color, to_color
|
from .rgb import Color, to_color
|
||||||
|
|
||||||
@ -92,6 +92,8 @@ def parse_xrdb(raw):
|
|||||||
|
|
||||||
|
|
||||||
def x11_dpi():
|
def x11_dpi():
|
||||||
|
if iswayland:
|
||||||
|
return
|
||||||
XResourceManagerString = load_libx11()
|
XResourceManagerString = load_libx11()
|
||||||
display = x11_display()
|
display = x11_display()
|
||||||
if display:
|
if display:
|
||||||
@ -103,18 +105,22 @@ def x11_dpi():
|
|||||||
|
|
||||||
|
|
||||||
def get_logical_dpi():
|
def get_logical_dpi():
|
||||||
|
# See https://github.com/glfw/glfw/issues/1019 for why we cant use
|
||||||
|
# glfw_get_physical_dpi()
|
||||||
if not hasattr(get_logical_dpi, 'ans'):
|
if not hasattr(get_logical_dpi, 'ans'):
|
||||||
if isosx or iswayland:
|
if isosx:
|
||||||
# TODO: Investigate if this needs a different implementation on OS X or Wayland
|
# TODO: Investigate if this needs a different implementation on OS X
|
||||||
get_logical_dpi.ans = glfw_get_physical_dpi()
|
get_logical_dpi.ans = glfw_get_physical_dpi()
|
||||||
else:
|
else:
|
||||||
# See https://github.com/glfw/glfw/issues/1019 for why we cant use
|
try:
|
||||||
# glfw_get_physical_dpi()
|
xscale, yscale = glfw_primary_monitor_content_scale()
|
||||||
dpi = x11_dpi()
|
except NotImplementedError: # glfw < 3.3
|
||||||
if dpi is None:
|
xdpi = ydpi = x11_dpi()
|
||||||
get_logical_dpi.ans = glfw_get_physical_dpi()
|
if xdpi is None:
|
||||||
|
xdpi, ydpi = glfw_get_physical_dpi()
|
||||||
else:
|
else:
|
||||||
get_logical_dpi.ans = dpi, dpi
|
xdpi, ydpi = xscale * 96.0, yscale * 96.0
|
||||||
|
get_logical_dpi.ans = xdpi, ydpi
|
||||||
return get_logical_dpi.ans
|
return get_logical_dpi.ans
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user