How to detect the rectangle of the Desktop for Linux?

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Odin_KG
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 10, 2021 6:08 am

How to detect the rectangle of the Desktop for Linux?

Post by Odin_KG »

Hello

I use wxGTK 3.1.14 on Fedora with Code::blocks 20.3.
I can't detect the rectangle of the Desktop, because the following variants do not consider the Taskbar.

1)

Code: Select all

wxDisplay display((unsigned int)0);
wxRect r=display.GetClientArea();
2)

Code: Select all

wxRect r=wxGetClientDisplayRect();
And I read the description of wxGetClientDisplayRect:
On Windows this means the area not covered by the taskbar, etc. Other platforms are currently defaulting to the whole display until a way is found to provide this info for all window managers, etc.
The code "frame->Maximize()" does not work. And style wxMAXIMIZE for wxFrame is ignored too.

But I have no any problems on Windows with these functions.

How to deside this problem on Linux ?
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to detect the rectangle of the Desktop for Linux?

Post by doublemax »

I can't detect the rectangle of the Desktop, because the following variants do not consider the Taskbar.
If the documentation says it's not supported, i guess there is nothing you can do.
The code "frame->Maximize()" does not work.
This should definitely work though. Can you build the "minimal" sample that comes with wxWidgets? Try adding "frame->Maximize() directly after "frame->Show()"
Use the source, Luke!
Odin_KG
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 10, 2021 6:08 am

Re: How to detect the rectangle of the Desktop for Linux?

Post by Odin_KG »

doublemax
Can you build the "minimal" sample that comes with wxWidgets?
I added Minimize() to "minimal" sample and it works.

I will try to detect the Desktop rectangle using the size of maximized window.

Thanks for the help
Odin_KG
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 10, 2021 6:08 am

Re: How to detect the rectangle of the Desktop for Linux?

Post by Odin_KG »

Unfortunately, in my case the wxFrame is not maximized:

Code: Select all

void GPlatformWidgets::GetDesktopRect(CMagicRect* rect)
{
wxFrame temp(NULL, wxID_ANY, "");
temp.Show(true);
temp.Maximize();

wxPoint pos=temp.GetPosition();
rect->left=pos.x;
rect->top=pos.y;
temp.GetSize(&rect->right, &rect->bottom);
}
I think, the problem is "deleting" of the wxFrame in the function. May I update the size of wxFrame forced ?
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to detect the rectangle of the Desktop for Linux?

Post by doublemax »

You shouldn't create a frame (or any wxWindow except for modal dialogs) on the stack. It will be destroyed when it goes out of scope.

I can't test under Linux, but maybe you need some specific window style flags to make Maximize() work. Try adding wxMAXIMIZE_BOX and / or wxRESIZE_BORDER to the style flags.

You could also try wxTopLevelWindow::ShowFullScreen
https://docs.wxwidgets.org/trunk/classw ... d1fb84ee28
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4182
Joined: Sun Jan 03, 2010 5:45 pm

Re: How to detect the rectangle of the Desktop for Linux?

Post by PB »

I am not really familiar with Linux but I tried running the wxWidgets 3.1.4 display sample compiled for GTK3 under Mint 20 and Ubuntu 20 running from VirtualBox.

It seems that the display client area is obtained correctly there, i.e., it is properly offset from the full display size? There is also no platform-specific warning for wxDisplay::GetClientArea()?

BTW, wxTopLevelWindow::ShowFullScreen() uses wxDisplay::GetGeometry(), i.e., the whole display area. At least on Windows, see viewtopic.php?f=1&t=47813#p202724
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to detect the rectangle of the Desktop for Linux?

Post by doublemax »

So i fired up a few VMs myself and wxDisplay::GetClientArea() worked in 2 out of 3 cases.
It worked on Ubuntu Cinnamon and Mint 20. It didnt' work on Q4OS.

I don't know how to find out which window manager / desktop they were using ;)
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to detect the rectangle of the Desktop for Linux?

Post by ONEEYEMAN »

doublemax,
Can you post the screenshots of said VMs?

Thank you.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to detect the rectangle of the Desktop for Linux?

Post by ONEEYEMAN »

Hi,
@OP:

Maximize() definitely should work.

I think GTK is keeping something internally (i.e. not exposed to outside world) in order to make it work. Probably they get the screen info using the function I referenced in the other forum and subtract the size of the menu bar if available and the task bar if available, because theyy know it internally.

They just don't expose this functionality, because it is based on the X server and they didn't want this to break to anyone if the X API changes or something new will comes (Wayland).

Keep in mind though that under Wayland trying to set the size of the Window or even start the program maximized will NOT work. Wayland relies on the composite manager and user preferences to set the position and size of the TLW. So under Wayland, even if you want to call Maximize() on you main frame you window may start with 200x200. Because Wayland (its Composite Manager) will decide that for you.

And so under Linux that point is moot.

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to detect the rectangle of the Desktop for Linux?

Post by doublemax »

ONEEYEMAN wrote: Thu Mar 11, 2021 4:02 pm doublemax,
Can you post the screenshots of said VMs?
Ubuntu Cinnamon
Ubuntu Cinnamon.jpg
Q4OS
Q4OS.jpg
Mint20
Mint20.jpg
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to detect the rectangle of the Desktop for Linux?

Post by ONEEYEMAN »

doublemax,
I think the Mint looks like KDE or something KDE/Qt-based, Q4 and Ubuntu looks like Mate.

I maybe wrong though...

What does it say when it starts?

On My KDE Gentoo install with KDE 5, I see the big letter "K" while the WM starts up.
And on my other Gentoo with GNOME 3 it doesn't say anythiong - it just starts the VM with an empty desktop.

Thank you.
Post Reply