From f9cbad9ad99d6ca12591406c8142778d5f621e5d Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Tue, 21 Dec 2021 12:15:46 -0800 Subject: [PATCH] general: Use `adw` alias for `libadwaita` This will make writing libadwaita-based code a bit nicer, and make it nicer when we use crates that libadwaita's API re-exports. Also clean up the unused imports exposed by this change. --- Cargo.toml | 5 ++++- src/application.rs | 13 +++++-------- src/main.rs | 2 +- src/widgets/image_view.rs | 7 +++---- src/window.rs | 15 +++++++-------- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 56e93db..741d458 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ gdk-pixbuf = "0.14" gio = "0.14" glib = "0.14" cairo-rs = "0.14" -libadwaita = "0.1.0-alpha-6" [dependencies.ashpd] git = "https://github.com/bilelmoussaoui/ashpd" @@ -29,6 +28,10 @@ version = "0.3" package = "gdk4" version = "0.3" +[dependencies.adw] +package = "libadwaita" +version = "0.1.0-alpha-6" + [dependencies.gettext-rs] version = "0.7.0" features = ["gettext-system"] diff --git a/src/application.rs b/src/application.rs index f83b4e5..60786f9 100644 --- a/src/application.rs +++ b/src/application.rs @@ -17,14 +17,11 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -use gio::prelude::*; +use adw::prelude::*; +use adw::subclass::prelude::*; use glib::clone; -use glib::subclass::prelude::*; -use gtk::prelude::*; use gtk::subclass::prelude::*; use gtk_macros::*; -use libadwaita::prelude::*; -use libadwaita::subclass::prelude::*; use crate::config; use crate::window::LpWindow; @@ -46,7 +43,7 @@ mod imp { impl ObjectSubclass for LpApplication { const NAME: &'static str = "LpApplication"; type Type = super::LpApplication; - type ParentType = libadwaita::Application; + type ParentType = adw::Application; // Initialize with default values fn new() -> Self { @@ -64,7 +61,7 @@ mod imp { // Force dark theme obj.style_manager() - .set_color_scheme(libadwaita::ColorScheme::PreferDark); + .set_color_scheme(adw::ColorScheme::PreferDark); // Set up the actions obj.setup_actions(); @@ -100,7 +97,7 @@ mod imp { // LpApplication without casting. glib::wrapper! { pub struct LpApplication(ObjectSubclass) - @extends gio::Application, gtk::Application, libadwaita::Application, + @extends gio::Application, gtk::Application, adw::Application, @implements gio::ActionGroup, gio::ActionMap; } diff --git a/src/main.rs b/src/main.rs index e81a466..7658bfe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ use application::LpApplication; fn main() { gtk::init().expect("Failed to initialize GTK."); - libadwaita::init(); + adw::init(); pretty_env_logger::init(); setlocale(LocaleCategory::LcAll, ""); diff --git a/src/widgets/image_view.rs b/src/widgets/image_view.rs index de9bafd..2908dc8 100644 --- a/src/widgets/image_view.rs +++ b/src/widgets/image_view.rs @@ -17,13 +17,12 @@ // // SPDX-License-Identifier: GPL-3.0-or-later +use adw::subclass::prelude::*; use gdk::prelude::*; use glib::clone; -use glib::subclass::prelude::*; use gtk::prelude::*; use gtk::subclass::prelude::*; use gtk::CompositeTemplate; -use libadwaita::subclass::prelude::*; use anyhow::Context; use ashpd::desktop::wallpaper; @@ -68,7 +67,7 @@ mod imp { impl ObjectSubclass for LpImageView { const NAME: &'static str = "LpImageView"; type Type = super::LpImageView; - type ParentType = libadwaita::Bin; + type ParentType = adw::Bin; fn class_init(klass: &mut Self::Class) { Self::bind_template(klass); @@ -140,7 +139,7 @@ mod imp { glib::wrapper! { pub struct LpImageView(ObjectSubclass) - @extends gtk::Widget, libadwaita::Bin, + @extends gtk::Widget, adw::Bin, @implements gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable; } diff --git a/src/window.rs b/src/window.rs index 9b657a1..02400f1 100644 --- a/src/window.rs +++ b/src/window.rs @@ -17,13 +17,12 @@ // // SPDX-License-Identifier: GPL-3.0-or-later +use adw::subclass::prelude::*; use gio::prelude::*; use glib::clone; -use glib::subclass::prelude::*; use gtk::prelude::*; use gtk::subclass::prelude::*; use gtk::CompositeTemplate; -use libadwaita::subclass::prelude::*; use crate::config; use crate::widgets::LpImageView; @@ -52,7 +51,7 @@ mod imp { // TemplateChild wrapper, where T is the // object type of the template child. #[template_child] - pub flap: TemplateChild, + pub flap: TemplateChild, #[template_child] pub headerbar: TemplateChild, #[template_child] @@ -62,7 +61,7 @@ mod imp { #[template_child] pub stack: TemplateChild, #[template_child] - pub status_page: TemplateChild, + pub status_page: TemplateChild, #[template_child] pub image_view: TemplateChild, #[template_child] @@ -73,7 +72,7 @@ mod imp { impl ObjectSubclass for LpWindow { const NAME: &'static str = "LpWindow"; type Type = super::LpWindow; - type ParentType = libadwaita::ApplicationWindow; + type ParentType = adw::ApplicationWindow; fn class_init(klass: &mut Self::Class) { // bind_template() is a function generated by the @@ -154,7 +153,7 @@ mod imp { glib::wrapper! { pub struct LpWindow(ObjectSubclass) - @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, libadwaita::ApplicationWindow, + @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, adw::ApplicationWindow, @implements gio::ActionMap, gio::ActionGroup; } @@ -167,7 +166,7 @@ impl LpWindow { let imp = imp::LpWindow::from_instance(&self); if fullscreen { - imp.flap.set_fold_policy(libadwaita::FlapFoldPolicy::Always); + imp.flap.set_fold_policy(adw::FlapFoldPolicy::Always); imp.headerbar.add_css_class("osd"); imp.menu_button.unparent(); imp.fullscreen_button.unparent(); @@ -175,7 +174,7 @@ impl LpWindow { imp.headerbar.pack_end(&*imp.menu_button); imp.fullscreen_button.set_icon_name("view-restore-symbolic"); } else { - imp.flap.set_fold_policy(libadwaita::FlapFoldPolicy::Never); + imp.flap.set_fold_policy(adw::FlapFoldPolicy::Never); imp.headerbar.remove_css_class("osd"); imp.menu_button.unparent(); imp.fullscreen_button.unparent();