From 584faa537d5ac706378d8e03008e43abd078945a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 9 Dec 2023 10:47:56 -0800 Subject: [PATCH] Port to GTK4 (#67) --- .github/workflows/main.yml | 2 +- README.md | 4 ++-- meson.build | 4 ++-- src/Agent.vala | 2 +- src/PolkitDialog.vala | 37 +++++++++++-------------------------- 5 files changed, 17 insertions(+), 32 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fc72412..5626d82 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: - name: Install Dependencies run: | apt update - apt install -y libgranite-dev libgtk-3-dev libpolkit-agent-1-dev libpolkit-gobject-1-dev meson valac + apt install -y libgranite-7-dev libgtk-4-dev libpolkit-agent-1-dev libpolkit-gobject-1-dev meson valac - name: Build env: DESTDIR: out diff --git a/README.md b/README.md index 789fc20..a543523 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ ## Building, Testing, and Installation You'll need the following dependencies: -* libgranite-dev (>= 6.0.0) -* libgtk-3-dev +* libgranite-7-dev (>= 7.0.0) +* libgtk-4-dev * libpolkit-gobject-1-dev * libpolkit-agent-1-dev * meson diff --git a/meson.build b/meson.build index ff2b1ce..354312f 100644 --- a/meson.build +++ b/meson.build @@ -18,8 +18,8 @@ executable( dependencies: [ dependency('glib-2.0'), dependency('gobject-2.0'), - dependency('granite', version: '>=6.0.0'), - dependency('gtk+-3.0'), + dependency('granite-7', version: '>=7.0.0'), + dependency('gtk4'), dependency('polkit-agent-1'), dependency('polkit-gobject-1'), meson.get_compiler('vala').find_library('posix') diff --git a/src/Agent.vala b/src/Agent.vala index 485037e..6752c1e 100644 --- a/src/Agent.vala +++ b/src/Agent.vala @@ -34,7 +34,7 @@ namespace Ag { var dialog = new PolkitDialog (message, icon_name, cookie, identities, cancellable); dialog.done.connect (() => initiate_authentication.callback ()); - dialog.show_all (); + dialog.present (); yield; dialog.destroy (); diff --git a/src/PolkitDialog.vala b/src/PolkitDialog.vala index 5db00df..e20ca98 100644 --- a/src/PolkitDialog.vala +++ b/src/PolkitDialog.vala @@ -74,7 +74,7 @@ public class Ag.PolkitDialog : Granite.MessageDialog { wrap = true, xalign = 1 }; - password_feedback.get_style_context ().add_class (Gtk.STYLE_CLASS_ERROR); + password_feedback.add_css_class (Granite.STYLE_CLASS_ERROR); feedback_revealer = new Gtk.Revealer () { child = password_feedback @@ -95,31 +95,29 @@ public class Ag.PolkitDialog : Granite.MessageDialog { idents_combo.add_attribute (renderer, "text", 1); idents_combo.set_id_column (1); - var credentials_grid = new Gtk.Grid () { - column_spacing = 12, - row_spacing = 6 - }; - credentials_grid.attach (idents_combo, 0, 0); - credentials_grid.attach (password_entry, 0, 2); - credentials_grid.attach (feedback_revealer, 0, 3); + var credentials_box = new Gtk.Box (VERTICAL, 6); + credentials_box.append (idents_combo); + credentials_box.append (password_entry); + credentials_box.append (feedback_revealer); image_icon = new ThemedIcon ("dialog-password"); - if (icon_name != "" && Gtk.IconTheme.get_default ().has_icon (icon_name)) { + if (icon_name != "" && Gtk.IconTheme.get_for_display (Gdk.Display.get_default ()).has_icon (icon_name)) { badge_icon = new ThemedIcon (icon_name); } - custom_bin.add (credentials_grid); + custom_bin.append (credentials_box); var cancel_button = (Gtk.Button)add_button (_("Cancel"), Gtk.ResponseType.CANCEL); cancel_button.clicked.connect (() => cancel ()); var authenticate_button = (Gtk.Button)add_button (_("Authenticate"), Gtk.ResponseType.APPLY); - authenticate_button.can_default = true; - authenticate_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); + authenticate_button.receives_default = true; + authenticate_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION); authenticate_button.clicked.connect (authenticate); - set_default (authenticate_button); + default_widget = authenticate_button; + focus_widget = password_entry; close.connect (cancel); @@ -127,18 +125,6 @@ public class Ag.PolkitDialog : Granite.MessageDialog { select_session (); } - public override void show () { - base.show (); - - var window = get_window (); - if (window == null) { - return; - } - - window.focus (Gdk.CURRENT_TIME); - password_entry.grab_focus (); - } - private void update_idents () { var model = new Gtk.ListStore (3, typeof (string), typeof (string), typeof (Polkit.Identity)); Gtk.TreeIter iter; @@ -188,7 +174,6 @@ public class Ag.PolkitDialog : Granite.MessageDialog { if (length < 2) { if (target_user == Environment.get_user_name ()) { idents_combo.visible = false; - idents_combo.no_show_all = true; } else { idents_combo.sensitive = false; }