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.
This commit is contained in:
Christopher Davis 2021-12-21 12:15:46 -08:00
parent ec0f13d250
commit f9cbad9ad9
5 changed files with 20 additions and 22 deletions

View file

@ -15,7 +15,6 @@ gdk-pixbuf = "0.14"
gio = "0.14" gio = "0.14"
glib = "0.14" glib = "0.14"
cairo-rs = "0.14" cairo-rs = "0.14"
libadwaita = "0.1.0-alpha-6"
[dependencies.ashpd] [dependencies.ashpd]
git = "https://github.com/bilelmoussaoui/ashpd" git = "https://github.com/bilelmoussaoui/ashpd"
@ -29,6 +28,10 @@ version = "0.3"
package = "gdk4" package = "gdk4"
version = "0.3" version = "0.3"
[dependencies.adw]
package = "libadwaita"
version = "0.1.0-alpha-6"
[dependencies.gettext-rs] [dependencies.gettext-rs]
version = "0.7.0" version = "0.7.0"
features = ["gettext-system"] features = ["gettext-system"]

View file

@ -17,14 +17,11 @@
// //
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use gio::prelude::*; use adw::prelude::*;
use adw::subclass::prelude::*;
use glib::clone; use glib::clone;
use glib::subclass::prelude::*;
use gtk::prelude::*;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk_macros::*; use gtk_macros::*;
use libadwaita::prelude::*;
use libadwaita::subclass::prelude::*;
use crate::config; use crate::config;
use crate::window::LpWindow; use crate::window::LpWindow;
@ -46,7 +43,7 @@ mod imp {
impl ObjectSubclass for LpApplication { impl ObjectSubclass for LpApplication {
const NAME: &'static str = "LpApplication"; const NAME: &'static str = "LpApplication";
type Type = super::LpApplication; type Type = super::LpApplication;
type ParentType = libadwaita::Application; type ParentType = adw::Application;
// Initialize with default values // Initialize with default values
fn new() -> Self { fn new() -> Self {
@ -64,7 +61,7 @@ mod imp {
// Force dark theme // Force dark theme
obj.style_manager() obj.style_manager()
.set_color_scheme(libadwaita::ColorScheme::PreferDark); .set_color_scheme(adw::ColorScheme::PreferDark);
// Set up the actions // Set up the actions
obj.setup_actions(); obj.setup_actions();
@ -100,7 +97,7 @@ mod imp {
// LpApplication without casting. // LpApplication without casting.
glib::wrapper! { glib::wrapper! {
pub struct LpApplication(ObjectSubclass<imp::LpApplication>) pub struct LpApplication(ObjectSubclass<imp::LpApplication>)
@extends gio::Application, gtk::Application, libadwaita::Application, @extends gio::Application, gtk::Application, adw::Application,
@implements gio::ActionGroup, gio::ActionMap; @implements gio::ActionGroup, gio::ActionMap;
} }

View file

@ -30,7 +30,7 @@ use application::LpApplication;
fn main() { fn main() {
gtk::init().expect("Failed to initialize GTK."); gtk::init().expect("Failed to initialize GTK.");
libadwaita::init(); adw::init();
pretty_env_logger::init(); pretty_env_logger::init();
setlocale(LocaleCategory::LcAll, ""); setlocale(LocaleCategory::LcAll, "");

View file

@ -17,13 +17,12 @@
// //
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use adw::subclass::prelude::*;
use gdk::prelude::*; use gdk::prelude::*;
use glib::clone; use glib::clone;
use glib::subclass::prelude::*;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::CompositeTemplate; use gtk::CompositeTemplate;
use libadwaita::subclass::prelude::*;
use anyhow::Context; use anyhow::Context;
use ashpd::desktop::wallpaper; use ashpd::desktop::wallpaper;
@ -68,7 +67,7 @@ mod imp {
impl ObjectSubclass for LpImageView { impl ObjectSubclass for LpImageView {
const NAME: &'static str = "LpImageView"; const NAME: &'static str = "LpImageView";
type Type = super::LpImageView; type Type = super::LpImageView;
type ParentType = libadwaita::Bin; type ParentType = adw::Bin;
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
Self::bind_template(klass); Self::bind_template(klass);
@ -140,7 +139,7 @@ mod imp {
glib::wrapper! { glib::wrapper! {
pub struct LpImageView(ObjectSubclass<imp::LpImageView>) pub struct LpImageView(ObjectSubclass<imp::LpImageView>)
@extends gtk::Widget, libadwaita::Bin, @extends gtk::Widget, adw::Bin,
@implements gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable; @implements gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
} }

View file

@ -17,13 +17,12 @@
// //
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use adw::subclass::prelude::*;
use gio::prelude::*; use gio::prelude::*;
use glib::clone; use glib::clone;
use glib::subclass::prelude::*;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::CompositeTemplate; use gtk::CompositeTemplate;
use libadwaita::subclass::prelude::*;
use crate::config; use crate::config;
use crate::widgets::LpImageView; use crate::widgets::LpImageView;
@ -52,7 +51,7 @@ mod imp {
// TemplateChild<T> wrapper, where T is the // TemplateChild<T> wrapper, where T is the
// object type of the template child. // object type of the template child.
#[template_child] #[template_child]
pub flap: TemplateChild<libadwaita::Flap>, pub flap: TemplateChild<adw::Flap>,
#[template_child] #[template_child]
pub headerbar: TemplateChild<gtk::HeaderBar>, pub headerbar: TemplateChild<gtk::HeaderBar>,
#[template_child] #[template_child]
@ -62,7 +61,7 @@ mod imp {
#[template_child] #[template_child]
pub stack: TemplateChild<gtk::Stack>, pub stack: TemplateChild<gtk::Stack>,
#[template_child] #[template_child]
pub status_page: TemplateChild<libadwaita::StatusPage>, pub status_page: TemplateChild<adw::StatusPage>,
#[template_child] #[template_child]
pub image_view: TemplateChild<LpImageView>, pub image_view: TemplateChild<LpImageView>,
#[template_child] #[template_child]
@ -73,7 +72,7 @@ mod imp {
impl ObjectSubclass for LpWindow { impl ObjectSubclass for LpWindow {
const NAME: &'static str = "LpWindow"; const NAME: &'static str = "LpWindow";
type Type = super::LpWindow; type Type = super::LpWindow;
type ParentType = libadwaita::ApplicationWindow; type ParentType = adw::ApplicationWindow;
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
// bind_template() is a function generated by the // bind_template() is a function generated by the
@ -154,7 +153,7 @@ mod imp {
glib::wrapper! { glib::wrapper! {
pub struct LpWindow(ObjectSubclass<imp::LpWindow>) pub struct LpWindow(ObjectSubclass<imp::LpWindow>)
@extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, libadwaita::ApplicationWindow, @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, adw::ApplicationWindow,
@implements gio::ActionMap, gio::ActionGroup; @implements gio::ActionMap, gio::ActionGroup;
} }
@ -167,7 +166,7 @@ impl LpWindow {
let imp = imp::LpWindow::from_instance(&self); let imp = imp::LpWindow::from_instance(&self);
if fullscreen { 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.headerbar.add_css_class("osd");
imp.menu_button.unparent(); imp.menu_button.unparent();
imp.fullscreen_button.unparent(); imp.fullscreen_button.unparent();
@ -175,7 +174,7 @@ impl LpWindow {
imp.headerbar.pack_end(&*imp.menu_button); imp.headerbar.pack_end(&*imp.menu_button);
imp.fullscreen_button.set_icon_name("view-restore-symbolic"); imp.fullscreen_button.set_icon_name("view-restore-symbolic");
} else { } else {
imp.flap.set_fold_policy(libadwaita::FlapFoldPolicy::Never); imp.flap.set_fold_policy(adw::FlapFoldPolicy::Never);
imp.headerbar.remove_css_class("osd"); imp.headerbar.remove_css_class("osd");
imp.menu_button.unparent(); imp.menu_button.unparent();
imp.fullscreen_button.unparent(); imp.fullscreen_button.unparent();