window_manager: apply clippy lints
Browse files
mostly `collapsible_if` and `needless_type_cast`
+342 −377 src/window_manager.rs Large diff collapsed, click to expand
| @@ -546,10 +546,10 @@ impl WindowManager { | ||
| 546 | 546 | } |
| 547 | 547 | let focused = focused.unwrap(); |
| 548 | 548 | |
| 549 | - if let Some(client) = self.clients.get(&focused) { | |
| 550 | - if client.is_fullscreen { | |
| 551 | - return Ok(()); | |
| 552 | - } | |
| 549 | + if let Some(client) = self.clients.get(&focused) | |
| 550 | + && client.is_fullscreen | |
| 551 | + { | |
| 552 | + return Ok(()); | |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | let (is_fixed, x, y, w, h) = if let Some(client) = self.clients.get(&focused) { |
| @@ -594,7 +594,7 @@ impl WindowManager { | ||
| 594 | 594 | |
| 595 | 595 | fn set_master_factor(&mut self, delta: f32) -> WmResult<()> { |
| 596 | 596 | if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 597 | - let new_mfact = (monitor.master_factor + delta).max(0.05).min(0.95); | |
| 597 | + let new_mfact = (monitor.master_factor + delta).clamp(0.05, 0.95); | |
| 598 | 598 | monitor.master_factor = new_mfact; |
| 599 | 599 | self.apply_layout()?; |
| 600 | 600 | } |
| @@ -993,10 +993,10 @@ impl WindowManager { | ||
| 993 | 993 | ) -> WmResult<()> { |
| 994 | 994 | let current_monitor_index = self.clients.get(&window).map(|c| c.monitor_index); |
| 995 | 995 | |
| 996 | - if let Some(current_idx) = current_monitor_index { | |
| 997 | - if current_idx == target_monitor_index { | |
| 998 | - return Ok(()); | |
| 999 | - } | |
| 996 | + if let Some(current_idx) = current_monitor_index | |
| 997 | + && current_idx == target_monitor_index | |
| 998 | + { | |
| 999 | + return Ok(()); | |
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | self.unfocus(window)?; |
| @@ -1030,12 +1030,10 @@ impl WindowManager { | ||
| 1030 | 1030 | } else { |
| 1031 | 1031 | Some(0) |
| 1032 | 1032 | } |
| 1033 | + } else if self.selected_monitor == 0 { | |
| 1034 | + Some(self.monitors.len() - 1) | |
| 1033 | 1035 | } else { |
| 1034 | - if self.selected_monitor == 0 { | |
| 1035 | - Some(self.monitors.len() - 1) | |
| 1036 | - } else { | |
| 1037 | - Some(self.selected_monitor - 1) | |
| 1038 | - } | |
| 1036 | + Some(self.selected_monitor - 1) | |
| 1039 | 1037 | } |
| 1040 | 1038 | } |
| 1041 | 1039 | |
| @@ -1405,34 +1403,34 @@ impl WindowManager { | ||
| 1405 | 1403 | .get_property(false, window, AtomEnum::WM_HINTS, AtomEnum::WM_HINTS, 0, 9)? |
| 1406 | 1404 | .reply(); |
| 1407 | 1405 | |
| 1408 | - if let Ok(hints) = hints_reply { | |
| 1409 | - if hints.value.len() >= 4 { | |
| 1410 | - let mut flags = u32::from_ne_bytes([ | |
| 1411 | - hints.value[0], | |
| 1412 | - hints.value[1], | |
| 1413 | - hints.value[2], | |
| 1414 | - hints.value[3], | |
| 1415 | - ]); | |
| 1416 | - | |
| 1417 | - if urgent { | |
| 1418 | - flags |= 256; | |
| 1419 | - } else { | |
| 1420 | - flags &= !256; | |
| 1421 | - } | |
| 1406 | + if let Ok(hints) = hints_reply | |
| 1407 | + && hints.value.len() >= 4 | |
| 1408 | + { | |
| 1409 | + let mut flags = u32::from_ne_bytes([ | |
| 1410 | + hints.value[0], | |
| 1411 | + hints.value[1], | |
| 1412 | + hints.value[2], | |
| 1413 | + hints.value[3], | |
| 1414 | + ]); | |
| 1415 | + | |
| 1416 | + if urgent { | |
| 1417 | + flags |= 256; | |
| 1418 | + } else { | |
| 1419 | + flags &= !256; | |
| 1420 | + } | |
| 1422 | 1421 | |
| 1423 | - let mut new_hints = hints.value.clone(); | |
| 1424 | - new_hints[0..4].copy_from_slice(&flags.to_ne_bytes()); | |
| 1422 | + let mut new_hints = hints.value.clone(); | |
| 1423 | + new_hints[0..4].copy_from_slice(&flags.to_ne_bytes()); | |
| 1425 | 1424 | |
| 1426 | - self.connection.change_property( | |
| 1427 | - PropMode::REPLACE, | |
| 1428 | - window, | |
| 1429 | - AtomEnum::WM_HINTS, | |
| 1430 | - AtomEnum::WM_HINTS, | |
| 1431 | - 32, | |
| 1432 | - new_hints.len() as u32 / 4, | |
| 1433 | - &new_hints, | |
| 1434 | - )?; | |
| 1435 | - } | |
| 1425 | + self.connection.change_property( | |
| 1426 | + PropMode::REPLACE, | |
| 1427 | + window, | |
| 1428 | + AtomEnum::WM_HINTS, | |
| 1429 | + AtomEnum::WM_HINTS, | |
| 1430 | + 32, | |
| 1431 | + new_hints.len() as u32 / 4, | |
| 1432 | + &new_hints, | |
| 1433 | + )?; | |
| 1436 | 1434 | } |
| 1437 | 1435 | |
| 1438 | 1436 | Ok(()) |
| @@ -1481,13 +1479,7 @@ impl WindowManager { | ||
| 1481 | 1479 | if let Ok(geom) = self.connection.get_geometry(*window)?.reply() { |
| 1482 | 1480 | self.floating_geometry_before_fullscreen.insert( |
| 1483 | 1481 | *window, |
| 1484 | - ( | |
| 1485 | - geom.x, | |
| 1486 | - geom.y, | |
| 1487 | - geom.width, | |
| 1488 | - geom.height, | |
| 1489 | - geom.border_width as u16, | |
| 1490 | - ), | |
| 1482 | + (geom.x, geom.y, geom.width, geom.height, geom.border_width), | |
| 1491 | 1483 | ); |
| 1492 | 1484 | } |
| 1493 | 1485 | } |
| @@ -1562,10 +1554,10 @@ impl WindowManager { | ||
| 1562 | 1554 | |
| 1563 | 1555 | self.fullscreen_windows.remove(&focused_window); |
| 1564 | 1556 | |
| 1565 | - if let Some(last) = self.last_layout { | |
| 1566 | - if let Ok(layout) = layout_from_str(last) { | |
| 1567 | - self.layout = layout; | |
| 1568 | - } | |
| 1557 | + if let Some(last) = self.last_layout | |
| 1558 | + && let Ok(layout) = layout_from_str(last) | |
| 1559 | + { | |
| 1560 | + self.layout = layout; | |
| 1569 | 1561 | } |
| 1570 | 1562 | |
| 1571 | 1563 | let windows_to_restore: Vec<Window> = self |
| @@ -1605,15 +1597,13 @@ impl WindowManager { | ||
| 1605 | 1597 | |
| 1606 | 1598 | if self.layout.name() != "normie" { |
| 1607 | 1599 | self.apply_layout()?; |
| 1608 | - } else { | |
| 1609 | - if let Some(bar) = self.bars.get(self.selected_monitor) { | |
| 1610 | - self.connection.configure_window( | |
| 1611 | - bar.window(), | |
| 1612 | - &x11rb::protocol::xproto::ConfigureWindowAux::new() | |
| 1613 | - .stack_mode(x11rb::protocol::xproto::StackMode::ABOVE), | |
| 1614 | - )?; | |
| 1615 | - self.connection.flush()?; | |
| 1616 | - } | |
| 1600 | + } else if let Some(bar) = self.bars.get(self.selected_monitor) { | |
| 1601 | + self.connection.configure_window( | |
| 1602 | + bar.window(), | |
| 1603 | + &x11rb::protocol::xproto::ConfigureWindowAux::new() | |
| 1604 | + .stack_mode(x11rb::protocol::xproto::StackMode::ABOVE), | |
| 1605 | + )?; | |
| 1606 | + self.connection.flush()?; | |
| 1617 | 1607 | } |
| 1618 | 1608 | } |
| 1619 | 1609 | Ok(()) |
| @@ -1751,15 +1741,14 @@ impl WindowManager { | ||
| 1751 | 1741 | .ok() |
| 1752 | 1742 | .and_then(|cookie| cookie.reply().ok()); |
| 1753 | 1743 | |
| 1754 | - if let Some(reply) = reply { | |
| 1755 | - if !reply.value.is_empty() { | |
| 1756 | - if let Ok(text) = std::str::from_utf8(&reply.value) { | |
| 1757 | - let parts: Vec<&str> = text.split('\0').collect(); | |
| 1758 | - let instance = parts.get(0).unwrap_or(&"").to_string(); | |
| 1759 | - let class = parts.get(1).unwrap_or(&"").to_string(); | |
| 1760 | - return (instance, class); | |
| 1761 | - } | |
| 1762 | - } | |
| 1744 | + if let Some(reply) = reply | |
| 1745 | + && !reply.value.is_empty() | |
| 1746 | + && let Ok(text) = std::str::from_utf8(&reply.value) | |
| 1747 | + { | |
| 1748 | + let parts: Vec<&str> = text.split('\0').collect(); | |
| 1749 | + let instance = parts.first().unwrap_or(&"").to_string(); | |
| 1750 | + let class = parts.get(1).unwrap_or(&"").to_string(); | |
| 1751 | + return (instance, class); | |
| 1763 | 1752 | } |
| 1764 | 1753 | |
| 1765 | 1754 | (String::new(), String::new()) |
| @@ -1801,10 +1790,10 @@ impl WindowManager { | ||
| 1801 | 1790 | } |
| 1802 | 1791 | } |
| 1803 | 1792 | |
| 1804 | - if let Some(monitor_index) = rule_monitor { | |
| 1805 | - if monitor_index < self.monitors.len() { | |
| 1806 | - client.monitor_index = monitor_index; | |
| 1807 | - } | |
| 1793 | + if let Some(monitor_index) = rule_monitor | |
| 1794 | + && monitor_index < self.monitors.len() | |
| 1795 | + { | |
| 1796 | + client.monitor_index = monitor_index; | |
| 1808 | 1797 | } |
| 1809 | 1798 | |
| 1810 | 1799 | let tags = rule_tags.unwrap_or_else(|| { |
| @@ -1937,11 +1926,11 @@ impl WindowManager { | ||
| 1937 | 1926 | .get(&window) |
| 1938 | 1927 | .map(|c| c.is_fixed) |
| 1939 | 1928 | .unwrap_or(false); |
| 1940 | - if let Some(c) = self.clients.get_mut(&window) { | |
| 1941 | - if !c.is_floating { | |
| 1942 | - c.is_floating = is_transient || is_fixed; | |
| 1943 | - c.old_state = c.is_floating; | |
| 1944 | - } | |
| 1929 | + if let Some(c) = self.clients.get_mut(&window) | |
| 1930 | + && !c.is_floating | |
| 1931 | + { | |
| 1932 | + c.is_floating = is_transient || is_fixed; | |
| 1933 | + c.old_state = c.is_floating; | |
| 1945 | 1934 | } |
| 1946 | 1935 | |
| 1947 | 1936 | if self |
| @@ -1976,14 +1965,13 @@ impl WindowManager { | ||
| 1976 | 1965 | let final_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(tags); |
| 1977 | 1966 | let _ = self.save_client_tag(window, final_tags); |
| 1978 | 1967 | |
| 1979 | - if client_monitor == self.selected_monitor { | |
| 1980 | - if let Some(old_sel) = self | |
| 1968 | + if client_monitor == self.selected_monitor | |
| 1969 | + && let Some(old_sel) = self | |
| 1981 | 1970 | .monitors |
| 1982 | 1971 | .get(self.selected_monitor) |
| 1983 | 1972 | .and_then(|m| m.selected_client) |
| 1984 | - { | |
| 1985 | - self.unfocus(old_sel)?; | |
| 1986 | - } | |
| 1973 | + { | |
| 1974 | + self.unfocus(old_sel)?; | |
| 1987 | 1975 | } |
| 1988 | 1976 | |
| 1989 | 1977 | if let Some(m) = self.monitors.get_mut(client_monitor) { |
| @@ -2036,7 +2024,7 @@ impl WindowManager { | ||
| 2036 | 2024 | self.connection.grab_button( |
| 2037 | 2025 | false, |
| 2038 | 2026 | window, |
| 2039 | - EventMask::BUTTON_PRESS.into(), | |
| 2027 | + EventMask::BUTTON_PRESS, | |
| 2040 | 2028 | GrabMode::SYNC, |
| 2041 | 2029 | GrabMode::SYNC, |
| 2042 | 2030 | x11rb::NONE, |
| @@ -2052,10 +2040,10 @@ impl WindowManager { | ||
| 2052 | 2040 | let monitor = self.monitors.get_mut(self.selected_monitor).unwrap(); |
| 2053 | 2041 | let old_selected = monitor.selected_client; |
| 2054 | 2042 | |
| 2055 | - if let Some(old_win) = old_selected { | |
| 2056 | - if old_selected != window { | |
| 2057 | - self.unfocus(old_win)?; | |
| 2058 | - } | |
| 2043 | + if let Some(old_win) = old_selected | |
| 2044 | + && old_selected != window | |
| 2045 | + { | |
| 2046 | + self.unfocus(old_win)?; | |
| 2059 | 2047 | } |
| 2060 | 2048 | |
| 2061 | 2049 | let mut win = window; |
| @@ -2132,18 +2120,19 @@ impl WindowManager { | ||
| 2132 | 2120 | |
| 2133 | 2121 | let mut windows_to_restack: Vec<Window> = Vec::new(); |
| 2134 | 2122 | |
| 2135 | - if let Some(selected) = monitor.selected_client { | |
| 2136 | - if self.floating_windows.contains(&selected) { | |
| 2137 | - windows_to_restack.push(selected); | |
| 2138 | - } | |
| 2123 | + if let Some(selected) = monitor.selected_client | |
| 2124 | + && self.floating_windows.contains(&selected) | |
| 2125 | + { | |
| 2126 | + windows_to_restack.push(selected); | |
| 2139 | 2127 | } |
| 2140 | 2128 | |
| 2141 | 2129 | let mut current = monitor.stack_head; |
| 2142 | 2130 | while let Some(win) = current { |
| 2143 | - if self.windows.contains(&win) && self.floating_windows.contains(&win) { | |
| 2144 | - if Some(win) != monitor.selected_client { | |
| 2145 | - windows_to_restack.push(win); | |
| 2146 | - } | |
| 2131 | + if self.windows.contains(&win) | |
| 2132 | + && self.floating_windows.contains(&win) | |
| 2133 | + && Some(win) != monitor.selected_client | |
| 2134 | + { | |
| 2135 | + windows_to_restack.push(win); | |
| 2147 | 2136 | } |
| 2148 | 2137 | current = self.clients.get(&win).and_then(|c| c.stack_next); |
| 2149 | 2138 | } |
| @@ -2214,12 +2203,10 @@ impl WindowManager { | ||
| 2214 | 2203 | } else { |
| 2215 | 2204 | stack_windows[0] |
| 2216 | 2205 | } |
| 2206 | + } else if idx > 0 { | |
| 2207 | + stack_windows[idx - 1] | |
| 2217 | 2208 | } else { |
| 2218 | - if idx > 0 { | |
| 2219 | - stack_windows[idx - 1] | |
| 2220 | - } else { | |
| 2221 | - stack_windows[stack_windows.len() - 1] | |
| 2222 | - } | |
| 2209 | + stack_windows[stack_windows.len() - 1] | |
| 2223 | 2210 | } |
| 2224 | 2211 | } else { |
| 2225 | 2212 | return Ok(()); |
| @@ -2337,20 +2324,18 @@ impl WindowManager { | ||
| 2337 | 2324 | client.next = temp; |
| 2338 | 2325 | } |
| 2339 | 2326 | |
| 2340 | - if let Some(prev) = prev_selected { | |
| 2341 | - if prev != target { | |
| 2342 | - if let Some(client) = self.clients.get_mut(&prev) { | |
| 2343 | - client.next = Some(target); | |
| 2344 | - } | |
| 2345 | - } | |
| 2327 | + if let Some(prev) = prev_selected | |
| 2328 | + && prev != target | |
| 2329 | + && let Some(client) = self.clients.get_mut(&prev) | |
| 2330 | + { | |
| 2331 | + client.next = Some(target); | |
| 2346 | 2332 | } |
| 2347 | 2333 | |
| 2348 | - if let Some(prev) = prev_target { | |
| 2349 | - if prev != selected { | |
| 2350 | - if let Some(client) = self.clients.get_mut(&prev) { | |
| 2351 | - client.next = Some(selected); | |
| 2352 | - } | |
| 2353 | - } | |
| 2334 | + if let Some(prev) = prev_target | |
| 2335 | + && prev != selected | |
| 2336 | + && let Some(client) = self.clients.get_mut(&prev) | |
| 2337 | + { | |
| 2338 | + client.next = Some(selected); | |
| 2354 | 2339 | } |
| 2355 | 2340 | |
| 2356 | 2341 | if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
| @@ -2420,18 +2405,18 @@ impl WindowManager { | ||
| 2420 | 2405 | old_focused: Option<Window>, |
| 2421 | 2406 | new_focused: Window, |
| 2422 | 2407 | ) -> WmResult<()> { |
| 2423 | - if let Some(old_win) = old_focused { | |
| 2424 | - if old_win != new_focused { | |
| 2425 | - self.connection.configure_window( | |
| 2426 | - old_win, | |
| 2427 | - &ConfigureWindowAux::new().border_width(self.config.border_width), | |
| 2428 | - )?; | |
| 2408 | + if let Some(old_win) = old_focused | |
| 2409 | + && old_win != new_focused | |
| 2410 | + { | |
| 2411 | + self.connection.configure_window( | |
| 2412 | + old_win, | |
| 2413 | + &ConfigureWindowAux::new().border_width(self.config.border_width), | |
| 2414 | + )?; | |
| 2429 | 2415 | |
| 2430 | - self.connection.change_window_attributes( | |
| 2431 | - old_win, | |
| 2432 | - &ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused), | |
| 2433 | - )?; | |
| 2434 | - } | |
| 2416 | + self.connection.change_window_attributes( | |
| 2417 | + old_win, | |
| 2418 | + &ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused), | |
| 2419 | + )?; | |
| 2435 | 2420 | } |
| 2436 | 2421 | |
| 2437 | 2422 | self.connection.configure_window( |
| @@ -2490,8 +2475,7 @@ impl WindowManager { | ||
| 2490 | 2475 | .grab_pointer( |
| 2491 | 2476 | false, |
| 2492 | 2477 | self.root, |
| 2493 | - (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | EventMask::BUTTON_PRESS) | |
| 2494 | - .into(), | |
| 2478 | + EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | EventMask::BUTTON_PRESS, | |
| 2495 | 2479 | GrabMode::ASYNC, |
| 2496 | 2480 | GrabMode::ASYNC, |
| 2497 | 2481 | x11rb::NONE, |
| @@ -2748,8 +2732,7 @@ impl WindowManager { | ||
| 2748 | 2732 | .grab_pointer( |
| 2749 | 2733 | false, |
| 2750 | 2734 | self.root, |
| 2751 | - (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | EventMask::BUTTON_PRESS) | |
| 2752 | - .into(), | |
| 2735 | + EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | EventMask::BUTTON_PRESS, | |
| 2753 | 2736 | GrabMode::ASYNC, |
| 2754 | 2737 | GrabMode::ASYNC, |
| 2755 | 2738 | x11rb::NONE, |
| @@ -2784,29 +2767,27 @@ impl WindowManager { | ||
| 2784 | 2767 | .map(|c| c.is_floating) |
| 2785 | 2768 | .unwrap_or(false); |
| 2786 | 2769 | |
| 2787 | - if should_resize { | |
| 2788 | - if let Some(client) = self.clients.get(&window).cloned() { | |
| 2789 | - let (_, _, hint_width, hint_height, _) = self.apply_size_hints( | |
| 2790 | - window, | |
| 2791 | - client.x_position as i32, | |
| 2792 | - client.y_position as i32, | |
| 2793 | - new_width as i32, | |
| 2794 | - new_height as i32, | |
| 2795 | - ); | |
| 2796 | - | |
| 2797 | - if let Some(client_mut) = self.clients.get_mut(&window) { | |
| 2798 | - client_mut.width = hint_width as u16; | |
| 2799 | - client_mut.height = hint_height as u16; | |
| 2800 | - } | |
| 2801 | - | |
| 2802 | - self.connection.configure_window( | |
| 2803 | - window, | |
| 2804 | - &ConfigureWindowAux::new() | |
| 2805 | - .width(hint_width as u32) | |
| 2806 | - .height(hint_height as u32), | |
| 2807 | - )?; | |
| 2808 | - self.connection.flush()?; | |
| 2770 | + if should_resize && let Some(client) = self.clients.get(&window).cloned() { | |
| 2771 | + let (_, _, hint_width, hint_height, _) = self.apply_size_hints( | |
| 2772 | + window, | |
| 2773 | + client.x_position as i32, | |
| 2774 | + client.y_position as i32, | |
| 2775 | + new_width as i32, | |
| 2776 | + new_height as i32, | |
| 2777 | + ); | |
| 2778 | + | |
| 2779 | + if let Some(client_mut) = self.clients.get_mut(&window) { | |
| 2780 | + client_mut.width = hint_width as u16; | |
| 2781 | + client_mut.height = hint_height as u16; | |
| 2809 | 2782 | } |
| 2783 | + | |
| 2784 | + self.connection.configure_window( | |
| 2785 | + window, | |
| 2786 | + &ConfigureWindowAux::new() | |
| 2787 | + .width(hint_width as u32) | |
| 2788 | + .height(hint_height as u32), | |
| 2789 | + )?; | |
| 2790 | + self.connection.flush()?; | |
| 2810 | 2791 | } |
| 2811 | 2792 | } |
| 2812 | 2793 | Event::ButtonRelease(_) => break, |
| @@ -2861,26 +2842,26 @@ impl WindowManager { | ||
| 2861 | 2842 | fn handle_event(&mut self, event: Event) -> WmResult<Option<bool>> { |
| 2862 | 2843 | match event { |
| 2863 | 2844 | Event::KeyPress(ref key_event) if key_event.event == self.overlay.window() => { |
| 2864 | - if self.overlay.is_visible() { | |
| 2865 | - if let Err(error) = self.overlay.hide(&self.connection) { | |
| 2866 | - eprintln!("Failed to hide overlay: {:?}", error); | |
| 2867 | - } | |
| 2845 | + if self.overlay.is_visible() | |
| 2846 | + && let Err(error) = self.overlay.hide(&self.connection) | |
| 2847 | + { | |
| 2848 | + eprintln!("Failed to hide overlay: {:?}", error); | |
| 2868 | 2849 | } |
| 2869 | 2850 | return Ok(None); |
| 2870 | 2851 | } |
| 2871 | 2852 | Event::ButtonPress(ref button_event) if button_event.event == self.overlay.window() => { |
| 2872 | - if self.overlay.is_visible() { | |
| 2873 | - if let Err(error) = self.overlay.hide(&self.connection) { | |
| 2874 | - eprintln!("Failed to hide overlay: {:?}", error); | |
| 2875 | - } | |
| 2853 | + if self.overlay.is_visible() | |
| 2854 | + && let Err(error) = self.overlay.hide(&self.connection) | |
| 2855 | + { | |
| 2856 | + eprintln!("Failed to hide overlay: {:?}", error); | |
| 2876 | 2857 | } |
| 2877 | 2858 | return Ok(None); |
| 2878 | 2859 | } |
| 2879 | 2860 | Event::Expose(ref expose_event) if expose_event.window == self.overlay.window() => { |
| 2880 | - if self.overlay.is_visible() { | |
| 2881 | - if let Err(error) = self.overlay.draw(&self.connection, &self.font) { | |
| 2882 | - eprintln!("Failed to draw overlay: {:?}", error); | |
| 2883 | - } | |
| 2861 | + if self.overlay.is_visible() | |
| 2862 | + && let Err(error) = self.overlay.draw(&self.connection, &self.font) | |
| 2863 | + { | |
| 2864 | + eprintln!("Failed to draw overlay: {:?}", error); | |
| 2884 | 2865 | } |
| 2885 | 2866 | return Ok(None); |
| 2886 | 2867 | } |
| @@ -2893,10 +2874,10 @@ impl WindowManager { | ||
| 2893 | 2874 | let keysym = mapping.keycode_to_keysym(e.detail); |
| 2894 | 2875 | let is_escape = keysym == keysyms::XK_ESCAPE; |
| 2895 | 2876 | let is_q = keysym == keysyms::XK_Q || keysym == 0x0051; |
| 2896 | - if is_escape || is_q { | |
| 2897 | - if let Err(error) = self.keybind_overlay.hide(&self.connection) { | |
| 2898 | - eprintln!("Failed to hide keybind overlay: {:?}", error); | |
| 2899 | - } | |
| 2877 | + if (is_escape || is_q) | |
| 2878 | + && let Err(error) = self.keybind_overlay.hide(&self.connection) | |
| 2879 | + { | |
| 2880 | + eprintln!("Failed to hide keybind overlay: {:?}", error); | |
| 2900 | 2881 | } |
| 2901 | 2882 | } |
| 2902 | 2883 | } |
| @@ -2910,10 +2891,10 @@ impl WindowManager { | ||
| 2910 | 2891 | Event::Expose(ref expose_event) |
| 2911 | 2892 | if expose_event.window == self.keybind_overlay.window() => |
| 2912 | 2893 | { |
| 2913 | - if self.keybind_overlay.is_visible() { | |
| 2914 | - if let Err(error) = self.keybind_overlay.draw(&self.connection, &self.font) { | |
| 2915 | - eprintln!("Failed to draw keybind overlay: {:?}", error); | |
| 2916 | - } | |
| 2894 | + if self.keybind_overlay.is_visible() | |
| 2895 | + && let Err(error) = self.keybind_overlay.draw(&self.connection, &self.font) | |
| 2896 | + { | |
| 2897 | + eprintln!("Failed to draw keybind overlay: {:?}", error); | |
| 2917 | 2898 | } |
| 2918 | 2899 | return Ok(None); |
| 2919 | 2900 | } |
| @@ -2956,16 +2937,15 @@ impl WindowManager { | ||
| 2956 | 2937 | .get(&event.window) |
| 2957 | 2938 | .map(|c| c.is_floating) |
| 2958 | 2939 | .unwrap_or(false); |
| 2959 | - if !is_floating { | |
| 2960 | - if let Some(parent) = self.get_transient_parent(event.window) { | |
| 2961 | - if self.clients.contains_key(&parent) { | |
| 2962 | - if let Some(c) = self.clients.get_mut(&event.window) { | |
| 2963 | - c.is_floating = true; | |
| 2964 | - } | |
| 2965 | - self.floating_windows.insert(event.window); | |
| 2966 | - self.apply_layout()?; | |
| 2967 | - } | |
| 2940 | + if !is_floating | |
| 2941 | + && let Some(parent) = self.get_transient_parent(event.window) | |
| 2942 | + && self.clients.contains_key(&parent) | |
| 2943 | + { | |
| 2944 | + if let Some(c) = self.clients.get_mut(&event.window) { | |
| 2945 | + c.is_floating = true; | |
| 2968 | 2946 | } |
| 2947 | + self.floating_windows.insert(event.window); | |
| 2948 | + self.apply_layout()?; | |
| 2969 | 2949 | } |
| 2970 | 2950 | } else if event.atom == AtomEnum::WM_NORMAL_HINTS.into() { |
| 2971 | 2951 | if let Some(c) = self.clients.get_mut(&event.window) { |
| @@ -2992,11 +2972,11 @@ impl WindowManager { | ||
| 2992 | 2972 | return Ok(None); |
| 2993 | 2973 | } |
| 2994 | 2974 | if self.windows.contains(&event.event) { |
| 2995 | - if let Some(client) = self.clients.get(&event.event) { | |
| 2996 | - if client.monitor_index != self.selected_monitor { | |
| 2997 | - self.selected_monitor = client.monitor_index; | |
| 2998 | - self.update_bar()?; | |
| 2999 | - } | |
| 2975 | + if let Some(client) = self.clients.get(&event.event) | |
| 2976 | + && client.monitor_index != self.selected_monitor | |
| 2977 | + { | |
| 2978 | + self.selected_monitor = client.monitor_index; | |
| 2979 | + self.update_bar()?; | |
| 3000 | 2980 | } |
| 3001 | 2981 | self.focus(Some(event.event))?; |
| 3002 | 2982 | self.update_tab_bars()?; |
| @@ -3009,16 +2989,15 @@ impl WindowManager { | ||
| 3009 | 2989 | |
| 3010 | 2990 | if let Some(monitor_index) = |
| 3011 | 2991 | self.get_monitor_at_point(event.root_x as i32, event.root_y as i32) |
| 2992 | + && monitor_index != self.selected_monitor | |
| 3012 | 2993 | { |
| 3013 | - if monitor_index != self.selected_monitor { | |
| 3014 | - self.selected_monitor = monitor_index; | |
| 3015 | - self.update_bar()?; | |
| 2994 | + self.selected_monitor = monitor_index; | |
| 2995 | + self.update_bar()?; | |
| 3016 | 2996 | |
| 3017 | - let visible = self.visible_windows_on_monitor(monitor_index); | |
| 3018 | - if let Some(&win) = visible.first() { | |
| 3019 | - self.focus(Some(win))?; | |
| 3020 | - self.update_tab_bars()?; | |
| 3021 | - } | |
| 2997 | + let visible = self.visible_windows_on_monitor(monitor_index); | |
| 2998 | + if let Some(&win) = visible.first() { | |
| 2999 | + self.focus(Some(win))?; | |
| 3000 | + self.update_tab_bars()?; | |
| 3022 | 3001 | } |
| 3023 | 3002 | } |
| 3024 | 3003 | } |
| @@ -3100,11 +3079,11 @@ impl WindowManager { | ||
| 3100 | 3079 | } |
| 3101 | 3080 | } |
| 3102 | 3081 | Event::ButtonPress(event) => { |
| 3103 | - if self.keybind_overlay.is_visible() && event.event != self.keybind_overlay.window() | |
| 3082 | + if self.keybind_overlay.is_visible() | |
| 3083 | + && event.event != self.keybind_overlay.window() | |
| 3084 | + && let Err(error) = self.keybind_overlay.hide(&self.connection) | |
| 3104 | 3085 | { |
| 3105 | - if let Err(error) = self.keybind_overlay.hide(&self.connection) { | |
| 3106 | - eprintln!("Failed to hide keybind overlay: {:?}", error); | |
| 3107 | - } | |
| 3086 | + eprintln!("Failed to hide keybind overlay: {:?}", error); | |
| 3108 | 3087 | } |
| 3109 | 3088 | |
| 3110 | 3089 | let is_bar_click = self |
| @@ -3278,14 +3257,13 @@ impl WindowManager { | ||
| 3278 | 3257 | let width_with_border = w + 2 * bw; |
| 3279 | 3258 | let height_with_border = h + 2 * bw; |
| 3280 | 3259 | |
| 3281 | - if (x + w) > monitor.screen_x + monitor.screen_width as i32 && is_floating { | |
| 3260 | + if (x + w) > monitor.screen_x + monitor.screen_width && is_floating { | |
| 3282 | 3261 | x = monitor.screen_x |
| 3283 | - + (monitor.screen_width as i32 / 2 - width_with_border / 2); | |
| 3262 | + + (monitor.screen_width / 2 - width_with_border / 2); | |
| 3284 | 3263 | } |
| 3285 | - if (y + h) > monitor.screen_y + monitor.screen_height as i32 && is_floating | |
| 3286 | - { | |
| 3264 | + if (y + h) > monitor.screen_y + monitor.screen_height && is_floating { | |
| 3287 | 3265 | y = monitor.screen_y |
| 3288 | - + (monitor.screen_height as i32 / 2 - height_with_border / 2); | |
| 3266 | + + (monitor.screen_height / 2 - height_with_border / 2); | |
| 3289 | 3267 | } |
| 3290 | 3268 | |
| 3291 | 3269 | if let Some(c) = self.clients.get_mut(&event.window) { |
| @@ -3349,17 +3327,17 @@ impl WindowManager { | ||
| 3349 | 3327 | } |
| 3350 | 3328 | |
| 3351 | 3329 | if event.type_ == self.atoms.net_wm_state { |
| 3352 | - if let Some(data) = event.data.as_data32().get(1) { | |
| 3353 | - if *data == self.atoms.net_wm_state_fullscreen { | |
| 3354 | - let action = event.data.as_data32()[0]; | |
| 3355 | - let fullscreen = match action { | |
| 3356 | - 1 => true, | |
| 3357 | - 0 => false, | |
| 3358 | - 2 => !self.fullscreen_windows.contains(&event.window), | |
| 3359 | - _ => return Ok(None), | |
| 3360 | - }; | |
| 3361 | - self.set_window_fullscreen(event.window, fullscreen)?; | |
| 3362 | - } | |
| 3330 | + if let Some(data) = event.data.as_data32().get(1) | |
| 3331 | + && *data == self.atoms.net_wm_state_fullscreen | |
| 3332 | + { | |
| 3333 | + let action = event.data.as_data32()[0]; | |
| 3334 | + let fullscreen = match action { | |
| 3335 | + 1 => true, | |
| 3336 | + 0 => false, | |
| 3337 | + 2 => !self.fullscreen_windows.contains(&event.window), | |
| 3338 | + _ => return Ok(None), | |
| 3339 | + }; | |
| 3340 | + self.set_window_fullscreen(event.window, fullscreen)?; | |
| 3363 | 3341 | } |
| 3364 | 3342 | } else if event.type_ == self.atoms.net_active_window { |
| 3365 | 3343 | let selected_window = self |
| @@ -3384,10 +3362,10 @@ impl WindowManager { | ||
| 3384 | 3362 | .get(self.selected_monitor) |
| 3385 | 3363 | .and_then(|m| m.selected_client); |
| 3386 | 3364 | |
| 3387 | - if let Some(sel_win) = selected_window { | |
| 3388 | - if event.event != sel_win { | |
| 3389 | - self.set_focus(sel_win)?; | |
| 3390 | - } | |
| 3365 | + if let Some(sel_win) = selected_window | |
| 3366 | + && event.event != sel_win | |
| 3367 | + { | |
| 3368 | + self.set_focus(sel_win)?; | |
| 3391 | 3369 | } |
| 3392 | 3370 | } |
| 3393 | 3371 | Event::MappingNotify(event) => { |
| @@ -3484,18 +3462,18 @@ impl WindowManager { | ||
| 3484 | 3462 | let mut adjusted_width = geometry.width.saturating_sub(2 * border_width); |
| 3485 | 3463 | let mut adjusted_height = geometry.height.saturating_sub(2 * border_width); |
| 3486 | 3464 | |
| 3487 | - if let Some(client) = self.clients.get(window).cloned() { | |
| 3488 | - if !client.is_floating { | |
| 3489 | - let (_, _, hint_width, hint_height, _) = self.apply_size_hints( | |
| 3490 | - *window, | |
| 3491 | - geometry.x_coordinate as i32, | |
| 3492 | - geometry.y_coordinate as i32, | |
| 3493 | - adjusted_width as i32, | |
| 3494 | - adjusted_height as i32, | |
| 3495 | - ); | |
| 3496 | - adjusted_width = hint_width as u32; | |
| 3497 | - adjusted_height = hint_height as u32; | |
| 3498 | - } | |
| 3465 | + if let Some(client) = self.clients.get(window).cloned() | |
| 3466 | + && !client.is_floating | |
| 3467 | + { | |
| 3468 | + let (_, _, hint_width, hint_height, _) = self.apply_size_hints( | |
| 3469 | + *window, | |
| 3470 | + geometry.x_coordinate, | |
| 3471 | + geometry.y_coordinate, | |
| 3472 | + adjusted_width as i32, | |
| 3473 | + adjusted_height as i32, | |
| 3474 | + ); | |
| 3475 | + adjusted_width = hint_width as u32; | |
| 3476 | + adjusted_height = hint_height as u32; | |
| 3499 | 3477 | } |
| 3500 | 3478 | |
| 3501 | 3479 | let adjusted_x = geometry.x_coordinate + monitor_x; |
| @@ -3601,10 +3579,8 @@ impl WindowManager { | ||
| 3601 | 3579 | if let Err(e) = self.tab_bars[monitor_index].show(&self.connection) { |
| 3602 | 3580 | eprintln!("Failed to show tab bar: {:?}", e); |
| 3603 | 3581 | } |
| 3604 | - } else { | |
| 3605 | - if let Err(e) = self.tab_bars[monitor_index].hide(&self.connection) { | |
| 3606 | - eprintln!("Failed to hide tab bar: {:?}", e); | |
| 3607 | - } | |
| 3582 | + } else if let Err(e) = self.tab_bars[monitor_index].hide(&self.connection) { | |
| 3583 | + eprintln!("Failed to hide tab bar: {:?}", e); | |
| 3608 | 3584 | } |
| 3609 | 3585 | } |
| 3610 | 3586 | |
| @@ -3765,15 +3741,13 @@ impl WindowManager { | ||
| 3765 | 3741 | .ok() |
| 3766 | 3742 | .and_then(|cookie| cookie.reply().ok()); |
| 3767 | 3743 | |
| 3768 | - if let Some(name) = net_name { | |
| 3769 | - if !name.value.is_empty() { | |
| 3770 | - if let Ok(title) = String::from_utf8(name.value.clone()) { | |
| 3771 | - if let Some(client) = self.clients.get_mut(&window) { | |
| 3772 | - client.name = title; | |
| 3773 | - return Ok(()); | |
| 3774 | - } | |
| 3775 | - } | |
| 3776 | - } | |
| 3744 | + if let Some(name) = net_name | |
| 3745 | + && !name.value.is_empty() | |
| 3746 | + && let Ok(title) = String::from_utf8(name.value.clone()) | |
| 3747 | + && let Some(client) = self.clients.get_mut(&window) | |
| 3748 | + { | |
| 3749 | + client.name = title; | |
| 3750 | + return Ok(()); | |
| 3777 | 3751 | } |
| 3778 | 3752 | |
| 3779 | 3753 | let wm_name = self |
| @@ -3788,12 +3762,11 @@ impl WindowManager { | ||
| 3788 | 3762 | )? |
| 3789 | 3763 | .reply()?; |
| 3790 | 3764 | |
| 3791 | - if !wm_name.value.is_empty() { | |
| 3792 | - if let Ok(title) = String::from_utf8(wm_name.value.clone()) { | |
| 3793 | - if let Some(client) = self.clients.get_mut(&window) { | |
| 3794 | - client.name = title; | |
| 3795 | - } | |
| 3796 | - } | |
| 3765 | + if !wm_name.value.is_empty() | |
| 3766 | + && let Ok(title) = String::from_utf8(wm_name.value.clone()) | |
| 3767 | + && let Some(client) = self.clients.get_mut(&window) | |
| 3768 | + { | |
| 3769 | + client.name = title; | |
| 3797 | 3770 | } |
| 3798 | 3771 | |
| 3799 | 3772 | Ok(()) |
| @@ -3805,56 +3778,52 @@ impl WindowManager { | ||
| 3805 | 3778 | .get_property(false, window, AtomEnum::WM_HINTS, AtomEnum::WM_HINTS, 0, 9)? |
| 3806 | 3779 | .reply(); |
| 3807 | 3780 | |
| 3808 | - if let Ok(hints) = hints_reply { | |
| 3809 | - if hints.value.len() >= 4 { | |
| 3810 | - let flags = u32::from_ne_bytes([ | |
| 3811 | - hints.value[0], | |
| 3812 | - hints.value[1], | |
| 3813 | - hints.value[2], | |
| 3814 | - hints.value[3], | |
| 3815 | - ]); | |
| 3816 | - | |
| 3817 | - let selected_window = self | |
| 3818 | - .monitors | |
| 3819 | - .get(self.selected_monitor) | |
| 3820 | - .and_then(|m| m.selected_client); | |
| 3781 | + if let Ok(hints) = hints_reply | |
| 3782 | + && hints.value.len() >= 4 | |
| 3783 | + { | |
| 3784 | + let flags = u32::from_ne_bytes([ | |
| 3785 | + hints.value[0], | |
| 3786 | + hints.value[1], | |
| 3787 | + hints.value[2], | |
| 3788 | + hints.value[3], | |
| 3789 | + ]); | |
| 3790 | + | |
| 3791 | + let selected_window = self | |
| 3792 | + .monitors | |
| 3793 | + .get(self.selected_monitor) | |
| 3794 | + .and_then(|m| m.selected_client); | |
| 3821 | 3795 | |
| 3822 | - if Some(window) == selected_window && (flags & 256) != 0 { | |
| 3823 | - let new_flags = flags & !256; | |
| 3824 | - let mut new_hints = hints.value.clone(); | |
| 3825 | - new_hints[0..4].copy_from_slice(&new_flags.to_ne_bytes()); | |
| 3796 | + if Some(window) == selected_window && (flags & 256) != 0 { | |
| 3797 | + let new_flags = flags & !256; | |
| 3798 | + let mut new_hints = hints.value.clone(); | |
| 3799 | + new_hints[0..4].copy_from_slice(&new_flags.to_ne_bytes()); | |
| 3826 | 3800 | |
| 3827 | - self.connection.change_property( | |
| 3828 | - x11rb::protocol::xproto::PropMode::REPLACE, | |
| 3829 | - window, | |
| 3830 | - AtomEnum::WM_HINTS, | |
| 3831 | - AtomEnum::WM_HINTS, | |
| 3832 | - 32, | |
| 3833 | - 9, | |
| 3834 | - &new_hints, | |
| 3835 | - )?; | |
| 3836 | - } else { | |
| 3837 | - if let Some(client) = self.clients.get_mut(&window) { | |
| 3838 | - client.is_urgent = (flags & 256) != 0; | |
| 3839 | - } | |
| 3840 | - } | |
| 3801 | + self.connection.change_property( | |
| 3802 | + x11rb::protocol::xproto::PropMode::REPLACE, | |
| 3803 | + window, | |
| 3804 | + AtomEnum::WM_HINTS, | |
| 3805 | + AtomEnum::WM_HINTS, | |
| 3806 | + 32, | |
| 3807 | + 9, | |
| 3808 | + &new_hints, | |
| 3809 | + )?; | |
| 3810 | + } else if let Some(client) = self.clients.get_mut(&window) { | |
| 3811 | + client.is_urgent = (flags & 256) != 0; | |
| 3812 | + } | |
| 3841 | 3813 | |
| 3842 | - if hints.value.len() >= 8 && (flags & 1) != 0 { | |
| 3843 | - let input = i32::from_ne_bytes([ | |
| 3844 | - hints.value[4], | |
| 3845 | - hints.value[5], | |
| 3846 | - hints.value[6], | |
| 3847 | - hints.value[7], | |
| 3848 | - ]); | |
| 3814 | + if hints.value.len() >= 8 && (flags & 1) != 0 { | |
| 3815 | + let input = i32::from_ne_bytes([ | |
| 3816 | + hints.value[4], | |
| 3817 | + hints.value[5], | |
| 3818 | + hints.value[6], | |
| 3819 | + hints.value[7], | |
| 3820 | + ]); | |
| 3849 | 3821 | |
| 3850 | - if let Some(client) = self.clients.get_mut(&window) { | |
| 3851 | - client.never_focus = input == 0; | |
| 3852 | - } | |
| 3853 | - } else { | |
| 3854 | - if let Some(client) = self.clients.get_mut(&window) { | |
| 3855 | - client.never_focus = false; | |
| 3856 | - } | |
| 3822 | + if let Some(client) = self.clients.get_mut(&window) { | |
| 3823 | + client.never_focus = input == 0; | |
| 3857 | 3824 | } |
| 3825 | + } else if let Some(client) = self.clients.get_mut(&window) { | |
| 3826 | + client.never_focus = false; | |
| 3858 | 3827 | } |
| 3859 | 3828 | } |
| 3860 | 3829 | |
| @@ -3863,21 +3832,19 @@ impl WindowManager { | ||
| 3863 | 3832 | |
| 3864 | 3833 | fn update_window_type(&mut self, window: Window) -> WmResult<()> { |
| 3865 | 3834 | if let Ok(Some(state_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_state) |
| 3835 | + && state_atom == self.atoms.net_wm_state_fullscreen | |
| 3866 | 3836 | { |
| 3867 | - if state_atom == self.atoms.net_wm_state_fullscreen { | |
| 3868 | - self.set_window_fullscreen(window, true)?; | |
| 3869 | - } | |
| 3837 | + self.set_window_fullscreen(window, true)?; | |
| 3870 | 3838 | } |
| 3871 | 3839 | |
| 3872 | 3840 | if let Ok(Some(type_atom)) = |
| 3873 | 3841 | self.get_window_atom_property(window, self.atoms.net_wm_window_type) |
| 3842 | + && type_atom == self.atoms.net_wm_window_type_dialog | |
| 3874 | 3843 | { |
| 3875 | - if type_atom == self.atoms.net_wm_window_type_dialog { | |
| 3876 | - if let Some(client) = self.clients.get_mut(&window) { | |
| 3877 | - client.is_floating = true; | |
| 3878 | - } | |
| 3879 | - self.floating_windows.insert(window); | |
| 3844 | + if let Some(client) = self.clients.get_mut(&window) { | |
| 3845 | + client.is_floating = true; | |
| 3880 | 3846 | } |
| 3847 | + self.floating_windows.insert(window); | |
| 3881 | 3848 | } |
| 3882 | 3849 | |
| 3883 | 3850 | Ok(()) |
| @@ -4060,11 +4027,11 @@ impl WindowManager { | ||
| 4060 | 4027 | } |
| 4061 | 4028 | |
| 4062 | 4029 | fn attach(&mut self, window: Window, monitor_index: usize) { |
| 4063 | - if let Some(monitor) = self.monitors.get_mut(monitor_index) { | |
| 4064 | - if let Some(client) = self.clients.get_mut(&window) { | |
| 4065 | - client.next = monitor.clients_head; | |
| 4066 | - monitor.clients_head = Some(window); | |
| 4067 | - } | |
| 4030 | + if let Some(monitor) = self.monitors.get_mut(monitor_index) | |
| 4031 | + && let Some(client) = self.clients.get_mut(&window) | |
| 4032 | + { | |
| 4033 | + client.next = monitor.clients_head; | |
| 4034 | + monitor.clients_head = Some(window); | |
| 4068 | 4035 | } |
| 4069 | 4036 | } |
| 4070 | 4037 | |
| @@ -4082,44 +4049,43 @@ impl WindowManager { | ||
| 4082 | 4049 | return; |
| 4083 | 4050 | } |
| 4084 | 4051 | |
| 4085 | - if let Some(insert_after_window) = first_tagged { | |
| 4086 | - if let Some(after_client) = self.clients.get(&insert_after_window) { | |
| 4087 | - let old_next = after_client.next; | |
| 4088 | - if let Some(new_client) = self.clients.get_mut(&window) { | |
| 4089 | - new_client.next = old_next; | |
| 4090 | - } | |
| 4091 | - if let Some(after_client_mut) = self.clients.get_mut(&insert_after_window) { | |
| 4092 | - after_client_mut.next = Some(window); | |
| 4093 | - } | |
| 4052 | + if let Some(insert_after_window) = first_tagged | |
| 4053 | + && let Some(after_client) = self.clients.get(&insert_after_window) | |
| 4054 | + { | |
| 4055 | + let old_next = after_client.next; | |
| 4056 | + if let Some(new_client) = self.clients.get_mut(&window) { | |
| 4057 | + new_client.next = old_next; | |
| 4058 | + } | |
| 4059 | + if let Some(after_client_mut) = self.clients.get_mut(&insert_after_window) { | |
| 4060 | + after_client_mut.next = Some(window); | |
| 4094 | 4061 | } |
| 4095 | 4062 | } |
| 4096 | 4063 | } |
| 4097 | 4064 | |
| 4098 | 4065 | fn detach(&mut self, window: Window) { |
| 4099 | 4066 | let monitor_index = self.clients.get(&window).map(|c| c.monitor_index); |
| 4100 | - if let Some(monitor_index) = monitor_index { | |
| 4101 | - if let Some(monitor) = self.monitors.get_mut(monitor_index) { | |
| 4102 | - if monitor.clients_head == Some(window) { | |
| 4103 | - if let Some(client) = self.clients.get(&window) { | |
| 4104 | - monitor.clients_head = client.next; | |
| 4105 | - } | |
| 4106 | - } else { | |
| 4107 | - let mut current = monitor.clients_head; | |
| 4108 | - while let Some(current_window) = current { | |
| 4109 | - if let Some(current_client) = self.clients.get(¤t_window) { | |
| 4110 | - if current_client.next == Some(window) { | |
| 4111 | - let new_next = self.clients.get(&window).and_then(|c| c.next); | |
| 4112 | - if let Some(current_client_mut) = | |
| 4113 | - self.clients.get_mut(¤t_window) | |
| 4114 | - { | |
| 4115 | - current_client_mut.next = new_next; | |
| 4116 | - } | |
| 4117 | - break; | |
| 4067 | + if let Some(monitor_index) = monitor_index | |
| 4068 | + && let Some(monitor) = self.monitors.get_mut(monitor_index) | |
| 4069 | + { | |
| 4070 | + if monitor.clients_head == Some(window) { | |
| 4071 | + if let Some(client) = self.clients.get(&window) { | |
| 4072 | + monitor.clients_head = client.next; | |
| 4073 | + } | |
| 4074 | + } else { | |
| 4075 | + let mut current = monitor.clients_head; | |
| 4076 | + while let Some(current_window) = current { | |
| 4077 | + if let Some(current_client) = self.clients.get(¤t_window) { | |
| 4078 | + if current_client.next == Some(window) { | |
| 4079 | + let new_next = self.clients.get(&window).and_then(|c| c.next); | |
| 4080 | + if let Some(current_client_mut) = self.clients.get_mut(¤t_window) | |
| 4081 | + { | |
| 4082 | + current_client_mut.next = new_next; | |
| 4118 | 4083 | } |
| 4119 | - current = current_client.next; | |
| 4120 | - } else { | |
| 4121 | 4084 | break; |
| 4122 | 4085 | } |
| 4086 | + current = current_client.next; | |
| 4087 | + } else { | |
| 4088 | + break; | |
| 4123 | 4089 | } |
| 4124 | 4090 | } |
| 4125 | 4091 | } |
| @@ -4127,61 +4093,60 @@ impl WindowManager { | ||
| 4127 | 4093 | } |
| 4128 | 4094 | |
| 4129 | 4095 | fn attach_stack(&mut self, window: Window, monitor_index: usize) { |
| 4130 | - if let Some(monitor) = self.monitors.get_mut(monitor_index) { | |
| 4131 | - if let Some(client) = self.clients.get_mut(&window) { | |
| 4132 | - client.stack_next = monitor.stack_head; | |
| 4133 | - monitor.stack_head = Some(window); | |
| 4134 | - } | |
| 4096 | + if let Some(monitor) = self.monitors.get_mut(monitor_index) | |
| 4097 | + && let Some(client) = self.clients.get_mut(&window) | |
| 4098 | + { | |
| 4099 | + client.stack_next = monitor.stack_head; | |
| 4100 | + monitor.stack_head = Some(window); | |
| 4135 | 4101 | } |
| 4136 | 4102 | } |
| 4137 | 4103 | |
| 4138 | 4104 | fn detach_stack(&mut self, window: Window) { |
| 4139 | 4105 | let monitor_index = self.clients.get(&window).map(|c| c.monitor_index); |
| 4140 | - if let Some(monitor_index) = monitor_index { | |
| 4141 | - if let Some(monitor) = self.monitors.get_mut(monitor_index) { | |
| 4142 | - if monitor.stack_head == Some(window) { | |
| 4143 | - if let Some(client) = self.clients.get(&window) { | |
| 4144 | - monitor.stack_head = client.stack_next; | |
| 4145 | - } | |
| 4146 | - let should_update_selected = monitor.selected_client == Some(window); | |
| 4147 | - let mut new_selected: Option<Window> = None; | |
| 4148 | - if should_update_selected { | |
| 4149 | - let mut stack_current = monitor.stack_head; | |
| 4150 | - while let Some(stack_window) = stack_current { | |
| 4151 | - if let Some(stack_client) = self.clients.get(&stack_window) { | |
| 4152 | - if self.is_window_visible(stack_window) { | |
| 4153 | - new_selected = Some(stack_window); | |
| 4154 | - break; | |
| 4155 | - } | |
| 4156 | - stack_current = stack_client.stack_next; | |
| 4157 | - } else { | |
| 4106 | + if let Some(monitor_index) = monitor_index | |
| 4107 | + && let Some(monitor) = self.monitors.get_mut(monitor_index) | |
| 4108 | + { | |
| 4109 | + if monitor.stack_head == Some(window) { | |
| 4110 | + if let Some(client) = self.clients.get(&window) { | |
| 4111 | + monitor.stack_head = client.stack_next; | |
| 4112 | + } | |
| 4113 | + let should_update_selected = monitor.selected_client == Some(window); | |
| 4114 | + let mut new_selected: Option<Window> = None; | |
| 4115 | + if should_update_selected { | |
| 4116 | + let mut stack_current = monitor.stack_head; | |
| 4117 | + while let Some(stack_window) = stack_current { | |
| 4118 | + if let Some(stack_client) = self.clients.get(&stack_window) { | |
| 4119 | + if self.is_window_visible(stack_window) { | |
| 4120 | + new_selected = Some(stack_window); | |
| 4158 | 4121 | break; |
| 4159 | 4122 | } |
| 4123 | + stack_current = stack_client.stack_next; | |
| 4124 | + } else { | |
| 4125 | + break; | |
| 4160 | 4126 | } |
| 4161 | 4127 | } |
| 4162 | - if should_update_selected { | |
| 4163 | - if let Some(monitor) = self.monitors.get_mut(monitor_index) { | |
| 4164 | - monitor.selected_client = new_selected; | |
| 4165 | - } | |
| 4166 | - } | |
| 4167 | - } else { | |
| 4168 | - let mut current = monitor.stack_head; | |
| 4169 | - while let Some(current_window) = current { | |
| 4170 | - if let Some(current_client) = self.clients.get(¤t_window) { | |
| 4171 | - if current_client.stack_next == Some(window) { | |
| 4172 | - let new_stack_next = | |
| 4173 | - self.clients.get(&window).and_then(|c| c.stack_next); | |
| 4174 | - if let Some(current_client_mut) = | |
| 4175 | - self.clients.get_mut(¤t_window) | |
| 4176 | - { | |
| 4177 | - current_client_mut.stack_next = new_stack_next; | |
| 4178 | - } | |
| 4179 | - break; | |
| 4128 | + } | |
| 4129 | + if should_update_selected | |
| 4130 | + && let Some(monitor) = self.monitors.get_mut(monitor_index) | |
| 4131 | + { | |
| 4132 | + monitor.selected_client = new_selected; | |
| 4133 | + } | |
| 4134 | + } else { | |
| 4135 | + let mut current = monitor.stack_head; | |
| 4136 | + while let Some(current_window) = current { | |
| 4137 | + if let Some(current_client) = self.clients.get(¤t_window) { | |
| 4138 | + if current_client.stack_next == Some(window) { | |
| 4139 | + let new_stack_next = | |
| 4140 | + self.clients.get(&window).and_then(|c| c.stack_next); | |
| 4141 | + if let Some(current_client_mut) = self.clients.get_mut(¤t_window) | |
| 4142 | + { | |
| 4143 | + current_client_mut.stack_next = new_stack_next; | |
| 4180 | 4144 | } |
| 4181 | - current = current_client.stack_next; | |
| 4182 | - } else { | |
| 4183 | 4145 | break; |
| 4184 | 4146 | } |
| 4147 | + current = current_client.stack_next; | |
| 4148 | + } else { | |
| 4149 | + break; | |
| 4185 | 4150 | } |
| 4186 | 4151 | } |
| 4187 | 4152 | } |