[baobab/wip/gtk4] start gtk4 port



commit 9a3fc0c2acf7ceed58802343379c5316f416b4df
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Mon Sep 4 13:31:31 2017 +0200

    start gtk4 port

 README                        |    2 +-
 meson.build                   |    2 +-
 src/baobab-application.vala   |    6 +-----
 src/baobab-cellrenderers.vala |   16 ++++++++--------
 src/baobab-chart.vala         |   35 +++++++++++++++++++----------------
 src/baobab-main-window.ui     |   15 ---------------
 src/baobab-ringschart.vala    |   14 +++++---------
 src/baobab-treemap.vala       |    2 +-
 src/baobab-window.vala        |   28 +++++++++++-----------------
 9 files changed, 47 insertions(+), 73 deletions(-)
---
diff --git a/README b/README
index 0b2c077..100a73e 100644
--- a/README
+++ b/README
@@ -14,7 +14,7 @@ A detailed documentation of the program could be read at:
 System Requirements
 ===================
 
-Baobab should build on most unices. It needs GTK+ 3.
+Baobab needs GTK+ 4.
 
 
 Development
diff --git a/meson.build b/meson.build
index dfde7cb..230ca14 100644
--- a/meson.build
+++ b/meson.build
@@ -12,7 +12,7 @@ glib = dependency('glib-2.0', version: '>=2.44')
 gio = dependency('gio-2.0', version: '>=2.44')
 gio_unix = dependency('gio-unix-2.0', version: '>=2.44')
 gobject = dependency('gobject-2.0', version: '>=2.44')
-gtk = dependency('gtk+-3.0', version: '>=3.20')
+gtk = dependency('gtk+-4.0', version: '>=3.91.2')
 
 cc = meson.get_compiler('c')
 math = cc.find_library('m', required: false)
diff --git a/src/baobab-application.vala b/src/baobab-application.vala
index 0e004e7..03aeb02 100644
--- a/src/baobab-application.vala
+++ b/src/baobab-application.vala
@@ -77,11 +77,7 @@ namespace Baobab {
             // Load custom CSS
             var css_provider = new Gtk.CssProvider ();
             var css_file = File.new_for_uri ("resource:///org/gnome/baobab/baobab.css");
-            try {
-              css_provider.load_from_file (css_file);
-            } catch (Error e) {
-                warning ("loading css: %s", e.message);
-            }
+            css_provider.load_from_file (css_file);
             Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, 
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
 
             // Settings
diff --git a/src/baobab-cellrenderers.vala b/src/baobab-cellrenderers.vala
index 95c02eb..a47d3cb 100644
--- a/src/baobab-cellrenderers.vala
+++ b/src/baobab-cellrenderers.vala
@@ -40,7 +40,7 @@ namespace Baobab {
             }
         }
 
-        protected override void render (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, 
Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
+        protected override void snapshot (Gtk.Snapshot snapshot, Gtk.Widget widget, Gdk.Rectangle 
background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
             var context = widget.get_style_context ();
 
             context.save ();
@@ -54,7 +54,7 @@ namespace Baobab {
                 break;
             }
 
-            base.render (cr, widget, background_area, cell_area, flags);
+            base.snapshot (snapshot, widget, background_area, cell_area, flags);
 
             context.restore ();
         }
@@ -128,7 +128,7 @@ namespace Baobab {
     public class CellRendererProgress : Gtk.CellRendererProgress {
         public Scanner.State state { set; get; }
 
-        public override void render (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, 
Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
+        public override void snapshot (Gtk.Snapshot snapshot, Gtk.Widget widget, Gdk.Rectangle 
background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
             if (state == Scanner.State.ERROR) {
                 return;
             }
@@ -147,16 +147,16 @@ namespace Baobab {
             context.save ();
             context.add_class ("baobab-level-cell");
 
-            context.render_background (cr, x, y, w, h);
-            context.render_frame (cr, x, y, w, h);
+            snapshot.render_background (context, x, y, w, h);
+            snapshot.render_frame (context, x, y, w, h);
 
-            var border = context.get_border (Gtk.StateFlags.NORMAL);
+            var border = context.get_border ();
             x += border.left;
             y += border.top;
             w -= border.left + border.right;
             h -= border.top + border.bottom;
 
-            border = context.get_padding (Gtk.StateFlags.NORMAL);
+            border = context.get_padding ();
             x += border.left;
             y += border.top;
             w -= border.left + border.right;
@@ -177,7 +177,7 @@ namespace Baobab {
                 context.add_class ("level-high");
             }
 
-            context.render_background (cr, x_bar, y, perc_w, h);
+            snapshot.render_background (context, x_bar, y, perc_w, h);
 
             context.restore ();
         }
diff --git a/src/baobab-chart.vala b/src/baobab-chart.vala
index 703a734..a202b15 100644
--- a/src/baobab-chart.vala
+++ b/src/baobab-chart.vala
@@ -218,8 +218,6 @@ namespace Baobab {
         };
 
         construct {
-            add_events (Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.ENTER_NOTIFY_MASK | 
Gdk.EventMask.LEAVE_NOTIFY_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK | 
Gdk.EventMask.SCROLL_MASK);
-
             action_group = new SimpleActionGroup ();
             action_group.add_action_entries (action_entries, this);
             insert_action_group ("chart", action_group);
@@ -227,8 +225,8 @@ namespace Baobab {
             build_context_menu ();
         }
 
-        public override void size_allocate (Gtk.Allocation allocation) {
-            base.size_allocate (allocation);
+        public override void size_allocate (Gtk.Allocation allocation, int baseline, out Gtk.Allocation 
clip) {
+            base.size_allocate (allocation, baseline, out clip);
             foreach (ChartItem item in items) {
                 item.has_visible_children = false;
                 item.visible = false;
@@ -250,9 +248,11 @@ namespace Baobab {
         }
 
         public override bool motion_notify_event (Gdk.EventMotion event) {
-            has_tooltip = highlight_item_at_point (event.x, event.y);
+            double x, y;
+            event.get_coords(out x, out y);
+            has_tooltip = highlight_item_at_point (x, y);
 
-            Gdk.Event.request_motions (event);
+            //Gdk.Event.request_motions (event);
 
             return false;
         }
@@ -487,15 +487,20 @@ namespace Baobab {
         }
 
         protected override bool button_press_event (Gdk.EventButton event) {
-            if (event.type == Gdk.EventType.BUTTON_PRESS) {
+            if (event.get_event_type () == Gdk.EventType.BUTTON_PRESS) {
                 if (event.triggers_context_menu ()) {
                     show_popup_menu (event);
                     return true;
                 }
 
-                switch (event.button) {
+                uint button;
+                double x, y;
+                event.get_button (out button);
+                event.get_coords (out x, out y);
+
+                switch (button) {
                 case Gdk.BUTTON_PRIMARY:
-                    if (highlight_item_at_point (event.x, event.y)) {
+                    if (highlight_item_at_point (x, y)) {
                         var path = model.get_path (highlighted_item.iter);
                         if (root.compare (path) == 0) {
                             move_up_root ();
@@ -517,7 +522,9 @@ namespace Baobab {
 
         protected override bool scroll_event (Gdk.EventScroll event) {
             Gdk.EventMotion e = (Gdk.EventMotion) event;
-            switch (event.direction) {
+            Gdk.ScrollDirection direction;
+            event.get_scroll_direction (out direction);
+            switch (direction) {
             case Gdk.ScrollDirection.LEFT:
             case Gdk.ScrollDirection.UP:
                 zoom_out ();
@@ -582,7 +589,7 @@ namespace Baobab {
             context_menu.attach_to_widget (this, null);
         }
 
-        void show_popup_menu (Gdk.EventButton? event) {
+        void show_popup_menu (Gdk.EventButton event) {
             var enable = highlighted_item != null;
             var action = action_group.lookup_action ("open-file") as SimpleAction;
             action.set_enabled (enable);
@@ -599,11 +606,7 @@ namespace Baobab {
             action = action_group.lookup_action ("zoom-out") as SimpleAction;
             action.set_enabled (can_zoom_out ());
 
-            if (event != null) {
-                context_menu.popup (null, null, null, event.button, event.time);
-            } else {
-                context_menu.popup (null, null, null, 0, Gtk.get_current_event_time ());
-            }
+            context_menu.popup_at_pointer (event);
         }
 
         void connect_model_signals (Gtk.TreeModel m) {
diff --git a/src/baobab-main-window.ui b/src/baobab-main-window.ui
index 6716d9c..89c1495 100644
--- a/src/baobab-main-window.ui
+++ b/src/baobab-main-window.ui
@@ -14,7 +14,6 @@
     <property name="can_focus">False</property>
     <child>
       <object class="GtkMenuItem" id="treeview_popup_open">
-        <property name="use_action_appearance">False</property>
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="label" translatable="yes">_Open Folder</property>
@@ -23,7 +22,6 @@
     </child>
     <child>
       <object class="GtkMenuItem" id="treeview_popup_copy">
-        <property name="use_action_appearance">False</property>
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="label" translatable="yes">_Copy Path to Clipboard</property>
@@ -32,7 +30,6 @@
     </child>
     <child>
       <object class="GtkMenuItem" id="treeview_popup_trash">
-        <property name="use_action_appearance">False</property>
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="label" translatable="yes">Mo_ve to Trash</property>
@@ -120,7 +117,6 @@
                 <object class="GtkBox" id="infobar_content_area">
                   <property name="visible">True</property>
                   <property name="can_focus">False</property>
-                  <property name="border_width">8</property>
                   <property name="orientation">vertical</property>
                   <property name="spacing">16</property>
                   <property name="hexpand">True</property>
@@ -133,11 +129,6 @@
                       <property name="halign">GTK_ALIGN_START</property>
                       <property name="wrap">True</property>
                     </object>
-                    <packing>
-                      <property name="expand">False</property>
-                      <property name="fill">True</property>
-                      <property name="position">0</property>
-                    </packing>
                   </child>
                   <child>
                     <object class="GtkLabel" id="infobar_secondary_label">
@@ -148,11 +139,6 @@
                       <property name="halign">GTK_ALIGN_START</property>
                       <property name="wrap">True</property>
                     </object>
-                    <packing>
-                      <property name="expand">False</property>
-                      <property name="fill">True</property>
-                      <property name="position">1</property>
-                    </packing>
                   </child>
                 </object>
               </child>
@@ -160,7 +146,6 @@
                 <object class="GtkButtonBox" id="infobar_action_area">
                   <property name="visible">True</property>
                   <property name="can_focus">False</property>
-                  <property name="border_width">5</property>
                   <property name="orientation">vertical</property>
                   <property name="spacing">6</property>
                   <property name="layout_style">end</property>
diff --git a/src/baobab-ringschart.vala b/src/baobab-ringschart.vala
index 6fe2841..6173edf 100644
--- a/src/baobab-ringschart.vala
+++ b/src/baobab-ringschart.vala
@@ -98,7 +98,6 @@ namespace Baobab {
             }
 
             var context = get_style_context ();
-            var context_state = context.get_state ();
             context.save ();
             context.add_class ("subfolder-tip");
 
@@ -111,7 +110,7 @@ namespace Baobab {
 
             Gdk.Rectangle last_rect = Gdk.Rectangle ();
 
-            var padding = context.get_padding (context_state);
+            var padding = context.get_padding ();
             var vpadding = padding.top + padding.bottom;
             var hpadding = padding.left + padding.right;
 
@@ -198,7 +197,7 @@ namespace Baobab {
                     cr.rectangle (tooltip_rect.x + tooltip_rect.width, tooltip_rect.y, -tooltip_rect.width, 
tooltip_rect.height);
                     cr.clip ();
 
-                    var bg_color = context.get_background_color (context_state);
+                    var bg_color = context.get_background_color ();
                     cr.set_line_width (1);
                     cr.move_to (sector_center_x, sector_center_y);
                     Gdk.cairo_set_source_rgba (cr, bg_color);
@@ -239,14 +238,12 @@ namespace Baobab {
             get_allocation (out allocation);
 
             var context = get_style_context ();
-            var context_state = context.get_state ();
             context.save ();
 
             var toplevel_context = get_toplevel ().get_style_context ();
-            var toplevel_context_state = toplevel_context.get_state ();
 
-            var border_color = context.get_border_color (context_state);
-            var bg_color = toplevel_context.get_background_color (toplevel_context_state);
+            var border_color = context.get_border_color ();
+            var bg_color = toplevel_context.get_background_color ();
 
             var center_x = allocation.width / 2;
             var center_y = allocation.height / 2;
@@ -307,9 +304,8 @@ namespace Baobab {
             get_allocation (out allocation);
 
             var context = get_style_context ();
-            var context_state = context.get_state ();
 
-            var padding = context.get_padding (context_state);
+            var padding = context.get_padding ();
             var max_radius = int.min (allocation.width / 2, allocation.height / 2) - padding.left; // 
Assuming that padding is the same for all sides
             var thickness = max_radius / (max_depth + 1);
 
diff --git a/src/baobab-treemap.vala b/src/baobab-treemap.vala
index 2788a3e..d58fa19 100644
--- a/src/baobab-treemap.vala
+++ b/src/baobab-treemap.vala
@@ -66,7 +66,7 @@ namespace Baobab {
             cr.rectangle (x + border, y + border, width - border * 2, height - border * 2);
             Gdk.cairo_set_source_rgba (cr, fill_color);
             cr.fill_preserve ();
-            var border_color = context.get_border_color (context.get_state ());
+            var border_color = context.get_border_color ();
             Gdk.cairo_set_source_rgba (cr, border_color);
             cr.stroke ();
 
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index eaa394a..3dea674 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -154,13 +154,13 @@ namespace Baobab {
             resize (width, height);
 
             window_state_event.connect ((event) => {
-                ui_settings.set_int ("window-state", event.new_window_state);
+                //ui_settings.set_int ("window-state", event.new_window_state);
                 return false;
             });
 
             configure_event.connect ((event) => {
                 if (!(Gdk.WindowState.MAXIMIZED in get_window ().get_state ())) {
-                    ui_settings.set ("window-size", "(ii)", event.width, event.height);
+                    //ui_settings.set ("window-size", "(ii)", event.width, event.height);
                 }
                 return false;
             });
@@ -178,7 +178,7 @@ namespace Baobab {
             {
                 header_bar.show_close_button = false;
                 header_bar.get_style_context().remove_class("titlebar");
-                vbox.pack_start(header_bar,  false, false, 0);
+                vbox.pack_start(header_bar);
             }
 
             set_ui_state (home_page, false);
@@ -275,7 +275,7 @@ namespace Baobab {
 
         void on_help_activate () {
             try {
-                Gtk.show_uri (get_screen (), "help:baobab", Gtk.get_current_event_time ());
+                Gtk.show_uri_on_window (this, "help:baobab", Gtk.get_current_event_time ());
             } catch (Error e) {
                 message (_("Failed to show help"), e.message, Gtk.MessageType.WARNING);
             }
@@ -349,16 +349,6 @@ namespace Baobab {
             Gtk.drag_dest_unset (this);
         }
 
-        bool show_treeview_popup (Gtk.Menu popup, Gdk.EventButton? event) {
-            if (event != null) {
-                popup.popup (null, null, null, event.button, event.time);
-            } else {
-                popup.popup (null, null, null, 0, Gtk.get_current_event_time ());
-                popup.select_first (false);
-            }
-            return true;
-        }
-
         public void open_item (Gtk.TreeIter iter) {
             string parse_name;
             active_location.scanner.get (iter, Scanner.Columns.PARSE_NAME, out parse_name);
@@ -401,9 +391,12 @@ namespace Baobab {
             treeview.button_press_event.connect ((event) => {
                 if (event.triggers_context_menu ()) {
                     Gtk.TreePath path;
-                    if (treeview.get_path_at_pos ((int)event.x, (int)event.y, out path, null, null, null)) {
+                    double x, y;
+                    event.get_coords (out x, out y);
+                    if (treeview.get_path_at_pos ((int)x, (int)y, out path, null, null, null)) {
                         treeview.get_selection ().select_path (path);
-                        return show_treeview_popup (treeview_popup_menu, event);
+                        treeview_popup_menu.popup_at_pointer (event);
+                        return true;
                     }
                 }
 
@@ -411,7 +404,8 @@ namespace Baobab {
             });
 
             treeview.popup_menu.connect (() => {
-                return show_treeview_popup (treeview_popup_menu, null);
+                treeview_popup_menu.popup_at_pointer (null);
+                return true;
             });
 
             treeview_popup_open.activate.connect (() => {


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