partial fix for transient dialogs
Browse files
+279 −175 src/window_manager.rs Large diff collapsed, click to expand
| @@ -1673,6 +1673,36 @@ impl WindowManager { | ||
| 1673 | 1673 | }) |
| 1674 | 1674 | } |
| 1675 | 1675 | |
| 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 | + | |
| 1676 | 1706 | fn is_dialog_window(&self, window: Window) -> bool { |
| 1677 | 1707 | let window_type_property = self.connection |
| 1678 | 1708 | .get_property( |
| @@ -1693,7 +1723,8 @@ impl WindowManager { | ||
| 1693 | 1723 | .map(|chunk| u32::from_ne_bytes([chunk[0], chunk[1], chunk[2], chunk[3]])) |
| 1694 | 1724 | .collect(); |
| 1695 | 1725 | |
| 1696 | - atoms.contains(&self.atoms.net_wm_window_type_dialog) | |
| 1726 | + let is_dialog = atoms.contains(&self.atoms.net_wm_window_type_dialog); | |
| 1727 | + is_dialog | |
| 1697 | 1728 | } else { |
| 1698 | 1729 | false |
| 1699 | 1730 | } |
| @@ -1790,13 +1821,42 @@ impl WindowManager { | ||
| 1790 | 1821 | let geometry = self.connection.get_geometry(window)?.reply()?; |
| 1791 | 1822 | let mut window_x = geometry.x as i32; |
| 1792 | 1823 | let mut window_y = geometry.y as i32; |
| 1793 | - let window_width = geometry.width as u32; | |
| 1794 | - let window_height = geometry.height as u32; | |
| 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; | |
| 1827 | + | |
| 1828 | + self.update_window_title(window)?; | |
| 1795 | 1829 | |
| 1796 | 1830 | let transient_parent = self.get_transient_parent(window); |
| 1797 | - let (window_tags, monitor_index) = if let Some(parent) = transient_parent { | |
| 1798 | - if let Some(parent_client) = self.clients.get(&parent) { | |
| 1799 | - (parent_client.tags, parent_client.monitor_index) | |
| 1831 | + let is_transient = transient_parent.is_some(); | |
| 1832 | + | |
| 1833 | + let parent_geometry = if let Some(parent) = transient_parent { | |
| 1834 | + self.connection.get_geometry(parent) | |
| 1835 | + .ok() | |
| 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) | |
| 1800 | 1860 | } else { |
| 1801 | 1861 | let tags = self.monitors |
| 1802 | 1862 | .get(self.selected_monitor) |
| @@ -1805,175 +1865,149 @@ impl WindowManager { | ||
| 1805 | 1865 | (tags, self.selected_monitor) |
| 1806 | 1866 | } |
| 1807 | 1867 | } else { |
| 1808 | - let selected_tags = self.monitors | |
| 1868 | + let tags = self.monitors | |
| 1809 | 1869 | .get(self.selected_monitor) |
| 1810 | 1870 | .map(|m| m.tagset[m.selected_tags_index]) |
| 1811 | 1871 | .unwrap_or(tag_mask(0)); |
| 1812 | - (selected_tags, self.selected_monitor) | |
| 1872 | + (tags, self.selected_monitor) | |
| 1813 | 1873 | }; |
| 1814 | 1874 | |
| 1815 | - let monitor = self.monitors[monitor_index].clone(); | |
| 1816 | - let border_width = self.config.border_width; | |
| 1817 | - | |
| 1818 | - let mut client = Client::new(window, monitor_index, window_tags); | |
| 1819 | - client.x_position = window_x as i16; | |
| 1820 | - client.y_position = window_y as i16; | |
| 1821 | - client.width = window_width as u16; | |
| 1822 | - client.height = window_height as u16; | |
| 1823 | - client.old_x_position = window_x as i16; | |
| 1824 | - client.old_y_position = window_y as i16; | |
| 1825 | - client.old_width = window_width as u16; | |
| 1826 | - client.old_height = window_height as u16; | |
| 1827 | - client.border_width = border_width as u16; | |
| 1875 | + let mut client = Client::new(window, initial_monitor_index, initial_tags); | |
| 1828 | 1876 | client.old_border_width = border_width as u16; |
| 1829 | 1877 | |
| 1830 | - if window_x + (window_width as i32) + (2 * border_width as i32) > monitor.screen_x + monitor.screen_width as i32 { | |
| 1831 | - window_x = monitor.screen_x + monitor.screen_width as i32 - (window_width as i32) - (2 * border_width as i32); | |
| 1832 | - } | |
| 1833 | - if window_y + (window_height as i32) + (2 * border_width as i32) > monitor.screen_y + monitor.screen_height as i32 { | |
| 1834 | - window_y = monitor.screen_y + monitor.screen_height as i32 - (window_height as i32) - (2 * border_width as i32); | |
| 1878 | + self.clients.insert(window, client); | |
| 1879 | + | |
| 1880 | + if !is_transient { | |
| 1881 | + self.apply_rules(window)?; | |
| 1835 | 1882 | } |
| 1836 | - window_x = window_x.max(monitor.screen_x); | |
| 1837 | - window_y = window_y.max(monitor.screen_y); | |
| 1838 | 1883 | |
| 1839 | - let is_transient = transient_parent.is_some(); | |
| 1884 | + let final_monitor_index = self.clients.get(&window).map(|c| c.monitor_index).unwrap_or(initial_monitor_index); | |
| 1885 | + let final_monitor = self.monitors.get(final_monitor_index).cloned().unwrap_or_else(|| { | |
| 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 | + | |
| 1894 | + self.update_window_type(window)?; | |
| 1895 | + | |
| 1896 | + let has_explicit_position = self.has_user_set_position(window); | |
| 1840 | 1897 | let is_dialog = self.is_dialog_window(window); |
| 1898 | + let position_is_origin = window_x == 0 && window_y == 0; | |
| 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 | + } | |
| 1841 | 1917 | |
| 1842 | - let class_name = self.get_window_class(window).unwrap_or_default(); | |
| 1843 | - eprintln!("MapRequest 0x{:x}: class='{}' size={}x{} pos=({},{}) transient={} dialog={}", | |
| 1844 | - window, class_name, window_width, window_height, window_x, window_y, is_transient, is_dialog); | |
| 1918 | + if window_x + total_width > final_monitor.window_area_x + final_monitor.window_area_width { | |
| 1919 | + window_x = final_monitor.window_area_x + final_monitor.window_area_width - total_width; | |
| 1920 | + } | |
| 1921 | + if window_y + total_height > final_monitor.window_area_y + final_monitor.window_area_height { | |
| 1922 | + window_y = final_monitor.window_area_y + final_monitor.window_area_height - total_height; | |
| 1923 | + } | |
| 1924 | + window_x = window_x.max(final_monitor.window_area_x); | |
| 1925 | + window_y = window_y.max(final_monitor.window_area_y); | |
| 1845 | 1926 | |
| 1846 | - let off_screen_x = window_x + (2 * self.screen.width_in_pixels as i32); | |
| 1927 | + if let Some(client) = self.clients.get_mut(&window) { | |
| 1928 | + client.x_position = window_x as i16; | |
| 1929 | + client.y_position = window_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 | + } | |
| 1847 | 1938 | |
| 1848 | 1939 | self.connection.configure_window( |
| 1849 | 1940 | window, |
| 1850 | 1941 | &ConfigureWindowAux::new() |
| 1851 | - .x(off_screen_x) | |
| 1942 | + .x(window_x) | |
| 1852 | 1943 | .y(window_y) |
| 1853 | - .width(window_width) | |
| 1854 | - .height(window_height) | |
| 1855 | - .border_width(border_width) | |
| 1944 | + .border_width(border_width), | |
| 1856 | 1945 | )?; |
| 1857 | 1946 | |
| 1947 | + self.send_configure_notify(window)?; | |
| 1948 | + self.update_size_hints(window)?; | |
| 1949 | + | |
| 1858 | 1950 | self.connection.change_window_attributes( |
| 1859 | 1951 | window, |
| 1860 | 1952 | &ChangeWindowAttributesAux::new().event_mask( |
| 1861 | - EventMask::ENTER_WINDOW | EventMask::STRUCTURE_NOTIFY | EventMask::PROPERTY_CHANGE | |
| 1953 | + EventMask::ENTER_WINDOW | EventMask::FOCUS_CHANGE | EventMask::PROPERTY_CHANGE | EventMask::STRUCTURE_NOTIFY | |
| 1862 | 1954 | ), |
| 1863 | 1955 | )?; |
| 1864 | 1956 | |
| 1865 | - client.is_floating = is_transient || is_dialog; | |
| 1866 | - | |
| 1867 | - self.clients.insert(window, client); | |
| 1868 | - self.update_size_hints(window)?; | |
| 1869 | - self.update_window_title(window)?; | |
| 1870 | - self.apply_rules(window)?; | |
| 1871 | - | |
| 1872 | - let updated_monitor_index = self.clients.get(&window).map(|c| c.monitor_index).unwrap_or(monitor_index); | |
| 1873 | - let updated_monitor = self.monitors.get(updated_monitor_index).cloned().unwrap_or(monitor.clone()); | |
| 1874 | - let is_rule_floating = self.clients.get(&window).map(|c| c.is_floating).unwrap_or(false); | |
| 1875 | - | |
| 1876 | - self.attach_aside(window, updated_monitor_index); | |
| 1877 | - self.attach_stack(window, updated_monitor_index); | |
| 1957 | + 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); | |
| 1878 | 1959 | |
| 1879 | - self.windows.push(window); | |
| 1960 | + if !already_floating { | |
| 1961 | + if let Some(client) = self.clients.get_mut(&window) { | |
| 1962 | + client.is_floating = is_transient || is_fixed; | |
| 1963 | + client.old_state = client.is_floating; | |
| 1964 | + } | |
| 1965 | + } | |
| 1880 | 1966 | |
| 1881 | - if is_transient || is_dialog { | |
| 1967 | + let is_floating = self.clients.get(&window).map(|c| c.is_floating).unwrap_or(false); | |
| 1968 | + if is_floating { | |
| 1882 | 1969 | self.floating_windows.insert(window); |
| 1883 | - | |
| 1884 | - let (center_x, center_y) = if let Some(parent) = transient_parent { | |
| 1885 | - if let Ok(parent_geom) = self.connection.get_geometry(parent)?.reply() { | |
| 1886 | - let parent_center_x = parent_geom.x as i32 + (parent_geom.width as i32 / 2); | |
| 1887 | - let parent_center_y = parent_geom.y as i32 + (parent_geom.height as i32 / 2); | |
| 1888 | - (parent_center_x, parent_center_y) | |
| 1889 | - } else { | |
| 1890 | - let monitor_center_x = monitor.screen_x + (monitor.screen_width as i32 / 2); | |
| 1891 | - let monitor_center_y = monitor.screen_y + (monitor.screen_height as i32 / 2); | |
| 1892 | - (monitor_center_x, monitor_center_y) | |
| 1893 | - } | |
| 1894 | - } else { | |
| 1895 | - let monitor_center_x = monitor.screen_x + (monitor.screen_width as i32 / 2); | |
| 1896 | - let monitor_center_y = monitor.screen_y + (monitor.screen_height as i32 / 2); | |
| 1897 | - (monitor_center_x, monitor_center_y) | |
| 1898 | - }; | |
| 1899 | - | |
| 1900 | - let positioned_x = center_x - (window_width as i32 / 2); | |
| 1901 | - let positioned_y = center_y - (window_height as i32 / 2); | |
| 1902 | - | |
| 1903 | - let clamped_x = positioned_x | |
| 1904 | - .max(monitor.screen_x) | |
| 1905 | - .min(monitor.screen_x + monitor.screen_width as i32 - window_width as i32); | |
| 1906 | - let clamped_y = positioned_y | |
| 1907 | - .max(monitor.screen_y) | |
| 1908 | - .min(monitor.screen_y + monitor.screen_height as i32 - window_height as i32); | |
| 1909 | - | |
| 1910 | - self.update_geometry_cache(window, CachedGeometry { | |
| 1911 | - x_position: clamped_x as i16, | |
| 1912 | - y_position: clamped_y as i16, | |
| 1913 | - width: window_width as u16, | |
| 1914 | - height: window_height as u16, | |
| 1915 | - border_width: border_width as u16, | |
| 1916 | - }); | |
| 1917 | - | |
| 1918 | 1970 | self.connection.configure_window( |
| 1919 | 1971 | window, |
| 1920 | - &ConfigureWindowAux::new() | |
| 1921 | - .x(clamped_x) | |
| 1922 | - .y(clamped_y) | |
| 1923 | - .width(window_width) | |
| 1924 | - .height(window_height) | |
| 1925 | - .border_width(border_width) | |
| 1926 | - .stack_mode(StackMode::ABOVE), | |
| 1972 | + &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE), | |
| 1927 | 1973 | )?; |
| 1928 | - } else if is_rule_floating && !is_transient && !is_dialog { | |
| 1929 | - let mut adjusted_x = window_x; | |
| 1930 | - let mut adjusted_y = window_y; | |
| 1931 | - | |
| 1932 | - if adjusted_x + (window_width as i32) + (2 * border_width as i32) > updated_monitor.screen_x + updated_monitor.screen_width as i32 { | |
| 1933 | - adjusted_x = updated_monitor.screen_x + updated_monitor.screen_width as i32 - (window_width as i32) - (2 * border_width as i32); | |
| 1934 | - } | |
| 1935 | - if adjusted_y + (window_height as i32) + (2 * border_width as i32) > updated_monitor.screen_y + updated_monitor.screen_height as i32 { | |
| 1936 | - adjusted_y = updated_monitor.screen_y + updated_monitor.screen_height as i32 - (window_height as i32) - (2 * border_width as i32); | |
| 1937 | - } | |
| 1938 | - adjusted_x = adjusted_x.max(updated_monitor.screen_x); | |
| 1939 | - adjusted_y = adjusted_y.max(updated_monitor.screen_y); | |
| 1974 | + } | |
| 1940 | 1975 | |
| 1941 | - if let Some(client) = self.clients.get_mut(&window) { | |
| 1942 | - client.x_position = adjusted_x as i16; | |
| 1943 | - client.y_position = adjusted_y as i16; | |
| 1944 | - client.width = window_width as u16; | |
| 1945 | - client.height = window_height as u16; | |
| 1946 | - } | |
| 1947 | - | |
| 1948 | - self.update_geometry_cache(window, CachedGeometry { | |
| 1949 | - x_position: adjusted_x as i16, | |
| 1950 | - y_position: adjusted_y as i16, | |
| 1951 | - width: window_width as u16, | |
| 1952 | - height: window_height as u16, | |
| 1953 | - border_width: border_width as u16, | |
| 1954 | - }); | |
| 1976 | + self.attach_aside(window, final_monitor_index); | |
| 1977 | + self.attach_stack(window, final_monitor_index); | |
| 1978 | + self.windows.push(window); | |
| 1955 | 1979 | |
| 1956 | - self.connection.configure_window( | |
| 1957 | - window, | |
| 1958 | - &ConfigureWindowAux::new() | |
| 1959 | - .x(adjusted_x) | |
| 1960 | - .y(adjusted_y) | |
| 1961 | - .width(window_width) | |
| 1962 | - .height(window_height) | |
| 1963 | - .border_width(border_width) | |
| 1964 | - .stack_mode(StackMode::ABOVE), | |
| 1965 | - )?; | |
| 1966 | - } | |
| 1980 | + let off_screen_x = window_x + 2 * self.screen.width_in_pixels as i32; | |
| 1981 | + self.connection.configure_window( | |
| 1982 | + window, | |
| 1983 | + &ConfigureWindowAux::new() | |
| 1984 | + .x(off_screen_x) | |
| 1985 | + .y(window_y) | |
| 1986 | + .width(window_width) | |
| 1987 | + .height(window_height), | |
| 1988 | + )?; | |
| 1967 | 1989 | |
| 1968 | 1990 | self.set_wm_state(window, 1)?; |
| 1969 | - if let Err(error) = self.save_client_tag(window, window_tags) { | |
| 1991 | + | |
| 1992 | + let final_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(initial_tags); | |
| 1993 | + if let Err(error) = self.save_client_tag(window, final_tags) { | |
| 1970 | 1994 | eprintln!("Failed to save client tag for new window: {:?}", error); |
| 1971 | 1995 | } |
| 1972 | 1996 | |
| 1997 | + if final_monitor_index == self.selected_monitor { | |
| 1998 | + if let Some(old_selected) = self.monitors.get(self.selected_monitor).and_then(|m| m.selected_client) { | |
| 1999 | + self.unfocus(old_selected)?; | |
| 2000 | + } | |
| 2001 | + } | |
| 2002 | + | |
| 2003 | + if let Some(monitor) = self.monitors.get_mut(final_monitor_index) { | |
| 2004 | + monitor.selected_client = Some(window); | |
| 2005 | + } | |
| 2006 | + | |
| 1973 | 2007 | self.apply_layout()?; |
| 1974 | 2008 | self.connection.map_window(window)?; |
| 1975 | - self.update_bar()?; | |
| 1976 | 2009 | self.focus(Some(window))?; |
| 2010 | + self.update_bar()?; | |
| 1977 | 2011 | |
| 1978 | 2012 | if self.layout.name() == "tabbed" { |
| 1979 | 2013 | self.update_tab_bars()?; |
| @@ -2796,6 +2830,77 @@ impl WindowManager { | ||
| 2796 | 2830 | |
| 2797 | 2831 | if event.atom == self.atoms.net_wm_window_type { |
| 2798 | 2832 | 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 | + } | |
| 2799 | 2904 | } |
| 2800 | 2905 | } |
| 2801 | 2906 | Event::EnterNotify(event) => { |
| @@ -3021,38 +3126,47 @@ impl WindowManager { | ||
| 3021 | 3126 | if is_floating || !is_tiling_layout { |
| 3022 | 3127 | let cached_geom = self.window_geometry_cache.get(&event.window); |
| 3023 | 3128 | let border_width = self.config.border_width as u16; |
| 3024 | - | |
| 3025 | - let mut config = ConfigureWindowAux::new(); | |
| 3026 | 3129 | let value_mask = event.value_mask; |
| 3027 | 3130 | |
| 3028 | - if value_mask.contains(ConfigWindow::BORDER_WIDTH) { | |
| 3029 | - config = config.border_width(event.border_width as u32); | |
| 3030 | - } | |
| 3031 | - | |
| 3032 | - if value_mask.contains(ConfigWindow::X) { | |
| 3131 | + let final_x = if value_mask.contains(ConfigWindow::X) { | |
| 3033 | 3132 | let mut x = event.x as i32; |
| 3034 | 3133 | x = x.max(monitor.screen_x); |
| 3035 | 3134 | if x + event.width as i32 + 2 * border_width as i32 > monitor.screen_x + monitor.screen_width as i32 { |
| 3036 | 3135 | x = monitor.screen_x + monitor.screen_width as i32 - event.width as i32 - 2 * border_width as i32; |
| 3037 | 3136 | } |
| 3038 | - config = config.x(x); | |
| 3039 | - } | |
| 3137 | + x as i16 | |
| 3138 | + } else { | |
| 3139 | + cached_geom.map(|g| g.x_position).unwrap_or(0) | |
| 3140 | + }; | |
| 3040 | 3141 | |
| 3041 | - if value_mask.contains(ConfigWindow::Y) { | |
| 3142 | + let final_y = if value_mask.contains(ConfigWindow::Y) { | |
| 3042 | 3143 | let mut y = event.y as i32; |
| 3043 | 3144 | y = y.max(monitor.screen_y); |
| 3044 | 3145 | if y + event.height as i32 + 2 * border_width as i32 > monitor.screen_y + monitor.screen_height as i32 { |
| 3045 | 3146 | y = monitor.screen_y + monitor.screen_height as i32 - event.height as i32 - 2 * border_width as i32; |
| 3046 | 3147 | } |
| 3047 | - config = config.y(y); | |
| 3048 | - } | |
| 3148 | + y as i16 | |
| 3149 | + } else { | |
| 3150 | + cached_geom.map(|g| g.y_position).unwrap_or(0) | |
| 3151 | + }; | |
| 3049 | 3152 | |
| 3050 | - if value_mask.contains(ConfigWindow::WIDTH) { | |
| 3051 | - config = config.width(event.width as u32); | |
| 3153 | + let mut final_width = if value_mask.contains(ConfigWindow::WIDTH) { event.width } else { cached_geom.map(|g| g.width).unwrap_or(1) }; | |
| 3154 | + let mut final_height = if value_mask.contains(ConfigWindow::HEIGHT) { event.height } else { cached_geom.map(|g| g.height).unwrap_or(1) }; | |
| 3155 | + | |
| 3156 | + if let Some(client) = self.clients.get(&event.window) { | |
| 3157 | + let (w, h) = self.apply_size_hints(client, final_width as i32, final_height as i32); | |
| 3158 | + final_width = w as u16; | |
| 3159 | + final_height = h as u16; | |
| 3052 | 3160 | } |
| 3053 | 3161 | |
| 3054 | - if value_mask.contains(ConfigWindow::HEIGHT) { | |
| 3055 | - config = config.height(event.height as u32); | |
| 3162 | + let mut config = ConfigureWindowAux::new() | |
| 3163 | + .x(final_x as i32) | |
| 3164 | + .y(final_y as i32) | |
| 3165 | + .width(final_width as u32) | |
| 3166 | + .height(final_height as u32); | |
| 3167 | + | |
| 3168 | + if value_mask.contains(ConfigWindow::BORDER_WIDTH) { | |
| 3169 | + config = config.border_width(event.border_width as u32); | |
| 3056 | 3170 | } |
| 3057 | 3171 | |
| 3058 | 3172 | if value_mask.contains(ConfigWindow::SIBLING) { |
| @@ -3065,30 +3179,16 @@ impl WindowManager { | ||
| 3065 | 3179 | |
| 3066 | 3180 | self.connection.configure_window(event.window, &config)?; |
| 3067 | 3181 | |
| 3068 | - let final_x = if value_mask.contains(ConfigWindow::X) { | |
| 3069 | - let mut x = event.x as i32; | |
| 3070 | - x = x.max(monitor.screen_x); | |
| 3071 | - if x + event.width as i32 + 2 * border_width as i32 > monitor.screen_x + monitor.screen_width as i32 { | |
| 3072 | - x = monitor.screen_x + monitor.screen_width as i32 - event.width as i32 - 2 * border_width as i32; | |
| 3073 | - } | |
| 3074 | - x as i16 | |
| 3075 | - } else { | |
| 3076 | - cached_geom.map(|g| g.x_position).unwrap_or(0) | |
| 3077 | - }; | |
| 3078 | - | |
| 3079 | - let final_y = if value_mask.contains(ConfigWindow::Y) { | |
| 3080 | - let mut y = event.y as i32; | |
| 3081 | - y = y.max(monitor.screen_y); | |
| 3082 | - if y + event.height as i32 + 2 * border_width as i32 > monitor.screen_y + monitor.screen_height as i32 { | |
| 3083 | - y = monitor.screen_y + monitor.screen_height as i32 - event.height as i32 - 2 * border_width as i32; | |
| 3084 | - } | |
| 3085 | - y as i16 | |
| 3086 | - } else { | |
| 3087 | - cached_geom.map(|g| g.y_position).unwrap_or(0) | |
| 3088 | - }; | |
| 3089 | - | |
| 3090 | - let final_width = if value_mask.contains(ConfigWindow::WIDTH) { event.width } else { cached_geom.map(|g| g.width).unwrap_or(1) }; | |
| 3091 | - let final_height = if value_mask.contains(ConfigWindow::HEIGHT) { event.height } else { cached_geom.map(|g| g.height).unwrap_or(1) }; | |
| 3182 | + if let Some(client) = self.clients.get_mut(&event.window) { | |
| 3183 | + client.old_x_position = client.x_position; | |
| 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 | + } | |
| 3092 | 3192 | |
| 3093 | 3193 | self.update_geometry_cache(event.window, CachedGeometry { |
| 3094 | 3194 | x_position: final_x, |
| @@ -3674,8 +3774,12 @@ impl WindowManager { | ||
| 3674 | 3774 | } |
| 3675 | 3775 | |
| 3676 | 3776 | fn apply_size_hints(&self, client: &Client, mut width: i32, mut height: i32) -> (i32, i32) { |
| 3777 | + let min_size = 20; | |
| 3778 | + width = width.max(min_size); | |
| 3779 | + height = height.max(min_size); | |
| 3780 | + | |
| 3677 | 3781 | if !client.hints_valid { |
| 3678 | - return (width.max(1), height.max(1)); | |
| 3782 | + return (width, height); | |
| 3679 | 3783 | } |
| 3680 | 3784 | |
| 3681 | 3785 | if client.min_width > 0 { |