From be1000669f1072d3b126339e3ca6e6d5106a63ac Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 17 Jun 2024 22:45:34 -0700 Subject: [PATCH] Prevent Fn key from scrolling to the bottom When the Fn key is pressed it should not cause us to scroll to the bottom of the scrollback. This is because Fn may be used to access movement keys (e.g. on a MacBook keyboard, Fn+Up = Page Up). Most keyboards do not expose Fn to the operating system as a separate key event, but there are two known exceptions: Macs running Linux (generates XF86Fn) and some ThinkPads (generates XF86WakeUp). Ignore both key events when deciding whether to scroll to the bottom. For consistency, do the same when deciding whether key events should hide the mouse. --- kitty/keys.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/kitty/keys.c b/kitty/keys.c index f2f793d720..dfab1aa424 100644 --- a/kitty/keys.c +++ b/kitty/keys.c @@ -11,6 +11,10 @@ #include "glfw-wrapper.h" #include +#ifndef __APPLE__ +#include +#endif + // python KeyEvent object {{{ typedef struct { PyObject_HEAD @@ -44,6 +48,19 @@ is_modifier_key(const uint32_t key) { END_ALLOW_CASE_RANGE } +static bool +is_no_action_key(const uint32_t key, const uint32_t native_key) { + switch (native_key) { +#ifndef __APPLE__ + case XKB_KEY_XF86Fn: + case XKB_KEY_XF86WakeUp: + return true; +#endif + default: + return is_modifier_key(key); + } +} + static void dealloc(PyKeyEvent* self) { Py_CLEAR(self->key); Py_CLEAR(self->shifted_key); Py_CLEAR(self->alternate_key); @@ -163,7 +180,7 @@ on_key_input(GLFWkeyevent *ev) { } } if (!w) { debug("no active window, ignoring\n"); return; } - if (OPT(mouse_hide_wait) < 0 && !is_modifier_key(key)) hide_mouse(global_state.callback_os_window); + if (OPT(mouse_hide_wait) < 0 && !is_no_action_key(key, native_key)) hide_mouse(global_state.callback_os_window); Screen *screen = w->render_data.screen; id_type active_window_id = w->id; @@ -227,7 +244,7 @@ on_key_input(GLFWkeyevent *ev) { debug("discarding repeat key event as DECARM is off\n"); return; } - if (screen->scrolled_by && action == GLFW_PRESS && !is_modifier_key(key)) { + if (screen->scrolled_by && action == GLFW_PRESS && !is_no_action_key(key, native_key)) { screen_history_scroll(screen, SCROLL_FULL, false); // scroll back to bottom } char encoded_key[KEY_BUFFER_SIZE] = {0};