From c1abb7038d4dcedd543e694185d3aad84c93bf0f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 Feb 2020 08:31:09 +0530 Subject: [PATCH] Fix border/margin/padding sizes not being recalculated on DPI change Fixes #2346 Fixes #2347 --- docs/changelog.rst | 3 +++ kitty/borders.py | 8 ++++---- kitty/boss.py | 1 + kitty/layout.py | 6 ++++++ kitty/tabs.py | 29 ++++++++++++++++++++++------- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index d7bd06d82..8b472deb6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -28,6 +28,9 @@ To update |kitty|, :doc:`follow the instructions `. - Fix a bug that prevented using custom functions with the new marks feature (:iss:`2344`) +- Fix border/margin/padding sizes not being recalculated on DPI change + (:iss:`2346`) + 0.16.0 [2020-01-28] -------------------- diff --git a/kitty/borders.py b/kitty/borders.py index 225a7b75b..59daecfeb 100644 --- a/kitty/borders.py +++ b/kitty/borders.py @@ -48,11 +48,9 @@ def load_borders_program(): class Borders: - def __init__(self, os_window_id, tab_id, opts, border_width, padding_width): + def __init__(self, os_window_id, tab_id, opts): self.os_window_id = os_window_id self.tab_id = tab_id - self.border_width = border_width - self.padding_width = padding_width self.draw_active_borders = opts.active_border_color is not None def __call__( @@ -61,6 +59,8 @@ class Borders: active_window, current_layout, extra_blank_rects, + padding_width, + border_width, draw_window_borders=True, ): add_borders_rect(self.os_window_id, self.tab_id, 0, 0, 0, 0, BorderColor.default_bg) @@ -68,7 +68,7 @@ class Borders: if not has_background_image: for br in chain(current_layout.blank_rects, extra_blank_rects): add_borders_rect(self.os_window_id, self.tab_id, *br, BorderColor.default_bg) - bw, pw = self.border_width, self.padding_width + bw, pw = border_width, padding_width if bw + pw <= 0: return draw_borders = bw > 0 and draw_window_borders diff --git a/kitty/boss.py b/kitty/boss.py index 6ead05297..25cfac0ee 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -484,6 +484,7 @@ class Boss: sz = os_window_font_size(os_window_id) if sz: os_window_font_size(os_window_id, sz, True) + tm.update_dpi_based_sizes() tm.resize() def _set_os_window_background_opacity(self, os_window_id, opacity): diff --git a/kitty/layout.py b/kitty/layout.py index 4f7521edd..3d26a4187 100644 --- a/kitty/layout.py +++ b/kitty/layout.py @@ -180,6 +180,12 @@ class Layout: # {{{ self.full_name = self.name + ((':' + layout_opts) if layout_opts else '') self.remove_all_biases() + def update_sizes(self, margin_width, single_window_margin_width, padding_width, border_width): + self.border_width = border_width + self.margin_width = margin_width + self.single_window_margin_width = single_window_margin_width + self.padding_width = padding_width + def bias_increment_for_cell(self, is_horizontal): self._set_dimensions() if is_horizontal: diff --git a/kitty/tabs.py b/kitty/tabs.py index 0d496390a..9232c65b9 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -46,12 +46,10 @@ class Tab: # {{{ if not self.id: raise Exception('No OS window with id {} found, or tab counter has wrapped'.format(self.os_window_id)) self.opts, self.args = tab_manager.opts, tab_manager.args - self.margin_width, self.padding_width, self.single_window_margin_width = map( - lambda x: pt_to_px(getattr(self.opts, x), self.os_window_id), ( - 'window_margin_width', 'window_padding_width', 'single_window_margin_width')) + self.recalculate_sizes(update_layout=False) self.name = getattr(session_tab, 'name', '') self.enabled_layouts = [x.lower() for x in getattr(session_tab, 'enabled_layouts', None) or self.opts.enabled_layouts] - self.borders = Borders(self.os_window_id, self.id, self.opts, pt_to_px(self.opts.window_border_width, self.os_window_id), self.padding_width) + self.borders = Borders(self.os_window_id, self.id, self.opts) self.windows = deque() for i, which in enumerate('first second third fourth fifth sixth seventh eighth ninth tenth'.split()): setattr(self, which + '_window', partial(self.nth_window, num=i)) @@ -73,6 +71,15 @@ class Tab: # {{{ self._set_current_layout(l0) self.startup(session_tab) + def recalculate_sizes(self, update_layout=True): + self.margin_width, self.padding_width, self.single_window_margin_width = map( + lambda x: pt_to_px(getattr(self.opts, x), self.os_window_id), ( + 'window_margin_width', 'window_padding_width', 'single_window_margin_width')) + self.border_width = pt_to_px(self.opts.window_border_width, self.os_window_id) + if update_layout and self.current_layout: + self.current_layout.update_sizes( + self.margin_width, self.single_window_margin_width, self.padding_width, self.border_width) + def take_over_from(self, other_tab): self.name, self.cwd = other_tab.name, other_tab.cwd self.enabled_layouts = list(other_tab.enabled_layouts) @@ -176,8 +183,12 @@ class Tab: # {{{ if tm is not None: visible_windows = [w for w in self.windows if w.is_visible_in_layout] w = self.active_window - self.borders(visible_windows, w, self.current_layout, - tm.blank_rects, self.current_layout.needs_window_borders and len(visible_windows) > 1) + self.borders( + windows=visible_windows, active_window=w, + current_layout=self.current_layout, extra_blank_rects=tm.blank_rects, + padding_width=self.padding_width, border_width=self.border_width, + draw_window_borders=self.current_layout.needs_window_borders and len(visible_windows) > 1 + ) if w is not None: w.change_titlebar_color() @@ -185,7 +196,7 @@ class Tab: # {{{ return create_layout_object_for( name, self.os_window_id, self.id, self.margin_width, self.single_window_margin_width, self.padding_width, - self.borders.border_width) + self.border_width) def next_layout(self): if len(self.enabled_layouts) > 1: @@ -542,6 +553,10 @@ class TabManager: # {{{ def update_tab_bar_data(self): self.tab_bar.update(self.tab_bar_data) + def update_dpi_based_sizes(self): + for tab in self.tabs: + tab.recalculate_sizes() + def resize(self, only_tabs=False): if not only_tabs: if not self.tab_bar_hidden: