diff --git a/docs/changelog.rst b/docs/changelog.rst index 65b5b1244..c65e4286f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,6 +7,10 @@ To update |kitty|, :doc:`follow the instructions `. 0.14.2 [future] --------------------- +- Add an option :opt:`placement_strategy` to control how the cell area is + aligned inside the window when the window size is not an exact multiple + of the cell size (:pull:`1670`) + - hints kitten: Add a :option:`kitty +kitten hints --multiple-joiner` option to control how multiple selections are serialized when copying to clipboard or inserting into the terminal. You can have them on separate lines, diff --git a/kitty/boss.py b/kitty/boss.py index 552895367..d4ff7cdae 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -28,7 +28,7 @@ from .fast_data_types import ( toggle_maximized ) from .keys import get_shortcut, shortcut_matches -from .layout import set_draw_borders_options +from .layout import set_layout_options from .remote_control import handle_cmd from .rgb import Color, color_from_int from .session import create_sessions @@ -105,7 +105,7 @@ class DumpCommands: # {{{ class Boss: def __init__(self, os_window_id, opts, args, cached_values, new_os_window_trigger): - set_draw_borders_options(opts) + set_layout_options(opts) self.clipboard_buffers = {} self.update_check_process = None self.window_id_map = WeakValueDictionary() diff --git a/kitty/config_data.py b/kitty/config_data.py index 38c3f80b4..4f1444a4f 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -586,6 +586,14 @@ Negative values will cause the value of :opt:`window_margin_width` to be used in o('window_padding_width', 0.0, option_type=positive_float, long_text=_(''' The window padding (in pts) (blank area between the text and the window border)''')) +o('placement_strategy', 'center', option_type=choices('center', 'top-left'), long_text=_(''' +When the window size is not an exact multiple of the cell size, the cell area of the terminal +window will have some extra padding on the sides. You can control how that padding is +distributed with this option. Using a value of :code:`center` means the cell area will +be placed centrally. A value of :code:`top-left` means the padding will be on only +the bottom and right edges. +''')) + o('active_border_color', '#00ff00', option_type=to_color_or_none, long_text=_(''' The color for the border of the active window. Set this to none to not draw borders around the active window.''')) diff --git a/kitty/layout.py b/kitty/layout.py index 333dc27e5..5ce756288 100644 --- a/kitty/layout.py +++ b/kitty/layout.py @@ -18,6 +18,7 @@ all_borders = True, True, True, True no_borders = False, False, False, False draw_minimal_borders = False draw_active_borders = True +align_top_left = False def idx_for_id(win_id, windows): @@ -26,10 +27,11 @@ def idx_for_id(win_id, windows): return i -def set_draw_borders_options(opts): - global draw_minimal_borders, draw_active_borders +def set_layout_options(opts): + global draw_minimal_borders, draw_active_borders, align_top_left draw_minimal_borders = opts.draw_minimal_borders and opts.window_margin_width == 0 draw_active_borders = opts.active_border_color is not None + align_top_left = opts.placement_strategy == 'top-left' def layout_dimension(start_at, length, cell_length, decoration_pairs, left_align=False, bias=None): @@ -86,9 +88,9 @@ def window_geometry(xstart, xnum, ystart, ynum): return WindowGeometry(left=xstart, top=ystart, xnum=xnum, ynum=ynum, right=xstart + cell_width * xnum, bottom=ystart + cell_height * ynum) -def layout_single_window(xdecoration_pairs, ydecoration_pairs): - xstart, xnum = next(layout_dimension(central.left, central.width, cell_width, xdecoration_pairs)) - ystart, ynum = next(layout_dimension(central.top, central.height, cell_height, ydecoration_pairs)) +def layout_single_window(xdecoration_pairs, ydecoration_pairs, left_align=False): + xstart, xnum = next(layout_dimension(central.left, central.width, cell_width, xdecoration_pairs, left_align=align_top_left)) + ystart, ynum = next(layout_dimension(central.top, central.height, cell_height, ydecoration_pairs, left_align=align_top_left)) return window_geometry(xstart, xnum, ystart, ynum) @@ -368,12 +370,12 @@ class Layout: # {{{ def xlayout(self, num, bias=None): decoration = self.margin_width + self.border_width + self.padding_width decoration_pairs = tuple(repeat((decoration, decoration), num)) - return layout_dimension(central.left, central.width, cell_width, decoration_pairs, bias=bias) + return layout_dimension(central.left, central.width, cell_width, decoration_pairs, bias=bias, left_align=align_top_left) def ylayout(self, num, left_align=True, bias=None): decoration = self.margin_width + self.border_width + self.padding_width decoration_pairs = tuple(repeat((decoration, decoration), num)) - return layout_dimension(central.top, central.height, cell_height, decoration_pairs, bias=bias) + return layout_dimension(central.top, central.height, cell_height, decoration_pairs, bias=bias, left_align=align_top_left) def simple_blank_rects(self, first_window, last_window): br = self.blank_rects @@ -417,7 +419,7 @@ class Stack(Layout): # {{{ def do_layout(self, windows, active_window_idx): mw = self.margin_width if self.single_window_margin_width < 0 else self.single_window_margin_width decoration_pairs = ((mw + self.padding_width, mw + self.padding_width),) - wg = layout_single_window(decoration_pairs, decoration_pairs) + wg = layout_single_window(decoration_pairs, decoration_pairs, left_align=align_top_left) for i, w in enumerate(windows): w.set_geometry(i, wg) if w.is_visible_in_layout: