<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>490057</bug_id>
          
          <creation_ts>2024-07-10 22:22:47 +0000</creation_ts>
          <short_desc>Legacy X11 apps include mouse buttons results in focus stealing after application switch</short_desc>
          <delta_ts>2025-07-01 17:29:31 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>4</classification_id>
          <classification>Plasma</classification>
          <product>kwin</product>
          <component>wayland-generic</component>
          <version>6.1.2</version>
          <rep_platform>Arch Linux</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>CONFIRMED</bug_status>
          <resolution></resolution>
          
          <see_also>https://gitlab.freedesktop.org/xorg/xserver/-/issues/1818</see_also>
    
    <see_also>https://bugs.kde.org/show_bug.cgi?id=484992</see_also>
          <bug_file_loc>https://gitlab.freedesktop.org/xorg/xserver/-/issues/1818</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>wayland-only</keywords>
          <priority>NOR</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Andrew">chuvik.hacker</reporter>
          <assigned_to name="KWin default assignee">kwin-bugs-null</assigned_to>
          <cc>4wy78uwh</cc>
    
    <cc>chuvik.hacker</cc>
    
    <cc>dashonwwIII</cc>
    
    <cc>horacek.pavel</cc>
    
    <cc>joncox1987</cc>
    
    <cc>kde</cc>
    
    <cc>kdedev</cc>
    
    <cc>miranda</cc>
    
    <cc>nate</cc>
    
    <cc>pollux66</cc>
    
    <cc>randomprimary2004</cc>
    
    <cc>semaraputraputugede</cc>
    
    <cc>steemandlinux</cc>
    
    <cc>tesfabpel</cc>
    
    <cc>vasilis</cc>
    
    <cc>xaver.hugl</cc>
          
          <cf_commitlink></cf_commitlink>
          <cf_versionfixedin>6.3.6, 6.4.3</cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2336410</commentid>
    <comment_count>0</comment_count>
    <who name="Andrew">chuvik.hacker</who>
    <bug_when>2024-07-10 22:22:47 +0000</bug_when>
    <thetext>SUMMARY
Enabling &quot;Additionally include mouse buttons&quot; under &quot;System settings - Application permissions - Legacy X11 App Support&quot; results in X11 apps receinving the clicks and gaining focus unintentionally after virtual desktop switching.

STEPS TO REPRODUCE
1. Open an X11 app, I experience this with Google Chrome and Discord.
2. Open System settings and check the &quot;Additionally include mouse buttons&quot;.
3. Switch to a different virtual desktop.
4. Use mouse to interact with another X11 app window there, can be window of the same app. Any mouse events sent to X11 window seem to work including mouse move and scrolling.
5. Go back to previous desktop using keybaord shortcuts, I used Meta+Ctrl+Left. It seems important that the cursor is positioned such that it lands on top of a wayland window after virtual desktop switch. Making sure the cursor is also within X11 window bounds seems to help reproduce more reliably.
6. Without moving the cursor away from Wayland window, click in the Setting or or some other wayland app window again.

OBSERVED RESULT
The click drops right through into the X11 app, the X11 app becomes focused on top of wayland app.


EXPECTED RESULT
The click does not go through the same way it did not go through before the virtual desktop switching.


SOFTWARE/OS VERSIONS
KDE Plasma Version: 6.1.2
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.2

ADDITIONAL INFORMATION
With focus stealing prevention is set to &quot;High&quot;, the X11 app would still get the click although it would not gain focus.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2337961</commentid>
    <comment_count>1</comment_count>
    <who name="David Edmundson">kde</who>
    <bug_when>2024-07-17 13:50:03 +0000</bug_when>
    <thetext>We cannot reproduce using the steps above. If you have any more concrete steps (video?) that could help.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2337962</commentid>
    <comment_count>2</comment_count>
    <who name="David Edmundson">kde</who>
    <bug_when>2024-07-17 13:52:25 +0000</bug_when>
    <thetext>edit, someone just did</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2382966</commentid>
    <comment_count>3</comment_count>
    <who name="Zamundaaa">xaver.hugl</who>
    <bug_when>2024-12-20 13:50:40 +0000</bug_when>
    <thetext>*** Bug 497030 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2388036</commentid>
    <comment_count>4</comment_count>
    <who name="Zamundaaa">xaver.hugl</who>
    <bug_when>2025-01-09 14:22:34 +0000</bug_when>
    <thetext>*** Bug 498424 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2388501</commentid>
    <comment_count>5</comment_count>
    <who name="">tesfabpel</who>
    <bug_when>2025-01-10 19:42:24 +0000</bug_when>
    <thetext>(In reply to David Edmundson from comment #1)
&gt; We cannot reproduce using the steps above. If you have any more concrete
&gt; steps (video?) that could help.

In my duplicate bug (Bug #498424), I have attached a video of the problem, if it may help.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2394364</commentid>
    <comment_count>6</comment_count>
    <who name="Jonathan Cox">joncox1987</who>
    <bug_when>2025-02-01 17:41:05 +0000</bug_when>
    <thetext>I believe the vdesktop switch makes this problem more evident, but it isn&apos;t a requirement to reproduce this particular bug. Is this feature intended to capture ALL mouse buttons, such as Left and Right mouse?

As far as I know, most people who use this feature use it for Push To Talk in apps like discord or potentially from Chrome, or other similar functionality. 

Should it exclude buttons like, left mouse button, right, mouse button,  mousewheel up, and  mousewheel down to prevent focus stealing? Or does it already and somehow focus stealing happens anyways?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2394864</commentid>
    <comment_count>7</comment_count>
    <who name="Vlad Zahorodnii">vlad.zahorodnii</who>
    <bug_when>2025-02-04 13:05:02 +0000</bug_when>
    <thetext>The issue is linked to allowing X11 clients sniff keyboard events. If you set the keyboard sniffing policy to &quot;Never&quot;, the issue doesn&apos;t occur.

With the keyboard sniffing policy set to &quot;Never&quot;, the X11 client will receive no button press event after switching between virtual desktops.

With any other keyboard sniffing policy, the X11 client will receive a button press event. Most toolkits attempt to activate themselves after receiving a button press event. So what happens is that the x11 client receives a button press event, it asks kwin to activate its window, since the event has a valid timestamp and things as such, the activation request should succeed. As the result, the window will also be raised.

Not sure if it&apos;s an Xwayland bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2394913</commentid>
    <comment_count>8</comment_count>
    <who name="Jonathan Cox">joncox1987</who>
    <bug_when>2025-02-04 15:57:51 +0000</bug_when>
    <thetext>(In reply to Vlad Zahorodnii from comment #7)
&gt; The issue is linked to allowing X11 clients sniff keyboard events. If you
&gt; set the keyboard sniffing policy to &quot;Never&quot;, the issue doesn&apos;t occur.

Of course, but those of us with it on are using push to talk and similar functionality. 

&gt; With the keyboard sniffing policy set to &quot;Never&quot;, the X11 client will
&gt; receive no button press event after switching between virtual desktops.

This is true, I was suggesting that perhaps the buttons being sent contribute to the focus stealing, perhaps some buttons are being sent that are not actually being used by users for this functionality. 

&gt; With any other keyboard sniffing policy, the X11 client will receive a
&gt; button press event. Most toolkits attempt to activate themselves after
&gt; receiving a button press event. So what happens is that the x11 client
&gt; receives a button press event, it asks kwin to activate its window, since
&gt; the event has a valid timestamp and things as such, the activation request
&gt; should succeed. As the result, the window will also be raised.
&gt; 
&gt; Not sure if it&apos;s an Xwayland bug.

Do ALL buttons being sent to an app raise focus? Is it only a few buttons like Left, Right Mouse that do this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2394914</commentid>
    <comment_count>9</comment_count>
    <who name="Vlad Zahorodnii">vlad.zahorodnii</who>
    <bug_when>2025-02-04 16:01:34 +0000</bug_when>
    <thetext>&gt; Do ALL buttons being sent to an app raise focus? Is it only a few buttons
&gt; like Left, Right Mouse that do this?

In case of Qt, all buttons.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2412018</commentid>
    <comment_count>10</comment_count>
    <who name="Myra">vasilis</who>
    <bug_when>2025-03-31 17:01:09 +0000</bug_when>
    <thetext>I can</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2412021</commentid>
    <comment_count>11</comment_count>
    <who name="Myra">vasilis</who>
    <bug_when>2025-03-31 17:04:57 +0000</bug_when>
    <thetext>For me, a vdesktop switch is not even needed. It just happens if I click onto a window infront of the xwayland one (also sorry for the dupe comment did not mean to send that)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2419388</commentid>
    <comment_count>12</comment_count>
    <who name="Meteora Osterreich">semaraputraputugede</who>
    <bug_when>2025-04-27 17:12:27 +0000</bug_when>
    <thetext>Is there any progress on this issue?
This also happen in opensuse tumbleweed</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2419510</commentid>
    <comment_count>13</comment_count>
    <who name="John Kizer">john</who>
    <bug_when>2025-04-28 05:31:02 +0000</bug_when>
    <thetext>*** Bug 503368 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2423855</commentid>
    <comment_count>14</comment_count>
    <who name="Zamundaaa">xaver.hugl</who>
    <bug_when>2025-05-14 12:15:27 +0000</bug_when>
    <thetext>*** Bug 504165 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2423889</commentid>
    <comment_count>15</comment_count>
    <who name="Zamundaaa">xaver.hugl</who>
    <bug_when>2025-05-14 14:43:55 +0000</bug_when>
    <thetext>I spent some time looking into this again, but still couldn&apos;t figure out a good solution. Let&apos;s see if Xwayland developers have any ideas: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1818</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2429083</commentid>
    <comment_count>16</comment_count>
    <who name="Roke Julian Lockhart Beedell">4wy78uwh</who>
    <bug_when>2025-05-30 13:47:25 +0000</bug_when>
    <thetext>(In reply to Andrew from comment #0)

I realise that comments can&apos;t be modified, but titles can. Considering that this occurs to me despite me never having utilised a virtual desktop in my life, the scope is incorrect.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2429150</commentid>
    <comment_count>17</comment_count>
    <who name="TraceyC">kdedev</who>
    <bug_when>2025-05-30 16:56:39 +0000</bug_when>
    <thetext>Changing the title to make it clear it&apos;s application focus change that&apos;s involved. vdesktop switching isn&apos;t necessary to trigger the bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2437721</commentid>
    <comment_count>18</comment_count>
    <who name="Bug Janitor Service">bug-janitor</who>
    <bug_when>2025-07-01 12:44:36 +0000</bug_when>
    <thetext>A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/7854</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2437732</commentid>
    <comment_count>19</comment_count>
    <who name="Zamundaaa">xaver.hugl</who>
    <bug_when>2025-07-01 13:15:57 +0000</bug_when>
    <thetext>Git commit ed8c663105136790c50df611a0a294fe83c2887f by Xaver Hugl.
Committed on 01/07/2025 at 12:44.
Pushed by zamundaaa into branch &apos;master&apos;.

xwayland: don&apos;t forward left/middle/right mouse buttons to Xwayland

They&apos;re not used for global shortcuts, and make X11 apps stealing focus on
button press much more likely

M  +5    -0    src/xwayland/xwayland.cpp

https://invent.kde.org/plasma/kwin/-/commit/ed8c663105136790c50df611a0a294fe83c2887f</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2437741</commentid>
    <comment_count>20</comment_count>
    <who name="Bug Janitor Service">bug-janitor</who>
    <bug_when>2025-07-01 14:06:45 +0000</bug_when>
    <thetext>A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/7855</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2437742</commentid>
    <comment_count>21</comment_count>
    <who name="Bug Janitor Service">bug-janitor</who>
    <bug_when>2025-07-01 14:06:53 +0000</bug_when>
    <thetext>A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/7856</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2437745</commentid>
    <comment_count>22</comment_count>
    <who name="Zamundaaa">xaver.hugl</who>
    <bug_when>2025-07-01 14:27:03 +0000</bug_when>
    <thetext>Git commit 75ca3e39a1ccb6f168113df0e5f12e3b8369d523 by Xaver Hugl, on behalf of Xaver Hugl.
Committed on 01/07/2025 at 14:06.
Pushed by zamundaaa into branch &apos;Plasma/6.4&apos;.

xwayland: don&apos;t forward left/middle/right mouse buttons to Xwayland

They&apos;re not used for global shortcuts, and make X11 apps stealing focus on
button press much more likely


(cherry picked from commit ed8c663105136790c50df611a0a294fe83c2887f)

Co-authored-by: Xaver Hugl &lt;xaver.hugl@kde.org&gt;

M  +5    -0    src/xwayland/xwayland.cpp

https://invent.kde.org/plasma/kwin/-/commit/75ca3e39a1ccb6f168113df0e5f12e3b8369d523</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2437764</commentid>
    <comment_count>23</comment_count>
    <who name="Zamundaaa">xaver.hugl</who>
    <bug_when>2025-07-01 15:58:13 +0000</bug_when>
    <thetext>Git commit cbe2aa7d71bbb554cd82b7832cee45c7d7afc211 by Xaver Hugl, on behalf of Xaver Hugl.
Committed on 01/07/2025 at 14:06.
Pushed by zamundaaa into branch &apos;Plasma/6.3&apos;.

xwayland: don&apos;t forward left/middle/right mouse buttons to Xwayland

They&apos;re not used for global shortcuts, and make X11 apps stealing focus on
button press much more likely


(cherry picked from commit ed8c663105136790c50df611a0a294fe83c2887f)

Co-authored-by: Xaver Hugl &lt;xaver.hugl@kde.org&gt;

M  +5    -0    src/xwayland/xwayland.cpp

https://invent.kde.org/plasma/kwin/-/commit/cbe2aa7d71bbb554cd82b7832cee45c7d7afc211</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2437787</commentid>
    <comment_count>24</comment_count>
    <who name="Zamundaaa">xaver.hugl</who>
    <bug_when>2025-07-01 17:29:25 +0000</bug_when>
    <thetext>This is not fixed yet, the linked commits just make it less likely to trigger the issue</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>