refactor: better event types
This commit is contained in:
parent
3a41e58159
commit
c67f6fdb2d
4 changed files with 12 additions and 13 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -394,7 +394,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-panel-config"
|
name = "cosmic-panel-config"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/cosmic-panel/#8787823d807ea9a9d7b96ecacf017d695ba7b58a"
|
source = "git+https://github.com/pop-os/cosmic-panel#8787823d807ea9a9d7b96ecacf017d695ba7b58a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,10 @@ use gtk4::{
|
||||||
CssProvider, StyleContext,
|
CssProvider, StyleContext,
|
||||||
};
|
};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
|
use wayland::State;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use utils::{Activate, WorkspaceEvent};
|
use utils::{Activate};
|
||||||
use window::CosmicWorkspacesWindow;
|
use window::CosmicWorkspacesWindow;
|
||||||
|
|
||||||
mod localize;
|
mod localize;
|
||||||
|
|
@ -56,7 +57,7 @@ fn main() {
|
||||||
|
|
||||||
app.connect_activate(|app| {
|
app.connect_activate(|app| {
|
||||||
load_css();
|
load_css();
|
||||||
let (tx, mut rx) = mpsc::channel::<Vec<WorkspaceEvent>>(100);
|
let (tx, mut rx) = mpsc::channel::<State>(100);
|
||||||
|
|
||||||
let wayland_tx = wayland::spawn_workspaces(tx.clone());
|
let wayland_tx = wayland::spawn_workspaces(tx.clone());
|
||||||
let window = CosmicWorkspacesWindow::new(app);
|
let window = CosmicWorkspacesWindow::new(app);
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,6 @@ use gtk4::glib;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
pub type Activate = u32;
|
pub type Activate = u32;
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub struct WorkspaceEvent {
|
|
||||||
pub(crate) id: u32,
|
|
||||||
pub(crate) active: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn data_path() -> PathBuf {
|
pub fn data_path() -> PathBuf {
|
||||||
let mut path = glib::user_data_dir();
|
let mut path = glib::user_data_dir();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::utils::{Activate, WorkspaceEvent};
|
use crate::utils::{Activate};
|
||||||
use std::{env, os::unix::net::UnixStream, path::PathBuf};
|
use std::{env, os::unix::net::UnixStream, path::PathBuf};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use wayland_client::{
|
use wayland_client::{
|
||||||
|
|
@ -36,7 +36,7 @@ use self::generated::client::{
|
||||||
zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1},
|
zext_workspace_handle_v1::{self, ZextWorkspaceHandleV1},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn spawn_workspaces(tx: mpsc::Sender<Vec<WorkspaceEvent>>) -> mpsc::Sender<Activate> {
|
pub fn spawn_workspaces(tx: mpsc::Sender<State>) -> mpsc::Sender<Activate> {
|
||||||
let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100);
|
let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100);
|
||||||
if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY")
|
if let Ok(Ok(conn)) = std::env::var("HOST_WAYLAND_DISPLAY")
|
||||||
.map_err(anyhow::Error::msg)
|
.map_err(anyhow::Error::msg)
|
||||||
|
|
@ -76,19 +76,22 @@ pub fn spawn_workspaces(tx: mpsc::Sender<Vec<WorkspaceEvent>>) -> mpsc::Sender<A
|
||||||
workspaces_tx
|
workspaces_tx
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct State {
|
||||||
running: bool,
|
running: bool,
|
||||||
tx: mpsc::Sender<Vec<WorkspaceEvent>>,
|
tx: mpsc::Sender<State>,
|
||||||
workspace_manager: Option<zext_workspace_manager_v1::ZextWorkspaceManagerV1>,
|
workspace_manager: Option<zext_workspace_manager_v1::ZextWorkspaceManagerV1>,
|
||||||
workspace_groups: Vec<WorkspaceGroup>,
|
workspace_groups: Vec<WorkspaceGroup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
struct WorkspaceGroup {
|
struct WorkspaceGroup {
|
||||||
workspace_group_handle: ZextWorkspaceGroupHandleV1,
|
workspace_group_handle: ZextWorkspaceGroupHandleV1,
|
||||||
output: Option<WlOutput>,
|
output: Option<WlOutput>,
|
||||||
workspaces: Vec<Workspace>,
|
workspaces: Vec<Workspace>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
struct Workspace {
|
struct Workspace {
|
||||||
workspace_handle: ZextWorkspaceHandleV1,
|
workspace_handle: ZextWorkspaceHandleV1,
|
||||||
name: String,
|
name: String,
|
||||||
|
|
@ -151,7 +154,7 @@ impl Dispatch<zext_workspace_manager_v1::ZextWorkspaceManagerV1, ()> for State {
|
||||||
zext_workspace_manager_v1::Event::Done => {
|
zext_workspace_manager_v1::Event::Done => {
|
||||||
// TODO
|
// TODO
|
||||||
println!("sending event with workspace list state");
|
println!("sending event with workspace list state");
|
||||||
let _ = self.tx.send(Vec::new());
|
let _ = self.tx.send(self.clone());
|
||||||
}
|
}
|
||||||
zext_workspace_manager_v1::Event::Finished => {
|
zext_workspace_manager_v1::Event::Finished => {
|
||||||
self.workspace_manager.take();
|
self.workspace_manager.take();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue