Merge branch 'feat-visual-bell-color' of https://github.com/page-down/kitty

This commit is contained in:
Kovid Goyal 2021-11-03 09:13:27 +05:30
commit 76834c0975
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
11 changed files with 38 additions and 13 deletions

View File

@ -125,6 +125,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- A new option :opt:`tab_bar_margin_color` to control the color of the tab bar
margins
- A new option :opt:`visual_bell_color` to customize the color of the visual bell
(:pull:`4181`)
- Add support for OSC 777 based desktop notifications
- Wayland: Fix pasting from applications that use a MIME type of "text/plain"

View File

@ -317,6 +317,7 @@ def patch_conf(raw: str, theme_name: str) -> str:
'tab_bar_background',
'tab_bar_margin_color',
'url_color',
'visual_bell_color',
'wayland_titlebar_color',
# ALL_COLORS_END
) # }}}

View File

@ -170,7 +170,7 @@ patch_color_profiles(PyObject *module UNUSED, PyObject *args) {
}
S(foreground, default_fg); S(background, default_bg); S(cursor, cursor_color);
S(selection_foreground, highlight_fg); S(selection_background, highlight_bg);
S(cursor_text_color, cursor_text_color);
S(cursor_text_color, cursor_text_color); S(visual_bell_color, visual_bell_color);
#undef SI
#undef S
Py_RETURN_NONE;
@ -195,11 +195,11 @@ colorprofile_to_color(ColorProfile *self, DynamicColor entry, DynamicColor defva
}
color_type
colorprofile_to_color_with_fallback(ColorProfile *self, DynamicColor entry, DynamicColor defval, DynamicColor fallback, DynamicColor falback_defval) {
colorprofile_to_color_with_fallback(ColorProfile *self, DynamicColor entry, DynamicColor defval, DynamicColor fallback, DynamicColor fallback_defval) {
switch(entry.type) {
case COLOR_NOT_SET:
case COLOR_IS_SPECIAL:
if (defval.type == COLOR_IS_SPECIAL) return colorprofile_to_color(self, fallback, falback_defval).rgb;
if (defval.type == COLOR_IS_SPECIAL) return colorprofile_to_color(self, fallback, fallback_defval).rgb;
return defval.rgb;
case COLOR_IS_RGB:
return entry.rgb;
@ -234,7 +234,7 @@ as_dict(ColorProfile *self, PyObject *args UNUSED) {
}}
D(default_fg, foreground); D(default_bg, background);
D(cursor_color, cursor); D(cursor_text_color, cursor_text); D(highlight_fg, selection_foreground);
D(highlight_bg, selection_background);
D(highlight_bg, selection_background); D(visual_bell_color, visual_bell_color);
#undef D
return ans;
@ -295,13 +295,13 @@ set_color(ColorProfile *self, PyObject *args) {
static PyObject*
set_configured_colors(ColorProfile *self, PyObject *args) {
#define set_configured_colors_doc "Set the configured colors"
unsigned int default_fg, default_bg, cursor_color, cursor_text_color, highlight_fg, highlight_bg;
if (!PyArg_ParseTuple(args, "II|IIII", &default_fg, &default_bg,
&cursor_color, &cursor_text_color, &highlight_fg, &highlight_bg)) return NULL;
unsigned int default_fg, default_bg, cursor_color, cursor_text_color, highlight_fg, highlight_bg, visual_bell_color;
if (!PyArg_ParseTuple(args, "II|IIIII", &default_fg, &default_bg,
&cursor_color, &cursor_text_color, &highlight_fg, &highlight_bg, &visual_bell_color)) return NULL;
#define S(which) \
self->configured.which.rgb = which & 0xffffff; \
self->configured.which.type = (which & 0xff000000) ? COLOR_IS_RGB : COLOR_IS_SPECIAL;
S(default_fg); S(default_bg); S(cursor_color); S(cursor_text_color); S(highlight_fg); S(highlight_bg);
S(default_fg); S(default_bg); S(cursor_color); S(cursor_text_color); S(highlight_fg); S(highlight_bg); S(visual_bell_color);
#undef S
self->dirty = true;
Py_RETURN_NONE;
@ -412,6 +412,7 @@ CGETSET(cursor_color)
CGETSET(cursor_text_color)
CGETSET(highlight_fg)
CGETSET(highlight_bg)
CGETSET(visual_bell_color)
#undef CGETSET
static PyGetSetDef cp_getsetters[] = {
@ -421,6 +422,7 @@ static PyGetSetDef cp_getsetters[] = {
GETSET(cursor_text_color)
GETSET(highlight_fg)
GETSET(highlight_bg)
GETSET(visual_bell_color)
{NULL} /* Sentinel */
};

View File

@ -258,7 +258,7 @@ typedef union DynamicColor {
} DynamicColor;
typedef struct {
DynamicColor default_fg, default_bg, cursor_color, cursor_text_color, highlight_fg, highlight_bg;
DynamicColor default_fg, default_bg, cursor_color, cursor_text_color, highlight_fg, highlight_bg, visual_bell_color;
} DynamicColors;

View File

@ -701,7 +701,7 @@ class ColorProfile:
pass
def set_configured_colors(
self, fg: int, bg: int, cursor: int = 0, cursor_text: int = 0, highlight_fg: int = 0, highlight_bg: int = 0
self, fg: int, bg: int, cursor: int = 0, cursor_text: int = 0, highlight_fg: int = 0, highlight_bg: int = 0, visual_bell_color: int = 0
) -> None:
pass

View File

@ -670,6 +670,14 @@ number of seconds. Set to zero to disable.
'''
)
opt('visual_bell_color', 'none',
option_type='to_color_or_none',
long_text='''
The color used by visual bell. Set to :code:`none` will fall back to selection
background color. If you feel that the visual bell is too bright, you can
set it to a darker color.
''')
opt('window_alert_on_bell', 'yes',
option_type='to_bool', ctype='bool',
long_text='''

View File

@ -1248,6 +1248,9 @@ class Parser:
def url_style(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['url_style'] = url_style(val)
def visual_bell_color(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['visual_bell_color'] = to_color_or_none(val)
def visual_bell_duration(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['visual_bell_duration'] = positive_float(val)

View File

@ -431,6 +431,7 @@ option_names = ( # {{{
'url_excluded_characters',
'url_prefixes',
'url_style',
'visual_bell_color',
'visual_bell_duration',
'watcher',
'wayland_titlebar_color',
@ -570,6 +571,7 @@ class Options:
url_excluded_characters: str = ''
url_prefixes: typing.Tuple[str, ...] = ('http', 'https', 'file', 'ftp', 'gemini', 'irc', 'gopher', 'mailto', 'news', 'git')
url_style: int = 3
visual_bell_color: typing.Optional[kitty.fast_data_types.Color] = None
visual_bell_duration: float = 0
wayland_titlebar_color: int = 0
wheel_scroll_multiplier: float = 5.0

View File

@ -18,6 +18,7 @@ if TYPE_CHECKING:
nullable_colors = (
# generated by gen-config.py DO NOT edit
# NULLABLE_COLORS_START
'active_border_color',
'cursor',
@ -26,6 +27,7 @@ nullable_colors = (
'selection_foreground',
'tab_bar_background',
'tab_bar_margin_color',
'visual_bell_color',
# NULLABLE_COLORS_END
)

View File

@ -635,8 +635,11 @@ draw_visual_bell_flash(GLfloat intensity, GLfloat xstart, GLfloat ystart, GLfloa
glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
bind_program(TINT_PROGRAM);
GLfloat attenuation = 0.4f;
const color_type flash = colorprofile_to_color_with_fallback(
screen->color_profile, screen->color_profile->overridden.highlight_bg, screen->color_profile->configured.highlight_bg, screen->color_profile->overridden.default_fg, screen->color_profile->configured.default_fg);
#define IS_SPECIAL_COLOR(name) (screen->color_profile->overridden.name.type == COLOR_IS_SPECIAL || (screen->color_profile->overridden.name.type == COLOR_NOT_SET && screen->color_profile->configured.name.type == COLOR_IS_SPECIAL))
#define COLOR(name, fallback) colorprofile_to_color_with_fallback(screen->color_profile, screen->color_profile->overridden.name, screen->color_profile->configured.name, screen->color_profile->overridden.fallback, screen->color_profile->configured.fallback)
const color_type flash = !IS_SPECIAL_COLOR(highlight_bg) ? COLOR(visual_bell_color, highlight_bg) : COLOR(visual_bell_color, default_fg);
#undef IS_SPECIAL_COLOR
#undef COLOR
#define C(shift) ((((GLfloat)((flash >> shift) & 0xFF)) / 255.0f) )
const GLfloat r = C(16), g = C(8), b = C(0);
const GLfloat max_channel = r > g ? (r > b ? r : b) : (g > b ? g : b);

View File

@ -268,7 +268,8 @@ def setup_colors(screen: Screen, opts: Options) -> None:
screen.color_profile.set_configured_colors(
s(opts.foreground), s(opts.background),
s(opts.cursor), s(opts.cursor_text_color),
s(opts.selection_foreground), s(opts.selection_background)
s(opts.selection_foreground), s(opts.selection_background),
s(opts.visual_bell_color)
)