Lazarus

Programming => Widgetset => QT => Topic started by: El Salvador on November 15, 2022, 12:08:08 pm

Title: QT6 and new stuff
Post by: El Salvador on November 15, 2022, 12:08:08 pm
Hi,

@zeljko I'm porting my component ASuiteComps in QT6 (precisely global hotkey) and I am seeing that they have removed QX11Extras from QT. In QT5 I needed QX11Info_display, but now I need to use nativeInterface (and QNativeInterface) method from QGuiApplication https://doc-snapshots.qt.io/qt6-dev/qguiapplication.html#nativeInterface(https://code.qt.io/cgit/qt/qtbase.git/commit/?id=f5203eeada83bbe8e316a5188e24636af3e83b09).

I saw that this code is missing in libqt6pas bindings. Is there any hope it could be added?
Title: Re: QT6 and new stuff
Post by: zeljko on November 15, 2022, 12:39:52 pm
Yes, feel free to create patch
Title: Re: QT6 and new stuff
Post by: zeljko on November 15, 2022, 12:45:37 pm
hmmmm.....there's warning about QNativeInterface: "Warning: There are no source or binary compatibility guarantees for the native interface APIs, meaning that an application using these interfaces is only guaranteed to work with the Qt version it was developed against."
Title: Re: QT6 and new stuff
Post by: zeljko on November 15, 2022, 01:09:51 pm
I've added TQtWidgetSet.x11Display:PDisplay
https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/1751d3c2edc6197773d5ad48e1086b238b411613
So, no need to implement risky QNativeInterface.
Title: Re: QT6 and new stuff
Post by: El Salvador on November 16, 2022, 02:49:15 pm
Hey thanks! I should have adapted the code to qt6, but I still have to figure out why the hotkeys only work in the program window and not globally.

Anyway, if I will complete it, is there any hope for including this code (see https://github.com/salvadorbs/AsuiteComps/tree/main/library/platform/unix/QGHotkeyHookPas/src) in libqt5pas & libqt6pas for Lazarus 2.4?
Title: Re: QT6 and new stuff
Post by: zeljko on November 16, 2022, 03:01:56 pm
That looks interesting, but why include QX11Info and Xlib ?
1.It can work with xcb only included.
2.If it's suposed to work on win32 and mac then ifdefs for platforms should be added, so native events can be passed to the lcl.
3.It's pitty to have keypress only events from nativeevent hook.
Title: Re: QT6 and new stuff
Post by: El Salvador on November 16, 2022, 04:46:25 pm
Indeed, you are right. Unfortunately I am very inexperienced on QT and c(++).

Quote
why include QX11Info and Xlib ?
Removed. Thanks. https://github.com/salvadorbs/AsuiteComps/commit/45f47680f97363d01efea01d5e5bc10ffb2f5b44#diff-da8349f220705517018be2ff4d677f21b2b15a0db3baeb3948b500e70b470c72

Quote
2.If it's suposed to work on win32 and mac then ifdefs for platforms should be added, so native events can be passed to the lcl.
I would like to, but I don't have the time and knowledge to expand on windows & mac. Also, for my software, I only needed the Linux & QT combination (on windows, I use the win32 widgetset) and capture global hotkey.

Quote
3.It's pitty to have keypress only events from nativeevent hook.
What other events were you thinking about?
Title: Re: QT6 and new stuff
Post by: zeljko on November 16, 2022, 05:01:08 pm
Actually, you're grabbing only keyPress event on xcb...why not other events if nativeeventfilter hook is installed ?
Title: Re: QT6 and new stuff
Post by: El Salvador on November 16, 2022, 05:26:38 pm
For global hotkey, you need only key press event (XCB_KEY_PRESS). Maybe you mean it's better to bring the event to pascal and handle it via LCL?
Title: Re: QT6 and new stuff
Post by: zeljko on November 16, 2022, 05:34:11 pm
Yes, not only key events, but others to, just pass native event to lcl and handle it there.
Title: Re: QT6 and new stuff
Post by: El Salvador on November 16, 2022, 06:20:31 pm
Ok, now I understand what you meant. But in this case, I wouldn't know how to translate the actual C code into pascal.

Code: [Select]
        auto *genericEvent = static_cast<xcb_generic_event_t *>(message);

        //Pass to FPC only XCB_KEY_PRESS
        if (genericEvent->response_type == XCB_KEY_PRESS) {
          Q_GHotkey_hook* sender = this;

          // Pass keyCode and Modifiers to FPC
          xcb_key_press_event_t *keyEvent = static_cast<xcb_key_press_event_t *>(message);
          uint8_t keyCode = (uint8_t) keyEvent->detail;
          uint16_t keyState = (uint8_t) keyEvent->state;
And pass eventType as QByteArray and message as ? in lcl?
Title: Re: QT6 and new stuff
Post by: zeljko on November 16, 2022, 11:07:26 pm
See here about static_cast, reinterpret_cast and dynamic_cast ...
https://stackoverflow.com/questions/52648049/what-is-the-equivalent-of-dynamic-cast-in-delphi
you need translation of xcb headers and event structs
Title: Re: QT6 and new stuff
Post by: El Salvador on November 18, 2022, 05:26:37 pm
Done. See commit https://github.com/salvadorbs/AsuiteComps/commit/d87adccddc90be486ccac9a8b547301c8760f511

Anyway for a reason I still don't understand, the key_press_event event is not caught by the nativeEventFilter when the program has no focus in qt6 (in qt5, it works everywhere). Between qt5 and qt6, only how the display is retrieved changes. I will continue to investigate.
Title: Re: QT6 and new stuff
Post by: zeljko on November 18, 2022, 07:36:44 pm
Probably you (me) should get Display from xcb_get_connection() and then see what happens.
EDIT: should be xcb_connect() to get xcb_connection structure but I'm wrong about it - you cannot get Display from xcb_connection_t.
XOpenDisplay() is used only if we mix xlib and xcb calls. So, xcb_connect() is proper way to get connection and then use it  in all xcb functions.
Title: Re: QT6 and new stuff
Post by: El Salvador on November 28, 2022, 12:45:10 am
Nothing. All my attempts with xcb have failed. When I have focus on a different window than my lcl program, the lib doesn't catch the xcb_key_press event. This only in qt6. Quite strange.
Title: Re: QT6 and new stuff
Post by: zeljko on November 28, 2022, 08:21:16 am
In that case you should check Qt bugtracker, but that could be because of security (especially wayland and xwayland) - key snooping IMO.
Title: Re: QT6 and new stuff
Post by: El Salvador on November 28, 2022, 10:50:12 am
Nope. For reference, I'm using QHotkey (https://github.com/Skycoder42/QHotkey) and it works everywhere. This lib uses xdg and get display from QNativeInterface. Honestly I don't think display can affect that much. As soon as I have time, I'll make another attempt with xlib-xdg (maybe something changed in the calls for x_grab_key?) and only xdg.

Quote
could be because of security (especially wayland and xwayland) - key snooping IMO.
Mmm... I'm using X11, so I guess it's more of a development error than a security issue. On wayland, we can use xdg-desktop-portal (it is fresh news https://www.youtube.com/watch?v=rfXP9gltk3A), but I highly doubt I'll have time to put myself to work on it. For me, it will already be a success to have this functionality on x11 (gtk2, gtk3, qt5 and qt6) out of the box.
Title: Re: QT6 and new stuff
Post by: zeljko on November 28, 2022, 02:00:14 pm
Qt6 is still fresh lib, maybe it's bug in bindings, but Qt6 have a lot of bugs atm, so problem can be anywhere.
Title: Re: QT6 and new stuff
Post by: El Salvador on November 30, 2022, 01:41:31 pm
Oh my gosh. Today I discovered that QX11Info (https://www.qt.io/blog/qt-extras-modules-in-qt-6) still exists in qt6, but it has been moved to private header. In fact KGlobalAccel still uses it! https://github.com/KDE/kglobalaccel/blob/788890556134f3cb9cbfc1fa498b90f06ca0c779/src/runtime/plugins/xcb/kglobalaccel_x11.cpp#L21

So in my lib I reintroduced the QX11Info_display method to retrieve the display and... it works. Everywhere. But I really don't think it's a stable solution for the future. Using qt internals is a bad thing, imho.

However I don't understand the difference between XOpenDisplay() and QX11Info::display().

P.S.: I don't want to annoy you, but all my posts are for tracking for anyone who runs into the same problem as me.
Title: Re: QT6 and new stuff
Post by: zeljko on November 30, 2022, 04:02:51 pm
I guess that QX11Info_display() is not XOpenDisplay() but xcb_connection, so that makes difference.
Title: Re: QT6 and new stuff
Post by: zeljko on December 16, 2022, 03:43:39 pm
New Qt6 CBindings version is commited. I've added QGuiApplication_x11Display() and QGuiApplication_xcbConnection(), now our app and Qt uses same descriptor for Display, so you don't need to use private stuff from Qt. Bindings version is 6.2.3.
Note for future versions: in Qt6-6.5 there will be QNativeInterface::WaylandApplication, I'll add it to our 6.2 based bindings but via versioning in source, so if Qt6 version >= 6.5 we'll be able to use wayland struct members, so our bindings will be 6.2 compatibile and returned wayland stuff will be nil for Qt6 < 6.5.
Title: Re: QT6 and new stuff
Post by: El Salvador on December 16, 2022, 03:50:49 pm
Great news! I will test it later. I will let you know. Meanwhile, thank you!
Title: Re: QT6 and new stuff
Post by: El Salvador on December 17, 2022, 12:23:11 am
Great. It works. In the coming days, I will make a patch to introduce hook methods in qt5/qt6 cbindings.
Title: Re: QT6 and new stuff
Post by: zeljko on December 17, 2022, 08:57:37 am
Glad to hear that  :D
Title: Re: QT6 and new stuff
Post by: El Salvador on December 21, 2022, 03:07:06 pm
I just opened a merge request: https://gitlab.com/freepascal.org/lazarus/lazarus/-/merge_requests/126
Title: Re: QT6 and new stuff
Post by: zeljko on December 21, 2022, 03:21:50 pm
Just follow my notes on merge request. Qt5Pas.pro version should be changed, also QT_VERSION_CHECK since this is for qt5 only.
Later, all hook files can be copied to qt6/cbindings/src, and added to qt6/Qt6Pas.pro and merged to qt6 too.
TinyPortal © 2005-2018