gtk: Add suspended window state

This is implemented using a new xdg_toplevel `suspended` state, and is
meant for allowing applications to know when they can stop doing
unnecessary work and thus save power.

In the other backends, the `suspended` state is set at the same time as
`minimized` as it's the closest there is to traditional windowing
systems.
This commit is contained in:
Jonas Ådahl
2023-05-24 16:22:42 +02:00
committed by Matthias Clasen
parent 03a8b9cf17
commit 7f946eff01
12 changed files with 144 additions and 16 deletions

View File

@@ -103,6 +103,7 @@ gtk_tests = [
['teststack'],
['testrevealer'],
['testrevealer2'],
['testsuspended'],
['testwindowsize'],
['testpopover'],
['listmodel'],

View File

@@ -4542,6 +4542,8 @@ surface_state_callback (GdkSurface *window,
msg = g_strconcat ((const char *)g_object_get_data (G_OBJECT (label), "title"), ": ",
(new_state & GDK_TOPLEVEL_STATE_MINIMIZED) ?
"minimized" : "not minimized", ", ",
(new_state & GDK_TOPLEVEL_STATE_SUSPENDED) ?
"suspended" : "not suspended", ", ",
(new_state & GDK_TOPLEVEL_STATE_STICKY) ?
"sticky" : "not sticky", ", ",
(new_state & GDK_TOPLEVEL_STATE_MAXIMIZED) ?

46
tests/testsuspended.c Normal file
View File

@@ -0,0 +1,46 @@
#include <gtk/gtk.h>
static void
quit_cb (GtkWidget *widget,
gpointer data)
{
gboolean *done = data;
*done = TRUE;
g_main_context_wakeup (NULL);
}
static void
report_suspended_state (GtkWindow *window)
{
g_print ("Window is %s\n",
gtk_window_is_suspended (window) ? "suspended" : "active");
}
static void
suspended_changed_cb (GtkWindow *window)
{
report_suspended_state (window);
}
int main (int argc, char *argv[])
{
GtkWidget *window;
gboolean done = FALSE;
gtk_init ();
window = gtk_window_new ();
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
g_signal_connect (window, "notify::suspended",
G_CALLBACK (suspended_changed_cb), &done);
gtk_window_present (GTK_WINDOW (window));
report_suspended_state (GTK_WINDOW (window));
while (!done)
g_main_context_iteration (NULL, TRUE);
return EXIT_SUCCESS;
}