libcosmic/examples/dock/window/imp.rs

92 lines
2.9 KiB
Rust
Raw Normal View History

use std::cell::RefCell;
use std::rc::Rc;
use glib::subclass::InitializingObject;
2021-12-29 22:32:10 -05:00
use glib::SignalHandlerId;
2021-12-30 16:54:35 -05:00
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
2021-12-27 17:59:49 -05:00
use gtk4::DragSource;
use gtk4::DropTarget;
use gtk4::EventControllerMotion;
use gtk4::Revealer;
2021-12-30 16:54:35 -05:00
use gtk4::{gio, glib};
use gtk4::{Box, GestureClick};
2021-12-30 16:54:35 -05:00
use gtk4::{CompositeTemplate, ListView};
use once_cell::sync::OnceCell;
// Object holding the state
#[derive(CompositeTemplate, Default)]
#[template(file = "window.ui")]
pub struct Window {
2021-12-15 11:37:28 -05:00
#[template_child]
2021-12-15 14:03:23 -05:00
pub saved_app_list_view: TemplateChild<ListView>,
#[template_child]
2021-12-21 13:01:32 -05:00
pub active_app_list_view: TemplateChild<ListView>,
#[template_child]
pub revealer: TemplateChild<Revealer>,
2021-12-15 12:19:01 -05:00
#[template_child]
pub cursor_handle: TemplateChild<Box>,
2021-12-15 14:03:23 -05:00
pub saved_app_model: OnceCell<gio::ListStore>,
2021-12-21 13:01:32 -05:00
pub active_app_model: OnceCell<gio::ListStore>,
pub cursor_motion_controller: OnceCell<EventControllerMotion>,
pub saved_click_controller: Rc<OnceCell<GestureClick>>,
pub active_click_controller: Rc<OnceCell<GestureClick>>,
pub drop_controller: OnceCell<DropTarget>,
2021-12-27 17:59:49 -05:00
pub saved_drag_source: Rc<OnceCell<DragSource>>,
pub active_drag_source: Rc<OnceCell<DragSource>>,
2021-12-27 20:19:59 -05:00
pub saved_drag_end_signal: Rc<RefCell<Option<SignalHandlerId>>>,
pub active_drag_end_signal: Rc<RefCell<Option<SignalHandlerId>>>,
pub saved_drag_cancel_signal: Rc<RefCell<Option<SignalHandlerId>>>,
pub active_drag_cancel_signal: Rc<RefCell<Option<SignalHandlerId>>>,
pub window_drop_controller: Rc<OnceCell<DropTarget>>,
}
// The central trait for subclassing a GObject
#[glib::object_subclass]
impl ObjectSubclass for Window {
// `NAME` needs to match `class` attribute of template
const NAME: &'static str = "LauncherWindow";
type Type = super::Window;
2021-12-30 16:54:35 -05:00
type ParentType = gtk4::ApplicationWindow;
fn class_init(klass: &mut Self::Class) {
Self::bind_template(klass);
}
fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template();
}
}
// Trait shared by all GObjects
impl ObjectImpl for Window {
fn constructed(&self, obj: &Self::Type) {
// Call "constructed" on parent
self.parent_constructed(obj);
// Setup
2021-12-27 17:59:49 -05:00
obj.setup_model();
obj.setup_motion_controller();
obj.setup_click_controller();
obj.setup_drop_target();
2021-12-27 17:59:49 -05:00
obj.setup_drag_source();
obj.restore_saved_apps();
obj.setup_callbacks();
// obj.setup_window_callbacks();
// obj.setup_saved_list_callbacks();
// obj.setup_active_list_callbacks();
// obj.setup_drag_callbacks();
obj.setup_click_callbacks();
obj.setup_factory();
}
}
// Trait shared by all widgets
impl WidgetImpl for Window {}
// Trait shared by all windows
impl WindowImpl for Window {}
// Trait shared by all application
impl ApplicationWindowImpl for Window {}