SWT: How to “render” a Widget in the background / into an offscreenbuffer - swt

I would very much appreciate your advice and help:
How can I render a SWT Widget/Component in the BACKGROUND (offscreenbuffer?) and get the “painted” pixels that were drawn by the Widget/Component to save them on the harddisk:
What I currently have is:
Display display = new Display();
Shell shell = new Shell(display);
// ...
MyWidgetComponent mwc = new MyWidgetComponent(shell, SWT.BORDER);
shell.open();
Image screenshot = new Image(shell.getDisplay(), shell.getBounds());
GC.copyArea(screenshot, 0, 0);
//...
Problem:
Taking the screenshot itself of the shell/widget works, but it will open a new Window in the Taskbar. That is something I do NOT want.
What I want to achieve is:
I want to run this application completely in the background as a “server application” (for example embed and call this into a servlet). So the MyWidgetComponent should be rendered pixel by pixel completely in the offscreenbuffer and I later I retrieve the pixels and save them to the harddisk or directly return the rendered widget as an image as the result of the servlet-request. (I do not want to popup any windows in a server environment, in case this might be a windows server...).
How can I achieve this. I searched a lot but havent found anything useful.
Thank you very much!!
Jan

I can't answer your question directly, but I have run into a similar problem that I struggled with: taking a screenshot of a Shell or Widget while it is obstructed from view.
Consider, for instance, window A that overlaps window B. A screenshot is made of B using your code:
Image screenshot = new Image(shellB.getDisplay(), shellB.getBounds());
GC.copyArea(screenshot, 0, 0);
My findings revealed that this could be done under Windows Vista, Windows 7 and Mac OS X (although I'm unsure about the latter). However, under Windows XP, Linux with GNOME and Linux with KDE, the screenshot contains a white area where the overlapping window obstructs the view.
I haven't found a solution for this, and I suspect that not only is this behavior platform dependent, but also fairly buggy in SWT.
I'd love to hear that I'm off the mark, though!

Related

Set the size and position of windows on current or specific screen in Swift MacOS [duplicate]

Beginner question:
I am working on a macOS App with current Xcode 8.3.3 and Swift3. I am using MASShortcut to open a window by a shortcut that has been hidden by startup.
I use the following code on the shortcut event:
NSApplication.shared().windows.last!.makeKeyAndOrderFront(nil)
NSApplication.shared().activate(ignoringOtherApps: true)
For multiple monitor setups (I have two external displays attached to my MacBook), I want to specify the screen where the window pops up. I know there is NSScreen.screens() that gives back all available screens. But how do I use it for letting my window pop up on screen 1/2/3?
Thanks a lot!
Edit: Solved with the answer of #michael-doltermann:
I can iterate over NSScreen.screens() and access for example the midX/midY coords to create a NSPoint instance to replace my window.
var pos = NSPoint()
pos.x = NSScreen.screens()![myIndex].visibleFrame.midX)
pos.y = NSScreen.screens()![myIndex].visibleFrame.midY)
self.window?.setFrameOrigin(pos)
Each screen from NSScreen.screens() has a visibleFrame property that tells you the global frame rectangle.
You can then set your window origin to fit inside the frame rect coordinates of whatever screen you want. Objective-C answers can be seen here and here.
This does mean you have to write some code to specify the preferred window. In my own app, I take the global frame rectangles for each screen and then scale them way down into a NSView to display something that looks like the Monitors pane from System Preferences:

Unity WebGL Mobile browser workaround and keyboard input fix?

Hey everyone so I read that unity doesn't really support mobile browsers for WebGL games. im using 2020.1.4.And sure enough, the game gets a bit distorted by not being scaled properly. it's like the camera is bigger so it shows on the screen that blue color. I tried some things, setting width and height to auto or removing config.devicePixelRatio = 1; as suggested by a friend but nope! still looks horrible! And if that wasn't enough the keyboard doesn't show up when clicking on form fields. i tried this one
https://github.com/eforerog/keyboardMobileWebGLUnity
which displayed an error when pressed on and this one
https://github.com/dantasulisses/WebMobileInputFix which just didn't even compile!
Any ideas, please?
I did my research and tried every plugin I could find. I used Unity 2020.3.28f1 and tested both on Android-phone and iPhone.Here is my report.
These plugins don't work:
https://unitylist.com/p/f58/Unity-webgl-inputfield
https://github.com/eforerog/keyboardMobileWebGLUnity
https://github.com/dantasulisses/WebMobileInputFix
This plugin works, but you should use different settings for IOS and Android on same input field game object. If you use "prompt", it works for IOS only, and "overlay" works for Android only. Look for documentation in page:
https://github.com/unity3d-jp/WebGLNativeInputField
And this plugin works best at the moment. Yes, it is a bit ugly though, but it works.
https://github.com/kou-yeung/WebGLInput
And there is a fix for Unity 2021 for it:
https://github.com/kou-yeung/WebGLInput/releases/tag/1.0
There's a keyboard that overlays, when using it you just need to tap the notification to access it and then click the "back" button to hide it https://play.google.com/store/apps/details?id=com.fishstix.gameboard
I made this project that simply recreates a keyboard using buttons in unity.
I implemented it in a WebGL build successfully.
https://github.com/thetimeste/WebGL-Build-Keyboard-Unity.git
I would recommend using the native js window.prompt() fields as of writing. They have great cross-platform support, allow for extra features like special characters, emojis, copy and paste etc. and are pretty easy to set up. Once (or honestly if ever) Unity adds their own reliable implementation you can easily remove this lightweight implementation.
Create a .jslib file that has a function opening a window.prompt(description, currentText)
Return the result at the end of that function back to a unity object with a recipient script
Make a derivation from Unity's event system overwriting the OnApplicationFocus(bool focus) function (leaving it empty), to fix a sneaky Chrome Android bug.
That's it. The result should look something like in this demo: https://pop.demo.neoludic.games
If you want to save some development time on a feature that really should just be native in Unity, you can also check out my plugin based on the method above. https://neoludic-games.itch.io/pop-input
I also need to enable mobile virtual keyboard for running webgl on mobile device.
I've tried the code from your mentioned url. It gives you some idea on how to do
it, but the code are totally buggy and unusable. Now I am trying to implement it
by myself.

Xvfb GTK3 transparency

I have a GTK a application which creates "transparent" windows using the following snippet of code
GdkScreen* screen = gtk_window_get_screen(window);
GdkVisual* screen_visual = gdk_screen_get_rgba_visual(screen);
gtk_widget_set_visual(GTK_WIDGET(window), screen_visual);
gtk_widget_set_app_paintable(GTK_WIDGET(window), true);
This works just fine when running on a "regular" display and the windows are correctly layered on top of each other, however when running it in an Xvfb screen, using something like this Xvfb :0 -nocursor -screen 0 1920x1080x24+32 +extension RANDR +extension XVideo +extension RENDER, GTK completely disables the transparancy and the windows end up being opaque. (resuting in only the top layer window being visible)
Is there a way to allow GTK to create this transparancy inside the headless screen?
For anyone looking into the same issue, I was missing an x composite manager for Xvfb (such as xcompmgr). When running this for the Xvfb display it works as expected.

Template10 overwriting Windows Mobile System Header

Doing some testing with Template10 I noticed that with say Hamburger Template that the windows system header/menu/whatever its called at the very top of my Windows Mobile 10 screen goes white and none of the icons (time, battery level, wifi signal etc) are visible when the light theme is used but they appear if I use the black theme.
If I use the Minimal Template then the system menu isn't visible with either the dark or light themes, its just a white band at the top.
Any idea on how to fix this? I'm running a 950XL if that matters.
That is a function of the theming and you need to account for it with the application being "mobile". The so called "System Menu" is the StatusBar
I added this to the OnInitializeAsync in the App.xaml.cs file
if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1, 0))
{
var statusBar = StatusBar.GetForCurrentView();
statusBar.BackgroundOpacity = 1;
}
and that seems to fix the problem. Not sure how portable this is as I'm just targeting Windows Phone for this app so I haven't tried testing other platforms.

Gtk menu with icons

This is critical part of my run-time created menu:
GtkWidget *menu, *menu_item;
menu = gtk_menu_new();
menu_item = gtk_image_menu_item_new_with_label("Uredi...");
//approach1 - icon don't work
//gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU));
//approach2 - icon also don't work
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), GTK_WIDGET(gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU)));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
g_signal_connect(G_OBJECT(menu_item), "button-release-event", G_CALLBACK(menu_RELEASE), (gpointer)"");
gtk_menu_attach_to_widget(GTK_MENU(menu), button, NULL);
gtk_widget_show_all(menu);
Menu works OK but this is only one "imagemenuitem" on which I see label but don't see image.
What can be wrong here?
Gtk2, Ubuntu 11.10
I'm not 100% sure, but I believe icons in menus and buttons are no longer enabled by default. You need to turn them on to make them show up.
gconftool-2 --type bool --set /desktop/gnome/interface/menus_have_icons true
Or using dconf:
dconf write /org/gnome/desktop/interface/menus-have-icons true
Hey pretty old question so probably not much use. But I was having a very similar problem with a menu not showing images (in my case it was popup menu triggered by a button).
The way I solved it was calling the
gtk_image_menu_item_set_always_show_image(menu_item,TRUE);
This solved my problem, now my images always show :D woot :) As passing in 1 (true) means it will always show.
Ref:
http://developer.gnome.org/gtk3/3.0/GtkImageMenuItem.html