Simply code to query xrdb for Xft.dpi
This commit is contained in:
parent
be6e41c400
commit
1276bd6f5d
@ -124,4 +124,12 @@ def x11_window_id(window):
|
|||||||
return lib.glfwGetX11Window(window.window_id())
|
return lib.glfwGetX11Window(window.window_id())
|
||||||
|
|
||||||
|
|
||||||
|
def x11_display():
|
||||||
|
lib = glfw_lib()
|
||||||
|
ans = lib.glfwGetX11Display
|
||||||
|
ans.restype = ctypes.c_void_p
|
||||||
|
ans.argtypes = []
|
||||||
|
return ans()
|
||||||
|
|
||||||
|
|
||||||
iswayland = not isosx and hasattr(glfw_lib(), 'glfwGetWaylandDisplay')
|
iswayland = not isosx and hasattr(glfw_lib(), 'glfwGetWaylandDisplay')
|
||||||
|
|||||||
@ -12,7 +12,7 @@ from contextlib import contextmanager
|
|||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from time import monotonic
|
from time import monotonic
|
||||||
|
|
||||||
from .constants import isosx, iswayland, selection_clipboard_funcs
|
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, redirect_std_streams,
|
||||||
wcwidth as wcwidth_impl
|
wcwidth as wcwidth_impl
|
||||||
@ -72,7 +72,6 @@ def load_libx11():
|
|||||||
import ctypes
|
import ctypes
|
||||||
from ctypes.util import find_library
|
from ctypes.util import find_library
|
||||||
libx11 = ctypes.CDLL(find_library('X11'))
|
libx11 = ctypes.CDLL(find_library('X11'))
|
||||||
ans = []
|
|
||||||
|
|
||||||
def cdef(name, restype, *argtypes):
|
def cdef(name, restype, *argtypes):
|
||||||
f = getattr(libx11, name)
|
f = getattr(libx11, name)
|
||||||
@ -80,12 +79,9 @@ def load_libx11():
|
|||||||
f.restype = restype
|
f.restype = restype
|
||||||
if argtypes:
|
if argtypes:
|
||||||
f.argtypes = argtypes
|
f.argtypes = argtypes
|
||||||
ans.append(f)
|
return f
|
||||||
|
|
||||||
cdef('XOpenDisplay', ctypes.c_void_p, ctypes.c_char_p)
|
return cdef('XResourceManagerString', ctypes.c_char_p, ctypes.c_void_p)
|
||||||
cdef('XCloseDisplay', ctypes.c_int, ctypes.c_void_p)
|
|
||||||
cdef('XResourceManagerString', ctypes.c_char_p, ctypes.c_void_p)
|
|
||||||
return ans
|
|
||||||
|
|
||||||
|
|
||||||
def parse_xrdb(raw):
|
def parse_xrdb(raw):
|
||||||
@ -95,28 +91,11 @@ def parse_xrdb(raw):
|
|||||||
return float(line[len(q):])
|
return float(line[len(q):])
|
||||||
|
|
||||||
|
|
||||||
def x11_dpi_native():
|
|
||||||
XOpenDisplay, XCloseDisplay, XResourceManagerString = load_libx11()
|
|
||||||
display = XOpenDisplay(None)
|
|
||||||
if display is None:
|
|
||||||
raise RuntimeError('Could not connect to the X server')
|
|
||||||
try:
|
|
||||||
raw = XResourceManagerString(display)
|
|
||||||
return parse_xrdb(raw)
|
|
||||||
finally:
|
|
||||||
XCloseDisplay(display)
|
|
||||||
|
|
||||||
|
|
||||||
def x11_dpi():
|
def x11_dpi():
|
||||||
try:
|
XResourceManagerString = load_libx11()
|
||||||
return x11_dpi_native()
|
display = x11_display()
|
||||||
except Exception:
|
raw = XResourceManagerString(display)
|
||||||
pass
|
return parse_xrdb(raw)
|
||||||
try:
|
|
||||||
raw = subprocess.check_output(['xrdb', '-query'], stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL)
|
|
||||||
return parse_xrdb(raw)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def get_logical_dpi():
|
def get_logical_dpi():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user