Have pt_to_px use global_state instead of get_dpi

DRYer and reduces code size
This commit is contained in:
Kovid Goyal 2017-12-14 18:02:06 +05:30
parent ce7be5a05e
commit c7e1a12eb6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 13 additions and 20 deletions

View File

@ -6,9 +6,10 @@ from functools import partial
from itertools import chain
from .fast_data_types import (
BORDERS_PROGRAM, add_borders_rect, compile_program, init_borders_program
BORDERS_PROGRAM, add_borders_rect, compile_program, init_borders_program,
pt_to_px
)
from .utils import color_as_int, load_shaders, pt_to_px
from .utils import color_as_int, load_shaders
def vertical_edge(os_window_id, tab_id, color, width, top, bottom, left):

View File

@ -6,9 +6,7 @@ from collections import namedtuple
from itertools import islice
from .constants import WindowGeometry
from .utils import pt_to_px
from .fast_data_types import viewport_for_window
from .fast_data_types import pt_to_px, viewport_for_window
viewport_width = viewport_height = available_height = 400
cell_width = cell_height = 20

View File

@ -421,6 +421,13 @@ PYWRAP1(set_logical_dpi) {
Py_RETURN_NONE;
}
PYWRAP1(pt_to_px) {
long pt = PyLong_AsLong(args);
double dpi = (global_state.logical_dpi_x + global_state.logical_dpi_y) / 2.f;
return PyLong_FromLong((long)(pt * (dpi / 72.0)));
}
PYWRAP1(set_boss) {
Py_CLEAR(global_state.boss);
global_state.boss = args;
@ -460,6 +467,7 @@ static PyMethodDef module_methods[] = {
MW(set_options, METH_VARARGS),
MW(handle_for_window_id, METH_VARARGS),
MW(set_logical_dpi, METH_VARARGS),
MW(pt_to_px, METH_O),
MW(add_tab, METH_O),
MW(add_window, METH_VARARGS),
MW(update_window_title, METH_VARARGS),

View File

@ -19,7 +19,7 @@ from time import monotonic
from .constants import appname, is_macos, is_wayland
from .fast_data_types import (
GLSL_VERSION, glfw_get_physical_dpi, glfw_primary_monitor_content_scale,
GLSL_VERSION, glfw_primary_monitor_content_scale,
redirect_std_streams, wcwidth as wcwidth_impl, x11_display, x11_window_id
)
from .rgb import Color, to_color
@ -52,13 +52,6 @@ def wcwidth(c: str) -> int:
return wcwidth_impl(ord(c[0]))
@lru_cache()
def pt_to_px(pts):
dpix, dpiy = get_dpi()['logical']
dpi = (dpix + dpiy) / 2
return round(pts * dpi / 72)
@contextmanager
def timeit(name, do_timing=False):
if do_timing:
@ -85,13 +78,6 @@ def get_logical_dpi(override_dpi=None):
return get_logical_dpi.ans
def get_dpi():
if not hasattr(get_dpi, 'ans'):
pdpi = glfw_get_physical_dpi()
get_dpi.ans = {'physical': pdpi, 'logical': get_logical_dpi()}
return get_dpi.ans
def color_as_int(val):
return val[0] << 16 | val[1] << 8 | val[2]