kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.11k stars 972 forks source link

Bluetooth mouse wheel scrolling on Mac only works when Kitty's window is unfocused #5206

Closed moniquelive closed 2 years ago

moniquelive commented 2 years ago

Mouse scrolling on Mac only works when Kitty's window is unfocused On macOS 12.4 and Kitty 0.25.2, bluetooth mouse scrolling only works if I click away from Kitty's window. Using the built-in trackpad works both with and without focus. Macbook Pro 14" 2021 (M1).

To Reproduce Steps to reproduce the behavior:

  1. Have enough content to be able to scroll
  2. Use bt mouse scroll wheel to try to scroll. Won't work.
  3. When kitty's window is unfocused works as expected.
  4. Using built-in trackpad works both when kitty's window is or isn't in focus.

Environment details

kitty 0.25.2 created by Kovid Goyal
Darwin armrama.local 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000 arm64
ProductName:    macOS ProductVersion:   12.4 BuildVersion:  21F79
Frozen: True
Paths:
  kitty: /Applications/kitty.app/Contents/MacOS/kitty
  base dir: /Applications/kitty.app/Contents/Resources/kitty
  extensions dir: /Applications/kitty.app/Contents/Resources/Python/lib/kitty-extensions
  system shell: /bin/zsh
Loaded config files:
  /Users/cyber/.config/kitty/kitty.conf

Config options different from defaults:
allow_remote_control               y
background_opacity                 0.85
bell_on_tab                        πŸ””
clipboard_control                  ('write-clipboard', 'write-primary')
close_on_child_death               True
confirm_os_window_close            0
copy_on_select                     a1
enable_audio_bell                  False
enabled_layouts                    ['splits']
font_family                        emoji-amperama
font_size                          16.0
inactive_tab_font_style            (False, True)
listen_on                          unix:/tmp/mykitty
macos_option_as_alt                3
macos_quit_when_last_window_closed True
mouse_hide_wait                    3.0
scrollback_pager                   ['/Users/cyber/bin/nvim-scrollback.sh', 'INPUT_LINE_NUMBER', 'CURSOR_LINE', 'CURSOR_COLUMN']
tab_activity_symbol                Β·
tab_bar_align                      center
tab_bar_style                      powerline
tab_title_template                 {title}
url_prefixes                       ('http', 'https', 'file', 'ftp')
visual_bell_duration               0.1
Added shortcuts:
    f1 β†’ launch --allow-remote-control kitty +kitten broadcast
    opt+- β†’ launch --location=hsplit --cwd=current
    opt+\ β†’ launch --location=vsplit --cwd=current
    opt+h β†’ neighboring_window left
    opt+j β†’ neighboring_window down
    opt+k β†’ neighboring_window up
    opt+l β†’ neighboring_window right
    opt+n β†’ new_tab
    shift+opt+, β†’ set_tab_title
    shift+opt+0 β†’ goto_tab 0
    shift+opt+1 β†’ goto_tab 1
    shift+opt+2 β†’ goto_tab 2
    shift+opt+3 β†’ goto_tab 3
    shift+opt+4 β†’ goto_tab 4
    shift+opt+5 β†’ goto_tab 5
    shift+opt+6 β†’ goto_tab 6
    shift+opt+7 β†’ goto_tab 7
    shift+opt+8 β†’ goto_tab 8
    shift+opt+9 β†’ goto_tab 9
    shift+opt+h β†’ resize_window wider
    shift+opt+j β†’ resize_window taller
    shift+opt+k β†’ resize_window shorter
    shift+opt+l β†’ resize_window narrower
    shift+opt+n β†’ next_tab
    shift+opt+p β†’ previous_tab
    cmd+s β†’ paste_from_buffer a1
Changed shortcuts:
    ctrl+shift+e β†’ kitten hints
Colors:
    active_tab_background              #b16185   
    active_tab_foreground              #ebdbb2   
    background                         #272727   
    color0                             #272727   
    color1                             #cc231c   
    color10                            #b8ba25   
    color11                            #fabc2e   
    color12                            #83a597   
    color13                            #d3859a   
    color14                            #8ec07b   
    color15                            #ebdbb2   
    color2                             #989719   
    color3                             #d79920   
    color4                             #448488   
    color5                             #b16185   
    color6                             #689d69   
    color7                             #a89983   
    color8                             #928373   
    color9                             #fb4833   
    foreground                         #ebdbb2   
    inactive_tab_background            #272727   
    inactive_tab_foreground            #ebdbb2   
    selection_background               #ebdbb2   
    selection_foreground               #655b53   
    url_color                          #d65c0d   

Important environment variables seen by the kitty process:
    PATH                                /Applications/kitty.app/Contents/MacOS:/usr/bin:/bin:/usr/sbin:/sbin
    LANG                                en_US.UTF-8
    SHELL                               /bin/zsh
    USER                                cyber

Additional context Trying to reproduce the problem with kitty --config NONE has the same behavior.

kovidgoyal commented 2 years ago

Run with --debug-input and see if events are being delivered to kitty by the system in that case. If not then there isnt anything kitty can do. If yes, then post the --debug-input log and I will take a look.

moniquelive commented 2 years ago

Running with --debug-input outputs nothing when I turn the wheel, in both situations (with or without focus). But scrolling behaves the same as described (works when unfocused, doesn't work when focused).

moniquelive commented 2 years ago

@kovidgoyal do you have a minimal glfw code I could tinker with to investigate this behavior? maybe there's a missing flag somewhere to enable these events.

kovidgoyal commented 2 years ago

On Fri, Jun 17, 2022 at 09:28:56AM -0700, Cyber Oliveira wrote:

@kovidgoyal do you have a minimal glfw code I could tinker with to investigate this behavior? maybe there's a missing flag somewhere to enable these events.

Ah, right debug input does not debug wheel events since I've never hear dof issues with them only. You dont need minimal glfw. The relevant code in glfw/cocoa_window.m look at scrollWheel() it should be trivial to ad a print there to check if the events are coming in from the system.

kovidgoyal commented 2 years ago

And another place to look is the scroll_event() function in kitty/mouse.c (where I have now added debug output for scroll events)

moniquelive commented 2 years ago

Thanks! That helped a lot! Now I'm trying to compile locally and this is happening:

python3 setup.py build \
  --extra-include-dirs=/opt/homebrew/Cellar/librsync/2.3.2/include \
  --extra-include-dirs=/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/include/python3.9 \
  --extra-library-dirs=/opt/homebrew/Cellar/librsync/2.3.2/lib \
  --extra-library-dirs=/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib  

all goes well but...

$ ./kitty/launcher/kitty
dyld[16026]: Library not loaded: @rpath/Python3.framework/Versions/3.8/Python3
  Referenced from: /Users/cyber/prj/c/kitty/kitty/launcher/kitty.app/Contents/MacOS/kitty
  Reason: tried: '/Library/Frameworks/Python3.framework/Versions/3.8/Python3' (no such file), '/System/Library/Frameworks/Python3.framework/Versions/3.8/Python3' (no such file)
[1]    16026 abort      ./kitty/launcher/kitty

How do I make it load the homebrew python instead of the non-existing system framework?


Answering myself:

❯ /opt/homebrew/Cellar/python@3.9/3.9.13_1/bin/python3 setup.py build \
  --extra-include-dirs=/opt/homebrew/Cellar/librsync/2.3.2/include \
  --extra-include-dirs=/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/include/python3.9 \
  --extra-library-dirs=/opt/homebrew/Cellar/librsync/2.3.2/lib \
  --extra-library-dirs=/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib
kovidgoyal commented 2 years ago

Dont do any of that just run

make clean make debug ./kitty/launcher/kitty

moniquelive commented 2 years ago

It can't find librsync if I use make... :(

kovidgoyal commented 2 years ago

Then just

python setup.py build -I /path/to/folder/with/librsync.h --debug
moniquelive commented 2 years ago

Now the results:

I believe you changed something else when you added the debug log, because now it's working perfectly with the scroll wheel. I double checked, my system version 0.25.2 still no scroll when focused, but the custom debug build scrolls both with and without focus!

kovidgoyal commented 2 years ago

Hah well good enough then

moniquelive commented 2 years ago

Maybe your release process somehow removes the code you added above, because the current homebrew version of kitty (0.26.2) won't scroll.. :(

kovidgoyal commented 2 years ago

It doesnt

moniquelive commented 1 year ago

Finally (!!!) Giving some closure to this matter. After reading an iterm2 issue the mistery was solved. Logitech's MX Master mouse scroll wheel (and any other custom button) won't work if secure keyboard is enabled.

In case of Kitty it's solved by pressing alt+cmd+s . It gets persisted between runs.

I can finally sleep in peace πŸ™πŸ»

Leaving this here for the frustrated from the future.