<?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>157219</bug_id>
          
          <creation_ts>2008-02-05 17:01:18 +0000</creation_ts>
          <short_desc>Unpredictable focus when switching desktops on a multi-head system</short_desc>
          <delta_ts>2024-05-14 21:38:19 +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>multi-screen</component>
          <version>unspecified</version>
          <rep_platform>Gentoo Packages</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>UNMAINTAINED</resolution>
          
          <see_also>https://bugs.kde.org/show_bug.cgi?id=324782</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Bernd Schmidt">bernds_cb1</reporter>
          <assigned_to name="KWin default assignee">kwin-bugs-null</assigned_to>
          <cc>cpigat242</cc>
    
    <cc>johnny</cc>
    
    <cc>kde</cc>
    
    <cc>kde</cc>
    
    <cc>non7top</cc>
    
    <cc>postix</cc>
    
    <cc>riaasm</cc>
    
    <cc>sogerc1</cc>
          
          <cf_commitlink></cf_commitlink>
          <cf_versionfixedin></cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>577902</commentid>
    <comment_count>0</comment_count>
    <who name="Bernd Schmidt">bernds_cb1</who>
    <bug_when>2008-02-05 17:01:19 +0000</bug_when>
    <thetext>Version:            (using KDE 3.5.8)
Installed from:    Gentoo Packages
Compiler:          gcc-4.1 gentoo&apos;s 4.1
OS:                Linux

I have two monitors, which show X displays :0.0 and :0.1.  There are two instances of kwin running, apparently handling the displays separately.  Each of the displays has 12 virtual desktops with a konsole and possibly other windows on each of them.

When switching desktops with Ctrl-F1..Ctrl-F12, the focus often (but unpredictably) switches to the other monitor, rather than a window on the desktop you&apos;ve just switched to getting the focus.  This is highly annoying; it means you can&apos;t quickly look through all virtual desktops on one screen by hitting Ctrl-F1, Ctrl-F2, etc. successively, because at some point the keypresses go to the wrong screen.

I don&apos;t know exactly how focus is handled in X, especially with multiple monitors.  I&apos;ve looked at the code in kwin&apos;s workspace.cpp, and developed the following theory:
Switching desktops is implemented by unmapping all windows from the current desktop, then mapping all windows on the new one.  It appears that when there&apos;s more than one kwin running, they can fight for the right to focus a window.  My theory is that when all windows from the previous desktop on one screen are unmapped (thus losing focus), the kwin running on the other screen tries to set the focus to one of the windows showing on its current desktop.

Based on this, I&apos;ve created a patch which just calls focusToNull before unmapping the windows in a desktop switch, and this seems to take care of the problem.  I&apos;ll be attaching the patch once I&apos;m out of this bugzilla wizard.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>577904</commentid>
    <comment_count>1</comment_count>
      <attachid>23431</attachid>
    <who name="Bernd Schmidt">bernds_cb1</who>
    <bug_when>2008-02-05 17:02:07 +0000</bug_when>
    <thetext>Created attachment 23431
A patch which fixes the problem on my system.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>577914</commentid>
    <comment_count>2</comment_count>
    <who name="Lubos Lunak">l.lunak</who>
    <bug_when>2008-02-05 17:40:34 +0000</bug_when>
    <thetext>The patch does not look right. Can you figure out where the focus changes come from? KWin on the inactive screen should not do anything at all when working with the active one. If you use e.g. &apos;kdDebug() &lt;&lt; getenv(&quot;DISPLAY&quot;) &lt;&lt; &quot;:&quot; &lt;&lt; kdBacktrace();&apos; in Workspace::requestFocus()  (and possibly before all calls to XSetInputFocus() ), it should show where the unwanted activation comes from.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>578006</commentid>
    <comment_count>3</comment_count>
    <who name="Bernd Schmidt">bernds_cb1</who>
    <bug_when>2008-02-05 23:27:31 +0000</bug_when>
    <thetext>That&apos;s just giving me stuff like

kwin: :0.1:[
0: /usr/kde/3.5/lib/libkdecore.so.4(_Z11kdBacktracei+0x45) [0xb7b59255]
]

which isn&apos;t very enlightening.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>578007</commentid>
    <comment_count>4</comment_count>
    <who name="Bernd Schmidt">bernds_cb1</who>
    <bug_when>2008-02-05 23:28:18 +0000</bug_when>
    <thetext>BTW, what doesn&apos;t look right about the patch?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>578432</commentid>
    <comment_count>5</comment_count>
    <who name="Lubos Lunak">l.lunak</who>
    <bug_when>2008-02-07 15:28:42 +0000</bug_when>
    <thetext>You probably have things compiled without any debug support at all, kdBacktrace() works best with &apos;-rdynamic&apos; in CXXFLAGS and &apos;-D__KDE_HAVE_GCC_VISIBILITY=0&apos; in cmake flags. You may try that or some other ways like more debug outputs to find out where it comes from.

As for comment #4, the patch moves the X focus where it should not be, even if temporarily, and I&apos;d prefer to find the correct problem and fix it instead of just patching it over.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>578698</commentid>
    <comment_count>6</comment_count>
    <who name="Bernd Schmidt">bernds_cb1</who>
    <bug_when>2008-02-08 15:44:16 +0000</bug_when>
    <thetext>BTW, I forgot to mention in my previous posts that I&apos;m using click-to-focus; that may or may not make a difference.

I think I managed to capture the right backtrace.  Sequence of events: I activated a a window on display :0.1, then hit one of the Ctrl-Fn keys to switch desktops.  Desktops got switched on :0.1, but a window on display :0.0 got activated.  The following backtrace came out of the kwin for display :0.0 in this instant:

kwin: :0.0:[
0: /local/src/kdelibs-3.5.8/kdecore/.libs/libkdecore.so.4.2.0(_Z11kdBacktracei+0x36) [0xb7e5e29e]
1: /local/src/kdelibs-3.5.8/kdecore/.libs/libkdecore.so.4.2.0(_Z11kdBacktracev+0x28) [0xb7e5e4ac]
2: /local/src/kdebase-3.5.8/kwin/./.libs/libkdeinit_kwin.so(_ZN12KWinInternal9Workspace12requestFocusEPNS_6ClientEb+0x24) [0xb7d2bbe6]
3: /local/src/kdebase-3.5.8/kwin/./.libs/libkdeinit_kwin.so(_ZN12KWinInternal9Workspace18activateNextClientEPNS_6ClientE+0x2cd) [0xb7d2bff3]
4: /local/src/kdebase-3.5.8/kwin/./.libs/libkdeinit_kwin.so(_ZN12KWinInternal9Workspace14workspaceEventEP7_XEvent+0xbb0) [0xb7d1c238]
5: /local/src/kdebase-3.5.8/kwin/./.libs/libkdeinit_kwin.so(_ZN12KWinInternal11Application14x11EventFilterEP7_XEvent+0x28) [0xb7d0cc56]
6: /usr/qt/3/lib/libqt-mt.so.3 [0x44393174]
7: /usr/qt/3/lib/libqt-mt.so.3(_ZN12QApplication15x11ProcessEventEP7_XEvent+0x228) [0x443a2a38]
8: /usr/qt/3/lib/libqt-mt.so.3(_ZN10QEventLoop13processEventsEj+0x4c1) [0x443b3b51]
9: /usr/qt/3/lib/libqt-mt.so.3(_ZN10QEventLoop9enterLoopEv+0x50) [0x444193a0]
10: /usr/qt/3/lib/libqt-mt.so.3(_ZN10QEventLoop4execEv+0x26) [0x44419226]
11: /usr/qt/3/lib/libqt-mt.so.3(_ZN12QApplication4execEv+0x1f) [0x444027af]
12: /local/src/kdebase-3.5.8/kwin/./.libs/libkdeinit_kwin.so(kdemain+0x620) [0xb7d0da64]
13: lt-kwin [0x80486c6]
14: /lib/libc.so.6(__libc_start_main+0xe0) [0xb74889c0]
15: lt-kwin [0x8048621]
]

As for the focus moving where it should not be - this happens anyway, as a side effect, when we unmap all windows from a virtual desktop, doesn&apos;t it?  So the patch I proposed just moves it explicitly, earlier.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>579598</commentid>
    <comment_count>7</comment_count>
    <who name="Lubos Lunak">l.lunak</who>
    <bug_when>2008-02-11 13:17:40 +0000</bug_when>
    <thetext>SVN commit 773568 by lunakl:

Disable resetting focus from root window as it seems to cause focus
problems with multihead for an unknown reason.
CCBUG: 157219



 M  +2 -1      events.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&amp;revision=773568
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>579600</commentid>
    <comment_count>8</comment_count>
    <who name="Lubos Lunak">l.lunak</who>
    <bug_when>2008-02-11 13:18:45 +0000</bug_when>
    <thetext>Because of the imminent 3.5.9 tagging I&apos;ve committed a hack for the multihead case that probably will avoid the problem.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>579616</commentid>
    <comment_count>9</comment_count>
    <who name="Bernd Schmidt">bernds_cb1</who>
    <bug_when>2008-02-11 14:19:15 +0000</bug_when>
    <thetext>This seems to work so far, with no ill effects.  From an engineering point of view my earlier patch still seems preferrable to me, since it has the same behaviour on all systems and is therefore more testable.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>593949</commentid>
    <comment_count>10</comment_count>
    <who name="Magnus Johansson">magnus</who>
    <bug_when>2008-04-13 15:17:21 +0000</bug_when>
    <thetext>Just to add to this...

This annoying behaviour seems to be present in 4.0.3 as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1197712</commentid>
    <comment_count>11</comment_count>
    <who name="Vladimir Berezhnoy">non7top</who>
    <bug_when>2011-12-10 21:18:10 +0000</bug_when>
    <thetext>This bug is still valid on 4.7.2.
Steps to reproduce:
1. Launch yakuake on :0.0, may also open some more windows on :0.0
2. Focus some window on :0.0
3. Press yakuake hotkey, yakuake then opens as expected, press hotkey once more to hide yakuake
4. At this point focus jumps to second screen :0.1, while it should return to where it was befor yakuake got opened.
I should note that some times 4 hapens only after repeating 3 second time in a row.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1197750</commentid>
    <comment_count>12</comment_count>
    <who name="Thomas Lübking">thomas.luebking</who>
    <bug_when>2011-12-10 23:56:52 +0000</bug_when>
    <thetext>Still or again?
The workaround from comment #7 is absent and indeed the other KWin instance recognizes a FocusIn on *its* rootWindow and so thinks it&apos;s time to activate something (in doubt a dummy)
Since this is usually slight faster than the post-window-hiding stuff the kwin instance on the yakuake screen does, the other kwin wins.

We must eg. figure which screen has the mouse and only act on it or avoid KWin2 getting rootwindow FocusIn&apos;s when KWin1 closes a client.

Also see bug #256242 (and be aware that there&apos;s not much pace on multihead development - eg. i only actiavted it to check some bugs, didn&apos;t like it at all)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1237943</commentid>
    <comment_count>13</comment_count>
    <who name="">riaasm</who>
    <bug_when>2012-03-19 04:22:46 +0000</bug_when>
    <thetext>I think this problem might be the same as bug 237260 which is similar but with alt-tab. I described it in more detail in bug 274369 with a reproduction recipe which also seems to work when trying to look through your virtual desktops with Ctrl+F1 to Ctrl+F2 and so on.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1238634</commentid>
    <comment_count>14</comment_count>
    <who name="Thomas Lübking">thomas.luebking</who>
    <bug_when>2012-03-21 00:43:12 +0000</bug_when>
    <thetext>*** Bug 134677 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1317106</commentid>
    <comment_count>15</comment_count>
    <who name="Thomas Lübking">thomas.luebking</who>
    <bug_when>2012-11-20 23:44:50 +0000</bug_when>
    <thetext>bump to self to look at when checking for the other bug next time</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2319624</commentid>
    <comment_count>16</comment_count>
    <who name="David Edmundson">kde</who>
    <bug_when>2024-05-14 21:38:19 +0000</bug_when>
    <thetext>Multihead is no longer supported</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>23431</attachid>
            <date>2008-02-05 17:02:07 +0000</date>
            <delta_ts>2008-02-05 17:02:07 +0000</delta_ts>
            <desc>A patch which fixes the problem on my system.</desc>
            <filename>kwin.diff</filename>
            <type>text/plain</type>
            <size>377</size>
            <attacher name="Bernd Schmidt">bernds_cb1</attacher>
            
              <data encoding="base64">LS0tIC4va3dpbi93b3Jrc3BhY2UuY3BwfgkyMDA3LTEwLTA4IDExOjUxOjMyLjAwMDAwMDAwMCAr
MDIwMAorKysgLi9rd2luL3dvcmtzcGFjZS5jcHAJMjAwOC0wMi0wNSAxNTo0NzowOC4wMDAwMDAw
MDAgKzAxMDAKQEAgLTExODgsNiArMTE4OCw4IEBACiAgICAgICAgIHJldHVybiBmYWxzZTsKIAog
ICAgIGNsb3NlQWN0aXZlUG9wdXAoKTsKKyAgICBmb2N1c1RvTnVsbCgpOworCiAgICAgKytibG9j
a19mb2N1czsKIC8vIFRPRE8gICAgUV9BU1NFUlQoIGJsb2NrX3N0YWNraW5nX3VwZGF0ZXMgPT0g
MCApOyAvLyBtYWtlIHN1cmUgc3RhY2tpbmdfb3JkZXIgaXMgdXAgdG8gZGF0ZQogICAgIFN0YWNr
aW5nVXBkYXRlc0Jsb2NrZXIgYmxvY2tlciggdGhpcyApOwo=
</data>

          </attachment>
      

    </bug>

</bugzilla>