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

Bug 529327

Summary: [GTK3] [hidpi] Dragging and dropping editor tabs does not work when "Scale for menu and title bar" (Unity/Ubuntu Display Settings) is other than "1"
Product: [Eclipse Project] Platform Reporter: Janis Danisevskis <werwurm>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: VERIFIED FIXED QA Contact: Sravan Kumar Lakkimsetti <sravankumarl>
Severity: normal    
Priority: P3 CC: jan.public, lorenzo.bettini, loskutov, lshanmug, lufimtse, michael.weirauch, niraj.modi, sravankumarl
Version: 4.7.2Keywords: triaged
Target Milestone: 4.7.3Flags: niraj.modi: review+
sravankumarl: review+
Hardware: PC   
OS: Linux   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=506326
https://git.eclipse.org/r/117088
https://git.eclipse.org/r/117089
https://git.eclipse.org/c/platform/e.git/commit/?id=fe40b71bf454aca078e8f0be9f2171b9803901cd
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=34bfe2b05ea6e6107d7a1aeae76e639811959eb5
https://bugs.eclipse.org/bugs/show_bug.cgi?id=531169
Whiteboard:
Bug Depends on:    
Bug Blocks: 517055    
Attachments:
Description Flags
Proposed patch hiDPI DND bug none

Description Janis Danisevskis CLA 2017-12-31 13:53:40 EST
I am using Eclipse on a 4K laptop screen with Ubuntu 16.04.1. When I set the option "Scale for menu and title bar" in the "Displays" dialog to "2", dragging and dropping editor tabs breaks.

Sometimes a tab is actually dragged but then it is the wrong one.
My suspicion is that the logic of the drag start event does not respect the scaling factor correctly and selects the wrong tab or no tab at all.

I am not familiar with the Eclipse code base, nor do I know how this scaling factor is exposed to applications. But if someone can give me some pointers I'd be happy to investigate further.

This bug is really annoying to me because I would like to make better use of my high res screen and have multiple editor tabs next to each other. But I cannot arrange them due to the broken drag and drop. If I set the scale factor to 1 however menu items and other elements become unreadably small.
Comment 1 Leo Ufimtsev CLA 2018-01-02 09:58:28 EST
Thank you for the bug report.

Do you know if this bug occurs only on linux, or on Windows/OSX as well?
Comment 2 Janis Danisevskis CLA 2018-01-20 12:09:18 EST
I just tried it on Windows 10 with a scale factor of 250%. It worked flawlessly. So it seems to be an issue only on Linux. I cannot test it on MacOS.

This is off topic, but it could help me address this issue myself:
Is there a good introduction to Eclipse platform development? All I found was outdated or only plugin development is covered. Basically, how do I build Eclispe Oxygen from source and run it?
Comment 3 Andrey Loskutov CLA 2018-01-20 12:13:14 EST
(In reply to Janis Danisevskis from comment #2)
> This is off topic, but it could help me address this issue myself:
> Is there a good introduction to Eclipse platform development? All I found
> was outdated or only plugin development is covered. Basically, how do I
> build Eclispe Oxygen from source and run it?

https://wiki.eclipse.org/Platform-releng/Platform_Build
Comment 4 Janis Danisevskis CLA 2018-02-06 00:51:37 EST
Thanks Andrew, for the link.

I investigated a little and here is what I found:

Assume a scale factor of 2.

When I start the drag event in the top left quarter of the leftmost tab, it works. If the event is started in the top right quarter of the leftmost tab, the second to the left tab is dragged. If the event is started in the bottom half of the tab, nothing happens.

I instrumented the code a little and took screen shots and measured pixels with gimp.

Consider a physical and a virtual coordinate system. Functions like Control.getBounds() return coordinates in the virtual system. What I measure with gimp I'll call the physical system. If the scaling factor is 1 both are essentially the same. But at scaling factor of 2, WxH in the virtual system corresponds to 2Wx2H in the physical.

So getBounds and also Display.map() operate on the virtual system. And this is also what gets used in CTabFolder.getItem(int pos) to determine the drag source. Interestingly, the coordinates in the DragDetectEvent are in physical coordinates. Which is why things go awry.

With this information I actually tried dragging something else, like a file in the Package Explorer, and yes, this is also broken. I just never used it.

I tracked the DragDetectEvent back to the handleEvent function. I would guess that it is actually generated in the native GTK layer, and I would assume that the bug is to be found somewhere in the glue between the libgtk and the eclipse swt. And it boils down to a missing application of the scale factor in the drag detect case. But I did not go further for now.

Can someone who is actually familiar with the code base take it from here?
Comment 5 Lakshmi P Shanmugam CLA 2018-02-06 01:00:55 EST
This looks related to Bug 506326.
Comment 6 Janis Danisevskis CLA 2018-02-08 01:53:01 EST
Created attachment 272580 [details]
Proposed patch hiDPI DND bug

I think I found the the root cause of the issue. As opposed to sendMouseEvent, sendDragEvent does not subject the event coordinates to DPIUtil.autoScaleDown.
This patch scales the coordinates at the two call sites gtk_button_press_event and gtk_motion_notify_event. It is somewhat inconsistent that sendMounseEvent scales the coordinates which sendDragEvent does not. However, sendDragEvent is also called from dragDetect which passes scaled coordinates.

This patch is untested. I would have loved to test this patch but, I can for the life of me not get the Maven build system to compile org.eclipse.swt without replacing the build artifact with the baseline. I have never used Maven before, and I have not figured out a usable development cycle. This was the most frustrating experience I ever had with a build system. I must say the link https://wiki.eclipse.org/Platform-releng/Platform_Build explains how to build eclipse from source. But for getting started with development it is completely useless.
Comment 7 Lakshmi P Shanmugam CLA 2018-02-08 03:16:12 EST
(In reply to Janis Danisevskis from comment #6)
> Created attachment 272580 [details] [diff]
> Proposed patch hiDPI DND bug
> 
Thanks for contributing the patch!

Can you please provide the patch via gerrit? For setup details, please see: https://wiki.eclipse.org/Gerrit

For testing:
- If the problem is reproducible in self-hosted Eclipse, then you can test it in the Eclipse instance launched from your workspace which has the patch.

- Another option is to replace the SWT fragment in the Eclipse/plugins folder and test it on Eclipse. 
First setup SWT from Git (https://www.eclipse.org/swt/git.php).
Since the patch involves only java changes you don't have to rebuild the native libraries. Just export the SWT fragment (org.eclipse.swt.linux.gtk.x86_64.v<build-id>.jar) with the matching build id version and replace it in your Eclipse/plugins and test the fix.

Please post here if you have any questions.
Comment 8 Eclipse Genie CLA 2018-02-09 20:00:13 EST
New Gerrit change created: https://git.eclipse.org/r/117088
Comment 9 Eclipse Genie CLA 2018-02-09 20:04:28 EST
New Gerrit change created: https://git.eclipse.org/r/117089
Comment 10 Janis Danisevskis CLA 2018-02-09 20:40:48 EST
I have uploaded a patch to master and R4_7_maintenance for review.

I still don't quiet get how to I can test this. What does self-hosted Eclipse mean, and what is a fragment?

I tried to build org.eclipse.swt with the following command

mvn -Pbuild-individual-bundles -Dtycho.baseline.replace=none package -Dnative=gtk.linux.x86_64

But then I always get something like this, indicating that the resulting .jar does not have my changes.

[WARNING] MavenProject: org.eclipse.swt:org.eclipse.swt:3.106.3-SNAPSHOT @ /home/janis/eclipse/eclipse-source/eclipse.platform.releng.aggregator/eclipse.platform.swt/bundles/org.eclipse.swt/pom.xml: baseline and build artifacts have same version but different contents
   no-classifier: different
      META-INF/ECLIPSE_.RSA: present in baseline only
      META-INF/ECLIPSE_.SF: present in baseline only

[INFO] MavenProject: org.eclipse.swt:org.eclipse.swt:3.106.3-SNAPSHOT @ /home/janis/eclipse/eclipse-source/eclipse.platform.releng.aggregator/eclipse.platform.swt/bundles/org.eclipse.swt/pom.xml
    The main artifact has been replaced with the baseline version.

For some other bundles the strategy of replacing the jar in the plugin directory worked but not for swt, because maven does not like me.

I guess there should be a way to change something, save, have eclipse autobuild, restart and see the changes, right? I mean this is an IDE. There must be a convenient way to develop this :-)
Comment 11 Janis Danisevskis CLA 2018-02-10 18:22:01 EST
I finally managed to get a build of R4_7_maintenance going that contained my patch. I can confirm that it fixes the issue.
Comment 12 Lakshmi P Shanmugam CLA 2018-02-12 00:20:19 EST
(In reply to Janis Danisevskis from comment #10)
Thanks for creating the gerrit patch.

>What does self-hosted Eclipse mean
Sorry, it means the Eclipse launch configuration [1] which used for testing and debugging the plugins/code in your workspace. You can launch another Eclipse instance from your workspace and it'll use the plugins from your workspace. 

[1] https://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.pde.doc.user%2Fguide%2Ftools%2Flaunchers%2Feclipse_application_launcher.htm&cp=4_3_3_0
Comment 13 Lakshmi P Shanmugam CLA 2018-02-12 00:22:09 EST
Sravan, can you please review the patch? Also, please verify if it fixes Bug 506326 as well?
Comment 14 Sravan Kumar Lakkimsetti CLA 2018-02-12 07:43:25 EST
(In reply to Lakshmi Shanmugam from comment #13)
> Sravan, can you please review the patch? Also, please verify if it fixes Bug
> 506326 as well?

The patch works well and it fixes Bug 506326 as well.
Comment 16 Sravan Kumar Lakkimsetti CLA 2018-02-14 03:32:30 EST
Verified in I20180213-2000
Comment 18 Sravan Kumar Lakkimsetti CLA 2018-02-14 03:42:20 EST
Merged to master and R4_7_maintenance
Comment 19 Lakshmi P Shanmugam CLA 2018-02-15 02:35:03 EST
*** Bug 506326 has been marked as a duplicate of this bug. ***
Comment 20 Niraj Modi CLA 2018-02-16 00:45:49 EST
Verified in MBuild id: M20180214-1700 using Ubuntu 16.04 at 1.75 OS zoom settings.