tony / oxwm

Merge pull request #257 from tonybanters/fix-warcraft-for-degens Browse files
Fix warcraft for degens
Tony, btw. committed 2026-10-06 parents 8a50a1f 3daf041 commit 50c7f9b9b05b10a5c82b8cb26b55d6254f8f82f5
Showing 6 changed files with 90 additions and 31 deletions. UnifiedSplit
+1 −0 src/client.zig
@@ -33,6 +33,7 @@ pub const Client = struct {
33 33 never_focus: bool = false,
34 34 old_state: bool = false,
35 35 is_fullscreen: bool = false,
36 + rule_fullscreen: bool = false,
36 37 next: ?*Client = null,
37 38 stack_next: ?*Client = null,
38 39 monitor: ?*Monitor = null,
+1 −0 src/config/config.zig
@@ -56,6 +56,7 @@ pub const Rule = struct {
56 56 title: ?[]const u8,
57 57 tags: u32,
58 58 is_floating: bool,
59 + is_fullscreen: bool,
59 60 monitor: i32,
60 61 focus: bool,
61 62 };
+7 −0 src/config/lua.zig
@@ -738,6 +738,7 @@ fn luaRuleAdd(state: ?*c.lua_State) callconv(.c) c_int {
738 738 .title = null,
739 739 .tags = 0,
740 740 .is_floating = false,
741 + .is_fullscreen = false,
741 742 .monitor = -1,
742 743 .focus = false,
743 744 };
@@ -775,6 +776,12 @@ fn luaRuleAdd(state: ?*c.lua_State) callconv(.c) c_int {
775 776 }
776 777 c.lua_settop(s, -2);
777 778
779 + _ = c.lua_getfield(s, 1, "fullscreen");
780 + if (c.lua_type(s, -1) == c.LUA_TBOOLEAN) {
781 + rule.is_fullscreen = c.lua_toboolean(s, -1) != 0;
782 + }
783 + c.lua_settop(s, -2);
784 +
778 785 _ = c.lua_getfield(s, 1, "monitor");
779 786 if (c.lua_type(s, -1) == c.LUA_TNUMBER) {
780 787 rule.monitor = @intCast(c.lua_tointegerx(s, -1, null));
+69 −29 src/wm/core.zig
@@ -110,11 +110,19 @@ pub fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *Wind
110 110 arrange(monitor, wm);
111 111 _ = xlib.XMapWindow(wm.display.handle, win);
112 112 focus(null, wm);
113 +
114 + if (client.rule_fullscreen) {
115 + setFullscreen(client, true, wm);
116 + }
113 117 }
114 118
115 -pub fn unmanage(client: *Client, wm: *WindowManager) void {
119 +pub fn unmanage(client: *Client, destroyed: bool, wm: *WindowManager) void {
116 120 const client_monitor = client.monitor;
117 121
122 + if (!destroyed) {
123 + setClientState(client, window_manager.WithdrawnState, wm);
124 + }
125 +
118 126 var next_focus: ?*Client = null;
119 127 if (client_monitor) |monitor| {
120 128 if (monitor.sel == client and isScrollingLayout(monitor)) {
@@ -328,25 +336,30 @@ pub fn grabbuttons(client: *Client, focused: bool, wm: *WindowManager) void {
328 336
329 337 pub fn setClientState(client: *Client, state: c_long, wm: *WindowManager) void {
330 338 var data: [2]c_long = .{ state, xlib.None };
331 - _ = xlib.c.XChangeProperty(wm.display.handle, client.window, wm.atoms.wm_state, xlib.XA_ATOM, 32, xlib.PropModeReplace, @ptrCast(&data), 2);
339 + _ = xlib.c.XChangeProperty(wm.display.handle, client.window, wm.atoms.wm_state, wm.atoms.wm_state, 32, xlib.PropModeReplace, @ptrCast(&data), 2);
340 +}
341 +
342 +pub fn publishNetWmState(client: *Client, wm: *WindowManager) void {
343 + var fullscreen_atom = wm.atoms.net_wm_state_fullscreen;
344 + const count: c_int = if (client.is_fullscreen) 1 else 0;
345 + _ = xlib.XChangeProperty(
346 + wm.display.handle,
347 + client.window,
348 + wm.atoms.net_wm_state,
349 + xlib.XA_ATOM,
350 + 32,
351 + xlib.PropModeReplace,
352 + @ptrCast(&fullscreen_atom),
353 + count,
354 + );
332 355 }
333 356
334 357 pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void {
335 358 const monitor = client.monitor orelse return;
336 359
337 360 if (fullscreen and !client.is_fullscreen) {
338 - var fullscreen_atom = wm.atoms.net_wm_state_fullscreen;
339 - _ = xlib.XChangeProperty(
340 - wm.display.handle,
341 - client.window,
342 - wm.atoms.net_wm_state,
343 - xlib.XA_ATOM,
344 - 32,
345 - xlib.PropModeReplace,
346 - @ptrCast(&fullscreen_atom),
347 - 1,
348 - );
349 361 client.is_fullscreen = true;
362 + publishNetWmState(client, wm);
350 363 client.old_state = client.is_floating;
351 364 client.old_border_width = client.border_width;
352 365 client.border_width = 0;
@@ -358,18 +371,8 @@ pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void
358 371
359 372 std.debug.print("fullscreen enabled: window=0x{x}\n", .{client.window});
360 373 } else if (!fullscreen and client.is_fullscreen) {
361 - var no_atom: xlib.Atom = 0;
362 - _ = xlib.XChangeProperty(
363 - wm.display.handle,
364 - client.window,
365 - wm.atoms.net_wm_state,
366 - xlib.XA_ATOM,
367 - 32,
368 - xlib.PropModeReplace,
369 - @ptrCast(&no_atom),
370 - 0,
371 - );
372 374 client.is_fullscreen = false;
375 + publishNetWmState(client, wm);
373 376 client.is_floating = client.old_state;
374 377 client.border_width = client.old_border_width;
375 378
@@ -463,24 +466,61 @@ fn positionFloating(client: *Client, monitor: *Monitor, pos: config_mod.Floating
463 466 client.y = y;
464 467 }
465 468
469 +fn ruleMatches(rule: config_mod.Rule, class_str: []const u8, instance_str: []const u8, title_str: []const u8) bool {
470 + const class_matches = if (rule.class) |rc| std.mem.indexOf(u8, class_str, rc) != null else true;
471 + const instance_matches = if (rule.instance) |ri| std.mem.indexOf(u8, instance_str, ri) != null else true;
472 + const title_matches = if (rule.title) |rt| std.mem.indexOf(u8, title_str, rt) != null else true;
473 + return class_matches and instance_matches and title_matches;
474 +}
475 +
476 +pub fn applyFullscreenRule(client: *Client, wm: *WindowManager) void {
477 + if (client.rule_fullscreen or client.is_fullscreen) return;
478 +
479 + var has_fullscreen_rule = false;
480 + for (wm.config.rules.items) |rule| {
481 + if (rule.is_fullscreen) has_fullscreen_rule = true;
482 + }
483 + if (!has_fullscreen_rule) return;
484 +
485 + var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null };
486 + _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint);
487 + defer {
488 + if (class_hint.res_class) |ptr| _ = xlib.XFree(@ptrCast(ptr));
489 + if (class_hint.res_name) |ptr| _ = xlib.XFree(@ptrCast(ptr));
490 + }
491 +
492 + const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else "";
493 + const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else "";
494 + const title_str = std.mem.sliceTo(&client.name, 0);
495 +
496 + for (wm.config.rules.items) |rule| {
497 + if (rule.is_fullscreen and ruleMatches(rule, class_str, instance_str, title_str)) {
498 + client.rule_fullscreen = true;
499 + setFullscreen(client, true, wm);
500 + return;
501 + }
502 + }
503 +}
504 +
466 505 pub fn applyRules(client: *Client, wm: *WindowManager) void {
467 506 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null };
468 507 _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint);
469 508
470 509 const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else "";
471 510 const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else "";
511 + const title_str = std.mem.sliceTo(&client.name, 0);
472 512
473 513 client.is_floating = false;
474 514 client.tags = 0;
515 + client.rule_fullscreen = false;
475 516 var rule_focus = false;
476 517
477 518 for (wm.config.rules.items) |rule| {
478 - const class_matches = if (rule.class) |rc| std.mem.indexOf(u8, class_str, rc) != null else true;
479 - const instance_matches = if (rule.instance) |ri| std.mem.indexOf(u8, instance_str, ri) != null else true;
480 - const title_matches = if (rule.title) |rt| std.mem.indexOf(u8, std.mem.sliceTo(&client.name, 0), rt) != null else true;
481 -
482 - if (class_matches and instance_matches and title_matches) {
519 + if (ruleMatches(rule, class_str, instance_str, title_str)) {
483 520 client.is_floating = rule.is_floating;
521 + if (rule.is_fullscreen) {
522 + client.rule_fullscreen = true;
523 + }
484 524 client.tags |= rule.tags;
485 525 if (rule.monitor >= 0) {
486 526 var target = wm.monitors;
+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"),