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

window focus issue #3267

Closed
raffaeleflorio opened this issue Oct 31, 2017 · 38 comments · May be fixed by QubesOS/qubes-gui-agent-linux#171
Closed

window focus issue #3267

raffaeleflorio opened this issue Oct 31, 2017 · 38 comments · May be fixed by QubesOS/qubes-gui-agent-linux#171
Labels
affects-4.1 This issue affects Qubes OS 4.1. C: gui-virtualization diagnosed Technical diagnosis has been performed (see issue comments). eol-4.1 Closed because Qubes 4.1 has reached end-of-life (EOL) fixed-by-wayland Bugs that would not appear if Qubes OS used Wayland instead of X11 P: major Priority: major. Between "default" and "critical" in severity. pr submitted A pull request has been submitted for this issue. T: bug Type: bug report. A problem or defect resulting in unintended behavior in something that exists.

Comments

@raffaeleflorio
Copy link

raffaeleflorio commented Oct 31, 2017

Qubes OS version:

R3.2

Affected TemplateVMs:

fedora-25


Steps to reproduce the behavior:

Every program should be opened in the same qube.

A real world effect is reached in this way:

  1. Open two terminals.
  2. Hook one terminal to the left, and one to the right. They should be on the same workspace only for comfort.
  3. Go to another workspace.
  4. Open some webpage and maximize it.
  5. Remember a link's position.
  6. Focus the terminal that doesn't cover the link position.
  7. Focus the browser.
  8. Go to the terminal's workspace.
  9. Click on link's position in the terminal that covers it.
  10. In the webpage the link is clicked.

UPDATE 1
With xev:

  1. Open two terminals.
  2. Hook one terminal to the left, and one to the right. They should be on the same workspace only for comfort.
  3. Open xev with one terminal.
  4. Move xev in another workspace.
  5. Maximize xev.
  6. Move to the terminal's workspace.
  7. Move the mouse on the terminals.
  8. Xev receives input.

UPDATE 2
Stolen keyboard input:

  1. Open two terminals.
  2. Hook one terminal to the left, and one to the right. They should be on the same workspace only for comfort.
  3. Open gnome-terminal (however it's not related to gnome-terminal) and echo an URL. Remember URL position.
  4. Move gnome-terminal to another workspace.
  5. Move to the two terminals workspace.
  6. Focus the terminal that doesn't cover the URL (the right one, if ltr).
  7. Focus gnome-terminal.
  8. Move to the two terminals workspace.
  9. CTRL+CLICK on the URL position on the unfocused terminal.
  10. The URL is opened.

UPDATE 3
Stolen keyboard input can be reproduced also with browser (e.g. CTRL+CLICK on a link).

Actually a previous focused program (like xev or the browser) receive input iff an unfocused window and the former overlap. Furthermore input is stolen until a click happens on the unfocused window.

For example, in the first case, if the browser and the unfocused terminal overlap, the click on the terminal is stolen by the browser. After that the browser cannot steal more.

Expected behavior:

Unfocused window doesn't have to get input.

Actual behavior:

Unfocused window get input.

General notes:

Thanks to secure gui, It affects only programs opened in the same VM.
However it isn't related to any particular window or qube.

This issue isn't related to any particular windows order.

UPDATE 4
I think that it's related to Xorg


Related issues:

@andrewdavidwong
Copy link
Member

This sounds like a regression of #738. It may be related to #1455.

@e6lk7dqzm83p
Copy link

I have this issue in R4.14.

@improvethings
Copy link

I think this might be a dual monitor issue. It got to a point where even on a reboot I couldn't click on the windows of one specific (debian 9) AppVM. I've turned off my 2nd monitor (in hardware, and in "Displays") and upon reboot, I can resume window focus as expected.

@e6lk7dqzm83p
Copy link

@improvethings I have this with only one monitor enabled (either my laptop scree or an external monitor only).

@donob4n
Copy link

donob4n commented Jan 31, 2019

@improvethings @e6lk7dqzm83p try generic modesetting driver if you still experimenting the problem.

@ptitdoc
Copy link

ptitdoc commented Feb 7, 2019

Moving part of the troubleshooting performed in #3267:

  • X11 clients such as chromium that keep the focus even when clicking on another windows. This behavior is probably related even if it is not blocking. The consequence is that it makes middle-click-to-paste unusable in these circumstance because the input apparently stays on the chromium window (but i wonder if it is mouse input or keyboard input which is locked).

To reproduce this bug in chromium:
1/ Open google in chromium
2/ Open a terminal and place it over a link in google
3/ Click inside goggle search bar to give focus to chromium
4/ Click on the terminal around the chromium link position, it will open the link instead of giving focus to the terminal.
For this bug to be visible, you also need to have "Raise windows on click" disabled in your windows manager (check focus configuration for instance in xfce>Settings>Windows Manager>Focus).

This bug does not affect firefox, which as shown below, uses a different Input Model.

I'm trying to review the potential use case that are missed in QubesOS related to the ICCCM windows manager convention and verify of buggy cases are realted to a specific input focus model :
https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.2.4
https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7

@ptitdoc
Copy link

ptitdoc commented Feb 7, 2019

Here are logs when testing with Chromium (which have focus problems) and Firefox (which does not have focus problems).
Chromium is apparently using what they call a Passive Input Model (InputHint 1 and TakeFocus 0). When firefox is using a Locally Active Input Model (InputHint 1 and TakeFocus 1).

# Click on chromium input box
Feb 07 11:46:57 untrusted qubes-gui[495]: Starting handle_focus for 0x2c00036 key.type:9 key.mode:0 # FocusIn
Feb 07 11:46:57 untrusted qubes-gui[495]: Window 0x2c00036 has inputhit set to 1 and takefocus set to 0 # Passive Input Model
Feb 07 11:46:57 untrusted qubes-gui[495]: FocusIn actions for 0x2c00036 # Chromium Tab
Feb 07 11:46:57 untrusted qubes-gui[495]: 0x2c00036 raised
Feb 07 11:46:57 untrusted qubes-gui[495]: sent XSetInputFocus for win 0x2c00036 # Set Input Focus

# Click on the terminal
Feb 07 11:48:04 untrusted qubes-gui[495]: Starting handle_focus for 0x2c00036 key.type:10 key.mode:0 # FocusOut
Feb 07 11:48:04 untrusted qubes-gui[495]: Window 0x2c00036 has inputhit set to 1 and takefocus set to 0 # Passive Input Model
Feb 07 11:48:04 untrusted qubes-gui[495]: FocusOut actions for 0x2c00036 # Chromium Tab
Feb 07 11:48:04 untrusted qubes-gui[495]: sent XSetInputFocus for win 0x00
Feb 07 11:48:04 untrusted qubes-gui[495]: 0x2c00036 lost focus

Feb 07 11:48:04 untrusted qubes-gui[495]: received message type 142 for 0x0
Feb 07 11:48:04 untrusted qubes-gui[495]: received message type 128 for 0xc033b9
Feb 07 11:48:04 untrusted qubes-gui[495]: Starting handle_focus for 0xc033b9 key.type:9 key.mode:0 # FocusIn
Feb 07 11:48:04 untrusted qubes-gui[495]: Window 0xc033b9 has inputhit set to 1 and takefocus set to 1 # Locally Input Model
Feb 07 11:48:04 untrusted qubes-gui[495]: FocusIn actions for 0xc033b9 # Is it terminal ?
Feb 07 11:48:04 untrusted qubes-gui[495]: 0xc033b9 raised
Feb 07 11:48:04 untrusted qubes-gui[495]: sent XSetInputFocus for win 0xc033b9
Feb 07 11:48:04 untrusted qubes-gui[495]: WM_TAKE_FOCUS sent for 0xc033b9
Feb 07 11:48:04 untrusted qubes-gui[495]: received message type 125 for 0xc033b9
Feb 07 11:48:04 untrusted qubes-gui[495]: send buttonevent, win 0xc033b9 type=4 button=1 # Then send button event to 0xc033b9. It is the terminal. Why is chromium receiving it?
Feb 07 11:48:04 untrusted qubes-gui[495]: handle configure event 0xc033b9 w=814 h=485 ovr=0
Feb 07 11:48:04 untrusted qubes-gui[495]: handle property CHROMIUM_TIMESTAMP for window 0x2c00005
Feb 07 11:48:04 untrusted qubes-gui[495]: handle property CHROMIUM_TIMESTAMP for window 0x2c00005
Feb 07 11:48:04 untrusted qubes-gui[495]: handle configure event 0x2c00036 w=1920 h=1145 ovr=0
Feb 07 11:48:04 untrusted qubes-gui[495]: UNMAP for window 0x2c00038
Feb 07 11:48:04 untrusted qubes-gui[495]: handle property CHROMIUM_TIMESTAMP for window 0x2c00005
Feb 07 11:48:04 untrusted qubes-gui[495]: handle property _NET_WM_STATE for window 0x2c00038
Feb 07 11:48:04 untrusted qubes-gui[495]: received message type 125 for 0xc033b9
Feb 07 11:48:04 untrusted qubes-gui[495]: send buttonevent, win 0xc033b9 type=5 button=1
Feb 07 11:48:04 untrusted qubes-gui[495]: handle property CHROMIUM_TIMESTAMP for window 0x2c00005
Feb 07 11:48:04 untrusted qubes-gui[495]: handle property CHROMIUM_TIMESTAMP for window 0x2c00005
Feb 07 11:48:26 untrusted qubes-gui[495]: received message type 126 for 0xc033b9
Feb 07 11:48:26 untrusted qubes-gui[495]: handle property CHROMIUM_TIMESTAMP for window 0x2c00005
Feb 07 11:48:26 untrusted qubes-gui[495]: received message type 126 for 0xc033b9
Feb 07 11:48:26 untrusted qubes-gui[495]: handle property CHROMIUM_TIMESTAMP for window 0x2c00005
Feb 07 11:48:26 untrusted qubes-gui[495]: handle property CHROMIUM_TIMESTAMP for window 0x2c00005
Feb 07 11:48:26 untrusted qubes-gui[495]: received message type 126 for 0xc033b9
Feb 07 11:48:26 untrusted qubes-gui[495]: handle property CHROMIUM_TIMESTAMP for window 0x2c00005

# Click on FF inputtext
Feb 07 11:49:10 untrusted qubes-gui[495]: Create for 0x160006f class 0x1
Feb 07 11:49:10 untrusted qubes-gui[495]: got net_wm_name=Firefox
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property WM_PROTOCOLS for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: Protocol take_focus supported for Window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property WM_NORMAL_HINTS for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property WM_CLIENT_MACHINE for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property WM_LOCALE_NAME for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property _NET_WM_PID for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property WM_CLIENT_LEADER for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property _NET_WM_USER_TIME_WINDOW for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property _NET_WM_USER_TIME for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property _NET_WM_SYNC_REQUEST_COUNTER for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property _NET_WM_WINDOW_TYPE for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property WM_TRANSIENT_FOR for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property _NET_WM_OPAQUE_REGION for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property XdndAware for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property _NET_WM_BYPASS_COMPOSITOR for window 0x160006f
Feb 07 11:49:10 untrusted qubes-gui[495]: Create for 0x1600079 class 0x1
Feb 07 11:49:10 untrusted qubes-gui[495]: got net_wm_name=Firefox
Feb 07 11:49:10 untrusted qubes-gui[495]: Protocol take_focus supported for Window 0x1600079
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property WM_NORMAL_HINTS for window 0x1600079
Feb 07 11:49:10 untrusted qubes-gui[495]: handle configure event 0x1600079 w=132 h=47 ovr=1
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property _NET_WM_OPAQUE_REGION for window 0x1600079
Feb 07 11:49:10 untrusted qubes-gui[495]: handle message _NET_WM_STATE to window 0x1600079
Feb 07 11:49:10 untrusted qubes-gui[495]: handle property WM_HINTS for window 0x1600079
Feb 07 11:49:10 untrusted qubes-gui[495]: Received input hint 0x1 for Window 0x1600079
Feb 07 11:49:10 untrusted qubes-gui[495]: MAP for window 0x1600079
Feb 07 11:49:10 untrusted qubes-gui[495]: got net_wm_name=Firefox
Feb 07 11:49:35 untrusted qubes-gui[495]: received message type 126 for 0x160005e
Feb 07 11:49:36 untrusted qubes-gui[495]: received message type 126 for 0x160005e
Feb 07 11:49:36 untrusted qubes-gui[495]: UNMAP for window 0x1600079
Feb 07 11:49:36 untrusted qubes-gui[495]: UNMAP for window 0x1600079
Feb 07 11:49:36 untrusted qubes-gui[495]: received message type 126 for 0x160005e
Feb 07 11:49:36 untrusted qubes-gui[495]: received message type 126 for 0x160005e
Feb 07 11:49:36 untrusted qubes-gui[495]: received message type 126 for 0x160005e
Feb 07 11:49:36 untrusted qubes-gui[495]: received message type 126 for 0xc033b9
Feb 07 11:49:36 untrusted qubes-gui[495]: received message type 126 for 0xc033b9
Feb 07 11:49:38 untrusted qubes-gui[495]: received message type 128 for 0x160005e
Feb 07 11:49:38 untrusted qubes-gui[495]: Starting handle_focus for 0x160005e key.type:10 key.mode:0
Feb 07 11:49:38 untrusted qubes-gui[495]: Window 0x160005e has inputhit set to 1 and takefocus set to 1
Feb 07 11:49:38 untrusted qubes-gui[495]: FocusOut actions for 0x160005e
Feb 07 11:49:38 untrusted qubes-gui[495]: sent XSetInputFocus for win 0x00
Feb 07 11:49:38 untrusted qubes-gui[495]: 0x160005e lost focus
Feb 07 11:49:38 untrusted qubes-gui[495]: received message type 142 for 0x0
Feb 07 11:49:38 untrusted qubes-gui[495]: received message type 128 for 0xc033b9
Feb 07 11:49:38 untrusted qubes-gui[495]: Starting handle_focus for 0xc033b9 key.type:9 key.mode:0 # Focus In
Feb 07 11:49:38 untrusted qubes-gui[495]: Window 0xc033b9 has inputhit set to 1 and takefocus set to 1 # Locally Active Input Model
Feb 07 11:49:38 untrusted qubes-gui[495]: FocusIn actions for 0xc033b9
Feb 07 11:49:38 untrusted qubes-gui[495]: 0xc033b9 raised
Feb 07 11:49:38 untrusted qubes-gui[495]: sent XSetInputFocus for win 0xc033b9
Feb 07 11:49:38 untrusted qubes-gui[495]: WM_TAKE_FOCUS sent for 0xc033b9
Feb 07 11:49:38 untrusted qubes-gui[495]: received message type 125 for 0xc033b9
Feb 07 11:49:38 untrusted qubes-gui[495]: send buttonevent, win 0xc033b9 type=4 button=1
Feb 07 11:49:38 untrusted qubes-gui[495]: handle configure event 0xc033b9 w=814 h=485 ovr=0
Feb 07 11:49:38 untrusted qubes-gui[495]: handle property _NET_WM_USER_TIME for window 0x160005e
Feb 07 11:49:38 untrusted qubes-gui[495]: received message type 125 for 0xc033b9
Feb 07 11:49:38 untrusted qubes-gui[495]: send buttonevent, win 0xc033b9 type=5 button=1
Feb 07 11:49:38 untrusted qubes-gui[495]: received message type 126 for 0xc033b9
Feb 07 11:49:38 untrusted qubes-gui[495]: received message type 126 for 0xc033b9

# Click on Terminal over a FF window over a link
Feb 07 11:49:51 untrusted qubes-gui[495]: received message type 128 for 0x160005e
Feb 07 11:49:51 untrusted qubes-gui[495]: Starting handle_focus for 0x160005e key.type:10 key.mode:0 # Focus Out
Feb 07 11:49:51 untrusted qubes-gui[495]: Window 0x160005e has inputhit set to 1 and takefocus set to 1
Feb 07 11:49:51 untrusted qubes-gui[495]: FocusOut actions for 0x160005e # Focus Out from firefox tab
Feb 07 11:49:51 untrusted qubes-gui[495]: sent XSetInputFocus for win 0x00
Feb 07 11:49:51 untrusted qubes-gui[495]: 0x160005e lost focus
Feb 07 11:49:51 untrusted qubes-gui[495]: received message type 142 for 0x0
Feb 07 11:49:51 untrusted qubes-gui[495]: received message type 128 for 0xc033b9
Feb 07 11:49:51 untrusted qubes-gui[495]: Starting handle_focus for 0xc033b9 key.type:9 key.mode:0 # Focus In to terminal
Feb 07 11:49:51 untrusted qubes-gui[495]: Window 0xc033b9 has inputhit set to 1 and takefocus set to 1 #  Locally Active Input model
Feb 07 11:49:51 untrusted qubes-gui[495]: FocusIn actions for 0xc033b9
Feb 07 11:49:51 untrusted qubes-gui[495]: 0xc033b9 raised
Feb 07 11:49:51 untrusted qubes-gui[495]: sent XSetInputFocus for win 0xc033b9
Feb 07 11:49:51 untrusted qubes-gui[495]: WM_TAKE_FOCUS sent for 0xc033b9
Feb 07 11:49:51 untrusted qubes-gui[495]: received message type 125 for 0xc033b9
Feb 07 11:49:51 untrusted qubes-gui[495]: send buttonevent, win 0xc033b9 type=4 button=1 # Button event to Terminal
Feb 07 11:49:51 untrusted qubes-gui[495]: handle configure event 0xc033b9 w=814 h=485 ovr=0
Feb 07 11:49:51 untrusted qubes-gui[495]: handle property _NET_WM_USER_TIME for window 0x160005e
Feb 07 11:49:51 untrusted qubes-gui[495]: received message type 125 for 0xc033b9
Feb 07 11:49:51 untrusted qubes-gui[495]: send buttonevent, win 0xc033b9 type=5 button=1
Feb 07 11:49:58 untrusted qubes-gui[495]: received message type 126 for 0xc033b9
Feb 07 11:49:58 untrusted qubes-gui[495]: received message type 126 for 0xc033b9

@ptitdoc
Copy link

ptitdoc commented Feb 8, 2019

Here are the logs on dom0 side (gui daemon):

# Click on chromium with focus set on chromium:
xside: win 0x5800012(0x1400001) type=4 button=1 x=842, y=445
xside: win 0x5800012(0x1400001) type=5 button=1 x=842, y=445

# Click on terminal with focuse set on terminal
xside: win 0x5800007(0xa00003) type=4 button=1 x=394, y=410
xside: win 0x5800007(0xa00003) type=5 button=1 x=394, y=410

# Click on terminal with focus set on chromium
xside: win 0x5800007(0xa00003) type=4 button=1 x=106, y=371
handle_configure_from_vm, local 0x5800007 remote 0xa00003, 814/526, was 814/526, ovr=0, xy 918/177, was 918/177
MSG_MFNDUMP for 0x5800007(0xa00003): 814x526, num_mfn 0x1a3 off 0xaf8
shmimage for 0x5800007(remote 0xa00003), x: 0, y: 0, w: 372, h: 526
  do_shm_update for 0x5800007(remote 0xa00003), after border calc: x=0, y=0, w=372, h=526
handle_configure_from_vm, local 0x5800012 remote 0x1400001, 1286/1025, was 1286/1025, ovr=0, xy 4/79, was 4/79
MSG_MFNDUMP for 0x5800012(0x1400001): 1286x1025, num_mfn 0x508 off 0x178
xside: win 0x5800007(0xa00003) type=5 button=1 x=106, y=371

@ptitdoc
Copy link

ptitdoc commented Feb 8, 2019

From what I can see:

  • the keyboard focus is apparently properly transfered from chromium to the terminal
  • the dom0 gui-agent xsite shows a click event assigned to the right windows
  • the vm gui-agent vmside send XSetInputFocus with windows:None to chromium
  • the vm gui-agent vmside send XSetInputFocus to the console and a WM_TAKE_FOCUS message
  • however the "mouse button" or hover information is still grabbed by chromium when the mouse is over the terminal.

Things that still need to be investigated and that could be the culprit:

  • potential requirement of XSetInputFocus RootPointer for chromium
  • unhandled case for Passive Input Model in vmside (inputhit set to 1 and takefocus set to 0) as I did not identified other apps than chromium that uses Passive Input Model until now.

@ptitdoc
Copy link

ptitdoc commented Feb 8, 2019

Here is a potential workaround I found in XFCE which requires to enable focus follow mouse (which is not really what I want in my case):

  • Enable Settings>Window Manager>Focus>Focus follows mouse

Using this option, the hovered windows (eg: the console) is given proper focus before I have a chance to click on it. This avoid the focus problem described there.

The behavior of the windows manager will however be slightly different there. Which makes me think that it may also be a XFCE bug or some kind of race condition between focus and click event.

I also tried playing with "focus stealing prevention" but it does not seems to have any effect in my chrome use case.

@marmarek
Copy link
Member

marmarek commented Feb 8, 2019

It may be worth checking if XGrabPointer is not involved, which could explain why mouse events are intercepted by chromium. There may be some ICCCM (or NetWM) protocol missing and incorrectly assumed to be present by chromium. I've seen already one such case: QubesOS/qubes-gui-agent-linux@a8e6343

If you're familiar enough with X11 protocol (which I believe is already the case), then I recommend x11trace - I'd call it strace equivalent for X11. Quite verbose, but can help a lot with figuring what is going on. AFAIR -n option is needed.

@ptitdoc
Copy link

ptitdoc commented Feb 8, 2019

Thanks for the pointer (ha ha), I will check that. I also through of potential issue with the timestamps used in XEvents in gui-agent or gui-daemon when looking at this bug:
https://git.xfce.org/xfce/xfwm4/commit/?id=261bcc782d99f38ccc9218ea0c9461e721710e8d

Based on ICCCM, they often ask to avoid sending CurrentTime in focus related events which is what the gui-agent is doing everytime.

@ptitdoc
Copy link

ptitdoc commented Feb 8, 2019

I'm not so confortable with X11 (I'm just feeling in pain trying to debug that, and re-reading ICCCM hundred times).
I will check if I can get information related to XGrabPointer by adding debugging to qubes-agent. I just tried x11trace but I don't know what to look for.

@marmarek
Copy link
Member

marmarek commented Feb 8, 2019

The problem with timestamps is you don't really have time of the event in VM-Xorg time units, since the event does not come from VM-Xorg initially.

Maybe it is a time to re-try using XSendEvent with specific target, instead of (or in addition to?) trying to switch focus in the right order? AFAIR we're tried that before and there were some problems, but I don't remember details. The code is still there, #if 0-ed.

@ptitdoc
Copy link

ptitdoc commented Feb 8, 2019

I see that you are not using winid in handle_button and handle_keypress. Is it what you are talking about ?

@marmarek
Copy link
Member

marmarek commented Feb 8, 2019

Yes, exactly.

@marmarek
Copy link
Member

marmarek commented Feb 8, 2019

Or maybe it should be some combination - like restore XSetInputFocus call, but still send actual even through emulated mouse/keyboard (this is what feed_xdriver does).

@ptitdoc
Copy link

ptitdoc commented Feb 8, 2019

Here are my random debugging attempts with x11trace

$ x11trace -n /usr/bin/chromium | grep -i grab
[...]
001:<:0289: 28: XInputExtension-Request(131,51): XIGrabDevice grab_window=0x01600001 time=0x00000000 cursor=0x00000000 device=2 grab_mode=Asynchronous(0x01) paired_device_mode=Asynchronous(0x01) owner_events=true(0x01) masks=0x001c0070;
001:<:02a6: 12: XInputExtension-Request(131,52): XIUngrabDevice opcode=0x83 opcode2=0x34 unparsed-data=0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00;
001:<:02a7:  8: Request(27): UngrabPointer time=CurrentTime(0x00000000)
001:<:062e: 28: XInputExtension-Request(131,51): XIGrabDevice grab_window=0x01600001 time=0x00000000 cursor=0x00000000 device=2 grab_mode=Asynchronous(0x01) paired_device_mode=Asynchronous(0x01) owner_events=true(0x01) masks=0x001c0070;
001:<:0668: 12: XInputExtension-Request(131,52): XIUngrabDevice opcode=0x83 opcode2=0x34 unparsed-data=0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00;
001:<:0669:  8: Request(27): UngrabPointer time=CurrentTime(0x00000000)
001:<:06a7: 28: XInputExtension-Request(131,51): XIGrabDevice grab_window=0x01600001 time=0x00000000 cursor=0x00000000 device=2 grab_mode=Asynchronous(0x01) paired_device_mode=Asynchronous(0x01) owner_events=true(0x01) masks=0x001c0070;
001:<:07b3: 12: XInputExtension-Request(131,52): XIUngrabDevice opcode=0x83 opcode2=0x34 unparsed-data=0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00;
001:<:07b4:  8: Request(27): UngrabPointer time=CurrentTime(0x00000000)
001:<:0d09: 28: XInputExtension-Request(131,51): XIGrabDevice grab_window=0x01600001 time=0x00000000 cursor=0x00000000 device=2 grab_mode=Asynchronous(0x01) paired_device_mode=Asynchronous(0x01) owner_events=true(0x01) masks=0x001c0070;
001:<:0e49: 12: XInputExtension-Request(131,52): XIUngrabDevice opcode=0x83 opcode2=0x34 unparsed-data=0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00;
001:<:0e4a:  8: Request(27): UngrabPointer time=CurrentTime(0x00000000)
001:<:0fa9: 28: XInputExtension-Request(131,51): XIGrabDevice grab_window=0x01600001 time=0x00000000 cursor=0x00000000 device=2 grab_mode=Asynchronous(0x01) paired_device_mode=Asynchronous(0x01) owner_events=true(0x01) masks=0x001c0070;
001:<:0fc6: 12: XInputExtension-Request(131,52): XIUngrabDevice opcode=0x83 opcode2=0x34 unparsed-data=0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00;
001:<:0fc7:  8: Request(27): UngrabPointer time=CurrentTime(0x00000000)
001:<:0fd2: 28: XInputExtension-Request(131,51): XIGrabDevice grab_window=0x01600001 time=0x00000000 cursor=0x00000000 device=2 grab_mode=Asynchronous(0x01) paired_device_mode=Asynchronous(0x01) owner_events=true(0x01) masks=0x001c0070;
001:<:0fea: 12: XInputExtension-Request(131,52): XIUngrabDevice opcode=0x83 opcode2=0x34 unparsed-data=0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00;
001:<:0feb:  8: Request(27): UngrabPointer time=CurrentTime(0x00000000)
001:<:0ff8: 28: XInputExtension-Request(131,51): XIGrabDevice grab_window=0x01600001 time=0x00000000 cursor=0x00000000 device=2 grab_mode=Asynchronous(0x01) paired_device_mode=Asynchronous(0x01) owner_events=true(0x01) masks=0x001c0070;
001:<:1016: 12: XInputExtension-Request(131,52): XIUngrabDevice opcode=0x83 opcode2=0x34 unparsed-data=0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00;
[...]
x11trace -n /usr/bin/firefox | grep -i grab
[...]
000:<:4b6a:  4: Request(37): UngrabServer 
000:<:4e53:  4: Request(36): GrabServer 
000:<:4e56:  4: Request(37): UngrabServer 
000:<:5058:  4: Request(36): GrabServer 
000:<:505b:  4: Request(37): UngrabServer 
000:<:5081: 24: Request(26): GrabPointer owner-events=true(0x01) grab-window=0x01200038 event-mask=ButtonPress,ButtonRelease,EnterWindow,LeaveWindow,PointerMotion,VisibilityChange,OwnerGrabButton pointer-mode=Asynchronous(0x01) keyboard-mode=Asynchronous(0x01) confine-to=None(0x00000000) cursor=None(0x00000000) time=0x010af8b0
000:>:5081: Event LeaveNotify(8) detail=Nonlinear(0x03) mode=Grab(0x01) flags=same-screen time=0x010af8c8 root=0x000003aa event=0x01200010 child=None(0x00000000) root-x=743 root-y=561 event-x=739 event-y=337 state=Mod2,Button1
000:>:5081:32: Reply to GrabPointer: status=Success(0x00)
000:<:5085:  4: Request(36): GrabServer 
000:<:5088:  4: Request(37): UngrabServer 
000:<:53b5:  8: Request(27): UngrabPointer time=CurrentTime(0x00000000)
000:>:53b7: Event LeaveNotify(8) detail=Nonlinear(0x03) mode=Ungrab(0x02) flags=same-screen time=0x010afcca root=0x000003aa event=0x01200038 child=None(0x00000000) root-x=855 root-y=915 event-x=126 event-y=330 state=Mod2,Button2
000:>:53b7: Event EnterNotify(7) detail=Nonlinear(0x03) mode=Ungrab(0x02) flags=same-screen time=0x010afcca root=0x000003aa event=0x01200010 child=None(0x00000000) root-x=855 root-y=915 event-x=851 event-y=691 state=Mod2,Button2
000:<:53c4:  4: Request(36): GrabServer 
000:<:53c7:  4: Request(37): UngrabServer 
000:<:53c9:  4: Request(36): GrabServer 
000:<:53cc:  4: Request(37): UngrabServer 
000:<:53cd:  4: Request(36): GrabServer 
000:<:53d0:  4: Request(37): UngrabServer

@marmarek
Copy link
Member

marmarek commented Feb 8, 2019

Ok, so it does grab mouse pointer.
Can you tell how exactly those XIGrabDevice/XIUngrabDevice are ordered vs input events (click, EnterNotify/LeaveNotify)?

@ptitdoc
Copy link

ptitdoc commented Feb 13, 2019

So, here is the X11 events when using firefox right when I click on the overlapping terminal window with firefox focused in. We clearly see the ButtonPress event coming before FocusOut (I did not analysed the windows numbers however).
Events are coming in this order:

FocusOut WIN 01400011
ButtonPress
 time: TIM 00d5f4e1
 root: WIN 000003aa
 event: WIN 01400010
LeaveNotify
 time: TIM 00d5f4e1
 root: WIN 000003aa
 event: WIN 01400010

Then GetInputFocus is coming later, but parameters are not visible (I will try to increase verbose)

18.95: 					  64 bytes <-- X11 Server 1
					 ..............EVENT: FocusOut
					              detail: Nonlinear
					               event: WIN 01400011
					                mode: Normal
					 ..............EVENT: FocusOut
					              detail: NonlinearVirtual
					               event: WIN 01400010
					                mode: Normal
18.95: 					  64 bytes <-- X11 Server 1
					 ..............EVENT: ButtonPress
					              detail: 1 (^A)
					                time: TIM 00d5f4e1
					                root: WIN 000003aa
					               event: WIN 01400010
					               child: None
					              root-x: 673
					              root-y: 879
					             event-x: 669
					             event-y: 477
					               state: Mod2
					         same-screen: True
					 ..............EVENT: LeaveNotify
					              detail: Nonlinear
					                time: TIM 00d5f4e1
					                root: WIN 000003aa
					               event: WIN 01400010
					               child: None
					              root-x: 673
					              root-y: 879
					             event-x: 669
					             event-y: 477
					               state: Mod2 | Button1
					                mode: Normal
					  same-screen, focus: same-screen
18.95: Client 1 -->   36 bytes
	 ............REQUEST: ChangeProperty
	                mode: Replace
	              window: WIN 01400010
	            property: <_NET_WM_USER_TIME>
	                type: <CARDINAL>
	              format: 20
	                data: 00d5f4e1
	 ............REQUEST: QueryTree
	              window: WIN 01400010
18.95: 					  68 bytes <-- X11 Server 1
					 ..............EVENT: PropertyNotify
					              window: WIN 01400010
					                atom: <_NET_WM_USER_TIME>
					                time: TIM 00d5f4e5
					               state: NewValue
					 ..............REPLY: QueryTree
					                root: WIN 000003aa
					              parent: WIN 000003aa
					            children: (1)
18.95: Client 1 -->    8 bytes
	 ............REQUEST: GetGeometry
	            drawable: DWB 01400010
18.95: 					  32 bytes <-- X11 Server 1
					 ..............REPLY: GetGeometry
					               depth: 18
					                root: WIN 000003aa
					                   x: 4
					                   y: 402
					               width: 04b2
					              height: 031a
					        border-width: 0000
18.95: Client 1 -->   16 bytes
	 ............REQUEST: TranslateCoordinates
	          src-window: WIN 01400010
	          dst-window: WIN 000003aa
	               src-x: 0
	               src-y: 0
18.95: Client 1 -->   52 bytes
	 ............REQUEST: SetClipRectangles
	            ordering: YXBanded
	                  gc: GXC 01400024
	       clip-x-origin: 0
	       clip-y-origin: 0
	          rectangles: (1)
	 ............REQUEST: CopyArea
	        src-drawable: DWB 01400023
	        dst-drawable: DWB 01400010
	                  gc: GXC 01400024
	               src-x: 0
	               src-y: 0
	               dst-x: 0
	               dst-y: 0
	               width: 04b2
	              height: 031a
	 ............REQUEST: GetInputFocus
18.95: 					  32 bytes <-- X11 Server 1
					 ..............REPLY: TranslateCoordinates
					         same-screen: True
					               child: WIN 01400010
					               dst-x: 4
					               dst-y: 402
18.95: Client 1 -->   16 bytes
	 ............REQUEST: TranslateCoordinates
	          src-window: WIN 01400010
	          dst-window: WIN 000003aa
	               src-x: 0
	               src-y: 0
18.95: 					  64 bytes <-- X11 Server 1
					 ..............EVENT: NoExposure
					            drawable: DWB 01400010
					        minor-opcode: 0000
					        major-opcode: 3e
					 ..............REPLY: GetInputFocus
					           revert-to: Parent
					               focus: WIN 01000008
18.95: 					  32 bytes <-- X11 Server 1
					 ..............REPLY: TranslateCoordinates
					         same-screen: True
					               child: WIN 01400010
					               dst-x: 4
					               dst-y: 402
18.95: Client 1 -->   16 bytes
	 ............REQUEST: TranslateCoordinates
	          src-window: WIN 01400010
	          dst-window: WIN 000003aa
	               src-x: 0
	               src-y: 0
18.95: 					  32 bytes <-- X11 Server 1
					 ..............REPLY: TranslateCoordinates
					         same-screen: True
					               child: WIN 01400010
					               dst-x: 4
					               dst-y: 402
18.95: Client 1 -->   12 bytes
	 ............REQUEST: GrabServer
	 ............REQUEST: QueryPointer
	              window: WIN 000003aa
18.95: 					  32 bytes <-- X11 Server 1
					 ..............REPLY: QueryPointer
					         same-screen: True
					                root: WIN 000003aa
					               child: WIN 01000007
					              root-x: 673
					              root-y: 879
					               win-x: 673
					               win-y: 879
					                mask: Mod2 | Button1
18.95: Client 1 -->    8 bytes
	 ............REQUEST: QueryPointer
	              window: WIN 01000007
18.95: 					  32 bytes <-- X11 Server 1
					 ..............REPLY: QueryPointer
					         same-screen: True
					                root: WIN 000003aa
					               child: None
					              root-x: 673
					              root-y: 879
					               win-x: 27
					               win-y: 338
					                mask: Mod2 | Button1
18.96: Client 1 -->   16 bytes
	 ............REQUEST: UngrabServer
	 ............REQUEST: GrabServer
	 ............REQUEST: QueryPointer
	              window: WIN 000003aa
18.96: 					  32 bytes <-- X11 Server 1
					 ..............REPLY: QueryPointer
					         same-screen: True
					                root: WIN 000003aa
					               child: WIN 01000007
					              root-x: 673
					              root-y: 879
					               win-x: 673
					               win-y: 879
					                mask: Mod2 | Button1
18.96: Client 1 -->    8 bytes
	 ............REQUEST: QueryPointer
	              window: WIN 01000007
18.96: 					  32 bytes <-- X11 Server 1
					 ..............REPLY: QueryPointer
					         same-screen: True
					                root: WIN 000003aa
					               child: None
					              root-x: 673
					              root-y: 879
					               win-x: 27
					               win-y: 338
					                mask: Mod2 | Button1
18.96: Client 1 -->   20 bytes
	 ............REQUEST: UngrabServer
	 ............REQUEST: TranslateCoordinates
	          src-window: WIN 01400010
	          dst-window: WIN 000003aa
	               src-x: 0
	               src-y: 0
18.96: 					  32 bytes <-- X11 Server 1
					 ..............REPLY: TranslateCoordinates
					         same-screen: True
					               child: WIN 01400010
					               dst-x: 4
					               dst-y: 402
18.96: Client 1 -->   52 bytes
	 ............REQUEST: SetClipRectangles
	            ordering: YXBanded
	                  gc: GXC 01400027
	       clip-x-origin: 0
	       clip-y-origin: 0
	          rectangles: (1)
	 ............REQUEST: CopyArea
	        src-drawable: DWB 01400026
	        dst-drawable: DWB 01400010
	                  gc: GXC 01400027
	               src-x: 0
	               src-y: 0
	               dst-x: 0
	               dst-y: 0
	               width: 04b2
	              height: 031a
	 ............REQUEST: GetInputFocus
18.96: 					  64 bytes <-- X11 Server 1
					 ..............EVENT: NoExposure
					            drawable: DWB 01400010
					        minor-opcode: 0000
					        major-opcode: 3e
					 ..............REPLY: GetInputFocus
					           revert-to: Parent
					               focus: WIN 01000008
18.99: Client 1 -->   52 bytes
	 ............REQUEST: SetClipRectangles
	            ordering: YXBanded
	                  gc: GXC 01400024
	       clip-x-origin: 0
	       clip-y-origin: 0
	          rectangles: (1)
	 ............REQUEST: CopyArea
	        src-drawable: DWB 01400023
	        dst-drawable: DWB 01400010
	                  gc: GXC 01400024
	               src-x: 0
	               src-y: 0
	               dst-x: 0
	               dst-y: 0
	               width: 04b2
	              height: 031a
	 ............REQUEST: GetInputFocus
18.99: 					  64 bytes <-- X11 Server 1
					 ..............EVENT: NoExposure
					            drawable: DWB 01400010
					        minor-opcode: 0000
					        major-opcode: 3e
					 ..............REPLY: GetInputFocus
					           revert-to: Parent
					               focus: WIN 01000008
19.08: 					  64 bytes <-- X11 Server 1
					 ..............EVENT: ButtonRelease
					              detail: 1 (^A)
					                time: TIM 00d5f568
					                root: WIN 000003aa
					               event: WIN 01400010
					               child: None
					              root-x: 673
					              root-y: 879
					             event-x: 669
					             event-y: 477
					               state: Mod2 | Button1
					         same-screen: True
					 ..............EVENT: LeaveNotify
					              detail: Nonlinear
					                time: TIM 00d5f568
					                root: WIN 000003aa
					               event: WIN 01400010
					               child: None
					              root-x: 673
					              root-y: 879
					             event-x: 669
					             event-y: 477
					               state: Mod2
					                mode: Ungrab
					  same-screen, focus: same-screen
19.08: Client 1 -->   12 bytes
	 ............REQUEST: GrabServer
	 ............REQUEST: QueryPointer
	              window: WIN 000003aa
19.08: 					  32 bytes <-- X11 Server 1
					 ..............REPLY: QueryPointer
					         same-screen: True
					                root: WIN 000003aa
					               child: WIN 01000007
					              root-x: 673
					              root-y: 879
					               win-x: 673
					               win-y: 879
					                mask: Mod2

@ptitdoc
Copy link

ptitdoc commented Feb 13, 2019

Same for chromium, XInputEvents are coming immediately before SetInputFocus, however in this case the mouse is apparently still grabbed by chromium:

29.57: 					  32 bytes <-- X11 Server 2
					 ..............EVENT: FocusOut
					              detail: Nonlinear
					               event: WIN 01800001
					                mode: Normal
29.57: 					  76 bytes <-- X11 Server 2
					 ..............EVENT: GenericEvent
					           extension: XInputExtension
					          event type: 000a
					                data: (16)
29.57: 					 120 bytes <-- X11 Server 2
					 ..............EVENT: GenericEvent
					           extension: XInputExtension
					          event type: 0004
					                data: (27)
29.57: 					 120 bytes <-- X11 Server 2
					 ..............EVENT: GenericEvent
					           extension: XInputExtension
					          event type: 0004
					                data: (27)
29.57: 					  32 bytes <-- X11 Server 2
					 ..............EVENT: ConfigureNotify
					               event: WIN 000003aa
					              window: WIN 01000007
					       above-sibling: WIN 00200002
					                   x: 645
					                   y: 526
					               width: 02de
					              height: 01c5
					        border-width: 0000
					   override-redirect: False
29.57: 					  76 bytes <-- X11 Server 2
					 ..............EVENT: GenericEvent
					           extension: XInputExtension
					          event type: 0008
					                data: (16)
29.57: 					  76 bytes <-- X11 Server 2
					 ..............EVENT: GenericEvent
					           extension: XInputExtension
					          event type: 0007
					                data: (16)
29.57: Client 2 -->   24 bytes
	 ............REQUEST: ChangeProperty
	                mode: Append
	              window: WIN 01800005
	            property: <CHROMIUM_TIMESTAMP>
	                type: <STRING>
	              format: 08
29.57: 					  32 bytes <-- X11 Server 2
					 ..............EVENT: PropertyNotify
					              window: WIN 01800005
					                atom: <CHROMIUM_TIMESTAMP>
					                time: TIM 00e23b84
					               state: NewValue
29.58: Client 2 -->   24 bytes
	 ............REQUEST: ChangeProperty
	                mode: Append
	              window: WIN 01800005
	            property: <CHROMIUM_TIMESTAMP>
	                type: <STRING>
	              format: 08
29.58: 					  32 bytes <-- X11 Server 2
					 ..............EVENT: PropertyNotify
					              window: WIN 01800005
					                atom: <CHROMIUM_TIMESTAMP>
					                time: TIM 00e23b87
					               state: NewValue
29.58: Client 2 -->   88 bytes
	 ............REQUEST: ChangeWindowAttributes
	              window: WIN 01800017
	          value-mask: cursor
	          value-list:
		              cursor: CUR 0180001c
	 ............REQUEST: ChangeWindowAttributes
	              window: WIN 01800001
	          value-mask: cursor
	          value-list:
		              cursor: CUR 0180001c
	 ............REQUEST: ConfigureWindow
	              window: WIN 01800001
	          value-mask: stack-mode
	          value-list:
		          stack-mode: Above
	 ............REQUEST: SetInputFocus
	           revert-to: Parent
	               focus: WIN 01800001
	                time: TIM 00e23b82
	 ............REQUEST: XInputExtension-Request
	        minor opcode: 33
	                data: (6)
29.58: 					 280 bytes <-- X11 Server 2
					 ..............EVENT: ConfigureNotify
					               event: WIN 01800001
					              window: WIN 01800001
					       above-sibling: WIN 01000007
					                   x: 1015
					                   y: 114
					               width: 0780
					              height: 0479
					        border-width: 0000
					   override-redirect: False
					 ..............EVENT: ConfigureNotify
					               event: WIN 000003aa
					              window: WIN 01800001
					       above-sibling: WIN 01000007
					                   x: 1015
					                   y: 114
					               width: 0780
					              height: 0479
					        border-width: 0000
					   override-redirect: False
					 ..............EVENT: EnterNotify
					              detail: Nonlinear
					                time: TIM 00e23b88
					                root: WIN 000003aa
					               event: WIN 01800001
					               child: None
					              root-x: 1305
					              root-y: 837
					             event-x: 290
					             event-y: 723
					               state: Mod2 | Button1
					                mode: Normal
					  same-screen, focus: same-screen
					 ..............EVENT: GenericEvent
					           extension: XInputExtension
					          event type: 0008
					                data: (16)
					 ..............EVENT: GenericEvent
					           extension: XInputExtension
					          event type: 0007
					                data: (16)
					 ..............REPLY: XInputExtension-Reply
					                data: 33
					                data: (6)
29.58: Client 2 -->   16 bytes
	 ............REQUEST: TranslateCoordinates
	          src-window: WIN 01800001
	          dst-window: WIN 000003aa
	               src-x: 0
	               src-y: 0
29.58: 					  32 bytes <-- X11 Server 2
					 ..............REPLY: TranslateCoordinates
					         same-screen: True
					               child: WIN 01800001
					               dst-x: 1015
					               dst-y: 114
29.58: Client 2 -->   24 bytes
	 ............REQUEST: ChangeProperty
	                mode: Append
	              window: WIN 01800005
	            property: <CHROMIUM_TIMESTAMP>
	                type: <STRING>
	              format: 08
29.58: 					  32 bytes <-- X11 Server 2
					 ..............EVENT: PropertyNotify
					              window: WIN 01800005
					                atom: <CHROMIUM_TIMESTAMP>
					                time: TIM 00e23b8c
					               state: NewValue
29.58: Client 2 -->   24 bytes
	 ............REQUEST: ChangeProperty
	                mode: Append
	              window: WIN 01800005
	            property: <CHROMIUM_TIMESTAMP>
	                type: <STRING>
	              format: 08
29.58: 					  32 bytes <-- X11 Server 2
					 ..............EVENT: PropertyNotify
					              window: WIN 01800005
					                atom: <CHROMIUM_TIMESTAMP>
					                time: TIM 00e23b8c
					               state: NewValue
29.58: Client 2 -->   32 bytes
	 ............REQUEST: ChangeWindowAttributes
	              window: WIN 01800017
	          value-mask: cursor
	          value-list:
		              cursor: CUR 0180001c
	 ............REQUEST: ChangeWindowAttributes
	              window: WIN 01800001
	          value-mask: cursor
	          value-list:
		              cursor: CUR 0180001c
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 4248 bytes
	 ............REQUEST: PutImage
	              format: ZPixmap
	            drawable: DWB 01800001
	                  gc: GXC 0180000a
	               width: 0778
	              height: 0022
	               dst-x: 4
	               dst-y: 80
	            left-pad: 00
	               depth: 18
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 32768 bytes
29.59: Client 2 --> 3776 bytes
29.59: Client 2 --> 4248 bytes

@ptitdoc
Copy link

ptitdoc commented Feb 13, 2019

The main difference for chromium is that in a working situation ("Focus follow mouse" model), a LeaveNotify event is sent from the XServer:

15.40: 					  32 bytes <-- X11 Server 2
					 ..............EVENT: FocusOut
					              detail: Nonlinear
					               event: WIN 01600001
					                mode: Normal
15.40: 					  76 bytes <-- X11 Server 2
					 ..............EVENT: GenericEvent
					           extension: XInputExtension
					          event type: 000a
					                data: (16)
15.40: 					  32 bytes <-- X11 Server 2
					 ..............EVENT: ConfigureNotify
					               event: WIN 000003aa
					              window: WIN 01000007
					       above-sibling: WIN 00200002
					                   x: 1063
					                   y: 55
					               width: 02de
					              height: 01c5
					        border-width: 0000
					   override-redirect: False
15.40: 					  32 bytes <-- X11 Server 2
					 ..............EVENT: LeaveNotify
					              detail: Nonlinear
					                time: TIM 0121fc44
					                root: WIN 000003aa
					               event: WIN 01600001
					               child: None
					              root-x: 1182
					              root-y: 232
					             event-x: 1182
					             event-y: 177
					               state: Mod2
					                mode: Normal
					  same-screen, focus: same-screen
15.41: 					  76 bytes <-- X11 Server 2
					 ..............EVENT: GenericEvent
					           extension: XInputExtension
					          event type: 0008
					                data: (16)

@marmarek
Copy link
Member

I think this may be related to front-back windows relation on the VM side. It is very hard to get them in sync with dom0. We workaround this by bringing window to front whenever it should receive focus. This works fine with "focus follow mouse", because focus is given before the click. But if focus is given on click, order of those events may be swapped (as click and XRaiseWindow are delivered to X server through different channels).

Since fixing #4351 you can actually take a look how it is on the VM side, by using x11vnc + vncviewer locally in that VM.

One possible fix would be to bring a window to front not only when it gets focus, but also when mouse enters its region (see EnterNotify, handle_crossing() function). This may be too extensive, but worth a try. I'd recommend also analyzing git history around that function and related tickets pointed from there - to get an idea what could possibly go wrong and verify if the change doesn't break it.

Ideally, windows ordering on the VM side should be the same as in dom0...

@iacore
Copy link

iacore commented Mar 8, 2022

Cannot reproduce under this branch, which treat all focus events equally.

QubesOS/qubes-gui-agent-linux#152

@DemiMarie DemiMarie added the fixed-by-wayland Bugs that would not appear if Qubes OS used Wayland instead of X11 label Aug 19, 2022
DemiMarie added a commit to DemiMarie/qubes-gui-agent-linux that referenced this issue Aug 23, 2022
Events from the GUI daemon are directed at specific windows.  Ensuring
that they are sent to the correct window is more importent than obeying
the ICCCM input hint.  Giving pointer focus to a window is accomplished
by raising it.

Fixes QubesOS/qubes-issues#3267.
@DemiMarie DemiMarie added diagnosed Technical diagnosis has been performed (see issue comments). pr submitted A pull request has been submitted for this issue. and removed needs diagnosis Requires technical diagnosis from developer. Replace with "diagnosed" or remove if otherwise closed. labels Aug 23, 2022
@andrewdavidwong andrewdavidwong added the affects-4.1 This issue affects Qubes OS 4.1. label Aug 8, 2023
@andrewdavidwong andrewdavidwong removed this from the Release 4.1 updates milestone Aug 13, 2023
@andrewdavidwong andrewdavidwong added the eol-4.1 Closed because Qubes 4.1 has reached end-of-life (EOL) label Dec 7, 2024
Copy link

github-actions bot commented Dec 7, 2024

This issue is being closed because:

If anyone believes that this issue should be reopened, please leave a comment saying so.
(For example, if a bug still affects Qubes OS 4.2, then the comment "Affects 4.2" will suffice.)

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-4.1 This issue affects Qubes OS 4.1. C: gui-virtualization diagnosed Technical diagnosis has been performed (see issue comments). eol-4.1 Closed because Qubes 4.1 has reached end-of-life (EOL) fixed-by-wayland Bugs that would not appear if Qubes OS used Wayland instead of X11 P: major Priority: major. Between "default" and "critical" in severity. pr submitted A pull request has been submitted for this issue. T: bug Type: bug report. A problem or defect resulting in unintended behavior in something that exists.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants