[gnome-mahjongg/arnaudb/wip/gtk4: 4/24] Make on_window_state_event work.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mahjongg/arnaudb/wip/gtk4: 4/24] Make on_window_state_event work.
- Date: Fri, 25 Sep 2020 14:20:32 +0000 (UTC)
commit d0ca0c846ac167b5970f771ddb16801b5be874d6
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri Mar 27 18:54:53 2020 +0100
Make on_window_state_event work.
src/gnome-mahjongg.vala | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/src/gnome-mahjongg.vala b/src/gnome-mahjongg.vala
index f44666c..b5187e4 100644
--- a/src/gnome-mahjongg.vala
+++ b/src/gnome-mahjongg.vala
@@ -81,7 +81,7 @@ public class Mahjongg : Gtk.Application
window = new Gtk.ApplicationWindow (this);
window.size_allocate.connect (size_allocate_cb);
- window.window_state_event.connect (window_state_event_cb);
+ window.map.connect (init_state_watcher);
window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
if (settings.get_boolean ("window-is-maximized"))
window.maximize ();
@@ -194,14 +194,27 @@ public class Mahjongg : Gtk.Application
window.get_size (out window_width, out window_height);
}
- private bool window_state_event_cb (Gdk.EventWindowState event)
+ private void init_state_watcher ()
{
- if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
- 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)
- is_tiled = (event.new_window_state & Gdk.WindowState.TILED) != 0;
- return false;
+ 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_window_state_event);
+ }
+
+ 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_window_state_event ()
+ {
+ Gdk.ToplevelState state = surface.get_state ();
+
+ is_maximized = (state & Gdk.ToplevelState.MAXIMIZED) != 0;
+ is_tiled = (state & tiled_state) != 0;
}
protected override void shutdown ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]