tony / oxwm

refactor: remove local `display` alias and use `wm.display` directly Browse files
emzywastaken committed 2026-02-21 parent 8f72bc0 commit f7c278625136dcc92ef201b04c9e4df5950f7b71
Showing 1 changed file with 93 additions and 128 deletions. UnifiedSplit
+93 −128 src/main.zig Large diff collapsed, click to expand
@@ -272,23 +272,22 @@ fn initialize_default_config(cfg: *config_mod.Config) void {
272 } 272 }
273 273
274 fn grab_keybinds(wm: *WindowManager) void { 274 fn grab_keybinds(wm: *WindowManager) void {
275 - const display = &wm.display;
276 update_numlock_mask(wm); 275 update_numlock_mask(wm);
277 const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask }; 276 const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask };
278 277
279 - _ = xlib.XUngrabKey(display.handle, xlib.AnyKey, xlib.AnyModifier, display.root); 278 + _ = xlib.XUngrabKey(wm.display.handle, xlib.AnyKey, xlib.AnyModifier, wm.display.root);
280 279
281 for (wm.config.keybinds.items) |keybind| { 280 for (wm.config.keybinds.items) |keybind| {
282 if (keybind.key_count == 0) continue; 281 if (keybind.key_count == 0) continue;
283 const first_key = keybind.keys[0]; 282 const first_key = keybind.keys[0];
284 - const keycode = xlib.XKeysymToKeycode(display.handle, @intCast(first_key.keysym)); 283 + const keycode = xlib.XKeysymToKeycode(wm.display.handle, @intCast(first_key.keysym));
285 if (keycode != 0) { 284 if (keycode != 0) {
286 for (modifiers) |modifier| { 285 for (modifiers) |modifier| {
287 _ = xlib.XGrabKey( 286 _ = xlib.XGrabKey(
288 - display.handle, 287 + wm.display.handle,
289 keycode, 288 keycode,
290 first_key.mod_mask | modifier, 289 first_key.mod_mask | modifier,
291 - display.root, 290 + wm.display.root,
292 xlib.True, 291 xlib.True,
293 xlib.GrabModeAsync, 292 xlib.GrabModeAsync,
294 xlib.GrabModeAsync, 293 xlib.GrabModeAsync,
@@ -301,10 +300,10 @@ fn grab_keybinds(wm: *WindowManager) void {
301 if (button.click == .client_win) { 300 if (button.click == .client_win) {
302 for (modifiers) |modifier| { 301 for (modifiers) |modifier| {
303 _ = xlib.XGrabButton( 302 _ = xlib.XGrabButton(
304 - display.handle, 303 + wm.display.handle,
305 @intCast(button.button), 304 @intCast(button.button),
306 button.mod_mask | modifier, 305 button.mod_mask | modifier,
307 - display.root, 306 + wm.display.root,
308 xlib.True, 307 xlib.True,
309 xlib.ButtonPressMask | xlib.ButtonReleaseMask | xlib.PointerMotionMask, 308 xlib.ButtonPressMask | xlib.ButtonReleaseMask | xlib.PointerMotionMask,
310 xlib.GrabModeAsync, 309 xlib.GrabModeAsync,
@@ -320,7 +319,6 @@ fn grab_keybinds(wm: *WindowManager) void {
320 } 319 }
321 320
322 fn get_state(window: xlib.Window, wm: *WindowManager) c_long { 321 fn get_state(window: xlib.Window, wm: *WindowManager) c_long {
323 - const display = &wm.display;
324 var actual_type: xlib.Atom = 0; 322 var actual_type: xlib.Atom = 0;
325 var actual_format: c_int = 0; 323 var actual_format: c_int = 0;
326 var num_items: c_ulong = 0; 324 var num_items: c_ulong = 0;
@@ -328,7 +326,7 @@ fn get_state(window: xlib.Window, wm: *WindowManager) c_long {
328 var prop: [*c]u8 = null; 326 var prop: [*c]u8 = null;
329 327
330 const result = xlib.XGetWindowProperty( 328 const result = xlib.XGetWindowProperty(
331 - display.handle, 329 + wm.display.handle,
332 window, 330 window,
333 wm.atoms.wm_state, 331 wm.atoms.wm_state,
334 0, 332 0,
@@ -355,27 +353,26 @@ fn get_state(window: xlib.Window, wm: *WindowManager) c_long {
355 } 353 }
356 354
357 fn scan_existing_windows(wm: *WindowManager) void { 355 fn scan_existing_windows(wm: *WindowManager) void {
358 - const display = &wm.display;
359 var root_return: xlib.Window = undefined; 356 var root_return: xlib.Window = undefined;
360 var parent_return: xlib.Window = undefined; 357 var parent_return: xlib.Window = undefined;
361 var children: [*c]xlib.Window = undefined; 358 var children: [*c]xlib.Window = undefined;
362 var num_children: c_uint = undefined; 359 var num_children: c_uint = undefined;
363 360
364 - if (xlib.XQueryTree(display.handle, display.root, &root_return, &parent_return, &children, &num_children) == 0) { 361 + if (xlib.XQueryTree(wm.display.handle, wm.display.root, &root_return, &parent_return, &children, &num_children) == 0) {
365 return; 362 return;
366 } 363 }
367 364
368 var index: c_uint = 0; 365 var index: c_uint = 0;
369 while (index < num_children) : (index += 1) { 366 while (index < num_children) : (index += 1) {
370 var window_attrs: xlib.XWindowAttributes = undefined; 367 var window_attrs: xlib.XWindowAttributes = undefined;
371 - if (xlib.XGetWindowAttributes(display.handle, children[index], &window_attrs) == 0) { 368 + if (xlib.XGetWindowAttributes(wm.display.handle, children[index], &window_attrs) == 0) {
372 continue; 369 continue;
373 } 370 }
374 if (window_attrs.override_redirect != 0) { 371 if (window_attrs.override_redirect != 0) {
375 continue; 372 continue;
376 } 373 }
377 var trans: xlib.Window = 0; 374 var trans: xlib.Window = 0;
378 - if (xlib.XGetTransientForHint(display.handle, children[index], &trans) != 0) { 375 + if (xlib.XGetTransientForHint(wm.display.handle, children[index], &trans) != 0) {
379 continue; 376 continue;
380 } 377 }
381 if (window_attrs.map_state == IsViewable or get_state(children[index], wm) == IconicState) { 378 if (window_attrs.map_state == IsViewable or get_state(children[index], wm) == IconicState) {
@@ -386,11 +383,11 @@ fn scan_existing_windows(wm: *WindowManager) void {
386 index = 0; 383 index = 0;
387 while (index < num_children) : (index += 1) { 384 while (index < num_children) : (index += 1) {
388 var window_attrs: xlib.XWindowAttributes = undefined; 385 var window_attrs: xlib.XWindowAttributes = undefined;
389 - if (xlib.XGetWindowAttributes(display.handle, children[index], &window_attrs) == 0) { 386 + if (xlib.XGetWindowAttributes(wm.display.handle, children[index], &window_attrs) == 0) {
390 continue; 387 continue;
391 } 388 }
392 var trans: xlib.Window = 0; 389 var trans: xlib.Window = 0;
393 - if (xlib.XGetTransientForHint(display.handle, children[index], &trans) != 0) { 390 + if (xlib.XGetTransientForHint(wm.display.handle, children[index], &trans) != 0) {
394 if (window_attrs.map_state == IsViewable or get_state(children[index], wm) == IconicState) { 391 if (window_attrs.map_state == IsViewable or get_state(children[index], wm) == IconicState) {
395 manage(children[index], &window_attrs, wm); 392 manage(children[index], &window_attrs, wm);
396 } 393 }
@@ -454,11 +451,10 @@ fn handle_event(event: *xlib.XEvent, wm: *WindowManager) void {
454 } 451 }
455 452
456 fn handle_map_request(event: *xlib.XMapRequestEvent, wm: *WindowManager) void { 453 fn handle_map_request(event: *xlib.XMapRequestEvent, wm: *WindowManager) void {
457 - const display = &wm.display;
458 std.debug.print("map_request: window=0x{x}\n", .{event.window}); 454 std.debug.print("map_request: window=0x{x}\n", .{event.window});
459 455
460 var window_attributes: xlib.XWindowAttributes = undefined; 456 var window_attributes: xlib.XWindowAttributes = undefined;
461 - if (xlib.XGetWindowAttributes(display.handle, event.window, &window_attributes) == 0) { 457 + if (xlib.XGetWindowAttributes(wm.display.handle, event.window, &window_attributes) == 0) {
462 return; 458 return;
463 } 459 }
464 if (window_attributes.override_redirect != 0) { 460 if (window_attributes.override_redirect != 0) {
@@ -472,7 +468,6 @@ fn handle_map_request(event: *xlib.XMapRequestEvent, wm: *WindowManager) void {
472 } 468 }
473 469
474 fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *WindowManager) void { 470 fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *WindowManager) void {
475 - const display = &wm.display;
476 const client = client_mod.create(gpa.allocator(), win) orelse return; 471 const client = client_mod.create(gpa.allocator(), win) orelse return;
477 var trans: xlib.Window = 0; 472 var trans: xlib.Window = 0;
478 473
@@ -489,7 +484,7 @@ fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *WindowMa
489 484
490 update_title(client, wm); 485 update_title(client, wm);
491 486
492 - if (xlib.XGetTransientForHint(display.handle, win, &trans) != 0) { 487 + if (xlib.XGetTransientForHint(wm.display.handle, win, &trans) != 0) {
493 if (client_mod.window_to_client(monitor_mod.monitors, trans)) |transient_client| { 488 if (client_mod.window_to_client(monitor_mod.monitors, trans)) |transient_client| {
494 client.monitor = transient_client.monitor; 489 client.monitor = transient_client.monitor;
495 client.tags = transient_client.tags; 490 client.tags = transient_client.tags;
@@ -512,8 +507,8 @@ fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *WindowMa
512 client.x = @max(client.x, monitor.win_x); 507 client.x = @max(client.x, monitor.win_x);
513 client.y = @max(client.y, monitor.win_y); 508 client.y = @max(client.y, monitor.win_y);
514 509
515 - _ = xlib.XSetWindowBorderWidth(display.handle, win, @intCast(client.border_width)); 510 + _ = xlib.XSetWindowBorderWidth(wm.display.handle, win, @intCast(client.border_width));
516 - _ = xlib.XSetWindowBorder(display.handle, win, wm.config.border_unfocused); 511 + _ = xlib.XSetWindowBorder(wm.display.handle, win, wm.config.border_unfocused);
517 tiling.send_configure(client); 512 tiling.send_configure(client);
518 513
519 update_window_type(client, wm); 514 update_window_type(client, wm);
@@ -521,7 +516,7 @@ fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *WindowMa
521 update_wm_hints(client, wm); 516 update_wm_hints(client, wm);
522 517
523 _ = xlib.XSelectInput( 518 _ = xlib.XSelectInput(
524 - display.handle, 519 + wm.display.handle,
525 win, 520 win,
526 xlib.EnterWindowMask | xlib.FocusChangeMask | xlib.PropertyChangeMask | xlib.StructureNotifyMask, 521 xlib.EnterWindowMask | xlib.FocusChangeMask | xlib.PropertyChangeMask | xlib.StructureNotifyMask,
527 ); 522 );
@@ -532,14 +527,14 @@ fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *WindowMa
532 client.old_state = client.is_floating; 527 client.old_state = client.is_floating;
533 } 528 }
534 if (client.is_floating) { 529 if (client.is_floating) {
535 - _ = xlib.XRaiseWindow(display.handle, client.window); 530 + _ = xlib.XRaiseWindow(wm.display.handle, client.window);
536 } 531 }
537 532
538 client_mod.attach_aside(client); 533 client_mod.attach_aside(client);
539 client_mod.attach_stack(client); 534 client_mod.attach_stack(client);
540 535
541 - _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_client_list, xlib.XA_WINDOW, 32, xlib.PropModeAppend, @ptrCast(&client.window), 1); 536 + _ = xlib.XChangeProperty(wm.display.handle, wm.display.root, wm.atoms.net_client_list, xlib.XA_WINDOW, 32, xlib.PropModeAppend, @ptrCast(&client.window), 1);
542 - _ = xlib.XMoveResizeWindow(display.handle, client.window, client.x + 2 * display.screen_width(), client.y, @intCast(client.width), @intCast(client.height)); 537 + _ = xlib.XMoveResizeWindow(wm.display.handle, client.window, client.x + 2 * wm.display.screen_width(), client.y, @intCast(client.width), @intCast(client.height));
543 set_client_state(client, NormalState, wm); 538 set_client_state(client, NormalState, wm);
544 539
545 if (client.monitor == monitor_mod.selected_monitor) { 540 if (client.monitor == monitor_mod.selected_monitor) {
@@ -553,12 +548,11 @@ fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *WindowMa
553 } 548 }
554 549
555 arrange(monitor, wm); 550 arrange(monitor, wm);
556 - _ = xlib.XMapWindow(display.handle, win); 551 + _ = xlib.XMapWindow(wm.display.handle, win);
557 focus(null, wm); 552 focus(null, wm);
558 } 553 }
559 554
560 fn handle_configure_request(event: *xlib.XConfigureRequestEvent, wm: *WindowManager) void { 555 fn handle_configure_request(event: *xlib.XConfigureRequestEvent, wm: *WindowManager) void {
561 - const display = &wm.display;
562 const client = client_mod.window_to_client(monitor_mod.monitors, event.window); 556 const client = client_mod.window_to_client(monitor_mod.monitors, event.window);
563 557
564 if (client) |managed_client| { 558 if (client) |managed_client| {
@@ -594,7 +588,7 @@ fn handle_configure_request(event: *xlib.XConfigureRequestEvent, wm: *WindowMana
594 tiling.send_configure(managed_client); 588 tiling.send_configure(managed_client);
595 } 589 }
596 if (client_mod.is_visible(managed_client)) { 590 if (client_mod.is_visible(managed_client)) {
597 - _ = xlib.XMoveResizeWindow(display.handle, managed_client.window, managed_client.x, managed_client.y, @intCast(managed_client.width), @intCast(managed_client.height)); 591 + _ = xlib.XMoveResizeWindow(wm.display.handle, managed_client.window, managed_client.x, managed_client.y, @intCast(managed_client.width), @intCast(managed_client.height));
598 } 592 }
599 } else { 593 } else {
600 tiling.send_configure(managed_client); 594 tiling.send_configure(managed_client);
@@ -608,14 +602,13 @@ fn handle_configure_request(event: *xlib.XConfigureRequestEvent, wm: *WindowMana
608 changes.border_width = event.border_width; 602 changes.border_width = event.border_width;
609 changes.sibling = event.above; 603 changes.sibling = event.above;
610 changes.stack_mode = event.detail; 604 changes.stack_mode = event.detail;
611 - _ = xlib.XConfigureWindow(display.handle, event.window, @intCast(event.value_mask), &changes); 605 + _ = xlib.XConfigureWindow(wm.display.handle, event.window, @intCast(event.value_mask), &changes);
612 } 606 }
613 - _ = xlib.XSync(display.handle, xlib.False); 607 + _ = xlib.XSync(wm.display.handle, xlib.False);
614 } 608 }
615 609
616 fn handle_key_press(event: *xlib.XKeyEvent, wm: *WindowManager) void { 610 fn handle_key_press(event: *xlib.XKeyEvent, wm: *WindowManager) void {
617 - const display = &wm.display; 611 + const keysym = xlib.XKeycodeToKeysym(wm.display.handle, @intCast(event.keycode), 0);
618 - const keysym = xlib.XKeycodeToKeysym(display.handle, @intCast(event.keycode), 0);
619 612
620 if (wm.overlay) |overlay| { 613 if (wm.overlay) |overlay| {
621 if (overlay.handle_key(keysym)) return; 614 if (overlay.handle_key(keysym)) return;
@@ -624,7 +617,7 @@ fn handle_key_press(event: *xlib.XKeyEvent, wm: *WindowManager) void {
624 const clean_state = event.state & ~@as(c_uint, xlib.LockMask | xlib.Mod2Mask); 617 const clean_state = event.state & ~@as(c_uint, xlib.LockMask | xlib.Mod2Mask);
625 618
626 if (wm.chord.is_timed_out()) { 619 if (wm.chord.is_timed_out()) {
627 - wm.chord.reset(display.handle); 620 + wm.chord.reset(wm.display.handle);
628 } 621 }
629 622
630 _ = wm.chord.push(.{ .mod_mask = clean_state, .keysym = keysym }); 623 _ = wm.chord.push(.{ .mod_mask = clean_state, .keysym = keysym });
@@ -644,7 +637,7 @@ fn handle_key_press(event: *xlib.XKeyEvent, wm: *WindowManager) void {
644 } 637 }
645 if (matches) { 638 if (matches) {
646 execute_action(keybind.action, keybind.int_arg, keybind.str_arg, wm); 639 execute_action(keybind.action, keybind.int_arg, keybind.str_arg, wm);
647 - wm.chord.reset(display.handle); 640 + wm.chord.reset(wm.display.handle);
648 return; 641 return;
649 } 642 }
650 } 643 }
@@ -670,9 +663,9 @@ fn handle_key_press(event: *xlib.XKeyEvent, wm: *WindowManager) void {
670 } 663 }
671 664
672 if (has_partial_match) { 665 if (has_partial_match) {
673 - wm.chord.grab_keyboard(display.handle, display.root); 666 + wm.chord.grab_keyboard(wm.display.handle, wm.display.root);
674 } else { 667 } else {
675 - wm.chord.reset(display.handle); 668 + wm.chord.reset(wm.display.handle);
676 } 669 }
677 } 670 }
678 671
@@ -739,7 +732,6 @@ fn execute_action(action: config_mod.Action, int_arg: i32, str_arg: ?[]const u8,
739 } 732 }
740 733
741 fn reload_config(wm: *WindowManager) void { 734 fn reload_config(wm: *WindowManager) void {
742 - const display = &wm.display;
743 std.debug.print("reloading config...\n", .{}); 735 std.debug.print("reloading config...\n", .{});
744 736
745 ungrab_keybinds(wm); 737 ungrab_keybinds(wm);
@@ -768,7 +760,7 @@ fn reload_config(wm: *WindowManager) void {
768 initialize_default_config(&wm.config); 760 initialize_default_config(&wm.config);
769 } 761 }
770 762
771 - bar_mod.destroy_bars(wm.bars, gpa.allocator(), display.handle); 763 + bar_mod.destroy_bars(wm.bars, gpa.allocator(), wm.display.handle);
772 wm.bars = null; 764 wm.bars = null;
773 wm.setup_bars(); 765 wm.setup_bars();
774 rebuild_bar_blocks(wm); 766 rebuild_bar_blocks(wm);
@@ -786,8 +778,7 @@ fn rebuild_bar_blocks(wm: *WindowManager) void {
786 } 778 }
787 779
788 fn ungrab_keybinds(wm: *WindowManager) void { 780 fn ungrab_keybinds(wm: *WindowManager) void {
789 - const display = &wm.display; 781 + _ = xlib.XUngrabKey(wm.display.handle, xlib.AnyKey, xlib.AnyModifier, wm.display.root);
790 - _ = xlib.XUngrabKey(display.handle, xlib.AnyKey, xlib.AnyModifier, display.root);
791 } 782 }
792 783
793 fn spawn_child_setup() void { 784 fn spawn_child_setup() void {
@@ -959,16 +950,15 @@ fn toggle_gaps(wm: *WindowManager) void {
959 } 950 }
960 951
961 fn kill_focused(wm: *WindowManager) void { 952 fn kill_focused(wm: *WindowManager) void {
962 - const display = &wm.display;
963 const selected = monitor_mod.selected_monitor orelse return; 953 const selected = monitor_mod.selected_monitor orelse return;
964 const client = selected.sel orelse return; 954 const client = selected.sel orelse return;
965 std.debug.print("killing window: 0x{x}\n", .{client.window}); 955 std.debug.print("killing window: 0x{x}\n", .{client.window});
966 956
967 if (!send_event(client, wm.atoms.wm_delete, wm)) { 957 if (!send_event(client, wm.atoms.wm_delete, wm)) {
968 - _ = xlib.XGrabServer(display.handle); 958 + _ = xlib.XGrabServer(wm.display.handle);
969 - _ = xlib.XKillClient(display.handle, client.window); 959 + _ = xlib.XKillClient(wm.display.handle, client.window);
970 - _ = xlib.XSync(display.handle, xlib.False); 960 + _ = xlib.XSync(wm.display.handle, xlib.False);
971 - _ = xlib.XUngrabServer(display.handle); 961 + _ = xlib.XUngrabServer(wm.display.handle);
972 } 962 }
973 } 963 }
974 964
@@ -979,13 +969,12 @@ fn toggle_fullscreen(wm: *WindowManager) void {
979 } 969 }
980 970
981 fn set_fullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void { 971 fn set_fullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void {
982 - const display = &wm.display;
983 const monitor = client.monitor orelse return; 972 const monitor = client.monitor orelse return;
984 973
985 if (fullscreen and !client.is_fullscreen) { 974 if (fullscreen and !client.is_fullscreen) {
986 var fullscreen_atom = wm.atoms.net_wm_state_fullscreen; 975 var fullscreen_atom = wm.atoms.net_wm_state_fullscreen;
987 _ = xlib.XChangeProperty( 976 _ = xlib.XChangeProperty(
988 - display.handle, 977 + wm.display.handle,
989 client.window, 978 client.window,
990 wm.atoms.net_wm_state, 979 wm.atoms.net_wm_state,
991 xlib.XA_ATOM, 980 xlib.XA_ATOM,
@@ -1000,15 +989,15 @@ fn set_fullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void {
1000 client.border_width = 0; 989 client.border_width = 0;
1001 client.is_floating = true; 990 client.is_floating = true;
1002 991
1003 - _ = xlib.XSetWindowBorderWidth(display.handle, client.window, 0); 992 + _ = xlib.XSetWindowBorderWidth(wm.display.handle, client.window, 0);
1004 tiling.resize_client(client, monitor.mon_x, monitor.mon_y, monitor.mon_w, monitor.mon_h); 993 tiling.resize_client(client, monitor.mon_x, monitor.mon_y, monitor.mon_w, monitor.mon_h);
1005 - _ = xlib.XRaiseWindow(display.handle, client.window); 994 + _ = xlib.XRaiseWindow(wm.display.handle, client.window);
1006 995
1007 std.debug.print("fullscreen enabled: window=0x{x}\n", .{client.window}); 996 std.debug.print("fullscreen enabled: window=0x{x}\n", .{client.window});
1008 } else if (!fullscreen and client.is_fullscreen) { 997 } else if (!fullscreen and client.is_fullscreen) {
1009 var no_atom: xlib.Atom = 0; 998 var no_atom: xlib.Atom = 0;
1010 _ = xlib.XChangeProperty( 999 _ = xlib.XChangeProperty(
1011 - display.handle, 1000 + wm.display.handle,
1012 client.window, 1001 client.window,
1013 wm.atoms.net_wm_state, 1002 wm.atoms.net_wm_state,
1014 xlib.XA_ATOM, 1003 xlib.XA_ATOM,
@@ -1125,7 +1114,6 @@ fn tag_client(tag_mask: u32, wm: *WindowManager) void {
1125 } 1114 }
1126 1115
1127 fn focus_top_client(monitor: *Monitor, wm: *WindowManager) void { 1116 fn focus_top_client(monitor: *Monitor, wm: *WindowManager) void {
1128 - const display = &wm.display;
1129 var visible_client = monitor.stack; 1117 var visible_client = monitor.stack;
1130 while (visible_client) |client| { 1118 while (visible_client) |client| {
1131 if (client_mod.is_visible(client)) { 1119 if (client_mod.is_visible(client)) {
@@ -1135,7 +1123,7 @@ fn focus_top_client(monitor: *Monitor, wm: *WindowManager) void {
1135 visible_client = client.stack_next; 1123 visible_client = client.stack_next;
1136 } 1124 }
1137 monitor.sel = null; 1125 monitor.sel = null;
1138 - _ = xlib.XSetInputFocus(display.handle, display.root, xlib.RevertToPointerRoot, xlib.CurrentTime); 1126 + _ = xlib.XSetInputFocus(wm.display.handle, wm.display.root, xlib.RevertToPointerRoot, xlib.CurrentTime);
1139 } 1127 }
1140 1128
1141 fn focusstack(direction: i32, wm: *WindowManager) void { 1129 fn focusstack(direction: i32, wm: *WindowManager) void {
@@ -1348,7 +1336,6 @@ fn snap_y(client: *Client, new_y: i32, monitor: *Monitor) i32 {
1348 } 1336 }
1349 1337
1350 fn movemouse(wm: *WindowManager) void { 1338 fn movemouse(wm: *WindowManager) void {
1351 - const display = &wm.display;
1352 const monitor = monitor_mod.selected_monitor orelse return; 1339 const monitor = monitor_mod.selected_monitor orelse return;
1353 const client = monitor.sel orelse return; 1340 const client = monitor.sel orelse return;
1354 1341
@@ -1369,11 +1356,11 @@ fn movemouse(wm: *WindowManager) void {
1369 var dummy_int: c_int = undefined; 1356 var dummy_int: c_int = undefined;
1370 var dummy_uint: c_uint = undefined; 1357 var dummy_uint: c_uint = undefined;
1371 1358
1372 - _ = xlib.XQueryPointer(display.handle, display.root, &dummy_win, &dummy_win, &root_x, &root_y, &dummy_int, &dummy_int, &dummy_uint); 1359 + _ = xlib.XQueryPointer(wm.display.handle, wm.display.root, &dummy_win, &dummy_win, &root_x, &root_y, &dummy_int, &dummy_int, &dummy_uint);
1373 1360
1374 const grab_result = xlib.XGrabPointer( 1361 const grab_result = xlib.XGrabPointer(
1375 - display.handle, 1362 + wm.display.handle,
1376 - display.root, 1363 + wm.display.root,
1377 xlib.False, 1364 xlib.False,
1378 xlib.ButtonPressMask | xlib.ButtonReleaseMask | xlib.PointerMotionMask, 1365 xlib.ButtonPressMask | xlib.ButtonReleaseMask | xlib.PointerMotionMask,
1379 xlib.GrabModeAsync, 1366 xlib.GrabModeAsync,
@@ -1397,7 +1384,7 @@ fn movemouse(wm: *WindowManager) void {
1397 var done = false; 1384 var done = false;
1398 1385
1399 while (!done) { 1386 while (!done) {
1400 - _ = xlib.XNextEvent(display.handle, &event); 1387 + _ = xlib.XNextEvent(wm.display.handle, &event);
1401 1388
1402 switch (event.type) { 1389 switch (event.type) {
1403 xlib.MotionNotify => { 1390 xlib.MotionNotify => {
@@ -1423,7 +1410,7 @@ fn movemouse(wm: *WindowManager) void {
1423 } 1410 }
1424 } 1411 }
1425 1412
1426 - _ = xlib.XUngrabPointer(display.handle, xlib.CurrentTime); 1413 + _ = xlib.XUngrabPointer(wm.display.handle, xlib.CurrentTime);
1427 1414
1428 const new_mon = monitor_mod.rect_to_monitor(client.x, client.y, client.width, client.height); 1415 const new_mon = monitor_mod.rect_to_monitor(client.x, client.y, client.width, client.height);
1429 if (new_mon != null and new_mon != monitor) { 1416 if (new_mon != null and new_mon != monitor) {
@@ -1456,7 +1443,6 @@ fn movemouse(wm: *WindowManager) void {
1456 } 1443 }
1457 1444
1458 fn resizemouse(wm: *WindowManager) void { 1445 fn resizemouse(wm: *WindowManager) void {
1459 - const display = &wm.display;
1460 const monitor = monitor_mod.selected_monitor orelse return; 1446 const monitor = monitor_mod.selected_monitor orelse return;
1461 const client = monitor.sel orelse return; 1447 const client = monitor.sel orelse return;
1462 1448
@@ -1471,8 +1457,8 @@ fn resizemouse(wm: *WindowManager) void {
1471 } 1457 }
1472 1458
1473 const grab_result = xlib.XGrabPointer( 1459 const grab_result = xlib.XGrabPointer(
1474 - display.handle, 1460 + wm.display.handle,
1475 - display.root, 1461 + wm.display.root,
1476 xlib.False, 1462 xlib.False,
1477 xlib.ButtonPressMask | xlib.ButtonReleaseMask | xlib.PointerMotionMask, 1463 xlib.ButtonPressMask | xlib.ButtonReleaseMask | xlib.PointerMotionMask,
1478 xlib.GrabModeAsync, 1464 xlib.GrabModeAsync,
@@ -1486,14 +1472,14 @@ fn resizemouse(wm: *WindowManager) void {
1486 return; 1472 return;
1487 } 1473 }
1488 1474
1489 - _ = xlib.XWarpPointer(display.handle, xlib.None, client.window, 0, 0, 0, 0, client.width + client.border_width - 1, client.height + client.border_width - 1); 1475 + _ = xlib.XWarpPointer(wm.display.handle, xlib.None, client.window, 0, 0, 0, 0, client.width + client.border_width - 1, client.height + client.border_width - 1);
1490 1476
1491 var event: xlib.XEvent = undefined; 1477 var event: xlib.XEvent = undefined;
1492 var done = false; 1478 var done = false;
1493 var last_time: c_ulong = 0; 1479 var last_time: c_ulong = 0;
1494 1480
1495 while (!done) { 1481 while (!done) {
1496 - _ = xlib.XNextEvent(display.handle, &event); 1482 + _ = xlib.XNextEvent(wm.display.handle, &event);
1497 1483
1498 switch (event.type) { 1484 switch (event.type) {
1499 xlib.MotionNotify => { 1485 xlib.MotionNotify => {
@@ -1525,16 +1511,15 @@ fn resizemouse(wm: *WindowManager) void {
1525 } 1511 }
1526 } 1512 }
1527 1513
1528 - _ = xlib.XUngrabPointer(display.handle, xlib.CurrentTime); 1514 + _ = xlib.XUngrabPointer(wm.display.handle, xlib.CurrentTime);
1529 arrange(monitor, wm); 1515 arrange(monitor, wm);
1530 } 1516 }
1531 1517
1532 fn handle_expose(event: *xlib.XExposeEvent, wm: *WindowManager) void { 1518 fn handle_expose(event: *xlib.XExposeEvent, wm: *WindowManager) void {
1533 - const display = &wm.display;
1534 if (event.count != 0) return; 1519 if (event.count != 0) return;
1535 if (bar_mod.window_to_bar(wm.bars, event.window)) |bar| { 1520 if (bar_mod.window_to_bar(wm.bars, event.window)) |bar| {
1536 bar.invalidate(); 1521 bar.invalidate();
1537 - bar.draw(display.handle, wm.config); 1522 + bar.draw(wm.display.handle, wm.config);
1538 } 1523 }
1539 } 1524 }
1540 1525
@@ -1551,10 +1536,9 @@ fn clean_mask(mask: c_uint, wm: *WindowManager) c_uint {
1551 } 1536 }
1552 1537
1553 fn handle_button_press(event: *xlib.XButtonEvent, wm: *WindowManager) void { 1538 fn handle_button_press(event: *xlib.XButtonEvent, wm: *WindowManager) void {
1554 - const display = &wm.display;
1555 std.debug.print("button_press: window=0x{x} subwindow=0x{x}\n", .{ event.window, event.subwindow }); 1539 std.debug.print("button_press: window=0x{x} subwindow=0x{x}\n", .{ event.window, event.subwindow });
1556 1540
1557 - const clicked_monitor = monitor_mod.window_to_monitor(display.handle, display.root, event.window); 1541 + const clicked_monitor = monitor_mod.window_to_monitor(wm.display.handle, wm.display.root, event.window);
1558 if (clicked_monitor) |monitor| { 1542 if (clicked_monitor) |monitor| {
1559 if (monitor != monitor_mod.selected_monitor) { 1543 if (monitor != monitor_mod.selected_monitor) {
1560 if (monitor_mod.selected_monitor) |selmon| { 1544 if (monitor_mod.selected_monitor) |selmon| {
@@ -1566,7 +1550,7 @@ fn handle_button_press(event: *xlib.XButtonEvent, wm: *WindowManager) void {
1566 } 1550 }
1567 1551
1568 if (bar_mod.window_to_bar(wm.bars, event.window)) |bar| { 1552 if (bar_mod.window_to_bar(wm.bars, event.window)) |bar| {
1569 - const clicked_tag = bar.handle_click(display.handle, event.x, wm.config); 1553 + const clicked_tag = bar.handle_click(wm.display.handle, event.x, wm.config);
1570 if (clicked_tag) |tag_index| { 1554 if (clicked_tag) |tag_index| {
1571 const tag_mask: u32 = @as(u32, 1) << @intCast(tag_index); 1555 const tag_mask: u32 = @as(u32, 1) << @intCast(tag_index);
1572 view(tag_mask, wm); 1556 view(tag_mask, wm);
@@ -1580,7 +1564,7 @@ fn handle_button_press(event: *xlib.XButtonEvent, wm: *WindowManager) void {
1580 if (monitor_mod.selected_monitor) |selmon| { 1564 if (monitor_mod.selected_monitor) |selmon| {
1581 restack(selmon, wm); 1565 restack(selmon, wm);
1582 } 1566 }
1583 - _ = xlib.XAllowEvents(display.handle, xlib.ReplayPointer, xlib.CurrentTime); 1567 + _ = xlib.XAllowEvents(wm.display.handle, xlib.ReplayPointer, xlib.CurrentTime);
1584 } 1568 }
1585 1569
1586 const clean_state = clean_mask(event.state, wm); 1570 const clean_state = clean_mask(event.state, wm);
@@ -1696,13 +1680,12 @@ fn unmanage(client: *Client, wm: *WindowManager) void {
1696 } 1680 }
1697 1681
1698 fn handle_enter_notify(event: *xlib.XCrossingEvent, wm: *WindowManager) void { 1682 fn handle_enter_notify(event: *xlib.XCrossingEvent, wm: *WindowManager) void {
1699 - const display = &wm.display; 1683 + if ((event.mode != xlib.NotifyNormal or event.detail == xlib.NotifyInferior) and event.window != wm.display.root) {
1700 - if ((event.mode != xlib.NotifyNormal or event.detail == xlib.NotifyInferior) and event.window != display.root) {
1701 return; 1684 return;
1702 } 1685 }
1703 1686
1704 const client = client_mod.window_to_client(monitor_mod.monitors, event.window); 1687 const client = client_mod.window_to_client(monitor_mod.monitors, event.window);
1705 - const target_mon = if (client) |c| c.monitor else monitor_mod.window_to_monitor(display.handle, display.root, event.window); 1688 + const target_mon = if (client) |c| c.monitor else monitor_mod.window_to_monitor(wm.display.handle, wm.display.root, event.window);
1706 const selmon = monitor_mod.selected_monitor; 1689 const selmon = monitor_mod.selected_monitor;
1707 1690
1708 if (target_mon != selmon) { 1691 if (target_mon != selmon) {
@@ -1730,17 +1713,15 @@ fn handle_focus_in(event: *xlib.XFocusChangeEvent, wm: *WindowManager) void {
1730 } 1713 }
1731 1714
1732 fn set_focus(client: *Client, wm: *WindowManager) void { 1715 fn set_focus(client: *Client, wm: *WindowManager) void {
1733 - const display = &wm.display;
1734 if (!client.never_focus) { 1716 if (!client.never_focus) {
1735 - _ = xlib.XSetInputFocus(display.handle, client.window, xlib.RevertToPointerRoot, xlib.CurrentTime); 1717 + _ = xlib.XSetInputFocus(wm.display.handle, client.window, xlib.RevertToPointerRoot, xlib.CurrentTime);
1736 - _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_active_window, xlib.XA_WINDOW, 32, xlib.PropModeReplace, @ptrCast(&client.window), 1); 1718 + _ = xlib.XChangeProperty(wm.display.handle, wm.display.root, wm.atoms.net_active_window, xlib.XA_WINDOW, 32, xlib.PropModeReplace, @ptrCast(&client.window), 1);
1737 } 1719 }
1738 _ = send_event(client, wm.atoms.wm_take_focus, wm); 1720 _ = send_event(client, wm.atoms.wm_take_focus, wm);
1739 } 1721 }
1740 1722
1741 fn handle_motion_notify(event: *xlib.XMotionEvent, wm: *WindowManager) void { 1723 fn handle_motion_notify(event: *xlib.XMotionEvent, wm: *WindowManager) void {
1742 - const display = &wm.display; 1724 + if (event.window != wm.display.root) return;
1743 - if (event.window != display.root) return;
1744 1725
1745 const target_mon = monitor_mod.rect_to_monitor(event.x_root, event.y_root, 1, 1); 1726 const target_mon = monitor_mod.rect_to_monitor(event.x_root, event.y_root, 1, 1);
1746 if (target_mon != wm.last_motion_monitor and wm.last_motion_monitor != null) { 1727 if (target_mon != wm.last_motion_monitor and wm.last_motion_monitor != null) {
@@ -1754,7 +1735,6 @@ fn handle_motion_notify(event: *xlib.XMotionEvent, wm: *WindowManager) void {
1754 } 1735 }
1755 1736
1756 fn handle_property_notify(event: *xlib.XPropertyEvent, wm: *WindowManager) void { 1737 fn handle_property_notify(event: *xlib.XPropertyEvent, wm: *WindowManager) void {
1757 - const display = &wm.display;
1758 if (event.state == xlib.PropertyDelete) { 1738 if (event.state == xlib.PropertyDelete) {
1759 return; 1739 return;
1760 } 1740 }
@@ -1763,7 +1743,7 @@ fn handle_property_notify(event: *xlib.XPropertyEvent, wm: *WindowManager) void
1763 1743
1764 if (event.atom == xlib.XA_WM_TRANSIENT_FOR) { 1744 if (event.atom == xlib.XA_WM_TRANSIENT_FOR) {
1765 var trans: xlib.Window = 0; 1745 var trans: xlib.Window = 0;
1766 - if (!client.is_floating and xlib.XGetTransientForHint(display.handle, client.window, &trans) != 0) { 1746 + if (!client.is_floating and xlib.XGetTransientForHint(wm.display.handle, client.window, &trans) != 0) {
1767 client.is_floating = client_mod.window_to_client(monitor_mod.monitors, trans) != null; 1747 client.is_floating = client_mod.window_to_client(monitor_mod.monitors, trans) != null;
1768 if (client.is_floating) { 1748 if (client.is_floating) {
1769 if (client.monitor) |monitor| { 1749 if (client.monitor) |monitor| {
@@ -1784,30 +1764,27 @@ fn handle_property_notify(event: *xlib.XPropertyEvent, wm: *WindowManager) void
1784 } 1764 }
1785 1765
1786 fn unfocus_client(client: ?*Client, reset_input_focus: bool, wm: *WindowManager) void { 1766 fn unfocus_client(client: ?*Client, reset_input_focus: bool, wm: *WindowManager) void {
1787 - const display = &wm.display;
1788 const unfocus_target = client orelse return; 1767 const unfocus_target = client orelse return;
1789 grabbuttons(unfocus_target, false, wm); 1768 grabbuttons(unfocus_target, false, wm);
1790 - _ = xlib.XSetWindowBorder(display.handle, unfocus_target.window, wm.config.border_unfocused); 1769 + _ = xlib.XSetWindowBorder(wm.display.handle, unfocus_target.window, wm.config.border_unfocused);
1791 if (reset_input_focus) { 1770 if (reset_input_focus) {
1792 - _ = xlib.XSetInputFocus(display.handle, display.root, xlib.RevertToPointerRoot, xlib.CurrentTime); 1771 + _ = xlib.XSetInputFocus(wm.display.handle, wm.display.root, xlib.RevertToPointerRoot, xlib.CurrentTime);
1793 - _ = xlib.XDeleteProperty(display.handle, display.root, wm.atoms.net_active_window); 1772 + _ = xlib.XDeleteProperty(wm.display.handle, wm.display.root, wm.atoms.net_active_window);
1794 } 1773 }
1795 } 1774 }
1796 1775
1797 fn set_client_state(client: *Client, state: c_long, wm: *WindowManager) void { 1776 fn set_client_state(client: *Client, state: c_long, wm: *WindowManager) void {
1798 - const display = &wm.display;
1799 var data: [2]c_long = .{ state, xlib.None }; 1777 var data: [2]c_long = .{ state, xlib.None };
1800 - _ = xlib.c.XChangeProperty(display.handle, client.window, wm.atoms.wm_state, xlib.XA_ATOM, 32, xlib.PropModeReplace, @ptrCast(&data), 2); 1778 + _ = xlib.c.XChangeProperty(wm.display.handle, client.window, wm.atoms.wm_state, xlib.XA_ATOM, 32, xlib.PropModeReplace, @ptrCast(&data), 2);
1801 } 1779 }
1802 1780
1803 fn update_numlock_mask(wm: *WindowManager) void { 1781 fn update_numlock_mask(wm: *WindowManager) void {
1804 - const display = &wm.display;
1805 wm.numlock_mask = 0; 1782 wm.numlock_mask = 0;
1806 - const modmap = xlib.XGetModifierMapping(display.handle); 1783 + const modmap = xlib.XGetModifierMapping(wm.display.handle);
1807 if (modmap == null) return; 1784 if (modmap == null) return;
1808 defer _ = xlib.XFreeModifiermap(modmap); 1785 defer _ = xlib.XFreeModifiermap(modmap);
1809 1786
1810 - const numlock_keycode = xlib.XKeysymToKeycode(display.handle, xlib.XK_Num_Lock); 1787 + const numlock_keycode = xlib.XKeysymToKeycode(wm.display.handle, xlib.XK_Num_Lock);
1811 1788
1812 var modifier_index: usize = 0; 1789 var modifier_index: usize = 0;
1813 while (modifier_index < 8) : (modifier_index += 1) { 1790 while (modifier_index < 8) : (modifier_index += 1) {
@@ -1822,14 +1799,13 @@ fn update_numlock_mask(wm: *WindowManager) void {
1822 } 1799 }
1823 1800
1824 fn grabbuttons(client: *Client, focused: bool, wm: *WindowManager) void { 1801 fn grabbuttons(client: *Client, focused: bool, wm: *WindowManager) void {
1825 - const display = &wm.display;
1826 update_numlock_mask(wm); 1802 update_numlock_mask(wm);
1827 const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask }; 1803 const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask };
1828 1804
1829 - _ = xlib.XUngrabButton(display.handle, xlib.AnyButton, xlib.AnyModifier, client.window); 1805 + _ = xlib.XUngrabButton(wm.display.handle, xlib.AnyButton, xlib.AnyModifier, client.window);
1830 if (!focused) { 1806 if (!focused) {
1831 _ = xlib.XGrabButton( 1807 _ = xlib.XGrabButton(
1832 - display.handle, 1808 + wm.display.handle,
1833 xlib.AnyButton, 1809 xlib.AnyButton,
1834 xlib.AnyModifier, 1810 xlib.AnyModifier,
1835 client.window, 1811 client.window,
@@ -1845,7 +1821,7 @@ fn grabbuttons(client: *Client, focused: bool, wm: *WindowManager) void {
1845 if (button.click == .client_win) { 1821 if (button.click == .client_win) {
1846 for (modifiers) |modifier| { 1822 for (modifiers) |modifier| {
1847 _ = xlib.XGrabButton( 1823 _ = xlib.XGrabButton(
1848 - display.handle, 1824 + wm.display.handle,
1849 @intCast(button.button), 1825 @intCast(button.button),
1850 button.mod_mask | modifier, 1826 button.mod_mask | modifier,
1851 client.window, 1827 client.window,
@@ -1862,7 +1838,6 @@ fn grabbuttons(client: *Client, focused: bool, wm: *WindowManager) void {
1862 } 1838 }
1863 1839
1864 fn focus(target_client: ?*Client, wm: *WindowManager) void { 1840 fn focus(target_client: ?*Client, wm: *WindowManager) void {
1865 - const display = &wm.display;
1866 const selmon = monitor_mod.selected_monitor orelse return; 1841 const selmon = monitor_mod.selected_monitor orelse return;
1867 1842
1868 var focus_client = target_client; 1843 var focus_client = target_client;
@@ -1888,15 +1863,15 @@ fn focus(target_client: ?*Client, wm: *WindowManager) void {
1888 client_mod.detach_stack(client); 1863 client_mod.detach_stack(client);
1889 client_mod.attach_stack(client); 1864 client_mod.attach_stack(client);
1890 grabbuttons(client, true, wm); 1865 grabbuttons(client, true, wm);
1891 - _ = xlib.XSetWindowBorder(display.handle, client.window, wm.config.border_focused); 1866 + _ = xlib.XSetWindowBorder(wm.display.handle, client.window, wm.config.border_focused);
1892 if (!client.never_focus) { 1867 if (!client.never_focus) {
1893 - _ = xlib.XSetInputFocus(display.handle, client.window, xlib.RevertToPointerRoot, xlib.CurrentTime); 1868 + _ = xlib.XSetInputFocus(wm.display.handle, client.window, xlib.RevertToPointerRoot, xlib.CurrentTime);
1894 - _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_active_window, xlib.XA_WINDOW, 32, xlib.PropModeReplace, @ptrCast(&client.window), 1); 1869 + _ = xlib.XChangeProperty(wm.display.handle, wm.display.root, wm.atoms.net_active_window, xlib.XA_WINDOW, 32, xlib.PropModeReplace, @ptrCast(&client.window), 1);
1895 } 1870 }
1896 _ = send_event(client, wm.atoms.wm_take_focus, wm); 1871 _ = send_event(client, wm.atoms.wm_take_focus, wm);
1897 } else { 1872 } else {
1898 - _ = xlib.XSetInputFocus(display.handle, display.root, xlib.RevertToPointerRoot, xlib.CurrentTime); 1873 + _ = xlib.XSetInputFocus(wm.display.handle, wm.display.root, xlib.RevertToPointerRoot, xlib.CurrentTime);
1899 - _ = xlib.XDeleteProperty(display.handle, display.root, wm.atoms.net_active_window); 1874 + _ = xlib.XDeleteProperty(wm.display.handle, wm.display.root, wm.atoms.net_active_window);
1900 } 1875 }
1901 1876
1902 const current_selmon = monitor_mod.selected_monitor orelse return; 1877 const current_selmon = monitor_mod.selected_monitor orelse return;
@@ -1912,12 +1887,11 @@ fn focus(target_client: ?*Client, wm: *WindowManager) void {
1912 } 1887 }
1913 1888
1914 fn restack(monitor: *Monitor, wm: *WindowManager) void { 1889 fn restack(monitor: *Monitor, wm: *WindowManager) void {
1915 - const display = &wm.display;
1916 wm.invalidate_bars(); 1890 wm.invalidate_bars();
1917 const selected_client = monitor.sel orelse return; 1891 const selected_client = monitor.sel orelse return;
1918 1892
1919 if (selected_client.is_floating or monitor.lt[monitor.sel_lt] == null) { 1893 if (selected_client.is_floating or monitor.lt[monitor.sel_lt] == null) {
1920 - _ = xlib.XRaiseWindow(display.handle, selected_client.window); 1894 + _ = xlib.XRaiseWindow(wm.display.handle, selected_client.window);
1921 } 1895 }
1922 1896
1923 if (monitor.lt[monitor.sel_lt] != null) { 1897 if (monitor.lt[monitor.sel_lt] != null) {
@@ -1928,17 +1902,17 @@ fn restack(monitor: *Monitor, wm: *WindowManager) void {
1928 var current = monitor.stack; 1902 var current = monitor.stack;
1929 while (current) |client| { 1903 while (current) |client| {
1930 if (!client.is_floating and client_mod.is_visible(client)) { 1904 if (!client.is_floating and client_mod.is_visible(client)) {
1931 - _ = xlib.c.XConfigureWindow(display.handle, client.window, xlib.c.CWSibling | xlib.c.CWStackMode, &window_changes); 1905 + _ = xlib.c.XConfigureWindow(wm.display.handle, client.window, xlib.c.CWSibling | xlib.c.CWStackMode, &window_changes);
1932 window_changes.sibling = client.window; 1906 window_changes.sibling = client.window;
1933 } 1907 }
1934 current = client.stack_next; 1908 current = client.stack_next;
1935 } 1909 }
1936 } 1910 }
1937 1911
1938 - _ = xlib.XSync(display.handle, xlib.False); 1912 + _ = xlib.XSync(wm.display.handle, xlib.False);
1939 1913
1940 var discard_event: xlib.XEvent = undefined; 1914 var discard_event: xlib.XEvent = undefined;
1941 - while (xlib.c.XCheckMaskEvent(display.handle, xlib.EnterWindowMask, &discard_event) != 0) {} 1915 + while (xlib.c.XCheckMaskEvent(wm.display.handle, xlib.EnterWindowMask, &discard_event) != 0) {}
1942 } 1916 }
1943 1917
1944 fn arrange(monitor: *Monitor, wm: *WindowManager) void { 1918 fn arrange(monitor: *Monitor, wm: *WindowManager) void {
@@ -2001,10 +1975,9 @@ fn scroll_to_window(client: *Client, animate: bool, wm: *WindowManager) void {
2001 } 1975 }
2002 1976
2003 fn showhide_client(client: ?*Client, wm: *WindowManager) void { 1977 fn showhide_client(client: ?*Client, wm: *WindowManager) void {
2004 - const display = &wm.display;
2005 const target = client orelse return; 1978 const target = client orelse return;
2006 if (client_mod.is_visible(target)) { 1979 if (client_mod.is_visible(target)) {
2007 - _ = xlib.XMoveWindow(display.handle, target.window, target.x, target.y); 1980 + _ = xlib.XMoveWindow(wm.display.handle, target.window, target.x, target.y);
2008 const monitor = target.monitor orelse return; 1981 const monitor = target.monitor orelse return;
2009 if ((monitor.lt[monitor.sel_lt] == null or target.is_floating) and !target.is_fullscreen) { 1982 if ((monitor.lt[monitor.sel_lt] == null or target.is_floating) and !target.is_fullscreen) {
2010 tiling.resize(target, target.x, target.y, target.width, target.height, false); 1983 tiling.resize(target, target.x, target.y, target.width, target.height, false);
@@ -2013,7 +1986,7 @@ fn showhide_client(client: ?*Client, wm: *WindowManager) void {
2013 } else { 1986 } else {
2014 showhide_client(target.stack_next, wm); 1987 showhide_client(target.stack_next, wm);
2015 const client_width = target.width + 2 * target.border_width; 1988 const client_width = target.width + 2 * target.border_width;
2016 - _ = xlib.XMoveWindow(display.handle, target.window, -2 * client_width, target.y); 1989 + _ = xlib.XMoveWindow(wm.display.handle, target.window, -2 * client_width, target.y);
2017 } 1990 }
2018 } 1991 }
2019 1992
@@ -2022,11 +1995,10 @@ fn showhide(monitor: *Monitor, wm: *WindowManager) void {
2022 } 1995 }
2023 1996
2024 fn update_size_hints(client: *Client, wm: *WindowManager) void { 1997 fn update_size_hints(client: *Client, wm: *WindowManager) void {
2025 - const display = &wm.display;
2026 var size_hints: xlib.XSizeHints = undefined; 1998 var size_hints: xlib.XSizeHints = undefined;
2027 var msize: c_long = 0; 1999 var msize: c_long = 0;
2028 2000
2029 - if (xlib.XGetWMNormalHints(display.handle, client.window, &size_hints, &msize) == 0) { 2001 + if (xlib.XGetWMNormalHints(wm.display.handle, client.window, &size_hints, &msize) == 0) {
2030 size_hints.flags = xlib.PSize; 2002 size_hints.flags = xlib.PSize;
2031 } 2003 }
2032 2004
@@ -2081,14 +2053,13 @@ fn update_size_hints(client: *Client, wm: *WindowManager) void {
2081 } 2053 }
2082 2054
2083 fn update_wm_hints(client: *Client, wm: *WindowManager) void { 2055 fn update_wm_hints(client: *Client, wm: *WindowManager) void {
2084 - const display = &wm.display; 2056 + const wmh = xlib.XGetWMHints(wm.display.handle, client.window);
2085 - const wmh = xlib.XGetWMHints(display.handle, client.window);
2086 if (wmh) |hints| { 2057 if (wmh) |hints| {
2087 defer _ = xlib.XFree(@ptrCast(hints)); 2058 defer _ = xlib.XFree(@ptrCast(hints));
2088 2059
2089 if (client == (monitor_mod.selected_monitor orelse return).sel and (hints.*.flags & xlib.XUrgencyHint) != 0) { 2060 if (client == (monitor_mod.selected_monitor orelse return).sel and (hints.*.flags & xlib.XUrgencyHint) != 0) {
2090 hints.*.flags = hints.*.flags & ~@as(c_long, xlib.XUrgencyHint); 2061 hints.*.flags = hints.*.flags & ~@as(c_long, xlib.XUrgencyHint);
2091 - _ = xlib.XSetWMHints(display.handle, client.window, hints); 2062 + _ = xlib.XSetWMHints(wm.display.handle, client.window, hints);
2092 } else { 2063 } else {
2093 client.is_urgent = (hints.*.flags & xlib.XUrgencyHint) != 0; 2064 client.is_urgent = (hints.*.flags & xlib.XUrgencyHint) != 0;
2094 } 2065 }
@@ -2123,14 +2094,13 @@ fn update_title(client: *Client, wm: *WindowManager) void {
2123 } 2094 }
2124 2095
2125 fn get_atom_prop(client: *Client, prop: xlib.Atom, wm: *WindowManager) xlib.Atom { 2096 fn get_atom_prop(client: *Client, prop: xlib.Atom, wm: *WindowManager) xlib.Atom {
2126 - const display = &wm.display;
2127 var actual_type: xlib.Atom = undefined; 2097 var actual_type: xlib.Atom = undefined;
2128 var actual_format: c_int = undefined; 2098 var actual_format: c_int = undefined;
2129 var num_items: c_ulong = undefined; 2099 var num_items: c_ulong = undefined;
2130 var bytes_after: c_ulong = undefined; 2100 var bytes_after: c_ulong = undefined;
2131 var prop_data: [*c]u8 = undefined; 2101 var prop_data: [*c]u8 = undefined;
2132 2102
2133 - if (xlib.XGetWindowProperty(display.handle, client.window, prop, 0, @sizeOf(xlib.Atom), xlib.False, xlib.XA_ATOM, &actual_type, &actual_format, &num_items, &bytes_after, &prop_data) == 0 and prop_data != null) { 2103 + if (xlib.XGetWindowProperty(wm.display.handle, client.window, prop, 0, @sizeOf(xlib.Atom), xlib.False, xlib.XA_ATOM, &actual_type, &actual_format, &num_items, &bytes_after, &prop_data) == 0 and prop_data != null) {
2134 const atom: xlib.Atom = @as(*xlib.Atom, @ptrCast(@alignCast(prop_data))).*; 2104 const atom: xlib.Atom = @as(*xlib.Atom, @ptrCast(@alignCast(prop_data))).*;
2135 _ = xlib.XFree(@ptrCast(prop_data)); 2105 _ = xlib.XFree(@ptrCast(prop_data));
2136 return atom; 2106 return atom;
@@ -2139,11 +2109,10 @@ fn get_atom_prop(client: *Client, prop: xlib.Atom, wm: *WindowManager) xlib.Atom
2139 } 2109 }
2140 2110
2141 fn get_text_prop(window: xlib.Window, atom: xlib.Atom, text: *[256]u8, wm: *WindowManager) bool { 2111 fn get_text_prop(window: xlib.Window, atom: xlib.Atom, text: *[256]u8, wm: *WindowManager) bool {
2142 - const display = &wm.display;
2143 var name: xlib.XTextProperty = undefined; 2112 var name: xlib.XTextProperty = undefined;
2144 text[0] = 0; 2113 text[0] = 0;
2145 2114
2146 - if (xlib.XGetTextProperty(display.handle, window, &name, atom) == 0 or name.nitems == 0) { 2115 + if (xlib.XGetTextProperty(wm.display.handle, window, &name, atom) == 0 or name.nitems == 0) {
2147 return false; 2116 return false;
2148 } 2117 }
2149 2118
@@ -2154,7 +2123,7 @@ fn get_text_prop(window: xlib.Window, atom: xlib.Atom, text: *[256]u8, wm: *Wind
2154 } else { 2123 } else {
2155 var list: [*c][*c]u8 = undefined; 2124 var list: [*c][*c]u8 = undefined;
2156 var count: c_int = undefined; 2125 var count: c_int = undefined;
2157 - if (xlib.XmbTextPropertyToTextList(display.handle, &name, &list, &count) >= xlib.Success and count > 0 and list[0] != null) { 2126 + if (xlib.XmbTextPropertyToTextList(wm.display.handle, &name, &list, &count) >= xlib.Success and count > 0 and list[0] != null) {
2158 const str = std.mem.sliceTo(list[0], 0); 2127 const str = std.mem.sliceTo(list[0], 0);
2159 const copy_len = @min(str.len, 255); 2128 const copy_len = @min(str.len, 255);
2160 @memcpy(text[0..copy_len], str[0..copy_len]); 2129 @memcpy(text[0..copy_len], str[0..copy_len]);
@@ -2168,9 +2137,8 @@ fn get_text_prop(window: xlib.Window, atom: xlib.Atom, text: *[256]u8, wm: *Wind
2168 } 2137 }
2169 2138
2170 fn apply_rules(client: *Client, wm: *WindowManager) void { 2139 fn apply_rules(client: *Client, wm: *WindowManager) void {
2171 - const display = &wm.display;
2172 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null }; 2140 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null };
2173 - _ = xlib.XGetClassHint(display.handle, client.window, &class_hint); 2141 + _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint);
2174 2142
2175 const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else ""; 2143 const class_str: []const u8 = if (class_hint.res_class) |ptr| std.mem.sliceTo(ptr, 0) else "";
2176 const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else ""; 2144 const instance_str: []const u8 = if (class_hint.res_name) |ptr| std.mem.sliceTo(ptr, 0) else "";
@@ -2227,14 +2195,13 @@ fn apply_rules(client: *Client, wm: *WindowManager) void {
2227 } 2195 }
2228 2196
2229 fn update_client_list(wm: *WindowManager) void { 2197 fn update_client_list(wm: *WindowManager) void {
2230 - const display = &wm.display; 2198 + _ = xlib.XDeleteProperty(wm.display.handle, wm.display.root, wm.atoms.net_client_list);
2231 - _ = xlib.XDeleteProperty(display.handle, display.root, wm.atoms.net_client_list);
2232 2199
2233 var current_monitor = monitor_mod.monitors; 2200 var current_monitor = monitor_mod.monitors;
2234 while (current_monitor) |monitor| { 2201 while (current_monitor) |monitor| {
2235 var current_client = monitor.clients; 2202 var current_client = monitor.clients;
2236 while (current_client) |client| { 2203 while (current_client) |client| {
2237 - _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_client_list, xlib.XA_WINDOW, 32, xlib.PropModeAppend, @ptrCast(&client.window), 1); 2204 + _ = xlib.XChangeProperty(wm.display.handle, wm.display.root, wm.atoms.net_client_list, xlib.XA_WINDOW, 32, xlib.PropModeAppend, @ptrCast(&client.window), 1);
2238 current_client = client.next; 2205 current_client = client.next;
2239 } 2206 }
2240 current_monitor = monitor.next; 2207 current_monitor = monitor.next;
@@ -2242,12 +2209,11 @@ fn update_client_list(wm: *WindowManager) void {
2242 } 2209 }
2243 2210
2244 fn send_event(client: *Client, protocol: xlib.Atom, wm: *WindowManager) bool { 2211 fn send_event(client: *Client, protocol: xlib.Atom, wm: *WindowManager) bool {
2245 - const display = &wm.display;
2246 var protocols: [*c]xlib.Atom = undefined; 2212 var protocols: [*c]xlib.Atom = undefined;
2247 var num_protocols: c_int = 0; 2213 var num_protocols: c_int = 0;
2248 var exists = false; 2214 var exists = false;
2249 2215
2250 - if (xlib.XGetWMProtocols(display.handle, client.window, &protocols, &num_protocols) != 0) { 2216 + if (xlib.XGetWMProtocols(wm.display.handle, client.window, &protocols, &num_protocols) != 0) {
2251 var index: usize = 0; 2217 var index: usize = 0;
2252 while (index < @as(usize, @intCast(num_protocols))) : (index += 1) { 2218 while (index < @as(usize, @intCast(num_protocols))) : (index += 1) {
2253 if (protocols[index] == protocol) { 2219 if (protocols[index] == protocol) {
@@ -2266,22 +2232,21 @@ fn send_event(client: *Client, protocol: xlib.Atom, wm: *WindowManager) bool {
2266 event.xclient.format = 32; 2232 event.xclient.format = 32;
2267 event.xclient.data.l[0] = @intCast(protocol); 2233 event.xclient.data.l[0] = @intCast(protocol);
2268 event.xclient.data.l[1] = xlib.CurrentTime; 2234 event.xclient.data.l[1] = xlib.CurrentTime;
2269 - _ = xlib.XSendEvent(display.handle, client.window, xlib.False, xlib.NoEventMask, &event); 2235 + _ = xlib.XSendEvent(wm.display.handle, client.window, xlib.False, xlib.NoEventMask, &event);
2270 } 2236 }
2271 return exists; 2237 return exists;
2272 } 2238 }
2273 2239
2274 fn set_urgent(client: *Client, urgent: bool, wm: *WindowManager) void { 2240 fn set_urgent(client: *Client, urgent: bool, wm: *WindowManager) void {
2275 - const display = &wm.display;
2276 client.is_urgent = urgent; 2241 client.is_urgent = urgent;
2277 - const wmh = xlib.XGetWMHints(display.handle, client.window); 2242 + const wmh = xlib.XGetWMHints(wm.display.handle, client.window);
2278 if (wmh) |hints| { 2243 if (wmh) |hints| {
2279 if (urgent) { 2244 if (urgent) {
2280 hints.*.flags = hints.*.flags | xlib.XUrgencyHint; 2245 hints.*.flags = hints.*.flags | xlib.XUrgencyHint;
2281 } else { 2246 } else {
2282 hints.*.flags = hints.*.flags & ~@as(c_long, xlib.XUrgencyHint); 2247 hints.*.flags = hints.*.flags & ~@as(c_long, xlib.XUrgencyHint);
2283 } 2248 }
2284 - _ = xlib.XSetWMHints(display.handle, client.window, hints); 2249 + _ = xlib.XSetWMHints(wm.display.handle, client.window, hints);
2285 _ = xlib.XFree(@ptrCast(hints)); 2250 _ = xlib.XFree(@ptrCast(hints));
2286 } 2251 }
2287 } 2252 }