From 253b219d676acdc749514f094e7940043f77311d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 24 May 2021 11:50:03 +0530 Subject: [PATCH] Store the options object globally --- kitty/fast_data_types.pyi | 6 +++++- kitty/main.py | 3 ++- kitty/state.c | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 7e3852302..72b367cc0 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -515,7 +515,7 @@ def sync_os_window_title(os_window_id: int) -> None: def set_options( - opts: Options, + opts: Optional[Options], is_wayland: bool = False, debug_rendering: bool = False, debug_font_fallback: bool = False @@ -523,6 +523,10 @@ def set_options( pass +def get_options() -> Options: + pass + + def resolve_key_mods(kitty_mod: int, mods: int) -> int: pass diff --git a/kitty/main.py b/kitty/main.py index 98ac20b3b..0b3e8ab45 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -171,10 +171,11 @@ class AppRunner: def __call__(self, opts: OptionsStub, args: CLIOptions, bad_lines: Sequence[BadLine] = ()) -> None: set_scale(opts.box_drawing_scale) set_options(opts, is_wayland(), args.debug_rendering, args.debug_font_fallback) - set_font_family(opts, debug_font_matching=args.debug_font_fallback) try: + set_font_family(opts, debug_font_matching=args.debug_font_fallback) _run_app(opts, args, bad_lines) finally: + set_options(None) free_font_data() # must free font data before glfw/freetype/fontconfig/opengl etc are finalized diff --git a/kitty/state.c b/kitty/state.c index e6d0b4d36..51ce439c8 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -694,10 +694,25 @@ PYWRAP1(handle_for_window_id) { return NULL; } +static PyObject* options_object = NULL; + +PYWRAP0(get_options) { + if (!options_object) { + PyErr_SetString(PyExc_RuntimeError, "Must call set_options() before using get_options()"); + return NULL; + } + Py_INCREF(options_object); + return options_object; +} + PYWRAP1(set_options) { PyObject *ret, *opts; int is_wayland = 0, debug_rendering = 0, debug_font_fallback = 0; PA("O|ppp", &opts, &is_wayland, &debug_rendering, &debug_font_fallback); + if (opts == Py_None) { + Py_CLEAR(options_object); + Py_RETURN_NONE; + } global_state.is_wayland = is_wayland ? true : false; #ifdef __APPLE__ global_state.has_render_frames = true; @@ -814,6 +829,8 @@ PYWRAP1(set_options) { #undef read_adjust #undef S #undef SS + options_object = opts; + Py_INCREF(options_object); Py_RETURN_NONE; } @@ -1206,6 +1223,7 @@ static PyMethodDef module_methods[] = { MW(current_os_window, METH_NOARGS), MW(next_window_id, METH_NOARGS), MW(set_options, METH_VARARGS), + MW(get_options, METH_NOARGS), MW(click_mouse_url, METH_VARARGS), MW(mouse_selection, METH_VARARGS), MW(set_in_sequence_mode, METH_O),