Fixed quick bug where spamming tag switching would lose a window. Dwms approach to this is making me appreciate suckless.
Browse files
+39 −17 src/window_manager.rs
| @@ -268,6 +268,7 @@ impl WindowManager { | ||
| 268 | 268 | |
| 269 | 269 | if has_wm_class { |
| 270 | 270 | let tag = self.get_saved_tag(window, net_client_info)?; |
| 271 | + self.connection.map_window(window)?; | |
| 271 | 272 | self.windows.push(window); |
| 272 | 273 | self.window_tags.insert(window, tag); |
| 273 | 274 | self.window_monitor.insert(window, self.selected_monitor); |
| @@ -784,7 +785,10 @@ impl WindowManager { | ||
| 784 | 785 | fn get_keychord_indicator(&self) -> Option<String> { |
| 785 | 786 | match &self.keychord_state { |
| 786 | 787 | keyboard::handlers::KeychordState::Idle => None, |
| 787 | - keyboard::handlers::KeychordState::InProgress { candidates, keys_pressed } => { | |
| 788 | + keyboard::handlers::KeychordState::InProgress { | |
| 789 | + candidates, | |
| 790 | + keys_pressed, | |
| 791 | + } => { | |
| 788 | 792 | if candidates.is_empty() { |
| 789 | 793 | return None; |
| 790 | 794 | } |
| @@ -872,7 +876,8 @@ impl WindowManager { | ||
| 872 | 876 | XF86_MON_BRIGHTNESS_UP => "Bri+", |
| 873 | 877 | XF86_MON_BRIGHTNESS_DOWN => "Bri-", |
| 874 | 878 | _ => "?", |
| 875 | - }.to_string() | |
| 879 | + } | |
| 880 | + .to_string() | |
| 876 | 881 | } |
| 877 | 882 | |
| 878 | 883 | fn update_bar(&mut self) -> WmResult<()> { |
| @@ -1081,12 +1086,18 @@ impl WindowManager { | ||
| 1081 | 1086 | .position(|mon| mon.contains_point(x, y)) |
| 1082 | 1087 | } |
| 1083 | 1088 | |
| 1089 | + // Dwm's g-loaded approach to handling the spam alternating crash. | |
| 1084 | 1090 | fn update_window_visibility(&self) -> WmResult<()> { |
| 1085 | 1091 | for &window in &self.windows { |
| 1086 | - if self.is_window_visible(window) { | |
| 1087 | - self.connection.map_window(window)?; | |
| 1088 | - } else { | |
| 1089 | - self.connection.unmap_window(window)?; | |
| 1092 | + if !self.is_window_visible(window) { | |
| 1093 | + if let Ok(geom) = self.connection.get_geometry(window)?.reply() { | |
| 1094 | + self.connection.configure_window( | |
| 1095 | + window, | |
| 1096 | + &ConfigureWindowAux::new() | |
| 1097 | + .x(-(geom.width as i32 * 2)) | |
| 1098 | + .y(geom.y as i32), | |
| 1099 | + )?; | |
| 1100 | + } | |
| 1090 | 1101 | } |
| 1091 | 1102 | } |
| 1092 | 1103 | self.connection.flush()?; |
| @@ -1103,7 +1114,6 @@ impl WindowManager { | ||
| 1103 | 1114 | } |
| 1104 | 1115 | |
| 1105 | 1116 | self.save_selected_tags()?; |
| 1106 | - | |
| 1107 | 1117 | self.update_window_visibility()?; |
| 1108 | 1118 | self.apply_layout()?; |
| 1109 | 1119 | self.update_bar()?; |
| @@ -1203,12 +1213,13 @@ impl WindowManager { | ||
| 1203 | 1213 | let min_keycode = setup.min_keycode; |
| 1204 | 1214 | let max_keycode = setup.max_keycode; |
| 1205 | 1215 | |
| 1206 | - let keyboard_mapping = self.connection.get_keyboard_mapping( | |
| 1207 | - min_keycode, | |
| 1208 | - max_keycode - min_keycode + 1, | |
| 1209 | - )?.reply()?; | |
| 1216 | + let keyboard_mapping = self | |
| 1217 | + .connection | |
| 1218 | + .get_keyboard_mapping(min_keycode, max_keycode - min_keycode + 1)? | |
| 1219 | + .reply()?; | |
| 1210 | 1220 | |
| 1211 | - let mut keysym_to_keycode: HashMap<keyboard::keysyms::Keysym, Vec<Keycode>> = HashMap::new(); | |
| 1221 | + let mut keysym_to_keycode: HashMap<keyboard::keysyms::Keysym, Vec<Keycode>> = | |
| 1222 | + HashMap::new(); | |
| 1212 | 1223 | let keysyms_per_keycode = keyboard_mapping.keysyms_per_keycode; |
| 1213 | 1224 | |
| 1214 | 1225 | for keycode in min_keycode..=max_keycode { |
| @@ -1216,7 +1227,10 @@ impl WindowManager { | ||
| 1216 | 1227 | for i in 0..keysyms_per_keycode as usize { |
| 1217 | 1228 | if let Some(&keysym) = keyboard_mapping.keysyms.get(index + i) { |
| 1218 | 1229 | if keysym != 0 { |
| 1219 | - keysym_to_keycode.entry(keysym).or_insert_with(Vec::new).push(keycode); | |
| 1230 | + keysym_to_keycode | |
| 1231 | + .entry(keysym) | |
| 1232 | + .or_insert_with(Vec::new) | |
| 1233 | + .push(keycode); | |
| 1220 | 1234 | } |
| 1221 | 1235 | } |
| 1222 | 1236 | } |
| @@ -1267,7 +1281,8 @@ impl WindowManager { | ||
| 1267 | 1281 | } |
| 1268 | 1282 | |
| 1269 | 1283 | fn ungrab_chord_keys(&self) -> WmResult<()> { |
| 1270 | - self.connection.ungrab_key(x11rb::protocol::xproto::Grab::ANY, self.root, ModMask::ANY)?; | |
| 1284 | + self.connection | |
| 1285 | + .ungrab_key(x11rb::protocol::xproto::Grab::ANY, self.root, ModMask::ANY)?; | |
| 1271 | 1286 | keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?; |
| 1272 | 1287 | self.connection.flush()?; |
| 1273 | 1288 | Ok(()) |
| @@ -1543,7 +1558,9 @@ impl WindowManager { | ||
| 1543 | 1558 | keyboard::handlers::KeychordResult::InProgress(candidates) => { |
| 1544 | 1559 | let keys_pressed = match &self.keychord_state { |
| 1545 | 1560 | keyboard::handlers::KeychordState::Idle => 1, |
| 1546 | - keyboard::handlers::KeychordState::InProgress { keys_pressed, .. } => keys_pressed + 1, | |
| 1561 | + keyboard::handlers::KeychordState::InProgress { | |
| 1562 | + keys_pressed, .. | |
| 1563 | + } => keys_pressed + 1, | |
| 1547 | 1564 | }; |
| 1548 | 1565 | |
| 1549 | 1566 | self.keychord_state = keyboard::handlers::KeychordState::InProgress { |
| @@ -1554,7 +1571,8 @@ impl WindowManager { | ||
| 1554 | 1571 | self.grab_next_keys(&candidates, keys_pressed)?; |
| 1555 | 1572 | self.update_bar()?; |
| 1556 | 1573 | } |
| 1557 | - keyboard::handlers::KeychordResult::Cancelled | keyboard::handlers::KeychordResult::None => { | |
| 1574 | + keyboard::handlers::KeychordResult::Cancelled | |
| 1575 | + | keyboard::handlers::KeychordResult::None => { | |
| 1558 | 1576 | self.keychord_state = keyboard::handlers::KeychordState::Idle; |
| 1559 | 1577 | self.ungrab_chord_keys()?; |
| 1560 | 1578 | self.update_bar()?; |
| @@ -1605,7 +1623,11 @@ impl WindowManager { | ||
| 1605 | 1623 | } |
| 1606 | 1624 | |
| 1607 | 1625 | for (monitor_index, monitor) in self.monitors.iter().enumerate() { |
| 1608 | - let border_width = if monitor.fullscreen_enabled { 0 } else { self.config.border_width }; | |
| 1626 | + let border_width = if monitor.fullscreen_enabled { | |
| 1627 | + 0 | |
| 1628 | + } else { | |
| 1629 | + self.config.border_width | |
| 1630 | + }; | |
| 1609 | 1631 | |
| 1610 | 1632 | let gaps = if self.gaps_enabled && !monitor.fullscreen_enabled { |
| 1611 | 1633 | GapConfig { |