Skip to content

Commit

Permalink
panel kitten: Fix rendering with non-zero margin.padding in kitty.conf
Browse files Browse the repository at this point in the history
Fixes #6923
  • Loading branch information
kovidgoyal committed Dec 17, 2023
1 parent 2a5ba51 commit 017947d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Detailed list of changes

- Font fallback: Fix the font used to render a character sometimes dependent on the order in which characters appear on screen (:iss:`6865`)

- panel kitten: Fix rendering with non-zero margin.padding in kitty.conf (:iss:`6923`)


0.31.0 [2023-11-08]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
27 changes: 24 additions & 3 deletions kittens/panel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from kitty.cli import parse_args
from kitty.cli_stub import PanelCLIOptions
from kitty.constants import appname, is_macos
from kitty.constants import appname, is_macos, is_wayland
from kitty.fast_data_types import make_x11_window_a_dock_window
from kitty.os_window_size import WindowSizeData

Expand Down Expand Up @@ -103,15 +103,36 @@ def setup_x11_window(win_id: int) -> None:

def initial_window_size_func(opts: WindowSizeData, cached_values: Dict[str, Any]) -> Callable[[int, int, float, float, float, float], Tuple[int, int]]:
from kitty.fast_data_types import glfw_primary_monitor_size
from kitty.typing import EdgeLiteral

def effective_margin(which: EdgeLiteral) -> float:
ans: float = getattr(opts.single_window_margin_width, which)
if ans < 0:
ans = getattr(opts.window_margin_width, which)
return ans

def effective_padding(which: EdgeLiteral) -> float:
ans: float = getattr(opts.single_window_padding_width, which)
if ans < 0:
ans = getattr(opts.window_padding_width, which)
return ans

def initial_window_size(cell_width: int, cell_height: int, dpi_x: float, dpi_y: float, xscale: float, yscale: float) -> Tuple[int, int]:
if not is_macos and not is_wayland():
# Not sure what the deal with scaling on X11 is
xscale = yscale = 1
global window_width, window_height
monitor_width, monitor_height = glfw_primary_monitor_size()

if args.edge in {'top', 'bottom'}:
window_height = cell_height * args.lines + 1
spacing = effective_margin('top') + effective_margin('bottom')
spacing += effective_padding('top') + effective_padding('bottom')
window_height = int(cell_height * args.lines / yscale + (dpi_y / 72) * spacing + 1)
window_width = monitor_width
else:
window_width = cell_width * args.columns + 1
spacing = effective_margin('left') + effective_margin('right')
spacing += effective_padding('left') + effective_padding('right')
window_width = int(cell_width * args.columns / xscale + (dpi_x / 72) * spacing + 1)
window_height = monitor_height
return window_width, window_height

Expand Down

0 comments on commit 017947d

Please sign in to comment.