tony / oxwm

fixed the wm_state property type, set withdrawn state on unmap, published net_wm_state through one helper and applied fullscreen rules on manage and title change Browse files
tonybanters committed 2026-10-06 parent 1ccdbc9 commit 67e11410382060b5d7714ccc7662b7aabc39289c
Showing 1 changed file with 69 additions and 29 deletions. UnifiedSplit
+69 −29 src/wm/core.zig
@@ -110,11 +110,19 @@ pub fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *Wind
110 arrange(monitor, wm); 110 arrange(monitor, wm);
111 _ = xlib.XMapWindow(wm.display.handle, win); 111 _ = xlib.XMapWindow(wm.display.handle, win);
112 focus(null, wm); 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 const client_monitor = client.monitor; 120 const client_monitor = client.monitor;
117 121
122 + if (!destroyed) {
123 + setClientState(client, window_manager.WithdrawnState, wm);
124 + }
125 +
118 var next_focus: ?*Client = null; 126 var next_focus: ?*Client = null;
119 if (client_monitor) |monitor| { 127 if (client_monitor) |monitor| {
120 if (monitor.sel == client and isScrollingLayout(monitor)) { 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 pub fn setClientState(client: *Client, state: c_long, wm: *WindowManager) void { 337 pub fn setClientState(client: *Client, state: c_long, wm: *WindowManager) void {
330 var data: [2]c_long = .{ state, xlib.None }; 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 pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void { 357 pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void {
335 const monitor = client.monitor orelse return; 358 const monitor = client.monitor orelse return;
336 359
337 if (fullscreen and !client.is_fullscreen) { 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 client.is_fullscreen = true; 361 client.is_fullscreen = true;
362 + publishNetWmState(client, wm);
350 client.old_state = client.is_floating; 363 client.old_state = client.is_floating;
351 client.old_border_width = client.border_width; 364 client.old_border_width = client.border_width;
352 client.border_width = 0; 365 client.border_width = 0;
@@ -358,18 +371,8 @@ pub fn setFullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void
358 371
359 std.debug.print("fullscreen enabled: window=0x{x}\n", .{client.window}); 372 std.debug.print("fullscreen enabled: window=0x{x}\n", .{client.window});
360 } else if (!fullscreen and client.is_fullscreen) { 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 client.is_fullscreen = false; 374 client.is_fullscreen = false;
375 + publishNetWmState(client, wm);
373 client.is_floating = client.old_state; 376 client.is_floating = client.old_state;
374 client.border_width = client.old_border_width; 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 client.y = y; 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 pub fn applyRules(client: *Client, wm: *WindowManager) void { 505 pub fn applyRules(client: *Client, wm: *WindowManager) void {
467 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null }; 506 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null };
468 _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint); 507 _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint);
469 508
470 const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else ""; 509 const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else "";
471 const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else ""; 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 client.is_floating = false; 513 client.is_floating = false;
474 client.tags = 0; 514 client.tags = 0;
515 + client.rule_fullscreen = false;
475 var rule_focus = false; 516 var rule_focus = false;
476 517
477 for (wm.config.rules.items) |rule| { 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; 519 + if (ruleMatches(rule, class_str, instance_str, title_str)) {
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) {
483 client.is_floating = rule.is_floating; 520 client.is_floating = rule.is_floating;
521 + if (rule.is_fullscreen) {
522 + client.rule_fullscreen = true;
523 + }
484 client.tags |= rule.tags; 524 client.tags |= rule.tags;
485 if (rule.monitor >= 0) { 525 if (rule.monitor >= 0) {
486 var target = wm.monitors; 526 var target = wm.monitors;