From 24c44861ef9b2742d0ed06b3dfb287e69cb0b96f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 Jan 2022 22:06:07 +0530 Subject: [PATCH] Cleanup previous PR Simplify wrapping of toggle_secure_input Dont duplicate debug_keyboard flag in two places --- kitty/boss.py | 2 +- kitty/cocoa_window.m | 2 +- kitty/fast_data_types.pyi | 3 ++- kitty/glfw.c | 16 +++++++++------- kitty/main.py | 2 +- kitty/state.c | 11 ++--------- kitty/state.h | 3 +-- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 551f9710d..8e152aaf1 100755 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1894,7 +1894,7 @@ class Boss: from .fonts.box_drawing import set_scale # Update options storage - set_options(opts, is_wayland(), self.args.debug_keyboard, self.args.debug_rendering, self.args.debug_font_fallback) + set_options(opts, is_wayland(), self.args.debug_rendering, self.args.debug_font_fallback) apply_options_update() set_layout_options(opts) set_default_env(opts.env.copy()) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index f1290c570..a9ad95243 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -76,7 +76,7 @@ find_app_name(void) { return @"kitty"; } -#define debug_key(...) if (global_state.debug_keyboard) { fprintf(stderr, __VA_ARGS__); fflush(stderr); } +#define debug_key(...) if (OPT(debug_keyboard)) { fprintf(stderr, __VA_ARGS__); fflush(stderr); } // SecureKeyboardEntryController {{{ @interface SecureKeyboardEntryController : NSObject diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index d04b50ca1..59261ab79 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -526,7 +526,6 @@ def sync_os_window_title(os_window_id: int) -> None: def set_options( opts: Optional[Options], is_wayland: bool = False, - debug_keyboard: bool = False, debug_rendering: bool = False, debug_font_fallback: bool = False ) -> None: @@ -764,9 +763,11 @@ def get_clipboard_string() -> str: def focus_os_window(os_window_id: int, also_raise: bool = True) -> bool: pass + def toggle_secure_input() -> None: pass + def start_profiler(path: str) -> None: pass diff --git a/kitty/glfw.c b/kitty/glfw.c index 379dfe12a..26c7fc412 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -966,13 +966,6 @@ focus_os_window(OSWindow *w, bool also_raise) { } } -void -toggle_secure_input(void) { -#ifdef __APPLE__ - cocoa_toggle_secure_keyboard_entry(); -#endif -} - // Global functions {{{ static void error_callback(int error, const char* description) { @@ -1189,6 +1182,14 @@ glfw_window_hint(PyObject UNUSED *self, PyObject *args) { // }}} +static PyObject* +toggle_secure_input(PYNOARG) { +#ifdef __APPLE__ + cocoa_toggle_secure_keyboard_entry(); +#endif + Py_RETURN_NONE; +} + static PyObject* get_clipboard_string(PYNOARG) { OSWindow *w = current_os_window(); @@ -1570,6 +1571,7 @@ static PyMethodDef module_methods[] = { {"create_os_window", (PyCFunction)(void (*) (void))(create_os_window), METH_VARARGS | METH_KEYWORDS, NULL}, METHODB(set_default_window_icon, METH_VARARGS), METHODB(get_clipboard_string, METH_NOARGS), + METHODB(toggle_secure_input, METH_NOARGS), METHODB(get_content_scale_for_window, METH_NOARGS), METHODB(ring_bell, METH_NOARGS), METHODB(set_clipboard_string, METH_VARARGS), diff --git a/kitty/main.py b/kitty/main.py index a3e8dc0c0..458bb455e 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -191,7 +191,7 @@ class AppRunner: def __call__(self, opts: Options, args: CLIOptions, bad_lines: Sequence[BadLine] = ()) -> None: set_scale(opts.box_drawing_scale) - set_options(opts, is_wayland(), args.debug_keyboard, args.debug_rendering, args.debug_font_fallback) + set_options(opts, is_wayland(), args.debug_rendering, args.debug_font_fallback) try: set_font_family(opts, debug_font_matching=args.debug_font_fallback) _run_app(opts, args, bad_lines) diff --git a/kitty/state.c b/kitty/state.c index d0930735c..1d9498ff2 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -684,8 +684,8 @@ PYWRAP0(get_options) { PYWRAP1(set_options) { PyObject *opts; - int is_wayland = 0, debug_keyboard = 0, debug_rendering = 0, debug_font_fallback = 0; - PA("O|pppp", &opts, &is_wayland, &debug_keyboard, &debug_rendering, &debug_font_fallback); + int is_wayland = 0, debug_rendering = 0, debug_font_fallback = 0; + PA("O|pppp", &opts, &is_wayland, &debug_rendering, &debug_font_fallback); if (opts == Py_None) { Py_CLEAR(options_object); Py_RETURN_NONE; @@ -695,7 +695,6 @@ PYWRAP1(set_options) { global_state.has_render_frames = true; #endif if (global_state.is_wayland) global_state.has_render_frames = true; - global_state.debug_keyboard = debug_keyboard ? true : false; global_state.debug_rendering = debug_rendering ? true : false; global_state.debug_font_fallback = debug_font_fallback ? true : false; if (!convert_opts_from_python_opts(opts, &global_state.opts)) return NULL; @@ -822,11 +821,6 @@ PYWRAP1(focus_os_window) { Py_RETURN_FALSE; } -PYWRAP0(toggle_secure_input) { - toggle_secure_input(); - Py_RETURN_NONE; -} - PYWRAP1(set_titlebar_color) { id_type os_window_id; unsigned int color; @@ -1272,7 +1266,6 @@ static PyMethodDef module_methods[] = { MW(current_application_quit_request, METH_NOARGS), MW(set_titlebar_color, METH_VARARGS), MW(focus_os_window, METH_VARARGS), - MW(toggle_secure_input, METH_NOARGS), MW(mark_tab_bar_dirty, METH_O), MW(change_background_opacity, METH_VARARGS), MW(background_opacity_of, METH_O), diff --git a/kitty/state.h b/kitty/state.h index 57a0c5f72..db88486e2 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -224,7 +224,7 @@ typedef struct { OSWindow *callback_os_window; bool is_wayland; bool has_render_frames; - bool debug_keyboard, debug_rendering, debug_font_fallback; + bool debug_rendering, debug_font_fallback; bool has_pending_resizes, has_pending_closes; bool in_sequence_mode; bool check_for_active_animated_images; @@ -262,7 +262,6 @@ void hide_mouse(OSWindow *w); bool is_mouse_hidden(OSWindow *w); void destroy_os_window(OSWindow *w); void focus_os_window(OSWindow *w, bool also_raise); -void toggle_secure_input(void); void set_os_window_title(OSWindow *w, const char *title); OSWindow* os_window_for_kitty_window(id_type); OSWindow* add_os_window(void);