Bug 160964 - size and bounds are buggy on Linux/gtk
Summary: size and bounds are buggy on Linux/gtk
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.3   Edit
Hardware: PC Linux
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
: 239201 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-10-14 15:57 EDT by Anton Keks CLA
Modified: 2018-06-21 10:37 EDT (History)
7 users (show)

See Also:


Attachments
Size and window bug (42.54 KB, image/png)
2015-10-22 06:33 EDT, Leonid Krashenko CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Keks CLA 2006-10-14 15:57:09 EDT
This bug also exists in version 3.2 as well as in latest SWT (3.3M2).

The bug seems to be related with window decorations when setting/getting of window sizes.

When calling setSize() for the first time, it works correctly. However, for the second time (applied to any other window) the height of the window becomes larger. It is always reproducible with all my code.

Another problem is with bounds/clientArea (possibly related):

shell.setSize(new Point(350, 423)); // appears correctly
Point p = shell.getSize(); // returns 350,423
Rectangle r = shell.getClientArea(); // returns 395,345,0,0 - wrong!
Rectangle r = shell.getBounds(); // returns 423,350,0,0
Comment 1 Steve Northover CLA 2006-10-17 21:07:37 EDT
Looks like a dup?
Comment 2 Anton Keks CLA 2006-12-25 13:10:59 EST
Can't find the dup bug unfortunately...

Is it really that hard to fix? 
Maybe I could provide more information on the issue?
Comment 3 Anton Keks CLA 2007-01-02 16:49:37 EST
OK, guys, according to this discussion:
http://dev.eclipse.org/mhonarc/lists/platform-swt-dev/msg00599.html
you seem to be pretty well aware of the issue. 

After debugging SWT GTK code a little bit, I have found out that this initial trimming guess is actual cause of the bug:

Display.java:
	/* Initial Guesses for Shell Trimmings. */
	int borderTrimWidth = 4, borderTrimHeight = 4;
	int resizeTrimWidth = 6, resizeTrimHeight = 6;
	int titleBorderTrimWidth = 5, titleBorderTrimHeight = 28;
	int titleResizeTrimWidth = 6, titleResizeTrimHeight = 29;
	int titleTrimWidth = 0, titleTrimHeight = 23;

I understand the problem, however, maybe it would be a good idea to adjust the size of the shell as soon as the new trim values are known?

This could be achieved by changing the size again in the Shell.adjustTrim() using the newly set values returned by the gdk_window_get_frame_extents().

However, in my case it always returns {0,0}, so all the windows are smaller the first time and then get larger when created again with the same parameters :-(
Comment 4 Anton Keks CLA 2007-01-02 17:29:09 EST
I made a mistake stating that gdk_window_get_frame_extents() returns {0,0}.

Actually, it returns the same as the following:
	int width = OS.GTK_WIDGET_WIDTH (shellHandle);
	int height = OS.GTK_WIDGET_HEIGHT (shellHandle);

And results in zeros:
	OS.gdk_window_get_frame_extents (window, rect);
	int trimWidth = Math.max (0, rect.width - width);
	int trimHeight = Math.max (0, rect.height - height);

Secondly, it seems to be a bigger problem on Compiz window manager (ver 0.0.13 from FC6). I have just tried it with Metacity and the difference between first and second window sizes are less noticable.
Comment 5 Steve Northover CLA 2007-01-02 18:23:01 EST
BG isn't around to look at this right now.  However, after reading it closely, I don't think there's much we can do.  There is no API to get the trim from the window manager.  At one point in time, we had code that resized the window to the right size, after it was first displayed using a bad guess.  This caused the window to flash and look bad.  We decided that it was better that the size be wrong the first time.

Any thoughts?  I'm sorry but this is looking like WONTFIX.
Comment 6 Steve Northover CLA 2007-01-02 18:23:54 EST
Should say: "There is no API to get the trim from the window manager, before a window has been opened."
Comment 7 Anton Keks CLA 2007-07-04 15:39:20 EDT
The initial cause of the problem is actually too Windows-centric API :-)
By this I mean that window size is set together with border, while in X world window sizes are usually set excluding borders (Window manager later adds whatever is needed).

Anyway, a workaround does exist that tries to remember the size of the border after first window is displayed and then reuse it.

However, getting the size of border is broken with Compiz (probably a compiz bug?). Recently I have noticed the following code in the Shell.java:

       /*
	* Bug in GTK.  gdk_window_get_frame_extents() fails for various window
	* managers, causing a large incorrect value to be returned as the trim.
	* The fix is to ignore the returned trim values if they are too large.
	*/
	if (trimWidth > MAXIMUM_TRIM || trimHeight > MAXIMUM_TRIM) {
		display.ignoreTrim = true;
		return;
	}

Maybe trimWidth and trimHeight should be checked for 0 as well? At least this will produce consistent behavior for all windows.
Comment 8 Steve Northover CLA 2007-07-04 15:58:33 EDT
Can you confirm that checking for zero fixes this for Compiz?
Comment 9 Anton Keks CLA 2007-07-09 13:13:33 EDT
"Fixes" would be a wrong word.

It just makes window sizes to be more consistent, meaning that if you open the same window (with the same setSize()) several times, it will have the same size every time. 

Currently windows become larger after the first time they are opened.

Comment 10 Steve Northover CLA 2007-07-16 12:52:52 EDT
Bogdan, can you run Compiz?
Comment 11 Bogdan Gheorghe CLA 2007-07-17 17:29:33 EDT
I'll track it down and install it and get back with my findings.
Comment 12 Andrew Robinson CLA 2008-07-24 15:05:06 EDT
FYI, this can still be reproduced with Ubuntu using Compiz and eclipse 3.3.2 swt/jface jars.
Comment 13 Bogdan Gheorghe CLA 2008-07-24 17:19:22 EDT
The bug doesn't require Compiz - I can reproduce this on RHEL5. There is a X Window atom - "NET_REQUEST_FRAME_EXTENTS" - that might be able to supply the initial size of the window. If this is the case; we can get rid of the hardcoded values.
Comment 14 Bogdan Gheorghe CLA 2008-07-24 17:20:08 EDT
*** Bug 239201 has been marked as a duplicate of this bug. ***
Comment 15 Leonid Krashenko CLA 2015-10-22 06:33:07 EDT
Created attachment 257438 [details]
Size and window bug
Comment 16 Leonid Krashenko CLA 2015-10-22 06:34:38 EDT
On KDE 4.12.4 in commit diff window dialog this bug is very annoying :-(
Comment 17 Eric Williams CLA 2018-05-11 15:14:48 EDT
This should be investigated for 4.9.
Comment 18 Eric Williams CLA 2018-06-21 10:37:04 EDT
I can't reproduce this issue anymore, the size and bounds returned are correct, as well as the client area. The compare window bug was fixed elsewhere.