Bug 530152 - [GTK] Real shell transparency feature
Summary: [GTK] Real shell transparency feature
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
: 285026 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-01-23 03:45 EST by Ivan Morelli CLA
Modified: 2020-12-13 04:22 EST (History)
9 users (show)

See Also:


Attachments
Result of the test (3.34 KB, image/png)
2018-05-03 04:23 EDT, Ivan Morelli CLA
no flags Details
use swt to display result (246.30 KB, patch)
2020-01-11 00:08 EST, Allen Jiang CLA
no flags Details | Diff
use swt to display (246.30 KB, image/jpeg)
2020-01-11 00:10 EST, Allen Jiang CLA
no flags Details
the source png image (4.36 KB, image/png)
2020-01-11 00:12 EST, Allen Jiang CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Morelli CLA 2018-01-23 03:45:05 EST
Hi SWT developers,
Would be great to have a Shell transparency feature in SWT.
I mean: I know we can set Alpha on Shell, but using alpha everything is affected, the shell it self and all its content. But most of the time, in my experience, you want to set the transparency only for the background and not for the widgets on it.

Is that possible? Are there some restrictions that prevent an implementation for that? Does it require a lot of time?


I would really appreciate any reply on this.

Thank you in advance
Comment 1 Eric Williams CLA 2018-05-02 15:41:37 EDT
Have you tried setBackground() with SWT.COLOR_TRANSPARENT?
Comment 2 Ivan Morelli CLA 2018-05-03 04:23:20 EDT
Created attachment 273897 [details]
Result of the test
Comment 3 Ivan Morelli CLA 2018-05-03 04:23:46 EDT
Hi Eric,
Thank you for your reply. Yes I tryed on Windows 8.1 not luck, I didn't try in other environments. This is the code I tried to use:

package helloWorld;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class SWTHelloWorld {

	public static void main (String [] args) {
		Display display = new Display ();
		Shell shell = new Shell(display,SWT.NO_BACKGROUND);
		shell.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));

		shell.addPaintListener(new PaintListener() {

			@Override
			public void paintControl(PaintEvent arg0) {
				GC gc=arg0.gc;
				gc.setAlpha(0);
				gc.fillRectangle(shell.getClientArea());

			}
		});

		Text helloWorldTest = new Text(shell, SWT.NONE);
		helloWorldTest.setText("Hello World SWT");
		helloWorldTest.pack();

		shell.setSize(200,200);
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}

And in the attachments you can see the result.
Did I miss something?
Comment 4 Eric Williams CLA 2018-05-03 11:01:19 EDT
(In reply to Ivan Morelli from comment #3)
> And in the attachments you can see the result.
> Did I miss something?

I ran the snippet on GTK3 and it looks the same as on Windows. I presume the desired output is to have the shell completely transparent (i.e., only the Text visible and everything else will be whatever you have on your desktop)?
Comment 5 Ivan Morelli CLA 2018-05-03 12:06:47 EDT
Yes, that's what I expect to see...
As far as I understood, with the current SWT version, there is no way to achieve that.

I don't know if that is difficult to implement and if would be possible to have it in the next release, what do you think about it?

By the way, When is it planned to release the new SWT version?
Comment 6 Ivan Morelli CLA 2018-05-03 12:09:31 EDT
I forgot to say that I have also tested this version of the code with the same result:


public class SWTHelloWorld {

	public static void main (String [] args) {
		Display display = new Display ();
		Shell shell = new Shell(display);
		shell.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));

		
		Text helloWorldTest = new Text(shell, SWT.NONE);
		helloWorldTest.setText("Hello World SWT");
		helloWorldTest.pack();

		shell.setSize(200,200);
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}
Comment 7 Eric Williams CLA 2018-05-03 12:29:00 EDT
(In reply to Ivan Morelli from comment #6)
> I forgot to say that I have also tested this version of the code with the
> same result:
> 
> 
> public class SWTHelloWorld {
> 
> 	public static void main (String [] args) {
> 		Display display = new Display ();
> 		Shell shell = new Shell(display);
> 		shell.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
> 
> 		
> 		Text helloWorldTest = new Text(shell, SWT.NONE);
> 		helloWorldTest.setText("Hello World SWT");
> 		helloWorldTest.pack();
> 
> 		shell.setSize(200,200);
> 		shell.open ();
> 		while (!shell.isDisposed ()) {
> 			if (!display.readAndDispatch ()) display.sleep ();
> 		}
> 		display.dispose ();
> 	}
> }

Same result for me as well.



(In reply to Ivan Morelli from comment #5)
> Yes, that's what I expect to see...
> As far as I understood, with the current SWT version, there is no way to
> achieve that.
> 
> I don't know if that is difficult to implement and if would be possible to
> have it in the next release, what do you think about it?
> 
> By the way, When is it planned to release the new SWT version?

I don't know how hard it would be to implement, I haven't tried it out. Also an effort like this would presumably need a Windows and Mac version as well -- not sure the native functionality is there.

The next planned release of SWT is with Photon (4.8), which is late June.
Comment 8 Ivan Morelli CLA 2018-05-03 12:45:43 EDT
I have a mac and a windows machine. I'm a java developer, but no experience with native development. It would be an honor to help you to implement that... 

Not sure what do you mean for native functionality, but in both operating systems (windows and mac) I suppose this is possible, these are two example of transparent windows:

On mac:
https://ravingroo.com/1282/how-to-transparent-terminal-window-profile-mac-os-x/

On win:
https://winaero.com/blog/make-command-prompt-transparent-in-windows-10/

As you can see, only the background of the window is transparent, but the text is opaque.

Did I miss something?
Comment 9 Ivan Morelli CLA 2018-05-03 13:18:42 EDT
On a second check, the example I proposed reletive to windows OS, seems to work as SWT works now, and searching on internet it seems not possible to achieve this on windows, unless using some tricks:
https://www.codeguru.com/csharp/csharp/cs_controls/tutorials/article.php/c12323/Creating-NonTransparent-Controls-on-a-SemiTransparent-Window.htm


I would like to be contradicted... by anyone
Comment 10 Eric Williams CLA 2018-05-03 14:10:03 EDT
I would have to do some research to see if it's possible on Linux. If it is, it's definitely something I'd be happy to implement sometime in the future.
Comment 11 Ivan Morelli CLA 2018-05-04 04:43:16 EDT
Thank you Eric.
I really appreciate that.
If there's anything I can do to help, just let me know.

Just one small question, in order to see the progress of this, I would like to be notified on the evolution of the status, but even if I'm in the CC list, I'm not receiving the notification emails,(I have also verified the spam folder in my gmail account). It's really annoying to come back here every time in order to verify the status. Is that normal?
Comment 12 Eric Williams CLA 2018-05-04 08:51:59 EDT
(In reply to Ivan Morelli from comment #11)
> Thank you Eric.
> I really appreciate that.
> If there's anything I can do to help, just let me know.
> 
> Just one small question, in order to see the progress of this, I would like
> to be notified on the evolution of the status, but even if I'm in the CC
> list, I'm not receiving the notification emails,(I have also verified the
> spam folder in my gmail account). It's really annoying to come back here
> every time in order to verify the status. Is that normal?

That shouldn't be the case...are you sure you didn't accidentally check the "Ignore Bug Mail" box?
Comment 13 Ivan Morelli CLA 2018-05-04 12:15:37 EDT
Yes, The checkbox is not checked and my email address is in the list with other two, of which one I supppse is yours...
Comment 14 Eric Williams CLA 2018-05-04 12:30:24 EDT
(In reply to Ivan Morelli from comment #13)
> Yes, The checkbox is not checked and my email address is in the list with
> other two, of which one I supppse is yours...

Check your email settings just to be sure (Bottom of the page, Preferences -> Email Preferences). If everything looks the way it's supposed to, email the webmaster: webmaster@eclipse.org

Last option would be to create an account using a different email address, but this is a last resort.
Comment 15 Ivan Morelli CLA 2018-09-20 08:16:28 EDT
Hi,
Is there a possibility to see this feature in the new release?
Can somebody point me to some guidelines/tutorial about how to contribute, I would like to contribute to make this feature available for the SO on which that's possible...
Would be nice to know which file have to be changed to accomplish that feature.

Thank you in advance to everyone can help me.
Comment 16 Eric Williams CLA 2018-09-20 09:43:42 EDT
(In reply to Ivan Morelli from comment #15)
> Hi,
> Is there a possibility to see this feature in the new release?
> Can somebody point me to some guidelines/tutorial about how to contribute, I
> would like to contribute to make this feature available for the SO on which
> that's possible...
> Would be nice to know which file have to be changed to accomplish that
> feature.
> 
> Thank you in advance to everyone can help me.

From the GTK side of things, this work is not planned until later (probably late next year at the earliest), as we have GTK4, and other bugs to fix.

If you'd like to contribute a patch, please see the SWT beginner's guide: https://wiki.eclipse.org/SWT/Beginners

There is also further development documentation here: https://wiki.eclipse.org/SWT/Devel
Comment 17 Ivan Morelli CLA 2018-09-20 10:00:38 EDT
Thank you Eric,
I will have a look on those resources.
Comment 18 Eric Williams CLA 2019-03-20 14:28:44 EDT
*** Bug 285026 has been marked as a duplicate of this bug. ***
Comment 19 Allen Jiang CLA 2020-01-10 23:57:40 EST
(In reply to Ivan Morelli from comment #8)
> I have a mac and a windows machine. I'm a java developer, but no experience
> with native development. It would be an honor to help you to implement
> that... 
> 
> Not sure what do you mean for native functionality, but in both operating
> systems (windows and mac) I suppose this is possible, these are two example
> of transparent windows:
> 
> On mac:
> https://ravingroo.com/1282/how-to-transparent-terminal-window-profile-mac-os-
> x/
> 
> On win:
> https://winaero.com/blog/make-command-prompt-transparent-in-windows-10/
> 
> As you can see, only the background of the window is transparent, but the
> text is opaque.
> 
> Did I miss something?

I have meet the same requirement,has the feature implemented?
my requirement is to display a image on Shell ,to except the shell's background is transparency and the image of png formate need to display
Comment 20 Allen Jiang CLA 2020-01-11 00:08:13 EST
Created attachment 281449 [details]
use swt to display result

I have meet the same requirement,has the feature implemented?
my requirement is to display a image on Shell ,to except the shell's background is transparency and the image of png formate need to display
Comment 21 Allen Jiang CLA 2020-01-11 00:10:55 EST
Created attachment 281450 [details]
use swt to display
Comment 22 Allen Jiang CLA 2020-01-11 00:12:02 EST
Created attachment 281451 [details]
the source png image
Comment 23 Allen Jiang CLA 2020-01-11 00:20:05 EST
I have upload the result snapshot of test using swt and the source image ,and my code is as follows:

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

public class LoginUI extends Shell {
	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			LoginUI shell = new LoginUI(display);
			shell.open();
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the shell.
	 * 
	 * @param display
	 */
	public LoginUI(Display display) {
		super(display, SWT.NO_TRIM);
		this.setBackgroundMode(SWT.INHERIT_DEFAULT);
		createContents();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("SWT Application");
		Image image = SWTResourceManager.getImage(this.getClass(), "/resource/assets/login/login_bg.png");
		Region region = new Region();
		final ImageData imageData = image.getImageData();
		if (imageData.alphaData != null) {
			Rectangle pixel = new Rectangle(0, 0, 1, 1);
			for (int y = 0; y < imageData.height; y++) {
				for (int x = 0; x < imageData.width; x++) {
					 if (imageData.getAlpha(x, y) >0) {
					pixel.x = imageData.x + x;
					pixel.y = imageData.y + y;
					region.add(pixel);
					 }
				}
			}
		} else {
			ImageData mask = imageData.getTransparencyMask();
			Rectangle pixel = new Rectangle(0, 0, 1, 1);
			for (int y = 0; y < mask.height; y++) {
				for (int x = 0; x < mask.width; x++) {
					if (mask.getPixel(x, y) != 0) {
						pixel.x = imageData.x + x;
						pixel.y = imageData.y + y;
						region.add(pixel);
					}
				}
			}
		}
		this.setRegion(region);
		final Shell shell = this;
		Listener listener = new Listener() {
			/** The x/y of the MouseDown, relative to top-left of the shell. */
			int startX, startY;

			@Override
			public void handleEvent(Event e) {
				if (e.type == SWT.MouseDown) {
					Point p = shell.toDisplay(e.x, e.y);
					Point loc = shell.getLocation();
					startX = p.x - loc.x;
					startY = p.y - loc.y;
				}
				if (e.type == SWT.MouseMove && (e.stateMask) != 0) {
					Point p = shell.toDisplay(e.x, e.y);
					p.x -= startX;
					p.y -= startY;
					shell.setLocation(p);
				}
				if (e.type == SWT.Paint) {
					//e.gc.setAdvanced(true);
					//e.gc.setAntialias(SWT.ON);
					e.gc.drawImage(image, imageData.x, imageData.y);
				}
			}
		};

		this.addListener(SWT.Paint, listener);
		shell.addListener(SWT.KeyDown, listener);
		shell.addListener(SWT.MouseDown, listener);
		shell.addListener(SWT.MouseMove, listener);
		shell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TRANSPARENT));
		setSize(450, 419);

	}

}