[gnome-klotski/arnaudb/wip/gtk4: 24/42] Make on_window_state_event work.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-klotski/arnaudb/wip/gtk4: 24/42] Make on_window_state_event work.
- Date: Mon, 1 Jun 2020 21:22:58 +0000 (UTC)
commit b5c48a9b301f480eccf2e3269be2dd8c97297dd2
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Mar 5 18:54:15 2020 +0100
Make on_window_state_event work.
data/ui/klotski.ui | 2 +-
src/klotski-window.vala | 37 +++++++++++++++++++++++--------------
2 files changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/data/ui/klotski.ui b/data/ui/klotski.ui
index 62b6fe9..6962071 100644
--- a/data/ui/klotski.ui
+++ b/data/ui/klotski.ui
@@ -330,7 +330,7 @@
<property name="width-request">600</property>
<property name="height-request">400</property>
<signal name="size_allocate" handler="on_size_allocate"/>
- <signal name="window_state_event" handler="on_window_state_event"/>
+ <signal name="map" handler="init_state_watcher"/>
<signal name="destroy" handler="on_destroy"/>
<child type="titlebar">
<object class="GtkHeaderBar" id="headerbar">
diff --git a/src/klotski-window.vala b/src/klotski-window.vala
index da471ba..d385192 100644
--- a/src/klotski-window.vala
+++ b/src/klotski-window.vala
@@ -639,30 +639,39 @@ private class KlotskiWindow : ApplicationWindow
}
[GtkCallback]
- private bool on_window_state_event (Gdk.EventWindowState event)
+ private inline void init_state_watcher ()
{
- if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
- window_is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
+ Gdk.Surface? nullable_surface = 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 inline void on_window_state_event ()
+ {
+ Gdk.SurfaceState state = surface.get_state ();
+
+ window_is_maximized = (state & Gdk.SurfaceState.MAXIMIZED) != 0;
/* fullscreen: saved as maximized */
bool window_was_fullscreen = window_is_fullscreen;
- if ((event.changed_mask & Gdk.WindowState.FULLSCREEN) != 0)
- window_is_fullscreen = (event.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;
+
+ window_is_fullscreen = (state & Gdk.SurfaceState.FULLSCREEN) != 0;
+
if (window_was_fullscreen && !window_is_fullscreen)
on_unfullscreen ();
else if (!window_was_fullscreen && window_is_fullscreen)
on_fullscreen ();
/* tiled: not saved, but should not change saved window size */
- Gdk.WindowState tiled_state = Gdk.WindowState.TILED
- | Gdk.WindowState.TOP_TILED
- | Gdk.WindowState.BOTTOM_TILED
- | Gdk.WindowState.LEFT_TILED
- | Gdk.WindowState.RIGHT_TILED;
- if ((event.changed_mask & tiled_state) != 0)
- window_is_tiled = (event.new_window_state & tiled_state) != 0;
-
- return false;
+ window_is_tiled = (state & tiled_state) != 0;
}
protected void on_fullscreen ()
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]