Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 244274

Summary: SWT.NO_FOCUS on Linux (Gtk) is inconsistent with Windows
Product: [Eclipse Project] Platform Reporter: Feng Yao Yao <fengyaoy>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: minor    
Priority: P3 CC: ericwill, pinnamur, Silenio_Quarti, snorthov
Version: 3.4.2Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:
Attachments:
Description Flags
Patch v01 none

Description Feng Yao Yao CLA 2008-08-15 02:46:53 EDT
Build ID: 3.4

Steps To Reproduce:
1. Following is the test code for SWT.NO_FOCUS:

	public static void main(String[] args) {
		Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setText("NO_FOCUS Example");
		final Shell hoverShell = new Shell(shell, SWT.TOOL | SWT.NO_FOCUS | SWT.NO_TRIM);
		hoverShell.setSize(10, 10);
		hoverShell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
		shell.addMouseTrackListener(new MouseTrackAdapter(){
			public void mouseEnter(MouseEvent event)
			{
				hoverShell.setLocation(100, 100);
				hoverShell.setVisible(true);
			}
			
			public void mouseExit(MouseEvent event)
			{
				hoverShell.setVisible(false);
			}
		});
		shell.open();
		while(!shell.isDisposed()){
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}	
2. On Windows, hovershell would not take focus when it is shown.
On Linux (Gtk), hovershell takes focus.
Comment 1 Steve Northover CLA 2008-08-15 11:35:36 EDT
Try using SWT.ON_TOP instead of SWT.NO_FOCUS.  SWT.NO_FOCUS is badly named.  It means "no mouse focus when I click".
Comment 2 Steve Northover CLA 2008-08-15 11:38:26 EDT
On possibility to avoid this platform difference in the future is to make Shell.setVisible() set focus for all shells except SWT.ON_TOP ones.  This would make the behavior consistent.
Comment 3 Feng Yao Yao CLA 2008-08-17 21:56:25 EDT
Yes, ON_TOP can prevent the shell getting focus when it is shown. But this bit makes the shell shown above all the top level windows belonging to other application. This is not what we want.

For example, task manager window is open and run above case (with ON_TOP bit), this hover shell is shown above the task manager window. This can be reproduced on both Windows and Linux.
Comment 4 Praveen CLA 2009-12-10 03:04:05 EST
Created attachment 154205 [details]
Patch v01

The patch allows the shell created with NO_FOCUS flag to be opened/visible without taking focus.
Comment 5 Eric Williams CLA 2016-10-18 12:15:23 EDT
This bug is still reproducible, not sure of its urgency though. Re-assigning to platform inbox.
Comment 6 Eric Williams CLA 2018-08-31 14:57:57 EDT
This seems to have been a GTK2 issue, I can't reproduce it on GTK3 using Wayland or X11 anymore.