[gnome-2048/arnaudb/wip/gtk4: 5/34] Make on_window_state_event work.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-2048/arnaudb/wip/gtk4: 5/34] Make on_window_state_event work.
- Date: Mon, 13 Jul 2020 15:34:27 +0000 (UTC)
commit f02dd76e37201dfdad6e5ced2628ad68efb51175
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Apr 28 07:26:19 2020 +0200
Make on_window_state_event work.
src/game-window.vala | 66 +++++++++++++++++++++++++++++-----------------------
1 file changed, 37 insertions(+), 29 deletions(-)
---
diff --git a/src/game-window.vala b/src/game-window.vala
index c2836b9..53e01de 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -108,7 +108,7 @@ private class GameWindow : ApplicationWindow
private void _init_window ()
{
- _init_window_state (this);
+ _init_window_state ();
_load_window_state (this, ref _settings);
_header_bar.popover_closed.connect (() => _board.grab_focus ());
@@ -149,15 +149,15 @@ private class GameWindow : ApplicationWindow
private int _window_width;
private int _window_height;
- private bool _window_maximized;
- private bool _window_fullscreen;
+ private bool _window_is_maximized;
+ private bool _window_is_fullscreen;
private bool _window_is_tiled;
- private static void _init_window_state (GameWindow _this)
+ private void _init_window_state ()
{
- _this.window_state_event.connect (state_event_cb);
- _this.size_allocate.connect (size_allocate_cb);
- _this.set_size_request (WINDOW_MINIMUM_SIZE_HEIGHT, WINDOW_MINIMUM_SIZE_WIDTH);
+ size_allocate.connect (size_allocate_cb);
+ map.connect (init_state_watcher);
+ set_size_request (WINDOW_MINIMUM_SIZE_HEIGHT, WINDOW_MINIMUM_SIZE_WIDTH);
}
private static void _load_window_state (GameWindow _this, ref GLib.Settings _settings)
@@ -174,14 +174,14 @@ private class GameWindow : ApplicationWindow
_settings.delay ();
_settings.set_int ("window-width", _this._window_width);
_settings.set_int ("window-height", _this._window_height);
- _settings.set_boolean ("window-maximized", _this._window_maximized || _this._window_fullscreen);
+ _settings.set_boolean ("window-maximized", _this._window_is_maximized ||
_this._window_is_fullscreen);
_settings.apply ();
}
private static void size_allocate_cb (Widget widget, Allocation allocation)
{
GameWindow _this = (GameWindow) widget;
- if (_this._window_maximized || _this._window_is_tiled || _this._window_fullscreen)
+ if (_this._window_is_maximized || _this._window_is_tiled || _this._window_is_fullscreen)
return;
int? window_width = null;
int? window_height = null;
@@ -192,31 +192,39 @@ private class GameWindow : ApplicationWindow
_this._window_height = (!) window_height;
}
- private static bool state_event_cb (Widget widget, Gdk.EventWindowState event)
+ private void init_state_watcher ()
{
- GameWindow _this = (GameWindow) widget;
- if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
- _this._window_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 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_fullscreen = _this._window_fullscreen;
- if ((event.changed_mask & Gdk.WindowState.FULLSCREEN) != 0)
- _this._window_fullscreen = (event.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;
- if (window_fullscreen && !_this._window_fullscreen)
- _this._unfullscreen_button.hide ();
- else if (!window_fullscreen && _this._window_fullscreen)
- _this._unfullscreen_button.show ();
+ bool window_was_fullscreen = _window_is_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)
- _this._window_is_tiled = (event.new_window_state & tiled_state) != 0;
+ _window_is_fullscreen = (state & Gdk.SurfaceState.FULLSCREEN) != 0;
- return false;
+ if (window_was_fullscreen && !_window_is_fullscreen)
+ _unfullscreen_button.hide ();
+ else if (!window_was_fullscreen && _window_is_fullscreen)
+ _unfullscreen_button.show ();
+
+ /* tiled: not saved, but should not change saved window size */
+ _window_is_tiled = (state & tiled_state) != 0;
}
/*\
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]