|
|
@@ -43,6 +43,8 @@ struct AtomCache { |
| 43 |
43 |
wm_delete_window: Atom, |
| 44 |
44 |
net_wm_state: Atom, |
| 45 |
45 |
net_wm_state_fullscreen: Atom, |
|
46 |
+ net_wm_window_type: Atom, |
|
47 |
+ net_wm_window_type_dialog: Atom, |
| 46 |
48 |
} |
| 47 |
49 |
|
| 48 |
50 |
impl AtomCache { |
|
|
@@ -79,6 +81,16 @@ impl AtomCache { |
| 79 |
81 |
.reply()? |
| 80 |
82 |
.atom; |
| 81 |
83 |
|
|
84 |
+ let net_wm_window_type = connection |
|
85 |
+ .intern_atom(false, b"_NET_WM_WINDOW_TYPE")? |
|
86 |
+ .reply()? |
|
87 |
+ .atom; |
|
88 |
+ |
|
89 |
+ let net_wm_window_type_dialog = connection |
|
90 |
+ .intern_atom(false, b"_NET_WM_WINDOW_TYPE_DIALOG")? |
|
91 |
+ .reply()? |
|
92 |
+ .atom; |
|
93 |
+ |
| 82 |
94 |
Ok(Self { |
| 83 |
95 |
net_current_desktop, |
| 84 |
96 |
net_client_info, |
|
|
@@ -87,6 +99,8 @@ impl AtomCache { |
| 87 |
99 |
wm_delete_window, |
| 88 |
100 |
net_wm_state, |
| 89 |
101 |
net_wm_state_fullscreen, |
|
102 |
+ net_wm_window_type, |
|
103 |
+ net_wm_window_type_dialog, |
| 90 |
104 |
}) |
| 91 |
105 |
} |
| 92 |
106 |
} |
|
|
@@ -154,29 +168,40 @@ impl WindowManager { |
| 154 |
168 |
)? |
| 155 |
169 |
.check()?; |
| 156 |
170 |
|
| 157 |
|
- connection.grab_button( |
| 158 |
|
- false, |
| 159 |
|
- root, |
| 160 |
|
- EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
| 161 |
|
- GrabMode::SYNC, |
| 162 |
|
- GrabMode::ASYNC, |
| 163 |
|
- x11rb::NONE, |
| 164 |
|
- x11rb::NONE, |
| 165 |
|
- ButtonIndex::M1, |
| 166 |
|
- u16::from(config.modkey).into(), |
| 167 |
|
- )?; |
|
171 |
+ let ignore_modifiers = [ |
|
172 |
+ 0, |
|
173 |
+ u16::from(ModMask::LOCK), |
|
174 |
+ u16::from(ModMask::M2), |
|
175 |
+ u16::from(ModMask::LOCK | ModMask::M2), |
|
176 |
+ ]; |
| 168 |
177 |
|
| 169 |
|
- connection.grab_button( |
| 170 |
|
- false, |
| 171 |
|
- root, |
| 172 |
|
- EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
| 173 |
|
- GrabMode::SYNC, |
| 174 |
|
- GrabMode::ASYNC, |
| 175 |
|
- x11rb::NONE, |
| 176 |
|
- x11rb::NONE, |
| 177 |
|
- ButtonIndex::M3, |
| 178 |
|
- u16::from(config.modkey).into(), |
| 179 |
|
- )?; |
|
178 |
+ for &ignore_mask in &ignore_modifiers { |
|
179 |
+ let grab_mask = u16::from(config.modkey) | ignore_mask; |
|
180 |
+ |
|
181 |
+ connection.grab_button( |
|
182 |
+ false, |
|
183 |
+ root, |
|
184 |
+ EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
|
185 |
+ GrabMode::SYNC, |
|
186 |
+ GrabMode::ASYNC, |
|
187 |
+ x11rb::NONE, |
|
188 |
+ x11rb::NONE, |
|
189 |
+ ButtonIndex::M1, |
|
190 |
+ grab_mask.into(), |
|
191 |
+ )?; |
|
192 |
+ |
|
193 |
+ connection.grab_button( |
|
194 |
+ false, |
|
195 |
+ root, |
|
196 |
+ EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE, |
|
197 |
+ GrabMode::SYNC, |
|
198 |
+ GrabMode::ASYNC, |
|
199 |
+ x11rb::NONE, |
|
200 |
+ x11rb::NONE, |
|
201 |
+ ButtonIndex::M3, |
|
202 |
+ grab_mask.into(), |
|
203 |
+ )?; |
|
204 |
+ } |
| 180 |
205 |
|
| 181 |
206 |
let monitors = detect_monitors(&connection, &screen, root)?; |
| 182 |
207 |
|
|
|
@@ -966,7 +991,7 @@ impl WindowManager { |
| 966 |
991 |
|
| 967 |
992 |
fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> { |
| 968 |
993 |
match action { |
| 969 |
|
- KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, |
|
994 |
+ KeyAction::Spawn => handlers::handle_spawn_action(action, arg, self.selected_monitor)?, |
| 970 |
995 |
KeyAction::SpawnTerminal => { |
| 971 |
996 |
use std::process::Command; |
| 972 |
997 |
let terminal = &self.config.terminal; |
|
|
@@ -1431,6 +1456,13 @@ impl WindowManager { |
| 1431 |
1456 |
|
| 1432 |
1457 |
let mut grabbed_keys: HashSet<(u16, Keycode)> = HashSet::new(); |
| 1433 |
1458 |
|
|
1459 |
+ let ignore_modifiers = [ |
|
1460 |
+ 0, |
|
1461 |
+ u16::from(ModMask::LOCK), |
|
1462 |
+ u16::from(ModMask::M2), |
|
1463 |
+ u16::from(ModMask::LOCK | ModMask::M2), |
|
1464 |
+ ]; |
|
1465 |
+ |
| 1434 |
1466 |
for &candidate_index in candidates { |
| 1435 |
1467 |
let binding = &self.config.keybindings[candidate_index]; |
| 1436 |
1468 |
if keys_pressed < binding.keys.len() { |
|
|
@@ -1439,17 +1471,20 @@ impl WindowManager { |
| 1439 |
1471 |
|
| 1440 |
1472 |
if let Some(keycodes) = keysym_to_keycode.get(&next_key.keysym) { |
| 1441 |
1473 |
if let Some(&keycode) = keycodes.first() { |
| 1442 |
|
- let key_tuple = (modifier_mask, keycode); |
| 1443 |
|
- |
| 1444 |
|
- if grabbed_keys.insert(key_tuple) { |
| 1445 |
|
- self.connection.grab_key( |
| 1446 |
|
- false, |
| 1447 |
|
- self.root, |
| 1448 |
|
- modifier_mask.into(), |
| 1449 |
|
- keycode, |
| 1450 |
|
- GrabMode::ASYNC, |
| 1451 |
|
- GrabMode::ASYNC, |
| 1452 |
|
- )?; |
|
1474 |
+ for &ignore_mask in &ignore_modifiers { |
|
1475 |
+ let grab_mask = modifier_mask | ignore_mask; |
|
1476 |
+ let key_tuple = (grab_mask, keycode); |
|
1477 |
+ |
|
1478 |
+ if grabbed_keys.insert(key_tuple) { |
|
1479 |
+ self.connection.grab_key( |
|
1480 |
+ false, |
|
1481 |
+ self.root, |
|
1482 |
+ grab_mask.into(), |
|
1483 |
+ keycode, |
|
1484 |
+ GrabMode::ASYNC, |
|
1485 |
+ GrabMode::ASYNC, |
|
1486 |
+ )?; |
|
1487 |
+ } |
| 1453 |
1488 |
} |
| 1454 |
1489 |
} |
| 1455 |
1490 |
} |
|
|
@@ -1458,14 +1493,16 @@ impl WindowManager { |
| 1458 |
1493 |
|
| 1459 |
1494 |
if let Some(keycodes) = keysym_to_keycode.get(&keyboard::keysyms::XK_ESCAPE) { |
| 1460 |
1495 |
if let Some(&keycode) = keycodes.first() { |
| 1461 |
|
- self.connection.grab_key( |
| 1462 |
|
- false, |
| 1463 |
|
- self.root, |
| 1464 |
|
- ModMask::from(0u16), |
| 1465 |
|
- keycode, |
| 1466 |
|
- GrabMode::ASYNC, |
| 1467 |
|
- GrabMode::ASYNC, |
| 1468 |
|
- )?; |
|
1496 |
+ for &ignore_mask in &ignore_modifiers { |
|
1497 |
+ self.connection.grab_key( |
|
1498 |
+ false, |
|
1499 |
+ self.root, |
|
1500 |
+ ModMask::from(ignore_mask), |
|
1501 |
+ keycode, |
|
1502 |
+ GrabMode::ASYNC, |
|
1503 |
+ GrabMode::ASYNC, |
|
1504 |
+ )?; |
|
1505 |
+ } |
| 1469 |
1506 |
} |
| 1470 |
1507 |
} |
| 1471 |
1508 |
|
|
|
@@ -1482,12 +1519,9 @@ impl WindowManager { |
| 1482 |
1519 |
} |
| 1483 |
1520 |
|
| 1484 |
1521 |
fn kill_client(&self, window: Window) -> WmResult<()> { |
| 1485 |
|
- // Try to send WM_DELETE_WINDOW message first (graceful close) |
| 1486 |
1522 |
if self.send_event(window, self.atoms.wm_delete_window)? { |
| 1487 |
|
- // Window supports WM_DELETE_WINDOW, it will close gracefully |
| 1488 |
1523 |
self.connection.flush()?; |
| 1489 |
1524 |
} else { |
| 1490 |
|
- // Window doesn't support WM_DELETE_WINDOW, forcefully kill it |
| 1491 |
1525 |
eprintln!("Window {} doesn't support WM_DELETE_WINDOW, killing forcefully", window); |
| 1492 |
1526 |
self.connection.kill_client(window)?; |
| 1493 |
1527 |
self.connection.flush()?; |
|
|
@@ -1496,7 +1530,6 @@ impl WindowManager { |
| 1496 |
1530 |
} |
| 1497 |
1531 |
|
| 1498 |
1532 |
fn send_event(&self, window: Window, protocol: Atom) -> WmResult<bool> { |
| 1499 |
|
- // Check if the window supports this protocol |
| 1500 |
1533 |
let protocols_reply = self.connection.get_property( |
| 1501 |
1534 |
false, |
| 1502 |
1535 |
window, |
|
|
@@ -1521,7 +1554,6 @@ impl WindowManager { |
| 1521 |
1554 |
return Ok(false); |
| 1522 |
1555 |
} |
| 1523 |
1556 |
|
| 1524 |
|
- // Send a ClientMessage event |
| 1525 |
1557 |
let event = x11rb::protocol::xproto::ClientMessageEvent { |
| 1526 |
1558 |
response_type: x11rb::protocol::xproto::CLIENT_MESSAGE_EVENT, |
| 1527 |
1559 |
format: 32, |
|
|
@@ -1736,8 +1768,8 @@ impl WindowManager { |
| 1736 |
1768 |
Ok(()) |
| 1737 |
1769 |
} |
| 1738 |
1770 |
|
| 1739 |
|
- fn is_transient_window(&self, window: Window) -> bool { |
| 1740 |
|
- let transient_for = self.connection |
|
1771 |
+ fn get_transient_parent(&self, window: Window) -> Option<Window> { |
|
1772 |
+ self.connection |
| 1741 |
1773 |
.get_property( |
| 1742 |
1774 |
false, |
| 1743 |
1775 |
window, |
|
|
@@ -1748,9 +1780,233 @@ impl WindowManager { |
| 1748 |
1780 |
) |
| 1749 |
1781 |
.ok() |
| 1750 |
1782 |
.and_then(|cookie| cookie.reply().ok()) |
| 1751 |
|
- .filter(|reply| !reply.value.is_empty()); |
|
1783 |
+ .filter(|reply| !reply.value.is_empty()) |
|
1784 |
+ .and_then(|reply| { |
|
1785 |
+ if reply.value.len() >= 4 { |
|
1786 |
+ let parent_window = u32::from_ne_bytes([ |
|
1787 |
+ reply.value[0], |
|
1788 |
+ reply.value[1], |
|
1789 |
+ reply.value[2], |
|
1790 |
+ reply.value[3], |
|
1791 |
+ ]); |
|
1792 |
+ Some(parent_window) |
|
1793 |
+ } else { |
|
1794 |
+ None |
|
1795 |
+ } |
|
1796 |
+ }) |
|
1797 |
+ } |
|
1798 |
+ |
|
1799 |
+ fn is_transient_window(&self, window: Window) -> bool { |
|
1800 |
+ self.get_transient_parent(window).is_some() |
|
1801 |
+ } |
|
1802 |
+ |
|
1803 |
+ fn is_dialog_window(&self, window: Window) -> bool { |
|
1804 |
+ let window_type_property = self.connection |
|
1805 |
+ .get_property( |
|
1806 |
+ false, |
|
1807 |
+ window, |
|
1808 |
+ self.atoms.net_wm_window_type, |
|
1809 |
+ AtomEnum::ATOM, |
|
1810 |
+ 0, |
|
1811 |
+ 32, |
|
1812 |
+ ) |
|
1813 |
+ .ok() |
|
1814 |
+ .and_then(|cookie| cookie.reply().ok()); |
|
1815 |
+ |
|
1816 |
+ if let Some(reply) = window_type_property { |
|
1817 |
+ let atoms: Vec<Atom> = reply |
|
1818 |
+ .value |
|
1819 |
+ .chunks_exact(4) |
|
1820 |
+ .map(|chunk| u32::from_ne_bytes([chunk[0], chunk[1], chunk[2], chunk[3]])) |
|
1821 |
+ .collect(); |
|
1822 |
+ |
|
1823 |
+ atoms.contains(&self.atoms.net_wm_window_type_dialog) |
|
1824 |
+ } else { |
|
1825 |
+ false |
|
1826 |
+ } |
|
1827 |
+ } |
|
1828 |
+ |
|
1829 |
+ fn get_window_class(&self, window: Window) -> Option<String> { |
|
1830 |
+ self.connection |
|
1831 |
+ .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024) |
|
1832 |
+ .ok() |
|
1833 |
+ .and_then(|cookie| cookie.reply().ok()) |
|
1834 |
+ .and_then(|reply| { |
|
1835 |
+ if reply.value.is_empty() { |
|
1836 |
+ None |
|
1837 |
+ } else { |
|
1838 |
+ std::str::from_utf8(&reply.value).ok().map(|s| { |
|
1839 |
+ s.split('\0').nth(1).unwrap_or(s.split('\0').next().unwrap_or("")).to_string() |
|
1840 |
+ }) |
|
1841 |
+ } |
|
1842 |
+ }) |
|
1843 |
+ } |
|
1844 |
+ |
|
1845 |
+ fn manage_window(&mut self, window: Window) -> WmResult<()> { |
|
1846 |
+ let geometry = self.connection.get_geometry(window)?.reply()?; |
|
1847 |
+ let mut window_x = geometry.x as i32; |
|
1848 |
+ let mut window_y = geometry.y as i32; |
|
1849 |
+ let window_width = geometry.width as u32; |
|
1850 |
+ let window_height = geometry.height as u32; |
|
1851 |
+ |
|
1852 |
+ let transient_parent = self.get_transient_parent(window); |
|
1853 |
+ let (window_tags, monitor_index) = if let Some(parent) = transient_parent { |
|
1854 |
+ let parent_tags = self.window_tags.get(&parent).copied().unwrap_or_else(|| { |
|
1855 |
+ self.monitors |
|
1856 |
+ .get(self.selected_monitor) |
|
1857 |
+ .map(|m| m.selected_tags) |
|
1858 |
+ .unwrap_or(tag_mask(0)) |
|
1859 |
+ }); |
|
1860 |
+ let parent_monitor = self.window_monitor.get(&parent).copied().unwrap_or(self.selected_monitor); |
|
1861 |
+ (parent_tags, parent_monitor) |
|
1862 |
+ } else { |
|
1863 |
+ let selected_tags = self.monitors |
|
1864 |
+ .get(self.selected_monitor) |
|
1865 |
+ .map(|m| m.selected_tags) |
|
1866 |
+ .unwrap_or(tag_mask(0)); |
|
1867 |
+ (selected_tags, self.selected_monitor) |
|
1868 |
+ }; |
|
1869 |
+ |
|
1870 |
+ let monitor = self.monitors[monitor_index].clone(); |
|
1871 |
+ let border_width = self.config.border_width; |
|
1872 |
+ |
|
1873 |
+ if window_x + (window_width as i32) + (2 * border_width as i32) > monitor.x + monitor.width as i32 { |
|
1874 |
+ window_x = monitor.x + monitor.width as i32 - (window_width as i32) - (2 * border_width as i32); |
|
1875 |
+ } |
|
1876 |
+ if window_y + (window_height as i32) + (2 * border_width as i32) > monitor.y + monitor.height as i32 { |
|
1877 |
+ window_y = monitor.y + monitor.height as i32 - (window_height as i32) - (2 * border_width as i32); |
|
1878 |
+ } |
|
1879 |
+ window_x = window_x.max(monitor.x); |
|
1880 |
+ window_y = window_y.max(monitor.y); |
|
1881 |
+ |
|
1882 |
+ let is_transient = transient_parent.is_some(); |
|
1883 |
+ let is_dialog = self.is_dialog_window(window); |
|
1884 |
+ |
|
1885 |
+ let class_name = self.get_window_class(window).unwrap_or_default(); |
|
1886 |
+ eprintln!("MapRequest 0x{:x}: class='{}' size={}x{} pos=({},{}) transient={} dialog={}", |
|
1887 |
+ window, class_name, window_width, window_height, window_x, window_y, is_transient, is_dialog); |
|
1888 |
+ |
|
1889 |
+ let off_screen_x = window_x + (2 * self.screen.width_in_pixels as i32); |
|
1890 |
+ |
|
1891 |
+ self.connection.configure_window( |
|
1892 |
+ window, |
|
1893 |
+ &ConfigureWindowAux::new() |
|
1894 |
+ .x(off_screen_x) |
|
1895 |
+ .y(window_y) |
|
1896 |
+ .width(window_width) |
|
1897 |
+ .height(window_height) |
|
1898 |
+ .border_width(border_width) |
|
1899 |
+ )?; |
|
1900 |
+ |
|
1901 |
+ self.connection.change_window_attributes( |
|
1902 |
+ window, |
|
1903 |
+ &ChangeWindowAttributesAux::new().event_mask( |
|
1904 |
+ EventMask::ENTER_WINDOW | EventMask::STRUCTURE_NOTIFY | EventMask::PROPERTY_CHANGE |
|
1905 |
+ ), |
|
1906 |
+ )?; |
|
1907 |
+ |
|
1908 |
+ self.windows.push(window); |
|
1909 |
+ self.window_tags.insert(window, window_tags); |
|
1910 |
+ self.window_monitor.insert(window, monitor_index); |
|
1911 |
+ |
|
1912 |
+ if is_transient || is_dialog { |
|
1913 |
+ self.floating_windows.insert(window); |
|
1914 |
+ |
|
1915 |
+ let (center_x, center_y) = if let Some(parent) = transient_parent { |
|
1916 |
+ if let Ok(parent_geom) = self.connection.get_geometry(parent)?.reply() { |
|
1917 |
+ let parent_center_x = parent_geom.x as i32 + (parent_geom.width as i32 / 2); |
|
1918 |
+ let parent_center_y = parent_geom.y as i32 + (parent_geom.height as i32 / 2); |
|
1919 |
+ (parent_center_x, parent_center_y) |
|
1920 |
+ } else { |
|
1921 |
+ let monitor_center_x = monitor.x + (monitor.width as i32 / 2); |
|
1922 |
+ let monitor_center_y = monitor.y + (monitor.height as i32 / 2); |
|
1923 |
+ (monitor_center_x, monitor_center_y) |
|
1924 |
+ } |
|
1925 |
+ } else { |
|
1926 |
+ let monitor_center_x = monitor.x + (monitor.width as i32 / 2); |
|
1927 |
+ let monitor_center_y = monitor.y + (monitor.height as i32 / 2); |
|
1928 |
+ (monitor_center_x, monitor_center_y) |
|
1929 |
+ }; |
|
1930 |
+ |
|
1931 |
+ let positioned_x = center_x - (window_width as i32 / 2); |
|
1932 |
+ let positioned_y = center_y - (window_height as i32 / 2); |
|
1933 |
+ |
|
1934 |
+ let clamped_x = positioned_x |
|
1935 |
+ .max(monitor.x) |
|
1936 |
+ .min(monitor.x + monitor.width as i32 - window_width as i32); |
|
1937 |
+ let clamped_y = positioned_y |
|
1938 |
+ .max(monitor.y) |
|
1939 |
+ .min(monitor.y + monitor.height as i32 - window_height as i32); |
|
1940 |
+ |
|
1941 |
+ self.update_geometry_cache(window, CachedGeometry { |
|
1942 |
+ x_position: clamped_x as i16, |
|
1943 |
+ y_position: clamped_y as i16, |
|
1944 |
+ width: window_width as u16, |
|
1945 |
+ height: window_height as u16, |
|
1946 |
+ border_width: border_width as u16, |
|
1947 |
+ }); |
|
1948 |
+ |
|
1949 |
+ self.connection.configure_window( |
|
1950 |
+ window, |
|
1951 |
+ &ConfigureWindowAux::new() |
|
1952 |
+ .x(clamped_x) |
|
1953 |
+ .y(clamped_y) |
|
1954 |
+ .width(window_width) |
|
1955 |
+ .height(window_height) |
|
1956 |
+ .border_width(border_width) |
|
1957 |
+ .stack_mode(StackMode::ABOVE), |
|
1958 |
+ )?; |
|
1959 |
+ } |
|
1960 |
+ |
|
1961 |
+ let is_normie_layout = self.layout.name() == "normie"; |
|
1962 |
+ if is_normie_layout && !is_transient && !is_dialog { |
|
1963 |
+ if let Ok(pointer) = self.connection.query_pointer(self.root)?.reply() { |
|
1964 |
+ let cursor_monitor = self.get_monitor_at_point(pointer.root_x as i32, pointer.root_y as i32) |
|
1965 |
+ .and_then(|idx| self.monitors.get(idx)) |
|
1966 |
+ .unwrap_or(&monitor); |
|
1967 |
+ |
|
1968 |
+ let float_width = (cursor_monitor.width as f32 * 0.6) as u32; |
|
1969 |
+ let float_height = (cursor_monitor.height as f32 * 0.6) as u32; |
|
1970 |
+ let spawn_x = pointer.root_x as i32 - (float_width as i32 / 2); |
|
1971 |
+ let spawn_y = pointer.root_y as i32 - (float_height as i32 / 2); |
|
1972 |
+ |
|
1973 |
+ let clamped_x = spawn_x |
|
1974 |
+ .max(cursor_monitor.x) |
|
1975 |
+ .min(cursor_monitor.x + cursor_monitor.width as i32 - float_width as i32); |
|
1976 |
+ let clamped_y = spawn_y |
|
1977 |
+ .max(cursor_monitor.y) |
|
1978 |
+ .min(cursor_monitor.y + cursor_monitor.height as i32 - float_height as i32); |
|
1979 |
+ |
|
1980 |
+ self.connection.configure_window( |
|
1981 |
+ window, |
|
1982 |
+ &ConfigureWindowAux::new() |
|
1983 |
+ .x(clamped_x) |
|
1984 |
+ .y(clamped_y) |
|
1985 |
+ .width(float_width) |
|
1986 |
+ .height(float_height) |
|
1987 |
+ .border_width(border_width) |
|
1988 |
+ .stack_mode(StackMode::ABOVE), |
|
1989 |
+ )?; |
|
1990 |
+ |
|
1991 |
+ self.floating_windows.insert(window); |
|
1992 |
+ } |
|
1993 |
+ } |
|
1994 |
+ |
|
1995 |
+ self.set_wm_state(window, 1)?; |
|
1996 |
+ if let Err(error) = self.save_client_tag(window, window_tags) { |
|
1997 |
+ eprintln!("Failed to save client tag for new window: {:?}", error); |
|
1998 |
+ } |
|
1999 |
+ |
|
2000 |
+ self.apply_layout()?; |
|
2001 |
+ self.connection.map_window(window)?; |
|
2002 |
+ self.update_bar()?; |
|
2003 |
+ self.set_focus(window)?; |
|
2004 |
+ |
|
2005 |
+ if self.layout.name() == "tabbed" { |
|
2006 |
+ self.update_tab_bars()?; |
|
2007 |
+ } |
| 1752 |
2008 |
|
| 1753 |
|
- transient_for.is_some() |
|
2009 |
+ Ok(()) |
| 1754 |
2010 |
} |
| 1755 |
2011 |
|
| 1756 |
2012 |
pub fn set_focus(&mut self, window: Window) -> WmResult<()> { |
|
|
@@ -2000,88 +2256,8 @@ impl WindowManager { |
| 2000 |
2256 |
return Ok(None); |
| 2001 |
2257 |
} |
| 2002 |
2258 |
|
| 2003 |
|
- if self.windows.contains(&event.window) { |
| 2004 |
|
- return Ok(None); |
| 2005 |
|
- } |
| 2006 |
|
- |
| 2007 |
|
- self.connection.map_window(event.window)?; |
| 2008 |
|
- self.connection.change_window_attributes( |
| 2009 |
|
- event.window, |
| 2010 |
|
- &ChangeWindowAttributesAux::new().event_mask(EventMask::ENTER_WINDOW | EventMask::STRUCTURE_NOTIFY | EventMask::PROPERTY_CHANGE), |
| 2011 |
|
- )?; |
| 2012 |
|
- |
| 2013 |
|
- let selected_tags = self |
| 2014 |
|
- .monitors |
| 2015 |
|
- .get(self.selected_monitor) |
| 2016 |
|
- .map(|m| m.selected_tags) |
| 2017 |
|
- .unwrap_or(tag_mask(0)); |
| 2018 |
|
- |
| 2019 |
|
- self.windows.push(event.window); |
| 2020 |
|
- self.window_tags.insert(event.window, selected_tags); |
| 2021 |
|
- self.window_monitor |
| 2022 |
|
- .insert(event.window, self.selected_monitor); |
| 2023 |
|
- self.set_wm_state(event.window, 1)?; |
| 2024 |
|
- if let Err(error) = self.save_client_tag(event.window, selected_tags) { |
| 2025 |
|
- eprintln!("Failed to save client tag for new window: {:?}", error); |
| 2026 |
|
- } |
| 2027 |
|
- |
| 2028 |
|
- let is_transient = self.is_transient_window(event.window); |
| 2029 |
|
- if is_transient { |
| 2030 |
|
- self.floating_windows.insert(event.window); |
| 2031 |
|
- } |
| 2032 |
|
- |
| 2033 |
|
- let is_normie_layout = self.layout.name() == "normie"; |
| 2034 |
|
- if is_normie_layout && !is_transient { |
| 2035 |
|
- let mut pointer_x: i32 = 0; |
| 2036 |
|
- let mut pointer_y: i32 = 0; |
| 2037 |
|
- let mut root_return: x11::xlib::Window = 0; |
| 2038 |
|
- let mut child_return: x11::xlib::Window = 0; |
| 2039 |
|
- let mut win_x: i32 = 0; |
| 2040 |
|
- let mut win_y: i32 = 0; |
| 2041 |
|
- let mut mask_return: u32 = 0; |
| 2042 |
|
- |
| 2043 |
|
- let pointer_queried = unsafe { |
| 2044 |
|
- x11::xlib::XQueryPointer( |
| 2045 |
|
- self.display, |
| 2046 |
|
- self.root as x11::xlib::Window, |
| 2047 |
|
- &mut root_return, |
| 2048 |
|
- &mut child_return, |
| 2049 |
|
- &mut pointer_x, |
| 2050 |
|
- &mut pointer_y, |
| 2051 |
|
- &mut win_x, |
| 2052 |
|
- &mut win_y, |
| 2053 |
|
- &mut mask_return, |
| 2054 |
|
- ) != 0 |
| 2055 |
|
- }; |
| 2056 |
|
- |
| 2057 |
|
- if pointer_queried { |
| 2058 |
|
- let window_width = (self.screen.width_in_pixels as f32 * 0.6) as u32; |
| 2059 |
|
- let window_height = (self.screen.height_in_pixels as f32 * 0.6) as u32; |
| 2060 |
|
- |
| 2061 |
|
- let spawn_x = pointer_x - (window_width as i32 / 2); |
| 2062 |
|
- let spawn_y = pointer_y - (window_height as i32 / 2); |
| 2063 |
|
- |
| 2064 |
|
- self.connection.configure_window( |
| 2065 |
|
- event.window, |
| 2066 |
|
- &ConfigureWindowAux::new() |
| 2067 |
|
- .x(spawn_x) |
| 2068 |
|
- .y(spawn_y) |
| 2069 |
|
- .width(window_width) |
| 2070 |
|
- .height(window_height) |
| 2071 |
|
- .border_width(self.config.border_width) |
| 2072 |
|
- .stack_mode(StackMode::ABOVE), |
| 2073 |
|
- )?; |
| 2074 |
|
- |
| 2075 |
|
- self.floating_windows.insert(event.window); |
| 2076 |
|
- } |
| 2077 |
|
- } |
| 2078 |
|
- |
| 2079 |
|
- self.apply_layout()?; |
| 2080 |
|
- self.update_bar()?; |
| 2081 |
|
- self.set_focus(event.window)?; |
| 2082 |
|
- |
| 2083 |
|
- if self.layout.name() == "tabbed" { |
| 2084 |
|
- self.update_tab_bars()?; |
|
2259 |
+ if !self.windows.contains(&event.window) { |
|
2260 |
+ self.manage_window(event.window)?; |
| 2085 |
2261 |
} |
| 2086 |
2262 |
} |
| 2087 |
2263 |
Event::UnmapNotify(event) => { |
|
|
@@ -2099,6 +2275,12 @@ impl WindowManager { |
| 2099 |
2275 |
return Ok(None); |
| 2100 |
2276 |
} |
| 2101 |
2277 |
if self.windows.contains(&event.event) { |
|
2278 |
+ if let Some(&window_monitor_index) = self.window_monitor.get(&event.event) { |
|
2279 |
+ if window_monitor_index != self.selected_monitor { |
|
2280 |
+ self.selected_monitor = window_monitor_index; |
|
2281 |
+ self.update_bar()?; |
|
2282 |
+ } |
|
2283 |
+ } |
| 2102 |
2284 |
self.set_focus(event.event)?; |
| 2103 |
2285 |
} |
| 2104 |
2286 |
} |
|
|
@@ -2272,6 +2454,111 @@ impl WindowManager { |
| 2272 |
2454 |
} |
| 2273 |
2455 |
} |
| 2274 |
2456 |
} |
|
2457 |
+ Event::ConfigureRequest(event) => { |
|
2458 |
+ if self.windows.contains(&event.window) { |
|
2459 |
+ let monitor_index = *self.window_monitor.get(&event.window).unwrap_or(&self.selected_monitor); |
|
2460 |
+ let monitor = &self.monitors[monitor_index]; |
|
2461 |
+ let is_floating = self.floating_windows.contains(&event.window); |
|
2462 |
+ let is_tiling_layout = self.layout.name() != "normie"; |
|
2463 |
+ |
|
2464 |
+ if is_floating || !is_tiling_layout { |
|
2465 |
+ let cached_geom = self.window_geometry_cache.get(&event.window); |
|
2466 |
+ let border_width = self.config.border_width as u16; |
|
2467 |
+ |
|
2468 |
+ let mut config = ConfigureWindowAux::new(); |
|
2469 |
+ let value_mask = event.value_mask; |
|
2470 |
+ |
|
2471 |
+ if value_mask.contains(ConfigWindow::BORDER_WIDTH) { |
|
2472 |
+ config = config.border_width(event.border_width as u32); |
|
2473 |
+ } |
|
2474 |
+ |
|
2475 |
+ if value_mask.contains(ConfigWindow::X) { |
|
2476 |
+ let mut x = event.x as i32; |
|
2477 |
+ x = x.max(monitor.x); |
|
2478 |
+ if x + event.width as i32 + 2 * border_width as i32 > monitor.x + monitor.width as i32 { |
|
2479 |
+ x = monitor.x + monitor.width as i32 - event.width as i32 - 2 * border_width as i32; |
|
2480 |
+ } |
|
2481 |
+ config = config.x(x); |
|
2482 |
+ } |
|
2483 |
+ |
|
2484 |
+ if value_mask.contains(ConfigWindow::Y) { |
|
2485 |
+ let mut y = event.y as i32; |
|
2486 |
+ y = y.max(monitor.y); |
|
2487 |
+ if y + event.height as i32 + 2 * border_width as i32 > monitor.y + monitor.height as i32 { |
|
2488 |
+ y = monitor.y + monitor.height as i32 - event.height as i32 - 2 * border_width as i32; |
|
2489 |
+ } |
|
2490 |
+ config = config.y(y); |
|
2491 |
+ } |
|
2492 |
+ |
|
2493 |
+ if value_mask.contains(ConfigWindow::WIDTH) { |
|
2494 |
+ config = config.width(event.width as u32); |
|
2495 |
+ } |
|
2496 |
+ |
|
2497 |
+ if value_mask.contains(ConfigWindow::HEIGHT) { |
|
2498 |
+ config = config.height(event.height as u32); |
|
2499 |
+ } |
|
2500 |
+ |
|
2501 |
+ if value_mask.contains(ConfigWindow::SIBLING) { |
|
2502 |
+ config = config.sibling(event.sibling); |
|
2503 |
+ } |
|
2504 |
+ |
|
2505 |
+ if value_mask.contains(ConfigWindow::STACK_MODE) { |
|
2506 |
+ config = config.stack_mode(event.stack_mode); |
|
2507 |
+ } |
|
2508 |
+ |
|
2509 |
+ self.connection.configure_window(event.window, &config)?; |
|
2510 |
+ |
|
2511 |
+ let final_x = if value_mask.contains(ConfigWindow::X) { |
|
2512 |
+ let mut x = event.x as i32; |
|
2513 |
+ x = x.max(monitor.x); |
|
2514 |
+ if x + event.width as i32 + 2 * border_width as i32 > monitor.x + monitor.width as i32 { |
|
2515 |
+ x = monitor.x + monitor.width as i32 - event.width as i32 - 2 * border_width as i32; |
|
2516 |
+ } |
|
2517 |
+ x as i16 |
|
2518 |
+ } else { |
|
2519 |
+ cached_geom.map(|g| g.x_position).unwrap_or(0) |
|
2520 |
+ }; |
|
2521 |
+ |
|
2522 |
+ let final_y = if value_mask.contains(ConfigWindow::Y) { |
|
2523 |
+ let mut y = event.y as i32; |
|
2524 |
+ y = y.max(monitor.y); |
|
2525 |
+ if y + event.height as i32 + 2 * border_width as i32 > monitor.y + monitor.height as i32 { |
|
2526 |
+ y = monitor.y + monitor.height as i32 - event.height as i32 - 2 * border_width as i32; |
|
2527 |
+ } |
|
2528 |
+ y as i16 |
|
2529 |
+ } else { |
|
2530 |
+ cached_geom.map(|g| g.y_position).unwrap_or(0) |
|
2531 |
+ }; |
|
2532 |
+ |
|
2533 |
+ self.update_geometry_cache(event.window, CachedGeometry { |
|
2534 |
+ x_position: final_x, |
|
2535 |
+ y_position: final_y, |
|
2536 |
+ width: if value_mask.contains(ConfigWindow::WIDTH) { event.width } else { cached_geom.map(|g| g.width).unwrap_or(1) }, |
|
2537 |
+ height: if value_mask.contains(ConfigWindow::HEIGHT) { event.height } else { cached_geom.map(|g| g.height).unwrap_or(1) }, |
|
2538 |
+ border_width: if value_mask.contains(ConfigWindow::BORDER_WIDTH) { event.border_width } else { border_width }, |
|
2539 |
+ }); |
|
2540 |
+ } else { |
|
2541 |
+ self.send_configure_notify(event.window)?; |
|
2542 |
+ } |
|
2543 |
+ } else { |
|
2544 |
+ let mut config = ConfigureWindowAux::new() |
|
2545 |
+ .x(event.x as i32) |
|
2546 |
+ .y(event.y as i32) |
|
2547 |
+ .width(event.width as u32) |
|
2548 |
+ .height(event.height as u32) |
|
2549 |
+ .border_width(event.border_width as u32); |
|
2550 |
+ |
|
2551 |
+ if event.value_mask.contains(ConfigWindow::SIBLING) { |
|
2552 |
+ config = config.sibling(event.sibling); |
|
2553 |
+ } |
|
2554 |
+ |
|
2555 |
+ if event.value_mask.contains(ConfigWindow::STACK_MODE) { |
|
2556 |
+ config = config.stack_mode(event.stack_mode); |
|
2557 |
+ } |
|
2558 |
+ |
|
2559 |
+ self.connection.configure_window(event.window, &config)?; |
|
2560 |
+ } |
|
2561 |
+ } |
| 2275 |
2562 |
Event::ClientMessage(event) => { |
| 2276 |
2563 |
if event.type_ == self.atoms.net_wm_state { |
| 2277 |
2564 |
if let Some(data) = event.data.as_data32().get(1) { |
|
|
@@ -2498,6 +2785,33 @@ impl WindowManager { |
| 2498 |
2785 |
Ok(cached) |
| 2499 |
2786 |
} |
| 2500 |
2787 |
|
|
2788 |
+ fn send_configure_notify(&mut self, window: Window) -> WmResult<()> { |
|
2789 |
+ let geometry = self.get_or_query_geometry(window)?; |
|
2790 |
+ |
|
2791 |
+ let event = x11rb::protocol::xproto::ConfigureNotifyEvent { |
|
2792 |
+ response_type: x11rb::protocol::xproto::CONFIGURE_NOTIFY_EVENT, |
|
2793 |
+ sequence: 0, |
|
2794 |
+ event: window, |
|
2795 |
+ window, |
|
2796 |
+ above_sibling: x11rb::NONE, |
|
2797 |
+ x: geometry.x_position, |
|
2798 |
+ y: geometry.y_position, |
|
2799 |
+ width: geometry.width, |
|
2800 |
+ height: geometry.height, |
|
2801 |
+ border_width: geometry.border_width, |
|
2802 |
+ override_redirect: false, |
|
2803 |
+ }; |
|
2804 |
+ |
|
2805 |
+ self.connection.send_event( |
|
2806 |
+ false, |
|
2807 |
+ window, |
|
2808 |
+ x11rb::protocol::xproto::EventMask::STRUCTURE_NOTIFY, |
|
2809 |
+ event, |
|
2810 |
+ )?; |
|
2811 |
+ |
|
2812 |
+ Ok(()) |
|
2813 |
+ } |
|
2814 |
+ |
| 2501 |
2815 |
fn remove_window(&mut self, window: Window) -> WmResult<()> { |
| 2502 |
2816 |
let initial_count = self.windows.len(); |
| 2503 |
2817 |
|