tony / oxwm

fixed merge conflicts. Browse files
tonybanters committed 2026-10-12 parents 9ae47bd 472c767 commit b33b7bb4c2bca83ca066072766df31b04969583c
Showing 11 changed files with 105 additions and 31 deletions. UnifiedSplit
+15 −0 README.md
@@ -6,6 +6,21 @@ A dynamic window manager written in Zig, inspired by dwm but designed to evolve
6 6
7 **Documentation:** [ox-docs.vercel.app](https://ox-docs.vercel.app/) 7 **Documentation:** [ox-docs.vercel.app](https://ox-docs.vercel.app/)
8 8
9 +## Showcase
10 +
11 +Setups from OXWM users across Arch, CachyOS, Debian and FreeBSD.
12 +
13 +<table>
14 + <tr>
15 + <td><img src="./images/example1.png" alt="OXWM on Arch Linux with btop and fastfetch in a Rosepuccin theme"></td>
16 + <td><img src="./images/example2.png" alt="OXWM on CachyOS with a custom bar, notifications and a floating terminal"></td>
17 + </tr>
18 + <tr>
19 + <td><img src="./images/example3.png" alt="OXWM on FreeBSD running under XLibre with st"></td>
20 + <td><img src="./images/example4.png" alt="OXWM on Debian showing the keybinds overlay over fastfetch and a music player"></td>
21 + </tr>
22 +</table>
23 +
9 ## Installation 24 ## Installation
10 25
11 ### NixOS (nixpkgs) 26 ### NixOS (nixpkgs)
+0 −0 images/example1.png new file mode 100644, Binary files /dev/null and b/images/example1.png differ
+0 −0 images/example2.png new file mode 100644, Binary files /dev/null and b/images/example2.png differ
+0 −0 images/example3.png new file mode 100644, Binary files /dev/null and b/images/example3.png differ
+0 −0 images/example4.png new file mode 100644, Binary files /dev/null and b/images/example4.png differ
+1 −0 src/client.zig
@@ -34,6 +34,7 @@ pub const Client = struct {
34 old_state: bool = false, 34 old_state: bool = false,
35 is_fullscreen: bool = false, 35 is_fullscreen: bool = false,
36 scroll_width: f32 = 0, 36 scroll_width: f32 = 0,
37 + rule_fullscreen: bool = false,
37 next: ?*Client = null, 38 next: ?*Client = null,
38 stack_next: ?*Client = null, 39 stack_next: ?*Client = null,
39 monitor: ?*Monitor = null, 40 monitor: ?*Monitor = null,
+1 −0 src/config/config.zig
@@ -58,6 +58,7 @@ pub const Rule = struct {
58 title: ?[]const u8, 58 title: ?[]const u8,
59 tags: u32, 59 tags: u32,
60 is_floating: bool, 60 is_floating: bool,
61 + is_fullscreen: bool,
61 monitor: i32, 62 monitor: i32,
62 focus: bool, 63 focus: bool,
63 width: f32 = 0, 64 width: f32 = 0,
+7 −0 src/config/lua.zig
@@ -869,6 +869,7 @@ fn luaRuleAdd(state: ?*c.lua_State) callconv(.c) c_int {
869 .title = null, 869 .title = null,
870 .tags = 0, 870 .tags = 0,
871 .is_floating = false, 871 .is_floating = false,
872 + .is_fullscreen = false,
872 .monitor = -1, 873 .monitor = -1,
873 .focus = false, 874 .focus = false,
874 }; 875 };
@@ -906,6 +907,12 @@ fn luaRuleAdd(state: ?*c.lua_State) callconv(.c) c_int {
906 } 907 }
907 c.lua_settop(s, -2); 908 c.lua_settop(s, -2);
908 909
910 + _ = c.lua_getfield(s, 1, "fullscreen");
911 + if (c.lua_type(s, -1) == c.LUA_TBOOLEAN) {
912 + rule.is_fullscreen = c.lua_toboolean(s, -1) != 0;
913 + }
914 + c.lua_settop(s, -2);
915 +
909 _ = c.lua_getfield(s, 1, "monitor"); 916 _ = c.lua_getfield(s, 1, "monitor");
910 if (c.lua_type(s, -1) == c.LUA_TNUMBER) { 917 if (c.lua_type(s, -1) == c.LUA_TNUMBER) {
911 rule.monitor = @intCast(c.lua_tointegerx(s, -1, null)); 918 rule.monitor = @intCast(c.lua_tointegerx(s, -1, null));
+69 −29 src/wm/core.zig
@@ -111,11 +111,19 @@ pub fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *Wind
111 arrange(monitor, wm); 111 arrange(monitor, wm);
112 _ = xlib.XMapWindow(wm.display.handle, win); 112 _ = xlib.XMapWindow(wm.display.handle, win);
113 focus(null, wm); 113 focus(null, wm);
114 +
115 + if (client.rule_fullscreen) {
116 + setFullscreen(client, true, wm);
117 + }
114 } 118 }
115 119
116 -pub fn unmanage(client: *Client, wm: *WindowManager) void { 120 +pub fn unmanage(client: *Client, destroyed: bool, wm: *WindowManager) void {
117 const client_monitor = client.monitor; 121 const client_monitor = client.monitor;
118 122
123 + if (!destroyed) {
124 + setClientState(client, window_manager.WithdrawnState, wm);
125 + }
126 +
119 var next_focus: ?*Client = null; 127 var next_focus: ?*Client = null;
120 if (client_monitor) |monitor| { 128 if (client_monitor) |monitor| {
121 if (monitor.sel == client and isScrollingLayout(monitor)) { 129 if (monitor.sel == client and isScrollingLayout(monitor)) {
@@ -336,25 +344,30 @@ pub fn grabbuttons(client: *Client, focused: bool, wm: *WindowManager) void {
336 344
337 pub fn setClientState(client: *Client, state: c_long, wm: *WindowManager) void { 345 pub fn setClientState(client: *Client, state: c_long, wm: *WindowManager) void {
338 var data: [2]c_long = .{ state, xlib.None }; 346 var data: [2]c_long = .{ state, xlib.None };
339 - _ = xlib.c.XChangeProperty(wm.display.handle, client.window, wm.atoms.wm_state, xlib.XA_ATOM, 32, xlib.PropModeReplace, @ptrCast(&data), 2); 347 + _ = xlib.c.XChangeProperty(wm.display.handle, client.window, wm.atoms.wm_state, wm.atoms.wm_state, 32, xlib.PropModeReplace, @ptrCast(&data), 2);
348 +}
349 +
350 +pub fn publishNetWmState(client: *Client, wm: *WindowManager) void {
351 + var fullscreen_atom = wm.atoms.net_wm_state_fullscreen;
352 + const count: c_int = if (client.is_fullscreen) 1 else 0;
353 + _ = xlib.XChangeProperty(
354 + wm.display.handle,
355 + client.window,
356 + wm.atoms.net_wm_state,
357 + xlib.XA_ATOM,
358 + 32,
359 + xlib.PropModeReplace,
360 + @ptrCast(&fullscreen_atom),
361 + count,
362 + );
340 } 363 }
341 364
342 pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void { 365 pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void {
343 const monitor = client.monitor orelse return; 366 const monitor = client.monitor orelse return;
344 367
345 if (fullscreen and !client.is_fullscreen) { 368 if (fullscreen and !client.is_fullscreen) {
346 - var fullscreen_atom = wm.atoms.net_wm_state_fullscreen;
347 - _ = xlib.XChangeProperty(
348 - wm.display.handle,
349 - client.window,
350 - wm.atoms.net_wm_state,
351 - xlib.XA_ATOM,
352 - 32,
353 - xlib.PropModeReplace,
354 - @ptrCast(&fullscreen_atom),
355 - 1,
356 - );
357 client.is_fullscreen = true; 369 client.is_fullscreen = true;
370 + publishNetWmState(client, wm);
358 client.old_state = client.is_floating; 371 client.old_state = client.is_floating;
359 client.old_border_width = client.border_width; 372 client.old_border_width = client.border_width;
360 client.border_width = 0; 373 client.border_width = 0;
@@ -366,18 +379,8 @@ pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void
366 379
367 std.debug.print("fullscreen enabled: window=0x{x}\n", .{client.window}); 380 std.debug.print("fullscreen enabled: window=0x{x}\n", .{client.window});
368 } else if (!fullscreen and client.is_fullscreen) { 381 } else if (!fullscreen and client.is_fullscreen) {
369 - var no_atom: xlib.Atom = 0;
370 - _ = xlib.XChangeProperty(
371 - wm.display.handle,
372 - client.window,
373 - wm.atoms.net_wm_state,
374 - xlib.XA_ATOM,
375 - 32,
376 - xlib.PropModeReplace,
377 - @ptrCast(&no_atom),
378 - 0,
379 - );
380 client.is_fullscreen = false; 382 client.is_fullscreen = false;
383 + publishNetWmState(client, wm);
381 client.is_floating = client.old_state; 384 client.is_floating = client.old_state;
382 client.border_width = client.old_border_width; 385 client.border_width = client.old_border_width;
383 386
@@ -570,24 +573,61 @@ fn positionFloating(client: *Client, monitor: *Monitor, pos: config_mod.Floating
570 client.y = y; 573 client.y = y;
571 } 574 }
572 575
576 +fn ruleMatches(rule: config_mod.Rule, class_str: []const u8, instance_str: []const u8, title_str: []const u8) bool {
577 + const class_matches = if (rule.class) |rc| std.mem.indexOf(u8, class_str, rc) != null else true;
578 + const instance_matches = if (rule.instance) |ri| std.mem.indexOf(u8, instance_str, ri) != null else true;
579 + const title_matches = if (rule.title) |rt| std.mem.indexOf(u8, title_str, rt) != null else true;
580 + return class_matches and instance_matches and title_matches;
581 +}
582 +
583 +pub fn applyFullscreenRule(client: *Client, wm: *WindowManager) void {
584 + if (client.rule_fullscreen or client.is_fullscreen) return;
585 +
586 + var has_fullscreen_rule = false;
587 + for (wm.config.rules.items) |rule| {
588 + if (rule.is_fullscreen) has_fullscreen_rule = true;
589 + }
590 + if (!has_fullscreen_rule) return;
591 +
592 + var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null };
593 + _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint);
594 + defer {
595 + if (class_hint.res_class) |ptr| _ = xlib.XFree(@ptrCast(ptr));
596 + if (class_hint.res_name) |ptr| _ = xlib.XFree(@ptrCast(ptr));
597 + }
598 +
599 + const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else "";
600 + const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else "";
601 + const title_str = std.mem.sliceTo(&client.name, 0);
602 +
603 + for (wm.config.rules.items) |rule| {
604 + if (rule.is_fullscreen and ruleMatches(rule, class_str, instance_str, title_str)) {
605 + client.rule_fullscreen = true;
606 + setFullscreen(client, true, wm);
607 + return;
608 + }
609 + }
610 +}
611 +
573 pub fn applyRules(client: *Client, wm: *WindowManager) void { 612 pub fn applyRules(client: *Client, wm: *WindowManager) void {
574 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null }; 613 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null };
575 _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint); 614 _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint);
576 615
577 const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else ""; 616 const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else "";
578 const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else ""; 617 const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else "";
618 + const title_str = std.mem.sliceTo(&client.name, 0);
579 619
580 client.is_floating = false; 620 client.is_floating = false;
581 client.tags = 0; 621 client.tags = 0;
622 + client.rule_fullscreen = false;
582 var rule_focus = false; 623 var rule_focus = false;
583 624
584 for (wm.config.rules.items) |rule| { 625 for (wm.config.rules.items) |rule| {
585 - const class_matches = if (rule.class) |rc| std.mem.indexOf(u8, class_str, rc) != null else true; 626 + if (ruleMatches(rule, class_str, instance_str, title_str)) {
586 - const instance_matches = if (rule.instance) |ri| std.mem.indexOf(u8, instance_str, ri) != null else true;
587 - const title_matches = if (rule.title) |rt| std.mem.indexOf(u8, std.mem.sliceTo(&client.name, 0), rt) != null else true;
588 -
589 - if (class_matches and instance_matches and title_matches) {
590 client.is_floating = rule.is_floating; 627 client.is_floating = rule.is_floating;
628 + if (rule.is_fullscreen) {
629 + client.rule_fullscreen = true;
630 + }
591 client.tags |= rule.tags; 631 client.tags |= rule.tags;
592 if (rule.width > 0) client.scroll_width = rule.width; 632 if (rule.width > 0) client.scroll_width = rule.width;
593 if (rule.monitor >= 0) { 633 if (rule.monitor >= 0) {
+10 −2 src/wm/handlers.zig
@@ -74,6 +74,10 @@ fn handleConfigureRequest(event: *xlib.XConfigureRequestEvent, wm: *WindowManage
74 const client = client_mod.windowToClient(wm.monitors, event.window); 74 const client = client_mod.windowToClient(wm.monitors, event.window);
75 75
76 if (client) |managed_client| { 76 if (client) |managed_client| {
77 + if (managed_client.is_fullscreen) {
78 + tiling.sendConfigure(managed_client);
79 + return;
80 + }
77 if ((event.value_mask & xlib.c.CWBorderWidth) != 0) { 81 if ((event.value_mask & xlib.c.CWBorderWidth) != 0) {
78 managed_client.border_width = event.border_width; 82 managed_client.border_width = event.border_width;
79 } else if (managed_client.is_floating or (managed_client.monitor != null and managed_client.monitor.?.lt[managed_client.monitor.?.sel_lt] == null)) { 83 } else if (managed_client.is_floating or (managed_client.monitor != null and managed_client.monitor.?.lt[managed_client.monitor.?.sel_lt] == null)) {
@@ -318,6 +322,9 @@ fn handleClientMessage(event: *xlib.XClientMessageEvent, wm: *WindowManager) voi
318 core.setFullscreen(client, !client.is_fullscreen, wm); 322 core.setFullscreen(client, !client.is_fullscreen, wm);
319 } 323 }
320 } 324 }
325 + core.publishNetWmState(client, wm);
326 + } else if (event.message_type == wm.atoms.wm_change_state) {
327 + core.setClientState(client, core.NormalState, wm);
321 } else if (event.message_type == wm.atoms.net_active_window) { 328 } else if (event.message_type == wm.atoms.net_active_window) {
322 const selected = wm.selected_monitor orelse return; 329 const selected = wm.selected_monitor orelse return;
323 if (client != selected.sel and !client.is_urgent) { 330 if (client != selected.sel and !client.is_urgent) {
@@ -336,7 +343,7 @@ fn handleDestroyNotify(event: *xlib.XDestroyWindowEvent, wm: *WindowManager) voi
336 343
337 const client = client_mod.windowToClient(wm.monitors, event.window) orelse return; 344 const client = client_mod.windowToClient(wm.monitors, event.window) orelse return;
338 std.debug.print("destroy_notify: window=0x{x}\n", .{event.window}); 345 std.debug.print("destroy_notify: window=0x{x}\n", .{event.window});
339 - core.unmanage(client, wm); 346 + core.unmanage(client, true, wm);
340 } 347 }
341 348
342 fn handleUnmapNotify(event: *xlib.XUnmapEvent, wm: *WindowManager) void { 349 fn handleUnmapNotify(event: *xlib.XUnmapEvent, wm: *WindowManager) void {
@@ -349,7 +356,7 @@ fn handleUnmapNotify(event: *xlib.XUnmapEvent, wm: *WindowManager) void {
349 356
350 const client = client_mod.windowToClient(wm.monitors, event.window) orelse return; 357 const client = client_mod.windowToClient(wm.monitors, event.window) orelse return;
351 std.debug.print("unmap_notify: window=0x{x}\n", .{event.window}); 358 std.debug.print("unmap_notify: window=0x{x}\n", .{event.window});
352 - core.unmanage(client, wm); 359 + core.unmanage(client, false, wm);
353 } 360 }
354 361
355 fn handleEnterNotify(event: *xlib.XCrossingEvent, wm: *WindowManager) void { 362 fn handleEnterNotify(event: *xlib.XCrossingEvent, wm: *WindowManager) void {
@@ -430,6 +437,7 @@ fn handlePropertyNotify(event: *xlib.XPropertyEvent, wm: *WindowManager) void {
430 wm.invalidateBars(); 437 wm.invalidateBars();
431 } else if (event.atom == xlib.XA_WM_NAME or event.atom == wm.atoms.net_wm_name) { 438 } else if (event.atom == xlib.XA_WM_NAME or event.atom == wm.atoms.net_wm_name) {
432 core.updateTitle(client, wm); 439 core.updateTitle(client, wm);
440 + core.applyFullscreenRule(client, wm);
433 } else if (event.atom == wm.atoms.net_wm_window_type) { 441 } else if (event.atom == wm.atoms.net_wm_window_type) {
434 core.updateWindowType(client, wm); 442 core.updateWindowType(client, wm);
435 } 443 }
+2 −0 src/x11/atoms.zig
@@ -7,6 +7,7 @@ pub const Atoms = struct {
7 wm_delete: xlib.Atom, 7 wm_delete: xlib.Atom,
8 wm_state: xlib.Atom, 8 wm_state: xlib.Atom,
9 wm_take_focus: xlib.Atom, 9 wm_take_focus: xlib.Atom,
10 + wm_change_state: xlib.Atom,
10 11
11 // EWHM atoms 12 // EWHM atoms
12 net_supported: xlib.Atom, 13 net_supported: xlib.Atom,
@@ -39,6 +40,7 @@ pub const Atoms = struct {
39 .wm_delete = intern(display, "WM_DELETE_WINDOW"), 40 .wm_delete = intern(display, "WM_DELETE_WINDOW"),
40 .wm_state = intern(display, "WM_STATE"), 41 .wm_state = intern(display, "WM_STATE"),
41 .wm_take_focus = intern(display, "WM_TAKE_FOCUS"), 42 .wm_take_focus = intern(display, "WM_TAKE_FOCUS"),
43 + .wm_change_state = intern(display, "WM_CHANGE_STATE"),
42 44
43 .net_supported = intern(display, "_NET_SUPPORTED"), 45 .net_supported = intern(display, "_NET_SUPPORTED"),
44 .net_wm_name = intern(display, "_NET_WM_NAME"), 46 .net_wm_name = intern(display, "_NET_WM_NAME"),