Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Corrected bring application to front

Corrected bring application to front

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 205 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrzejB
    wrote on last edited by AndrzejB
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AndrzejB
      wrote on last edited by AndrzejB
      #3

      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.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by ChrisW67
        #2

        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.
        b93cc6c6-bfda-4831-8437-8fdfce08cbf5-image.png

        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.

        1 Reply Last reply
        1
        • A Offline
          A Offline
          AndrzejB
          wrote on last edited by AndrzejB
          #3

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved