From fcedc9f5c3832d07891b80ce9cd3a72c30bdcdd3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 24 Mar 2019 10:04:32 +0530 Subject: [PATCH] Allow setting :opt:`active_border_color` to ``none`` to not draw a border around the active window Fixes #805 Fixes #1491 --- docs/changelog.rst | 3 +++ kitty/borders.py | 3 ++- kitty/boss.py | 4 ++-- kitty/conf/utils.py | 6 ++++++ kitty/config_data.py | 7 ++++--- kitty/layout.py | 13 +++++++++---- kitty/state.c | 5 +++++ 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 2892562cd..2f208ee08 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -98,6 +98,9 @@ To update |kitty|, :doc:`follow the instructions `. - Only update the selected text to clipboard when the selection is finished, not continuously as it is updated. (:iss:`1460`) +- Allow setting :opt:`active_border_color` to ``none`` to not draw a border + around the active window (:iss:`805`) + 0.13.3 [2019-01-19] ------------------------------ diff --git a/kitty/borders.py b/kitty/borders.py index a43e545b4..290faf101 100644 --- a/kitty/borders.py +++ b/kitty/borders.py @@ -52,6 +52,7 @@ class Borders: 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__( self, @@ -77,7 +78,7 @@ class Borders: window_bg = (window_bg << 8) | BorderColor.window_bg if draw_borders: # Draw the border rectangles - if w is active_window: + if w is active_window and self.draw_active_borders: color = BorderColor.active else: color = BorderColor.bell if w.needs_attention else BorderColor.inactive diff --git a/kitty/boss.py b/kitty/boss.py index 855721285..b8a563f15 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -27,7 +27,7 @@ from .fast_data_types import ( set_clipboard_string, set_in_sequence_mode, toggle_fullscreen ) from .keys import get_shortcut, shortcut_matches -from .layout import set_draw_minimal_borders +from .layout import set_draw_borders_options from .remote_control import handle_cmd from .rgb import Color, color_from_int from .session import create_session @@ -104,7 +104,7 @@ class DumpCommands: # {{{ class Boss: def __init__(self, os_window_id, opts, args, cached_values, new_os_window_trigger): - set_draw_minimal_borders(opts) + set_draw_borders_options(opts) self.clipboard_buffers = {} self.update_check_process = None self.window_id_map = WeakValueDictionary() diff --git a/kitty/conf/utils.py b/kitty/conf/utils.py index e7e358d52..e0984c268 100644 --- a/kitty/conf/utils.py +++ b/kitty/conf/utils.py @@ -16,6 +16,12 @@ def to_color(x): return as_color(x, validate=True) +def to_color_or_none(x): + if x.lower() == 'none': + return + return to_color(x) + + def positive_int(x): return max(0, int(x)) diff --git a/kitty/config_data.py b/kitty/config_data.py index ef69e6695..95382c225 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -10,7 +10,7 @@ from . import fast_data_types as defines from .conf.definition import option_func from .conf.utils import ( choices, positive_float, positive_int, to_bool, to_cmdline, to_color, - unit_float + to_color_or_none, unit_float ) from .constants import config_dir, is_macos from .fast_data_types import CURSOR_BEAM, CURSOR_BLOCK, CURSOR_UNDERLINE @@ -567,8 +567,9 @@ 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('active_border_color', '#00ff00', option_type=to_color, long_text=_(''' -The color for the border of the active window''')) +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.''')) o('inactive_border_color', '#cccccc', option_type=to_color, long_text=_(''' The color for the border of inactive windows''')) diff --git a/kitty/layout.py b/kitty/layout.py index cf6c1a169..db2c22618 100644 --- a/kitty/layout.py +++ b/kitty/layout.py @@ -17,6 +17,7 @@ cell_width = cell_height = 20 all_borders = True, True, True, True no_borders = False, False, False, False draw_minimal_borders = False +draw_active_borders = True def idx_for_id(win_id, windows): @@ -25,9 +26,10 @@ def idx_for_id(win_id, windows): return i -def set_draw_minimal_borders(opts): - global draw_minimal_borders +def set_draw_borders_options(opts): + global draw_minimal_borders, draw_active_borders draw_minimal_borders = opts.draw_minimal_borders and opts.window_margin_width == 0 + draw_active_borders = opts.active_border_color is not None def layout_dimension(start_at, length, cell_length, decoration_pairs, left_align=False, bias=None): @@ -392,14 +394,17 @@ class Layout: # {{{ def resolve_borders(self, windows, active_window): if draw_minimal_borders: - needs_borders_map = {w.id: (w is active_window or w.needs_attention) for w in windows} + needs_borders_map = {w.id: ((w is active_window and draw_active_borders) or w.needs_attention) for w in windows} yield from self.minimal_borders(windows, active_window, needs_borders_map) else: yield from Layout.minimal_borders(self, windows, active_window, None) def minimal_borders(self, windows, active_window, needs_borders_map): for w in windows: - yield all_borders + if w is active_window and not draw_active_borders and not w.needs_attention: + yield no_borders + else: + yield all_borders # }}} diff --git a/kitty/state.c b/kitty/state.c index 9ed24d157..7375e0088 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -291,8 +291,11 @@ os_window_regions(OSWindow *os_window, Region *central, Region *tab_bar) { #define KK5I(name) PYWRAP1(name) { id_type a, b; unsigned int c, d, e, f, g; PA("KKIIIII", &a, &b, &c, &d, &e, &f, &g); name(a, b, c, d, e, f, g); Py_RETURN_NONE; } #define BOOL_SET(name) PYWRAP1(set_##name) { global_state.name = PyObject_IsTrue(args); Py_RETURN_NONE; } +static color_type default_color = 0; + static inline color_type color_as_int(PyObject *color) { + if (color == Py_None && default_color) return default_color; if (!PyTuple_Check(color)) { PyErr_SetString(PyExc_TypeError, "Not a color tuple"); return 0; } #define I(n, s) ((PyLong_AsUnsignedLong(PyTuple_GET_ITEM(color, n)) & 0xff) << s) return (I(0, 16) | I(1, 8) | I(2, 0)) & 0xffffff; @@ -387,7 +390,9 @@ PYWRAP1(set_options) { S(url_color, color_as_int); S(background, color_as_int); S(foreground, color_as_int); + default_color = 0x00ff00; S(active_border_color, color_as_int); + default_color = 0; S(inactive_border_color, color_as_int); S(bell_border_color, color_as_int); S(repaint_delay, repaint_delay);