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 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 24 ## Installation
10 25
11 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 34 old_state: bool = false,
35 35 is_fullscreen: bool = false,
36 36 scroll_width: f32 = 0,
37 + rule_fullscreen: bool = false,
37 38 next: ?*Client = null,
38 39 stack_next: ?*Client = null,
39 40 monitor: ?*Monitor = null,
+1 −0 src/config/config.zig
@@ -58,6 +58,7 @@ pub const Rule = struct {
58 58 title: ?[]const u8,
59 59 tags: u32,
60 60 is_floating: bool,
61 + is_fullscreen: bool,
61 62 monitor: i32,
62 63 focus: bool,
63 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 869 .title = null,
870 870 .tags = 0,
871 871 .is_floating = false,
872 + .is_fullscreen = false,
872 873 .monitor = -1,
873 874 .focus = false,
874 875 };
@@ -906,6 +907,12 @@ fn luaRuleAdd(state: ?*c.lua_State) callconv(.c) c_int {
906 907 }
907 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 916 _ = c.lua_getfield(s, 1, "monitor");
910 917 if (c.lua_type(s, -1) == c.LUA_TNUMBER) {
911 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 111 arrange(monitor, wm);
112 112 _ = xlib.XMapWindow(wm.display.handle, win);
113 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 121 const client_monitor = client.monitor;
118 122
123 + if (!destroyed) {
124 + setClientState(client, window_manager.WithdrawnState, wm);
125 + }
126 +
119 127 var next_focus: ?*Client = null;
120 128 if (client_monitor) |monitor| {
121 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 345 pub fn setClientState(client: *Client, state: c_long, wm: *WindowManager) void {
338 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 365 pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void {
343 366 const monitor = client.monitor orelse return;
344 367
345 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 369 client.is_fullscreen = true;
370 + publishNetWmState(client, wm);
358 371 client.old_state = client.is_floating;
359 372 client.old_border_width = client.border_width;
360 373 client.border_width = 0;
@@ -366,18 +379,8 @@ pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void
366 379
367 380 std.debug.print("fullscreen enabled: window=0x{x}\n", .{client.window});
368 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 382 client.is_fullscreen = false;
383 + publishNetWmState(client, wm);
381 384 client.is_floating = client.old_state;
382 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 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 612 pub fn applyRules(client: *Client, wm: *WindowManager) void {
574 613 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null };
575 614 _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint);
576 615
577 616 const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else "";
578 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 620 client.is_floating = false;
581 621 client.tags = 0;
622 + client.rule_fullscreen = false;
582 623 var rule_focus = false;
583 624
584 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;
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) {
626 + if (ruleMatches(rule, class_str, instance_str, title_str)) {
590 627 client.is_floating = rule.is_floating;
628 + if (rule.is_fullscreen) {
629 + client.rule_fullscreen = true;
630 + }
591 631 client.tags |= rule.tags;
592 632 if (rule.width > 0) client.scroll_width = rule.width;
593 633 if (rule.monitor >= 0) {
+10 −2 src/wm/handlers.zig
@@ -74,6 +74,10 @@ fn handleConfigureRequest(event: *xlib.XConfigureRequestEvent, wm: *WindowManage
74 74 const client = client_mod.windowToClient(wm.monitors, event.window);
75 75
76 76 if (client) |managed_client| {
77 + if (managed_client.is_fullscreen) {
78 + tiling.sendConfigure(managed_client);
79 + return;
80 + }
77 81 if ((event.value_mask & xlib.c.CWBorderWidth) != 0) {
78 82 managed_client.border_width = event.border_width;
79 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 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 328 } else if (event.message_type == wm.atoms.net_active_window) {
322 329 const selected = wm.selected_monitor orelse return;
323 330 if (client != selected.sel and !client.is_urgent) {
@@ -336,7 +343,7 @@ fn handleDestroyNotify(event: *xlib.XDestroyWindowEvent, wm: *WindowManager) voi
336 343
337 344 const client = client_mod.windowToClient(wm.monitors, event.window) orelse return;
338 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 349 fn handleUnmapNotify(event: *xlib.XUnmapEvent, wm: *WindowManager) void {
@@ -349,7 +356,7 @@ fn handleUnmapNotify(event: *xlib.XUnmapEvent, wm: *WindowManager) void {
349 356
350 357 const client = client_mod.windowToClient(wm.monitors, event.window) orelse return;
351 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 362 fn handleEnterNotify(event: *xlib.XCrossingEvent, wm: *WindowManager) void {
@@ -430,6 +437,7 @@ fn handlePropertyNotify(event: *xlib.XPropertyEvent, wm: *WindowManager) void {
430 437 wm.invalidateBars();
431 438 } else if (event.atom == xlib.XA_WM_NAME or event.atom == wm.atoms.net_wm_name) {
432 439 core.updateTitle(client, wm);
440 + core.applyFullscreenRule(client, wm);
433 441 } else if (event.atom == wm.atoms.net_wm_window_type) {
434 442 core.updateWindowType(client, wm);
435 443 }
+2 −0 src/x11/atoms.zig
@@ -7,6 +7,7 @@ pub const Atoms = struct {
7 7 wm_delete: xlib.Atom,
8 8 wm_state: xlib.Atom,
9 9 wm_take_focus: xlib.Atom,
10 + wm_change_state: xlib.Atom,
10 11
11 12 // EWHM atoms
12 13 net_supported: xlib.Atom,
@@ -39,6 +40,7 @@ pub const Atoms = struct {
39 40 .wm_delete = intern(display, "WM_DELETE_WINDOW"),
40 41 .wm_state = intern(display, "WM_STATE"),
41 42 .wm_take_focus = intern(display, "WM_TAKE_FOCUS"),
43 + .wm_change_state = intern(display, "WM_CHANGE_STATE"),
42 44
43 45 .net_supported = intern(display, "_NET_SUPPORTED"),
44 46 .net_wm_name = intern(display, "_NET_WM_NAME"),