wip: applet workspaces
This commit is contained in:
parent
464338585c
commit
2cbaaae069
20 changed files with 669 additions and 0 deletions
84
applets/cosmic-applet-workspaces/src/workspace_object/imp.rs
Normal file
84
applets/cosmic-applet-workspaces/src/workspace_object/imp.rs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
// SPDX-License-Identifier: MPL-2.0-only
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use glib::{ParamFlags, ParamSpec, Value};
|
||||
use gtk4::gdk::glib::ParamSpecBoolean;
|
||||
use gtk4::glib;
|
||||
use gtk4::glib::ParamSpecUInt;
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::subclass::prelude::*;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
// Object holding the state
|
||||
#[derive(Default)]
|
||||
pub struct WorkspaceObject {
|
||||
pub(crate) id: Cell<u32>,
|
||||
pub(crate) active: Cell<bool>,
|
||||
}
|
||||
|
||||
// The central trait for subclassing a GObject
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for WorkspaceObject {
|
||||
const NAME: &'static str = "WorkspaceObject";
|
||||
type Type = super::WorkspaceObject;
|
||||
type ParentType = glib::Object;
|
||||
}
|
||||
|
||||
// Trait shared by all GObjects
|
||||
impl ObjectImpl for WorkspaceObject {
|
||||
fn properties() -> &'static [ParamSpec] {
|
||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||
vec![
|
||||
ParamSpecUInt::new(
|
||||
// Name
|
||||
"id",
|
||||
// Nickname
|
||||
"id",
|
||||
// Short description
|
||||
"id",
|
||||
// Minimum value
|
||||
u32::MIN,
|
||||
// Maximum value
|
||||
u32::MAX,
|
||||
// Default value
|
||||
0,
|
||||
// The property can be read and written to
|
||||
ParamFlags::READWRITE,
|
||||
),
|
||||
ParamSpecBoolean::new(
|
||||
"active",
|
||||
"active",
|
||||
"Indicates whether workspace is active",
|
||||
false,
|
||||
ParamFlags::READWRITE,
|
||||
),
|
||||
|
||||
]
|
||||
});
|
||||
PROPERTIES.as_ref()
|
||||
}
|
||||
|
||||
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
|
||||
match pspec.name() {
|
||||
"active" => {
|
||||
self.active
|
||||
.replace(value.get().expect("Value needs to be a boolean"));
|
||||
}
|
||||
"id" => {
|
||||
self.id
|
||||
.replace(value.get().expect("Value needs to be a boolean"));
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
|
||||
match pspec.name() {
|
||||
"id" => self.id.get().to_value(),
|
||||
"active" => self.active.get().to_value(),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
31
applets/cosmic-applet-workspaces/src/workspace_object/mod.rs
Normal file
31
applets/cosmic-applet-workspaces/src/workspace_object/mod.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// SPDX-License-Identifier: MPL-2.0-only
|
||||
|
||||
use gtk4::{glib, subclass::prelude::*};
|
||||
|
||||
mod imp;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct WorkspaceObject(ObjectSubclass<imp::WorkspaceObject>);
|
||||
}
|
||||
|
||||
impl WorkspaceObject {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(&[]).unwrap()
|
||||
}
|
||||
|
||||
pub fn from_id_active(id: u32, active: bool) -> Self {
|
||||
glib::Object::new(&[("id", &id), ("active", &active)]).unwrap()
|
||||
}
|
||||
|
||||
pub fn id(&self) -> u32 {
|
||||
imp::WorkspaceObject::from_instance(&self).id.get()
|
||||
}
|
||||
|
||||
pub fn active(&self) -> bool {
|
||||
imp::WorkspaceObject::from_instance(&self).active.get()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, glib::Boxed)]
|
||||
#[boxed_type(name = "BoxedWorkspaceObject")]
|
||||
pub struct BoxedWorkspaceObject(pub Option<WorkspaceObject>);
|
||||
Loading…
Add table
Add a link
Reference in a new issue