keyboard focus

Answered

We still receive a few requests that claim that the keyboard focus
sometimes gets lost under some conditions. Since IDEA is a very
keyboard-intense application this is very important and needs to be
fixed before the release.

If you experience such things, please write directly to this thread on
what you do before the focus gets lost. Please don't forget to mention
your OS and Java versions as well as an IDEA build number.

Thanks.

--
Kirill Kalishev
JetBrains, Inc.
http://jetbrains.com
"Develop with pleasure!"

0
65 comments
Avatar
Permanently deleted user

I've posted a screencast showing me re-creating the (very annoying) Keyboard Focus bug:



http://www.youtube.com/watch?v=_D1XxYbvcSY

Ubuntu 9.10 - also seen frequently on Fedora 10
Linux Kernel 2.6.31-15
Java 1.6.0_15-b03
Gnome 2.28.1 (Appearance-Visual Effects : none)
Intellij IDEA (Community Edition) IC-90.193Re: keyboard focus

I'd like to add this to a ticket in YouTRACK, looking around, probably IDEA-25209 is the closest existing ticket.

http://youtrack.jetbrains.net/issue/IDEA-25209

cheers,

Roberto

0
Avatar
Permanently deleted user

I've checked out the IDEA source code and done some digging -it turns out the correct WINDOW_GAINED_FOCUS event is getting generated and placed onto the IdeEventQueue, but there's code that's been explicitly added to the processAppActivationEvents() method that specifically swallows this event! The line of code is this:

if (processAppActivationEvents(e)) return;


If the method returns true, the method returns and the event never gets dispatched to the rest of the app - so the focus is not given to the editor in the newly activated window, and you get the irritating focus-is-in-the-other-intellij-window problem.

The conditions for the processAppActivationEvents() method returning true (and therefore swallowing the event) are:

  • the event passed to it is a WindowEvent of type WINDOW_GAINED_FOCUS (id=207) - precisely the kind we're interested in
  • the Window that lost activation is unknown to Swing (getOppositeWindow() == null) - for instance, if the window was the Nautilus file browser or Firefox, any non-JVM window
  • the IDEA app is currently inactive (!appImpl.isActive()) - this is a bit of IDEA's application state set by IdeEventQueue that basically tracks if it has focus or not - this is obviously the case if you have just been looking at a non-JVM window, Nautilus, etc
  • your operating system name starts with "linux" - I mean that quite literally. See Patches.REQUEST_FOCUS_MAY_ACTIVATE_APP


So you'll only see the problem on Linux systems. It looks like all of this event-swallowing code was added in response to a linux-specific bug :

commit 30230e5f398922df8b189394f9436d590b4d3dff
Author: Kirill Kalishev <Kirill.Kalishev@jetbrains.com>
Date:   Tue Mar 31 14:46:26 2009 +0400

    linux focus stealing: do not let WINDOW_GAINED_FOCUS pass throght + fixes for FrameStateManager to make refresh/save work under this condition


It would be great to have a reference to the exact ticket, but as you can see, it appears the code was added to stop IDEA stealing focus- and has had the unfortunate effect of now making IDEA too shy about taking focus when it is given it!

To test this, I built a build of IDEA with processAppActivationEvents() still getting called but it's boolean return value getting ignored, and not causing the _dispatchEvent() method to return. Focus now works perfectly - I can have two Intellij windows up, work in window A, switch a web browser or whatever, and return to Intellij by activating window B - and focus gets correctly assigned. I haven't witnessed any focus-stealing as yet, but I'd really need the original test case for the linux-focus-stealing bug to be sure.

0
Avatar
Permanently deleted user

Wow - nice work Roberto!  

Let's hope JetBrains take notice.

0

Hello Dave,

Wow - nice work Roberto! 

Let's hope JetBrains take notice.


Already taken - the problem reported by Roberto should be fixed in the 9.0RC
build.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Avatar
Permanently deleted user

Yup - reported the issue to Kirill a few days ago, and hurrah, you can see the commit here

http://git.jetbrains.org/?p=idea/community.git;a=commit;h=868e8f7a768ee96facdf6f0ce3eaf0fac9ae193c

You should be able to download 9.0RC1 with the fix here:


http://www.jetbrains.net/confluence/display/IDEADEV/Maia+EAP

It's wonderful to see Intellij responding to so well to patch contributions  - kudos to them!

Roberto

0
Avatar
Permanently deleted user

Good work all round!

0
Avatar
Permanently deleted user

I often switch focus between a file and the terminal to run some command, like tests or whatever.

The last month or two I sometimes have to repeat my shortcut to get focus in the terminal tab. The first time it only opens but leaves the focus in the file that had focus before. So many times I switch and start typing immediately only to notice that I am writing in the file and not in the terminal - it's annoying.

I'm running IntelliJ IDEA Ultimate 16.2 on Mac OSX.

0

OS: Mac 10.10.5

PyCharm 2016.2
Build #PY-162.1237.1, built on July 20, 2016
JRE: 1.8.0_76-release-b216 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

 

When I command+tab away and then back, my cursor disappears and I can't figure out how to get it back with anything other than clicking the mouse. I am using the IdeaVIM plugin. 

 

 

1

I just discovered that if I press command+shift+/, Esc then that brings my keyboard back to life. A solution, but a frustrating one. 

-1
Avatar
Permanently deleted user

hello, 

I have focus problems, each time I began to edit my code in the Pycharm it lose the focus for a second and go back.

The Event log shows that Anaconda Python is Faulting application than follow, even if the interpreter in my project does not use the Anaconda python, but Qgis Python  (OSGeow64). 

 

Faulting application name: python.exe, version: 3.5.2150.1013, time stamp: 0x577be340
Faulting module name: ucrtbase.DLL, version: 10.0.10240.16384, time stamp: 0x559f3851
Exception code: 0xc0000409
Fault offset: 0x0000000000065a4e
Faulting process id: 0x290c
Faulting application start time: 0x01d248f98141f10f
Faulting application path: C:\Anaconda3\python.exe
Faulting module path: C:\Anaconda3\ucrtbase.DLL
Report Id: bef803f6-b4ec-11e6-8294-54424909a90c
Faulting package full name:
Faulting package-relative application ID:

 

0
Avatar
Permanently deleted user

I also have a keyboard focus issue with WebStorm 2017.2.

Whenever I press CTRL+SHIFT+N to open the Open File Search Dialog, it immediately closes again. Only when I keep CTRL-SHIFT+N pressed for a few Seconds (the Dialog opening and closing all the time) I can get the menu to open.

I noticed, that the main WebStorm window loses focus as soon as the Dialog pops up and remains in unfocused state as long as the dialog is open.

>>>>>> WebStorm Info:
WebStorm 2017.2
Build #WS-172.3317.70, built on July 14, 2017
JRE: 1.8.0_152-release-915-b5 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.11.9-300.fc26.x86_64

>>>>>> OS Info:
OS: Fedora 26
DisplayManager: Wayland

0
Avatar
Permanently deleted user

My focus is always lost after commit using OSX (El Capitan & High Sierra) and shortcuts of 10.5+

Here are the steps to reproduce this issue using only keyboard shortcuts:

  1. Make any changes to your code so you have some git changes staged.
  2. Use the shortcut Cmd+K to bring up the commit panel.
  3. Type your commit message.
  4. [ Because OSX is unable to use accessibility shortcuts inside a textarea ] Use the shortcut Cmd+Shift+Tab to blur out of the comment field and move the focus to the file viewer.
  5. [ While focused on the file viewer, accessibility is now active ] Use the shortcut Alt+I to access the click on the commit button. 
  6. After the commit is done, the focus is lost from IntelliJ. You will need to use your mouse to continue using the keyboard inside IntelliJ.

 

Workaround: Instead of using Alt+I to commit. You can use Alt+P to commit and push. After pushing your changes to the repo, the focus is regained by IntelliJ.

0

Quite an old thread, this started happening to me this week when I started using intellij through xpra, it does not happen if working directly on the machine. I am using a distro derived from debian testing in both machines.

0

Thanks for the follow up!

0
Avatar
Permanently deleted user

Steps to reproduce:
1. Focus on the editor.
2. Open "Tool Windows" menu
3. Choose any tool window (eg. Project)

Actual result:
Focus is still on the editor.

Expected:
Focus is on the chosen tool window.

Workarounds:
1. Go to chosen tool window directly using a keyboard shortcut (requires shortcut to be set for all required tool windows)
or
2. Go to any chosen tool window by a keyboard shortcut (eg. Alt+1) and then open "Tool Windows" menu and select desired tool window.

Regards,
Wojciech

0

It is reproducible for me with this scenario:

1. open file in Editor

2. open Structure tool window for this file and close it

3. switch to different file

4. open Structure tool window (wither via View menu or via the shortcut)

5 the focus stays in Editor.

Created the https://youtrack.jetbrains.com/issue/IDEA-190561 The originally described issue is never reproducible for Project tool window for me. Could you please provide information from About dialog. Did it work before for you? Is the issue with 1-5 steps reproducible for you? Thanks.

0
Avatar
Permanently deleted user

Thanks for prompt reply.
About:
    IntelliJ IDEA 2017.2.7
    Build #IU-172.4574.19, built on March 2, 2018
    Licensed to ***
    You have *** license for this version
    Subscription is active until ***
    JRE: 1.8.0_162-8u162-b12-0ubuntu0.16.04.2-b12 amd64
    JVM: OpenJDK 64-Bit Server VM by Oracle Corporation
    Linux 4.13.0-36-generic
I can see I can upgrade to 2018.1. Do you think I should do that in order for this issue to stop ocuring?
As I recall, the behavior described in my scenario provided by me has always been the same.
Yes, the scenario provided by you Andrey is reproducible for me as well.

0

>I can see I can upgrade to 2018.1. Do you think I should do that in order for this issue to stop ocuring?

Yes, it is worh checking. In any case you have 2018.1 version installed together with 2017.2.7.

0
Avatar
Permanently deleted user

I can also see an issue with the new IntelliJ Idea 2018.1.4 - after last upgrade cancelling file\class search with ESC causes the cursor to become inactive (I can still see line highlight when moving with arrows) - no cursor is visible and it's not possible to enter or remove anything, or to execute any other keyboard shortcut (like opening another window or even switching with ctrl+tab!). An explicit click on the editor is required to bring focus back making all the keyboard shortcuts available again. I've also tried to disable all installed plugins but this didn't resolve the issue

Ubuntu 17.10

IntelliJ IDEA 2018.1.4 (Ultimate Edition)
Build #IU-181.5087.20, built on May 16, 2018
Licensed to **** / ****
Subscription is active until January 29, 2019
JRE: 1.8.0_152-release-1136-b39 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-41-generic

0

Hello Sebastian,

Issue should be fixed in 2018.1.5: https://youtrack.jetbrains.com/issue/IDEA-191839

 

0
Avatar
Permanently deleted user

I lose focus when I do alt+enter and enter one of the recommendations.

I am using ubuntu 16.04 and the build is

IntelliJ IDEA 2018.1.4 (Community Edition)
Build #IC-181.5087.20, built on May 17, 2018
JRE: 1.8.0_152-release-1136-b39 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-39-generic

 

Is there a workaround?

0

I'm seeing the same problem reported by Ben VanEvery, moving out of pycharm and back causes cursor to disappears and the only way to get it back is by clicking the mouse. I am also using the IdeaVIM plugin as Ben but disabling it has no effect.

Using

Ubuntu 16.04.4 LTS

PyCharm 2018.2.1 (community edition)

Build: #PC-182.3911.33

JRE: 1.8.0_152-release-1248-b8 

JVM: OpenJDK 64-bit server VM by JetBrains s.r.o

Thanks for the help

0
Avatar
Permanently deleted user

If I Command + Shift + F search for something, then I switch to another application w/ Command + Tab, when I Command + Tab back to PyCharm, the cmd+shift+F Find in Project dialog no longer has focus, even where the cursor was before. So instead of typing in the search box like I want to, I'm blindly editing whatever file is open underneath it, which isn't expected or helpful.

 

If there's a setting I can change or if it's a bug that you can fix, that would be great news

 

 

I'm on PyCharm 2018.2.4 (Professional Edition)
Build #PY-182.4505.26, built on September 19, 2018
Licensed to PyCharm Evaluator
Expiration date: December 8, 2018
JRE: 1.8.0_152-release-1248-b8 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6

0

Hello Nathan,

Please try the latest stable version. Issue should be fixed there.

0

Hey there sorry to again revive and old thread, (let me know if there is a newer thread floating around and i can repost)

i can replicate this is 100% but it is an edge case.

MacOS Mojave version 10.14.5
PHPstorm 2019.2 build #PS-192.5728.108 july 24,2019


it occurs on phpstorm when i am using "screen share"  feature on osx to rdp to my work box. 100% repeatable (atleast for myself)

When i unfocus a phpstorm window ie go to a browser and click back onto phpstorm i am required to then click on another project window in the phpstorm terminal then back to my original window and it will again start allowing keyboard inputs. (my guess screen share maybe has a special focus event? or the stack is out of sync with screensharing and so the second window brings it back to the top?)

if you need any logs to help just let me know, but to be clear there is no "freezing" or "bugs" it just doesnt accept any key presses :D

 

thanks in advance!!

0

@Jackc

Is it reproducible without RDP? 

Seems like the following bug: 

https://youtrack.jetbrains.com/issue/IDEA-216019

Check the thread and comment inside with additional details. 

0

Thanks for the speedy reply!

just to be super dooper clear :) i can only ever produce this via "screen share" which is ~= to rdp,

when im directly on the pc (like right now) everything is fine,

i gave the "cmd ~" a crack and it doesn't cause the issue. i will try the `cmd ~` tonight when im home via screen share and see if it has the issue or not,

(where do i find these logs for phpstorm sorry i have never needed to look!)

i also just found this thread https://apple.stackexchange.com/questions/269622/macos-windows-requiring-an-explicit-click-to-make-active-before-ui-elements-ins

so i will give these things a crack tonight and let you know if any of them help, but if they do it would still suggest there is maybe a mouse focus event "missing" (my swing in the dark :) )

Thanks again!

 

0

Please sign in to leave a comment.