[five-or-more] Revert "Improve state and size handling."



commit ba0ea7fbd9e2aaa1593cbc5c6968b2402c7f98d1
Author: Arnaud B <arnaud bonatti gmail com>
Date:   Thu Oct 22 17:22:58 2020 +0000

    Revert "Improve state and size handling."
    
    This reverts commit f98a053086efdabab758b0d1ba7aa484643f357e.

 data/ui/five-or-more.ui     |  56 ++++++++++++++-------
 data/ui/help-overlay.ui     |  19 +++++--
 meson.build                 |   2 +-
 org.gnome.five-or-more.json |   6 +--
 src/main.vala               |  15 ++++--
 src/next-pieces-widget.vala |   8 +--
 src/view.vala               |  83 +++++++++++++++---------------
 src/window.vala             | 120 ++++++++++++++++++--------------------------
 8 files changed, 162 insertions(+), 147 deletions(-)
---
diff --git a/data/ui/five-or-more.ui b/data/ui/five-or-more.ui
index e2c32d2..9976372 100644
--- a/data/ui/five-or-more.ui
+++ b/data/ui/five-or-more.ui
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <requires lib="gtk+" version="3.99"/>
+  <!-- interface-requires gtk+ 3.10 -->
   <menu id="primary-menu">
     <section>
       <item>
@@ -104,51 +104,69 @@
       </item>
     </section>
   </menu>
+  <object class="GtkAccelGroup" id="accelgroup"/>
   <template class="GameWindow" parent="GtkApplicationWindow">
+    <property name="can_focus">False</property>
     <property name="default_width">320</property>
     <property name="default_height">400</property>
     <property name="icon_name">five-or-more</property>
-<!--    <property name="border-width">18</property> FIXME -->
-    <!-- Translators: name of the application, as displayed in the window manager -->
-    <property name="title" translatable="yes">Five or More</property>
+    <property name="border-width">18</property>
+    <accel-groups>
+      <group name="accelgroup"/>
+    </accel-groups>
     <child type="titlebar">
       <object class="GtkHeaderBar" id="headerbar">
-        <property name="show_title_buttons">True</property>
-        <child type="start">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="show_close_button">True</property>
+        <!-- Translators: name of the application, as displayed in the window manager -->
+        <property name="title" translatable="yes">Five or More</property>
+        <child>
           <object class="GtkBox" id="preview_hbox">
-<!--            <property name="border_width">12</property> FIXME -->
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">12</property>
             <property name="orientation">horizontal</property>
             <child>
               <object class="GtkLabel" id="labelNext">
+                <property name="visible">True</property>
                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                <property name="can_focus">False</property>
                 <!-- Translators: label displayed in the headerbar, introducing the next balls to be added 
to the board -->
                 <property name="label" translatable="yes">Next:</property>
                 <attributes>
                   <attribute name="weight" value="bold"/>
                 </attributes>
               </object>
+              <packing>
+                <property name="pack_type">start</property>
+              </packing>
             </child>
           </object>
         </child>
-        <child type="end">
+        <child>
           <object class="GtkMenuButton">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
             <property name="menu_model">primary-menu</property>
-            <property name="icon_name">open-menu-symbolic</property>
-<!--            <accelerator key="F10" signal="activate"/> FIXME -->
+            <accelerator key="F10" signal="activate"/>
+            <child>
+              <object class="GtkImage" id="primary-menu-button-image">
+                <property name="visible">True</property>
+                <property name="icon_size">1</property>
+                <property name="icon_name">open-menu-symbolic</property>
+              </object>
+            </child>
           </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
         </child>
       </object>
     </child>
     <child>
-      <object class="GtkAspectFrame" id="grid_frame">
-        <property name="obey-child">False</property>
-        <property name="ratio">1.0</property>
-        <property name="xalign">0.5</property>
-        <property name="yalign">0.5</property>
-        <property name="margin-top">10</property>
-        <property name="margin-start">10</property>
-        <property name="margin-end">10</property>
-        <property name="margin-bottom">10</property>
+      <object class="GamesGridFrame" id="grid_frame">
+        <property name="visible">True</property>
       </object>
     </child>
   </template>
diff --git a/data/ui/help-overlay.ui b/data/ui/help-overlay.ui
index a2cac10..e70717b 100644
--- a/data/ui/help-overlay.ui
+++ b/data/ui/help-overlay.ui
@@ -16,30 +16,35 @@
   along with Five-or-More.  If not, see <https://www.gnu.org/licenses/>.
 -->
 <interface>
-  <requires lib="gtk+" version="3.99"/>
+  <requires lib="gtk+" version="3.12"/>
   <object class="GtkShortcutsWindow" id="help_overlay">
     <child>
       <object class="GtkShortcutsSection">
+        <property name="visible">True</property>
         <property name="max-height">6</property>
         <child>
           <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
             <!-- Translators: header of the "Start a new game" (only) shortcut section -->
             <property name="title" translatable="yes" context="shortcut window">New game</property>
             <child>
               <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
                 <!-- Translators: in the Keyboard Shortcuts window, section "New game"; action of the Ctrl-N 
shortcut -->
                 <property name="title" translatable="yes" context="shortcut window">Start a new 
game</property>
-                <property name="accelerator">&lt;Control&gt;n</property>
+                <property name="accelerator">&lt;Primary&gt;n</property>
               </object>
             </child>
           </object>
         </child>
         <child>
           <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
             <!-- Translators: header of the "Play with keyboard" shortcut section -->
             <property name="title" translatable="yes" context="shortcut window">Play with keyboard</property>
             <child>
               <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
                 <!-- Translators: in the Keyboard Shortcuts window, section "Play with keyboard"; action of 
the arrows -->
                 <property name="title" translatable="yes" context="shortcut window">Move keyboard 
cursor</property>
                 <property name="accelerator">Left Up Right Down</property>
@@ -47,6 +52,7 @@
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
                 <!-- Translators: in the Keyboard Shortcuts window, section "Play with keyboard"; action of 
the return or space keys -->
                 <property name="title" translatable="yes" context="shortcut window">Select or drop 
tile</property>
                 <property name="accelerator">Return space</property>
@@ -56,10 +62,12 @@
         </child>
         <child>
           <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
             <!-- Translators: header of the "Toggle main menu," "Keyboard shortcuts," "About," "Quit," etc. 
shortcuts section -->
             <property name="title" translatable="yes" context="shortcut window">Generic</property>
             <child>
               <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
                 <!-- Translators: in the Keyboard Shortcuts window, section "Generic"; action of the F10 
shortcut; toggles the hamburger menu -->
                 <property name="title" translatable="yes" context="shortcut window">Toggle main 
menu</property>
                 <property name="accelerator">F10</property>
@@ -67,13 +75,15 @@
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
                 <!-- Translators: in the Keyboard Shortcuts window, section "Generic"; action of the 
Ctrl-Shift-? shortcut; opens the Keyboard Shortcuts dialog -->
                 <property name="title" translatable="yes" context="shortcut window">Keyboard 
shortcuts</property>
-                <property name="accelerator">&lt;Control&gt;question</property> <!-- TODO &lt;Control&gt;F1 
-->
+                <property name="accelerator">&lt;Primary&gt;question</property> <!-- TODO &lt;Primary&gt;F1 
-->
               </object>
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
                 <!-- Translators: in the Keyboard Shortcuts window, section "Generic"; action of the F1 
shortcut; opens the help of the application -->
                 <property name="title" translatable="yes" context="shortcut window">Help</property>
                 <property name="accelerator">F1</property>
@@ -89,9 +99,10 @@
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
                 <!-- Translators: in the Keyboard Shortcuts window, section "Generic"; action of the Ctrl-Q 
shortcut; quits the application -->
                 <property name="title" translatable="yes" context="shortcut window">Quit</property>
-                <property name="accelerator">&lt;Control&gt;q</property>
+                <property name="accelerator">&lt;Primary&gt;q</property>
               </object>
             </child>
           </object>
diff --git a/meson.build b/meson.build
index af3a5b5..ec110fc 100644
--- a/meson.build
+++ b/meson.build
@@ -20,7 +20,7 @@ gee_dep = dependency('gee-0.8')
 gio_dep = dependency('gio-2.0', version: '>= ' + glib_min_version)
 glib_dep = dependency('glib-2.0', version: '>= ' + glib_min_version)
 gmodule_export_dep = dependency('gmodule-export-2.0')
-gtk_dep = dependency('gtk4', version: '>= 3.99.1')
+gtk_dep = dependency('gtk+-3.0', version: '>= 3.24.0')
 libgnome_games_support_dep = dependency('libgnome-games-support-1', version: '>= 1.7.1')
 librsvg_dep = dependency('librsvg-2.0', version: '>= 2.32.0')
 
diff --git a/org.gnome.five-or-more.json b/org.gnome.five-or-more.json
index dcac51b..1791cd5 100644
--- a/org.gnome.five-or-more.json
+++ b/org.gnome.five-or-more.json
@@ -30,9 +30,9 @@
             "name": "libgnome-games-support",
             "buildsystem": "meson",
             "sources": [{
-                "type": "git",
-                "url": "https://gitlab.gnome.org/GNOME/libgnome-games-support.git";,
-                "branch": "arnaudb/wip/gtk4"
+                "type": "archive",
+                "url": 
"https://download.gnome.org/sources/libgnome-games-support/1.7/libgnome-games-support-1.7.1.tar.xz";,
+                "sha256": "a625b32e12634bf94fa643f928eb46a387ed8eeb2fe969d5a868a775efc8e185"
             }]
         },
         {
diff --git a/src/main.vala b/src/main.vala
index 1c98e9c..4d910b6 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -66,8 +66,8 @@ private class FiveOrMoreApp: Gtk.Application
         add_window (window);
 
         add_action_entries (action_entries, this);
-        set_accels_for_action ("win.new-game",  { "<Control>n"  });
-        set_accels_for_action ("app.quit",      { "<Control>q"  });
+        set_accels_for_action ("win.new-game",  { "<Primary>n"  });
+        set_accels_for_action ("app.quit",      { "<Primary>q"  });
         set_accels_for_action ("app.help",      {          "F1" });
     }
 
@@ -78,7 +78,14 @@ private class FiveOrMoreApp: Gtk.Application
 
     private void help_cb ()
     {
-        Gtk.show_uri (window, "help:five-or-more", Gdk.CURRENT_TIME);
+        try
+        {
+            Gtk.show_uri_on_window (window, "help:five-or-more", Gtk.get_current_event_time ());
+        }
+        catch (GLib.Error e)
+        {
+            GLib.warning ("Unable to open help: %s", e.message);
+        }
     }
 
     private void about_cb ()
@@ -134,7 +141,7 @@ private class FiveOrMoreApp: Gtk.Application
 
     protected override void shutdown ()
     {
-        window.destroy ();
+        window.on_shutdown ();
         base.shutdown ();
     }
 }
diff --git a/src/next-pieces-widget.vala b/src/next-pieces-widget.vala
index 4b40349..b891676 100644
--- a/src/next-pieces-widget.vala
+++ b/src/next-pieces-widget.vala
@@ -36,8 +36,6 @@ private class NextPiecesWidget : Gtk.DrawingArea
         this.game = game;
         this.theme = theme;
 
-        set_draw_func (draw);
-
         set_queue_size ();
         settings.changed[FiveOrMoreApp.KEY_SIZE].connect (() => {
             set_queue_size ();
@@ -61,10 +59,10 @@ private class NextPiecesWidget : Gtk.DrawingArea
         queue_draw ();
     }
 
-    private void draw (Gtk.DrawingArea _this, Cairo.Context cr, int new_width, int new_height)
+    protected override bool draw (Cairo.Context cr)
     {
         if (theme == null)
-            return;
+            return false;
 
         if (widget_height == -1)
         {
@@ -88,5 +86,7 @@ private class NextPiecesWidget : Gtk.DrawingArea
         }
 
         cr.stroke ();
+
+        return true;
     }
 }
diff --git a/src/view.vala b/src/view.vala
index e714fa7..21ce61a 100644
--- a/src/view.vala
+++ b/src/view.vala
@@ -51,9 +51,8 @@ private class View : DrawingArea
     private uint animation_id;
 
     private EventControllerKey key_controller;          // for keeping in memory
-    private GestureClick click_controller;              // for keeping in memory
+    private GestureMultiPress click_controller;         // for keeping in memory
 
-    private Gdk.RGBA background_color_rgba;
     internal const string default_background_color = "rgb(117,144,174)";
     private string _background_color = default_background_color;
     internal string background_color
@@ -61,11 +60,21 @@ private class View : DrawingArea
         internal get { return _background_color; }
         internal set
         {
-            if (!background_color_rgba.parse (value))
-                if (!background_color_rgba.parse (default_background_color))
-                    assert_not_reached ();
-            _background_color = background_color_rgba.to_string ();
+            Gdk.RGBA color = Gdk.RGBA ();
+            if (!color.parse (value))
+                _background_color = default_background_color;
+            else
+                _background_color = color.to_string ();
 
+            try
+            {
+                provider.load_from_data (".game-view { background-color: %s; }".printf (_background_color));
+            }
+            catch (Error e)
+            {
+                warning ("Failed to load CSS data to provider");
+                return;
+            }
             queue_draw ();
         }
     }
@@ -75,11 +84,8 @@ private class View : DrawingArea
         this.game = game;
         this.theme = theme;
 
-        focusable = true;
-
         init_keyboard ();
         init_mouse ();
-        set_draw_func (draw);
 
         cs = get_style_context ();
         provider = new CssProvider ();
@@ -100,7 +106,10 @@ private class View : DrawingArea
         });
 
         game.board.grid_changed.connect (queue_draw);
+        add_events (Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK);
+        add_events (Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK);
 
+        set_can_focus (true);
         grab_focus ();
 
         game.current_path_cell_pos_changed.connect (queue_draw);
@@ -135,7 +144,7 @@ private class View : DrawingArea
         if (!show_cursor)
         {
             show_cursor = true;
-         // queue_draw_area (keyboard_cursor_x * piece_size, keyboard_cursor_y * piece_size, piece_size, 
piece_size);
+            queue_draw_area (keyboard_cursor_x * piece_size, keyboard_cursor_y * piece_size, piece_size, 
piece_size);
         }
 
         keyboard_cursor_x += x;
@@ -153,19 +162,17 @@ private class View : DrawingArea
         if (keyboard_cursor_x == prev_x && keyboard_cursor_y == prev_y)
             return;
 
-     // queue_draw_area (prev_x * piece_size, prev_y * piece_size, piece_size, piece_size);
-     // queue_draw_area (keyboard_cursor_x * piece_size, keyboard_cursor_y * piece_size, piece_size, 
piece_size);
-        queue_draw ();
+        queue_draw_area (prev_x * piece_size, prev_y * piece_size, piece_size, piece_size);
+        queue_draw_area (keyboard_cursor_x * piece_size, keyboard_cursor_y * piece_size, piece_size, 
piece_size);
     }
 
     private void init_keyboard ()
     {
-        key_controller = new EventControllerKey ();
+        key_controller = new Gtk.EventControllerKey (this);
         key_controller.key_pressed.connect (on_key_pressed);
-        add_controller (key_controller);
     }
 
-    private inline bool on_key_pressed (EventControllerKey _key_controller, uint keyval, uint keycode, 
Gdk.ModifierType state)
+    private inline bool on_key_pressed (Gtk.EventControllerKey _key_controller, uint keyval, uint keycode, 
Gdk.ModifierType state)
     {
         switch (keyval)
         {
@@ -286,12 +293,11 @@ private class View : DrawingArea
 
     private void init_mouse ()
     {
-        click_controller = new GestureClick ();         // only reacts to Gdk.BUTTON_PRIMARY
+        click_controller = new GestureMultiPress (this);    // only reacts to Gdk.BUTTON_PRIMARY
         click_controller.pressed.connect (on_click);
-        add_controller (click_controller);
     }
 
-    private inline void on_click (GestureClick _click_controller, int n_press, double event_x, double 
event_y)
+    private inline void on_click (GestureMultiPress _click_controller, int n_press, double event_x, double 
event_y)
     {
         if (game == null || game.animating)
             return;
@@ -299,8 +305,7 @@ private class View : DrawingArea
         if (show_cursor)
         {
             show_cursor = false;
-         // queue_draw_area (keyboard_cursor_x * piece_size, keyboard_cursor_y * piece_size, piece_size, 
piece_size);
-            queue_draw ();
+            queue_draw_area (keyboard_cursor_x * piece_size, keyboard_cursor_y * piece_size, piece_size, 
piece_size);
         }
 
         cell_x = (int)event_x / piece_size;
@@ -320,25 +325,27 @@ private class View : DrawingArea
     private void update_sizes (int width, int height)
     {
         piece_size = (width - 1) / game.n_cols;
-        board_rectangle.width  = piece_size * game.n_cols;
+        board_rectangle.width = piece_size * game.n_cols;
         board_rectangle.height = piece_size * game.n_rows;
-        board_rectangle.x = (width  - board_rectangle.width)  / 2;
-        board_rectangle.y = (height - board_rectangle.height) / 2;
+    }
+
+    protected override bool configure_event (Gdk.EventConfigure event)
+    {
+        update_sizes (event.width, event.height);
+        queue_draw ();
+
+        return true;
     }
 
     private void fill_background (Cairo.Context cr)
     {
-        Gdk.cairo_set_source_rgba (cr, background_color_rgba);
-        cr.rectangle (/* x and y */ board_rectangle.x + 1.0,
-                                    board_rectangle.y + 1.0,
-                      /* w and h */ board_rectangle.width,
-                                    board_rectangle.height);
-        cr.fill ();
+        cs.render_background (cr, board_rectangle.x, board_rectangle.y, board_rectangle.width, 
board_rectangle.height);
     }
 
     private void draw_gridlines (Cairo.Context cr)
     {
-        cr.set_source_rgba (0.0, 0.0, 0.0, 0.8);
+        Gdk.RGBA grid_color = cs.get_color (cs.get_state ());
+        Gdk.cairo_set_source_rgba (cr, grid_color);
         cr.set_line_width (1.0);
 
         for (int i = piece_size; i < board_rectangle.width; i += piece_size)
@@ -358,7 +365,6 @@ private class View : DrawingArea
         border.width = board_rectangle.width;
         border.height = board_rectangle.height;
 
-        cr.set_source_rgba (0.0, 0.0, 0.0, 1.0);
         Gdk.cairo_rectangle (cr, border);
         cr.stroke ();
     }
@@ -367,7 +373,7 @@ private class View : DrawingArea
     {
         if (show_cursor)
         {
-            Gdk.RGBA grid_color = cs.get_color ();
+            Gdk.RGBA grid_color = cs.get_color (cs.get_state ());
             Gdk.cairo_set_source_rgba (cr, grid_color);
             cr.set_line_width (2.0);
 
@@ -414,20 +420,17 @@ private class View : DrawingArea
         }
     }
 
-    private inline void draw (DrawingArea _this, Cairo.Context cr, int new_width, int new_height)
+    protected override bool draw (Cairo.Context cr)
     {
         if (theme == null)
-            return;
-
-        update_sizes (new_width, new_height);
+            return false;
 
         fill_background (cr);
-        cr.save ();
-        cr.translate (board_rectangle.x, board_rectangle.y);
         draw_gridlines (cr);
         draw_shapes (cr);
         draw_cursor_box (cr);
         draw_path (cr);
-        cr.restore ();
+
+        return true;
     }
 }
diff --git a/src/window.vala b/src/window.vala
index a899603..9f6e048 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -33,11 +33,11 @@ private class GameWindow : ApplicationWindow
     private Box preview_hbox;
 
     [GtkChild]
-    private AspectFrame grid_frame;
+    private Games.GridFrame grid_frame;
 
     private GLib.Settings settings = new GLib.Settings ("org.gnome.five-or-more");
-    private bool window_is_tiled;
-    private bool window_is_maximized;
+    private bool window_tiled;
+    private bool window_maximized;
     private int window_width;
     private int window_height;
 
@@ -74,9 +74,6 @@ private class GameWindow : ApplicationWindow
     {
         add_action_entries (win_actions, this);
 
-        map.connect (init_state_watcher);
-        unmap.connect (on_unmap);
-
         SimpleAction theme_action = (SimpleAction) lookup_action ("change-theme");
         string theme_value = settings.get_string (FiveOrMoreApp.KEY_THEME);
         if (theme_value != "balls.svg" && theme_value != "shapes.svg" && theme_value != "tango.svg") /* TODO 
use an enum in GSchema file? */
@@ -97,21 +94,21 @@ private class GameWindow : ApplicationWindow
             default: assert_not_reached ();
         }
         ((SimpleAction) board_size_action).set_state (board_size_string);
-        update_ratio (board_size);
 
         game = new Game (board_size);
         theme = new ThemeRenderer (settings);
 
-        window_width = settings.get_int ("window-width");
-        window_height = settings.get_int ("window-height");
-        window_is_maximized = settings.get_boolean ("window-is-maximized");
-        if (window_is_maximized)
+        set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
+        if (settings.get_boolean ("window-is-maximized"))
             maximize ();
-        set_default_size (window_width, window_height);
 
         NextPiecesWidget next_pieces_widget = new NextPiecesWidget (settings, game, theme);
-        preview_hbox.prepend (next_pieces_widget);
+        preview_hbox.pack_start (next_pieces_widget);
+        next_pieces_widget.realize ();
+        next_pieces_widget.show ();
 
+        grid_frame.set (game.n_cols, game.n_rows);
+        game.board.board_changed.connect (() => { grid_frame.set (game.n_cols, game.n_rows); });
         game.notify["score"].connect ((s, p) => { set_status_message 
(status[StatusMessage.NONE].printf(game.score)); });
         game.notify["status-message"].connect ((s, p) => { set_status_message 
(status[game.status_message].printf(game.score)); });
         set_status_message (status[game.status_message]);
@@ -120,64 +117,48 @@ private class GameWindow : ApplicationWindow
         SimpleAction reset_background_action = (SimpleAction) lookup_action ("reset-bg");
         game_view.notify ["background-color"].connect (() => { reset_background_action.set_enabled 
(game_view.background_color != View.default_background_color); });
         settings.bind (FiveOrMoreApp.KEY_BACKGROUND_COLOR, game_view, "background-color", 
SettingsBindFlags.DEFAULT);
-        grid_frame.set_child (game_view);
+        grid_frame.add (game_view);
+        game_view.show ();
+
+        grid_frame.show ();
 
         init_scores_dialog ();
     }
 
-    private void init_state_watcher ()
+    protected override bool window_state_event (Gdk.EventWindowState event)
     {
-        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);
-        surface.size_changed.connect (on_size_changed);
-    }
+        if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
+            window_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
 
-    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 ();
+        if ((event.changed_mask & Gdk.WindowState.TILED) != 0)
+            window_tiled = (event.new_window_state & Gdk.WindowState.TILED) != 0;
 
-        window_is_maximized =   (state & Gdk.ToplevelState.MAXIMIZED)   != 0;
-        window_is_tiled =       (state & tiled_state)                   != 0;
+        return false;
     }
 
-    private inline void on_size_changed (int width, int height)
+    protected override void size_allocate (Allocation allocation)
     {
-        if (window_is_maximized || window_is_tiled)
+        base.size_allocate (allocation);
+
+        if (window_maximized || window_tiled)
             return;
-        get_size (out window_width, out window_height);
+
+        window_width = allocation.width;
+        window_height = allocation.height;
     }
 
-    private inline void on_unmap ()
+    internal inline void on_shutdown ()
     {
         settings.delay ();
         settings.set_int ("window-width", window_width);
         settings.set_int ("window-height", window_height);
-        settings.set_boolean ("window-is-maximized", window_is_maximized);
+        settings.set_boolean ("window-is-maximized", window_maximized);
         settings.apply ();
-
-        application.quit ();
     }
 
     private void set_status_message (string? message)
     {
-//        headerbar.set_subtitle (message);
-    }
-
-    private void update_ratio (int size)
-    {
-        if (size == /* large */ 3)
-            grid_frame.ratio = 4.0f/3.0f;
-        else
-            grid_frame.ratio = 1.0f;
+        headerbar.set_subtitle (message);
     }
 
     /*\
@@ -189,14 +170,14 @@ private class GameWindow : ApplicationWindow
     private inline void init_scores_dialog ()
     {
         var importer = new Games.Scores.DirectoryImporter ();
-        highscores = new Games.Scores.Context.with_importer ("five-or-more",
-                                                             "org.gnome.five-or-more",
-                                                             /* Translators: text in the Scores dialog, 
introducing the combobox */
-                                                             _("Board Size: "),
-                                                             this,
-                                                             create_category_from_key,
-                                                             Games.Scores.Style.POINTS_GREATER_IS_BETTER,
-                                                             importer);
+        highscores = new Games.Scores.Context.with_importer_and_icon_name ("five-or-more",
+                                                                           /* Translators: text in the 
Scores dialog, introducing the combobox */
+                                                                           _("Board Size: "),
+                                                                           this,
+                                                                           create_category_from_key,
+                                                                           
Games.Scores.Style.POINTS_GREATER_IS_BETTER,
+                                                                           importer,
+                                                                           "org.gnome.five-or-more");
         game.game_over.connect (score_cb);
     }
 
@@ -246,12 +227,11 @@ private class GameWindow : ApplicationWindow
                 if (!settings.set_string (FiveOrMoreApp.KEY_BACKGROUND_COLOR, color.to_string ()))
                     warning ("Failed to set color: %s", color.to_string ());
             });
-        dialog.response.connect ((_dialog, response) => {
-                _dialog.destroy ();
-                if (response != ResponseType.OK)
-                    settings.set_string (FiveOrMoreApp.KEY_BACKGROUND_COLOR, old_color_string);
-            });
-        dialog.present ();
+        var result = dialog.run ();
+        dialog.destroy ();
+        if (result == ResponseType.OK)
+            return;
+        settings.set_string (FiveOrMoreApp.KEY_BACKGROUND_COLOR, old_color_string);
     }
 
     private inline void reset_background ()
@@ -282,7 +262,6 @@ private class GameWindow : ApplicationWindow
             default: assert_not_reached ();
         }
         settings.set_int (FiveOrMoreApp.KEY_SIZE, size);
-        update_ratio (size);
     }
 
     private inline void new_game (/* SimpleAction action, Variant? parameter */)
@@ -291,7 +270,7 @@ private class GameWindow : ApplicationWindow
         int n_rows = Game.game_difficulty[size].n_rows;
         int n_cols = Game.game_difficulty[size].n_cols;
         if (game.score > 0 && !game.is_game_over) {
-            var flags = DialogFlags.DESTROY_WITH_PARENT | DialogFlags.MODAL;
+            var flags = DialogFlags.DESTROY_WITH_PARENT;
             var restart_game_dialog = new MessageDialog (this,
                                                          flags,
                                                          MessageType.WARNING,
@@ -305,13 +284,10 @@ private class GameWindow : ApplicationWindow
             /* Translators: button of a dialog that appears when the user starts a new game while the score 
is not null; the other answer is "_Cancel" */
                                              _("_Restart"), ResponseType.OK);
 
-            restart_game_dialog.response.connect ((_restart_game_dialog, response) => {
-                    _restart_game_dialog.destroy ();
-                    if (response == ResponseType.OK)
-                        game.new_game (size);
-                });
-            restart_game_dialog.present ();
-            return;
+            var result = restart_game_dialog.run ();
+            restart_game_dialog.destroy ();
+            if (result != ResponseType.OK)
+                return;
         }
         game.new_game (size);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]