add option to scale window_logo via window_logo_scale

This commit is contained in:
aki 2024-06-12 21:29:04 +09:00
parent e3239fdcdf
commit 56fc4eddbd
6 changed files with 50 additions and 2 deletions

View file

@ -1160,6 +1160,13 @@
'''
)
opt('window_logo_scale', '0',
option_type='int', ctype='int',
long_text='''
The percentage [1-100] of the window which the logo should scale to.
0 to disable.
'''
)
opt('resize_debounce_time', '0.1 0.5',
option_type='resize_debounce_time', ctype='!resize_debounce_time',

View file

@ -1388,7 +1388,10 @@ def window_logo_position(self, val: str, ans: typing.Dict[str, typing.Any]) -> N
raise ValueError(f"The value {val} is not a valid choice for window_logo_position")
ans["window_logo_position"] = val
choices_for_window_logo_position = frozenset(('top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right'))
choices_for_window_logo_position = choices_for_placement_strategy
def window_logo_scale(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['window_logo_scale'] = int(val)
def window_margin_width(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['window_margin_width'] = edge_width(val)

View file

@ -616,6 +616,19 @@ convert_from_opts_window_logo_alpha(PyObject *py_opts, Options *opts) {
Py_DECREF(ret);
}
static void
convert_from_python_window_logo_scale(PyObject *val, Options *opts) {
opts->window_logo_scale = PyLong_AsLong(val);
}
static void
convert_from_opts_window_logo_scale(PyObject *py_opts, Options *opts) {
PyObject *ret = PyObject_GetAttrString(py_opts, "window_logo_scale");
if (ret == NULL) return;
convert_from_python_window_logo_scale(ret, opts);
Py_DECREF(ret);
}
static void
convert_from_python_resize_debounce_time(PyObject *val, Options *opts) {
resize_debounce_time(val, opts);
@ -1232,6 +1245,8 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) {
if (PyErr_Occurred()) return false;
convert_from_opts_window_logo_alpha(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_window_logo_scale(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_resize_debounce_time(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_resize_in_steps(py_opts, opts);

View file

@ -34,7 +34,7 @@
choices_for_terminfo_type = typing.Literal['path', 'direct', 'none']
choices_for_undercurl_style = typing.Literal['thin-sparse', 'thin-dense', 'thick-sparse', 'thick-dense']
choices_for_underline_hyperlinks = typing.Literal['hover', 'always', 'never']
choices_for_window_logo_position = typing.Literal['top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right']
choices_for_window_logo_position = choices_for_placement_strategy
option_names = ( # {{{
'action_alias',
@ -459,6 +459,7 @@
'window_logo_alpha',
'window_logo_path',
'window_logo_position',
'window_logo_scale',
'window_margin_width',
'window_padding_width',
'window_resize_step_cells',
@ -619,6 +620,7 @@ class Options:
window_logo_alpha: float = 0.5
window_logo_path: typing.Optional[str] = None
window_logo_position: choices_for_window_logo_position = 'bottom-right'
window_logo_scale: int = 0
window_margin_width: FloatEdges = FloatEdges(left=0, top=0, right=0, bottom=0)
window_padding_width: FloatEdges = FloatEdges(left=0, top=0, right=0, bottom=0)
window_resize_step_cells: int = 2

View file

@ -732,6 +732,26 @@ draw_window_logo(ssize_t vao_idx, OSWindow *os_window, const WindowLogoRenderDat
BLEND_PREMULT;
GLfloat logo_width_gl = gl_size(wl->instance->width, os_window->viewport_width);
GLfloat logo_height_gl = gl_size(wl->instance->height, os_window->viewport_height);
if (OPT(window_logo_scale) != 0) {
unsigned int scaled_wl_width;
unsigned int scaled_wl_height;
if (os_window->viewport_height < os_window->viewport_width) {
scaled_wl_height = os_window->viewport_height * OPT(window_logo_scale) / 100;
scaled_wl_width = wl->instance->width * scaled_wl_height / wl->instance->height;
} else {
scaled_wl_width = os_window->viewport_width * OPT(window_logo_scale) / 100;
scaled_wl_height = wl->instance->height * scaled_wl_width / wl->instance->width;
}
logo_height_gl = gl_size(scaled_wl_height, os_window->viewport_height);
logo_width_gl = gl_size(scaled_wl_width, os_window->viewport_width);
} else {
logo_height_gl = 0;
logo_width_gl = 0;
}
GLfloat logo_left_gl = clamp_position_to_nearest_pixel(
crd->gl.xstart + crd->gl.width * wl->position.canvas_x - logo_width_gl * wl->position.image_x, os_window->viewport_width);
GLfloat logo_top_gl = clamp_position_to_nearest_pixel(

View file

@ -65,6 +65,7 @@ typedef struct {
ImageAnchorPosition window_logo_position;
bool background_image_linear;
float background_tint, background_tint_gaps, window_logo_alpha;
unsigned int window_logo_scale;
bool dynamic_background_opacity;
float inactive_text_alpha;