audrey/src/application.rs

66 lines
1.6 KiB
Rust
Raw Normal View History

2024-10-29 13:02:29 +00:00
mod imp {
2024-11-03 09:37:37 +00:00
use crate::ui;
2024-11-02 14:43:43 +00:00
use adw::{prelude::*, subclass::prelude::*};
2024-10-29 13:02:29 +00:00
use gtk::glib;
2024-10-29 12:01:42 +00:00
2024-10-29 13:02:29 +00:00
#[derive(Default)]
2024-11-03 09:37:37 +00:00
pub struct Application {}
2024-10-29 13:02:29 +00:00
#[glib::object_subclass]
impl ObjectSubclass for Application {
const NAME: &'static str = "AudreyApplication";
type Type = super::Application;
type ParentType = adw::Application;
2024-10-29 12:01:42 +00:00
}
2024-10-29 13:02:29 +00:00
impl ObjectImpl for Application {}
impl ApplicationImpl for Application {
fn activate(&self) {
self.parent_activate();
match self.obj().active_window() {
2024-11-01 11:11:49 +00:00
None => {
let window = ui::Window::new(self.obj().as_ref());
window.present();
}
2024-10-29 13:02:29 +00:00
Some(win) => win.present(),
}
}
2024-10-29 12:01:42 +00:00
}
2024-10-29 13:02:29 +00:00
impl GtkApplicationImpl for Application {}
impl AdwApplicationImpl for Application {}
2024-11-02 14:43:43 +00:00
impl Application {}
2024-11-02 20:11:18 +00:00
impl Drop for Application {
fn drop(&mut self) {
println!("dropping AudreyApplication");
}
}
2024-10-29 12:01:42 +00:00
}
2024-10-29 13:02:29 +00:00
use gtk::{gio, glib};
2024-10-29 12:01:42 +00:00
glib::wrapper! {
2024-10-29 13:02:29 +00:00
pub struct Application(ObjectSubclass<imp::Application>)
2024-10-29 12:01:42 +00:00
@extends adw::Application, gtk::Application, gio::Application,
@implements gio::ActionGroup, gio::ActionMap;
}
2024-10-30 03:26:53 +00:00
impl Default for Application {
fn default() -> Self {
glib::Object::builder::<Application>()
2024-11-01 08:47:03 +00:00
.property("application-id", crate::APP_ID)
2024-10-29 13:02:29 +00:00
.property("flags", gio::ApplicationFlags::default())
.build()
2024-10-29 12:01:42 +00:00
}
}
2024-10-30 03:26:53 +00:00
impl Application {
pub fn new() -> Self {
Self::default()
}
}