Removed calls to legacy hashmap system for window management
Browse files
+67 −91 src/window_manager.rs
| @@ -128,8 +128,6 @@ pub struct WindowManager { | |||
| 128 | windows: Vec<Window>, | 128 | windows: Vec<Window>, |
| 129 | clients: HashMap<Window, Client>, | 129 | clients: HashMap<Window, Client>, |
| 130 | layout: LayoutBox, | 130 | layout: LayoutBox, |
| 131 | - window_tags: HashMap<Window, TagMask>, | ||
| 132 | - window_monitor: HashMap<Window, usize>, | ||
| 133 | window_geometry_cache: HashMap<Window, CachedGeometry>, | 131 | window_geometry_cache: HashMap<Window, CachedGeometry>, |
| 134 | gaps_enabled: bool, | 132 | gaps_enabled: bool, |
| 135 | floating_windows: HashSet<Window>, | 133 | floating_windows: HashSet<Window>, |
| @@ -286,8 +284,6 @@ impl WindowManager { | |||
| 286 | windows: Vec::new(), | 284 | windows: Vec::new(), |
| 287 | clients: HashMap::new(), | 285 | clients: HashMap::new(), |
| 288 | layout: Box::new(TilingLayout), | 286 | layout: Box::new(TilingLayout), |
| 289 | - window_tags: HashMap::new(), | ||
| 290 | - window_monitor: HashMap::new(), | ||
| 291 | window_geometry_cache: HashMap::new(), | 287 | window_geometry_cache: HashMap::new(), |
| 292 | gaps_enabled, | 288 | gaps_enabled, |
| 293 | floating_windows: HashSet::new(), | 289 | floating_windows: HashSet::new(), |
| @@ -390,10 +386,8 @@ impl WindowManager { | |||
| 390 | } | 386 | } |
| 391 | 387 | ||
| 392 | if attrs.map_state == MapState::VIEWABLE { | 388 | if attrs.map_state == MapState::VIEWABLE { |
| 393 | - let tag = self.get_saved_tag(window, net_client_info)?; | 389 | + let _tag = self.get_saved_tag(window, net_client_info)?; |
| 394 | self.windows.push(window); | 390 | self.windows.push(window); |
| 395 | - self.window_tags.insert(window, tag); | ||
| 396 | - self.window_monitor.insert(window, self.selected_monitor); | ||
| 397 | continue; | 391 | continue; |
| 398 | } | 392 | } |
| 399 | 393 | ||
| @@ -415,11 +409,9 @@ impl WindowManager { | |||
| 415 | .is_ok_and(|prop| !prop.value.is_empty()); | 409 | .is_ok_and(|prop| !prop.value.is_empty()); |
| 416 | 410 | ||
| 417 | if has_wm_class { | 411 | if has_wm_class { |
| 418 | - let tag = self.get_saved_tag(window, net_client_info)?; | 412 | + let _tag = self.get_saved_tag(window, net_client_info)?; |
| 419 | self.connection.map_window(window)?; | 413 | self.connection.map_window(window)?; |
| 420 | self.windows.push(window); | 414 | self.windows.push(window); |
| 421 | - self.window_tags.insert(window, tag); | ||
| 422 | - self.window_monitor.insert(window, self.selected_monitor); | ||
| 423 | } | 415 | } |
| 424 | } | 416 | } |
| 425 | } | 417 | } |
| @@ -537,60 +529,53 @@ impl WindowManager { | |||
| 537 | } | 529 | } |
| 538 | 530 | ||
| 539 | fn toggle_floating(&mut self) -> WmResult<()> { | 531 | fn toggle_floating(&mut self) -> WmResult<()> { |
| 540 | - if let Some(focused) = self | 532 | + let focused = self |
| 541 | .monitors | 533 | .monitors |
| 542 | .get(self.selected_monitor) | 534 | .get(self.selected_monitor) |
| 543 | - .and_then(|m| m.selected_client) | 535 | + .and_then(|m| m.selected_client); |
| 544 | - { | ||
| 545 | - if self.floating_windows.contains(&focused) { | ||
| 546 | - self.floating_windows.remove(&focused); | ||
| 547 | - if let Some(client) = self.clients.get_mut(&focused) { | ||
| 548 | - client.is_floating = false; | ||
| 549 | - } | ||
| 550 | - | ||
| 551 | - let selected_tags = self | ||
| 552 | - .monitors | ||
| 553 | - .get(self.selected_monitor) | ||
| 554 | - .map(|m| m.tagset[m.selected_tags_index]) | ||
| 555 | - .unwrap_or(tag_mask(0)); | ||
| 556 | - | ||
| 557 | - self.window_tags.insert(focused, selected_tags); | ||
| 558 | - self.window_monitor.insert(focused, self.selected_monitor); | ||
| 559 | - if let Err(error) = self.save_client_tag(focused, selected_tags) { | ||
| 560 | - eprintln!("Failed to save client tag: {:?}", error); | ||
| 561 | - } | ||
| 562 | 536 | ||
| 563 | - self.apply_layout()?; | 537 | + if focused.is_none() { |
| 564 | - } else { | 538 | + return Ok(()); |
| 565 | - if let Some(monitor) = self.monitors.get(self.selected_monitor) { | 539 | + } |
| 566 | - let float_width = (monitor.screen_width as f32 * 0.5) as u32; | 540 | + let focused = focused.unwrap(); |
| 567 | - let float_height = (monitor.screen_height as f32 * 0.5) as u32; | ||
| 568 | 541 | ||
| 569 | - let border_width = self.config.border_width; | 542 | + if let Some(client) = self.clients.get(&focused) { |
| 543 | + if client.is_fullscreen { | ||
| 544 | + return Ok(()); | ||
| 545 | + } | ||
| 546 | + } | ||
| 570 | 547 | ||
| 571 | - let center_x = monitor.screen_x + (monitor.screen_width as i32 - float_width as i32) / 2; | 548 | + let (is_fixed, x, y, w, h) = if let Some(client) = self.clients.get(&focused) { |
| 572 | - let center_y = monitor.screen_y + (monitor.screen_height as i32 - float_height as i32) / 2; | 549 | + (client.is_fixed, client.x_position as i32, client.y_position as i32, client.width as u32, client.height as u32) |
| 550 | + } else { | ||
| 551 | + return Ok(()); | ||
| 552 | + }; | ||
| 573 | 553 | ||
| 574 | - self.connection.configure_window( | 554 | + let was_floating = self.floating_windows.contains(&focused); |
| 575 | - focused, | ||
| 576 | - &ConfigureWindowAux::new() | ||
| 577 | - .x(center_x) | ||
| 578 | - .y(center_y) | ||
| 579 | - .width(float_width) | ||
| 580 | - .height(float_height) | ||
| 581 | - .border_width(border_width) | ||
| 582 | - .stack_mode(StackMode::ABOVE), | ||
| 583 | - )?; | ||
| 584 | 555 | ||
| 585 | - self.floating_windows.insert(focused); | 556 | + if was_floating { |
| 586 | - if let Some(client) = self.clients.get_mut(&focused) { | 557 | + self.floating_windows.remove(&focused); |
| 587 | - client.is_floating = true; | 558 | + if let Some(client) = self.clients.get_mut(&focused) { |
| 588 | - } | 559 | + client.is_floating = false; |
| 589 | - self.apply_layout()?; | ||
| 590 | - self.connection.flush()?; | ||
| 591 | - } | ||
| 592 | } | 560 | } |
| 561 | + } else { | ||
| 562 | + self.floating_windows.insert(focused); | ||
| 563 | + if let Some(client) = self.clients.get_mut(&focused) { | ||
| 564 | + client.is_floating = is_fixed || !client.is_floating; | ||
| 565 | + } | ||
| 566 | + | ||
| 567 | + self.connection.configure_window( | ||
| 568 | + focused, | ||
| 569 | + &ConfigureWindowAux::new() | ||
| 570 | + .x(x) | ||
| 571 | + .y(y) | ||
| 572 | + .width(w) | ||
| 573 | + .height(h) | ||
| 574 | + .stack_mode(StackMode::ABOVE), | ||
| 575 | + )?; | ||
| 593 | } | 576 | } |
| 577 | + | ||
| 578 | + self.apply_layout()?; | ||
| 594 | Ok(()) | 579 | Ok(()) |
| 595 | } | 580 | } |
| 596 | 581 | ||
| @@ -1219,8 +1204,6 @@ impl WindowManager { | |||
| 1219 | client.tags = mask; | 1204 | client.tags = mask; |
| 1220 | } | 1205 | } |
| 1221 | 1206 | ||
| 1222 | - self.window_tags.insert(focused, mask); | ||
| 1223 | - | ||
| 1224 | if let Err(error) = self.save_client_tag(focused, mask) { | 1207 | if let Err(error) = self.save_client_tag(focused, mask) { |
| 1225 | eprintln!("Failed to save client tag: {:?}", error); | 1208 | eprintln!("Failed to save client tag: {:?}", error); |
| 1226 | } | 1209 | } |
| @@ -1258,8 +1241,6 @@ impl WindowManager { | |||
| 1258 | client.tags = new_tags; | 1241 | client.tags = new_tags; |
| 1259 | } | 1242 | } |
| 1260 | 1243 | ||
| 1261 | - self.window_tags.insert(focused, new_tags); | ||
| 1262 | - | ||
| 1263 | if let Err(error) = self.save_client_tag(focused, new_tags) { | 1244 | if let Err(error) = self.save_client_tag(focused, new_tags) { |
| 1264 | eprintln!("Failed to save client tag: {:?}", error); | 1245 | eprintln!("Failed to save client tag: {:?}", error); |
| 1265 | } | 1246 | } |
| @@ -1678,6 +1659,11 @@ impl WindowManager { | |||
| 1678 | } | 1659 | } |
| 1679 | 1660 | ||
| 1680 | fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> { | 1661 | fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> { |
| 1662 | + let monitor_idx = self.clients.get(&window) | ||
| 1663 | + .map(|c| c.monitor_index) | ||
| 1664 | + .unwrap_or(self.selected_monitor); | ||
| 1665 | + let monitor = &self.monitors[monitor_idx]; | ||
| 1666 | + | ||
| 1681 | if fullscreen && !self.fullscreen_windows.contains(&window) { | 1667 | if fullscreen && !self.fullscreen_windows.contains(&window) { |
| 1682 | let bytes = self.atoms.net_wm_state_fullscreen.to_ne_bytes().to_vec(); | 1668 | let bytes = self.atoms.net_wm_state_fullscreen.to_ne_bytes().to_vec(); |
| 1683 | self.connection.change_property( | 1669 | self.connection.change_property( |
| @@ -1690,21 +1676,15 @@ impl WindowManager { | |||
| 1690 | &bytes, | 1676 | &bytes, |
| 1691 | )?; | 1677 | )?; |
| 1692 | 1678 | ||
| 1693 | - self.fullscreen_windows.insert(window); | ||
| 1694 | if let Some(client) = self.clients.get_mut(&window) { | 1679 | if let Some(client) = self.clients.get_mut(&window) { |
| 1695 | client.is_fullscreen = true; | 1680 | client.is_fullscreen = true; |
| 1681 | + client.old_state = client.is_floating; | ||
| 1682 | + client.old_border_width = client.border_width; | ||
| 1683 | + client.border_width = 0; | ||
| 1684 | + client.is_floating = true; | ||
| 1696 | } | 1685 | } |
| 1697 | 1686 | ||
| 1698 | - let monitor_idx = self.clients.get(&window) | 1687 | + self.fullscreen_windows.insert(window); |
| 1699 | - .map(|c| c.monitor_index) | ||
| 1700 | - .unwrap_or(self.selected_monitor); | ||
| 1701 | - let monitor = &self.monitors[monitor_idx]; | ||
| 1702 | - | ||
| 1703 | - if self.show_bar { | ||
| 1704 | - if let Some(bar) = self.bars.get(monitor_idx) { | ||
| 1705 | - self.connection.unmap_window(bar.window())?; | ||
| 1706 | - } | ||
| 1707 | - } | ||
| 1708 | 1688 | ||
| 1709 | self.connection.configure_window( | 1689 | self.connection.configure_window( |
| 1710 | window, | 1690 | window, |
| @@ -1718,7 +1698,6 @@ impl WindowManager { | |||
| 1718 | )?; | 1698 | )?; |
| 1719 | 1699 | ||
| 1720 | self.connection.flush()?; | 1700 | self.connection.flush()?; |
| 1721 | - self.update_bar()?; | ||
| 1722 | } else if !fullscreen && self.fullscreen_windows.contains(&window) { | 1701 | } else if !fullscreen && self.fullscreen_windows.contains(&window) { |
| 1723 | self.connection.change_property( | 1702 | self.connection.change_property( |
| 1724 | PropMode::REPLACE, | 1703 | PropMode::REPLACE, |
| @@ -1731,23 +1710,27 @@ impl WindowManager { | |||
| 1731 | )?; | 1710 | )?; |
| 1732 | 1711 | ||
| 1733 | self.fullscreen_windows.remove(&window); | 1712 | self.fullscreen_windows.remove(&window); |
| 1713 | + | ||
| 1734 | if let Some(client) = self.clients.get_mut(&window) { | 1714 | if let Some(client) = self.clients.get_mut(&window) { |
| 1735 | client.is_fullscreen = false; | 1715 | client.is_fullscreen = false; |
| 1736 | - } | 1716 | + client.is_floating = client.old_state; |
| 1717 | + client.border_width = client.old_border_width; | ||
| 1737 | 1718 | ||
| 1738 | - self.connection.configure_window( | 1719 | + let x = client.old_x_position; |
| 1739 | - window, | 1720 | + let y = client.old_y_position; |
| 1740 | - &x11rb::protocol::xproto::ConfigureWindowAux::new() | 1721 | + let w = client.old_width; |
| 1741 | - .border_width(self.config.border_width), | 1722 | + let h = client.old_height; |
| 1742 | - )?; | 1723 | + let bw = client.border_width; |
| 1743 | 1724 | ||
| 1744 | - let monitor_idx = self.clients.get(&window) | 1725 | + self.connection.configure_window( |
| 1745 | - .map(|c| c.monitor_index) | 1726 | + window, |
| 1746 | - .unwrap_or(self.selected_monitor); | 1727 | + &x11rb::protocol::xproto::ConfigureWindowAux::new() |
| 1747 | - if self.show_bar { | 1728 | + .x(x as i32) |
| 1748 | - if let Some(bar) = self.bars.get(monitor_idx) { | 1729 | + .y(y as i32) |
| 1749 | - self.connection.map_window(bar.window())?; | 1730 | + .width(w as u32) |
| 1750 | - } | 1731 | + .height(h as u32) |
| 1732 | + .border_width(bw as u32), | ||
| 1733 | + )?; | ||
| 1751 | } | 1734 | } |
| 1752 | 1735 | ||
| 1753 | self.apply_layout()?; | 1736 | self.apply_layout()?; |
| @@ -1910,8 +1893,6 @@ impl WindowManager { | |||
| 1910 | }); | 1893 | }); |
| 1911 | 1894 | ||
| 1912 | client.tags = tags; | 1895 | client.tags = tags; |
| 1913 | - self.window_tags.insert(window, tags); | ||
| 1914 | - self.window_monitor.insert(window, client.monitor_index); | ||
| 1915 | } | 1896 | } |
| 1916 | 1897 | ||
| 1917 | Ok(()) | 1898 | Ok(()) |
| @@ -3599,11 +3580,8 @@ impl WindowManager { | |||
| 3599 | .map(|m| m.tagset[m.selected_tags_index]) | 3580 | .map(|m| m.tagset[m.selected_tags_index]) |
| 3600 | .unwrap_or(1); | 3581 | .unwrap_or(1); |
| 3601 | client.tags = new_tags; | 3582 | client.tags = new_tags; |
| 3602 | - self.window_tags.insert(window, new_tags); | ||
| 3603 | } | 3583 | } |
| 3604 | 3584 | ||
| 3605 | - self.window_monitor.insert(window, target_monitor); | ||
| 3606 | - | ||
| 3607 | self.attach_aside(window, target_monitor); | 3585 | self.attach_aside(window, target_monitor); |
| 3608 | self.attach_stack(window, target_monitor); | 3586 | self.attach_stack(window, target_monitor); |
| 3609 | 3587 | ||
| @@ -3628,8 +3606,6 @@ impl WindowManager { | |||
| 3628 | } | 3606 | } |
| 3629 | 3607 | ||
| 3630 | self.windows.retain(|&w| w != window); | 3608 | self.windows.retain(|&w| w != window); |
| 3631 | - self.window_tags.remove(&window); | ||
| 3632 | - self.window_monitor.remove(&window); | ||
| 3633 | self.window_geometry_cache.remove(&window); | 3609 | self.window_geometry_cache.remove(&window); |
| 3634 | self.floating_windows.remove(&window); | 3610 | self.floating_windows.remove(&window); |
| 3635 | 3611 | ||