Skip to content

Commit

Permalink
Prevent Fn key from scrolling to the bottom
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pcc committed Jun 18, 2024
1 parent 48f053b commit be10006
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions kitty/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include "glfw-wrapper.h"
#include <structmember.h>

#ifndef __APPLE__
#include <xkbcommon/xkbcommon.h>
#endif

// python KeyEvent object {{{
typedef struct {
PyObject_HEAD
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit be10006

Please sign in to comment.