focus goes to the wrong window on multi window applications

Bug #1459671 reported by Guilherme Quentel Melo on 2015-05-28
24
This bug affects 5 people
Affects Status Importance Assigned to Milestone
compiz (Ubuntu)
Medium
Andrea Azzarone
Xenial
Undecided
Unassigned

Bug Description

Steps to reproduce on Ubuntu 15.04:

1 - Install eclipse with "apt-get install eclipse"
2 - Start eclipse
3 - Create a new project
4 - Create a file in the newly created project
5 - Detach any view (the task view , for example)
6 - Open the created file, or just focus on its editor
7 - Open any modal dialog (resources dialog for example (ctrl + shift + r))
8 - Close the dialog (ESC)

Expected:
- Focus goes back to the main window.

What happens:
- Focus goes to the detached view.

I think this is a unity bug because I did the same test under Fedora 22 (Gnome 3), Lubuntu and Kubuntu and all of them presented the expected behaviour.
Also, while I was editing some screenshots using gimp in multi window mode, something even stranger happened:
After doing step 8 on eclipse, the focus did not even go to eclipse, it went to one of the gimp windows.

Also I tried to disable all compiz plugins that unity does not depend on, but the behaviour kept the same.

ProblemType: Bug
DistroRelease: Ubuntu 15.04
Package: unity 7.3.2+15.04.20150420-0ubuntu1
ProcVersionSignature: Ubuntu 3.19.0-18.18-generic 3.19.6
Uname: Linux 3.19.0-18-generic x86_64
.tmp.unity.support.test.0:

ApportVersion: 2.17.2-0ubuntu1.1
Architecture: amd64
CompizPlugins: No value set for `/apps/compiz-1/general/screen0/options/active_plugins'
CompositorRunning: compiz
CompositorUnredirectDriverBlacklist: '(nouveau|Intel).*Mesa 8.0'
CompositorUnredirectFSW: true
CurrentDesktop: Unity
Date: Thu May 28 10:14:49 2015
DistUpgraded: 2015-05-07 19:41:01,746 DEBUG enabling apt cron job
DistroCodename: vivid
DistroVariant: ubuntu
DkmsStatus:
 virtualbox, 4.3.26, 3.19.0-16-generic, x86_64: installed
 virtualbox, 4.3.26, 3.19.0-18-generic, x86_64: installed
GraphicsCard:
 Advanced Micro Devices, Inc. [AMD/ATI] Caicos [Radeon HD 6450/7450/8450 / R5 230 OEM] [1002:6779] (prog-if 00 [VGA controller])
   Subsystem: Dell Radeon HD 6450 [1028:2120]
InstallationDate: Installed on 2015-05-07 (20 days ago)
InstallationMedia: Ubuntu 14.10 "Utopic Unicorn" - Release amd64 (20141022.1)
MachineType: Dell Inc. OptiPlex 7010
ProcKernelCmdLine: BOOT_IMAGE=/boot/vmlinuz-3.19.0-18-generic root=UUID=3394eb7d-5a46-4d1f-8f22-dadec1c23bc8 ro quiet splash vt.handoff=7
SourcePackage: unity
UpgradeStatus: Upgraded to vivid on 2015-05-07 (20 days ago)
dmi.bios.date: 06/10/2013
dmi.bios.vendor: Dell Inc.
dmi.bios.version: A14
dmi.board.name: 0XJT3J
dmi.board.vendor: Dell Inc.
dmi.board.version: A00
dmi.chassis.type: 6
dmi.chassis.vendor: Dell Inc.
dmi.modalias: dmi:bvnDellInc.:bvrA14:bd06/10/2013:svnDellInc.:pnOptiPlex7010:pvr01:rvnDellInc.:rn0XJT3J:rvrA00:cvnDellInc.:ct6:cvr:
dmi.product.name: OptiPlex 7010
dmi.product.version: 01
dmi.sys.vendor: Dell Inc.
version.compiz: compiz 1:0.9.12.1+15.04.20150410.1-0ubuntu1
version.ia32-libs: ia32-libs N/A
version.libdrm2: libdrm2 2.4.60-2
version.libgl1-mesa-dri: libgl1-mesa-dri 10.5.2-0ubuntu1
version.libgl1-mesa-dri-experimental: libgl1-mesa-dri-experimental N/A
version.libgl1-mesa-glx: libgl1-mesa-glx 10.5.2-0ubuntu1
version.xserver-xorg-core: xserver-xorg-core 2:1.17.1-0ubuntu3
version.xserver-xorg-input-evdev: xserver-xorg-input-evdev 1:2.9.0-1ubuntu2
version.xserver-xorg-video-ati: xserver-xorg-video-ati 1:7.5.0-1ubuntu2
version.xserver-xorg-video-intel: xserver-xorg-video-intel 2:2.99.917-1~exp1ubuntu2.1
version.xserver-xorg-video-nouveau: xserver-xorg-video-nouveau 1:1.0.11-1ubuntu2build1
xserver.bootTime: Thu May 28 08:47:13 2015
xserver.configfile: default
xserver.errors:

xserver.logfile: /var/log/Xorg.0.log
xserver.version: 2:1.17.1-0ubuntu3
xserver.video_driver: radeon

Related branches

Guilherme Quentel Melo (gqmelo) wrote :
tags: added: eclipse gimp
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in unity (Ubuntu):
status: New → Confirmed
Guilherme Quentel Melo (gqmelo) wrote :

I tested with Gimp alone in multi window mode. The problem occurs in Ubuntu, but not on Lubuntu.

1 - Open Gimp on multi window mode
2 - Open any dialog from menu (Open file for example)
3 - Press Esc

Expected (happens on Lubuntu):
- Focus goes back to the main window (the window with the menu)

What happens:
- Focus goes to any other Gimp window

Guilherme Quentel Melo (gqmelo) wrote :

I did some other tests using "Always on Top" feature.

1 - Open Gimp on multi window mode
2 - Open a terminal
3 - Set the terminal as always on top
4 - Go back to Gimp and press Ctrl + O (Open dialog)
5 - Press Esc

Now focus goes sometimes to Gimp main window, but keep doing opening and closing the dialog and eventually it always goes to the "always on top" terminal.

1 - Open Gimp on multi window mode
2 - Open two dock windows (if you there is none already)
3 - Let's say you have Layers and Toolbox windows open. Move the Toolbox over the Layers window.
4 - Click on the main window.
5 - Press Ctrl + O (Open dialog)
6 - Press Esc

Focus goes to the Toolbox window

7 - Move the Layers window over the Toolbox window, so it gets on front of it.
8 - Click on the main window.
9 - Press Ctrl + O (Open dialog)
10 - Press Esc

Focus goes to the Layers window.

So, considering all the tests I made, it seems that when you close any window, the window manager chooses to focus the most on top window even if this window is from another application, which is hardly ever the expected result. I would expect to always focus on the last window.

Changed in unity (Ubuntu):
importance: Undecided → Medium
Changed in unity:
importance: Undecided → Medium
status: New → Confirmed
Guilherme Quentel Melo (gqmelo) wrote :

I decided to investigate this problem and checked out the source code. After a lot of debugging I found out that the call to focus the wrong window is coming from compiz CompScreenImpl::focusDefaultWindow which comes from this code on compiz event.cpp :

  else if (event->xfocus.window == privateScreen.rootWindow())
  {
      /* Don't ever let the focus go to the root
       * window except in grab cases
       *
       * FIXME: There might be a case where we have to
       * handle root windows of other screens here, but
       * the other window managers should handle that
       */

      if (event->xfocus.detail == NotifyDetailNone ||
   (event->xfocus.mode == NotifyNormal &&
    event->xfocus.detail == NotifyInferior))
      {
   privateScreen.orphanData.activeWindow = None;

   if (event->xfocus.detail == NotifyDetailNone ||
       (event->xfocus.mode == NotifyNormal &&
        event->xfocus.detail == NotifyInferior))
   {
       screen->focusDefaultWindow ();
   }
      }
  }

The FIXME comment is very suspicious but I have no idea what would be the solution.
I'm adding an attachment file with the stacktrace.

Guilherme Quentel Melo (gqmelo) wrote :

This is the stacktrace obtained with gdb when the wrong call to focus is made.

Guilherme Quentel Melo (gqmelo) wrote :

Just to update, I removed the "screen->focusDefaultWindow ();" line and recompiled compiz and I've been using it for more than a month and this solved the problem and I could not observe any side effect. So I think this code could probably be removed at least when using unity.

Alex Baggott (alex-baggott) wrote :

As part of the big bug review for 16.04 LTS, I have tested this on 15.10 and the bug is still there.

tags: added: desktop-bugscrub-triaged
summary: - focus goes to the wrong window after a modal dialog is closed
+ focus goes to the wrong window on multi window applications
tags: added: desktop-trello-import
tags: removed: desktop-trello-import
Andrea Azzarone (azzar1) on 2016-07-06
no longer affects: unity

Hi Andrea,

Which Ubuntu version is not affected any more? I still get this behaviour on 16.04

Andrea Azzarone (azzar1) wrote :

Hi Guilherme,

unity (Ubuntu) is still targeted and this is the project we track. I'm planning to work on this bug this week.

> unity (Ubuntu) is still targeted and this is the project we track. I'm planning to work on this bug this week.

Great! Let me know if I can help

Andrea Azzarone (azzar1) on 2016-07-28
no longer affects: unity (Ubuntu)
Changed in compiz (Ubuntu):
importance: Undecided → Medium
assignee: nobody → Andrea Azzarone (azzar1)
status: New → In Progress
Andrea Azzarone (azzar1) wrote :

Hi Guilherme,
I just proposed a fix, thanks for the debugging. You've been very helpful!

Great! I tested the patch and confirm it fixes the problem.
Thanks

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package compiz - 1:0.9.13.0+16.10.20160801.3-0ubuntu1

---------------
compiz (1:0.9.13.0+16.10.20160801.3-0ubuntu1) yakkety; urgency=medium

  [ Andrea Azzarone ]
  * focusDefaultWindow: focus Most Recently Used (MRU) window and
    fallback to the top window in case MRU list is not available. (LP:
    #1073488, #1459671)

 -- Marco Trevisan (Treviño) <mail@3v1n0.net> Mon, 01 Aug 2016 13:25:42 +0000

Changed in compiz (Ubuntu):
status: In Progress → Fix Released

Hello Guilherme, or anyone else affected,

Accepted compiz into xenial-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/compiz/1:0.9.12.2+16.04.20160801.3-0ubuntu1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, and change the tag from verification-needed to verification-done. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in compiz (Ubuntu Xenial):
status: New → Fix Committed
tags: added: verification-needed

I can confirm that this fixes all problems reported on this bug (Eclipse and Gimp).
The following packages are installed:

$ dpkg -l | grep compiz
ii compiz 1:0.9.12.2+16.04.20160801.3-0ubuntu1 all
ii compiz-core 1:0.9.12.2+16.04.20160801.3-0ubuntu1 amd64
ii compiz-gnome 1:0.9.12.2+16.04.20160801.3-0ubuntu1 amd64
ii compiz-plugins:amd64 1:0.9.12.2+16.04.20160801.3-0ubuntu1 amd64
ii compiz-plugins-default:amd64 1:0.9.12.2+16.04.20160801.3-0ubuntu1 amd64
ii compizconfig-settings-manager 1:0.9.12.2+16.04.20160526-0ubuntu1 all
ii libcompizconfig0:amd64 1:0.9.12.2+16.04.20160801.3-0ubuntu1 amd64
ii python-compizconfig:amd64 1:0.9.12.2+16.04.20160526-0ubuntu1 amd64

tags: added: verification-done
removed: verification-needed
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package compiz - 1:0.9.12.2+16.04.20160801.3-0ubuntu1

---------------
compiz (1:0.9.12.2+16.04.20160801.3-0ubuntu1) xenial; urgency=medium

  [ Andrea Azzarone ]
  * Don't activate expo if not needed (1x1 setup) (LP: #1606254)
  * Don't crash if gsettings key is not found. Default value will be
    used. (LP: #1044662)
  * focusDefaultWindow: focus Most Recently Used (MRU) window and
    fallback to the top window in case MRU list is not available. (LP:
    #1073488, LP: #1459671)

  [ Marco Trevisan (Treviño) ]
  * Unity MigrationScript: sync gsettings on exit, and only use dconf on
    failure (LP: #1605011)

 -- Marco Trevisan (Treviño) <mail@3v1n0.net> Mon, 01 Aug 2016 13:41:42 +0000

Changed in compiz (Ubuntu Xenial):
status: Fix Committed → Fix Released

The verification of the Stable Release Update for compiz has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.