mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-11 14:45:31 +03:00
On linux query xrdb for Xft.dpi and use that, if set as the logical DPI.
Fall back to the actual physical dpi as returned by GLFW if that fails.
This commit is contained in:
parent
ccf66fc621
commit
83855e16ce
@ -82,7 +82,7 @@ the following dependencies are installed first.
|
||||
* glfw >= 3.2
|
||||
* glew >= 2.0 (not needed on macOS)
|
||||
* fontconfig (not needed on macOS)
|
||||
* xdpyinfo and xsel (only on X11 based systems)
|
||||
* xrdb and xsel (only on X11 based systems)
|
||||
* gcc or clang (required only for building)
|
||||
* pkg-config (required only for building)
|
||||
|
||||
|
@ -50,17 +50,32 @@ def sanitize_title(x):
|
||||
return re.sub(r'\s+', ' ', re.sub(r'[\0-\x19]', '', x))
|
||||
|
||||
|
||||
def x11_dpi():
|
||||
try:
|
||||
raw = subprocess.check_output(['xrdb', '-query']).decode('utf-8')
|
||||
except Exception:
|
||||
return None
|
||||
m = re.search(r'^Xft.dpi:\s+([0-9.]+)', raw, re.IGNORECASE | re.MULTILINE)
|
||||
if m is not None:
|
||||
try:
|
||||
return float(m.group(1))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def get_logical_dpi():
|
||||
if not hasattr(get_logical_dpi, 'ans'):
|
||||
if isosx:
|
||||
# TODO: Investigate if this needs a different implementation on OS X
|
||||
get_logical_dpi.ans = glfw_get_physical_dpi()
|
||||
else:
|
||||
raw = subprocess.check_output(['xdpyinfo']).decode('utf-8')
|
||||
m = re.search(
|
||||
r'^\s*resolution:\s*(\d+)+x(\d+)', raw, flags=re.MULTILINE
|
||||
)
|
||||
get_logical_dpi.ans = int(m.group(1)), int(m.group(2))
|
||||
# See https://github.com/glfw/glfw/issues/1019 for why we cant use
|
||||
# glfw_get_physical_dpi()
|
||||
dpi = x11_dpi()
|
||||
if dpi is None:
|
||||
get_logical_dpi.ans = glfw_get_physical_dpi()
|
||||
else:
|
||||
get_logical_dpi.ans = dpi, dpi
|
||||
return get_logical_dpi.ans
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user