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. Always On Top without Steal Focus - Linux
Forum Updated to NodeBB v4.3 + New Features

Always On Top without Steal Focus - Linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 4.0k Views 3 Watching
  • 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.
  • mannclearyM Offline
    mannclearyM Offline
    manncleary
    wrote on last edited by
    #1

    In Windows, we are using the following to bring the application to the foreground and always on top without stealing focus from other applications:

    mainWindow->setWindowState(Qt::WindowActive);
    mainWindow->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
    mainWindow->showNormal();

    In Linux, when implementing the above, the application does not come to the foreground. If I call activateWindow(), then the window comes to the foreground but steals focus from other applications.

    Replacing Qt::Tool with Qt::X11BypassWindowManagerHint works without calling activateWindow() and does not steal focus but with an issue. In this scenario, if you open a new window which is underneath buttons in our application, the user cannot interact with the buttons. The OS window management believes the newly opened window is now on top and limits the users interaction with buttons in our application. If you move the newly opened window off to the side, you can once again interact with buttons in our application.

    I need a solution for putting our window always on top of other applications and not stealing focus in Linux OS. Full interaction with our application should still be allowed regardless if a new window is opened while our application is displayed.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi
      It depends on the actual windows manager.
      Which one are you using?

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

        You're never going to be able to do that for linux as a whole. Linux doesn't have a set window manager. People can use whatever they like.

        You can plan for the big ones like Gnome, KDE, etc but in the end people can run whatever they want, even old things like fluxbox, englightenment, etc.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        1
        • mrjjM mrjj

          hi
          It depends on the actual windows manager.
          Which one are you using?

          mannclearyM Offline
          mannclearyM Offline
          manncleary
          wrote on last edited by
          #4

          @mrjj In our environment we are using Gnome.

          JonBJ 1 Reply Last reply
          0
          • mannclearyM manncleary

            @mrjj In our environment we are using Gnome.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @manncleary
            Is https://stackoverflow.com/a/1022121/489865 ("Show window in Qt without stealing focus") helpful?

            setAttribute(Qt::WA_ShowWithoutActivating)

            This forces the window not to activate. Even with the Qt::WindowStaysOnTopHint flag

            I'm not sure it's what you want [have a feeling it does the opposite of what you want... :( ], but might be worth a read/experiment for the ideas there?

            Something like https://major.io/2015/07/06/allow-new-windows-to-steal-focus-in-gnome-3/ or https://superuser.com/questions/143044/how-to-prevent-new-windows-from-stealing-focus-in-gnome discusses GNOME behaviour and tweaking. There are a fair number of hits from Google: gnome focus stealing prevention

            1 Reply Last reply
            1

            • Login

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