Community
Participate
Working Groups
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
Have you tried setBackground() with SWT.COLOR_TRANSPARENT?
Created attachment 273897 [details] Result of the test
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?
(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)?
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 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 (); } }
(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.
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?
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
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.
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?
(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?
Yes, The checkbox is not checked and my email address is in the list with other two, of which one I supppse is yours...
(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.
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.
(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
Thank you Eric, I will have a look on those resources.
*** Bug 285026 has been marked as a duplicate of this bug. ***
(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
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
Created attachment 281450 [details] use swt to display
Created attachment 281451 [details] the source png image
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); } }