Fix last commit
This commit is contained in:
		
							
								
								
									
										78
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										78
									
								
								src/main.rs
									
									
									
									
									
								
							| @ -11,7 +11,7 @@ use wayland_client::protocol::wl_registry::WlRegistry; | ||||
| use std::collections::{BTreeMap, HashMap}; | ||||
| use wayland_client::protocol::{wl_output, wl_output::WlOutput, wl_seat, | ||||
|     wl_seat::WlSeat}; | ||||
| use wayland_client::{Attached, DispatchData, Display, GlobalEvent, GlobalManager, Main}; | ||||
| use wayland_client::{Attached, DispatchData, Display, GlobalEvent, GlobalImplementor, GlobalManager, Main}; | ||||
|  | ||||
| #[derive(Debug)] | ||||
| struct Flags { | ||||
| @ -47,6 +47,8 @@ struct Tags(u32); | ||||
|  | ||||
| struct Env { | ||||
|     flags: Flags, | ||||
|     // I don't know very much about wayland, and it shows | ||||
|     output_id_map: HashMap<u32, u32>, | ||||
|     output_names: BTreeMap<u32, String>, | ||||
|     focused: Option<u32>, | ||||
|     layout: Option<String>, | ||||
| @ -134,10 +136,8 @@ impl Serialize for Env { | ||||
|             let mut name_id_map = HashMap::<&str, u32>::new(); | ||||
|             name_id_map.reserve(self.output_names.len()); | ||||
|             let mut id = 0; | ||||
|             for (_, value) in &self.output_names { | ||||
|                 if !name_id_map.contains_key(value.as_str()) { | ||||
|                     name_id_map.insert(value, id); | ||||
|                 } | ||||
|             for (key, value) in &self.output_names { | ||||
|                 name_id_map.insert(value, id); | ||||
|                 id += 1; | ||||
|             } | ||||
|             state.serialize_field("gtk_ids", &name_id_map)?; | ||||
| @ -161,6 +161,7 @@ impl Env { | ||||
|             viewtags: flags.viewtags.then(Default::default), | ||||
|             status_manager: None, | ||||
|             flags, | ||||
|             output_id_map: Default::default(), | ||||
|             output_names: Default::default(), | ||||
|         } | ||||
|     } | ||||
| @ -180,14 +181,6 @@ impl Env { | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn handle_zriver_status_manager_v1( | ||||
|     status_manager: Main<ZriverStatusManagerV1>, mut env: DispatchData | ||||
| ) { | ||||
|     if let Some(env) = env.get::<Env>() { | ||||
|         env.status_manager = Some(status_manager); | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn handle_river_seat_status( | ||||
|     _status: Main<ZriverSeatStatusV1>, event: zriver_seat_status_v1::Event, | ||||
|     mut env: DispatchData | ||||
| @ -328,34 +321,45 @@ fn handle_output_event( | ||||
| fn global_manager_callback( | ||||
|     event: GlobalEvent, registry: Attached<WlRegistry>, mut env: DispatchData | ||||
| ) { | ||||
|     let mut global_filter = wayland_client::global_filter!( | ||||
|         [ZriverStatusManagerV1, 1, handle_zriver_status_manager_v1], | ||||
|         [WlSeat, 7, |seat: Main<WlSeat>, _env: DispatchData| { | ||||
|             seat.quick_assign(handle_seat_event); | ||||
|         }], | ||||
|         [WlOutput, 3, |output: Main<WlOutput>, _env: DispatchData| { | ||||
|             output.quick_assign(handle_output_event); | ||||
|         }] | ||||
|     ); | ||||
|  | ||||
|     match event { | ||||
|         GlobalEvent::New { id: _, interface: _, version: _ } => { | ||||
|             global_filter(event, registry, env); | ||||
|         GlobalEvent::New { id, interface, version } => { | ||||
|             match interface.as_str() { | ||||
|                 "wl_output" if version >= 3 => { | ||||
|                     let output: Main<WlOutput> = registry.bind(version, id); | ||||
|                     if let Some(env) = env.get::<Env>() { | ||||
|                         env.output_id_map.insert(id, output.as_ref().id()); | ||||
|                         output.quick_assign(handle_output_event); | ||||
|                     } | ||||
|                 }, | ||||
|                 "wl_seat" if version >= 7 => { | ||||
|                     let seat: Main<WlSeat> = registry.bind(version, id); | ||||
|                     seat.quick_assign(handle_seat_event); | ||||
|                 }, | ||||
|                 "zriver_status_manager_v1" => { | ||||
|                     let status_manager = registry.bind(version, id); | ||||
|                     if let Some(env) = env.get::<Env>() { | ||||
|                         env.status_manager = Some(status_manager); | ||||
|                     } | ||||
|                 }, | ||||
|                 _ => {} | ||||
|             } | ||||
|         } | ||||
|         GlobalEvent::Removed { id, interface: _ } => { | ||||
|             if let Some(env) = env.get::<Env>() { | ||||
|                 env.output_names.remove(&id); | ||||
|                 if let Some(titles) = &mut env.titles { | ||||
|                     titles.remove(&id); | ||||
|                 } | ||||
|                 if let Some(tags) = &mut env.tags { | ||||
|                     tags.remove(&id); | ||||
|                 } | ||||
|                 if let Some(urgency) = &mut env.urgency { | ||||
|                     urgency.remove(&id); | ||||
|                 } | ||||
|                 if let Some(viewtags) = &mut env.viewtags { | ||||
|                     viewtags.remove(&id); | ||||
|                 if let Some(oid) = env.output_id_map.remove(&id) { | ||||
|                     env.output_names.remove(&oid); | ||||
|                     if let Some(titles) = &mut env.titles { | ||||
|                         titles.remove(&oid); | ||||
|                     } | ||||
|                     if let Some(tags) = &mut env.tags { | ||||
|                         tags.remove(&oid); | ||||
|                     } | ||||
|                     if let Some(urgency) = &mut env.urgency { | ||||
|                         urgency.remove(&oid); | ||||
|                     } | ||||
|                     if let Some(viewtags) = &mut env.viewtags { | ||||
|                         viewtags.remove(&oid); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user