[gnome-mahjongg/arnaudb/wip/gtk4: 7/23] 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: 7/23] Make on_window_state_event work.
- Date: Sun, 3 May 2020 16:22:34 +0000 (UTC)
commit 4e783c07258804b3dfd91c27eb00028ae98f6d97
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 b604e1a..d0cb733 100644
--- a/src/gnome-mahjongg.vala
+++ b/src/gnome-mahjongg.vala
@@ -79,7 +79,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 ();
@@ -189,14 +189,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.SurfaceState tiled_state = Gdk.SurfaceState.TILED
+ | Gdk.SurfaceState.TOP_TILED
+ | Gdk.SurfaceState.BOTTOM_TILED
+ | Gdk.SurfaceState.LEFT_TILED
+ | Gdk.SurfaceState.RIGHT_TILED;
+ private void on_window_state_event ()
+ {
+ Gdk.SurfaceState state = surface.get_state ();
+
+ is_maximized = (state & Gdk.SurfaceState.MAXIMIZED) != 0;
+ is_tiled = (state & Gdk.SurfaceState.TILED) != 0;
}
protected override void shutdown ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]