tony / oxwm

Added comboview logic from dwm, and added sticky tag view from dwm. updated logic so clients move offscreen instead of stay stored in respective tags. Browse files
tonybtw committed 2025-12-01 parent 23d144c commit fdbc8815968e9025ce980f05130443f4541b0bb2
Showing 5 changed files with 219 additions and 18 deletions. UnifiedSplit
+26 −0 resources/test-config.lua
@@ -94,6 +94,7 @@ oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down"))
94 94 oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up"))
95 95 oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right"))
96 96
97 +-- View tag (switch workspace)
97 98 oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
98 99 oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1))
99 100 oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2))
@@ -104,6 +105,7 @@ oxwm.key.bind({ modkey }, "7", oxwm.tag.view(6))
104 105 oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7))
105 106 oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8))
106 107
108 +-- Move window to tag
107 109 oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0))
108 110 oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1))
109 111 oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2))
@@ -114,6 +116,30 @@ oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(6))
114 116 oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7))
115 117 oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8))
116 118
119 +-- Toggle view (view multiple tags at once) - dwm-style multi-tag viewing
120 +-- Example: Mod+Ctrl+2 while on tag 1 will show BOTH tags 1 and 2
121 +oxwm.key.bind({ modkey, "Control" }, "1", oxwm.tag.toggleview(0))
122 +oxwm.key.bind({ modkey, "Control" }, "2", oxwm.tag.toggleview(1))
123 +oxwm.key.bind({ modkey, "Control" }, "3", oxwm.tag.toggleview(2))
124 +oxwm.key.bind({ modkey, "Control" }, "4", oxwm.tag.toggleview(3))
125 +oxwm.key.bind({ modkey, "Control" }, "5", oxwm.tag.toggleview(4))
126 +oxwm.key.bind({ modkey, "Control" }, "6", oxwm.tag.toggleview(5))
127 +oxwm.key.bind({ modkey, "Control" }, "7", oxwm.tag.toggleview(6))
128 +oxwm.key.bind({ modkey, "Control" }, "8", oxwm.tag.toggleview(7))
129 +oxwm.key.bind({ modkey, "Control" }, "9", oxwm.tag.toggleview(8))
130 +
131 +-- Toggle tag (window on multiple tags) - dwm-style sticky windows
132 +-- Example: Mod+Ctrl+Shift+2 puts focused window on BOTH current tag and tag 2
133 +oxwm.key.bind({ modkey, "Control", "Shift" }, "1", oxwm.tag.toggletag(0))
134 +oxwm.key.bind({ modkey, "Control", "Shift" }, "2", oxwm.tag.toggletag(1))
135 +oxwm.key.bind({ modkey, "Control", "Shift" }, "3", oxwm.tag.toggletag(2))
136 +oxwm.key.bind({ modkey, "Control", "Shift" }, "4", oxwm.tag.toggletag(3))
137 +oxwm.key.bind({ modkey, "Control", "Shift" }, "5", oxwm.tag.toggletag(4))
138 +oxwm.key.bind({ modkey, "Control", "Shift" }, "6", oxwm.tag.toggletag(5))
139 +oxwm.key.bind({ modkey, "Control", "Shift" }, "7", oxwm.tag.toggletag(6))
140 +oxwm.key.bind({ modkey, "Control", "Shift" }, "8", oxwm.tag.toggletag(7))
141 +oxwm.key.bind({ modkey, "Control", "Shift" }, "9", oxwm.tag.toggletag(8))
142 +
117 143 oxwm.bar.set_blocks({
118 144 oxwm.bar.block.battery({
119 145 format = "Bat: {}%",
+13 −1 src/config/lua_api.rs
@@ -301,12 +301,22 @@ fn register_tag_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
301 301 create_action_table(lua, "ViewTag", Value::Integer(idx as i64))
302 302 })?;
303 303
304 + let toggleview = lua.create_function(|lua, idx: i32| {
305 + create_action_table(lua, "ToggleView", Value::Integer(idx as i64))
306 + })?;
307 +
304 308 let move_to = lua.create_function(|lua, idx: i32| {
305 309 create_action_table(lua, "MoveToTag", Value::Integer(idx as i64))
306 310 })?;
307 311
312 + let toggletag = lua.create_function(|lua, idx: i32| {
313 + create_action_table(lua, "ToggleTag", Value::Integer(idx as i64))
314 + })?;
315 +
308 316 tag_table.set("view", view)?;
317 + tag_table.set("toggleview", toggleview)?;
309 318 tag_table.set("move_to", move_to)?;
319 + tag_table.set("toggletag", toggletag)?;
310 320 parent.set("tag", tag_table)?;
311 321 Ok(())
312 322 }
@@ -726,6 +736,9 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
726 736 "Restart" => Ok(KeyAction::Restart),
727 737 "Recompile" => Ok(KeyAction::Recompile),
728 738 "ViewTag" => Ok(KeyAction::ViewTag),
739 + "ToggleView" => Ok(KeyAction::ToggleView),
740 + "MoveToTag" => Ok(KeyAction::MoveToTag),
741 + "ToggleTag" => Ok(KeyAction::ToggleTag),
729 742 "ToggleGaps" => Ok(KeyAction::ToggleGaps),
730 743 "SetMasterFactor" => Ok(KeyAction::SetMasterFactor),
731 744 "IncNumMaster" => Ok(KeyAction::IncNumMaster),
@@ -733,7 +746,6 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
733 746 "ToggleFloating" => Ok(KeyAction::ToggleFloating),
734 747 "ChangeLayout" => Ok(KeyAction::ChangeLayout),
735 748 "CycleLayout" => Ok(KeyAction::CycleLayout),
736 - "MoveToTag" => Ok(KeyAction::MoveToTag),
737 749 "FocusMonitor" => Ok(KeyAction::FocusMonitor),
738 750 "ExchangeClient" => Ok(KeyAction::ExchangeClient),
739 751 "ShowKeybindOverlay" => Ok(KeyAction::ShowKeybindOverlay),
+3 −1 src/keyboard/handlers.rs
@@ -21,12 +21,14 @@ pub enum KeyAction {
21 21 Restart,
22 22 Recompile,
23 23 ViewTag,
24 + ToggleView,
25 + MoveToTag,
26 + ToggleTag,
24 27 ToggleGaps,
25 28 ToggleFullScreen,
26 29 ToggleFloating,
27 30 ChangeLayout,
28 31 CycleLayout,
29 - MoveToTag,
30 32 FocusMonitor,
31 33 ExchangeClient,
32 34 ShowKeybindOverlay,
+5 −0 src/overlay/keybind.rs
@@ -209,7 +209,12 @@ impl KeybindOverlay {
209 209 Arg::Int(n) => format!("View Workspace {}", n),
210 210 _ => "View Workspace".to_string(),
211 211 },
212 + KeyAction::ToggleView => match &binding.arg {
213 + Arg::Int(n) => format!("Toggle View Workspace {}", n),
214 + _ => "Toggle View Workspace".to_string(),
215 + },
212 216 KeyAction::MoveToTag => "Move Window to Workspace".to_string(),
217 + KeyAction::ToggleTag => "Toggle Window on Workspace".to_string(),
213 218 KeyAction::ToggleGaps => "Toggle Window Gaps".to_string(),
214 219 KeyAction::ToggleFullScreen => "Toggle Fullscreen Mode".to_string(),
215 220 KeyAction::ToggleFloating => "Toggle Floating Mode".to_string(),
+172 −16 src/window_manager.rs
@@ -900,11 +900,21 @@ impl WindowManager {
900 900 self.view_tag(*tag_index as usize)?;
901 901 }
902 902 }
903 + KeyAction::ToggleView => {
904 + if let Arg::Int(tag_index) = arg {
905 + self.toggleview(*tag_index as usize)?;
906 + }
907 + }
903 908 KeyAction::MoveToTag => {
904 909 if let Arg::Int(tag_index) = arg {
905 910 self.move_to_tag(*tag_index as usize)?;
906 911 }
907 912 }
913 + KeyAction::ToggleTag => {
914 + if let Arg::Int(tag_index) = arg {
915 + self.toggletag(*tag_index as usize)?;
916 + }
917 + }
908 918 KeyAction::ToggleGaps => {
909 919 self.gaps_enabled = !self.gaps_enabled;
910 920 self.apply_layout()?;
@@ -1041,25 +1051,112 @@ impl WindowManager {
1041 1051 Ok(())
1042 1052 }
1043 1053
1054 + fn showhide(&mut self, window: Option<Window>) -> WmResult<()> {
1055 + let Some(window) = window else {
1056 + return Ok(());
1057 + };
1058 +
1059 + let Some(client) = self.clients.get(&window).cloned() else {
1060 + return Ok(());
1061 + };
1062 +
1063 + let monitor = match self.monitors.get(client.monitor_index) {
1064 + Some(m) => m,
1065 + None => return Ok(()),
1066 + };
1067 +
1068 + let is_visible = (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0;
1069 +
1070 + if is_visible {
1071 + self.connection.configure_window(
1072 + window,
1073 + &ConfigureWindowAux::new()
1074 + .x(client.x_position as i32)
1075 + .y(client.y_position as i32),
1076 + )?;
1077 +
1078 + let is_floating = client.is_floating;
1079 + let is_fullscreen = client.is_fullscreen;
1080 + let has_no_layout = self.layout.name() == LayoutType::Normie.as_str();
1081 +
1082 + if (has_no_layout || is_floating) && !is_fullscreen {
1083 + self.connection.configure_window(
1084 + window,
1085 + &ConfigureWindowAux::new()
1086 + .x(client.x_position as i32)
1087 + .y(client.y_position as i32)
1088 + .width(client.width as u32)
1089 + .height(client.height as u32),
1090 + )?;
1091 + }
1092 +
1093 + self.showhide(client.stack_next)?;
1094 + } else {
1095 + self.showhide(client.stack_next)?;
1096 +
1097 + let width = client.width_with_border() as i32;
1098 + self.connection.configure_window(
1099 + window,
1100 + &ConfigureWindowAux::new()
1101 + .x(width * -2)
1102 + .y(client.y_position as i32),
1103 + )?;
1104 + }
1105 +
1106 + Ok(())
1107 + }
1108 +
1044 1109 pub fn view_tag(&mut self, tag_index: usize) -> WmResult<()> {
1045 1110 if tag_index >= self.config.tags.len() {
1046 1111 return Ok(());
1047 1112 }
1048 1113
1049 - if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
1050 - monitor.tagset[monitor.selected_tags_index] = tag_mask(tag_index);
1114 + let monitor = match self.monitors.get_mut(self.selected_monitor) {
1115 + Some(m) => m,
1116 + None => return Ok(()),
1117 + };
1118 +
1119 + let new_tagset = tag_mask(tag_index);
1120 +
1121 + if new_tagset == monitor.tagset[monitor.selected_tags_index] {
1122 + return Ok(());
1051 1123 }
1052 1124
1125 + monitor.selected_tags_index ^= 1;
1126 + monitor.tagset[monitor.selected_tags_index] = new_tagset;
1127 +
1053 1128 self.save_selected_tags()?;
1054 - self.update_window_visibility()?;
1055 - self.apply_layout()?;
1129 + self.focus(None)?;
1130 + self.apply_layout()?;
1056 1131 self.update_bar()?;
1057 1132
1058 - let visible = self.visible_windows_on_monitor(self.selected_monitor);
1059 - if let Some(&win) = visible.first() {
1060 - self.focus(Some(win))?;
1133 + Ok(())
1134 + }
1135 +
1136 + pub fn toggleview(&mut self, tag_index: usize) -> WmResult<()> {
1137 + if tag_index >= self.config.tags.len() {
1138 + return Ok(());
1061 1139 }
1062 1140
1141 + let monitor = match self.monitors.get_mut(self.selected_monitor) {
1142 + Some(m) => m,
1143 + None => return Ok(()),
1144 + };
1145 +
1146 + let mask = tag_mask(tag_index);
1147 + let new_tagset = monitor.tagset[monitor.selected_tags_index] ^ mask;
1148 +
1149 + if new_tagset == 0 {
1150 + return Ok(());
1151 + }
1152 +
1153 + monitor.tagset[monitor.selected_tags_index] = new_tagset;
1154 +
1155 + self.save_selected_tags()?;
1156 + self.focus(None)?;
1157 + self.apply_layout()?;
1158 + self.update_bar()?;
1159 +
1063 1160 Ok(())
1064 1161 }
1065 1162
@@ -1093,23 +1190,70 @@ impl WindowManager {
1093 1190 return Ok(());
1094 1191 }
1095 1192
1096 - if let Some(focused) = self
1193 + let focused = match self
1097 1194 .monitors
1098 1195 .get(self.selected_monitor)
1099 1196 .and_then(|m| m.selected_client)
1100 1197 {
1101 - let mask = tag_mask(tag_index);
1102 - self.window_tags.insert(focused, mask);
1198 + Some(win) => win,
1199 + None => return Ok(()),
1200 + };
1103 1201
1104 - if let Err(error) = self.save_client_tag(focused, mask) {
1105 - eprintln!("Failed to save client tag: {:?}", error);
1106 - }
1202 + let mask = tag_mask(tag_index);
1107 1203
1108 - self.update_window_visibility()?;
1109 - self.apply_layout()?;
1110 - self.update_bar()?;
1204 + if let Some(client) = self.clients.get_mut(&focused) {
1205 + client.tags = mask;
1206 + }
1207 +
1208 + self.window_tags.insert(focused, mask);
1209 +
1210 + if let Err(error) = self.save_client_tag(focused, mask) {
1211 + eprintln!("Failed to save client tag: {:?}", error);
1111 1212 }
1112 1213
1214 + self.focus(None)?;
1215 + self.apply_layout()?;
1216 + self.update_bar()?;
1217 +
1218 + Ok(())
1219 + }
1220 +
1221 + pub fn toggletag(&mut self, tag_index: usize) -> WmResult<()> {
1222 + if tag_index >= self.config.tags.len() {
1223 + return Ok(());
1224 + }
1225 +
1226 + let focused = match self
1227 + .monitors
1228 + .get(self.selected_monitor)
1229 + .and_then(|m| m.selected_client)
1230 + {
1231 + Some(win) => win,
1232 + None => return Ok(()),
1233 + };
1234 +
1235 + let mask = tag_mask(tag_index);
1236 + let current_tags = self.clients.get(&focused).map(|c| c.tags).unwrap_or(0);
1237 + let new_tags = current_tags ^ mask;
1238 +
1239 + if new_tags == 0 {
1240 + return Ok(());
1241 + }
1242 +
1243 + if let Some(client) = self.clients.get_mut(&focused) {
1244 + client.tags = new_tags;
1245 + }
1246 +
1247 + self.window_tags.insert(focused, new_tags);
1248 +
1249 + if let Err(error) = self.save_client_tag(focused, new_tags) {
1250 + eprintln!("Failed to save client tag: {:?}", error);
1251 + }
1252 +
1253 + self.focus(None)?;
1254 + self.apply_layout()?;
1255 + self.update_bar()?;
1256 +
1113 1257 Ok(())
1114 1258 }
1115 1259
@@ -2729,6 +2873,13 @@ impl WindowManager {
2729 2873 let adjusted_x = geometry.x_coordinate + monitor_x;
2730 2874 let adjusted_y = geometry.y_coordinate + monitor_y + bar_height as i32;
2731 2875
2876 + if let Some(client) = self.clients.get_mut(window) {
2877 + client.x_position = adjusted_x as i16;
2878 + client.y_position = adjusted_y as i16;
2879 + client.width = adjusted_width as u16;
2880 + client.height = adjusted_height as u16;
2881 + }
2882 +
2732 2883 self.connection.configure_window(
2733 2884 *window,
2734 2885 &ConfigureWindowAux::new()
@@ -2749,6 +2900,11 @@ impl WindowManager {
2749 2900 }
2750 2901 }
2751 2902
2903 + for monitor_index in 0..self.monitors.len() {
2904 + let stack_head = self.monitors[monitor_index].stack_head;
2905 + self.showhide(stack_head)?;
2906 + }
2907 +
2752 2908 self.connection.flush()?;
2753 2909
2754 2910 let is_tabbed = self.layout.name() == LayoutType::Tabbed.as_str();