fix: bind to output before workspaces and use latest cosmic-panel-config

This commit is contained in:
Ashley Wulber 2022-09-12 13:50:45 -04:00
parent 0ecba6a6d0
commit ec7a615d22
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
8 changed files with 191 additions and 168 deletions

View file

@ -24,12 +24,12 @@ i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-request
i18n-embed-fl = "0.6.4"
rust-embed = "6.3.0"
calloop = "0.10.1"
wayland-backend = { version = "0.1.0-beta.7" }
wayland-client = { version = "0.30.0-beta.7" }
nix = "0.24.1"
wayland-backend = { git = "https://github.com/Smithay/wayland-rs", version = "0.1.0-beta.9"}
wayland-client = { git = "https://github.com/Smithay/wayland-rs", version = "0.30.0-beta.9"}
nix = "0.25"
# config
anyhow = "1.0.53"
ron = "0.7.0"
ron = "0.8.0"
serde = { version = "1.0.136", features = ["derive"] }
log = "0.4"

View file

@ -71,7 +71,7 @@ pub fn spawn_toplevels() -> SyncSender<ToplevelEvent> {
.unwrap();
let display = conn.display();
display.get_registry(&qhandle, ()).unwrap();
display.get_registry(&qhandle, ());
let mut state = State {
workspace_manager: None,
@ -147,31 +147,6 @@ pub struct State {
seats: Vec<WlSeat>,
}
impl State {
pub fn workspace_list(&self) -> impl Iterator<Item = (String, u32)> + '_ {
self.workspace_groups
.iter()
.filter_map(|g| {
if g.output == self.expected_output {
Some(g.workspaces.iter().map(|w| {
(
w.name.clone(),
match &w.states {
x if x.contains(&zcosmic_workspace_handle_v1::State::Active) => 0,
x if x.contains(&zcosmic_workspace_handle_v1::State::Urgent) => 1,
x if x.contains(&zcosmic_workspace_handle_v1::State::Hidden) => 2,
_ => 3,
},
)
}))
} else {
None
}
})
.flatten()
}
}
#[derive(Debug, Clone)]
pub struct Toplevel {
pub name: String,
@ -215,27 +190,24 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
match &interface[..] {
"zcosmic_toplevel_info_v1" => {
let ti = registry
.bind::<ZcosmicToplevelInfoV1, _, _>(name, 1, qh, ())
.unwrap();
.bind::<ZcosmicToplevelInfoV1, _, _>(name, 1, qh, ());
state.toplevel_info = Some(ti);
}
"zcosmic_toplevel_manager_v1" => {
let tm = registry
.bind::<ZcosmicToplevelManagerV1, _, _>(name, 1, qh, ())
.unwrap();
.bind::<ZcosmicToplevelManagerV1, _, _>(name, 1, qh, ());
state.toplevel_manager = Some(tm);
}
"zcosmic_workspace_manager_v1" => {
let workspace_manager = registry
.bind::<ZcosmicWorkspaceManagerV1, _, _>(name, 1, qh, ())
.unwrap();
.bind::<ZcosmicWorkspaceManagerV1, _, _>(name, 1, qh, ());
state.workspace_manager = Some(workspace_manager);
}
"wl_seat" => {
registry.bind::<WlSeat, _, _>(name, 1, qh, ()).unwrap();
registry.bind::<WlSeat, _, _>(name, 1, qh, ());
}
"wl_output" => {
registry.bind::<WlOutput, _, _>(name, 1, qh, ()).unwrap();
registry.bind::<WlOutput, _, _>(name, 1, qh, ());
}
_ => {}
}

View file

@ -19,8 +19,8 @@ anyhow = "1.0.50"
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.6.4"
rust-embed = "6.3.0"
wayland-backend = { version = "0.1.0-beta.8" }
wayland-client = { version = "0.30.0-beta.8" }
wayland-backend = { git = "https://github.com/Smithay/wayland-rs", version = "0.1.0-beta.9"}
wayland-client = { git = "https://github.com/Smithay/wayland-rs", version = "0.30.0-beta.9"}
calloop = "*"
nix = "*"
log = "0.4"

View file

@ -12,7 +12,7 @@ use wayland_client::{
event_created_child,
protocol::{
wl_output::{self, WlOutput},
wl_registry,
wl_registry::{self, WlRegistry},
},
ConnectError,
};
@ -36,7 +36,7 @@ pub fn spawn_workspaces(tx: glib::Sender<State>) -> SyncSender<WorkspaceEvent> {
std::thread::spawn(move || {
let output = std::env::var("COSMIC_PANEL_OUTPUT")
.ok()
.and_then(|size| match size.parse::<CosmicPanelOuput>() {
.and_then(|output| match output.parse::<CosmicPanelOuput>() {
Ok(CosmicPanelOuput::Name(n)) => Some(n),
// TODO handle Active & panic if the space is still configured for All instead of being assigned a named output
_ => Some("".to_string()),
@ -54,9 +54,11 @@ pub fn spawn_workspaces(tx: glib::Sender<State>) -> SyncSender<WorkspaceEvent> {
.unwrap();
let display = conn.display();
display.get_registry(&qhandle, ()).unwrap();
display.get_registry(&qhandle, ());
let mut state = State {
outputs_to_handle: Default::default(),
wm_name: None,
workspace_manager: None,
workspace_groups: Vec::new(),
configured_output: output,
@ -136,6 +138,8 @@ pub fn spawn_workspaces(tx: glib::Sender<State>) -> SyncSender<WorkspaceEvent> {
#[derive(Debug, Clone)]
pub struct State {
outputs_to_handle: Option<Vec<WlOutput>>,
wm_name: Option<(u32, WlRegistry)>,
running: bool,
tx: glib::Sender<State>,
configured_output: String,
@ -185,6 +189,7 @@ struct Workspace {
states: Vec<zcosmic_workspace_handle_v1::State>,
}
impl Dispatch<wl_registry::WlRegistry, ()> for State {
fn event(
state: &mut Self,
@ -197,18 +202,30 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
if let wl_registry::Event::Global {
name,
interface,
version,
version: _version,
} = event
{
match &interface[..] {
"zcosmic_workspace_manager_v1" => {
let workspace_manager = registry
.bind::<ZcosmicWorkspaceManagerV1, _, _>(name, 1, qh, ())
.unwrap();
state.workspace_manager = Some(workspace_manager);
if let Some(outputs_to_handle) = state.outputs_to_handle.as_ref() {
if outputs_to_handle.is_empty() {
let workspace_manager =
registry.bind::<ZcosmicWorkspaceManagerV1, _, _>(name, 1, qh, ());
state.workspace_manager = Some(workspace_manager);
return;
}
}
// will be handled when outputs are done...
state.wm_name.replace((name, registry.clone()));
}
"wl_output" => {
registry.bind::<WlOutput, _, _>(name, 1, qh, ()).unwrap();
let _output = registry.bind::<WlOutput, _, _>(name, 4, qh, ());
match state.outputs_to_handle.as_mut() {
Some(outputs_to_handle) => outputs_to_handle.push(_output),
None => {
state.outputs_to_handle.replace(vec![_output]);
}
};
}
_ => {}
}
@ -391,13 +408,26 @@ impl Dispatch<WlOutput, ()> for State {
e: wl_output::Event,
_: &(),
_: &Connection,
_: &QueueHandle<Self>,
qh: &QueueHandle<Self>,
) {
match e {
wl_output::Event::Name { name } if name == state.configured_output => {
state.expected_output.replace(o.clone());
// Necessary bc often the output is handled after the workspaces
let _ = state.tx.send(state.clone());
}
wl_output::Event::Done => {
let outputs_to_handle = state.outputs_to_handle.as_mut().unwrap();
outputs_to_handle.retain(|o_to_handle| o != o_to_handle);
if outputs_to_handle.is_empty() {
if let Some((wm_name, registry)) = state.wm_name.as_ref() {
let workspace_manager =
registry.bind::<ZcosmicWorkspaceManagerV1, _, _>(*wm_name, 1, qh, ());
state.workspace_manager = Some(workspace_manager);
}
}
}
_ => {} // ignored
}
}
}
}

View file

@ -1,5 +1,7 @@
// SPDX-License-Identifier: MPL-2.0-only
use std::cmp::Ordering;
use crate::utils::WorkspaceEvent;
use crate::wayland::State;
use crate::workspace_button::WorkspaceButton;
@ -77,7 +79,11 @@ impl WorkspaceList {
let new_results: Vec<glib::Object> = workspaces
.workspace_list()
.sorted_by(|a, b| {
a.0.cmp(&b.0)
match a.0.len().cmp(&b.0.len()) {
Ordering::Less => Ordering::Less,
Ordering::Equal => a.0.cmp(&b.0),
Ordering::Greater => Ordering::Greater,
}
})
.filter_map(|w| {
// don't include hidden workspaces