Keyboard shortcuts to control background opacity

This commit is contained in:
Kovid Goyal
2018-05-23 08:48:59 +05:30
parent f46d3057ba
commit ae6e082419
6 changed files with 52 additions and 12 deletions

View File

@@ -19,11 +19,12 @@ from .constants import (
appname, config_dir, editor, set_boss, supports_primary_selection
)
from .fast_data_types import (
ChildMonitor, change_background_opacity, create_os_window,
current_os_window, destroy_global_data, destroy_sprite_map,
get_clipboard_string, glfw_post_empty_event, layout_sprite_map,
mark_os_window_for_close, set_clipboard_string, set_dpi_from_os_window,
set_in_sequence_mode, show_window, toggle_fullscreen, viewport_for_window
ChildMonitor, background_opacity_of, change_background_opacity,
create_os_window, current_os_window, destroy_global_data,
destroy_sprite_map, get_clipboard_string, glfw_post_empty_event,
layout_sprite_map, mark_os_window_for_close, set_clipboard_string,
set_dpi_from_os_window, set_in_sequence_mode, show_window,
toggle_fullscreen, viewport_for_window
)
from .fonts.render import prerender, resize_fonts, set_font_family
from .keys import get_shortcut, shortcut_matches
@@ -362,7 +363,23 @@ class Boss:
self._change_font_size()
def _set_os_window_background_opacity(self, os_window_id, opacity):
change_background_opacity(os_window_id, opacity)
change_background_opacity(os_window_id, max(0.1, min(opacity, 1.0)))
def set_background_opacity(self, opacity):
window = self.active_window
if window is None or not opacity:
return
os_window_id = window.os_window_id
if opacity[0] in '+-':
opacity = background_opacity_of(os_window_id)
if opacity is None:
return
opacity += float(opacity)
elif opacity == 'default':
opacity = self.opts.background_opacity
else:
opacity = float(opacity)
self._set_os_window_background_opacity(os_window_id, opacity)
@property
def active_tab_manager(self):

View File

@@ -124,6 +124,8 @@ def parse_key_action(action):
func = 'kitten'
elif func == 'goto_tab':
args = (max(0, int(rest)), )
elif func == 'set_background_opacity':
args = [rest]
elif func == 'goto_layout' or func == 'kitty_shell':
args = [rest]
elif func == 'set_font_size':

View File

@@ -501,6 +501,10 @@ map kitty_mod+u input_unicode_character
map kitty_mod+f2 edit_config_file
# Open the kitty shell in a new window/tab/overlay/os_window to control kitty using commands.
map kitty_mod+escape kitty_shell window
map kitty_mod+a>shift+= set_background_opacity +0.1
map kitty_mod+a>shift+- set_background_opacity -0.1
map kitty_mod+a>shift+1 set_background_opacity 1
map kitty_mod+a>shift+d set_background_opacity default
# Sending arbitrary text on shortcut key presses
# You can tell kitty to send arbitrary (UTF-8) encoded text to

View File

@@ -517,6 +517,14 @@ PYWRAP1(change_background_opacity) {
Py_RETURN_FALSE;
}
PYWRAP1(background_opacity_of) {
id_type os_window_id = PyLong_AsUnsignedLongLong(args);
WITH_OS_WINDOW(os_window_id)
return PyFloat_FromDouble((double)os_window->background_opacity);
END_WITH_OS_WINDOW
Py_RETURN_NONE;
}
static inline bool
fix_window_idx(Tab *tab, id_type window_id, unsigned int *window_idx) {
for (id_type fix = 0; fix < tab->num_windows; fix++) {
@@ -645,6 +653,7 @@ static PyMethodDef module_methods[] = {
MW(set_titlebar_color, METH_VARARGS),
MW(mark_tab_bar_dirty, METH_O),
MW(change_background_opacity, METH_VARARGS),
MW(background_opacity_of, METH_O),
MW(update_window_visibility, METH_VARARGS),
MW(set_boss, METH_O),
MW(set_display_state, METH_VARARGS),