feat: generated workspaces protocol and various improvements
This commit is contained in:
parent
bfa8fa58ff
commit
02e240b6bb
19 changed files with 480 additions and 110 deletions
|
|
@ -1,13 +1,12 @@
|
|||
use std::{rc::Rc, cell::RefCell};
|
||||
use gtk4::{ToggleButton, glib, subclass::prelude::*};
|
||||
use tokio::sync::mpsc;
|
||||
use crate::Activate;
|
||||
use gtk4::{glib, subclass::prelude::*, ToggleButton};
|
||||
use once_cell::sync::OnceCell;
|
||||
use crate::Event;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
// Object holding the state
|
||||
#[derive(Default)]
|
||||
pub struct WorkspaceButton {
|
||||
pub tx: Rc<OnceCell<mpsc::Sender<Event>>>,
|
||||
pub button: Rc<RefCell<ToggleButton>>,
|
||||
}
|
||||
|
||||
|
|
@ -26,4 +25,4 @@ impl ObjectImpl for WorkspaceButton {}
|
|||
impl WidgetImpl for WorkspaceButton {}
|
||||
|
||||
// Trait shared by all buttons
|
||||
impl BoxImpl for WorkspaceButton {}
|
||||
impl BoxImpl for WorkspaceButton {}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
mod imp;
|
||||
|
||||
use crate::{workspace_object::WorkspaceObject, Activate, TX};
|
||||
use glib::Object;
|
||||
use gtk4::{glib, prelude::*, subclass::prelude::*, ToggleButton};
|
||||
use tokio::sync::mpsc;
|
||||
use crate::{Event, workspace_object::WorkspaceObject};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct WorkspaceButton(ObjectSubclass<imp::WorkspaceButton>)
|
||||
|
|
@ -12,16 +11,15 @@ glib::wrapper! {
|
|||
}
|
||||
|
||||
impl WorkspaceButton {
|
||||
pub fn new(tx: mpsc::Sender<Event>) -> Self {
|
||||
pub fn new() -> Self {
|
||||
let self_ = Object::new(&[]).expect("Failed to create `WorkspaceButton`.");
|
||||
let imp = imp::WorkspaceButton::from_instance(&self_);
|
||||
imp.tx.set(tx).unwrap();
|
||||
|
||||
let tb = ToggleButton::with_label("");
|
||||
self_.append(&tb);
|
||||
|
||||
imp.button.replace(tb);
|
||||
|
||||
|
||||
self_
|
||||
}
|
||||
|
||||
|
|
@ -34,9 +32,9 @@ impl WorkspaceButton {
|
|||
let new_button = ToggleButton::with_label(&format!("{}", id));
|
||||
new_button.set_active(obj.active());
|
||||
self.append(&new_button);
|
||||
new_button.connect_clicked(glib::clone!(@weak imp.tx as tx => move |_| {
|
||||
let _ = tx.get().unwrap().send(Event::Activate(id));
|
||||
}));
|
||||
new_button.connect_clicked(move |_| {
|
||||
let _ = TX.get().unwrap().send(id);
|
||||
});
|
||||
|
||||
imp.button.replace(new_button);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue