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. [Ubuntu] How get screen available geometry?

[Ubuntu] How get screen available geometry?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 275 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote last edited by
    #4

    This might be a Wayland issue. I don't use Wayland so someone else must check it

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    I 1 Reply Last reply
    2
    • A AlexK7

      Hello Christian and thank you for replying.

      My bad, sorry - my current code's calling QScreen::availableSize() (I should've mentioned it) but unfortunately it too returns the whole screen resolution.

      To be clear, the code in question currently looks like:

      QScreen* screen = QGuiApplication::primaryScreen(); //static method
      QSize aSize = screen->availableSize();
      

      at runtime aSize is assigned: 2560x1440 (QHD resolution as far as I know, hence the whole screen).

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote last edited by JonB
      #5

      @AlexK7
      Like @Christian-Ehrlicher I wonder if this is a Wayland thing.

      I run Ubuntu 24.04 with GNOME but under Xorg. It's a bit hard to tell, because I run inside a VirtualBox which has its own menus/furniture, but if I full screen on a 2560x1440 monitor I get QSize(2494, 1294). Width-wise there is just the GNOME shortcut bar down the left, and that could well be 66 pixels wide? The 1294 is 146 short of 1440, which might be the top & bottom "furniture" I get from the VB host. And certainly I do not get the full 2560x1440. So I think Xorg is indeed excluding windowing furniture and your behaviour is Wayland. There may be a way to get what you want from Wayland but I don't know what call, for you to investigate.

      1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        This might be a Wayland issue. I don't use Wayland so someone else must check it

        I Offline
        I Offline
        IgKh
        wrote last edited by IgKh
        #6

        @Christian-Ehrlicher Not might be - definitely is. Under the core wayland protocol, applications are not allowed to know anything about surfaces belonging to other applications - not their size, not even that they exist. The information given to applications about screens via the wl_output protocol object is just their full size in physical units.

        This by itself is not so serious restriction, since the protocol also prevents applications from doing anything based on that information - as applications are not allowed to position themselves (or even query their own position), or obtain input events from outside their surfaces.

        @AlexK7 one escape hatch to is to run under the XWayland protocol, which allows much more information for backward compatibility. Run with the environment variable QT_QPA_PLATFORM=xcb. It would help to describe what your eventual goal in knowing this information is, since if you are doing something which is more shell-like, you may need to use specialized Wayland protocols or compositor-specific APIs.

        1 Reply Last reply
        1
        • A Offline
          A Offline
          AlexK7
          wrote last edited by
          #7

          Hello Christian, JonB and thank you both for replying.

          As for the question at hand, it's twofold (as I see it). First, yes - I've suspected it might be Wayland related. That's why I've mentioned it in the first place. Unfortunately, I haven't found a clear contact for Wayland/Ubuntu developers. If somebody can point out a proper channel, such as Internet forum, for such a question - it will be appreciated.

          Second, I fully understand that QT methods are essentially wrappers around system APIs (in our regard). But on the second hand, I think it should be either working (i.e. return values as intended) or throw an exception (we don't work with wayland). At the very least, I think QT developers (framework developers, not us - QT users) should be familiar with such limitation.

          JonBJ I 2 Replies Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote last edited by
            #8

            Wayland is so superior...😕

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • A AlexK7

              Hello Christian, JonB and thank you both for replying.

              As for the question at hand, it's twofold (as I see it). First, yes - I've suspected it might be Wayland related. That's why I've mentioned it in the first place. Unfortunately, I haven't found a clear contact for Wayland/Ubuntu developers. If somebody can point out a proper channel, such as Internet forum, for such a question - it will be appreciated.

              Second, I fully understand that QT methods are essentially wrappers around system APIs (in our regard). But on the second hand, I think it should be either working (i.e. return values as intended) or throw an exception (we don't work with wayland). At the very least, I think QT developers (framework developers, not us - QT users) should be familiar with such limitation.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote last edited by
              #9

              @AlexK7 said in [Ubuntu] How get screen available geometry?:

              But on the second hand, I think it should be either working (i.e. return values as intended) or throw an exception (we don't work with wayland).

              It (Qt) just does not work that way. At least here/in this area, the "as intended" is whatever the underlying windowing system returns, and you are expected to deal with differences between window systems as you see appropriate.

              At least just try @IgKh's QT_QPA_PLATFORM=xcb to see if that gets it right. Whether you will want to run your Qt app this way is another matter. For my own part I found so many "messy" issues with Wayland --- not just in Qt programming but elsewhere in behaviour too --- that I have given up on it and set my (GNOME) desktop to log in as Xorg instead.

              1 Reply Last reply
              1
              • A Offline
                A Offline
                AlexK7
                wrote last edited by
                #10

                Hello IgKh and thank you for replying.

                First, thank you for providing an explanation. Second, the goal is quite simple: I'd like my main window positioned at the leftmost/topmost position available, with width/height covering the entire screen but not larger.

                Since due to the business logic, the main window may grow very large in size - for UX/UI purposes, I'd rather reposition/scale/change elements within it, so a user can see the control he needs - without scrolling. Basically, available geometry = maximum window size.

                I 1 Reply Last reply
                0
                • A AlexK7

                  Hello Christian, JonB and thank you both for replying.

                  As for the question at hand, it's twofold (as I see it). First, yes - I've suspected it might be Wayland related. That's why I've mentioned it in the first place. Unfortunately, I haven't found a clear contact for Wayland/Ubuntu developers. If somebody can point out a proper channel, such as Internet forum, for such a question - it will be appreciated.

                  Second, I fully understand that QT methods are essentially wrappers around system APIs (in our regard). But on the second hand, I think it should be either working (i.e. return values as intended) or throw an exception (we don't work with wayland). At the very least, I think QT developers (framework developers, not us - QT users) should be familiar with such limitation.

                  I Offline
                  I Offline
                  IgKh
                  wrote last edited by
                  #11

                  @AlexK7 said in [Ubuntu] How get screen available geometry?:

                  Second, I fully understand that QT methods are essentially wrappers around system APIs (in our regard). But on the second hand, I think it should be either working (i.e. return values as intended) or throw an exception (we don't work with wayland). At the very least, I think QT developers (framework developers, not us - QT users) should be familiar with such limitation.

                  That is debatable, actually. When you have one windowing system that has very different capabilities to the other systems, returning error values (not an exception, Qt does not use exceptions in its' APIs and is only partially exception-safe) is one option. Returning the "next best thing", even if it is only an approximation, is another - and there are pros and cons from the perspective of a cross-platform application author either way. For better or worse, this second approach is what Qt usually does in such situations.

                  That said, I agree that limitations should be documented. The good thing about Qt is that it is open source, and anyone can be a "Qt developer". Adding a Wayland compatibility note on the availableGeometry property of QScreen could be a great first contribution, if you are so inclined.

                  JonBJ 1 Reply Last reply
                  1
                  • A AlexK7

                    Hello IgKh and thank you for replying.

                    First, thank you for providing an explanation. Second, the goal is quite simple: I'd like my main window positioned at the leftmost/topmost position available, with width/height covering the entire screen but not larger.

                    Since due to the business logic, the main window may grow very large in size - for UX/UI purposes, I'd rather reposition/scale/change elements within it, so a user can see the control he needs - without scrolling. Basically, available geometry = maximum window size.

                    I Offline
                    I Offline
                    IgKh
                    wrote last edited by IgKh
                    #12

                    @AlexK7 said in [Ubuntu] How get screen available geometry?:

                    First, thank you for providing an explanation. Second, the goal is quite simple: I'd like my main window positioned at the leftmost/topmost position available, with width/height covering the entire screen but not larger.

                    Ah, that's easy. In Wayland - you just can't do this from the application side. Applications are not allowed to set their own position, and QWidget::move is a no-op under Wayland for top-level widgets.

                    You can request to be maximized (via QWidget::showMaximized slot), but the compositor is allowed to completely ignore your request. Or you can do so from the compositor side (however assuming you are using GNOME - it has no facilities for that without writing a shell extension, sorry; KDE and Sway do have something).

                    1 Reply Last reply
                    3
                    • I IgKh

                      @AlexK7 said in [Ubuntu] How get screen available geometry?:

                      Second, I fully understand that QT methods are essentially wrappers around system APIs (in our regard). But on the second hand, I think it should be either working (i.e. return values as intended) or throw an exception (we don't work with wayland). At the very least, I think QT developers (framework developers, not us - QT users) should be familiar with such limitation.

                      That is debatable, actually. When you have one windowing system that has very different capabilities to the other systems, returning error values (not an exception, Qt does not use exceptions in its' APIs and is only partially exception-safe) is one option. Returning the "next best thing", even if it is only an approximation, is another - and there are pros and cons from the perspective of a cross-platform application author either way. For better or worse, this second approach is what Qt usually does in such situations.

                      That said, I agree that limitations should be documented. The good thing about Qt is that it is open source, and anyone can be a "Qt developer". Adding a Wayland compatibility note on the availableGeometry property of QScreen could be a great first contribution, if you are so inclined.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote last edited by JonB
                      #13

                      @IgKh said in [Ubuntu] How get screen available geometry?:

                      Adding a Wayland compatibility note on the availableGeometry property of QScreen could be a great first contribution, if you are so inclined.

                      This would only be the start of myriad necessary/suggested doc notes for Wayland. For example, as you yourself pointed out QWidget::move() is a no-op, showMaximized() may do nothing or whatever, and the compositor may or may not do things, and differently from other compositors.... If the Qt docs really intend to do anything about Wayland I would rather it were a large effort from the team covering everything than the occasional user note.

                      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