Corrected bring application to front
-
I have Mint 21 Cinnamon.
I am searching way for full handling one instance for my editor.
it is promising itay-grudev/SingleApplication , example Calculator.
Messages are sended and received, only one bad thing: first instance instead of bringing to front, only blink icon on taskbar.
(but QMessageBox::warning caused bringing to front!)
For compare, my very old editor in Pascal with Synedit go to front correctly.
Here is code:procedure TGtk2WidgetSet.AppBringToFront; begin if Assigned(Application.MainForm) and Application.MainForm.HandleAllocated then begin gdk_window_raise({%H-}PGtkWidget(Application.MainForm.Handle)^.window); gdk_window_focus({%H-}PGtkWidget(Application.MainForm.Handle)^.window, gtk_get_current_event_time); end; end;
But this is not compatible with Qt
Is other example from Kate editor:
https://github.com/KDE/kate/blob/e796092e5229c441a56804d53cdcc055fe080a52/apps/lib/kateappadaptor.cpp#L31// like QtSingleApplication win->setWindowState(win->windowState() & ~Qt::WindowMinimized); win->raise(); win->activateWindow(); // try to raise window, see bug 407288 win->setAttribute(Qt::WA_NativeWindow, true); KStartupInfo::setNewStartupId(win->windowHandle(), KStartupInfo::startupId()); KWindowSystem::setCurrentXdgActivationToken(token); KWindowSystem::activateWindow(win->effectiveWinId());
I apply almost all in my application, but token, I don't know which should be token.
-
Good result is using command wmctrl
https://stackoverflow.com/questions/73309270/bring-my-application-window-to-screen-front-in-mint/73360255#73360255
there is also pure C++ solution without execute binary. -
The example provided works within the limitations of the X11 window manager your user has. This is described in the QWidget::activateWindow docs. The example calls activatewindow() and raise(), but it still controlled by the window manager.
On my KDE desktop the window is not activated/raised because of the default "Focus stealing prevention" settings. Setting "None" takes the window manager out of the equation and the application is activated/raised.
I imagine that the window manager in Cinnamon has a similar setting.
There is no point trying to copy-and-paste code from a GTK or KDE application unless your application already a GTK or KDE application.
-
Good result is using command wmctrl
https://stackoverflow.com/questions/73309270/bring-my-application-window-to-screen-front-in-mint/73360255#73360255
there is also pure C++ solution without execute binary.