Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When moving mouse over inactive Kitty windows, text is selected as if the mouse button is pressed #7381

Closed
juztin opened this issue Apr 23, 2024 · 15 comments
Labels

Comments

@juztin
Copy link

juztin commented Apr 23, 2024

While having multiple Kitty sessions/windows open (some with single sessions, some with multiple tabs—doesn't seem to matter) when moving the mouse across the screen, over inactive Kitty windows, it begins to select all text in relation to the mouse (as if I've pressed the mouse button down). The window remains inactive, but text is selected. I have to click/activate the windows to stop it _(depending on where/how the mouse is moving, it will sometimes scroll select until the mouse is moved completely out, or the window is activated and clicked to unselect.

Steps to reproduce the behavior:

  1. Open multiple Kitty windows
  2. Open multiple tabs within the Kitty window(s) (sometimes this triggers it, sometimes not)
  3. Perform an ls, or anything that display text within the sessions
  4. Move mouse over all Kitty windows, some will randomly begin selecting text within the session as the mouse is moved over the inactive window

Screenshots
If applicable, add screenshots to help explain your problem.

Environment details

kitty 0.33.1 created by Kovid Goyal
Linux x 6.8.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 17 Apr 2024 15:20:28 +0000 x86_64
EndeavourOS Linux 6.8.7-arch1-1 (/dev/tty)

DISTRIB_ID="EndeavourOS"
DISTRIB_RELEASE="rolling"
DISTRIB_DESCRIPTION="EndeavourOS Linux"
DISTRIB_CODENAME="rolling"
Running under: Wayland
Frozen: False
Paths:
  kitty: /usr/bin/kitty
  base dir: /usr/lib/kitty
  extensions dir: /usr/lib/kitty/kitty
  system shell: /usr/bin/zsh
Loaded config files:
  /home/x/.config/kitty/kitty.conf

Config options different from defaults:
Changed shortcuts:
	kitty_mod+t →  launch --cwd=current --type=tab
Colors:
	background           #001e26   
	color0               #002731   
	color1               #d01b24   
	color10              #465a61   
	color11              #52676f   
	color12              #708183   
	color13              #5856b9   
	color14              #81908f   
	color15              #fcf4dc   
	color2               #728905   
	color3               #a57705   
	color4               #2075c7   
	color5               #c61b6e   
	color6               #259185   
	color7               #e9e2cb   
	color8               #465a61   
	color9               #bd3612   
	cursor               #708183   
	foreground           #708183   
	selection_background #9aeaca   
	selection_foreground #001e26   

Important environment variables seen by the kitty process:
	PATH                                /home/x/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
	LANG                                en_US.UTF-8
	EDITOR                              nano
	SHELL                               /usr/bin/zsh
	DISPLAY                             :1
	WAYLAND_DISPLAY                     wayland-0
	USER                                x
	LC_ADDRESS                          en_US.UTF-8
	LC_IDENTIFICATION                   en_US.UTF-8
	LC_MEASUREMENT                      en_US.UTF-8
	LC_MONETARY                         en_US.UTF-8
	LC_NAME                             en_US.UTF-8
	LC_NUMERIC                          en_US.UTF-8
	LC_PAPER                            en_US.UTF-8
	LC_TELEPHONE                        en_US.UTF-8
	LC_TIME                             en_US.UTF-8
	XDG_CONFIG_DIRS                     /home/x/.config/kdedefaults:/etc/xdg
	XDG_CURRENT_DESKTOP                 KDE
	XDG_MENU_PREFIX                     plasma-
	XDG_RUNTIME_DIR                     /run/user/2222
	XDG_SEAT                            seat0
	XDG_SEAT_PATH                       /org/freedesktop/DisplayManager/Seat0
	XDG_SESSION_CLASS                   user
	XDG_SESSION_DESKTOP                 KDE
	XDG_SESSION_ID                      2
	XDG_SESSION_PATH                    /org/freedesktop/DisplayManager/Session1
	XDG_SESSION_TYPE                    wayland
	XDG_VTNR                            1
d
@juztin juztin added the bug label Apr 23, 2024
@kovidgoyal
Copy link
Owner

Does not reproduce for me with those steps using current kitty version
0.34.1. Since you are using wayland and there were lots of improvements
to wayland support I suggest updating kitty.

@drammelt
Copy link

drammelt commented Jul 7, 2024

This happens still in kitty 0.35.2

Only happens in wayland sessions. I can reproduce consistently...

Open kitty with 3 internal windows.
Open Firefox on second monitor.
Select text in firefox.
Click on bottom right window in kitty.
Click on top window in kitty.
Move mouse to bottom right window, text will be selected in bottom right window with no mouse click.

@kovidgoyal
Copy link
Owner

Still doesnt repro for me with those steps. And wayland is meaningless, what actual compositor.

@drammelt
Copy link

drammelt commented Jul 8, 2024

Sorry here is the debug info

kitty 0.35.2 created by Kovid Goyal
Linux x 6.6.37-cachy-x86-64-v3 #2 SMP PREEMPT_DYNAMIC x x86_64

This is x (Linux x86_64 6.6.37-cachy-x86-64-v3) 13:3
[input.txt](https://github.com/user-attachments/files/16121771/input.txt)
0:54

DISTRIB_ID="Gentoo"
Running under: Wayland (kwin 6.1.2) missing: single_pixel_buffer
OpenGL: '3.1.0 NVIDIA 555.58.02' Detected version: 3.1
Frozen: False
Paths:
  kitty: /usr/bin/kitty
  base dir: /usr/lib64/kitty
  extensions dir: /usr/lib64/kitty/kitty
  system shell: /bin/zsh
Loaded config files:
  /home/daniel/.config/kitty/kitty.conf

Config options different from defaults:
background_blur               1
background_opacity            0.96
bold_font                     MonoLisa Bold
bold_italic_font              MonoLisa Bold Italic
enable_audio_bell             False
font_family                   MonoLisa Regular
font_features:
{'MonoLisa-Regular': ('+zero', '+ss04', '+ss07', '+ss08', '+ss09'),
 'MonoLisa-RegularItalic': ('+zero', '+ss04', '+ss07', '+ss08', '+ss09')}
font_size                     14.0
initial_window_height         (45, 'cells')
initial_window_width          (140, 'cells')
italic_font                   MonoLisa Regular Italic
remember_window_size          False
scrollback_pager              ['less', '--RAW-CONTROL-CHARS', '+INPUT_LINE_NUMBER']
scrollback_pager_history_size 1073741824
tab_bar_style                 powerline
tab_powerline_style           slanted

@drammelt
Copy link

drammelt commented Jul 8, 2024

input.txt

This is the input log, first click is clicking in the top kitty window, after last click text selection is enabled in the last (bottom right window). Also closing kitty internal windows does not clear selection. It looks like kitty thinks the left button is being held down.

@kovidgoyal
Copy link
Owner

Doesnt repro for me in kde wayland. Your input log ends with

[22.122] Release mouse_button: 0 mods: none handled as drag end
[22.622] MouseEvent matched action: mouse_handle_click
[22.622] on_mouse_input: click button: left mods: none grabbed: 0 handled_in_kitty: 1

which shows that kitty thinks the button was released and the drag (aka selection) finished.

@drammelt
Copy link

drammelt commented Jul 8, 2024

Do have any tips on how to start tracking down what is going on?

I tried various versions back to 0.21.0 and it reproduces consistently. The other user from (#7382) was using KDE 5.27.5 and 5.27.11 with wayland, I am using KDE 6.1.2 with wayland. There is almost zero likely hood we have wayland versions in common as debian is far out of date.

The issue only happens in Kitty, I have never experienced the issue with any other application or terminal (Konsole/Alacritty).

@kovidgoyal
Copy link
Owner

All the mouse related code is in mouse.c and wayland code is in wl_init.c and wl_window.c. Start with mouse.c and some prints see whats going on.

@drammelt
Copy link

drammelt commented Jul 8, 2024

Thanks, I think I found it. It is when the mouse comes back from the external focus. The click event in the window registers a click but never releases. Subsequent clicks register release but the original one has not.

It runs this code when mouse re-enters window

    switch((MouseSelectionType)code) {
        case MOUSE_SELECTION_NORMAL:
            screen_start_selection(screen, w->mouse_pos.cell_x, w->mouse_pos.cell_y, w->mouse_pos.in_left_half_of_cell, false, EXTEND_CELL);
            break;

But never runs the deselect code

        else if (action == GLFW_RELEASE && button == global_state.active_drag_button) {
            w = window_for_id(global_state.active_drag_in_window);
            if (w) {
                end_drag(w);
                printf("handled as drag end\n");
                dispatch_possible_click(w, button, modifiers);
                return;
            }
        }

@drammelt
Copy link

drammelt commented Jul 8, 2024

input2.txt

This is the input log with debug output, I have added comments to clarify what I am doing. You can see the "handled as drag end" is missing when clicking back in the window. I am not well versed in C, but let me know if you need more and I can give it a go.

@kovidgoyal
Copy link
Owner

I dont follow in your first comment you say no release event is
delivered leaving a persistent selection. In your input2.txt log you
have marked the release event as bogus. What's bogus about it? Are you
saying you didnt actually release the mouse? Or that the release event
didnt end the selection? Or something else?

And are you doing the following:

  1. Start a drag in kitty to select
  2. move mouse to firefox
  3. release pressed button
  4. selection continues to update in kitty

because I cannot replicate. Do you have some non-standard kwin settings?
focus follows mouse perhaps? Because that would cause it. If you release
the mouse after focus has switched to firefox then kitty wont get the
release event. This is a bug in kwin's focus follows mouse
implementation if so. Focus should not follow mouse when a drag is
active in the focused window.

@juztin
Copy link
Author

juztin commented Jul 8, 2024

This happens still in kitty 0.35.2

Only happens in wayland sessions. I can reproduce consistently...

Open kitty with 3 internal windows. Open Firefox on second monitor. Select text in firefox. Click on bottom right window in kitty. Click on top window in kitty. Move mouse to bottom right window, text will be selected in bottom right window with no mouse click.

I'm also still seeing the same thing as the original issue, but now on 0.35.2

arch: 6.9.7-arch1-1
compositor: kwin_wayland driver: X: loaded: amdgpu unloaded: modesetting

kwayland 6.1.1-1
kwayland5 5.116.0-1
qt5-wayland 5.15.14+kde+r58-1
qt6-wayland 6.7.2-1
wayland 1.23.0-1
wayland-utils 1.2.0-1
xorg-xwayland 24.1.0-1

@drammelt
Copy link

drammelt commented Jul 8, 2024

I dont follow in your first comment you say no release event is delivered leaving a persistent selection. In your input2.txt log you have marked the release event as bogus. What's bogus about it? Are you saying you didnt actually release the mouse? Or that the release event didnt end the selection? Or something else?
I don't see how that is unclear, check every other mouse release they call the function and run
printf("handled as drag end\n");
The mouse click that comes back into the window never calls this, it is an orphaned select.

Here maybe this helps?

+++++ SELECT START +++++on_mouse_input: press button: left mods: none grabbed: 0 handled_in_kitty: 1
...
Release mouse_button: 0 mods: none grabbed: 0
on_mouse_input: release button: left mods: none grabbed: 0 handled_in_kitty: 0

This code

mouse_selection(Window *w, int code, int button) {
...
    switch((MouseSelectionType)code) {
        case MOUSE_SELECTION_NORMAL:
            printf("+++++ SELECT START +++++");
            screen_start_selection(screen, w->mouse_pos.cell_x, w->mouse_pos.cell_y, w->mouse_pos.in_left_half_of_cell, false, EXTEND_CELL);
            break;

This code is never called....

mouse_event(const int button, int modifiers, int action) {
...
   if (global_state.active_drag_in_window) {
        printf("+++++ SELECT END? +++++\n");
        if (button == -1) {  // drag move
...
        else if (action == GLFW_RELEASE && button == global_state.active_drag_button) {
            w = window_for_id(global_state.active_drag_in_window);
            if (w) {
                end_drag(w);
                printf("handled as drag end\n");
                dispatch_possible_click(w, button, modifiers);
                return;

I dont see how this can be unclear the message from
printf("handled as drag end\n");
Is not in the logs, No other message from the mouse even function is in the logs, it never happened. Its a bogus message because kitty never handles the event. I am guessing that message comes from GLFW since the text is not in kitty source.

And are you doing the following:

  1. Open kitty, Ctrl-Alt-Enter 3 times to get 3 windows
  2. Click in bottom right window in kitty, type ls or something to display some text so selection is obvious.
  3. Move mouse to Firefox on second monitor, select some text. Release mouse
  4. Move mouse back to bottom right kitty window.
  5. Click mouse.
  6. Move mouse to top kitty window.
  7. Click mouse.
  8. Move mouse back to bottom right kitty window.

because I cannot replicate. Do you have some non-standard kwin settings? focus follows mouse perhaps? Because that would cause it. If you release the mouse after focus has switched to firefox then kitty wont get the release event. This is a bug in kwin's focus follows mouse implementation if so. Focus should not follow mouse when a drag is active in the focused window.

No non standard settings, its actually a fresh install. This also happened for me on KDE 5.27.11 on Gentoo and I can repo it on Debian 12 as well using stock settings.

EDIT:

If you release the mouse after focus has switched to Firefox then kitty wont get the release event.

Sorry I missed this point. Mouse is released inside kitty window before moving to Firefox. Mouse is released in Firefox window before moving back to kitty. There is no weird behaviour being performed. Just moving back to kitty and clicking the window again.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Jul 9, 2024 via email

@drammelt
Copy link

drammelt commented Jul 9, 2024

If I had to guess, I would say it's happening in glfw.c at line 522
where there is a workaround precisely for kwin. Comment that out and see
if it solves your issue.

Fixed by removing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants