[gnome-chess/arnaudb/wip/gtk4: 29/51] Make on_window_state_event() work.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess/arnaudb/wip/gtk4: 29/51] Make on_window_state_event() work.
- Date: Tue, 15 Sep 2020 16:25:26 +0000 (UTC)
commit a52052675f8536daa63a185b4d9c17f630fae3e5
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Apr 7 10:01:23 2020 +0200
Make on_window_state_event() work.
src/gnome-chess.vala | 42 ++++++++++++++++++++++++++++++------------
1 file changed, 30 insertions(+), 12 deletions(-)
---
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 3e6cbfe..cdff9a7 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -21,8 +21,9 @@ public class ChessApplication : Gtk.Application
}
private LayoutMode layout_mode;
- private bool is_tiled;
- private bool is_maximized;
+ private bool window_is_fullscreen;
+ private bool window_is_tiled;
+ private bool window_is_maximized;
private int window_width;
private int window_height;
@@ -159,7 +160,7 @@ Copyright © 2015–2016 Sahil Sareen""";
if (settings.get_boolean ("maximized"))
window.maximize ();
window.size_allocate.connect (size_allocate_cb);
- window.window_state_event.connect (window_state_event_cb);
+ window.map.connect (init_state_watcher);
info_bar = (InfoBar) builder.get_object ("info_bar");
pause_resume_button = (Button) builder.get_object ("pause_button");
@@ -265,7 +266,7 @@ Copyright © 2015–2016 Sahil Sareen""";
settings.delay ();
settings.set_int ("width", window_width);
settings.set_int ("height", window_height);
- settings.set_boolean ("maximized", is_maximized);
+ settings.set_boolean ("maximized", window_is_maximized || window_is_fullscreen);
settings.apply ();
}
@@ -280,23 +281,40 @@ Copyright © 2015–2016 Sahil Sareen""";
private void size_allocate_cb (Allocation allocation)
{
- if (is_maximized || is_tiled)
+ if (window_is_maximized || window_is_tiled || window_is_fullscreen)
return;
window.get_size (out window_width, out window_height);
+
if (window_width <= 500 && layout_mode == LayoutMode.NORMAL)
set_layout_mode (LayoutMode.NARROW);
else if (window_width > 500 && layout_mode == LayoutMode.NARROW)
set_layout_mode (LayoutMode.NORMAL);
}
- private bool window_state_event_cb (Gdk.EventWindowState event)
+ private inline 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.ToplevelState tiled_state = Gdk.ToplevelState.TILED
+ | Gdk.ToplevelState.TOP_TILED
+ | Gdk.ToplevelState.BOTTOM_TILED
+ | Gdk.ToplevelState.LEFT_TILED
+ | Gdk.ToplevelState.RIGHT_TILED;
+ private inline void on_window_state_event ()
+ {
+ Gdk.ToplevelState state = surface.get_state ();
+
+ window_is_maximized = (state & Gdk.ToplevelState.MAXIMIZED) != 0;
+ /* fullscreen: saved as maximized */
+ window_is_fullscreen = (state & Gdk.ToplevelState.FULLSCREEN) != 0;
+ /* tiled: not saved, but should not change saved window size */
+ window_is_tiled = (state & tiled_state) != 0;
}
public PieceType? show_promotion_type_selector ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]