Remote control command to set background image

This commit is contained in:
Kovid Goyal
2020-02-01 10:50:56 +05:30
parent 8116ee015a
commit eb57d0d431
3 changed files with 65 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ from .cli import (
)
from .config import parse_config, parse_send_text_bytes
from .constants import appname
from .fast_data_types import focus_os_window
from .fast_data_types import focus_os_window, set_background_image as set_background_image_impl
from .launch import (
launch as do_launch, options_spec as launch_options_spec,
parse_launch_args
@@ -1252,6 +1252,68 @@ def set_background_opacity(boss, window, payload):
# }}}
# set_background_image {{{
@cmd(
'Set the background_image',
'Set the background image for the specified OS windows.',
options_spec='''\
--all -a
type=bool-set
By default, background image is only changed for the currently active OS window. This option will
cause the image to be changed in all windows.
--configured -c
type=bool-set
Change the configured background image which is used for new OS windows.
--layout
type=choices
choices=tiled,scaled,mirror-tiled,configured
How the image should be displayed. The value of configured will use the configured value.
''' + '\n\n' + MATCH_WINDOW_OPTION,
argspec='PATH_TO_PNG_IMAGE',
args_count=1
)
def cmd_set_background_image(global_opts, opts, args):
'''
path: Path to a PNG image
match: Window to change opacity in
layout: The image layout
all: Boolean indicating operate on all windows
configured: Boolean indicating if the configured value should be changed
'''
if not args:
raise SystemExit('Must specify path to PNG image')
path = args[0]
import imghdr
if imghdr.what(path) != 'png':
raise SystemExit('{} is not a PNG image'.format(path))
return {
'path': path, 'match': opts.match, 'configured': opts.configured,
'layout': opts.layout, 'all': opts.all,
}
def set_background_image(boss, window, payload):
pg = cmd_set_background_image.payload_get
windows = windows_for_payload(boss, window, payload)
os_windows = tuple({w.os_window_id for w in windows})
layout = pg(payload, 'layout')
try:
if layout:
set_background_image_impl(pg(payload, 'path'), os_windows, pg(payload, 'configured'), layout)
else:
set_background_image_impl(pg(payload, 'path'), os_windows, pg(payload, 'configured'))
except ValueError as err:
err.hide_traceback = True
raise
# }}}
# disable_ligatures {{{
@cmd(
'Control ligature rendering',

View File

@@ -861,7 +861,7 @@ def config_or_absolute_path(x):
o('background_image', 'none', option_type=config_or_absolute_path, long_text=_('''
Path to a background image. Must be in PNG format.'''))
o('background_image_layout', 'tiled', option_type=choices('tiled', 'scaled', 'mirror_tiled'), long_text=_('''
o('background_image_layout', 'tiled', option_type=choices('tiled', 'scaled', 'mirror-tiled'), long_text=_('''
Whether to tile or scale the background image.'''))
o('background_image_linear', False, long_text=_('''

View File

@@ -908,7 +908,7 @@ pyset_background_image(PyObject *self UNUSED, PyObject *args) {
PyObject *layout_name = NULL;
PyObject *os_window_ids;
int configured = 0;
PA("sO&|pU", &path, &PyTuple_Type, &os_window_ids, &configured, &layout_name);
PA("sO!|pU", &path, &PyTuple_Type, &os_window_ids, &configured, &layout_name);
size_t size;
BackgroundImageLayout layout = layout_name ? bglayout(layout_name) : OPT(background_image_layout);
BackgroundImage *bgimage = calloc(1, sizeof(BackgroundImage));