[gnome-tetravex/arnaudb/wip/gtk4: 23/49] Adapt AdaptativeWindow.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tetravex/arnaudb/wip/gtk4: 23/49] Adapt AdaptativeWindow.
- Date: Wed, 2 Sep 2020 16:07:48 +0000 (UTC)
commit 0d7cb69f35e586034f47d0093a3ef6d3caa8ef32
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Feb 20 22:34:57 2020 +0100
Adapt AdaptativeWindow.
src/gnome-tetravex.vala | 50 +++++++++++++++++++++++++------------------------
1 file changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index 810047e..a3aa503 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -309,8 +309,7 @@ private class Tetravex : Gtk.Application
key_controller = new EventControllerKey ();
key_controller.key_pressed.connect (on_key_pressed);
((Widget) window).add_controller (key_controller);
- 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 ();
@@ -532,38 +531,41 @@ private class Tetravex : Gtk.Application
}
}
- private void size_allocate_cb (Allocation allocation)
+ private 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_window_state_event);
+ surface.size_changed.connect (on_size_changed);
+ }
+
+ private inline void on_size_changed (Gdk.Surface _surface, int width, int height)
{
if (window_is_maximized || window_is_tiled || window_is_fullscreen)
return;
- int? _window_width = null;
- int? _window_height = null;
- window.get_size (out _window_width, out _window_height);
- if (_window_width == null || _window_height == null)
- return;
- window_width = (!) _window_width;
- window_height = (!) _window_height;
+ window_width = width;
+ window_height = height;
}
- private const Gdk.WindowState tiled_state = Gdk.WindowState.TILED
- | Gdk.WindowState.TOP_TILED
- | Gdk.WindowState.BOTTOM_TILED
- | Gdk.WindowState.LEFT_TILED
- | Gdk.WindowState.RIGHT_TILED;
- private bool window_state_event_cb (Gdk.EventWindowState 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 ()
{
- if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
- window_is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
+ Gdk.SurfaceState state = surface.get_state ();
+
+ window_is_maximized = (state & Gdk.SurfaceState.MAXIMIZED) != 0;
/* fullscreen: saved as maximized */
- 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;
/* tiled: not saved, but should not change saved window size */
- 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 override void shutdown ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]