[gnome-tetravex/arnaudb/wip/gtk4: 10/32] Adapt AdaptativeWindow.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tetravex/arnaudb/wip/gtk4: 10/32] Adapt AdaptativeWindow.
- Date: Sun, 26 Apr 2020 13:12:37 +0000 (UTC)
commit 658dfee5230861c14c763b48dc12b81320cfb2ab
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Feb 20 22:34:57 2020 +0100
Adapt AdaptativeWindow.
src/gnome-tetravex.vala | 51 ++++++++++++++++++++++++++-----------------------
1 file changed, 27 insertions(+), 24 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index f5f4d31..aea0770 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -307,8 +307,8 @@ private class Tetravex : Gtk.Application
key_controller = new EventControllerKey ();
key_controller.key_pressed.connect (on_key_pressed);
window.add_controller (key_controller);
- window.size_allocate.connect (size_allocate_cb);
- window.window_state_event.connect (window_state_event_cb);
+ window.size_allocate.connect (on_size_allocate);
+ 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 ();
@@ -530,38 +530,41 @@ private class Tetravex : Gtk.Application
}
}
- private void size_allocate_cb (Allocation allocation)
+ private void on_size_allocate (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 bool window_state_event_cb (Gdk.EventWindowState event)
+ private 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 = 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 ();
+
+ 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 */
- 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 override void shutdown ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]