Saving and restoring window bounds using Views

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Saving and restoring window bounds using Views

Postby Mayhew » Tue Nov 30, 2021 8:01 pm

I'm trying to change over our linux app which uses a CEF browser housed in a GTK container window to utilize views and remove the GTK dependency. I am having trouble saving the full window bounds and restoring them on the next launch. I'm able to implement GetInitialBounds in my CefWindowDelegate subclass and pass it bounds which indeed sets the left/top of the container (frame and title/caption bar) to the specified left/top and sets the browser sub-window to the specified width/height. Ideally, the specified bounds would be for the overall window size including its frame and caption bar but we can work around this behavior.

The issue we have is attempting to save the main windows last position when our delegates CanClose method is about to return true. I have called the browser view's GetBoundsInScreen and GetBounds as well as the windows GetClientAreaBoundsInScreen and GetBoundsInScreen and all of these return the bounds of the browser window inside the frame and caption bar. If we store that and return it in GetInitialBounds the position is offset by the width of the frame (1px) and the height of the caption bar (34px on my linux distro which is debian). I can't find any way to get the actual left/top of the outer frame including the caption bar, or get simply get the frame width and caption bar height. Is there a way to get that info from within my view delegate?
Mayhew
Expert
 
Posts: 303
Joined: Mon Apr 18, 2011 8:02 pm

Re: Saving and restoring window bounds using Views

Postby magreenblatt » Tue Nov 30, 2021 9:28 pm

Did you try calling GetBounds/GetBoundsInScreen on the CefWindow object?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Saving and restoring window bounds using Views

Postby Mayhew » Wed Dec 01, 2021 1:02 pm

Yes, I have tried all window methods to obtain the bounds. My GetInitialBounds() override returns the following rect (left, top, width, height) 1, 1, 2000, 1000

I output the following values at the end of my CefWindowDelegate subclass's OnWindowCreated method
browser view GetBoundsInScreen 1 1 2000 1000
window GetClientAreaBoundsInScreen 1 1 2000 1000
window GetBoundsInScreen 1 1 2000 1000
window GetBounds 1 1 2000 1000
window GetSize 2000 1000
window GetPosition 1 1
These match what I specified in GetInitialBounds and the overall window (frame and titlebar) appear at 1,1 and the browser window inside the frame has a size of 2000, 1000 making the overall window size 2002, 1036 with a left/top of 1, 1

I don't move or resize the window, then in CanClose() of my CefWindowDelegate subclass I output the following values
browser view GetBoundsInScreen 2 35 2000 1000
window GetClientAreaBoundsInScreen 2 35 2000 1000
window GetBoundsInScreen 2 35 2000 1000
window GetBounds 2 35 2000 1000
window GetSize 2000 1000
window GetPosition 2 35

You can see that all values add 1 to the left (I'm assuming for the frame) and 34 to the top (I'm assuming for the caption/title bar).

I tried outputting the same values in OnWindowDestroyed but all report 0, 0, 0, 0 in there.
Mayhew
Expert
 
Posts: 303
Joined: Mon Apr 18, 2011 8:02 pm

Re: Saving and restoring window bounds using Views

Postby magreenblatt » Wed Dec 01, 2021 4:45 pm

This is a tricky one on Linux. I wonder if (internally) Views even knows about the frame that your WM is creating? You might need to debug/dig in the code to see if the bounds that you're seeking are available. Alternately, perhaps you can get the window bounds using the window handle and native (xlib or similar) APIs.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Saving and restoring window bounds using Views

Postby sirchaddington » Mon Mar 06, 2023 12:41 pm

My initial understanding looking at CEF source (which could be wrong), is that it's using GTK's get_position and gtk_window_move_resize to facilitate the getting/setting of the bounds.

Looking deeper at GTK's documentation (https://docs.gtk.org/gtk3/method.Window ... ition.html), they talk about the unreliability of get_position because of the decorator (captionbar/titlebar) and come to the conclusion: "In practice, saving the window position should not be left to applications, as they lack enough knowledge of the windowing system and the window manager state to effectively do so. The appropriate way to implement saving the window position is to use a platform-specific protocol, wherever that is available."

It's wacky, and I wonder if it has something to do with Chromium-94's switch to using client side decorators (CSD - the title bar is a called a decorator). Using X11 to inspect the window handle, the bounds of the main browser with is correct (the screen coordinate given is the top-left point of the content area... there's 37 pixels above that are a title bar. The content area is actually 45 pixels below, and 10 pixels to the right, of the parent window... as it's drawing the title bar and a drop shadow). It's weird that something like this moves the window down the exact height of the titlebar:

// CefRefPtr<CefBrowserView> mainBrowserView
CefRect bounds = mainBrowserView->GetWindow()->GetBounds();
// then later
mainBrowserView->GetWindow()->SetBounds(bounds);
sirchaddington
Newbie
 
Posts: 3
Joined: Tue Feb 07, 2023 11:53 am

Re: Saving and restoring window bounds using Views

Postby sirchaddington » Tue Mar 07, 2023 12:44 pm

This might help the original poster as well, but for my issue, the problem was the "extents" of the window changed between where I saved and restored the window location.

I ended up using xlib to query what the extents were, and found the window before being shown had a top-extents of 37 pixels... so when I tried to restore a saved position (saved when the extents were all 0), the window manager placed the window slightly lower.

The windowGeometry() function here has some LGPL code showing how to get the extents:
https://allstar.jhuapl.edu/repo/p3/amd6 ... em_x11.cpp
sirchaddington
Newbie
 
Posts: 3
Joined: Tue Feb 07, 2023 11:53 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 33 guests