Mininized/Restored window

Hi,

I have an application window that I do not want to be able to be resized (always maximized). On creating the window I set it to maximized, however if the window is minimized and then restored, it restores to the default size (width, height).

window = gtk_application_window_new(app);
gtk_window_maximize(GTK_WINDOW(window));

So my question is how do I ensure that the window is restored to a maximize state? Is there a window state changed signal (or something similar) that I need to handle?

Thank you.

Hi all,

An update, I was able to achieve the outcome with the following in my application activate signal callback (the window is created in startup to prevent multiple windows from being able to be opened):

GtkWindow* window = gtk_application_get_active_window(dos);
gtk_window_present(window);
GdkDisplay* display = gdk_display_get_default();
GdkSurface* surface = gtk_native_get_surface(GTK_NATIVE(window));
GdkMonitor* monitor = gdk_display_get_monitor_at_surface(display, surface);
GdkRectangle rectangle;
gdk_monitor_get_geometry(monitor, &rectangle);
gtk_window_set_default_size(window, rectangle.width, rectangle.height * 0.9375);

Note: the magic number is the ratio of the screen size to the maximized size.

I got the above by following advice from a previous thread on GNOME discourse.

I was just hoping to get some feedback on the above approach from an experienced hand as to whether this will lead to any issues.

Thank you.

in map

GdkSurface* surface = gtk_native_get_surface( ( gpointer )self );
g_signal_connect_swapped( surface, "enter-monitor", G_CALLBACK( gtk_window_maximize ), self );

But there are many problems.

You can give it a try

Hi @q962,

Thanks for that.

When you say there are problems, does this relate to multiple monitors etc?

In that case would you recommend using the callback or just setting the window size on activate?

Thank you.

Yes, I currently have two monitors. When I move windows between different monitors, it causes the window position to shift randomly. It’s very chaotic.

Perhaps it is possible to listen to motion events, determine the position of the pointer in a timely manner, and obtain the monitor where the mouse pointer is located. Then transfer the window. I haven’t tried yet. I am not very familiar with the operation of multiple monitors.

Another issue is to maintain maximization.

I am unable to obtain the status of the window by listening to Window:maximized.

You can continue your research. You can take a look at GdkToplevel

The possible issue is that setting maximum is not a timely operation and may result in delays.

The use of the minimize activate action can be disabled for this application.

Also overrides the event of the minimize button in header_bar.

Or create a control as the top-level container.
Override specific activate action

As for external forces, they need to be verified.

This is for a very specific application that is only going to run on a laptop (so single monitor and only one size). I just thought if I was going to try and achieve this behaviour, it may be worth figuring out how to do it for the general case (if the need ever arises again, I doubt it will though).

I was thinking about using the on focus signal to determine when the window was being restored (after being minimized), then calling maximize again.

Thank you for your feedback, having no experience/knowledge with GTK this is very much a learning journey for me.

Regards,
Adam.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.