Use Qt 5 Wayland QPA plugin to set window transparency with wl_surface - qt5

I have three Qt 5 applications that work fine independently on the BeagleBone X-15 using the Qt 5 Wayland plugin on the TI SDK image.
When I launch them, they fill the whole screen so that the first app launched is covered by the second, and the second app is covered by the third.
How can I modify the transparency of the second and third app launched, so that I can see some of the view from the first app launched?
I tried modifying the window opacity with Qt’s setWindowOpacity, but the Wayland plugin says: “Window Opacity not supported by this Plugin.”
Qt 5 on Wayland page says:
Qt 5 is structured with the Lighthouse (or Qt Platform) Abstraction, which is the windowing system and device agnostic architecture. That means Qt can load in run-time different backend plugins for different window systems as desired. For instance, an application developed on Qt could be run using "-platform xcb" and "-platform wayland" for XCB or Wayland respectively (or set the QT_QPA_PLATFORM environment variable) and should have a similar behavior on both systems, without the need to recompile.
Qt abstraction exposes to applications developers two native resources of Wayland: wl_display and wl_surface. With those types, one could access Wayland internals to deal with special cases through the interface:
void *QPlatformNativeInterface::nativeResourceForWindow(const QByteArray &resource, QWindow *window)
Getting the display global handler is quite straightforward, as shown in the following example:
QPlatformNativeInterface *native =
QGuiApplication::platformNativeInterface();
struct wl_display *wl_dpy = (struct wl_display *)
native->nativeResourceForWindow("display", NULL);
and for wl_surface:
QPlatformNativeInterface *native =
QGuiApplication::platformNativeInterface();
struct wl_surface *surface = static_cast<struct wl_surface *>(
native->nativeResourceForWindow("surface", this->windowHandle()));
If I get the handle to this wl_surface, how can I change the transparency directly?

Related

OpenGL with SRgb color space no longer works in Qt6.4+

I have an OpenGL application with a QWidget-based (no QtQuick/QML) Qt UI that I ported from Qt5 to Qt6. Most of it works fine, except that with Qt 6.4 and the Qt 6.5 beta (Qt up to 6.3 works fine!), the QSurfaceFormat color space setting no longer has an effect. I could not find any changes in the change log that should affect this. The only OpenGL-related change mentioned is to the RHI which shouldn't matter since I don't use QtQuick/QML.
In my main, before creating the QApplication instance I set up my default surface format and the Qt::AA_UseDesktopOpenGL attribute as follows:
auto surfaceFormat = QSurfaceFormat::defaultFormat();
surfaceFormat.setVersion(3, 3);
surfaceFormat.setProfile(QSurfaceFormat::CoreProfile);
surfaceFormat.setOption(QSurfaceFormat::DebugContext);
surfaceFormat.setColorSpace(QColorSpace::NamedColorSpace::SRgb);
surfaceFormat.setSamples(4);
QSurfaceFormat::setDefaultFormat(surfaceFormat);
QApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
QApplication app(argc, argv);
In the constructor of my QOpenGLWidget-derived widget, I set a compatible texture format and the update mode:
setTextureFormat(GL_SRGB8_ALPHA8);
setUpdateBehavior(QOpenGLWidget::NoPartialUpdate);
In initializeGL I set up a QOpenGLDebugLogger and load my OpenGL functions using glad Using QOpenGLFunctions is not an option as that would imply making the rendering code Qt-dependent and/or require significant changes. I also tried outputting the name of the color space reported by the widget's surface format via qDebug() and it is "SRgb" as expected.
At the beginning of paintGL I ensure GL_FRAMEBUFFER_SRGB is enabled before drawing using glEnable(GL_FRAMEBUFFER_SRGB).
In summary, it works in Qt 5.13 to Qt 6.3.2, but stops working with Qt 6.4 (the 6.5 beta adds another bug where menus have a black background but it's a beta). I am not getting any relevant OpenGL debugger messages, just a lone performance warning due to a re-compiled shader. Am I doing something wrong that just happens to work on previous versions or is this a bug that none of the many Qt users have discovered over the course of more than one minor revision? Any ideas regarding resolutions / workarounds?

Can a plugin(for safari on mac) be made windowed or windowless programmatically?

We are making a plugin for safari browser on mac.
After browsing over internet, i found that generally plugins on mac are windowless but i want a windowed plugin. Even in function NPP_SetWindow i tried to print the value of variable type(which is of type NPWindowType) as following:
NPError NPP_SetWindow(NPP instance, NPWindow * pNPWindow)
{
...
printf("....: %d",pNPWindow->type);
...
}
It prints 2 i.e its value is NPWindowTypeDrawable means windowless.
Moreover, I read the following code somewhere:
NPError NPP_New(NPMIMEType pluginType,
NPP instance, uint16 mode,
int16 argc, char *argn[],
char *argv[], NPSavedData *saved)
{
...
NPError result = NPN_SetValue(instance, NPPVpluginWindowBool, (void*)false);
}
Here it says that a plugin can be made windowless by passing value for NPPVpluginWindowBool as false in NPN_SetValue function call.
If a plugin does not make this call, it is considered a windowed plugin. But then it also says that " Plug-ins on Mac OS X are always windowless ". I haven't been sured about this yet.
My question is, will passing true value for NPPVpluginWindowBool here make plugin windowed? I haven't tried it yet.
Please suggest how to make it a windowed plugin whether programmatically or any other way around so that pNPWindow->type(in first code snippet) would also print 1 i.e NPWindowTypeWindow means windowed plugin.
Thanks.
There are no windowed plugins on Mac; there were at one time, but there aren't anymore.
Now you just have drawing models, and there are three:
CoreGraphics
CoreAnimation
InvalidatingCoreAnimation
The first two are the only ones that work on Safari. There is no way to get a window object on Mac. There used to be a couple of hacks you could use with Quartz and QuickDraw, possibly also with Carbon and CoreGraphics, but those models are long gone now.
See also:
https://developer.apple.com/library/safari/qa/qa1755/_index.html
https://wiki.mozilla.org/NPAPI:CoreGraphicsDrawing
http://www.firebreath.org/display/documentation/Event+models+and+drawing+models
How do I get an NSView in a cocoa event model NPAPI plugin

How to fake keyboard event to widget in Qt5

I have made a custom virtual keyboard widget for my kiosk application, and now comes the time when I want it to produce fake keyboard events and feed them to an QLineEdit of choice.
I do the following:
// target is the QWidget to receive the events
// k is the Qt::Key (keycode) I want to send (Testing with an 'A')
Qt::Key k=Qt::Key_A;
if(0!=target){
//According to docs this will be freed once posted
QKeyEvent * press=new QKeyEvent(QKeyEvent::KeyPress, (int )k,0);
QKeyEvent * release=new QKeyEvent(QKeyEvent::KeyRelease, (int )k,0);
//Give the target focus just to be sure it is available for input
target->setFocus();
//Post the events (queue up and let the target consume them when the eventloop gets around to the target)
QCoreApplication::postEvent ( target, press) ;
QCoreApplication::postEvent ( target, release) ;
}
I see the target widget receive focus, but there are no letters typed into the input field like I would expect. What am I doing wrong? Which assumptions are wrong?
PS: I know that this could be solved by using existing virtual keyboards or at least using the platform interface as is done in this post. In our approach we have decided to build the kayboard into the application to obtain full control over the UX and keyboard design.
Thanks!
Since no-one stepped up, I will try to provide some closure.
It turns out that Qt5 comes with a library of testing facilities called testlib. It has all sorts of goodies to facilitate easy creation, management and running of unit tests for Qt application. Among these facilities there is a set of functions for sending fake events such as fake typing of text, mouse clicks etc. It is quite comprehensive and covers many use-cases. Since this is used internally by Qt developers to test Qt itself it is also production proven code.
I simply copied what I needed from there.

Test automation - Win32 app - White/UI automation - problem with recognizing objects

I’m looking for alternative for existing tests written in QTP for my Win32 application written in Borland C++.
My candidate is White which based on UI Automation because it’s native solution,
I can create my tests using .NET/C# and easily integrate it with nUnit and Hudson.
White
http://white.codeplex.com
MS UI Automation
http://msdn.microsoft.com/en-us/library/ms747327.aspx
UI Verify
http://uiautomationverify.codeplex.com
I use UI Verify as a spy to identify properties of objects I want to find in my tests.
More or less when I can see something in the spy, I can find it using UI Automation/White.
Generally I don't have much problems with recognizing objects
but when I try to search some content inside the tab contained in Tab Panel
or try to see MenuItems of Menu bar then the problem appears.
UI Automation/UI Verify works wired. When I run UI Verify (1.0 version) I see that objects can be registered properly only then
when I set 'Focus tracking' option and click on target objects or change the keyboard cursor on them. Otherwise it's impossible to find them.
UI Verifier can show me children of my 'tab' panel then. But I can’t find them using UI Automation/White. This is example code:
Tab tab = window.Get();
ITabPage tabPage = tab.SelectedTab;
AutomationElementCollection newCol = tabPage.AutomationElement.FindAll(TreeScope.Descendants, Condition.TrueCondition);
window.Get("buttonName");
the collection is empty even though spy see the children.
Does any of you have some experience with White/UI Automation library that he/she would like to share with me?
I want to implement the tracking feature from the spy to my tests. Can you help me with that? I'm trying to study the code of UIA Verify spy. I think that there are two classes responsible for catching the objects: FocusChangeListener and FocusTracer - this is the code:
http://uiautomationverify.codeplex.com/SourceControl/changeset/view/9992#214260
http://uiautomationverify.codeplex.com/SourceControl/changeset/view/9992#214192
Requirements:
1. Windows SDK
2. .NET 3.5
3. White
4. UIA Verify code
Do you have any better alternative for White/UI Automation?
R.
Could you, the R or YoYo, put your form compiled or in source codes (preferable without the internal logic) somewhere on a file share?
I've never seen a control that'd be not caught using UI Automation if UIAVerify sees it. I saw such windows, which could be only caught with the Focus Tracking feature of UIAVerify. This case, such a window is untouchable by UI Automation search.
Regarding a control, are you sure that the controls you struggling with have the Name property? Maybe, this is a value available only by means of ValuePattern, not the Name?

How to Write OS X Finder plugin

I'm looking for a guide or sample code for writing Mac OS X Finder plugins? It would like to know how to do some simple actions:
adding image overlayers to icons
adding context menu items
listen to file changes
I found the following two resources:
Writing Contextual Menu Plugins for OS X: An outdated document from 2002 that uses the COM API targeting Mac OS X 8/9.
SCPlugin: Open-source SVN Mac application that includes a Finder plug-in.
I am tempted to review the SCPlugin code, but was hoping to find an easier sample to digest.
The Finder Icon Overlay example project represents a small and very basic but actually working example of the answer below.
https://github.com/lesnie/Finder-Icon-Overlay
I know this is so old, but some may be still interested in topic (?)
Here is what I have it done under Leopard (10.6). At first proper Finder's headers are needed. Use class-dump tool to get it. Then write your code as a SIMBL plugin (refer to documentation how to do it), swizzling some methods. For instance to draw something over icon in ListView, drawIconWithFrame: method of TIconAndTextCell method must be overriden.
Here's the code for method swizzling:
+ (void) Plugin_load
{
Method old, new;
Class self_class = [self class];
Class finder_class = [objc_getClass("TIconAndTextCell") class];
class_addMethod(finder_class, #selector(FT_drawIconWithFrame:),
class_getMethodImplementation(self_class, #selector(FT_drawIconWithFrame:)),"v#:{CGRect={CGPoint=dd}{CGSize=dd}}");
old = class_getInstanceMethod(finder_class, #selector(drawIconWithFrame:));
new = class_getInstanceMethod(finder_class, #selector(FT_drawIconWithFrame:));
method_exchangeImplementations(old, new);
}
I am overriding "drawIconWithFrame:" method with my method "FT_drawIconWithFrame:". Below is sample implementation for this method.
- (void) FT_drawIconWithFrame:(struct CGRect)arg1
{
[self FT_drawIconWithFrame:arg1];
if ([self respondsToSelector:#selector(node)]) {
if ([[[[NSClassFromString(#"FINode") nodeWithFENode:[(TNodeIconAndNameCell *)self node]] fullPath] lastPathComponent] hasPrefix:#"A"])
[myPrettyIconOverlayImage drawInRect:NSMakeRect(arg1.origin.x, arg1.origin.y, arg1.size.height, arg1.size.height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
}
Essentially it draws "myPrettyIconOverlayImage" over every icon for file with filename starts with letter "A". This logic is up to you.
Pay attention to this line: [self FT_drawIconWithFrame:arg1]; this is how to call 'super' in order to get normal icon and name etc. I know, looks weird, like loop, but actually it isn't. Then wrap in into SIMBL plugin, install SIMBL and ...run.
Due to changes in Lion some work have to be done from scratch (make new "Finder.h" file with all declarations needed in it, find proper classess and methods to override), but this technique still works.
Happy hacking!
For Yosemite (MacOS 10.10 & newer), you can use Apple's FinderSync framework, which allows Finder extensions to:
Express interest in specific folder hierarchies
Provide "badges" to
indicate the status of items inside those hierarchies
Provide dynamic
menu items in Finder contextual menus, when the selected items (or
the window target) are in those hierarchies
Provide a Toolbar Item
that displays a menu with dynamic items (even if the selection is
unrelated)
Sadly, programming a Finder plugin actually does still require getting your hands dirty with COM. If you look at the SCFinderPlugin subproject of the SCPlugin project, you will find that it follows exactly the same techniques outlined in your first link, including setting up a vtable for COM, writing AddRef/ReleaseRef functions, and so on. Writing a plugin, where you're simultaneously managing old-school Carbon memory management, COM-style memory management, and Cocoa/new-style Carbon memory management, can be an incredible pain—and that totally ignores the fact that you'll be interacting in three or more radically different APIs, with different naming conventions and calling semantics. Calling the situation hysterically poor would be a vast understatement.
On the bright side, the Finder in Mac OS X 10.6 Snow Leopard has been fully rewritten in Cocoa--and with that come vastly superior plugin interfaces. If you are lucky enough to be in a situation where you can actually only target Snow Leopard, you probably should grab an ADC Premier or higher membership, download the prerelease builds, and code against that. Besides, your plugin may not work on 10.6 anyway without a Cocoa rewrite, so it might make good sense to take a look at Snow Leopard before it gets released, regardless.
There is no official or supported plugin system for the Finder. Starting with OS X 10.6, you will need to inject code into the Finder process and override objective C methods in the Finder process.
I've done this for a proprietary project. I can tell you that the reason that there are no examples or tutorials for this is because it is a significantly difficult and time consuming development task. For this reason, there's plenty of incentive for individuals or organizations who have accomplished this to guard the specifics of their process closely.
If there's any way at all that you can accomplish your goal using the Services API, do it. Writing a Finder plugin will take you 1-2 solid months of painstaking development and reasonably deep knowledge of C and Objective-C internals.
If you're still convinced that you want do to this, grab mach_star. Good luck.
As far as I know, there's no official plugin architecture for the Finder. You may be able to add image overlays to icons through an external application without having to hook into the Finder, although it wouldn't be on the fly. I don't think there is a way to add contextual menu items aside from Folder Actions and Automator. You can also look into writing an external application to monitor File System changes using the FSEvents API.
Here's a completed solution for Finder icon badges and contextual menus in Lion and Mountain Lion using the techniques described by Les Nie.
Liferay Nativity provides a scripting bundle that will swizzle the relevant Finder methods and a Java client for setting the icons and context menus. It also includes equivalent projects for Windows and Linux.
The project is open source under LGPL, so feel free to contribute any bug fixes or improvements!
The pickings are slim; it's never been really clear to me whether Finder Plugins are actually supported. A few more leads, though:
SampleCMPlugIn - Carbon-based of course, since so is Finder. Note that almost any Finder plugin is probably going to stop working with 10.6.
Automator can save things as a "Finder plugin." It's a more supported version of what you're discussing, but of course less flexible.
To add Finder/File browser icon overlays and context menus, in a cross-platform manner, from Java, take a look at the Liferay Nativity library.
I also make mention of this in another SO post, which also contains links to Apple's 'Finder Sync' docs and API.