build: fix compilation errors caused by package update

This commit is contained in:
Jake Stanger 2022-10-15 00:07:10 +01:00
parent f411b7c451
commit 2cd59ef5ff
No known key found for this signature in database
GPG Key ID: C51FC8F9CB0BEA61
2 changed files with 46 additions and 22 deletions

4
Cargo.lock generated
View File

@ -2121,7 +2121,7 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "swayipc-async" name = "swayipc-async"
version = "2.0.1" version = "2.0.1"
source = "git+https://github.com/JakeStanger/swayipc-rs.git?branch=feat/derive-clone#be4235b075889b66a27ba739df9ef13a571979ff" source = "git+https://github.com/JakeStanger/swayipc-rs.git?branch=feat/derive-clone#d8322a5412b021d0c002506b92b83b91ffd238d7"
dependencies = [ dependencies = [
"async-io", "async-io",
"async-pidfd", "async-pidfd",
@ -2134,7 +2134,7 @@ dependencies = [
[[package]] [[package]]
name = "swayipc-types" name = "swayipc-types"
version = "1.1.2" version = "1.1.2"
source = "git+https://github.com/JakeStanger/swayipc-rs.git?branch=feat/derive-clone#be4235b075889b66a27ba739df9ef13a571979ff" source = "git+https://github.com/JakeStanger/swayipc-rs.git?branch=feat/derive-clone#d8322a5412b021d0c002506b92b83b91ffd238d7"
dependencies = [ dependencies = [
"serde", "serde",
"serde_json", "serde_json",

View File

@ -29,28 +29,25 @@ pub enum WorkspaceUpdate {
/// Creates a button from a workspace /// Creates a button from a workspace
fn create_button( fn create_button(
workspace: &Workspace, name: &str,
focused: bool,
name_map: &HashMap<String, String>, name_map: &HashMap<String, String>,
tx: &Sender<String>, tx: &Sender<String>,
) -> Button { ) -> Button {
let button = Button::builder() let button = Button::builder()
.label( .label(name_map.get(name).map(|str| str.as_str()).unwrap_or(name))
name_map
.get(workspace.name.as_str())
.unwrap_or(&workspace.name),
)
.build(); .build();
let style_context = button.style_context(); let style_context = button.style_context();
style_context.add_class("item"); style_context.add_class("item");
if workspace.focused { if focused {
style_context.add_class("focused"); style_context.add_class("focused");
} }
{ {
let tx = tx.clone(); let tx = tx.clone();
let name = workspace.name.clone(); let name = name.to_string();
button.connect_clicked(move |_item| { button.connect_clicked(move |_item| {
tx.try_send(name.clone()) tx.try_send(name.clone())
.expect("Failed to send workspace click event"); .expect("Failed to send workspace click event");
@ -143,49 +140,75 @@ impl Module<gtk::Box> for WorkspacesModule {
WorkspaceUpdate::Init(workspaces) => { WorkspaceUpdate::Init(workspaces) => {
trace!("Creating workspace buttons"); trace!("Creating workspace buttons");
for workspace in workspaces { for workspace in workspaces {
let item = create_button(&workspace, &name_map, &context.controller_tx); let item = create_button(
&workspace.name,
workspace.focused,
&name_map,
&context.controller_tx,
);
container.add(&item); container.add(&item);
button_map.insert(workspace.name, item); button_map.insert(workspace.name, item);
} }
container.show_all(); container.show_all();
} }
WorkspaceUpdate::Update(event) if event.change == WorkspaceChange::Focus => { WorkspaceUpdate::Update(event) if event.change == WorkspaceChange::Focus => {
let old = event.old.and_then(|old| button_map.get(&old.name)); let old = event
.old
.and_then(|old| old.name)
.and_then(|name| button_map.get(&name));
if let Some(old) = old { if let Some(old) = old {
old.style_context().remove_class("focused"); old.style_context().remove_class("focused");
} }
let new = event.current.and_then(|new| button_map.get(&new.name)); let new = event
.current
.and_then(|old| old.name)
.and_then(|new| button_map.get(&new));
if let Some(new) = new { if let Some(new) = new {
new.style_context().add_class("focused"); new.style_context().add_class("focused");
} }
} }
WorkspaceUpdate::Update(event) if event.change == WorkspaceChange::Init => { WorkspaceUpdate::Update(event) if event.change == WorkspaceChange::Init => {
if let Some(workspace) = event.current { if let Some(workspace) = event.current {
if self.all_monitors || workspace.output == output_name { if self.all_monitors || workspace.output.unwrap_or_default() == output_name {
let item = let name = workspace.name.unwrap_or_default();
create_button(&workspace, &name_map, &context.controller_tx); let item = create_button(
&name,
workspace.focused,
&name_map,
&context.controller_tx,
);
item.show(); item.show();
container.add(&item); container.add(&item);
button_map.insert(workspace.name, item);
if !name.is_empty() {
button_map.insert(name, item);
}
} }
} }
} }
WorkspaceUpdate::Update(event) if event.change == WorkspaceChange::Move => { WorkspaceUpdate::Update(event) if event.change == WorkspaceChange::Move => {
if let Some(workspace) = event.current { if let Some(workspace) = event.current {
if !self.all_monitors { if !self.all_monitors {
if workspace.output == output_name { if workspace.output.unwrap_or_default() == output_name {
let name = workspace.name.unwrap_or_default();
let item = create_button( let item = create_button(
&workspace, &name,
workspace.focused,
&name_map, &name_map,
&context.controller_tx, &context.controller_tx,
); );
item.show(); item.show();
container.add(&item); container.add(&item);
button_map.insert(workspace.name, item);
} else if let Some(item) = button_map.get(&workspace.name) { if !name.is_empty() {
button_map.insert(name, item);
}
} else if let Some(item) =
button_map.get(&workspace.name.unwrap_or_default())
{
container.remove(item); container.remove(item);
} }
} }
@ -193,7 +216,8 @@ impl Module<gtk::Box> for WorkspacesModule {
} }
WorkspaceUpdate::Update(event) if event.change == WorkspaceChange::Empty => { WorkspaceUpdate::Update(event) if event.change == WorkspaceChange::Empty => {
if let Some(workspace) = event.current { if let Some(workspace) = event.current {
if let Some(item) = button_map.get(&workspace.name) { if let Some(item) = button_map.get(&workspace.name.unwrap_or_default())
{
container.remove(item); container.remove(item);
} }
} }