[gnome-nibbles/arnaudb/wip/gtk4: 142/188] Handle window state change.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/wip/gtk4: 142/188] Handle window state change.
- Date: Fri, 2 Oct 2020 15:55:21 +0000 (UTC)
commit 495e6b44f9e9e06b6d6607894c3af51320863c2e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed Sep 30 16:23:34 2020 +0200
Handle window state change.
src/nibbles-window.vala | 40 +++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
---
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 6961326..85d48c8 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -126,7 +126,7 @@ private class NibblesWindow : ApplicationWindow
}
size_allocate.connect (size_allocate_cb);
- window_state_event.connect (window_state_event_cb);
+ map.connect (init_state_watcher);
set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
if (settings.get_boolean ("window-is-maximized"))
maximize ();
@@ -267,6 +267,34 @@ private class NibblesWindow : ApplicationWindow
return Source.CONTINUE;
}
+ /*\
+ * * State saving
+ \*/
+
+ private inline void init_state_watcher ()
+ {
+ Gdk.Surface? nullable_surface = window.get_surface (); // TODO report bug, get_surface() returns a
nullable Surface
+ if (nullable_surface == null || !((!) nullable_surface is Gdk.Toplevel))
+ assert_not_reached ();
+ surface = (Gdk.Toplevel) (!) nullable_surface;
+ surface.notify ["state"].connect (on_state_changed);
+ }
+
+ private Gdk.Toplevel surface;
+ private const Gdk.ToplevelState tiled_state = Gdk.ToplevelState.TILED
+ | Gdk.ToplevelState.TOP_TILED
+ | Gdk.ToplevelState.BOTTOM_TILED
+ | Gdk.ToplevelState.LEFT_TILED
+ | Gdk.ToplevelState.RIGHT_TILED;
+ private inline void on_state_changed ()
+ {
+ Gdk.ToplevelState state = surface.get_state ();
+
+ window_is_maximized = (state & Gdk.ToplevelState.MAXIMIZED) != 0;
+ /* tiled: not saved, but should not change saved window size */
+ window_is_tiled = (state & tiled_state) != 0;
+ }
+
/*\
* * Window events
\*/
@@ -294,16 +322,6 @@ private class NibblesWindow : ApplicationWindow
get_size (out window_width, out window_height);
}
- private bool window_state_event_cb (Gdk.EventWindowState event)
- {
- if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
- window_is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
- /* We don’t save this state, but track it for saving size allocation */
- if ((event.changed_mask & Gdk.WindowState.TILED) != 0)
- window_is_tiled = (event.new_window_state & Gdk.WindowState.TILED) != 0;
- return false;
- }
-
private void start_game ()
{
settings.set_boolean ("first-run", false);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]