macOS: Implement background blurring

Uses a private API that allows us to control the amount of blurring.
While using a private API is obviously not ideal, it is used by both
iTerm.app and Apple's own Terminal.app, so hopefully it should stick
around. Fixes #6135
This commit is contained in:
Kovid Goyal
2023-06-27 08:48:16 +05:30
parent 326b81a970
commit 7a1bdb4ff1
15 changed files with 89 additions and 1 deletions

View File

@@ -1371,6 +1371,17 @@ config.
'''
)
opt('background_blur', '0', option_type='int', ctype='int',
long_text='''
Set to a positive value to enable background blur (blurring of the visuals
behind a transparent window) on platforms that support it. Only takes effect
when :opt:`background_opacity` is less than one. On macOS, this will also
control the :italic:`blur radius` (amount of blurring). Setting it to too high
a value will cause severe performance issues and/or rendering artifacts.
Usually, values up to 64 work well. Note that this might cause performance issues,
depending on how the platform implements it, so use with care.
''')
opt('background_image', 'none',
option_type='config_or_absolute_path', ctype='!background_image',
long_text='Path to a background image. Must be in PNG format.'

View File

@@ -65,6 +65,9 @@ class Parser:
def background(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['background'] = to_color(val)
def background_blur(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['background_blur'] = int(val)
def background_image(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['background_image'] = config_or_absolute_path(val)

View File

@@ -733,6 +733,19 @@ convert_from_opts_background_opacity(PyObject *py_opts, Options *opts) {
Py_DECREF(ret);
}
static void
convert_from_python_background_blur(PyObject *val, Options *opts) {
opts->background_blur = PyLong_AsLong(val);
}
static void
convert_from_opts_background_blur(PyObject *py_opts, Options *opts) {
PyObject *ret = PyObject_GetAttrString(py_opts, "background_blur");
if (ret == NULL) return;
convert_from_python_background_blur(ret, opts);
Py_DECREF(ret);
}
static void
convert_from_python_background_image(PyObject *val, Options *opts) {
background_image(val, opts);
@@ -1159,6 +1172,8 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) {
if (PyErr_Occurred()) return false;
convert_from_opts_background_opacity(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_background_blur(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_background_image(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_background_image_layout(py_opts, opts);

View File

@@ -61,6 +61,7 @@ option_names = ( # {{{
'allow_hyperlinks',
'allow_remote_control',
'background',
'background_blur',
'background_image',
'background_image_layout',
'background_image_linear',
@@ -480,6 +481,7 @@ class Options:
allow_hyperlinks: int = 1
allow_remote_control: choices_for_allow_remote_control = 'no'
background: Color = Color(0, 0, 0)
background_blur: int = 0
background_image: typing.Optional[str] = None
background_image_layout: choices_for_background_image_layout = 'tiled'
background_image_linear: bool = False
@@ -511,7 +513,7 @@ class Options:
cursor_underline_thickness: float = 2.0
default_pointer_shape: choices_for_default_pointer_shape = 'beam'
detect_urls: bool = True
dim_opacity: float = 0.75
dim_opacity: float = 0.4
disable_ligatures: int = 0
draw_minimal_borders: bool = True
dynamic_background_opacity: bool = False