tony / oxwm

Added focus follows rule back into window rules on zig lua. Browse files
tonybanters committed 2026-02-19 parent f64308d commit 9de572d2f3992f8b8f5e25c068791181e2e3c191
Showing 3 changed files with 20 additions and 0 deletions. UnifiedSplit
+1 −0 src/config/config.zig
@@ -56,6 +56,7 @@ pub const Rule = struct {
56 56 tags: u32,
57 57 is_floating: bool,
58 58 monitor: i32,
59 + focus: bool,
59 60 };
60 61
61 62 pub const Block_Type = enum {
+7 −0 src/config/lua.zig
@@ -695,6 +695,7 @@ fn lua_rule_add(state: ?*c.lua_State) callconv(.c) c_int {
695 695 .tags = 0,
696 696 .is_floating = false,
697 697 .monitor = -1,
698 + .focus = false,
698 699 };
699 700
700 701 _ = c.lua_getfield(s, 1, "class");
@@ -736,6 +737,12 @@ fn lua_rule_add(state: ?*c.lua_State) callconv(.c) c_int {
736 737 }
737 738 c.lua_settop(s, -2);
738 739
740 + _ = c.lua_getfield(s, 1, "focus");
741 + if (c.lua_type(s, -1) == c.LUA_TBOOLEAN) {
742 + rule.focus = c.lua_toboolean(s, -1) != 0;
743 + }
744 + c.lua_settop(s, -2);
745 +
739 746 cfg.add_rule(rule) catch return 0;
740 747 return 0;
741 748 }
+12 −0 src/main.zig
@@ -2472,6 +2472,7 @@ fn apply_rules(display: *Display, client: *Client) void {
2472 2472
2473 2473 client.is_floating = false;
2474 2474 client.tags = 0;
2475 + var rule_focus = false;
2475 2476
2476 2477 for (config.rules.items) |rule| {
2477 2478 const class_matches = if (rule.class) |rc| std.mem.indexOf(u8, class_str, rc) != null else true;
@@ -2493,6 +2494,9 @@ fn apply_rules(display: *Display, client: *Client) void {
2493 2494 target = mon.next;
2494 2495 }
2495 2496 }
2497 + if (rule.focus) {
2498 + rule_focus = true;
2499 + }
2496 2500 }
2497 2501 }
2498 2502
@@ -2507,6 +2511,14 @@ fn apply_rules(display: *Display, client: *Client) void {
2507 2511 if (client.tags == 0) {
2508 2512 client.tags = monitor.tagset[monitor.sel_tags];
2509 2513 }
2514 +
2515 + if (rule_focus and client.tags != 0) {
2516 + const monitor_tagset = monitor.tagset[monitor.sel_tags];
2517 + const is_tag_focused = (monitor_tagset & client.tags) == client.tags;
2518 + if (!is_tag_focused) {
2519 + view(display, client.tags);
2520 + }
2521 + }
2510 2522 }
2511 2523
2512 2524 fn update_client_list(display: *Display) void {