Fix specifying initial window size in cells not working correctly on HiDPI screens
Fixes #1444
This commit is contained in:
parent
0a153e2524
commit
2550bc910d
@ -81,6 +81,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
||||
|
||||
- Update to using the Unicode 12 standard
|
||||
|
||||
- Fix specifying initial window size in cells not working correctly on HiDPI
|
||||
screens (:iss:`1444`)
|
||||
|
||||
|
||||
0.13.3 [2019-01-19]
|
||||
------------------------------
|
||||
|
||||
@ -104,7 +104,7 @@ def setup_x11_window(win_id):
|
||||
def initial_window_size_func(opts, *a):
|
||||
from kitty.fast_data_types import glfw_primary_monitor_size, set_smallest_allowed_resize
|
||||
|
||||
def initial_window_size(cell_width, cell_height, dpi_x, dpi_y):
|
||||
def initial_window_size(cell_width, cell_height, dpi_x, dpi_y, xscale, yscale):
|
||||
monitor_width, monitor_height = glfw_primary_monitor_size()
|
||||
if args.edge in {'top', 'bottom'}:
|
||||
h = initial_window_size_func.height = cell_height * args.lines + 1
|
||||
|
||||
@ -528,13 +528,13 @@ def initial_window_size_func(opts, cached_values):
|
||||
w, w_unit = opts.initial_window_width
|
||||
h, h_unit = opts.initial_window_height
|
||||
|
||||
def get_window_size(cell_width, cell_height, dpi_x, dpi_y):
|
||||
def get_window_size(cell_width, cell_height, dpi_x, dpi_y, xscale, yscale):
|
||||
if w_unit == 'cells':
|
||||
width = cell_width * w + (dpi_x / 72) * (opts.window_margin_width + opts.window_padding_width) + 1
|
||||
width = cell_width * w / xscale + (dpi_x / 72) * (opts.window_margin_width + opts.window_padding_width) + 1
|
||||
else:
|
||||
width = w
|
||||
if h_unit == 'cells':
|
||||
height = cell_height * h + (dpi_y / 72) * (opts.window_margin_width + opts.window_padding_width) + 1
|
||||
height = cell_height * h / yscale + (dpi_y / 72) * (opts.window_margin_width + opts.window_padding_width) + 1
|
||||
else:
|
||||
height = h
|
||||
return width, height
|
||||
|
||||
37
kitty/glfw.c
37
kitty/glfw.c
@ -372,23 +372,28 @@ current_monitor(GLFWwindow *window) {
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
get_window_dpi(GLFWwindow *w, double *x, double *y) {
|
||||
float xscale = 1, yscale = 1;
|
||||
if (w) glfwGetWindowContentScale(w, &xscale, &yscale);
|
||||
get_window_content_scale(GLFWwindow *w, float *xscale, float *yscale, double *xdpi, double *ydpi) {
|
||||
if (w) glfwGetWindowContentScale(w, xscale, yscale);
|
||||
else {
|
||||
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
|
||||
if (monitor) glfwGetMonitorContentScale(monitor, &xscale, &yscale);
|
||||
if (monitor) glfwGetMonitorContentScale(monitor, xscale, yscale);
|
||||
}
|
||||
// check for zero or NaN values of xscale/yscale
|
||||
if (!xscale || xscale != xscale) xscale = 1.0;
|
||||
if (!yscale || yscale != yscale) yscale = 1.0;
|
||||
if (!*xscale || *xscale != *xscale) *xscale = 1.0;
|
||||
if (!*yscale || *yscale != *yscale) *yscale = 1.0;
|
||||
#ifdef __APPLE__
|
||||
double factor = 72.0;
|
||||
const double factor = 72.0;
|
||||
#else
|
||||
double factor = 96.0;
|
||||
const double factor = 96.0;
|
||||
#endif
|
||||
*x = xscale * factor;
|
||||
*y = yscale * factor;
|
||||
*xdpi = *xscale * factor;
|
||||
*ydpi = *yscale * factor;
|
||||
}
|
||||
|
||||
static inline void
|
||||
get_window_dpi(GLFWwindow *w, double *x, double *y) {
|
||||
float xscale = 1, yscale = 1;
|
||||
get_window_content_scale(w, &xscale, &yscale, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -540,11 +545,11 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
|
||||
|
||||
GLFWwindow *temp_window = glfwCreateWindow(640, 480, "temp", NULL, common_context);
|
||||
if (temp_window == NULL) { fatal("Failed to create GLFW temp window! This usually happens because of old/broken OpenGL drivers. kitty requires working OpenGL 3.3 drivers."); }
|
||||
|
||||
double dpi_x, dpi_y;
|
||||
get_window_dpi(temp_window, &dpi_x, &dpi_y);
|
||||
FONTS_DATA_HANDLE fonts_data = load_fonts_data(global_state.font_sz_in_pts, dpi_x, dpi_y);
|
||||
PyObject *ret = PyObject_CallFunction(get_window_size, "IIdd", fonts_data->cell_width, fonts_data->cell_height, fonts_data->logical_dpi_x, fonts_data->logical_dpi_y);
|
||||
float xscale, yscale;
|
||||
double xdpi, ydpi;
|
||||
get_window_content_scale(temp_window, &xscale, &yscale, &xdpi, &ydpi);
|
||||
FONTS_DATA_HANDLE fonts_data = load_fonts_data(global_state.font_sz_in_pts, xdpi, ydpi);
|
||||
PyObject *ret = PyObject_CallFunction(get_window_size, "IIddff", fonts_data->cell_width, fonts_data->cell_height, fonts_data->logical_dpi_x, fonts_data->logical_dpi_y, xscale, yscale);
|
||||
if (ret == NULL) return NULL;
|
||||
int width = PyLong_AsLong(PyTuple_GET_ITEM(ret, 0)), height = PyLong_AsLong(PyTuple_GET_ITEM(ret, 1));
|
||||
Py_CLEAR(ret);
|
||||
@ -609,7 +614,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
|
||||
OSWindow *q = global_state.os_windows + i;
|
||||
q->is_focused = q == w ? true : false;
|
||||
}
|
||||
w->logical_dpi_x = dpi_x; w->logical_dpi_y = dpi_y;
|
||||
w->logical_dpi_x = xdpi; w->logical_dpi_y = ydpi;
|
||||
w->fonts_data = fonts_data;
|
||||
w->shown_once = true;
|
||||
w->last_focused_counter = ++focus_counter;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user