Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 469525 - GTK often reports null from Display.getActiveShell() while the application has focus
Summary: GTK often reports null from Display.getActiveShell() while the application ha...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 286244 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-06-05 16:21 EDT by Stefan Xenos CLA
Modified: 2020-08-15 15:26 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Xenos CLA 2015-06-05 16:21:39 EDT
Bug description:

On GTK, Display.getActiveShell() often returns null on GTK while Eclipse is in the foreground. 


Consequence:

This is causing problems in many areas, but most particularly with command handlers, since the command handler framework uses Display.getActiveShell() to supply the command handler with its shell. The consequence of initializing the active shell incorrectly is incorrectly parented and positioned dialog boxes, missing keybindings, and other issues.


Analysis:

I believe the entire process used SWT/gtk for determining the active shell is incorrect. It sets/clears the active shell pointer based on incoming focus events.

This is inconsistent with Windows, which asks the OS for the active Shell on demand (and will therefore never report a null active shell while the application is active).


Suggested solution:

GTK allows the window with focus to be queried using a loop over gtk_window_list_toplevels () which invokes gtk_window_is_active () to test if the window is active. Both APIs should work as far back as GTK 2.4. This approach is described here:

http://stackoverflow.com/questions/4166169/get-active-gtk-window-in-python
Comment 1 Stefan Xenos CLA 2015-06-05 16:22:18 EDT
Note that a very similar issue was reported in bug 41400. I believe this technique would address that bug, too.
Comment 2 Stefan Xenos CLA 2015-06-05 16:28:14 EDT
Note that if we want to maintain our own activeShell pointer separately from what's reported from GTK, we could still do so (if this were necessary for some reason to make the behavior more consistent between windows and GTK). The "search for active window" algorithm could be used to determine the new window with focus when opening shells or under focus changes and we could save the result in Display.activeShell if we want.

This way we could still have control over when Display.activeShell updates but there would be no need to update it asynchronously or to have it set to null temporarily during focus changes.
Comment 3 Xi Yan CLA 2018-08-23 13:08:20 EDT
*** Bug 286244 has been marked as a duplicate of this bug. ***
Comment 4 Eclipse Genie CLA 2020-08-15 15:26:36 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.