Add an option single_window_margin_width to allow different margins when only a single window is visible in the layout
Fixes #688
This commit is contained in:
parent
65fef81f29
commit
e35c3cc913
@ -19,6 +19,9 @@ Changelog
|
||||
|
||||
- Fix pasting large amounts of text very slow (:iss:`682`)
|
||||
|
||||
- Add an option :opt:`single_window_margin_width` to allow different margins
|
||||
when only a single window is visible in the layout (:iss:`688`)
|
||||
|
||||
- Add a :option:`kitty --hold` command line option to stay open after the child process exits (:iss:`667`)
|
||||
|
||||
- diff kitten: When triggering a search scroll to the first match automatically
|
||||
|
||||
@ -452,6 +452,10 @@ Note that borders are displayed only when more than one window is visible. They
|
||||
o('window_margin_width', 0.0, option_type=positive_float, long_text=_('''
|
||||
The window margin (in pts) (blank area outside the border)'''))
|
||||
|
||||
o('single_window_margin_width', -1000.0, option_type=float, long_text=_('''
|
||||
The window margin (in pts) to use when only a single window is visible.
|
||||
Negative values will cause the value of :opt:`window_margin_width` to be used instead.'''))
|
||||
|
||||
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)'''))
|
||||
|
||||
|
||||
@ -158,13 +158,14 @@ class Layout: # {{{
|
||||
needs_window_borders = True
|
||||
only_active_window_visible = False
|
||||
|
||||
def __init__(self, os_window_id, tab_id, margin_width, padding_width, border_width, layout_opts=''):
|
||||
def __init__(self, os_window_id, tab_id, margin_width, single_window_margin_width, padding_width, border_width, layout_opts=''):
|
||||
self.os_window_id = os_window_id
|
||||
self.tab_id = tab_id
|
||||
self.set_active_window_in_os_window = partial(set_active_window, os_window_id, tab_id)
|
||||
self.swap_windows_in_os_window = partial(swap_windows, os_window_id, tab_id)
|
||||
self.border_width = border_width
|
||||
self.margin_width = margin_width
|
||||
self.single_window_margin_width = single_window_margin_width
|
||||
self.padding_width = padding_width
|
||||
# A set of rectangles corresponding to the blank spaces at the edges of
|
||||
# this layout, i.e. spaces that are not covered by any window
|
||||
@ -336,7 +337,8 @@ class Layout: # {{{
|
||||
|
||||
# Utils {{{
|
||||
def layout_single_window(self, w):
|
||||
wg = layout_single_window(self.margin_width, self.padding_width)
|
||||
mw = self.margin_width if self.single_window_margin_width < 0 else self.single_window_margin_width
|
||||
wg = layout_single_window(mw, self.padding_width)
|
||||
w.set_geometry(0, wg)
|
||||
self.blank_rects = blank_rects_for_window(w)
|
||||
|
||||
@ -373,7 +375,8 @@ class Stack(Layout): # {{{
|
||||
only_active_window_visible = True
|
||||
|
||||
def do_layout(self, windows, active_window_idx):
|
||||
wg = layout_single_window(self.margin_width, self.padding_width)
|
||||
mw = self.margin_width if self.single_window_margin_width < 0 else self.single_window_margin_width
|
||||
wg = layout_single_window(mw, self.padding_width)
|
||||
for i, w in enumerate(windows):
|
||||
w.set_geometry(i, wg)
|
||||
if w.is_visible_in_layout:
|
||||
@ -671,12 +674,13 @@ class Horizontal(Vertical):
|
||||
all_layouts = {o.name: o for o in globals().values() if isinstance(o, type) and issubclass(o, Layout) and o is not Layout}
|
||||
|
||||
|
||||
def create_layout_object_for(name, os_window_id, tab_id, margin_width, padding_width, border_width, layout_opts=''):
|
||||
key = name, os_window_id, tab_id, margin_width, padding_width, border_width, layout_opts
|
||||
def create_layout_object_for(name, os_window_id, tab_id, margin_width, single_window_margin_width, padding_width, border_width, layout_opts=''):
|
||||
key = name, os_window_id, tab_id, margin_width, single_window_margin_width, padding_width, border_width, layout_opts
|
||||
ans = create_layout_object_for.cache.get(key)
|
||||
if ans is None:
|
||||
name, layout_opts = name.partition(':')[::2]
|
||||
ans = create_layout_object_for.cache[key] = all_layouts[name](os_window_id, tab_id, margin_width, padding_width, border_width, layout_opts)
|
||||
ans = create_layout_object_for.cache[key] = all_layouts[name](
|
||||
os_window_id, tab_id, margin_width, single_window_margin_width, padding_width, border_width, layout_opts)
|
||||
return ans
|
||||
|
||||
|
||||
|
||||
@ -37,8 +37,9 @@ 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 = pt_to_px(
|
||||
self.opts.window_margin_width, self.os_window_id), pt_to_px(self.opts.window_padding_width, self.os_window_id)
|
||||
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.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)
|
||||
@ -139,7 +140,10 @@ class Tab: # {{{
|
||||
w.change_titlebar_color()
|
||||
|
||||
def create_layout_object(self, name):
|
||||
return create_layout_object_for(name, self.os_window_id, self.id, self.margin_width, self.padding_width, self.borders.border_width)
|
||||
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)
|
||||
|
||||
def next_layout(self):
|
||||
if len(self.enabled_layouts) > 1:
|
||||
|
||||
@ -27,7 +27,7 @@ def create_layout(cls, opts=None, border_width=2):
|
||||
if opts is None:
|
||||
opts = defaults
|
||||
mw, pw = map(pt_to_px, (opts.window_margin_width, opts.window_padding_width))
|
||||
ans = cls(1, 1, mw, pw, border_width)
|
||||
ans = cls(1, 1, mw, mw, pw, border_width)
|
||||
ans.set_active_window_in_os_window = lambda idx: None
|
||||
ans.swap_windows_in_os_window = lambda a, b: None
|
||||
return ans
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user