tony / oxwm

Fixed transiet dialog handling for Firefox, Brave, and Discord. Removed geomtric caching in favor of using client struct as the source of truth. Browse files
tonybtw committed 2025-12-10 parent bc6b4cb commit d7dbcfd89e1b8ac5827b19c6b7b51447f9c4f21c
Showing 1 changed file with 313 additions and 528 deletions. UnifiedSplit
+313 −528 src/window_manager.rs Large diff collapsed, click to expand
@@ -17,14 +17,6 @@ use x11rb::protocol::Event;
17 use x11rb::protocol::xproto::*; 17 use x11rb::protocol::xproto::*;
18 use x11rb::rust_connection::RustConnection; 18 use x11rb::rust_connection::RustConnection;
19 19
20 -#[derive(Debug, Clone, Copy)]
21 -pub struct CachedGeometry {
22 - pub x_position: i16,
23 - pub y_position: i16,
24 - pub width: u16,
25 - pub height: u16,
26 - pub border_width: u16,
27 -}
28 20
29 pub fn tag_mask(tag: usize) -> TagMask { 21 pub fn tag_mask(tag: usize) -> TagMask {
30 1 << tag 22 1 << tag
@@ -43,9 +35,6 @@ struct AtomCache {
43 wm_name: Atom, 35 wm_name: Atom,
44 net_wm_name: Atom, 36 net_wm_name: Atom,
45 utf8_string: Atom, 37 utf8_string: Atom,
46 - wm_normal_hints: Atom,
47 - wm_hints: Atom,
48 - wm_transient_for: Atom,
49 net_active_window: Atom, 38 net_active_window: Atom,
50 } 39 }
51 40
@@ -96,9 +85,6 @@ impl AtomCache {
96 let wm_name = AtomEnum::WM_NAME.into(); 85 let wm_name = AtomEnum::WM_NAME.into();
97 let net_wm_name = connection.intern_atom(false, b"_NET_WM_NAME")?.reply()?.atom; 86 let net_wm_name = connection.intern_atom(false, b"_NET_WM_NAME")?.reply()?.atom;
98 let utf8_string = connection.intern_atom(false, b"UTF8_STRING")?.reply()?.atom; 87 let utf8_string = connection.intern_atom(false, b"UTF8_STRING")?.reply()?.atom;
99 - let wm_normal_hints = AtomEnum::WM_NORMAL_HINTS.into();
100 - let wm_hints = AtomEnum::WM_HINTS.into();
101 - let wm_transient_for = AtomEnum::WM_TRANSIENT_FOR.into();
102 let net_active_window = connection.intern_atom(false, b"_NET_ACTIVE_WINDOW")?.reply()?.atom; 88 let net_active_window = connection.intern_atom(false, b"_NET_ACTIVE_WINDOW")?.reply()?.atom;
103 89
104 Ok(Self { 90 Ok(Self {
@@ -114,9 +100,6 @@ impl AtomCache {
114 wm_name, 100 wm_name,
115 net_wm_name, 101 net_wm_name,
116 utf8_string, 102 utf8_string,
117 - wm_normal_hints,
118 - wm_hints,
119 - wm_transient_for,
120 net_active_window, 103 net_active_window,
121 }) 104 })
122 } 105 }
@@ -131,7 +114,6 @@ pub struct WindowManager {
131 windows: Vec<Window>, 114 windows: Vec<Window>,
132 clients: HashMap<Window, Client>, 115 clients: HashMap<Window, Client>,
133 layout: LayoutBox, 116 layout: LayoutBox,
134 - window_geometry_cache: HashMap<Window, CachedGeometry>,
135 gaps_enabled: bool, 117 gaps_enabled: bool,
136 floating_windows: HashSet<Window>, 118 floating_windows: HashSet<Window>,
137 fullscreen_windows: HashSet<Window>, 119 fullscreen_windows: HashSet<Window>,
@@ -289,7 +271,6 @@ impl WindowManager {
289 windows: Vec::new(), 271 windows: Vec::new(),
290 clients: HashMap::new(), 272 clients: HashMap::new(),
291 layout: Box::new(TilingLayout), 273 layout: Box::new(TilingLayout),
292 - window_geometry_cache: HashMap::new(),
293 gaps_enabled, 274 gaps_enabled,
294 floating_windows: HashSet::new(), 275 floating_windows: HashSet::new(),
295 fullscreen_windows: HashSet::new(), 276 fullscreen_windows: HashSet::new(),
@@ -1040,14 +1021,36 @@ impl WindowManager {
1040 let has_no_layout = self.layout.name() == LayoutType::Normie.as_str(); 1021 let has_no_layout = self.layout.name() == LayoutType::Normie.as_str();
1041 1022
1042 if (has_no_layout || is_floating) && !is_fullscreen { 1023 if (has_no_layout || is_floating) && !is_fullscreen {
1043 - self.connection.configure_window( 1024 + let (x, y, w, h, changed) = self.apply_size_hints(
1044 window, 1025 window,
1045 - &ConfigureWindowAux::new() 1026 + client.x_position as i32,
1046 - .x(client.x_position as i32) 1027 + client.y_position as i32,
1047 - .y(client.y_position as i32) 1028 + client.width as i32,
1048 - .width(client.width as u32) 1029 + client.height as i32,
1049 - .height(client.height as u32), 1030 + );
1050 - )?; 1031 + if changed {
1032 + if let Some(c) = self.clients.get_mut(&window) {
1033 + c.old_x_position = c.x_position;
1034 + c.old_y_position = c.y_position;
1035 + c.old_width = c.width;
1036 + c.old_height = c.height;
1037 + c.x_position = x as i16;
1038 + c.y_position = y as i16;
1039 + c.width = w as u16;
1040 + c.height = h as u16;
1041 + }
1042 + self.connection.configure_window(
1043 + window,
1044 + &ConfigureWindowAux::new()
1045 + .x(x)
1046 + .y(y)
1047 + .width(w as u32)
1048 + .height(h as u32)
1049 + .border_width(self.config.border_width),
1050 + )?;
1051 + self.send_configure_notify(window)?;
1052 + self.connection.flush()?;
1053 + }
1051 } 1054 }
1052 1055
1053 self.showhide(client.stack_next)?; 1056 self.showhide(client.stack_next)?;
@@ -1369,30 +1372,6 @@ impl WindowManager {
1369 Ok(()) 1372 Ok(())
1370 } 1373 }
1371 1374
1372 - fn get_window_state(&self, window: Window) -> WmResult<i32> {
1373 - let reply = self.connection.get_property(
1374 - false,
1375 - window,
1376 - self.atoms.wm_state,
1377 - self.atoms.wm_state,
1378 - 0,
1379 - 2,
1380 - )?.reply();
1381 -
1382 - match reply {
1383 - Ok(prop) if !prop.value.is_empty() && prop.value.len() >= 4 => {
1384 - let state = u32::from_ne_bytes([
1385 - prop.value[0],
1386 - prop.value[1],
1387 - prop.value[2],
1388 - prop.value[3],
1389 - ]);
1390 - Ok(state as i32)
1391 - }
1392 - _ => Ok(-1),
1393 - }
1394 - }
1395 -
1396 fn get_window_atom_property(&self, window: Window, property: Atom) -> WmResult<Option<Atom>> { 1375 fn get_window_atom_property(&self, window: Window, property: Atom) -> WmResult<Option<Atom>> {
1397 let reply = self.connection.get_property( 1376 let reply = self.connection.get_property(
1398 false, 1377 false,
@@ -1417,25 +1396,6 @@ impl WindowManager {
1417 } 1396 }
1418 } 1397 }
1419 1398
1420 - fn get_window_text_property(&self, window: Window, atom: Atom) -> WmResult<Option<String>> {
1421 - let reply = self.connection.get_property(
1422 - false,
1423 - window,
1424 - atom,
1425 - AtomEnum::ANY,
1426 - 0,
1427 - 1024,
1428 - )?.reply();
1429 -
1430 - match reply {
1431 - Ok(prop) if !prop.value.is_empty() => {
1432 - let text = String::from_utf8_lossy(&prop.value).to_string();
1433 - Ok(Some(text.trim_end_matches('\0').to_string()))
1434 - }
1435 - _ => Ok(None),
1436 - }
1437 - }
1438 -
1439 fn fullscreen(&mut self) -> WmResult<()> { 1399 fn fullscreen(&mut self) -> WmResult<()> {
1440 if self.show_bar { 1400 if self.show_bar {
1441 let windows: Vec<Window> = self.windows.iter() 1401 let windows: Vec<Window> = self.windows.iter()
@@ -1511,7 +1471,7 @@ impl WindowManager {
1511 if let Some(&(x, y, width, height, border_width)) = self.floating_geometry_before_fullscreen.get(&window) { 1471 if let Some(&(x, y, width, height, border_width)) = self.floating_geometry_before_fullscreen.get(&window) {
1512 self.connection.configure_window( 1472 self.connection.configure_window(
1513 window, 1473 window,
1514 - &x11rb::protocol::xproto::ConfigureWindowAux::new() 1474 + &ConfigureWindowAux::new()
1515 .x(x as i32) 1475 .x(x as i32)
1516 .y(y as i32) 1476 .y(y as i32)
1517 .width(width as u32) 1477 .width(width as u32)
@@ -1519,13 +1479,13 @@ impl WindowManager {
1519 .border_width(border_width as u32), 1479 .border_width(border_width as u32),
1520 )?; 1480 )?;
1521 1481
1522 - self.update_geometry_cache(window, CachedGeometry { 1482 + if let Some(c) = self.clients.get_mut(&window) {
1523 - x_position: x, 1483 + c.x_position = x;
1524 - y_position: y, 1484 + c.y_position = y;
1525 - width, 1485 + c.width = width;
1526 - height, 1486 + c.height = height;
1527 - border_width, 1487 + c.border_width = border_width;
1528 - }); 1488 + }
1529 1489
1530 self.floating_geometry_before_fullscreen.remove(&window); 1490 self.floating_geometry_before_fullscreen.remove(&window);
1531 } 1491 }
@@ -1673,79 +1633,6 @@ impl WindowManager {
1673 }) 1633 })
1674 } 1634 }
1675 1635
1676 - fn has_user_set_position(&self, window: Window) -> bool {
1677 - const US_POSITION: u32 = 1 << 0;
1678 - const P_POSITION: u32 = 1 << 2;
1679 -
1680 - let size_hints = self.connection
1681 - .get_property(
1682 - false,
1683 - window,
1684 - x11rb::protocol::xproto::AtomEnum::WM_NORMAL_HINTS,
1685 - x11rb::protocol::xproto::AtomEnum::WM_SIZE_HINTS,
1686 - 0,
1687 - 18,
1688 - )
1689 - .ok()
1690 - .and_then(|cookie| cookie.reply().ok());
1691 -
1692 - if let Some(hints) = size_hints {
1693 - if hints.value.len() >= 4 {
1694 - let flags = u32::from_ne_bytes([
1695 - hints.value[0],
1696 - hints.value[1],
1697 - hints.value[2],
1698 - hints.value[3],
1699 - ]);
1700 - return (flags & US_POSITION) != 0 || (flags & P_POSITION) != 0;
1701 - }
1702 - }
1703 - false
1704 - }
1705 -
1706 - fn is_dialog_window(&self, window: Window) -> bool {
1707 - let window_type_property = self.connection
1708 - .get_property(
1709 - false,
1710 - window,
1711 - self.atoms.net_wm_window_type,
1712 - AtomEnum::ATOM,
1713 - 0,
1714 - 32,
1715 - )
1716 - .ok()
1717 - .and_then(|cookie| cookie.reply().ok());
1718 -
1719 - if let Some(reply) = window_type_property {
1720 - let atoms: Vec<Atom> = reply
1721 - .value
1722 - .chunks_exact(4)
1723 - .map(|chunk| u32::from_ne_bytes([chunk[0], chunk[1], chunk[2], chunk[3]]))
1724 - .collect();
1725 -
1726 - let is_dialog = atoms.contains(&self.atoms.net_wm_window_type_dialog);
1727 - is_dialog
1728 - } else {
1729 - false
1730 - }
1731 - }
1732 -
1733 - fn get_window_class(&self, window: Window) -> Option<String> {
1734 - self.connection
1735 - .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024)
1736 - .ok()
1737 - .and_then(|cookie| cookie.reply().ok())
1738 - .and_then(|reply| {
1739 - if reply.value.is_empty() {
1740 - None
1741 - } else {
1742 - std::str::from_utf8(&reply.value).ok().map(|s| {
1743 - s.split('\0').nth(1).unwrap_or(s.split('\0').next().unwrap_or("")).to_string()
1744 - })
1745 - }
1746 - })
1747 - }
1748 -
1749 fn get_window_class_instance(&self, window: Window) -> (String, String) { 1636 fn get_window_class_instance(&self, window: Window) -> (String, String) {
1750 let reply = self.connection 1637 let reply = self.connection
1751 .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024) 1638 .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024)
@@ -1819,133 +1706,81 @@ impl WindowManager {
1819 1706
1820 fn manage_window(&mut self, window: Window) -> WmResult<()> { 1707 fn manage_window(&mut self, window: Window) -> WmResult<()> {
1821 let geometry = self.connection.get_geometry(window)?.reply()?; 1708 let geometry = self.connection.get_geometry(window)?.reply()?;
1822 - let mut window_x = geometry.x as i32;
1823 - let mut window_y = geometry.y as i32;
1824 - let mut window_width = geometry.width as u32;
1825 - let mut window_height = geometry.height as u32;
1826 let border_width = self.config.border_width; 1709 let border_width = self.config.border_width;
1827 1710
1828 - self.update_window_title(window)?;
1829 -
1830 let transient_parent = self.get_transient_parent(window); 1711 let transient_parent = self.get_transient_parent(window);
1831 let is_transient = transient_parent.is_some(); 1712 let is_transient = transient_parent.is_some();
1832 1713
1833 - let parent_geometry = if let Some(parent) = transient_parent { 1714 + let (monitor_index, tags) = if let Some(parent) = transient_parent {
1834 - self.connection.get_geometry(parent) 1715 + if let Some(parent_client) = self.clients.get(&parent) {
1835 - .ok() 1716 + (parent_client.monitor_index, parent_client.tags)
1836 - .and_then(|cookie| cookie.reply().ok())
1837 - } else {
1838 - None
1839 - };
1840 -
1841 - let (initial_tags, initial_monitor_index) = if let Some(parent) = transient_parent {
1842 - if let Some(ref parent_geom) = parent_geometry {
1843 - let parent_mon_idx = self.get_monitor_for_rect(
1844 - parent_geom.x as i32,
1845 - parent_geom.y as i32,
1846 - parent_geom.width as i32,
1847 - parent_geom.height as i32
1848 - );
1849 -
1850 - let tags = if let Some(parent_client) = self.clients.get(&parent) {
1851 - parent_client.tags
1852 - } else {
1853 - self.monitors
1854 - .get(parent_mon_idx)
1855 - .map(|m| m.tagset[m.selected_tags_index])
1856 - .unwrap_or(tag_mask(0))
1857 - };
1858 -
1859 - (tags, parent_mon_idx)
1860 } else { 1717 } else {
1861 - let tags = self.monitors 1718 + let tags = self.monitors.get(self.selected_monitor)
1862 - .get(self.selected_monitor)
1863 .map(|m| m.tagset[m.selected_tags_index]) 1719 .map(|m| m.tagset[m.selected_tags_index])
1864 .unwrap_or(tag_mask(0)); 1720 .unwrap_or(tag_mask(0));
1865 - (tags, self.selected_monitor) 1721 + (self.selected_monitor, tags)
1866 } 1722 }
1867 } else { 1723 } else {
1868 - let tags = self.monitors 1724 + let tags = self.monitors.get(self.selected_monitor)
1869 - .get(self.selected_monitor)
1870 .map(|m| m.tagset[m.selected_tags_index]) 1725 .map(|m| m.tagset[m.selected_tags_index])
1871 .unwrap_or(tag_mask(0)); 1726 .unwrap_or(tag_mask(0));
1872 - (tags, self.selected_monitor) 1727 + (self.selected_monitor, tags)
1873 }; 1728 };
1874 1729
1875 - let mut client = Client::new(window, initial_monitor_index, initial_tags); 1730 + let mut client = Client::new(window, monitor_index, tags);
1876 - client.old_border_width = border_width as u16; 1731 + client.x_position = geometry.x;
1732 + client.y_position = geometry.y;
1733 + client.width = geometry.width;
1734 + client.height = geometry.height;
1735 + client.old_x_position = geometry.x;
1736 + client.old_y_position = geometry.y;
1737 + client.old_width = geometry.width;
1738 + client.old_height = geometry.height;
1739 + client.old_border_width = geometry.border_width;
1740 + client.border_width = border_width as u16;
1877 1741
1878 self.clients.insert(window, client); 1742 self.clients.insert(window, client);
1743 + self.update_window_title(window)?;
1879 1744
1880 if !is_transient { 1745 if !is_transient {
1881 self.apply_rules(window)?; 1746 self.apply_rules(window)?;
1882 } 1747 }
1883 1748
1884 - let final_monitor_index = self.clients.get(&window).map(|c| c.monitor_index).unwrap_or(initial_monitor_index); 1749 + let client_monitor = self.clients.get(&window).map(|c| c.monitor_index).unwrap_or(monitor_index);
1885 - let final_monitor = self.monitors.get(final_monitor_index).cloned().unwrap_or_else(|| { 1750 + let monitor = &self.monitors[client_monitor];
1886 - self.monitors.get(self.selected_monitor).cloned().unwrap_or_else(|| {
1887 - Monitor::new(0, 0, self.screen.width_in_pixels as u32, self.screen.height_in_pixels as u32)
1888 - })
1889 - });
1890 -
1891 - let total_width = window_width as i32 + 2 * border_width as i32;
1892 - let total_height = window_height as i32 + 2 * border_width as i32;
1893 1751
1894 - self.update_window_type(window)?; 1752 + let mut x = self.clients.get(&window).map(|c| c.x_position as i32).unwrap_or(0);
1895 - 1753 + let mut y = self.clients.get(&window).map(|c| c.y_position as i32).unwrap_or(0);
1896 - let has_explicit_position = self.has_user_set_position(window); 1754 + let w = self.clients.get(&window).map(|c| c.width as i32).unwrap_or(1);
1897 - let is_dialog = self.is_dialog_window(window); 1755 + let h = self.clients.get(&window).map(|c| c.height as i32).unwrap_or(1);
1898 - let position_is_origin = window_x == 0 && window_y == 0; 1756 + let bw = border_width as i32;
1899 - let should_center = (is_transient || is_dialog) && (!has_explicit_position || position_is_origin);
1900 -
1901 - if should_center {
1902 - if transient_parent.is_some() {
1903 - if let Some(ref parent_geom) = parent_geometry {
1904 - let parent_center_x = parent_geom.x as i32 + parent_geom.width as i32 / 2;
1905 - let parent_center_y = parent_geom.y as i32 + parent_geom.height as i32 / 2;
1906 - window_x = parent_center_x - window_width as i32 / 2;
1907 - window_y = parent_center_y - window_height as i32 / 2;
1908 - } else {
1909 - window_x = final_monitor.window_area_x + final_monitor.window_area_width / 2 - window_width as i32 / 2;
1910 - window_y = final_monitor.window_area_y + final_monitor.window_area_height / 2 - window_height as i32 / 2;
1911 - }
1912 - } else {
1913 - window_x = final_monitor.window_area_x + final_monitor.window_area_width / 2 - window_width as i32 / 2;
1914 - window_y = final_monitor.window_area_y + final_monitor.window_area_height / 2 - window_height as i32 / 2;
1915 - }
1916 - }
1917 1757
1918 - if window_x + total_width > final_monitor.window_area_x + final_monitor.window_area_width { 1758 + if x + w + 2 * bw > monitor.window_area_x + monitor.window_area_width {
1919 - window_x = final_monitor.window_area_x + final_monitor.window_area_width - total_width; 1759 + x = monitor.window_area_x + monitor.window_area_width - w - 2 * bw;
1920 } 1760 }
1921 - if window_y + total_height > final_monitor.window_area_y + final_monitor.window_area_height { 1761 + if y + h + 2 * bw > monitor.window_area_y + monitor.window_area_height {
1922 - window_y = final_monitor.window_area_y + final_monitor.window_area_height - total_height; 1762 + y = monitor.window_area_y + monitor.window_area_height - h - 2 * bw;
1923 } 1763 }
1924 - window_x = window_x.max(final_monitor.window_area_x); 1764 + x = x.max(monitor.window_area_x);
1925 - window_y = window_y.max(final_monitor.window_area_y); 1765 + y = y.max(monitor.window_area_y);
1926 1766
1927 - if let Some(client) = self.clients.get_mut(&window) { 1767 + if let Some(c) = self.clients.get_mut(&window) {
1928 - client.x_position = window_x as i16; 1768 + c.x_position = x as i16;
1929 - client.y_position = window_y as i16; 1769 + c.y_position = y as i16;
1930 - client.width = window_width as u16;
1931 - client.height = window_height as u16;
1932 - client.old_x_position = window_x as i16;
1933 - client.old_y_position = window_y as i16;
1934 - client.old_width = window_width as u16;
1935 - client.old_height = window_height as u16;
1936 - client.border_width = border_width as u16;
1937 } 1770 }
1938 1771
1939 self.connection.configure_window( 1772 self.connection.configure_window(
1940 window, 1773 window,
1941 - &ConfigureWindowAux::new() 1774 + &ConfigureWindowAux::new().border_width(border_width),
1942 - .x(window_x) 1775 + )?;
1943 - .y(window_y) 1776 + self.connection.change_window_attributes(
1944 - .border_width(border_width), 1777 + window,
1778 + &ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused),
1945 )?; 1779 )?;
1946 -
1947 self.send_configure_notify(window)?; 1780 self.send_configure_notify(window)?;
1781 + self.update_window_type(window)?;
1948 self.update_size_hints(window)?; 1782 self.update_size_hints(window)?;
1783 + self.update_window_hints(window)?;
1949 1784
1950 self.connection.change_window_attributes( 1785 self.connection.change_window_attributes(
1951 window, 1786 window,
@@ -1955,17 +1790,14 @@ impl WindowManager {
1955 )?; 1790 )?;
1956 1791
1957 let is_fixed = self.clients.get(&window).map(|c| c.is_fixed).unwrap_or(false); 1792 let is_fixed = self.clients.get(&window).map(|c| c.is_fixed).unwrap_or(false);
1958 - let already_floating = self.clients.get(&window).map(|c| c.is_floating).unwrap_or(false); 1793 + if let Some(c) = self.clients.get_mut(&window) {
1959 - 1794 + if !c.is_floating {
1960 - if !already_floating { 1795 + c.is_floating = is_transient || is_fixed;
1961 - if let Some(client) = self.clients.get_mut(&window) { 1796 + c.old_state = c.is_floating;
1962 - client.is_floating = is_transient || is_fixed;
1963 - client.old_state = client.is_floating;
1964 } 1797 }
1965 } 1798 }
1966 1799
1967 - let is_floating = self.clients.get(&window).map(|c| c.is_floating).unwrap_or(false); 1800 + if self.clients.get(&window).map(|c| c.is_floating).unwrap_or(false) {
1968 - if is_floating {
1969 self.floating_windows.insert(window); 1801 self.floating_windows.insert(window);
1970 self.connection.configure_window( 1802 self.connection.configure_window(
1971 window, 1803 window,
@@ -1973,35 +1805,33 @@ impl WindowManager {
1973 )?; 1805 )?;
1974 } 1806 }
1975 1807
1976 - self.attach_aside(window, final_monitor_index); 1808 + self.attach_aside(window, client_monitor);
1977 - self.attach_stack(window, final_monitor_index); 1809 + self.attach_stack(window, client_monitor);
1978 self.windows.push(window); 1810 self.windows.push(window);
1979 1811
1980 - let off_screen_x = window_x + 2 * self.screen.width_in_pixels as i32; 1812 + let off_screen_x = x + 2 * self.screen.width_in_pixels as i32;
1981 self.connection.configure_window( 1813 self.connection.configure_window(
1982 window, 1814 window,
1983 &ConfigureWindowAux::new() 1815 &ConfigureWindowAux::new()
1984 .x(off_screen_x) 1816 .x(off_screen_x)
1985 - .y(window_y) 1817 + .y(y)
1986 - .width(window_width) 1818 + .width(w as u32)
1987 - .height(window_height), 1819 + .height(h as u32),
1988 )?; 1820 )?;
1989 1821
1990 self.set_wm_state(window, 1)?; 1822 self.set_wm_state(window, 1)?;
1991 1823
1992 - let final_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(initial_tags); 1824 + let final_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(tags);
1993 - if let Err(error) = self.save_client_tag(window, final_tags) { 1825 + let _ = self.save_client_tag(window, final_tags);
1994 - eprintln!("Failed to save client tag for new window: {:?}", error);
1995 - }
1996 1826
1997 - if final_monitor_index == self.selected_monitor { 1827 + if client_monitor == self.selected_monitor {
1998 - if let Some(old_selected) = self.monitors.get(self.selected_monitor).and_then(|m| m.selected_client) { 1828 + if let Some(old_sel) = self.monitors.get(self.selected_monitor).and_then(|m| m.selected_client) {
1999 - self.unfocus(old_selected)?; 1829 + self.unfocus(old_sel)?;
2000 } 1830 }
2001 } 1831 }
2002 1832
2003 - if let Some(monitor) = self.monitors.get_mut(final_monitor_index) { 1833 + if let Some(m) = self.monitors.get_mut(client_monitor) {
2004 - monitor.selected_client = Some(window); 1834 + m.selected_client = Some(window);
2005 } 1835 }
2006 1836
2007 self.apply_layout()?; 1837 self.apply_layout()?;
@@ -2647,9 +2477,11 @@ impl WindowManager {
2647 .unwrap_or(false); 2477 .unwrap_or(false);
2648 2478
2649 if should_resize { 2479 if should_resize {
2650 - if let Some(client) = self.clients.get(&window) { 2480 + if let Some(client) = self.clients.get(&window).cloned() {
2651 - let (hint_width, hint_height) = self.apply_size_hints( 2481 + let (_, _, hint_width, hint_height, _) = self.apply_size_hints(
2652 - client, 2482 + window,
2483 + client.x_position as i32,
2484 + client.y_position as i32,
2653 new_width as i32, 2485 new_width as i32,
2654 new_height as i32, 2486 new_height as i32,
2655 ); 2487 );
@@ -2787,7 +2619,7 @@ impl WindowManager {
2787 } 2619 }
2788 } 2620 }
2789 Event::PropertyNotify(event) => { 2621 Event::PropertyNotify(event) => {
2790 - if event.state == x11rb::protocol::xproto::Property::DELETE { 2622 + if event.state == Property::DELETE {
2791 return Ok(None); 2623 return Ok(None);
2792 } 2624 }
2793 2625
@@ -2796,16 +2628,12 @@ impl WindowManager {
2796 } 2628 }
2797 2629
2798 if event.atom == AtomEnum::WM_TRANSIENT_FOR.into() { 2630 if event.atom == AtomEnum::WM_TRANSIENT_FOR.into() {
2799 - let is_floating = self.clients 2631 + let is_floating = self.clients.get(&event.window).map(|c| c.is_floating).unwrap_or(false);
2800 - .get(&event.window)
2801 - .map(|c| c.is_floating)
2802 - .unwrap_or(false);
2803 -
2804 if !is_floating { 2632 if !is_floating {
2805 - if let Some(transient_parent) = self.get_transient_parent(event.window) { 2633 + if let Some(parent) = self.get_transient_parent(event.window) {
2806 - if self.clients.contains_key(&transient_parent) { 2634 + if self.clients.contains_key(&parent) {
2807 - if let Some(client) = self.clients.get_mut(&event.window) { 2635 + if let Some(c) = self.clients.get_mut(&event.window) {
2808 - client.is_floating = true; 2636 + c.is_floating = true;
2809 } 2637 }
2810 self.floating_windows.insert(event.window); 2638 self.floating_windows.insert(event.window);
2811 self.apply_layout()?; 2639 self.apply_layout()?;
@@ -2813,8 +2641,8 @@ impl WindowManager {
2813 } 2641 }
2814 } 2642 }
2815 } else if event.atom == AtomEnum::WM_NORMAL_HINTS.into() { 2643 } else if event.atom == AtomEnum::WM_NORMAL_HINTS.into() {
2816 - if let Some(client) = self.clients.get_mut(&event.window) { 2644 + if let Some(c) = self.clients.get_mut(&event.window) {
2817 - client.hints_valid = false; 2645 + c.hints_valid = false;
2818 } 2646 }
2819 } else if event.atom == AtomEnum::WM_HINTS.into() { 2647 } else if event.atom == AtomEnum::WM_HINTS.into() {
2820 self.update_window_hints(event.window)?; 2648 self.update_window_hints(event.window)?;
@@ -2830,77 +2658,6 @@ impl WindowManager {
2830 2658
2831 if event.atom == self.atoms.net_wm_window_type { 2659 if event.atom == self.atoms.net_wm_window_type {
2832 self.update_window_type(event.window)?; 2660 self.update_window_type(event.window)?;
2833 -
2834 - if self.is_dialog_window(event.window) {
2835 -
2836 - let client_info = self.clients.get(&event.window).map(|c| {
2837 - (c.width, c.height, c.border_width, c.monitor_index, c.is_floating)
2838 - });
2839 -
2840 - if let Some((width, height, border_width, current_monitor_index, is_floating)) = client_info {
2841 - if !is_floating {
2842 - if let Some(client) = self.clients.get_mut(&event.window) {
2843 - client.is_floating = true;
2844 - }
2845 - self.floating_windows.insert(event.window);
2846 - }
2847 -
2848 - let transient_parent = self.get_transient_parent(event.window);
2849 - let target_monitor_index = if let Some(parent) = transient_parent {
2850 - if let Ok(parent_geom_reply) = self.connection.get_geometry(parent) {
2851 - if let Ok(parent_geom) = parent_geom_reply.reply() {
2852 - self.get_monitor_for_rect(
2853 - parent_geom.x as i32,
2854 - parent_geom.y as i32,
2855 - parent_geom.width as i32,
2856 - parent_geom.height as i32,
2857 - )
2858 - } else {
2859 - current_monitor_index
2860 - }
2861 - } else {
2862 - current_monitor_index
2863 - }
2864 - } else {
2865 - current_monitor_index
2866 - };
2867 -
2868 - let monitor = &self.monitors[target_monitor_index];
2869 - let window_width = width as i32;
2870 - let window_height = height as i32;
2871 -
2872 - let mut window_x = monitor.window_area_x + monitor.window_area_width / 2 - window_width / 2;
2873 - let mut window_y = monitor.window_area_y + monitor.window_area_height / 2 - window_height / 2;
2874 -
2875 - let total_width = window_width + 2 * border_width as i32;
2876 - let total_height = window_height + 2 * border_width as i32;
2877 -
2878 - if window_x + total_width > monitor.window_area_x + monitor.window_area_width {
2879 - window_x = monitor.window_area_x + monitor.window_area_width - total_width;
2880 - }
2881 - if window_y + total_height > monitor.window_area_y + monitor.window_area_height {
2882 - window_y = monitor.window_area_y + monitor.window_area_height - total_height;
2883 - }
2884 - window_x = window_x.max(monitor.window_area_x);
2885 - window_y = window_y.max(monitor.window_area_y);
2886 -
2887 - if let Some(client) = self.clients.get_mut(&event.window) {
2888 - client.x_position = window_x as i16;
2889 - client.y_position = window_y as i16;
2890 - client.monitor_index = target_monitor_index;
2891 - }
2892 -
2893 - self.connection.configure_window(
2894 - event.window,
2895 - &ConfigureWindowAux::new()
2896 - .x(window_x)
2897 - .y(window_y)
2898 - )?.check()?;
2899 -
2900 - self.connection.flush()?;
2901 - self.apply_layout()?;
2902 - }
2903 - }
2904 } 2661 }
2905 } 2662 }
2906 Event::EnterNotify(event) => { 2663 Event::EnterNotify(event) => {
@@ -3115,117 +2872,109 @@ impl WindowManager {
3115 } 2872 }
3116 } 2873 }
3117 Event::ConfigureRequest(event) => { 2874 Event::ConfigureRequest(event) => {
3118 - if self.windows.contains(&event.window) { 2875 + if let Some(client) = self.clients.get(&event.window) {
3119 - let monitor_index = self.clients.get(&event.window) 2876 + let monitor = &self.monitors[client.monitor_index];
3120 - .map(|c| c.monitor_index) 2877 + let is_floating = client.is_floating;
3121 - .unwrap_or(self.selected_monitor); 2878 + let has_layout = self.layout.name() != "normie";
3122 - let monitor = &self.monitors[monitor_index]; 2879 +
3123 - let is_floating = self.floating_windows.contains(&event.window); 2880 + if event.value_mask.contains(ConfigWindow::BORDER_WIDTH) {
3124 - let is_tiling_layout = self.layout.name() != "normie"; 2881 + if let Some(c) = self.clients.get_mut(&event.window) {
3125 - 2882 + c.border_width = event.border_width;
3126 - if is_floating || !is_tiling_layout { 2883 + }
3127 - let cached_geom = self.window_geometry_cache.get(&event.window); 2884 + } else if is_floating || !has_layout {
3128 - let border_width = self.config.border_width as u16; 2885 + let mut x = client.x_position as i32;
3129 - let value_mask = event.value_mask; 2886 + let mut y = client.y_position as i32;
3130 - 2887 + let mut w = client.width as i32;
3131 - let final_x = if value_mask.contains(ConfigWindow::X) { 2888 + let mut h = client.height as i32;
3132 - let mut x = event.x as i32; 2889 +
3133 - x = x.max(monitor.screen_x); 2890 + if event.value_mask.contains(ConfigWindow::X) {
3134 - if x + event.width as i32 + 2 * border_width as i32 > monitor.screen_x + monitor.screen_width as i32 { 2891 + if let Some(c) = self.clients.get_mut(&event.window) {
3135 - x = monitor.screen_x + monitor.screen_width as i32 - event.width as i32 - 2 * border_width as i32; 2892 + c.old_x_position = c.x_position;
3136 } 2893 }
3137 - x as i16 2894 + x = monitor.screen_x + event.x as i32;
3138 - } else { 2895 + }
3139 - cached_geom.map(|g| g.x_position).unwrap_or(0) 2896 + if event.value_mask.contains(ConfigWindow::Y) {
3140 - }; 2897 + if let Some(c) = self.clients.get_mut(&event.window) {
3141 - 2898 + c.old_y_position = c.y_position;
3142 - let final_y = if value_mask.contains(ConfigWindow::Y) {
3143 - let mut y = event.y as i32;
3144 - y = y.max(monitor.screen_y);
3145 - if y + event.height as i32 + 2 * border_width as i32 > monitor.screen_y + monitor.screen_height as i32 {
3146 - y = monitor.screen_y + monitor.screen_height as i32 - event.height as i32 - 2 * border_width as i32;
3147 } 2899 }
3148 - y as i16 2900 + y = monitor.screen_y + event.y as i32;
3149 - } else { 2901 + }
3150 - cached_geom.map(|g| g.y_position).unwrap_or(0) 2902 + if event.value_mask.contains(ConfigWindow::WIDTH) {
3151 - }; 2903 + if let Some(c) = self.clients.get_mut(&event.window) {
3152 - 2904 + c.old_width = c.width;
3153 - let mut final_width = if value_mask.contains(ConfigWindow::WIDTH) { event.width } else { cached_geom.map(|g| g.width).unwrap_or(1) }; 2905 + }
3154 - let mut final_height = if value_mask.contains(ConfigWindow::HEIGHT) { event.height } else { cached_geom.map(|g| g.height).unwrap_or(1) }; 2906 + w = event.width as i32;
3155 - 2907 + }
3156 - if let Some(client) = self.clients.get(&event.window) { 2908 + if event.value_mask.contains(ConfigWindow::HEIGHT) {
3157 - let (w, h) = self.apply_size_hints(client, final_width as i32, final_height as i32); 2909 + if let Some(c) = self.clients.get_mut(&event.window) {
3158 - final_width = w as u16; 2910 + c.old_height = c.height;
3159 - final_height = h as u16; 2911 + }
2912 + h = event.height as i32;
3160 } 2913 }
3161 2914
3162 - let mut config = ConfigureWindowAux::new() 2915 + let bw = self.config.border_width as i32;
3163 - .x(final_x as i32) 2916 + let width_with_border = w + 2 * bw;
3164 - .y(final_y as i32) 2917 + let height_with_border = h + 2 * bw;
3165 - .width(final_width as u32)
3166 - .height(final_height as u32);
3167 2918
3168 - if value_mask.contains(ConfigWindow::BORDER_WIDTH) { 2919 + if (x + w) > monitor.screen_x + monitor.screen_width as i32 && is_floating {
3169 - config = config.border_width(event.border_width as u32); 2920 + x = monitor.screen_x + (monitor.screen_width as i32 / 2 - width_with_border / 2);
3170 } 2921 }
3171 - 2922 + if (y + h) > monitor.screen_y + monitor.screen_height as i32 && is_floating {
3172 - if value_mask.contains(ConfigWindow::SIBLING) { 2923 + y = monitor.screen_y + (monitor.screen_height as i32 / 2 - height_with_border / 2);
3173 - config = config.sibling(event.sibling);
3174 } 2924 }
3175 2925
3176 - if value_mask.contains(ConfigWindow::STACK_MODE) { 2926 + if let Some(c) = self.clients.get_mut(&event.window) {
3177 - config = config.stack_mode(event.stack_mode); 2927 + c.x_position = x as i16;
2928 + c.y_position = y as i16;
2929 + c.width = w as u16;
2930 + c.height = h as u16;
3178 } 2931 }
3179 2932
3180 - self.connection.configure_window(event.window, &config)?; 2933 + let only_position_change = event.value_mask.contains(ConfigWindow::X) || event.value_mask.contains(ConfigWindow::Y);
3181 - 2934 + let no_size_change = !event.value_mask.contains(ConfigWindow::WIDTH) && !event.value_mask.contains(ConfigWindow::HEIGHT);
3182 - if let Some(client) = self.clients.get_mut(&event.window) { 2935 + if only_position_change && no_size_change {
3183 - client.old_x_position = client.x_position; 2936 + self.send_configure_notify(event.window)?;
3184 - client.old_y_position = client.y_position;
3185 - client.old_width = client.width;
3186 - client.old_height = client.height;
3187 - client.x_position = final_x;
3188 - client.y_position = final_y;
3189 - client.width = final_width;
3190 - client.height = final_height;
3191 } 2937 }
3192 2938
3193 - self.update_geometry_cache(event.window, CachedGeometry { 2939 + if self.is_visible(event.window) {
3194 - x_position: final_x, 2940 + self.connection.configure_window(
3195 - y_position: final_y, 2941 + event.window,
3196 - width: final_width, 2942 + &ConfigureWindowAux::new()
3197 - height: final_height, 2943 + .x(x)
3198 - border_width: if value_mask.contains(ConfigWindow::BORDER_WIDTH) { event.border_width } else { border_width }, 2944 + .y(y)
3199 - }); 2945 + .width(w as u32)
3200 - 2946 + .height(h as u32),
3201 - if is_floating { 2947 + )?;
3202 - let new_monitor = self.get_monitor_for_rect(final_x as i32, final_y as i32, final_width as i32, final_height as i32);
3203 -
3204 - if new_monitor != monitor_index {
3205 - self.move_window_to_monitor(event.window, new_monitor)?;
3206 - }
3207 } 2948 }
3208 } else { 2949 } else {
3209 self.send_configure_notify(event.window)?; 2950 self.send_configure_notify(event.window)?;
3210 } 2951 }
3211 } else { 2952 } else {
3212 - let mut config = ConfigureWindowAux::new() 2953 + let mut aux = ConfigureWindowAux::new();
3213 - .x(event.x as i32) 2954 + if event.value_mask.contains(ConfigWindow::X) {
3214 - .y(event.y as i32) 2955 + aux = aux.x(event.x as i32);
3215 - .width(event.width as u32) 2956 + }
3216 - .height(event.height as u32) 2957 + if event.value_mask.contains(ConfigWindow::Y) {
3217 - .border_width(event.border_width as u32); 2958 + aux = aux.y(event.y as i32);
3218 - 2959 + }
2960 + if event.value_mask.contains(ConfigWindow::WIDTH) {
2961 + aux = aux.width(event.width as u32);
2962 + }
2963 + if event.value_mask.contains(ConfigWindow::HEIGHT) {
2964 + aux = aux.height(event.height as u32);
2965 + }
2966 + if event.value_mask.contains(ConfigWindow::BORDER_WIDTH) {
2967 + aux = aux.border_width(event.border_width as u32);
2968 + }
3219 if event.value_mask.contains(ConfigWindow::SIBLING) { 2969 if event.value_mask.contains(ConfigWindow::SIBLING) {
3220 - config = config.sibling(event.sibling); 2970 + aux = aux.sibling(event.sibling);
3221 } 2971 }
3222 -
3223 if event.value_mask.contains(ConfigWindow::STACK_MODE) { 2972 if event.value_mask.contains(ConfigWindow::STACK_MODE) {
3224 - config = config.stack_mode(event.stack_mode); 2973 + aux = aux.stack_mode(event.stack_mode);
3225 } 2974 }
3226 - 2975 + self.connection.configure_window(event.window, &aux)?;
3227 - self.connection.configure_window(event.window, &config)?;
3228 } 2976 }
2977 + self.connection.flush()?;
3229 } 2978 }
3230 Event::ClientMessage(event) => { 2979 Event::ClientMessage(event) => {
3231 if !self.clients.contains_key(&event.window) { 2980 if !self.clients.contains_key(&event.window) {
@@ -3293,6 +3042,11 @@ impl WindowManager {
3293 } 3042 }
3294 3043
3295 fn apply_layout(&mut self) -> WmResult<()> { 3044 fn apply_layout(&mut self) -> WmResult<()> {
3045 + for monitor_index in 0..self.monitors.len() {
3046 + let stack_head = self.monitors.get(monitor_index).and_then(|m| m.stack_head);
3047 + self.showhide(stack_head)?;
3048 + }
3049 +
3296 let is_normie = self.layout.name() == LayoutType::Normie.as_str(); 3050 let is_normie = self.layout.name() == LayoutType::Normie.as_str();
3297 3051
3298 if !is_normie { 3052 if !is_normie {
@@ -3360,10 +3114,12 @@ impl WindowManager {
3360 let mut adjusted_width = geometry.width.saturating_sub(2 * border_width); 3114 let mut adjusted_width = geometry.width.saturating_sub(2 * border_width);
3361 let mut adjusted_height = geometry.height.saturating_sub(2 * border_width); 3115 let mut adjusted_height = geometry.height.saturating_sub(2 * border_width);
3362 3116
3363 - if let Some(client) = self.clients.get(window) { 3117 + if let Some(client) = self.clients.get(window).cloned() {
3364 if !client.is_floating { 3118 if !client.is_floating {
3365 - let (hint_width, hint_height) = self.apply_size_hints( 3119 + let (_, _, hint_width, hint_height, _) = self.apply_size_hints(
3366 - client, 3120 + *window,
3121 + geometry.x_coordinate as i32,
3122 + geometry.y_coordinate as i32,
3367 adjusted_width as i32, 3123 adjusted_width as i32,
3368 adjusted_height as i32, 3124 adjusted_height as i32,
3369 ); 3125 );
@@ -3392,13 +3148,13 @@ impl WindowManager {
3392 .border_width(border_width), 3148 .border_width(border_width),
3393 )?; 3149 )?;
3394 3150
3395 - self.update_geometry_cache(*window, CachedGeometry { 3151 + if let Some(c) = self.clients.get_mut(window) {
3396 - x_position: adjusted_x as i16, 3152 + c.x_position = adjusted_x as i16;
3397 - y_position: adjusted_y as i16, 3153 + c.y_position = adjusted_y as i16;
3398 - width: adjusted_width as u16, 3154 + c.width = adjusted_width as u16;
3399 - height: adjusted_height as u16, 3155 + c.height = adjusted_height as u16;
3400 - border_width: border_width as u16, 3156 + c.border_width = border_width as u16;
3401 - }); 3157 + }
3402 } 3158 }
3403 } 3159 }
3404 } 3160 }
@@ -3494,52 +3250,33 @@ impl WindowManager {
3494 Ok(()) 3250 Ok(())
3495 } 3251 }
3496 3252
3497 - fn update_geometry_cache(&mut self, window: Window, geometry: CachedGeometry) { 3253 + fn send_configure_notify(&self, window: Window) -> WmResult<()> {
3498 - self.window_geometry_cache.insert(window, geometry); 3254 + let client = self.clients.get(&window);
3499 - } 3255 + let (x, y, w, h, bw) = if let Some(c) = client {
3500 - 3256 + (c.x_position, c.y_position, c.width, c.height, c.border_width)
3501 - fn get_cached_geometry(&self, window: Window) -> Option<CachedGeometry> { 3257 + } else {
3502 - self.window_geometry_cache.get(&window).copied() 3258 + let geom = self.connection.get_geometry(window)?.reply()?;
3503 - } 3259 + (geom.x, geom.y, geom.width, geom.height, geom.border_width)
3504 -
3505 - fn get_or_query_geometry(&mut self, window: Window) -> WmResult<CachedGeometry> {
3506 - if let Some(cached) = self.get_cached_geometry(window) {
3507 - return Ok(cached);
3508 - }
3509 -
3510 - let geometry = self.connection.get_geometry(window)?.reply()?;
3511 - let cached = CachedGeometry {
3512 - x_position: geometry.x,
3513 - y_position: geometry.y,
3514 - width: geometry.width,
3515 - height: geometry.height,
3516 - border_width: geometry.border_width as u16,
3517 }; 3260 };
3518 - self.update_geometry_cache(window, cached);
3519 - Ok(cached)
3520 - }
3521 -
3522 - fn send_configure_notify(&mut self, window: Window) -> WmResult<()> {
3523 - let geometry = self.get_or_query_geometry(window)?;
3524 3261
3525 - let event = x11rb::protocol::xproto::ConfigureNotifyEvent { 3262 + let event = ConfigureNotifyEvent {
3526 - response_type: x11rb::protocol::xproto::CONFIGURE_NOTIFY_EVENT, 3263 + response_type: CONFIGURE_NOTIFY_EVENT,
3527 sequence: 0, 3264 sequence: 0,
3528 event: window, 3265 event: window,
3529 window, 3266 window,
3530 above_sibling: x11rb::NONE, 3267 above_sibling: x11rb::NONE,
3531 - x: geometry.x_position, 3268 + x,
3532 - y: geometry.y_position, 3269 + y,
3533 - width: geometry.width, 3270 + width: w,
3534 - height: geometry.height, 3271 + height: h,
3535 - border_width: geometry.border_width, 3272 + border_width: bw,
3536 override_redirect: false, 3273 override_redirect: false,
3537 }; 3274 };
3538 3275
3539 self.connection.send_event( 3276 self.connection.send_event(
3540 false, 3277 false,
3541 window, 3278 window,
3542 - x11rb::protocol::xproto::EventMask::STRUCTURE_NOTIFY, 3279 + EventMask::STRUCTURE_NOTIFY,
3543 event, 3280 event,
3544 )?; 3281 )?;
3545 3282
@@ -3579,7 +3316,6 @@ impl WindowManager {
3579 3316
3580 let flags = read_u32(0); 3317 let flags = read_u32(0);
3581 3318
3582 - const P_SIZE: u32 = 1 << 3;
3583 const P_MIN_SIZE: u32 = 1 << 4; 3319 const P_MIN_SIZE: u32 = 1 << 4;
3584 const P_MAX_SIZE: u32 = 1 << 5; 3320 const P_MAX_SIZE: u32 = 1 << 5;
3585 const P_RESIZE_INC: u32 = 1 << 6; 3321 const P_RESIZE_INC: u32 = 1 << 6;
@@ -3588,8 +3324,8 @@ impl WindowManager {
3588 3324
3589 if let Some(client) = self.clients.get_mut(&window) { 3325 if let Some(client) = self.clients.get_mut(&window) {
3590 if flags & P_BASE_SIZE != 0 { 3326 if flags & P_BASE_SIZE != 0 {
3591 - client.base_width = read_u32(8) as i32; 3327 + client.base_width = read_u32(15) as i32;
3592 - client.base_height = read_u32(9) as i32; 3328 + client.base_height = read_u32(16) as i32;
3593 } else if flags & P_MIN_SIZE != 0 { 3329 } else if flags & P_MIN_SIZE != 0 {
3594 client.base_width = read_u32(5) as i32; 3330 client.base_width = read_u32(5) as i32;
3595 client.base_height = read_u32(6) as i32; 3331 client.base_height = read_u32(6) as i32;
@@ -3599,8 +3335,8 @@ impl WindowManager {
3599 } 3335 }
3600 3336
3601 if flags & P_RESIZE_INC != 0 { 3337 if flags & P_RESIZE_INC != 0 {
3602 - client.increment_width = read_u32(10) as i32; 3338 + client.increment_width = read_u32(9) as i32;
3603 - client.increment_height = read_u32(11) as i32; 3339 + client.increment_height = read_u32(10) as i32;
3604 } else { 3340 } else {
3605 client.increment_width = 0; 3341 client.increment_width = 0;
3606 client.increment_height = 0; 3342 client.increment_height = 0;
@@ -3617,17 +3353,17 @@ impl WindowManager {
3617 if flags & P_MIN_SIZE != 0 { 3353 if flags & P_MIN_SIZE != 0 {
3618 client.min_width = read_u32(5) as i32; 3354 client.min_width = read_u32(5) as i32;
3619 client.min_height = read_u32(6) as i32; 3355 client.min_height = read_u32(6) as i32;
3620 - } else if flags & P_SIZE != 0 { 3356 + } else if flags & P_BASE_SIZE != 0 {
3621 - client.min_width = read_u32(3) as i32; 3357 + client.min_width = read_u32(15) as i32;
3622 - client.min_height = read_u32(4) as i32; 3358 + client.min_height = read_u32(16) as i32;
3623 } else { 3359 } else {
3624 client.min_width = 0; 3360 client.min_width = 0;
3625 client.min_height = 0; 3361 client.min_height = 0;
3626 } 3362 }
3627 3363
3628 if flags & P_ASPECT != 0 { 3364 if flags & P_ASPECT != 0 {
3629 - client.min_aspect = (read_u32(12) as f32) / (read_u32(13) as f32).max(1.0); 3365 + client.min_aspect = (read_u32(12) as f32) / (read_u32(11) as f32).max(1.0);
3630 - client.max_aspect = (read_u32(14) as f32) / (read_u32(15) as f32).max(1.0); 3366 + client.max_aspect = (read_u32(13) as f32) / (read_u32(14) as f32).max(1.0);
3631 } else { 3367 } else {
3632 client.min_aspect = 0.0; 3368 client.min_aspect = 0.0;
3633 client.max_aspect = 0.0; 3369 client.max_aspect = 0.0;
@@ -3773,51 +3509,101 @@ impl WindowManager {
3773 Ok(()) 3509 Ok(())
3774 } 3510 }
3775 3511
3776 - fn apply_size_hints(&self, client: &Client, mut width: i32, mut height: i32) -> (i32, i32) { 3512 + fn apply_size_hints(&mut self, window: Window, mut x: i32, mut y: i32, mut w: i32, mut h: i32) -> (i32, i32, i32, i32, bool) {
3777 - let min_size = 20; 3513 + let bh = 20;
3778 - width = width.max(min_size);
3779 - height = height.max(min_size);
3780 3514
3781 - if !client.hints_valid { 3515 + let (client_x, client_y, client_w, client_h, bw, monitor_index, is_floating, mut hints_valid) = {
3782 - return (width, height); 3516 + let client = match self.clients.get(&window) {
3783 - } 3517 + Some(c) => c,
3518 + None => return (x, y, w, h, false),
3519 + };
3520 + (client.x_position as i32, client.y_position as i32, client.width as i32, client.height as i32,
3521 + client.border_width as i32, client.monitor_index, client.is_floating, client.hints_valid)
3522 + };
3523 +
3524 + let monitor = &self.monitors[monitor_index];
3525 + let client_width = client_w + 2 * bw;
3526 + let client_height = client_h + 2 * bw;
3784 3527
3785 - if client.min_width > 0 { 3528 + w = w.max(1);
3786 - width = width.max(client.min_width); 3529 + h = h.max(1);
3530 +
3531 + if x >= monitor.window_area_x + monitor.window_area_width {
3532 + x = monitor.window_area_x + monitor.window_area_width - client_width;
3787 } 3533 }
3788 - if client.min_height > 0 { 3534 + if y >= monitor.window_area_y + monitor.window_area_height {
3789 - height = height.max(client.min_height); 3535 + y = monitor.window_area_y + monitor.window_area_height - client_height;
3790 } 3536 }
3791 - 3537 + if x + w + 2 * bw <= monitor.window_area_x {
3792 - if client.max_width > 0 { 3538 + x = monitor.window_area_x;
3793 - width = width.min(client.max_width);
3794 } 3539 }
3795 - if client.max_height > 0 { 3540 + if y + h + 2 * bw <= monitor.window_area_y {
3796 - height = height.min(client.max_height); 3541 + y = monitor.window_area_y;
3797 } 3542 }
3798 3543
3799 - if client.increment_width > 0 { 3544 + if h < bh {
3800 - width -= client.base_width; 3545 + h = bh;
3801 - width -= width % client.increment_width;
3802 - width += client.base_width;
3803 } 3546 }
3804 - if client.increment_height > 0 { 3547 + if w < bh {
3805 - height -= client.base_height; 3548 + w = bh;
3806 - height -= height % client.increment_height;
3807 - height += client.base_height;
3808 } 3549 }
3809 3550
3810 - if client.min_aspect > 0.0 || client.max_aspect > 0.0 { 3551 + if is_floating || self.layout.name() == "normie" {
3811 - let actual_aspect = width as f32 / height as f32; 3552 + if !hints_valid {
3553 + let _ = self.update_size_hints(window);
3554 + hints_valid = self.clients.get(&window).map(|c| c.hints_valid).unwrap_or(false);
3555 + }
3556 +
3557 + if hints_valid {
3558 + let (base_width, base_height, min_width, min_height, max_width, max_height,
3559 + inc_width, inc_height, min_aspect, max_aspect) = {
3560 + let client = self.clients.get(&window).unwrap();
3561 + (client.base_width, client.base_height, client.min_width, client.min_height,
3562 + client.max_width, client.max_height, client.increment_width, client.increment_height,
3563 + client.min_aspect, client.max_aspect)
3564 + };
3812 3565
3813 - if client.max_aspect > 0.0 && actual_aspect > client.max_aspect { 3566 + let base_is_min = base_width == min_width && base_height == min_height;
3814 - width = (height as f32 * client.max_aspect) as i32; 3567 +
3815 - } else if client.min_aspect > 0.0 && actual_aspect < client.min_aspect { 3568 + if !base_is_min {
3816 - height = (width as f32 / client.min_aspect) as i32; 3569 + w -= base_width;
3570 + h -= base_height;
3571 + }
3572 +
3573 + if min_aspect > 0.0 && max_aspect > 0.0 {
3574 + if max_aspect < (w as f32 / h as f32) {
3575 + w = (h as f32 * max_aspect + 0.5) as i32;
3576 + } else if min_aspect < (h as f32 / w as f32) {
3577 + h = (w as f32 * min_aspect + 0.5) as i32;
3578 + }
3579 + }
3580 +
3581 + if base_is_min {
3582 + w -= base_width;
3583 + h -= base_height;
3584 + }
3585 +
3586 + if inc_width > 0 {
3587 + w -= w % inc_width;
3588 + }
3589 + if inc_height > 0 {
3590 + h -= h % inc_height;
3591 + }
3592 +
3593 + w = (w + base_width).max(min_width);
3594 + h = (h + base_height).max(min_height);
3595 +
3596 + if max_width > 0 {
3597 + w = w.min(max_width);
3598 + }
3599 + if max_height > 0 {
3600 + h = h.min(max_height);
3601 + }
3817 } 3602 }
3818 } 3603 }
3819 3604
3820 - (width.max(1), height.max(1)) 3605 + let changed = x != client_x || y != client_y || w != client_w || h != client_h;
3606 + (x, y, w, h, changed)
3821 } 3607 }
3822 3608
3823 fn next_tiled(&self, start: Option<Window>, monitor: &Monitor) -> Option<Window> { 3609 fn next_tiled(&self, start: Option<Window>, monitor: &Monitor) -> Option<Window> {
@@ -3991,7 +3777,6 @@ impl WindowManager {
3991 } 3777 }
3992 3778
3993 self.windows.retain(|&w| w != window); 3779 self.windows.retain(|&w| w != window);
3994 - self.window_geometry_cache.remove(&window);
3995 self.floating_windows.remove(&window); 3780 self.floating_windows.remove(&window);
3996 3781
3997 if self.windows.len() < initial_count { 3782 if self.windows.len() < initial_count {