Use AdwApplication

This allows to have a separate css file for dark mode.
This commit is contained in:
Maximiliano Sandoval R 2021-10-04 22:01:52 +02:00 committed by Julian Sparber
parent b623a931a7
commit 8b8631130d
2 changed files with 4 additions and 18 deletions

View file

@ -6,7 +6,7 @@ use glib::clone;
use glib::WeakRef; use glib::WeakRef;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::{gdk, gio, glib}; use gtk::{gio, glib};
use gtk_macros::action; use gtk_macros::action;
use log::{debug, info}; use log::{debug, info};
@ -33,7 +33,7 @@ mod imp {
impl ObjectSubclass for Application { impl ObjectSubclass for Application {
const NAME: &'static str = "Application"; const NAME: &'static str = "Application";
type Type = super::Application; type Type = super::Application;
type ParentType = gtk::Application; type ParentType = adw::Application;
} }
impl ObjectImpl for Application {} impl ObjectImpl for Application {}
@ -49,8 +49,6 @@ mod imp {
return; return;
} }
app.setup_css();
let window = Window::new(app); let window = Window::new(app);
self.window self.window
.set(window.downgrade()) .set(window.downgrade())
@ -69,11 +67,12 @@ mod imp {
} }
impl GtkApplicationImpl for Application {} impl GtkApplicationImpl for Application {}
impl AdwApplicationImpl for Application {}
} }
glib::wrapper! { glib::wrapper! {
pub struct Application(ObjectSubclass<imp::Application>) pub struct Application(ObjectSubclass<imp::Application>)
@extends gio::Application, gtk::Application, @implements gio::ActionMap, gio::ActionGroup; @extends gio::Application, gtk::Application, adw::Application, @implements gio::ActionMap, gio::ActionGroup;
} }
impl Application { impl Application {
@ -144,18 +143,6 @@ impl Application {
self.set_accels_for_action("win.show-help-overlay", &["<Control>question"]); self.set_accels_for_action("win.show-help-overlay", &["<Control>question"]);
} }
fn setup_css(&self) {
let provider = gtk::CssProvider::new();
provider.load_from_resource("/org/gnome/FractalNext/style.css");
if let Some(display) = gdk::Display::default() {
gtk::StyleContext::add_provider_for_display(
&display,
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
}
}
fn show_about_dialog(&self) { fn show_about_dialog(&self) {
let dialog = gtk::AboutDialogBuilder::new() let dialog = gtk::AboutDialogBuilder::new()
.logo_icon_name(config::APP_ID) .logo_icon_name(config::APP_ID)

View file

@ -47,7 +47,6 @@ fn main() {
gtk::glib::set_application_name("Fractal"); gtk::glib::set_application_name("Fractal");
gtk::init().expect("Unable to start GTK4"); gtk::init().expect("Unable to start GTK4");
adw::init();
gst::init().expect("Failed to initalize gst"); gst::init().expect("Failed to initalize gst");
let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file"); let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file");