tony / oxwm

Added window rules for floating, and tags similar to dwm. Browse files
tonybtw committed 2025-12-01 parent 3a6a48d commit 5767bfd3c104bf743d1faeff1eb7d8f2198f1b05
Showing 2 changed files with 43 additions and 2 deletions. UnifiedSplit
+1 −1 resources/test-config.lua
@@ -48,7 +48,7 @@ oxwm.gaps.set_outer(5, 5)
48 48
49 49 oxwm.rule.add({ class = "firefox", title = "Library", floating = true })
50 50 oxwm.rule.add({ instance = "gimp", tag = 5 })
51 -oxwm.rule.add({ class = "mpv", floating = true })
51 +oxwm.rule.add({ instance = "mpv", floating = true })
52 52
53 53 oxwm.bar.set_font("JetBrainsMono Nerd Font:style=Bold:size=12")
54 54
+42 −1 src/window_manager.rs
@@ -1980,6 +1980,9 @@ impl WindowManager {
1980 1980 self.apply_rules(window)?;
1981 1981
1982 1982 let updated_monitor_index = self.clients.get(&window).map(|c| c.monitor_index).unwrap_or(monitor_index);
1983 + let updated_monitor = self.monitors.get(updated_monitor_index).cloned().unwrap_or(monitor.clone());
1984 + let is_rule_floating = self.clients.get(&window).map(|c| c.is_floating).unwrap_or(false);
1985 +
1983 1986 self.attach_aside(window, updated_monitor_index);
1984 1987 self.attach_stack(window, updated_monitor_index);
1985 1988
@@ -2032,10 +2035,48 @@ impl WindowManager {
2032 2035 .border_width(border_width)
2033 2036 .stack_mode(StackMode::ABOVE),
2034 2037 )?;
2038 + } else if is_rule_floating && !is_transient && !is_dialog {
2039 + let mut adjusted_x = window_x;
2040 + let mut adjusted_y = window_y;
2041 +
2042 + if adjusted_x + (window_width as i32) + (2 * border_width as i32) > updated_monitor.screen_x + updated_monitor.screen_width as i32 {
2043 + adjusted_x = updated_monitor.screen_x + updated_monitor.screen_width as i32 - (window_width as i32) - (2 * border_width as i32);
2044 + }
2045 + if adjusted_y + (window_height as i32) + (2 * border_width as i32) > updated_monitor.screen_y + updated_monitor.screen_height as i32 {
2046 + adjusted_y = updated_monitor.screen_y + updated_monitor.screen_height as i32 - (window_height as i32) - (2 * border_width as i32);
2047 + }
2048 + adjusted_x = adjusted_x.max(updated_monitor.screen_x);
2049 + adjusted_y = adjusted_y.max(updated_monitor.screen_y);
2050 +
2051 + if let Some(client) = self.clients.get_mut(&window) {
2052 + client.x_position = adjusted_x as i16;
2053 + client.y_position = adjusted_y as i16;
2054 + client.width = window_width as u16;
2055 + client.height = window_height as u16;
2056 + }
2057 +
2058 + self.update_geometry_cache(window, CachedGeometry {
2059 + x_position: adjusted_x as i16,
2060 + y_position: adjusted_y as i16,
2061 + width: window_width as u16,
2062 + height: window_height as u16,
2063 + border_width: border_width as u16,
2064 + });
2065 +
2066 + self.connection.configure_window(
2067 + window,
2068 + &ConfigureWindowAux::new()
2069 + .x(adjusted_x)
2070 + .y(adjusted_y)
2071 + .width(window_width)
2072 + .height(window_height)
2073 + .border_width(border_width)
2074 + .stack_mode(StackMode::ABOVE),
2075 + )?;
2035 2076 }
2036 2077
2037 2078 let is_normie_layout = self.layout.name() == "normie";
2038 - if is_normie_layout && !is_transient && !is_dialog {
2079 + if is_normie_layout && !is_transient && !is_dialog && !is_rule_floating {
2039 2080 if let Ok(pointer) = self.connection.query_pointer(self.root)?.reply() {
2040 2081 let cursor_monitor = self.get_monitor_at_point(pointer.root_x as i32, pointer.root_y as i32)
2041 2082 .and_then(|idx| self.monitors.get(idx))