Fade the window logo by a configurable amount

This commit is contained in:
Kovid Goyal 2021-12-03 18:05:59 +05:30
parent 6f48dda8b9
commit 42a2493286
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
8 changed files with 39 additions and 7 deletions

View File

@ -1284,7 +1284,7 @@ def mouse_selection(os_window_id: int, tab_id: int, window_id: int, code: int, b
pass pass
def set_window_logo(os_window_id: int, tab_id: int, window_id: int, path: str, position: str) -> None: def set_window_logo(os_window_id: int, tab_id: int, window_id: int, path: str, position: str, alpha: float) -> None:
pass pass

View File

@ -881,6 +881,10 @@ Where to position the window logo in the window. The value can be one of:
''' '''
) )
opt('window_logo_alpha', 0.5, option_type='unit_float', ctype='float', long_text='''
The amount the logo should be faded into the background. With zero being fully faded
and one being fully opaque.''')
opt('resize_debounce_time', '0.1', opt('resize_debounce_time', '0.1',
option_type='positive_float', ctype='time', option_type='positive_float', ctype='time',

View File

@ -1270,6 +1270,9 @@ class Parser:
def window_border_width(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: def window_border_width(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['window_border_width'] = window_border_width(val) ans['window_border_width'] = window_border_width(val)
def window_logo_alpha(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['window_logo_alpha'] = unit_float(val)
def window_logo_path(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: def window_logo_path(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['window_logo_path'] = config_or_absolute_path(val) ans['window_logo_path'] = config_or_absolute_path(val)

View File

@ -538,6 +538,19 @@ convert_from_opts_window_logo_position(PyObject *py_opts, Options *opts) {
Py_DECREF(ret); Py_DECREF(ret);
} }
static void
convert_from_python_window_logo_alpha(PyObject *val, Options *opts) {
opts->window_logo_alpha = PyFloat_AsFloat(val);
}
static void
convert_from_opts_window_logo_alpha(PyObject *py_opts, Options *opts) {
PyObject *ret = PyObject_GetAttrString(py_opts, "window_logo_alpha");
if (ret == NULL) return;
convert_from_python_window_logo_alpha(ret, opts);
Py_DECREF(ret);
}
static void static void
convert_from_python_resize_debounce_time(PyObject *val, Options *opts) { convert_from_python_resize_debounce_time(PyObject *val, Options *opts) {
opts->resize_debounce_time = parse_s_double_to_monotonic_t(val); opts->resize_debounce_time = parse_s_double_to_monotonic_t(val);
@ -1051,6 +1064,8 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) {
if (PyErr_Occurred()) return false; if (PyErr_Occurred()) return false;
convert_from_opts_window_logo_position(py_opts, opts); convert_from_opts_window_logo_position(py_opts, opts);
if (PyErr_Occurred()) return false; if (PyErr_Occurred()) return false;
convert_from_opts_window_logo_alpha(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_resize_debounce_time(py_opts, opts); convert_from_opts_resize_debounce_time(py_opts, opts);
if (PyErr_Occurred()) return false; if (PyErr_Occurred()) return false;
convert_from_opts_resize_draw_strategy(py_opts, opts); convert_from_opts_resize_draw_strategy(py_opts, opts);

View File

@ -437,6 +437,7 @@ option_names = ( # {{{
'wheel_scroll_multiplier', 'wheel_scroll_multiplier',
'window_alert_on_bell', 'window_alert_on_bell',
'window_border_width', 'window_border_width',
'window_logo_alpha',
'window_logo_path', 'window_logo_path',
'window_logo_position', 'window_logo_position',
'window_margin_width', 'window_margin_width',
@ -578,6 +579,7 @@ class Options:
wheel_scroll_multiplier: float = 5.0 wheel_scroll_multiplier: float = 5.0
window_alert_on_bell: bool = True window_alert_on_bell: bool = True
window_border_width: typing.Tuple[float, str] = (0.5, 'pt') window_border_width: typing.Tuple[float, str] = (0.5, 'pt')
window_logo_alpha: float = 0.5
window_logo_path: typing.Optional[str] = None window_logo_path: typing.Optional[str] = None
window_logo_position: choices_for_window_logo_position = 'bottom-right' window_logo_position: choices_for_window_logo_position = 'bottom-right'
window_margin_width: FloatEdges = FloatEdges(left=0, top=0, right=0, bottom=0) window_margin_width: FloatEdges = FloatEdges(left=0, top=0, right=0, bottom=0)

View File

@ -535,6 +535,7 @@ set_cell_uniforms(float current_inactive_text_alpha, bool force) {
cell_uniform_data.prev_inactive_text_alpha = current_inactive_text_alpha; cell_uniform_data.prev_inactive_text_alpha = current_inactive_text_alpha;
#define S(prog, loc) { bind_program(prog); glUniform1f(cell_uniform_data.loc, current_inactive_text_alpha); } #define S(prog, loc) { bind_program(prog); glUniform1f(cell_uniform_data.loc, current_inactive_text_alpha); }
S(CELL_PROGRAM, cploc); S(CELL_FG_PROGRAM, cfploc); S(GRAPHICS_PROGRAM, gploc); S(GRAPHICS_PREMULT_PROGRAM, gpploc); S(CELL_PROGRAM, cploc); S(CELL_FG_PROGRAM, cfploc); S(GRAPHICS_PROGRAM, gploc); S(GRAPHICS_PREMULT_PROGRAM, gpploc);
#undef S
} }
} }
@ -590,7 +591,11 @@ draw_window_logo(int program, ssize_t vao_idx, OSWindow *os_window, const Window
ird.texture_id = wl->instance->texture_id; ird.texture_id = wl->instance->texture_id;
gpu_data_for_image(&ird, logo_left_gl, logo_top_gl, logo_left_gl + logo_width_gl, logo_top_gl - logo_height_gl); gpu_data_for_image(&ird, logo_left_gl, logo_top_gl, logo_left_gl + logo_width_gl, logo_top_gl - logo_height_gl);
send_graphics_data_to_gpu(1, os_window->gvao_idx, &ird); send_graphics_data_to_gpu(1, os_window->gvao_idx, &ird);
bind_program(program);
const int alpha_loc = program == GRAPHICS_PROGRAM ? cell_uniform_data.gploc : cell_uniform_data.gpploc;
glUniform1f(alpha_loc, cell_uniform_data.prev_inactive_text_alpha * wl->alpha);
draw_graphics(program, vao_idx, os_window->gvao_idx, &ird, 0, 1); draw_graphics(program, vao_idx, os_window->gvao_idx, &ird, 0, 1);
glUniform1f(alpha_loc, cell_uniform_data.prev_inactive_text_alpha);
} }
static void static void

View File

@ -225,13 +225,14 @@ release_gpu_resources_for_window(Window *w) {
} }
static bool static bool
set_window_logo(Window *w, const char *path, const ImageAnchorPosition pos, bool is_default) { set_window_logo(Window *w, const char *path, const ImageAnchorPosition pos, float alpha, bool is_default) {
bool ok = false; bool ok = false;
if (path && path[0]) { if (path && path[0]) {
window_logo_id_t wl = find_or_create_window_logo(global_state.all_window_logos, path); window_logo_id_t wl = find_or_create_window_logo(global_state.all_window_logos, path);
if (wl) { if (wl) {
w->window_logo.id = wl; w->window_logo.id = wl;
w->window_logo.position = pos; w->window_logo.position = pos;
w->window_logo.alpha = alpha;
ok = true; ok = true;
} }
} else { } else {
@ -252,7 +253,7 @@ initialize_window(Window *w, PyObject *title, bool init_gpu_resources) {
w->visible = true; w->visible = true;
w->title = title; w->title = title;
Py_XINCREF(title); Py_XINCREF(title);
if (!set_window_logo(w, OPT(default_window_logo), OPT(window_logo_position), true)) { if (!set_window_logo(w, OPT(default_window_logo), OPT(window_logo_position), OPT(window_logo_alpha), true)) {
log_error("Failed to load default window logo: %s", OPT(default_window_logo)); log_error("Failed to load default window logo: %s", OPT(default_window_logo));
if (PyErr_Occurred()) PyErr_Print(); if (PyErr_Occurred()) PyErr_Print();
} }
@ -1017,7 +1018,7 @@ PYWRAP0(apply_options_update) {
for (size_t w = 0; w < tab->num_windows; w++) { for (size_t w = 0; w < tab->num_windows; w++) {
Window *window = tab->windows + w; Window *window = tab->windows + w;
if (window->window_logo.using_default) { if (window->window_logo.using_default) {
set_window_logo(window, OPT(default_window_logo), OPT(window_logo_position), true); set_window_logo(window, OPT(default_window_logo), OPT(window_logo_position), OPT(window_logo_alpha), true);
} }
} }
} }
@ -1161,10 +1162,11 @@ pymouse_selection(PyObject *self UNUSED, PyObject *args) {
PYWRAP1(set_window_logo) { PYWRAP1(set_window_logo) {
id_type os_window_id, tab_id, window_id; id_type os_window_id, tab_id, window_id;
const char *path; PyObject *position; const char *path; PyObject *position;
PA("KKKsU", &os_window_id, &tab_id, &window_id, &path, &position); float alpha = 0.5;
PA("KKKsUf", &os_window_id, &tab_id, &window_id, &path, &position, &alpha);
bool ok = false; bool ok = false;
WITH_WINDOW(os_window_id, tab_id, window_id); WITH_WINDOW(os_window_id, tab_id, window_id);
ok = set_window_logo(window, path, bganchor(position), false); ok = set_window_logo(window, path, bganchor(position), alpha, false);
END_WITH_WINDOW; END_WITH_WINDOW;
if (ok) Py_RETURN_TRUE; if (ok) Py_RETURN_TRUE;
Py_RETURN_FALSE; Py_RETURN_FALSE;

View File

@ -50,7 +50,7 @@ typedef struct {
BackgroundImageLayout background_image_layout; BackgroundImageLayout background_image_layout;
ImageAnchorPosition window_logo_position; ImageAnchorPosition window_logo_position;
bool background_image_linear; bool background_image_linear;
float background_tint; float background_tint, window_logo_alpha;
bool dynamic_background_opacity; bool dynamic_background_opacity;
float inactive_text_alpha; float inactive_text_alpha;
@ -86,6 +86,7 @@ typedef struct WindowLogoRenderData {
window_logo_id_t id; window_logo_id_t id;
WindowLogo *instance; WindowLogo *instance;
ImageAnchorPosition position; ImageAnchorPosition position;
float alpha;
bool using_default; bool using_default;
} WindowLogoRenderData; } WindowLogoRenderData;