tony / oxwm

Merge pull request #44 from tonybanters/default-config-update Browse files
Tabbed Layout and NixOS Support for LSP File
Tony, btw. committed 2025-11-25 parents b23ed69 0fb0fff commit 8d0e55bcbc0b2b545393ea140c2bec1a68490fd7
Showing 12 changed files with 668 additions and 73 deletions. UnifiedSplit
+1 −1 Cargo.lock
@@ -291,7 +291,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
291 291
292 [[package]] 292 [[package]]
293 name = "oxwm" 293 name = "oxwm"
294 -version = "0.7.2" 294 +version = "0.7.3"
295 dependencies = [ 295 dependencies = [
296 "chrono", 296 "chrono",
297 "dirs", 297 "dirs",
+1 −1 Cargo.toml
@@ -1,6 +1,6 @@
1 [package] 1 [package]
2 name = "oxwm" 2 name = "oxwm"
3 -version = "0.7.2" 3 +version = "0.7.3"
4 edition = "2024" 4 edition = "2024"
5 5
6 [lib] 6 [lib]
+1 −0 default.nix
@@ -34,6 +34,7 @@ rustPlatform.buildRustPackage (finalAttrs: {
34 postInstall = '' 34 postInstall = ''
35 install resources/oxwm.desktop -Dt $out/share/xsessions 35 install resources/oxwm.desktop -Dt $out/share/xsessions
36 install -Dm644 resources/oxwm.1 -t $out/share/man/man1 36 install -Dm644 resources/oxwm.1 -t $out/share/man/man1
37 + install -Dm644 templates/oxwm.lua -t $out/share/oxwm
37 ''; 38 '';
38 39
39 passthru.providedSessions = ["oxwm"]; 40 passthru.providedSessions = ["oxwm"];
+28 −9 src/bin/main.rs
@@ -72,8 +72,6 @@ fn load_config(custom_path: Option<PathBuf>) -> Result<(oxwm::Config, bool), Box
72 println!(" Please manually port your configuration to the new Lua format."); 72 println!(" Please manually port your configuration to the new Lua format.");
73 println!(" See the new config.lua template for examples.\n"); 73 println!(" See the new config.lua template for examples.\n");
74 } 74 }
75 - } else {
76 - update_lsp_files()?;
77 } 75 }
78 76
79 lua_path 77 lua_path
@@ -116,19 +114,40 @@ fn init_config() -> Result<(), Box<dyn std::error::Error>> {
116 fn update_lsp_files() -> Result<(), Box<dyn std::error::Error>> { 114 fn update_lsp_files() -> Result<(), Box<dyn std::error::Error>> {
117 let config_directory = get_config_path(); 115 let config_directory = get_config_path();
118 116
119 - let library_directory = config_directory.join("lib"); 117 + let system_paths = [
120 - std::fs::create_dir_all(&library_directory)?; 118 + PathBuf::from("/usr/share/oxwm/oxwm.lua"),
119 + PathBuf::from("/usr/local/share/oxwm/oxwm.lua"),
120 + ];
121 121
122 - let oxwm_lua_template = include_str!("../../templates/oxwm.lua"); 122 + let system_oxwm_lua = system_paths.iter().find(|path| path.exists());
123 - let oxwm_lua_path = library_directory.join("oxwm.lua");
124 - std::fs::write(&oxwm_lua_path, oxwm_lua_template)?;
125 123
126 - let luarc_content = r#"{ 124 + let luarc_content = if let Some(system_path) = system_oxwm_lua {
125 + format!(
126 + r#"{{
127 + "workspace.library": [
128 + "{}"
129 + ]
130 +}}
131 +"#,
132 + system_path.parent().unwrap().display()
133 + )
134 + } else {
135 + let library_directory = config_directory.join("lib");
136 + std::fs::create_dir_all(&library_directory)?;
137 +
138 + let oxwm_lua_template = include_str!("../../templates/oxwm.lua");
139 + let oxwm_lua_path = library_directory.join("oxwm.lua");
140 + std::fs::write(&oxwm_lua_path, oxwm_lua_template)?;
141 +
142 + r#"{
127 "workspace.library": [ 143 "workspace.library": [
128 "lib" 144 "lib"
129 ] 145 ]
130 } 146 }
131 -"#; 147 +"#
148 + .to_string()
149 + };
150 +
132 let luarc_path = config_directory.join(".luarc.json"); 151 let luarc_path = config_directory.join(".luarc.json");
133 std::fs::write(&luarc_path, luarc_content)?; 152 std::fs::write(&luarc_path, luarc_content)?;
134 153
+0 −42 src/config/lua.rs
@@ -48,45 +48,3 @@ pub fn parse_lua_config(
48 autostart: builder_data.autostart, 48 autostart: builder_data.autostart,
49 }) 49 })
50 } 50 }
51 -
52 -#[cfg(test)]
53 -mod tests {
54 - use super::*;
55 -
56 - #[test]
57 - fn test_parse_minimal_lua_config() {
58 - let config_str = r#"
59 -oxwm.border.set_width(2)
60 -oxwm.border.set_focused_color(0x6dade3)
61 -oxwm.border.set_unfocused_color(0xbbbbbb)
62 -oxwm.bar.set_font("monospace:style=Bold:size=10")
63 -
64 -oxwm.gaps.set_enabled(true)
65 -oxwm.gaps.set_inner(5, 5)
66 -oxwm.gaps.set_outer(5, 5)
67 -
68 -oxwm.set_modkey("Mod4")
69 -oxwm.set_terminal("st")
70 -oxwm.set_tags({"1", "2", "3"})
71 -
72 -oxwm.key.bind({"Mod4"}, "Return", oxwm.spawn("st"))
73 -oxwm.key.bind({"Mod4"}, "Q", oxwm.client.kill())
74 -
75 -oxwm.bar.add_block("{}", "DateTime", "%H:%M", 1, 0xffffff, true)
76 -
77 -oxwm.bar.set_scheme_normal(0xffffff, 0x000000, 0x444444)
78 -oxwm.bar.set_scheme_occupied(0xffffff, 0x000000, 0x444444)
79 -oxwm.bar.set_scheme_selected(0xffffff, 0x000000, 0x444444)
80 -"#;
81 -
82 - let config = parse_lua_config(config_str, None).expect("Failed to parse config");
83 -
84 - assert_eq!(config.border_width, 2);
85 - assert_eq!(config.border_focused, 0x6dade3);
86 - assert_eq!(config.terminal, "st");
87 - assert_eq!(config.tags.len(), 3);
88 - assert_eq!(config.keybindings.len(), 2);
89 - assert_eq!(config.status_blocks.len(), 1);
90 - assert!(config.gaps_enabled);
91 - }
92 -}
+7 −1 src/layout/mod.rs
@@ -1,6 +1,7 @@
1 pub mod grid; 1 pub mod grid;
2 pub mod monocle; 2 pub mod monocle;
3 pub mod normie; 3 pub mod normie;
4 +pub mod tabbed;
4 pub mod tiling; 5 pub mod tiling;
5 6
6 use x11rb::protocol::xproto::Window; 7 use x11rb::protocol::xproto::Window;
@@ -19,6 +20,7 @@ pub enum LayoutType {
19 Normie, 20 Normie,
20 Grid, 21 Grid,
21 Monocle, 22 Monocle,
23 + Tabbed,
22 } 24 }
23 25
24 impl LayoutType { 26 impl LayoutType {
@@ -28,6 +30,7 @@ impl LayoutType {
28 Self::Normie => Box::new(normie::NormieLayout), 30 Self::Normie => Box::new(normie::NormieLayout),
29 Self::Grid => Box::new(grid::GridLayout), 31 Self::Grid => Box::new(grid::GridLayout),
30 Self::Monocle => Box::new(monocle::MonocleLayout), 32 Self::Monocle => Box::new(monocle::MonocleLayout),
33 + Self::Tabbed => Box::new(tabbed::TabbedLayout),
31 } 34 }
32 } 35 }
33 36
@@ -36,7 +39,8 @@ impl LayoutType {
36 Self::Tiling => Self::Normie, 39 Self::Tiling => Self::Normie,
37 Self::Normie => Self::Grid, 40 Self::Normie => Self::Grid,
38 Self::Grid => Self::Monocle, 41 Self::Grid => Self::Monocle,
39 - Self::Monocle => Self::Tiling, 42 + Self::Monocle => Self::Tabbed,
43 + Self::Tabbed => Self::Tiling,
40 } 44 }
41 } 45 }
42 46
@@ -46,6 +50,7 @@ impl LayoutType {
46 Self::Normie => "normie", 50 Self::Normie => "normie",
47 Self::Grid => "grid", 51 Self::Grid => "grid",
48 Self::Monocle => "monocle", 52 Self::Monocle => "monocle",
53 + Self::Tabbed => "tabbed",
49 } 54 }
50 } 55 }
51 56
@@ -55,6 +60,7 @@ impl LayoutType {
55 "normie" | "floating" => Ok(Self::Normie), 60 "normie" | "floating" => Ok(Self::Normie),
56 "grid" => Ok(Self::Grid), 61 "grid" => Ok(Self::Grid),
57 "monocle" => Ok(Self::Monocle), 62 "monocle" => Ok(Self::Monocle),
63 + "tabbed" => Ok(Self::Tabbed),
58 _ => Err(format!("Invalid Layout Type: {}", s)), 64 _ => Err(format!("Invalid Layout Type: {}", s)),
59 } 65 }
60 } 66 }
+45 −0 src/layout/tabbed.rs new file mode 100644
@@ -0,0 +1,45 @@
1 +use super::{GapConfig, Layout, WindowGeometry};
2 +use x11rb::protocol::xproto::Window;
3 +
4 +pub struct TabbedLayout;
5 +
6 +pub const TAB_BAR_HEIGHT: u32 = 28;
7 +
8 +impl Layout for TabbedLayout {
9 + fn name(&self) -> &'static str {
10 + super::LayoutType::Tabbed.as_str()
11 + }
12 +
13 + fn symbol(&self) -> &'static str {
14 + "[=]"
15 + }
16 +
17 + fn arrange(
18 + &self,
19 + windows: &[Window],
20 + screen_width: u32,
21 + screen_height: u32,
22 + gaps: &GapConfig,
23 + ) -> Vec<WindowGeometry> {
24 + let window_count = windows.len();
25 + if window_count == 0 {
26 + return Vec::new();
27 + }
28 +
29 + let x = gaps.outer_horizontal as i32;
30 + let y = (gaps.outer_vertical + TAB_BAR_HEIGHT) as i32;
31 + let width = screen_width.saturating_sub(2 * gaps.outer_horizontal);
32 + let height = screen_height
33 + .saturating_sub(2 * gaps.outer_vertical)
34 + .saturating_sub(TAB_BAR_HEIGHT);
35 +
36 + let geometry = WindowGeometry {
37 + x_coordinate: x,
38 + y_coordinate: y,
39 + width,
40 + height,
41 + };
42 +
43 + vec![geometry; window_count]
44 + }
45 +}
+1 −0 src/lib.rs
@@ -5,6 +5,7 @@ pub mod keyboard;
5 pub mod layout; 5 pub mod layout;
6 pub mod monitor; 6 pub mod monitor;
7 pub mod overlay; 7 pub mod overlay;
8 +pub mod tab_bar;
8 pub mod window_manager; 9 pub mod window_manager;
9 10
10 pub mod prelude { 11 pub mod prelude {
+307 −0 src/tab_bar.rs new file mode 100644
@@ -0,0 +1,307 @@
1 +use crate::bar::font::{Font, FontDraw};
2 +use crate::errors::X11Error;
3 +use crate::layout::tabbed::TAB_BAR_HEIGHT;
4 +use crate::ColorScheme;
5 +use x11rb::connection::Connection;
6 +use x11rb::protocol::xproto::*;
7 +use x11rb::rust_connection::RustConnection;
8 +use x11rb::COPY_DEPTH_FROM_PARENT;
9 +
10 +pub struct TabBar {
11 + window: Window,
12 + width: u16,
13 + height: u16,
14 + x_offset: i16,
15 + y_offset: i16,
16 + graphics_context: Gcontext,
17 + pixmap: x11::xlib::Pixmap,
18 + display: *mut x11::xlib::Display,
19 + font_draw: FontDraw,
20 + scheme_normal: ColorScheme,
21 + scheme_selected: ColorScheme,
22 +}
23 +
24 +impl TabBar {
25 + pub fn new(
26 + connection: &RustConnection,
27 + screen: &Screen,
28 + screen_num: usize,
29 + display: *mut x11::xlib::Display,
30 + _font: &Font,
31 + x: i16,
32 + y: i16,
33 + width: u16,
34 + scheme_normal: ColorScheme,
35 + scheme_selected: ColorScheme,
36 + ) -> Result<Self, X11Error> {
37 + let window = connection.generate_id()?;
38 + let graphics_context = connection.generate_id()?;
39 +
40 + let height = TAB_BAR_HEIGHT as u16;
41 +
42 + connection.create_window(
43 + COPY_DEPTH_FROM_PARENT,
44 + window,
45 + screen.root,
46 + x,
47 + y,
48 + width,
49 + height,
50 + 0,
51 + WindowClass::INPUT_OUTPUT,
52 + screen.root_visual,
53 + &CreateWindowAux::new()
54 + .background_pixel(scheme_normal.background)
55 + .event_mask(EventMask::EXPOSURE | EventMask::BUTTON_PRESS)
56 + .override_redirect(1),
57 + )?;
58 +
59 + connection.create_gc(
60 + graphics_context,
61 + window,
62 + &CreateGCAux::new()
63 + .foreground(scheme_normal.foreground)
64 + .background(scheme_normal.background),
65 + )?;
66 +
67 + connection.map_window(window)?;
68 + connection.flush()?;
69 +
70 + let visual = unsafe { x11::xlib::XDefaultVisual(display, screen_num as i32) };
71 + let colormap = unsafe { x11::xlib::XDefaultColormap(display, screen_num as i32) };
72 + let depth = unsafe { x11::xlib::XDefaultDepth(display, screen_num as i32) };
73 +
74 + let pixmap = unsafe {
75 + x11::xlib::XCreatePixmap(
76 + display,
77 + window as x11::xlib::Drawable,
78 + width as u32,
79 + height as u32,
80 + depth as u32,
81 + )
82 + };
83 +
84 + let font_draw = FontDraw::new(display, pixmap, visual, colormap)?;
85 +
86 + Ok(Self {
87 + window,
88 + width,
89 + height,
90 + x_offset: x,
91 + y_offset: y,
92 + graphics_context,
93 + pixmap,
94 + display,
95 + font_draw,
96 + scheme_normal,
97 + scheme_selected,
98 + })
99 + }
100 +
101 + pub fn window(&self) -> Window {
102 + self.window
103 + }
104 +
105 + pub fn draw(
106 + &mut self,
107 + connection: &RustConnection,
108 + font: &Font,
109 + windows: &[Window],
110 + focused_window: Option<Window>,
111 + ) -> Result<(), X11Error> {
112 + connection.change_gc(
113 + self.graphics_context,
114 + &ChangeGCAux::new().foreground(self.scheme_normal.background),
115 + )?;
116 + connection.flush()?;
117 +
118 + unsafe {
119 + let gc = x11::xlib::XCreateGC(self.display, self.pixmap, 0, std::ptr::null_mut());
120 + x11::xlib::XSetForeground(
121 + self.display,
122 + gc,
123 + self.scheme_normal.background as u64,
124 + );
125 + x11::xlib::XFillRectangle(
126 + self.display,
127 + self.pixmap,
128 + gc,
129 + 0,
130 + 0,
131 + self.width as u32,
132 + self.height as u32,
133 + );
134 + x11::xlib::XFreeGC(self.display, gc);
135 + }
136 +
137 + if windows.is_empty() {
138 + self.copy_pixmap_to_window();
139 + return Ok(());
140 + }
141 +
142 + let tab_width = self.width / windows.len() as u16;
143 + let mut x_position: i16 = 0;
144 +
145 + for (index, &window) in windows.iter().enumerate() {
146 + let is_focused = Some(window) == focused_window;
147 + let scheme = if is_focused {
148 + &self.scheme_selected
149 + } else {
150 + &self.scheme_normal
151 + };
152 +
153 + let title = self.get_window_title(connection, window);
154 + let display_title = if title.is_empty() {
155 + format!("Window {}", index + 1)
156 + } else {
157 + title
158 + };
159 +
160 + let text_width = font.text_width(&display_title);
161 + let text_x = x_position + ((tab_width.saturating_sub(text_width)) / 2) as i16;
162 +
163 + let top_padding = 6;
164 + let text_y = top_padding + font.ascent();
165 +
166 + self.font_draw
167 + .draw_text(font, scheme.foreground, text_x, text_y, &display_title);
168 +
169 + if is_focused {
170 + let underline_height = 3;
171 + let underline_y = self.height as i16 - underline_height;
172 +
173 + unsafe {
174 + let gc =
175 + x11::xlib::XCreateGC(self.display, self.pixmap, 0, std::ptr::null_mut());
176 + x11::xlib::XSetForeground(self.display, gc, scheme.underline as u64);
177 + x11::xlib::XFillRectangle(
178 + self.display,
179 + self.pixmap,
180 + gc,
181 + x_position as i32,
182 + underline_y as i32,
183 + tab_width as u32,
184 + underline_height as u32,
185 + );
186 + x11::xlib::XFreeGC(self.display, gc);
187 + }
188 + }
189 +
190 + x_position += tab_width as i16;
191 + }
192 +
193 + self.copy_pixmap_to_window();
194 + Ok(())
195 + }
196 +
197 + fn copy_pixmap_to_window(&self) {
198 + unsafe {
199 + let gc = x11::xlib::XCreateGC(self.display, self.window as u64, 0, std::ptr::null_mut());
200 + x11::xlib::XCopyArea(
201 + self.display,
202 + self.pixmap,
203 + self.window as u64,
204 + gc,
205 + 0,
206 + 0,
207 + self.width as u32,
208 + self.height as u32,
209 + 0,
210 + 0,
211 + );
212 + x11::xlib::XFreeGC(self.display, gc);
213 + }
214 + }
215 +
216 + fn get_window_title(&self, connection: &RustConnection, window: Window) -> String {
217 + connection
218 + .get_property(false, window, AtomEnum::WM_NAME, AtomEnum::STRING, 0, 1024)
219 + .ok()
220 + .and_then(|cookie| cookie.reply().ok())
221 + .and_then(|reply| {
222 + if reply.value.is_empty() {
223 + None
224 + } else {
225 + std::str::from_utf8(&reply.value).ok().map(|s| s.to_string())
226 + }
227 + })
228 + .unwrap_or_default()
229 + }
230 +
231 + pub fn get_clicked_window(
232 + &self,
233 + windows: &[Window],
234 + click_x: i16,
235 + ) -> Option<Window> {
236 + if windows.is_empty() {
237 + return None;
238 + }
239 +
240 + let tab_width = self.width / windows.len() as u16;
241 + let tab_index = (click_x as u16 / tab_width) as usize;
242 +
243 + windows.get(tab_index).copied()
244 + }
245 +
246 + pub fn reposition(
247 + &mut self,
248 + connection: &RustConnection,
249 + x: i16,
250 + y: i16,
251 + width: u16,
252 + ) -> Result<(), X11Error> {
253 + self.x_offset = x;
254 + self.y_offset = y;
255 + self.width = width;
256 +
257 + connection.configure_window(
258 + self.window,
259 + &ConfigureWindowAux::new()
260 + .x(x as i32)
261 + .y(y as i32)
262 + .width(width as u32),
263 + )?;
264 +
265 + unsafe {
266 + x11::xlib::XFreePixmap(self.display, self.pixmap);
267 + }
268 +
269 + let depth = unsafe { x11::xlib::XDefaultDepth(self.display, 0) };
270 + self.pixmap = unsafe {
271 + x11::xlib::XCreatePixmap(
272 + self.display,
273 + self.window as x11::xlib::Drawable,
274 + width as u32,
275 + self.height as u32,
276 + depth as u32,
277 + )
278 + };
279 +
280 + let visual = unsafe { x11::xlib::XDefaultVisual(self.display, 0) };
281 + let colormap = unsafe { x11::xlib::XDefaultColormap(self.display, 0) };
282 + self.font_draw = FontDraw::new(self.display, self.pixmap, visual, colormap)?;
283 +
284 + connection.flush()?;
285 + Ok(())
286 + }
287 +
288 + pub fn hide(&self, connection: &RustConnection) -> Result<(), X11Error> {
289 + connection.unmap_window(self.window)?;
290 + connection.flush()?;
291 + Ok(())
292 + }
293 +
294 + pub fn show(&self, connection: &RustConnection) -> Result<(), X11Error> {
295 + connection.map_window(self.window)?;
296 + connection.flush()?;
297 + Ok(())
298 + }
299 +}
300 +
301 +impl Drop for TabBar {
302 + fn drop(&mut self) {
303 + unsafe {
304 + x11::xlib::XFreePixmap(self.display, self.pixmap);
305 + }
306 + }
307 +}
+217 −13 src/window_manager.rs
@@ -107,6 +107,7 @@ pub struct WindowManager {
107 fullscreen_windows: HashSet<Window>, 107 fullscreen_windows: HashSet<Window>,
108 floating_geometry_before_fullscreen: std::collections::HashMap<Window, (i16, i16, u16, u16, u16)>, 108 floating_geometry_before_fullscreen: std::collections::HashMap<Window, (i16, i16, u16, u16, u16)>,
109 bars: Vec<Bar>, 109 bars: Vec<Bar>,
110 + tab_bars: Vec<crate::tab_bar::TabBar>,
110 show_bar: bool, 111 show_bar: bool,
111 last_layout: Option<&'static str>, 112 last_layout: Option<&'static str>,
112 monitors: Vec<Monitor>, 113 monitors: Vec<Monitor>,
@@ -202,6 +203,24 @@ impl WindowManager {
202 bars.push(bar); 203 bars.push(bar);
203 } 204 }
204 205
206 + let bar_height = font.height() as f32 * 1.4;
207 + let mut tab_bars = Vec::new();
208 + for monitor in monitors.iter() {
209 + let tab_bar = crate::tab_bar::TabBar::new(
210 + &connection,
211 + &screen,
212 + screen_number,
213 + display,
214 + &font,
215 + (monitor.x + config.gap_outer_horizontal as i32) as i16,
216 + (monitor.y as f32 + bar_height + config.gap_outer_vertical as f32) as i16,
217 + monitor.width.saturating_sub(2 * config.gap_outer_horizontal) as u16,
218 + config.scheme_occupied,
219 + config.scheme_selected,
220 + )?;
221 + tab_bars.push(tab_bar);
222 + }
223 +
205 let gaps_enabled = config.gaps_enabled; 224 let gaps_enabled = config.gaps_enabled;
206 225
207 let atoms = AtomCache::new(&connection)?; 226 let atoms = AtomCache::new(&connection)?;
@@ -234,6 +253,7 @@ impl WindowManager {
234 fullscreen_windows: HashSet::new(), 253 fullscreen_windows: HashSet::new(),
235 floating_geometry_before_fullscreen: std::collections::HashMap::new(), 254 floating_geometry_before_fullscreen: std::collections::HashMap::new(),
236 bars, 255 bars,
256 + tab_bars,
237 show_bar: true, 257 show_bar: true,
238 last_layout: None, 258 last_layout: None,
239 monitors, 259 monitors,
@@ -248,6 +268,10 @@ impl WindowManager {
248 keybind_overlay, 268 keybind_overlay,
249 }; 269 };
250 270
271 + for tab_bar in &window_manager.tab_bars {
272 + tab_bar.hide(&window_manager.connection)?;
273 + }
274 +
251 window_manager.scan_existing_windows()?; 275 window_manager.scan_existing_windows()?;
252 window_manager.update_bar()?; 276 window_manager.update_bar()?;
253 window_manager.run_autostart_commands()?; 277 window_manager.run_autostart_commands()?;
@@ -904,6 +928,42 @@ impl WindowManager {
904 Ok(()) 928 Ok(())
905 } 929 }
906 930
931 + fn update_tab_bars(&mut self) -> WmResult<()> {
932 + for (monitor_index, monitor) in self.monitors.iter().enumerate() {
933 + if let Some(tab_bar) = self.tab_bars.get_mut(monitor_index) {
934 + let visible_windows: Vec<Window> = self
935 + .windows
936 + .iter()
937 + .filter(|&&window| {
938 + let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0);
939 + if window_monitor_index != monitor_index
940 + || self.floating_windows.contains(&window)
941 + || self.fullscreen_windows.contains(&window)
942 + {
943 + return false;
944 + }
945 + if let Some(&tags) = self.window_tags.get(&window) {
946 + (tags & monitor.selected_tags) != 0
947 + } else {
948 + false
949 + }
950 + })
951 + .copied()
952 + .collect();
953 +
954 + let focused_window = monitor.focused_window;
955 +
956 + tab_bar.draw(
957 + &self.connection,
958 + &self.font,
959 + &visible_windows,
960 + focused_window,
961 + )?;
962 + }
963 + }
964 + Ok(())
965 + }
966 +
907 fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> { 967 fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> {
908 match action { 968 match action {
909 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, 969 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?,
@@ -1223,7 +1283,20 @@ impl WindowManager {
1223 visible[0] 1283 visible[0]
1224 }; 1284 };
1225 1285
1286 + let is_tabbed = self.layout.name() == "tabbed";
1287 + if is_tabbed {
1288 + self.connection.configure_window(
1289 + next_window,
1290 + &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE),
1291 + )?;
1292 + }
1293 +
1226 self.set_focus(next_window)?; 1294 self.set_focus(next_window)?;
1295 +
1296 + if is_tabbed {
1297 + self.update_tab_bars()?;
1298 + }
1299 +
1227 Ok(()) 1300 Ok(())
1228 } 1301 }
1229 1302
@@ -1693,6 +1766,11 @@ impl WindowManager {
1693 1766
1694 self.update_focus_visuals(old_focused, window)?; 1767 self.update_focus_visuals(old_focused, window)?;
1695 self.previous_focused = Some(window); 1768 self.previous_focused = Some(window);
1769 +
1770 + if self.layout.name() == "tabbed" {
1771 + self.update_tab_bars()?;
1772 + }
1773 +
1696 Ok(()) 1774 Ok(())
1697 } 1775 }
1698 1776
@@ -2001,6 +2079,10 @@ impl WindowManager {
2001 self.apply_layout()?; 2079 self.apply_layout()?;
2002 self.update_bar()?; 2080 self.update_bar()?;
2003 self.set_focus(event.window)?; 2081 self.set_focus(event.window)?;
2082 +
2083 + if self.layout.name() == "tabbed" {
2084 + self.update_tab_bars()?;
2085 + }
2004 } 2086 }
2005 Event::UnmapNotify(event) => { 2087 Event::UnmapNotify(event) => {
2006 if self.windows.contains(&event.window) && self.is_window_visible(event.window) { 2088 if self.windows.contains(&event.window) && self.is_window_visible(event.window) {
@@ -2123,13 +2205,55 @@ impl WindowManager {
2123 } 2205 }
2124 self.view_tag(tag_index)?; 2206 self.view_tag(tag_index)?;
2125 } 2207 }
2126 - } else if event.child != x11rb::NONE { 2208 + } else {
2127 - self.set_focus(event.child)?; 2209 + let is_tab_bar_click = self
2210 + .tab_bars
2211 + .iter()
2212 + .enumerate()
2213 + .find(|(_, tab_bar)| tab_bar.window() == event.event);
2214 +
2215 + if let Some((monitor_index, tab_bar)) = is_tab_bar_click {
2216 + if monitor_index != self.selected_monitor {
2217 + self.selected_monitor = monitor_index;
2218 + }
2219 +
2220 + let visible_windows: Vec<Window> = self
2221 + .windows
2222 + .iter()
2223 + .filter(|&&window| {
2224 + let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0);
2225 + if window_monitor_index != monitor_index
2226 + || self.floating_windows.contains(&window)
2227 + || self.fullscreen_windows.contains(&window)
2228 + {
2229 + return false;
2230 + }
2231 + let monitor_tags = self.monitors.get(monitor_index).map(|m| m.selected_tags).unwrap_or(0);
2232 + if let Some(&tags) = self.window_tags.get(&window) {
2233 + (tags & monitor_tags) != 0
2234 + } else {
2235 + false
2236 + }
2237 + })
2238 + .copied()
2239 + .collect();
2240 +
2241 + if let Some(clicked_window) = tab_bar.get_clicked_window(&visible_windows, event.event_x) {
2242 + self.connection.configure_window(
2243 + clicked_window,
2244 + &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE),
2245 + )?;
2246 + self.set_focus(clicked_window)?;
2247 + self.update_tab_bars()?;
2248 + }
2249 + } else if event.child != x11rb::NONE {
2250 + self.set_focus(event.child)?;
2128 2251
2129 - if event.detail == ButtonIndex::M1.into() { 2252 + if event.detail == ButtonIndex::M1.into() {
2130 - self.move_mouse(event.child)?; 2253 + self.move_mouse(event.child)?;
2131 - } else if event.detail == ButtonIndex::M3.into() { 2254 + } else if event.detail == ButtonIndex::M3.into() {
2132 - self.resize_mouse(event.child)?; 2255 + self.resize_mouse(event.child)?;
2256 + }
2133 } 2257 }
2134 } 2258 }
2135 } 2259 }
@@ -2141,6 +2265,12 @@ impl WindowManager {
2141 break; 2265 break;
2142 } 2266 }
2143 } 2267 }
2268 + for _tab_bar in &self.tab_bars {
2269 + if event.window == _tab_bar.window() {
2270 + self.update_tab_bars()?;
2271 + break;
2272 + }
2273 + }
2144 } 2274 }
2145 Event::ClientMessage(event) => { 2275 Event::ClientMessage(event) => {
2146 if event.type_ == self.atoms.net_wm_state { 2276 if event.type_ == self.atoms.net_wm_state {
@@ -2200,13 +2330,10 @@ impl WindowManager {
2200 .iter() 2330 .iter()
2201 .filter(|&&window| { 2331 .filter(|&&window| {
2202 let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0); 2332 let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0);
2203 - if window_monitor_index != monitor_index { 2333 + if window_monitor_index != monitor_index
2204 - return false; 2334 + || self.floating_windows.contains(&window)
2205 - } 2335 + || self.fullscreen_windows.contains(&window)
2206 - if self.floating_windows.contains(&window) { 2336 + {
2207 - return false;
2208 - }
2209 - if self.fullscreen_windows.contains(&window) {
2210 return false; 2337 return false;
2211 } 2338 }
2212 if let Some(&tags) = self.window_tags.get(&window) { 2339 if let Some(&tags) = self.window_tags.get(&window) {
@@ -2260,6 +2387,83 @@ impl WindowManager {
2260 } 2387 }
2261 2388
2262 self.connection.flush()?; 2389 self.connection.flush()?;
2390 +
2391 + let is_tabbed = self.layout.name() == LayoutType::Tabbed.as_str();
2392 +
2393 + if is_tabbed {
2394 + let outer_horizontal = if self.gaps_enabled {
2395 + self.config.gap_outer_horizontal
2396 + } else {
2397 + 0
2398 + };
2399 + let outer_vertical = if self.gaps_enabled {
2400 + self.config.gap_outer_vertical
2401 + } else {
2402 + 0
2403 + };
2404 +
2405 + for monitor_index in 0..self.tab_bars.len() {
2406 + if let Some(monitor) = self.monitors.get(monitor_index) {
2407 + let bar_height = if self.show_bar {
2408 + self.bars
2409 + .get(monitor_index)
2410 + .map(|bar| bar.height() as f32)
2411 + .unwrap_or(0.0)
2412 + } else {
2413 + 0.0
2414 + };
2415 +
2416 + let tab_bar_x = (monitor.x + outer_horizontal as i32) as i16;
2417 + let tab_bar_y = (monitor.y as f32 + bar_height + outer_vertical as f32) as i16;
2418 + let tab_bar_width = monitor.width.saturating_sub(2 * outer_horizontal) as u16;
2419 +
2420 + if let Err(e) = self.tab_bars[monitor_index].reposition(
2421 + &self.connection,
2422 + tab_bar_x,
2423 + tab_bar_y,
2424 + tab_bar_width,
2425 + ) {
2426 + eprintln!("Failed to reposition tab bar: {:?}", e);
2427 + }
2428 + }
2429 + }
2430 + }
2431 +
2432 + for monitor_index in 0..self.tab_bars.len() {
2433 + let has_visible_windows = self
2434 + .windows
2435 + .iter()
2436 + .any(|&window| {
2437 + let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0);
2438 + if window_monitor_index != monitor_index
2439 + || self.floating_windows.contains(&window)
2440 + || self.fullscreen_windows.contains(&window)
2441 + {
2442 + return false;
2443 + }
2444 + if let Some(monitor) = self.monitors.get(monitor_index) {
2445 + if let Some(&tags) = self.window_tags.get(&window) {
2446 + return (tags & monitor.selected_tags) != 0;
2447 + }
2448 + }
2449 + false
2450 + });
2451 +
2452 + if is_tabbed && has_visible_windows {
2453 + if let Err(e) = self.tab_bars[monitor_index].show(&self.connection) {
2454 + eprintln!("Failed to show tab bar: {:?}", e);
2455 + }
2456 + } else {
2457 + if let Err(e) = self.tab_bars[monitor_index].hide(&self.connection) {
2458 + eprintln!("Failed to hide tab bar: {:?}", e);
2459 + }
2460 + }
2461 + }
2462 +
2463 + if is_tabbed {
2464 + self.update_tab_bars()?;
2465 + }
2466 +
2263 Ok(()) 2467 Ok(())
2264 } 2468 }
2265 2469
+57 −3 templates/config.lua
@@ -40,10 +40,60 @@ local colors = {
40 40
41 -- Workspace tags - can be numbers, names, or icons (requires a Nerd Font) 41 -- Workspace tags - can be numbers, names, or icons (requires a Nerd Font)
42 local tags = { "1", "2", "3", "4", "5", "6", "7", "8", "9" } 42 local tags = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }
43 +-- local tags = { "", "󰊯", "", "", "󰙯", "󱇤", "", "󱘶", "󰧮" } -- Example of nerd font icon tags
43 44
44 -- Font for the status bar (use "fc-list" to see available fonts) 45 -- Font for the status bar (use "fc-list" to see available fonts)
45 local bar_font = "monospace:style=Bold:size=10" 46 local bar_font = "monospace:style=Bold:size=10"
46 47
48 +-- Define your blocks
49 +-- Similar to widgets in qtile, or dwmblocks
50 +local blocks = {
51 + oxwm.bar.block.ram({
52 + format = "Ram: {used}/{total} GB",
53 + interval = 5,
54 + color = colors.light_blue,
55 + underline = true,
56 + }),
57 + oxwm.bar.block.static({
58 + format = "{}",
59 + text = " │ ",
60 + interval = 999999999,
61 + color = colors.lavender,
62 + underline = false,
63 + }),
64 + oxwm.bar.block.shell({
65 + format = "Kernel: {}",
66 + command = "uname -r",
67 + interval = 999999999,
68 + color = colors.red,
69 + underline = true,
70 + }),
71 + oxwm.bar.block.static({
72 + format = "{}",
73 + text = " │ ",
74 + interval = 999999999,
75 + color = colors.lavender,
76 + underline = false,
77 + }),
78 + oxwm.bar.block.datetime({
79 + format = "{}",
80 + date_format = "%a, %b %d - %-I:%M %P",
81 + interval = 1,
82 + color = colors.cyan,
83 + underline = true,
84 + }),
85 + -- Uncomment to add battery status (useful for laptops)
86 + -- oxwm.bar.block.battery({
87 + -- format = "Bat: {}%",
88 + -- charging = "⚡ Bat: {}%",
89 + -- discharging = "- Bat: {}%",
90 + -- full = "✓ Bat: {}%",
91 + -- interval = 30,
92 + -- color = colors.green,
93 + -- underline = true,
94 + -- }),
95 +};
96 +
47 ------------------------------------------------------------------------------- 97 -------------------------------------------------------------------------------
48 -- Basic Settings 98 -- Basic Settings
49 ------------------------------------------------------------------------------- 99 -------------------------------------------------------------------------------
@@ -55,9 +105,10 @@ oxwm.set_tags(tags)
55 -- Layouts 105 -- Layouts
56 ------------------------------------------------------------------------------- 106 -------------------------------------------------------------------------------
57 -- Set custom symbols for layouts (displayed in the status bar) 107 -- Set custom symbols for layouts (displayed in the status bar)
58 --- Available layouts: "tiling" (master-stack), "normie" (floating) 108 +-- Available layouts: "tiling", "normie" (floating), "grid", "monocle", "tabbed"
59 oxwm.set_layout_symbol("tiling", "[T]") 109 oxwm.set_layout_symbol("tiling", "[T]")
60 oxwm.set_layout_symbol("normie", "[F]") 110 oxwm.set_layout_symbol("normie", "[F]")
111 +oxwm.set_layout_symbol("tabbed", "[=]")
61 112
62 ------------------------------------------------------------------------------- 113 -------------------------------------------------------------------------------
63 -- Appearance 114 -- Appearance
@@ -78,6 +129,9 @@ oxwm.gaps.set_outer(5, 5) -- Outer gaps (horizontal, vertical) in pixels
78 -- Font configuration 129 -- Font configuration
79 oxwm.bar.set_font(bar_font) 130 oxwm.bar.set_font(bar_font)
80 131
132 +-- Set your blocks here (defined above)
133 +oxwm.bar.set_blocks(blocks)
134 +
81 -- Bar color schemes (for workspace tag display) 135 -- Bar color schemes (for workspace tag display)
82 -- Parameters: foreground, background, border 136 -- Parameters: foreground, background, border
83 oxwm.bar.set_scheme_normal(colors.fg, colors.bg, "#444444") -- Unoccupied tags 137 oxwm.bar.set_scheme_normal(colors.fg, colors.bg, "#444444") -- Unoccupied tags
@@ -96,7 +150,7 @@ oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple) -- Currently
96 -- Common keys: Return, Space, Tab, Escape, Backspace, Delete, Left, Right, Up, Down 150 -- Common keys: Return, Space, Tab, Escape, Backspace, Delete, Left, Right, Up, Down
97 151
98 -- Basic window management 152 -- Basic window management
99 -oxwm.key.bind({ modkey }, "Return", oxwm.spawn(terminal)) -- Spawn terminal 153 +oxwm.key.bind({ modkey }, "Return", oxwm.spawn_terminal()) -- Spawn terminal
100 oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" })) -- Application launcher 154 oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" })) -- Application launcher
101 oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" })) -- Screenshot selection 155 oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" })) -- Screenshot selection
102 oxwm.key.bind({ modkey }, "Q", oxwm.client.kill()) -- Close focused window 156 oxwm.key.bind({ modkey }, "Q", oxwm.client.kill()) -- Close focused window
@@ -168,7 +222,7 @@ oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right")) --
168 oxwm.key.chord({ 222 oxwm.key.chord({
169 { { modkey }, "Space" }, 223 { { modkey }, "Space" },
170 { {}, "T" } 224 { {}, "T" }
171 -}, oxwm.spawn(terminal)) 225 +}, oxwm.spawn_terminal())
172 226
173 ------------------------------------------------------------------------------- 227 -------------------------------------------------------------------------------
174 -- Status Bar Blocks 228 -- Status Bar Blocks
+3 −3 templates/oxwm.lua
@@ -38,8 +38,8 @@ function oxwm.set_modkey(modkey) end
38 function oxwm.set_tags(tags) end 38 function oxwm.set_tags(tags) end
39 39
40 ---Set layout symbol override 40 ---Set layout symbol override
41 ----@param name string Layout name (e.g., "tiling", "normie") 41 +---@param name string Layout name (e.g., "tiling", "normie", "tabbed", "grid", "monocle")
42 ----@param symbol string Symbol to display (e.g., "[T]", "[F]") 42 +---@param symbol string Symbol to display (e.g., "[T]", "[F]", "[=]")
43 function oxwm.set_layout_symbol(name, symbol) end 43 function oxwm.set_layout_symbol(name, symbol) end
44 44
45 ---Quit the window manager 45 ---Quit the window manager
@@ -171,7 +171,7 @@ oxwm.layout = {}
171 function oxwm.layout.cycle() end 171 function oxwm.layout.cycle() end
172 172
173 ---Set specific layout 173 ---Set specific layout
174 ----@param name string Layout name (e.g., "tiling", "normie") 174 +---@param name string Layout name (e.g., "tiling", "normie", "tabbed", "grid", "monocle")
175 ---@return table Action table for keybinding 175 ---@return table Action table for keybinding
176 function oxwm.layout.set(name) end 176 function oxwm.layout.set(name) end
177 177