get workspace manager global

This commit is contained in:
Ashley Wulber 2022-06-15 16:51:08 -04:00
parent ff2d7e0237
commit c1039be812
12 changed files with 47 additions and 576 deletions

View file

@ -9,8 +9,6 @@ cosmic-panel-config = { git = "https://github.com/pop-os/cosmic-panel/", feature
cascade = "1.0.0"
gtk4 = { version = "0.4.5", features = ["v4_4"] }
gio = "0.15.3"
libcosmic = { git = "https://github.com/pop-os/libcosmic" }
relm4-macros = "0.4.4"
serde = "1.0.136"
serde_json = "1.0.78"
tokio = { version = "1.16.1", features = ["sync"] }

View file

@ -1,5 +1,3 @@
use std::env;
// SPDX-License-Identifier: MPL-2.0-only
use crate::dock_list::DockList;
use crate::dock_list::DockListType;

View file

@ -82,8 +82,6 @@ fn main() {
// .expect("Failed to close selected window");
}
Event::Favorite((name, should_favorite)) => {
dbg!(&name);
dbg!(should_favorite);
let saved_app_model = apps_container.model(DockListType::Saved);
let active_app_model = apps_container.model(DockListType::Active);
if should_favorite {

View file

@ -19,6 +19,7 @@ rust-embed = "6.3.0"
tokio = { version = "1.16.1", features = ["sync"] }
wayland-client = "0.29.4"
wayland-commons = "0.29.4"
sctk = { package = "smithay-client-toolkit", git = "https://github.com/wash2/client-toolkit.git", default-features = false, features = ["calloop"] }
[build-dependencies]
gio = "0.15.10"

View file

@ -19,7 +19,6 @@ fn main() {
);
let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());
// Location of the xml file, relative to the `Cargo.toml`
let drm_protocol_file = "data/resources/wayland-drm.xml";
let ext_workspace_protocol_file = "data/resources/ext-workspace-unstable-v1.xml";
// Target directory for the generate files
generate_code(

View file

@ -1 +1 @@
cosmic-app-list = Cosmic Dock App List
cosmic-applet-workspaces = Cosmic Workspaces

View file

@ -6,7 +6,9 @@ use std::{
};
use tokio::sync::mpsc;
use wayland_client::{protocol::wl_registry, Display, GlobalManager};
use generated::client::{zext_workspace_manager_v1, zext_workspace_group_handle_v1, zext_workspace_handle_v1};
use sctk::environment::{SimpleGlobal, Environment};
use sctk::environment;
mod generated {
// The generated code tends to trigger a lot of warnings
// so we isolate it into a very permissive module
@ -26,6 +28,18 @@ mod generated {
}
}
#[derive(Debug)]
struct State {
workspace_manager: SimpleGlobal<zext_workspace_manager_v1::ZextWorkspaceManagerV1>,
}
environment!(State,
singles = [
zext_workspace_manager_v1::ZextWorkspaceManagerV1 => workspace_manager,
],
multis = []
);
pub fn spawn_workspaces(tx: mpsc::Sender<Vec<Workspace>>) -> mpsc::Sender<Activate> {
let (workspaces_tx, mut workspaces_rx) = mpsc::channel(100);
if let Ok(display) = std::env::var("HOST_WAYLAND_DISPLAY")
@ -35,18 +49,30 @@ pub fn spawn_workspaces(tx: mpsc::Sender<Vec<Workspace>>) -> mpsc::Sender<Activa
std::thread::spawn(move || {
let mut event_queue = display.create_event_queue();
let attached_display = display.attach(event_queue.token());
let globals = GlobalManager::new(&attached_display);
dbg!(event_queue.sync_roundtrip(&mut (), |_, _, _| unreachable!()));
let env = State {
workspace_manager: SimpleGlobal::new(),
};
let env = Environment::new(&attached_display, &mut event_queue, env).expect("Failed to create environment");
println!("Globals: ");
for (name, interface, version) in globals.list() {
println!("{}: {} (version {})", name, interface, version);
}
let workspace_manager = env.require_global::<zext_workspace_manager_v1::ZextWorkspaceManagerV1>();
dbg!(workspace_manager);
// let globals = GlobalManager::new(&attached_display);
// let _ = event_queue.sync_roundtrip(&mut (), |_, _, _| unreachable!());
// println!("Globals: ");
// for (name, interface, version) in globals.list() {
// println!("{}: {} (version {})", name, interface, version);
// }
});
} else {
eprintln!("ENV variable HOST_WAYLAND_SOCKET is missing. Exiting...");
eprintln!("ENV variable HOST_WAYLAND_DISPLAY is missing. Exiting...");
std::process::exit(1);
}
workspaces_tx
}

View file

@ -32,7 +32,7 @@ impl CosmicWorkspacesWindow {
..set_height_request(1);
..set_decorated(false);
..set_resizable(false);
..set_title(Some(&fl!("cosmic-app-list")));
..set_title(Some(&fl!("cosmic-applet-workspaces")));
..add_css_class("transparent");
};
let config = CosmicPanelConfig::load_from_env().unwrap_or_default();

View file

@ -54,16 +54,16 @@ impl CosmicPanelAppButtonWindow {
container.append(&image);
app_button.set_child(Some(&container));
dbg!(apps_desktop_info.string("Exec").unwrap().as_str());
let app_id = app_desktop_file_name.to_string();
app_button.connect_clicked(move |_| {
let _ = Command::new("xdg-shell-wrapper")
.env_remove("WAYLAND_SOCKET")
.arg(apps_desktop_info.string("Exec").unwrap().as_str())
.arg(&app_id)
.spawn();
});
self_.set_child(Some(&app_button));
} else {
panic!("Requested application is not installed");
panic!("{} is not installed", app_desktop_file_name);
}
self_