Fix reloading of various settings

This commit is contained in:
Kovid Goyal 2021-06-07 08:27:58 +05:30
parent 9003c76261
commit ec31a36fd9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
8 changed files with 80 additions and 29 deletions

View File

@ -26,13 +26,13 @@ from .constants import (
)
from .fast_data_types import (
CLOSE_BEING_CONFIRMED, IMPERATIVE_CLOSE_REQUESTED, NO_CLOSE_REQUESTED,
ChildMonitor, KeyEvent, add_timer, background_opacity_of,
change_background_opacity, change_os_window_state, cocoa_set_menubar_title,
create_os_window, current_application_quit_request, current_os_window,
destroy_global_data, focus_os_window, get_clipboard_string, get_options,
global_font_size, mark_os_window_for_close, os_window_font_size,
patch_color_profiles, patch_global_colors, safe_pipe,
set_application_quit_request, set_background_image, set_boss,
ChildMonitor, KeyEvent, add_timer, apply_options_update,
background_opacity_of, change_background_opacity, change_os_window_state,
cocoa_set_menubar_title, create_os_window,
current_application_quit_request, current_os_window, destroy_global_data,
focus_os_window, get_clipboard_string, get_options, global_font_size,
mark_os_window_for_close, os_window_font_size, patch_global_colors,
safe_pipe, set_application_quit_request, set_background_image, set_boss,
set_clipboard_string, set_in_sequence_mode, set_options, thread_write,
toggle_fullscreen, toggle_maximized
)
@ -1436,9 +1436,14 @@ class Boss:
patch_global_colors(spec, configured)
def apply_new_options(self, opts: Options) -> None:
from .fonts.box_drawing import set_scale
# Update options storage
set_options(opts, is_wayland(), self.args.debug_rendering, self.args.debug_font_fallback)
apply_options_update()
set_layout_options(opts)
# Update font data
set_scale(opts.box_drawing_scale)
from .fonts.render import set_font_family
set_font_family(opts, debug_font_matching=self.args.debug_font_fallback)
for os_window_id, tm in self.os_window_map.items():
@ -1447,13 +1452,10 @@ class Boss:
tm.resize()
# Update key bindings
self.update_keymap()
# Update colors
spec = {k: int(v) if isinstance(v, Color) else v for k, v in opts._asdict().items()}
# Update misc options
for tm in self.all_tab_managers:
tm.tab_bar.patch_colors(spec)
profiles = tuple(w.screen.color_profile for w in self.all_windows)
ctc = None if opts.cursor_text_color is None else int(opts.cursor_text_color)
patch_color_profiles(spec, ctc, profiles, True)
tm.apply_options()
# Update colors
for w in self.all_windows:
self.default_bg_changed_for(w.id)
w.refresh()

View File

@ -1182,3 +1182,7 @@ def click_mouse_url(os_window_id: int, tab_id: int, window_id: int) -> None:
def mouse_selection(os_window_id: int, tab_id: int, window_id: int, code: int, button: int) -> None:
pass
def apply_options_update() -> None:
pass

View File

@ -32,6 +32,18 @@ static GLFWcursor *standard_cursor = NULL, *click_cursor = NULL, *arrow_cursor =
static void set_os_window_dpi(OSWindow *w);
void
get_platform_dependent_config_values(void *glfw_window) {
if (OPT(click_interval) < 0) OPT(click_interval) = glfwGetDoubleClickInterval(glfw_window);
if (OPT(cursor_blink_interval) < 0) {
OPT(cursor_blink_interval) = ms_to_monotonic_t(500ll);
#ifdef __APPLE__
monotonic_t cbi = cocoa_cursor_blink_interval();
if (cbi >= 0) OPT(cursor_blink_interval) = cbi / 2;
#endif
}
}
void
request_tick_callback(void) {
glfwPostEmptyEvent();
@ -706,16 +718,9 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
dest##_cursor = glfwCreateStandardCursor(GLFW_##shape##_CURSOR); \
if (dest##_cursor == NULL) { log_error("Failed to create the %s mouse cursor, using default cursor.", #shape); } \
}}
CC(standard, IBEAM); CC(click, HAND); CC(arrow, ARROW);
CC(standard, IBEAM); CC(click, HAND); CC(arrow, ARROW);
#undef CC
if (OPT(click_interval) < 0) OPT(click_interval) = glfwGetDoubleClickInterval(glfw_window);
if (OPT(cursor_blink_interval) < 0) {
OPT(cursor_blink_interval) = ms_to_monotonic_t(500ll);
#ifdef __APPLE__
monotonic_t cbi = cocoa_cursor_blink_interval();
if (cbi >= 0) OPT(cursor_blink_interval) = cbi / 2;
#endif
}
get_platform_dependent_config_values(glfw_window);
is_first_window = false;
}
OSWindow *w = add_os_window();

View File

@ -886,6 +886,15 @@ PYWRAP0(get_boss) {
Py_RETURN_NONE;
}
PYWRAP0(apply_options_update) {
for (size_t o = 0; o < global_state.num_os_windows; o++) {
OSWindow *os_window = global_state.os_windows + o;
get_platform_dependent_config_values(os_window->handle);
break;
}
Py_RETURN_NONE;
}
PYWRAP1(patch_global_colors) {
PyObject *spec;
int configured;
@ -1057,6 +1066,7 @@ static PyMethodDef module_methods[] = {
MW(os_window_font_size, METH_VARARGS),
MW(set_boss, METH_O),
MW(get_boss, METH_NOARGS),
MW(apply_options_update, METH_NOARGS),
MW(patch_global_colors, METH_VARARGS),
MW(create_mock_window, METH_VARARGS),
MW(destroy_global_data, METH_NOARGS),

View File

@ -300,3 +300,4 @@ void mouse_selection(Window *w, int code, int button);
const char* format_mods(unsigned mods);
void send_pending_click_to_window_id(id_type, void*);
void send_pending_click_to_window(Window*, void*);
void get_platform_dependent_config_values(void *glfw_window);

View File

@ -256,19 +256,25 @@ class TabBar:
def __init__(self, os_window_id: int):
self.os_window_id = os_window_id
self.num_tabs = 1
self.data_buffer_size = 0
self.blank_rects: Tuple[Rect, ...] = ()
self.laid_out_once = False
self.apply_options()
def apply_options(self) -> None:
opts = get_options()
self.dirty = True
self.margin_width = pt_to_px(opts.tab_bar_margin_width, self.os_window_id)
self.cell_width, cell_height = cell_size_for_window(self.os_window_id)
self.data_buffer_size = 0
self.laid_out_once = False
self.dirty = True
self.screen = s = Screen(None, 1, 10, 0, self.cell_width, cell_height)
if not hasattr(self, 'screen'):
self.screen = s = Screen(None, 1, 10, 0, self.cell_width, cell_height)
else:
s = self.screen
s.color_profile.update_ansi_color_table(build_ansi_color_table(opts))
s.color_profile.set_configured_colors(
color_as_int(opts.inactive_tab_foreground),
color_as_int(opts.tab_bar_background or opts.background)
)
self.blank_rects: Tuple[Rect, ...] = ()
sep = opts.tab_separator
self.trailing_spaces = self.leading_spaces = 0
while sep and sep[0] == ' ':
@ -309,6 +315,8 @@ class TabBar:
self.draw_data = self.draw_data._replace(active_bg=color_from_int(spec['active_tab_background']))
if 'inactive_tab_background' in spec:
self.draw_data = self.draw_data._replace(inactive_bg=color_from_int(spec['inactive_tab_background']))
if 'tab_bar_background' in spec:
self.draw_data = self.draw_data._replace(default_bg=color_from_int(spec['tab_bar_background']))
opts = get_options()
fg = spec.get('inactive_tab_foreground', color_as_int(opts.inactive_tab_foreground))
bg = spec.get('tab_bar_background', False)
@ -316,8 +324,6 @@ class TabBar:
bg = color_as_int(opts.background)
elif bg is False:
bg = color_as_int(opts.tab_bar_background or opts.background)
if 'tab_bar_background' in spec:
self.draw_data = self.draw_data._replace(default_bg=color_from_int(bg))
self.screen.color_profile.set_configured_colors(fg, bg)
def layout(self) -> None:

View File

@ -115,6 +115,14 @@ class Tab: # {{{
self._set_current_layout(l0)
self.startup(session_tab)
def apply_options(self) -> None:
for window in self:
window.apply_options()
self.enabled_layouts = [x.lower() for x in get_options().enabled_layouts] or ['tall']
if self.current_layout.name not in self.enabled_layouts:
self._set_current_layout(self.enabled_layouts[0])
self.relayout()
def take_over_from(self, other_tab: 'Tab') -> None:
self.name, self.cwd = other_tab.name, other_tab.cwd
self.enabled_layouts = list(other_tab.enabled_layouts)
@ -828,4 +836,13 @@ class TabManager: # {{{
self.tab_bar.destroy()
del self.tab_bar
del self.tabs
def apply_options(self) -> None:
for tab in self:
tab.apply_options()
self.tab_bar_hidden = get_options().tab_bar_style == 'hidden'
self.tab_bar.apply_options()
self.update_tab_bar_data()
self.mark_tab_bar_dirty()
self.tab_bar.layout()
# }}}

View File

@ -398,6 +398,12 @@ class Window:
val = round(val)
return int(val)
def apply_options(self) -> None:
opts = get_options()
self.update_effective_padding()
self.change_titlebar_color()
setup_colors(self.screen, opts)
@property
def title(self) -> str:
return self.override_title or self.child_title