tony / oxwm

refactor: remove `Display` param from wm functions and use `wm.Display` directly Browse files
emzywastaken committed 2026-02-21 parent 5acaef3 commit 8f72bc0b48f7d16ca259a6fd4279f2508a3cc15a
Showing 1 changed file with 203 additions and 169 deletions. UnifiedSplit
+203 −169 src/main.zig Large diff collapsed, click to expand
@@ -200,8 +200,8 @@ pub fn main() !void {
200 200 std.debug.print("successfully became window manager\n", .{});
201 201 std.debug.print("atoms initialized with EWMH support\n", .{});
202 202
203 - grab_keybinds(&wm.display, &wm);
204 - scan_existing_windows(&wm.display, &wm);
203 + grab_keybinds(&wm);
204 + scan_existing_windows(&wm);
205 205
206 206 try run_autostart_commands(allocator, wm.config.autostart.items);
207 207 std.debug.print("entering event loop\n", .{});
@@ -271,8 +271,9 @@ fn initialize_default_config(cfg: *config_mod.Config) void {
271 271 cfg.add_button(.{ .click = .client_win, .mod_mask = mod_key, .button = 3, .action = .resize_mouse }) catch {};
272 272 }
273 273
274 -fn grab_keybinds(display: *Display, wm: *WindowManager) void {
275 - update_numlock_mask(display, wm);
274 +fn grab_keybinds(wm: *WindowManager) void {
275 + const display = &wm.display;
276 + update_numlock_mask(wm);
276 277 const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask };
277 278
278 279 _ = xlib.XUngrabKey(display.handle, xlib.AnyKey, xlib.AnyModifier, display.root);
@@ -318,7 +319,8 @@ fn grab_keybinds(display: *Display, wm: *WindowManager) void {
318 319 std.debug.print("grabbed {d} keybinds from config\n", .{wm.config.keybinds.items.len});
319 320 }
320 321
321 -fn get_state(display: *Display, window: xlib.Window, wm: *WindowManager) c_long {
322 +fn get_state(window: xlib.Window, wm: *WindowManager) c_long {
323 + const display = &wm.display;
322 324 var actual_type: xlib.Atom = 0;
323 325 var actual_format: c_int = 0;
324 326 var num_items: c_ulong = 0;
@@ -352,7 +354,8 @@ fn get_state(display: *Display, window: xlib.Window, wm: *WindowManager) c_long
352 354 return state;
353 355 }
354 356
355 -fn scan_existing_windows(display: *Display, wm: *WindowManager) void {
357 +fn scan_existing_windows(wm: *WindowManager) void {
358 + const display = &wm.display;
356 359 var root_return: xlib.Window = undefined;
357 360 var parent_return: xlib.Window = undefined;
358 361 var children: [*c]xlib.Window = undefined;
@@ -375,8 +378,8 @@ fn scan_existing_windows(display: *Display, wm: *WindowManager) void {
375 378 if (xlib.XGetTransientForHint(display.handle, children[index], &trans) != 0) {
376 379 continue;
377 380 }
378 - if (window_attrs.map_state == IsViewable or get_state(display, children[index], wm) == IconicState) {
379 - manage(display, children[index], &window_attrs, wm);
381 + if (window_attrs.map_state == IsViewable or get_state(children[index], wm) == IconicState) {
382 + manage(children[index], &window_attrs, wm);
380 383 }
381 384 }
382 385
@@ -388,8 +391,8 @@ fn scan_existing_windows(display: *Display, wm: *WindowManager) void {
388 391 }
389 392 var trans: xlib.Window = 0;
390 393 if (xlib.XGetTransientForHint(display.handle, children[index], &trans) != 0) {
391 - if (window_attrs.map_state == IsViewable or get_state(display, children[index], wm) == IconicState) {
392 - manage(display, children[index], &window_attrs, wm);
394 + if (window_attrs.map_state == IsViewable or get_state(children[index], wm) == IconicState) {
395 + manage(children[index], &window_attrs, wm);
393 396 }
394 397 }
395 398 }
@@ -409,7 +412,7 @@ fn run_event_loop(wm: *WindowManager) void {
409 412 while (wm.running) {
410 413 while (xlib.XPending(wm.display.handle) > 0) {
411 414 var event = wm.display.next_event();
412 - handle_event(&wm.display, &event, wm);
415 + handle_event(&event, wm);
413 416 }
414 417
415 418 tick_animations(wm);
@@ -426,7 +429,7 @@ fn run_event_loop(wm: *WindowManager) void {
426 429 }
427 430 }
428 431
429 -fn handle_event(display: *Display, event: *xlib.XEvent, wm: *WindowManager) void {
432 +fn handle_event(event: *xlib.XEvent, wm: *WindowManager) void {
430 433 const event_type = events.get_event_type(event);
431 434
432 435 if (event_type == .button_press) {
@@ -434,23 +437,24 @@ fn handle_event(display: *Display, event: *xlib.XEvent, wm: *WindowManager) void
434 437 }
435 438
436 439 switch (event_type) {
437 - .map_request => handle_map_request(display, &event.xmaprequest, wm),
438 - .configure_request => handle_configure_request(display, &event.xconfigurerequest, wm),
439 - .key_press => handle_key_press(display, &event.xkey, wm),
440 - .destroy_notify => handle_destroy_notify(display, &event.xdestroywindow, wm),
441 - .unmap_notify => handle_unmap_notify(display, &event.xunmap, wm),
442 - .enter_notify => handle_enter_notify(display, &event.xcrossing, wm),
443 - .focus_in => handle_focus_in(display, &event.xfocus, wm),
444 - .motion_notify => handle_motion_notify(display, &event.xmotion, wm),
445 - .client_message => handle_client_message(display, &event.xclient, wm),
446 - .button_press => handle_button_press(display, &event.xbutton, wm),
447 - .expose => handle_expose(display, &event.xexpose, wm),
448 - .property_notify => handle_property_notify(display, &event.xproperty, wm),
440 + .map_request => handle_map_request(&event.xmaprequest, wm),
441 + .configure_request => handle_configure_request(&event.xconfigurerequest, wm),
442 + .key_press => handle_key_press(&event.xkey, wm),
443 + .destroy_notify => handle_destroy_notify(&event.xdestroywindow, wm),
444 + .unmap_notify => handle_unmap_notify(&event.xunmap, wm),
445 + .enter_notify => handle_enter_notify(&event.xcrossing, wm),
446 + .focus_in => handle_focus_in(&event.xfocus, wm),
447 + .motion_notify => handle_motion_notify(&event.xmotion, wm),
448 + .client_message => handle_client_message(&event.xclient, wm),
449 + .button_press => handle_button_press(&event.xbutton, wm),
450 + .expose => handle_expose(&event.xexpose, wm),
451 + .property_notify => handle_property_notify(&event.xproperty, wm),
449 452 else => {},
450 453 }
451 454 }
452 455
453 -fn handle_map_request(display: *Display, event: *xlib.XMapRequestEvent, wm: *WindowManager) void {
456 +fn handle_map_request(event: *xlib.XMapRequestEvent, wm: *WindowManager) void {
457 + const display = &wm.display;
454 458 std.debug.print("map_request: window=0x{x}\n", .{event.window});
455 459
456 460 var window_attributes: xlib.XWindowAttributes = undefined;
@@ -464,10 +468,11 @@ fn handle_map_request(display: *Display, event: *xlib.XMapRequestEvent, wm: *Win
464 468 return;
465 469 }
466 470
467 - manage(display, event.window, &window_attributes, wm);
471 + manage(event.window, &window_attributes, wm);
468 472 }
469 473
470 -fn manage(display: *Display, win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *WindowManager) void {
474 +fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *WindowManager) void {
475 + const display = &wm.display;
471 476 const client = client_mod.create(gpa.allocator(), win) orelse return;
472 477 var trans: xlib.Window = 0;
473 478
@@ -482,7 +487,7 @@ fn manage(display: *Display, win: xlib.Window, window_attrs: *xlib.XWindowAttrib
482 487 client.old_border_width = window_attrs.border_width;
483 488 client.border_width = wm.config.border_width;
484 489
485 - update_title(display, client, wm);
490 + update_title(client, wm);
486 491
487 492 if (xlib.XGetTransientForHint(display.handle, win, &trans) != 0) {
488 493 if (client_mod.window_to_client(monitor_mod.monitors, trans)) |transient_client| {
@@ -493,7 +498,7 @@ fn manage(display: *Display, win: xlib.Window, window_attrs: *xlib.XWindowAttrib
493 498
494 499 if (client.monitor == null) {
495 500 client.monitor = monitor_mod.selected_monitor;
496 - apply_rules(display, client, wm);
501 + apply_rules(client, wm);
497 502 }
498 503
499 504 const monitor = client.monitor orelse return;
@@ -511,16 +516,16 @@ fn manage(display: *Display, win: xlib.Window, window_attrs: *xlib.XWindowAttrib
511 516 _ = xlib.XSetWindowBorder(display.handle, win, wm.config.border_unfocused);
512 517 tiling.send_configure(client);
513 518
514 - update_window_type(display, client, wm);
515 - update_size_hints(display, client);
516 - update_wm_hints(display, client);
519 + update_window_type(client, wm);
520 + update_size_hints(client, wm);
521 + update_wm_hints(client, wm);
517 522
518 523 _ = xlib.XSelectInput(
519 524 display.handle,
520 525 win,
521 526 xlib.EnterWindowMask | xlib.FocusChangeMask | xlib.PropertyChangeMask | xlib.StructureNotifyMask,
522 527 );
523 - grabbuttons(display, client, false, wm);
528 + grabbuttons(client, false, wm);
524 529
525 530 if (!client.is_floating) {
526 531 client.is_floating = trans != 0 or client.is_fixed;
@@ -535,11 +540,11 @@ fn manage(display: *Display, win: xlib.Window, window_attrs: *xlib.XWindowAttrib
535 540
536 541 _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_client_list, xlib.XA_WINDOW, 32, xlib.PropModeAppend, @ptrCast(&client.window), 1);
537 542 _ = xlib.XMoveResizeWindow(display.handle, client.window, client.x + 2 * display.screen_width(), client.y, @intCast(client.width), @intCast(client.height));
538 - set_client_state(display, client, NormalState, wm);
543 + set_client_state(client, NormalState, wm);
539 544
540 545 if (client.monitor == monitor_mod.selected_monitor) {
541 546 const selmon = monitor_mod.selected_monitor orelse return;
542 - unfocus_client(display, selmon.sel, false, wm);
547 + unfocus_client(selmon.sel, false, wm);
543 548 }
544 549 monitor.sel = client;
545 550
@@ -549,11 +554,11 @@ fn manage(display: *Display, win: xlib.Window, window_attrs: *xlib.XWindowAttrib
549 554
550 555 arrange(monitor, wm);
551 556 _ = xlib.XMapWindow(display.handle, win);
552 - focus(display, null, wm);
557 + focus(null, wm);
553 558 }
554 559
555 -fn handle_configure_request(display: *Display, event: *xlib.XConfigureRequestEvent, wm: *WindowManager) void {
556 - _ = wm;
560 +fn handle_configure_request(event: *xlib.XConfigureRequestEvent, wm: *WindowManager) void {
561 + const display = &wm.display;
557 562 const client = client_mod.window_to_client(monitor_mod.monitors, event.window);
558 563
559 564 if (client) |managed_client| {
@@ -608,7 +613,8 @@ fn handle_configure_request(display: *Display, event: *xlib.XConfigureRequestEve
608 613 _ = xlib.XSync(display.handle, xlib.False);
609 614 }
610 615
611 -fn handle_key_press(display: *Display, event: *xlib.XKeyEvent, wm: *WindowManager) void {
616 +fn handle_key_press(event: *xlib.XKeyEvent, wm: *WindowManager) void {
617 + const display = &wm.display;
612 618 const keysym = xlib.XKeycodeToKeysym(display.handle, @intCast(event.keycode), 0);
613 619
614 620 if (wm.overlay) |overlay| {
@@ -637,7 +643,7 @@ fn handle_key_press(display: *Display, event: *xlib.XKeyEvent, wm: *WindowManage
637 643 }
638 644 }
639 645 if (matches) {
640 - execute_action(display, keybind.action, keybind.int_arg, keybind.str_arg, wm);
646 + execute_action(keybind.action, keybind.int_arg, keybind.str_arg, wm);
641 647 wm.chord.reset(display.handle);
642 648 return;
643 649 }
@@ -670,19 +676,19 @@ fn handle_key_press(display: *Display, event: *xlib.XKeyEvent, wm: *WindowManage
670 676 }
671 677 }
672 678
673 -fn execute_action(display: *Display, action: config_mod.Action, int_arg: i32, str_arg: ?[]const u8, wm: *WindowManager) void {
679 +fn execute_action(action: config_mod.Action, int_arg: i32, str_arg: ?[]const u8, wm: *WindowManager) void {
674 680 switch (action) {
675 681 .spawn_terminal => spawn_terminal(wm),
676 682 .spawn => {
677 683 if (str_arg) |cmd| spawn_command(cmd);
678 684 },
679 - .kill_client => kill_focused(display, wm),
685 + .kill_client => kill_focused(wm),
680 686 .quit => {
681 687 std.debug.print("quit keybind pressed\n", .{});
682 688 wm.running = false;
683 689 },
684 - .reload_config => reload_config(display, wm),
685 - .restart => reload_config(display, wm),
690 + .reload_config => reload_config(wm),
691 + .restart => reload_config(wm),
686 692 .show_keybinds => {
687 693 if (wm.overlay) |overlay| {
688 694 const mon = wm.selected_monitor orelse wm.monitors;
@@ -691,15 +697,15 @@ fn execute_action(display: *Display, action: config_mod.Action, int_arg: i32, st
691 697 }
692 698 }
693 699 },
694 - .focus_next => focusstack(display, 1, wm),
695 - .focus_prev => focusstack(display, -1, wm),
696 - .move_next => movestack(display, 1, wm),
697 - .move_prev => movestack(display, -1, wm),
700 + .focus_next => focusstack(1, wm),
701 + .focus_prev => focusstack(-1, wm),
702 + .move_next => movestack(1, wm),
703 + .move_prev => movestack(-1, wm),
698 704 .resize_master => setmfact(@as(f32, @floatFromInt(int_arg)) / 1000.0, wm),
699 705 .inc_master => incnmaster(1, wm),
700 706 .dec_master => incnmaster(-1, wm),
701 - .toggle_floating => toggle_floating(display, wm),
702 - .toggle_fullscreen => toggle_fullscreen(display, wm),
707 + .toggle_floating => toggle_floating(wm),
708 + .toggle_fullscreen => toggle_fullscreen(wm),
703 709 .toggle_gaps => toggle_gaps(wm),
704 710 .cycle_layout => cycle_layout(wm),
705 711 .set_layout => set_layout(str_arg, wm),
@@ -707,35 +713,36 @@ fn execute_action(display: *Display, action: config_mod.Action, int_arg: i32, st
707 713 .set_layout_floating => set_layout_index(2, wm),
708 714 .view_tag => {
709 715 const tag_mask: u32 = @as(u32, 1) << @intCast(int_arg);
710 - view(display, tag_mask, wm);
716 + view(tag_mask, wm);
711 717 },
712 - .view_next_tag => view_adjacent_tag(display, 1, wm),
713 - .view_prev_tag => view_adjacent_tag(display, -1, wm),
714 - .view_next_nonempty_tag => view_adjacent_nonempty_tag(display, 1, wm),
715 - .view_prev_nonempty_tag => view_adjacent_nonempty_tag(display, -1, wm),
718 + .view_next_tag => view_adjacent_tag(1, wm),
719 + .view_prev_tag => view_adjacent_tag(-1, wm),
720 + .view_next_nonempty_tag => view_adjacent_nonempty_tag(1, wm),
721 + .view_prev_nonempty_tag => view_adjacent_nonempty_tag(-1, wm),
716 722 .move_to_tag => {
717 723 const tag_mask: u32 = @as(u32, 1) << @intCast(int_arg);
718 - tag_client(display, tag_mask, wm);
724 + tag_client(tag_mask, wm);
719 725 },
720 726 .toggle_view_tag => {
721 727 const tag_mask: u32 = @as(u32, 1) << @intCast(int_arg);
722 - toggle_view(display, tag_mask, wm);
728 + toggle_view(tag_mask, wm);
723 729 },
724 730 .toggle_tag => {
725 731 const tag_mask: u32 = @as(u32, 1) << @intCast(int_arg);
726 - toggle_client_tag(display, tag_mask, wm);
732 + toggle_client_tag(tag_mask, wm);
727 733 },
728 - .focus_monitor => focusmon(display, int_arg, wm),
729 - .send_to_monitor => sendmon(display, int_arg, wm),
734 + .focus_monitor => focusmon(int_arg, wm),
735 + .send_to_monitor => sendmon(int_arg, wm),
730 736 .scroll_left => scroll_layout(-1, wm),
731 737 .scroll_right => scroll_layout(1, wm),
732 738 }
733 739 }
734 740
735 -fn reload_config(display: *Display, wm: *WindowManager) void {
741 +fn reload_config(wm: *WindowManager) void {
742 + const display = &wm.display;
736 743 std.debug.print("reloading config...\n", .{});
737 744
738 - ungrab_keybinds(display);
745 + ungrab_keybinds(wm);
739 746
740 747 wm.config.keybinds.clearRetainingCapacity();
741 748 wm.config.buttons.clearRetainingCapacity();
@@ -766,7 +773,7 @@ fn reload_config(display: *Display, wm: *WindowManager) void {
766 773 wm.setup_bars();
767 774 rebuild_bar_blocks(wm);
768 775
769 - grab_keybinds(display, wm);
776 + grab_keybinds(wm);
770 777 }
771 778
772 779 fn rebuild_bar_blocks(wm: *WindowManager) void {
@@ -778,7 +785,8 @@ fn rebuild_bar_blocks(wm: *WindowManager) void {
778 785 }
779 786 }
780 787
781 -fn ungrab_keybinds(display: *Display) void {
788 +fn ungrab_keybinds(wm: *WindowManager) void {
789 + const display = &wm.display;
782 790 _ = xlib.XUngrabKey(display.handle, xlib.AnyKey, xlib.AnyModifier, display.root);
783 791 }
784 792
@@ -829,7 +837,7 @@ fn spawn_terminal(wm: *WindowManager) void {
829 837 }
830 838 }
831 839
832 -fn movestack(display: *Display, direction: i32, wm: *WindowManager) void {
840 +fn movestack(direction: i32, wm: *WindowManager) void {
833 841 const monitor = monitor_mod.selected_monitor orelse return;
834 842 const current = monitor.sel orelse return;
835 843
@@ -887,12 +895,12 @@ fn movestack(display: *Display, direction: i32, wm: *WindowManager) void {
887 895 if (swap_client != current) {
888 896 client_mod.swap_clients(current, swap_client);
889 897 arrange(monitor, wm);
890 - focus(display, current, wm);
898 + focus(current, wm);
891 899 }
892 900 }
893 901 }
894 902
895 -fn toggle_view(display: *Display, tag_mask: u32, wm: *WindowManager) void {
903 +fn toggle_view(tag_mask: u32, wm: *WindowManager) void {
896 904 const monitor = monitor_mod.selected_monitor orelse return;
897 905 const new_tags = monitor.tagset[monitor.sel_tags] ^ tag_mask;
898 906 if (new_tags != 0) {
@@ -916,19 +924,19 @@ fn toggle_view(display: *Display, tag_mask: u32, wm: *WindowManager) void {
916 924 monitor.mfact = monitor.pertag.mfacts[monitor.pertag.curtag];
917 925 monitor.sel_lt = monitor.pertag.sellts[monitor.pertag.curtag];
918 926
919 - focus_top_client(display, monitor, wm);
927 + focus_top_client(monitor, wm);
920 928 arrange(monitor, wm);
921 929 wm.invalidate_bars();
922 930 }
923 931 }
924 932
925 -fn toggle_client_tag(display: *Display, tag_mask: u32, wm: *WindowManager) void {
933 +fn toggle_client_tag(tag_mask: u32, wm: *WindowManager) void {
926 934 const monitor = monitor_mod.selected_monitor orelse return;
927 935 const client = monitor.sel orelse return;
928 936 const new_tags = client.tags ^ tag_mask;
929 937 if (new_tags != 0) {
930 938 client.tags = new_tags;
931 - focus_top_client(display, monitor, wm);
939 + focus_top_client(monitor, wm);
932 940 arrange(monitor, wm);
933 941 wm.invalidate_bars();
934 942 }
@@ -950,12 +958,13 @@ fn toggle_gaps(wm: *WindowManager) void {
950 958 arrange(monitor, wm);
951 959 }
952 960
953 -fn kill_focused(display: *Display, wm: *WindowManager) void {
961 +fn kill_focused(wm: *WindowManager) void {
962 + const display = &wm.display;
954 963 const selected = monitor_mod.selected_monitor orelse return;
955 964 const client = selected.sel orelse return;
956 965 std.debug.print("killing window: 0x{x}\n", .{client.window});
957 966
958 - if (!send_event(display, client, wm.atoms.wm_delete, wm)) {
967 + if (!send_event(client, wm.atoms.wm_delete, wm)) {
959 968 _ = xlib.XGrabServer(display.handle);
960 969 _ = xlib.XKillClient(display.handle, client.window);
961 970 _ = xlib.XSync(display.handle, xlib.False);
@@ -963,13 +972,14 @@ fn kill_focused(display: *Display, wm: *WindowManager) void {
963 972 }
964 973 }
965 974
966 -fn toggle_fullscreen(display: *Display, wm: *WindowManager) void {
975 +fn toggle_fullscreen(wm: *WindowManager) void {
967 976 const selected = monitor_mod.selected_monitor orelse return;
968 977 const client = selected.sel orelse return;
969 - set_fullscreen(display, client, !client.is_fullscreen, wm);
978 + set_fullscreen(client, !client.is_fullscreen, wm);
970 979 }
971 980
972 -fn set_fullscreen(display: *Display, client: *Client, fullscreen: bool, wm: *WindowManager) void {
981 +fn set_fullscreen(client: *Client, fullscreen: bool, wm: *WindowManager) void {
982 + const display = &wm.display;
973 983 const monitor = client.monitor orelse return;
974 984
975 985 if (fullscreen and !client.is_fullscreen) {
@@ -1023,7 +1033,7 @@ fn set_fullscreen(display: *Display, client: *Client, fullscreen: bool, wm: *Win
1023 1033 }
1024 1034 }
1025 1035
1026 -fn view(display: *Display, tag_mask: u32, wm: *WindowManager) void {
1036 +fn view(tag_mask: u32, wm: *WindowManager) void {
1027 1037 const monitor = monitor_mod.selected_monitor orelse return;
1028 1038 if (tag_mask == monitor.tagset[monitor.sel_tags]) {
1029 1039 return;
@@ -1052,13 +1062,13 @@ fn view(display: *Display, tag_mask: u32, wm: *WindowManager) void {
1052 1062 monitor.mfact = monitor.pertag.mfacts[monitor.pertag.curtag];
1053 1063 monitor.sel_lt = monitor.pertag.sellts[monitor.pertag.curtag];
1054 1064
1055 - focus_top_client(display, monitor, wm);
1065 + focus_top_client(monitor, wm);
1056 1066 arrange(monitor, wm);
1057 1067 wm.invalidate_bars();
1058 1068 std.debug.print("view: tag_mask={d}\n", .{monitor.tagset[monitor.sel_tags]});
1059 1069 }
1060 1070
1061 -fn view_adjacent_tag(display: *Display, direction: i32, wm: *WindowManager) void {
1071 +fn view_adjacent_tag(direction: i32, wm: *WindowManager) void {
1062 1072 const monitor = monitor_mod.selected_monitor orelse return;
1063 1073 const current_tag = monitor.pertag.curtag;
1064 1074 var new_tag: i32 = @intCast(current_tag);
@@ -1068,10 +1078,10 @@ fn view_adjacent_tag(display: *Display, direction: i32, wm: *WindowManager) void
1068 1078 if (new_tag > 9) new_tag = 1;
1069 1079
1070 1080 const tag_mask: u32 = @as(u32, 1) << @intCast(new_tag - 1);
1071 - view(display, tag_mask, wm);
1081 + view(tag_mask, wm);
1072 1082 }
1073 1083
1074 -fn view_adjacent_nonempty_tag(display: *Display, direction: i32, wm: *WindowManager) void {
1084 +fn view_adjacent_nonempty_tag(direction: i32, wm: *WindowManager) void {
1075 1085 const monitor = monitor_mod.selected_monitor orelse return;
1076 1086 const current_tag = monitor.pertag.curtag;
1077 1087 var new_tag: i32 = @intCast(current_tag);
@@ -1084,7 +1094,7 @@ fn view_adjacent_nonempty_tag(display: *Display, direction: i32, wm: *WindowMana
1084 1094
1085 1095 const tag_mask: u32 = @as(u32, 1) << @intCast(new_tag - 1);
1086 1096 if (has_clients_on_tag(monitor, tag_mask)) {
1087 - view(display, tag_mask, wm);
1097 + view(tag_mask, wm);
1088 1098 return;
1089 1099 }
1090 1100 }
@@ -1101,24 +1111,25 @@ fn has_clients_on_tag(monitor: *monitor_mod.Monitor, tag_mask: u32) bool {
1101 1111 return false;
1102 1112 }
1103 1113
1104 -fn tag_client(display: *Display, tag_mask: u32, wm: *WindowManager) void {
1114 +fn tag_client(tag_mask: u32, wm: *WindowManager) void {
1105 1115 const monitor = monitor_mod.selected_monitor orelse return;
1106 1116 const client = monitor.sel orelse return;
1107 1117 if (tag_mask == 0) {
1108 1118 return;
1109 1119 }
1110 1120 client.tags = tag_mask;
1111 - focus_top_client(display, monitor, wm);
1121 + focus_top_client(monitor, wm);
1112 1122 arrange(monitor, wm);
1113 1123 wm.invalidate_bars();
1114 1124 std.debug.print("tag_client: window=0x{x} tag_mask={d}\n", .{ client.window, tag_mask });
1115 1125 }
1116 1126
1117 -fn focus_top_client(display: *Display, monitor: *Monitor, wm: *WindowManager) void {
1127 +fn focus_top_client(monitor: *Monitor, wm: *WindowManager) void {
1128 + const display = &wm.display;
1118 1129 var visible_client = monitor.stack;
1119 1130 while (visible_client) |client| {
1120 1131 if (client_mod.is_visible(client)) {
1121 - focus(display, client, wm);
1132 + focus(client, wm);
1122 1133 return;
1123 1134 }
1124 1135 visible_client = client.stack_next;
@@ -1127,7 +1138,7 @@ fn focus_top_client(display: *Display, monitor: *Monitor, wm: *WindowManager) vo
1127 1138 _ = xlib.XSetInputFocus(display.handle, display.root, xlib.RevertToPointerRoot, xlib.CurrentTime);
1128 1139 }
1129 1140
1130 -fn focusstack(display: *Display, direction: i32, wm: *WindowManager) void {
1141 +fn focusstack(direction: i32, wm: *WindowManager) void {
1131 1142 const monitor = monitor_mod.selected_monitor orelse return;
1132 1143 const current = monitor.sel orelse return;
1133 1144
@@ -1175,14 +1186,14 @@ fn focusstack(display: *Display, direction: i32, wm: *WindowManager) void {
1175 1186 }
1176 1187
1177 1188 if (next_client) |client| {
1178 - focus(display, client, wm);
1189 + focus(client, wm);
1179 1190 if (client.monitor) |client_monitor| {
1180 - restack(display, client_monitor, wm);
1191 + restack(client_monitor, wm);
1181 1192 }
1182 1193 }
1183 1194 }
1184 1195
1185 -fn toggle_floating(_: *Display, wm: *WindowManager) void {
1196 +fn toggle_floating(wm: *WindowManager) void {
1186 1197 const monitor = monitor_mod.selected_monitor orelse return;
1187 1198 const client = monitor.sel orelse return;
1188 1199
@@ -1281,19 +1292,19 @@ fn set_layout_index(index: u32, wm: *WindowManager) void {
1281 1292 }
1282 1293 }
1283 1294
1284 -fn focusmon(display: *Display, direction: i32, wm: *WindowManager) void {
1295 +fn focusmon(direction: i32, wm: *WindowManager) void {
1285 1296 const selmon = monitor_mod.selected_monitor orelse return;
1286 1297 const target = monitor_mod.dir_to_monitor(direction) orelse return;
1287 1298 if (target == selmon) {
1288 1299 return;
1289 1300 }
1290 - unfocus_client(display, selmon.sel, false, wm);
1301 + unfocus_client(selmon.sel, false, wm);
1291 1302 monitor_mod.selected_monitor = target;
1292 - focus(display, null, wm);
1303 + focus(null, wm);
1293 1304 std.debug.print("focusmon: monitor {d}\n", .{target.num});
1294 1305 }
1295 1306
1296 -fn sendmon(display: *Display, direction: i32, wm: *WindowManager) void {
1307 +fn sendmon(direction: i32, wm: *WindowManager) void {
1297 1308 const source_monitor = monitor_mod.selected_monitor orelse return;
1298 1309 const client = source_monitor.sel orelse return;
1299 1310 const target = monitor_mod.dir_to_monitor(direction) orelse return;
@@ -1309,7 +1320,7 @@ fn sendmon(display: *Display, direction: i32, wm: *WindowManager) void {
1309 1320 client_mod.attach_aside(client);
1310 1321 client_mod.attach_stack(client);
1311 1322
1312 - focus_top_client(display, source_monitor, wm);
1323 + focus_top_client(source_monitor, wm);
1313 1324 arrange(source_monitor, wm);
1314 1325 arrange(target, wm);
1315 1326
@@ -1336,7 +1347,8 @@ fn snap_y(client: *Client, new_y: i32, monitor: *Monitor) i32 {
1336 1347 return new_y;
1337 1348 }
1338 1349
1339 -fn movemouse(display: *Display, wm: *WindowManager) void {
1350 +fn movemouse(wm: *WindowManager) void {
1351 + const display = &wm.display;
1340 1352 const monitor = monitor_mod.selected_monitor orelse return;
1341 1353 const client = monitor.sel orelse return;
1342 1354
@@ -1344,7 +1356,7 @@ fn movemouse(display: *Display, wm: *WindowManager) void {
1344 1356 return;
1345 1357 }
1346 1358
1347 - restack(display, monitor, wm);
1359 + restack(monitor, wm);
1348 1360
1349 1361 const was_floating = client.is_floating;
1350 1362 if (!client.is_floating) {
@@ -1422,7 +1434,7 @@ fn movemouse(display: *Display, wm: *WindowManager) void {
1422 1434 client_mod.attach_aside(client);
1423 1435 client_mod.attach_stack(client);
1424 1436 monitor_mod.selected_monitor = new_mon;
1425 - focus(display, client, wm);
1437 + focus(client, wm);
1426 1438 arrange(monitor, wm);
1427 1439 arrange(new_mon.?, wm);
1428 1440 } else {
@@ -1443,7 +1455,8 @@ fn movemouse(display: *Display, wm: *WindowManager) void {
1443 1455 }
1444 1456 }
1445 1457
1446 -fn resizemouse(display: *Display, wm: *WindowManager) void {
1458 +fn resizemouse(wm: *WindowManager) void {
1459 + const display = &wm.display;
1447 1460 const monitor = monitor_mod.selected_monitor orelse return;
1448 1461 const client = monitor.sel orelse return;
1449 1462
@@ -1451,7 +1464,7 @@ fn resizemouse(display: *Display, wm: *WindowManager) void {
1451 1464 return;
1452 1465 }
1453 1466
1454 - restack(display, monitor, wm);
1467 + restack(monitor, wm);
1455 1468
1456 1469 if (!client.is_floating) {
1457 1470 client.is_floating = true;
@@ -1516,7 +1529,8 @@ fn resizemouse(display: *Display, wm: *WindowManager) void {
1516 1529 arrange(monitor, wm);
1517 1530 }
1518 1531
1519 -fn handle_expose(display: *Display, event: *xlib.XExposeEvent, wm: *WindowManager) void {
1532 +fn handle_expose(event: *xlib.XExposeEvent, wm: *WindowManager) void {
1533 + const display = &wm.display;
1520 1534 if (event.count != 0) return;
1521 1535 if (bar_mod.window_to_bar(wm.bars, event.window)) |bar| {
1522 1536 bar.invalidate();
@@ -1536,17 +1550,18 @@ fn clean_mask(mask: c_uint, wm: *WindowManager) c_uint {
1536 1550 return mask & ~(lock | wm.numlock_mask) & (shift | ctrl | mod1 | mod2 | mod3 | mod4 | mod5);
1537 1551 }
1538 1552
1539 -fn handle_button_press(display: *Display, event: *xlib.XButtonEvent, wm: *WindowManager) void {
1553 +fn handle_button_press(event: *xlib.XButtonEvent, wm: *WindowManager) void {
1554 + const display = &wm.display;
1540 1555 std.debug.print("button_press: window=0x{x} subwindow=0x{x}\n", .{ event.window, event.subwindow });
1541 1556
1542 1557 const clicked_monitor = monitor_mod.window_to_monitor(display.handle, display.root, event.window);
1543 1558 if (clicked_monitor) |monitor| {
1544 1559 if (monitor != monitor_mod.selected_monitor) {
1545 1560 if (monitor_mod.selected_monitor) |selmon| {
1546 - unfocus_client(display, selmon.sel, true, wm);
1561 + unfocus_client(selmon.sel, true, wm);
1547 1562 }
1548 1563 monitor_mod.selected_monitor = monitor;
1549 - focus(display, null, wm);
1564 + focus(null, wm);
1550 1565 }
1551 1566 }
1552 1567
@@ -1554,16 +1569,16 @@ fn handle_button_press(display: *Display, event: *xlib.XButtonEvent, wm: *Window
1554 1569 const clicked_tag = bar.handle_click(display.handle, event.x, wm.config);
1555 1570 if (clicked_tag) |tag_index| {
1556 1571 const tag_mask: u32 = @as(u32, 1) << @intCast(tag_index);
1557 - view(display, tag_mask, wm);
1572 + view(tag_mask, wm);
1558 1573 }
1559 1574 return;
1560 1575 }
1561 1576
1562 1577 const click_client = client_mod.window_to_client(monitor_mod.monitors, event.window);
1563 1578 if (click_client) |found_client| {
1564 - focus(display, found_client, wm);
1579 + focus(found_client, wm);
1565 1580 if (monitor_mod.selected_monitor) |selmon| {
1566 - restack(display, selmon, wm);
1581 + restack(selmon, wm);
1567 1582 }
1568 1583 _ = xlib.XAllowEvents(display.handle, xlib.ReplayPointer, xlib.CurrentTime);
1569 1584 }
@@ -1574,8 +1589,8 @@ fn handle_button_press(display: *Display, event: *xlib.XButtonEvent, wm: *Window
1574 1589 const button_clean_mask = clean_mask(button.mod_mask, wm);
1575 1590 if (clean_state == button_clean_mask and event.button == button.button) {
1576 1591 switch (button.action) {
1577 - .move_mouse => movemouse(display, wm),
1578 - .resize_mouse => resizemouse(display, wm),
1592 + .move_mouse => movemouse(wm),
1593 + .resize_mouse => resizemouse(wm),
1579 1594 .toggle_floating => {
1580 1595 if (click_client) |found_client| {
1581 1596 found_client.is_floating = !found_client.is_floating;
@@ -1590,7 +1605,7 @@ fn handle_button_press(display: *Display, event: *xlib.XButtonEvent, wm: *Window
1590 1605 }
1591 1606 }
1592 1607
1593 -fn handle_client_message(display: *Display, event: *xlib.XClientMessageEvent, wm: *WindowManager) void {
1608 +fn handle_client_message(event: *xlib.XClientMessageEvent, wm: *WindowManager) void {
1594 1609 const client = client_mod.window_to_client(monitor_mod.monitors, event.window) orelse return;
1595 1610
1596 1611 if (event.message_type == wm.atoms.net_wm_state) {
@@ -1604,34 +1619,34 @@ fn handle_client_message(display: *Display, event: *xlib.XClientMessageEvent, wm
1604 1619 const net_wm_state_toggle = 2;
1605 1620
1606 1621 if (action == net_wm_state_add) {
1607 - set_fullscreen(display, client, true, wm);
1622 + set_fullscreen(client, true, wm);
1608 1623 } else if (action == net_wm_state_remove) {
1609 - set_fullscreen(display, client, false, wm);
1624 + set_fullscreen(client, false, wm);
1610 1625 } else if (action == net_wm_state_toggle) {
1611 - set_fullscreen(display, client, !client.is_fullscreen, wm);
1626 + set_fullscreen(client, !client.is_fullscreen, wm);
1612 1627 }
1613 1628 }
1614 1629 } else if (event.message_type == wm.atoms.net_active_window) {
1615 1630 const selected = monitor_mod.selected_monitor orelse return;
1616 1631 if (client != selected.sel and !client.is_urgent) {
1617 - set_urgent(display, client, true);
1632 + set_urgent(client, true, wm);
1618 1633 }
1619 1634 }
1620 1635 }
1621 1636
1622 -fn handle_destroy_notify(display: *Display, event: *xlib.XDestroyWindowEvent, wm: *WindowManager) void {
1637 +fn handle_destroy_notify(event: *xlib.XDestroyWindowEvent, wm: *WindowManager) void {
1623 1638 const client = client_mod.window_to_client(monitor_mod.monitors, event.window) orelse return;
1624 1639 std.debug.print("destroy_notify: window=0x{x}\n", .{event.window});
1625 - unmanage(display, client, wm);
1640 + unmanage(client, wm);
1626 1641 }
1627 1642
1628 -fn handle_unmap_notify(display: *Display, event: *xlib.XUnmapEvent, wm: *WindowManager) void {
1643 +fn handle_unmap_notify(event: *xlib.XUnmapEvent, wm: *WindowManager) void {
1629 1644 const client = client_mod.window_to_client(monitor_mod.monitors, event.window) orelse return;
1630 1645 std.debug.print("unmap_notify: window=0x{x}\n", .{event.window});
1631 - unmanage(display, client, wm);
1646 + unmanage(client, wm);
1632 1647 }
1633 1648
1634 -fn unmanage(display: *Display, client: *Client, wm: *WindowManager) void {
1649 +fn unmanage(client: *Client, wm: *WindowManager) void {
1635 1650 const client_monitor = client.monitor;
1636 1651
1637 1652 var next_focus: ?*Client = null;
@@ -1671,16 +1686,17 @@ fn unmanage(display: *Display, client: *Client, wm: *WindowManager) void {
1671 1686
1672 1687 if (client_monitor) |monitor| {
1673 1688 if (monitor.sel) |selected| {
1674 - focus(display, selected, wm);
1689 + focus(selected, wm);
1675 1690 }
1676 1691 }
1677 1692
1678 1693 client_mod.destroy(gpa.allocator(), client);
1679 - update_client_list(display, wm);
1694 + update_client_list(wm);
1680 1695 wm.invalidate_bars();
1681 1696 }
1682 1697
1683 -fn handle_enter_notify(display: *Display, event: *xlib.XCrossingEvent, wm: *WindowManager) void {
1698 +fn handle_enter_notify(event: *xlib.XCrossingEvent, wm: *WindowManager) void {
1699 + const display = &wm.display;
1684 1700 if ((event.mode != xlib.NotifyNormal or event.detail == xlib.NotifyInferior) and event.window != display.root) {
1685 1701 return;
1686 1702 }
@@ -1691,7 +1707,7 @@ fn handle_enter_notify(display: *Display, event: *xlib.XCrossingEvent, wm: *Wind
1691 1707
1692 1708 if (target_mon != selmon) {
1693 1709 if (selmon) |sel| {
1694 - unfocus_client(display, sel.sel, true, wm);
1710 + unfocus_client(sel.sel, true, wm);
1695 1711 }
1696 1712 monitor_mod.selected_monitor = target_mon;
1697 1713 } else if (client == null) {
@@ -1702,40 +1718,43 @@ fn handle_enter_notify(display: *Display, event: *xlib.XCrossingEvent, wm: *Wind
1702 1718 }
1703 1719 }
1704 1720
1705 - focus(display, client, wm);
1721 + focus(client, wm);
1706 1722 }
1707 1723
1708 -fn handle_focus_in(display: *Display, event: *xlib.XFocusChangeEvent, wm: *WindowManager) void {
1724 +fn handle_focus_in(event: *xlib.XFocusChangeEvent, wm: *WindowManager) void {
1709 1725 const selmon = monitor_mod.selected_monitor orelse return;
1710 1726 const selected = selmon.sel orelse return;
1711 1727 if (event.window != selected.window) {
1712 - set_focus(display, selected, wm);
1728 + set_focus(selected, wm);
1713 1729 }
1714 1730 }
1715 1731
1716 -fn set_focus(display: *Display, client: *Client, wm: *WindowManager) void {
1732 +fn set_focus(client: *Client, wm: *WindowManager) void {
1733 + const display = &wm.display;
1717 1734 if (!client.never_focus) {
1718 1735 _ = xlib.XSetInputFocus(display.handle, client.window, xlib.RevertToPointerRoot, xlib.CurrentTime);
1719 1736 _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_active_window, xlib.XA_WINDOW, 32, xlib.PropModeReplace, @ptrCast(&client.window), 1);
1720 1737 }
1721 - _ = send_event(display, client, wm.atoms.wm_take_focus, wm);
1738 + _ = send_event(client, wm.atoms.wm_take_focus, wm);
1722 1739 }
1723 1740
1724 -fn handle_motion_notify(display: *Display, event: *xlib.XMotionEvent, wm: *WindowManager) void {
1741 +fn handle_motion_notify(event: *xlib.XMotionEvent, wm: *WindowManager) void {
1742 + const display = &wm.display;
1725 1743 if (event.window != display.root) return;
1726 1744
1727 1745 const target_mon = monitor_mod.rect_to_monitor(event.x_root, event.y_root, 1, 1);
1728 1746 if (target_mon != wm.last_motion_monitor and wm.last_motion_monitor != null) {
1729 1747 if (monitor_mod.selected_monitor) |selmon| {
1730 - unfocus_client(display, selmon.sel, true, wm);
1748 + unfocus_client(selmon.sel, true, wm);
1731 1749 }
1732 1750 monitor_mod.selected_monitor = target_mon;
1733 - focus(display, null, wm);
1751 + focus(null, wm);
1734 1752 }
1735 1753 wm.last_motion_monitor = target_mon;
1736 1754 }
1737 1755
1738 -fn handle_property_notify(display: *Display, event: *xlib.XPropertyEvent, wm: *WindowManager) void {
1756 +fn handle_property_notify(event: *xlib.XPropertyEvent, wm: *WindowManager) void {
1757 + const display = &wm.display;
1739 1758 if (event.state == xlib.PropertyDelete) {
1740 1759 return;
1741 1760 }
@@ -1755,18 +1774,19 @@ fn handle_property_notify(display: *Display, event: *xlib.XPropertyEvent, wm: *W
1755 1774 } else if (event.atom == xlib.XA_WM_NORMAL_HINTS) {
1756 1775 client.hints_valid = false;
1757 1776 } else if (event.atom == xlib.XA_WM_HINTS) {
1758 - update_wm_hints(display, client);
1777 + update_wm_hints(client, wm);
1759 1778 wm.invalidate_bars();
1760 1779 } else if (event.atom == xlib.XA_WM_NAME or event.atom == wm.atoms.net_wm_name) {
1761 - update_title(display, client, wm);
1780 + update_title(client, wm);
1762 1781 } else if (event.atom == wm.atoms.net_wm_window_type) {
1763 - update_window_type(display, client, wm);
1782 + update_window_type(client, wm);
1764 1783 }
1765 1784 }
1766 1785
1767 -fn unfocus_client(display: *Display, client: ?*Client, reset_input_focus: bool, wm: *WindowManager) void {
1786 +fn unfocus_client(client: ?*Client, reset_input_focus: bool, wm: *WindowManager) void {
1787 + const display = &wm.display;
1768 1788 const unfocus_target = client orelse return;
1769 - grabbuttons(display, unfocus_target, false, wm);
1789 + grabbuttons(unfocus_target, false, wm);
1770 1790 _ = xlib.XSetWindowBorder(display.handle, unfocus_target.window, wm.config.border_unfocused);
1771 1791 if (reset_input_focus) {
1772 1792 _ = xlib.XSetInputFocus(display.handle, display.root, xlib.RevertToPointerRoot, xlib.CurrentTime);
@@ -1774,12 +1794,14 @@ fn unfocus_client(display: *Display, client: ?*Client, reset_input_focus: bool,
1774 1794 }
1775 1795 }
1776 1796
1777 -fn set_client_state(display: *Display, client: *Client, state: c_long, wm: *WindowManager) void {
1797 +fn set_client_state(client: *Client, state: c_long, wm: *WindowManager) void {
1798 + const display = &wm.display;
1778 1799 var data: [2]c_long = .{ state, xlib.None };
1779 1800 _ = xlib.c.XChangeProperty(display.handle, client.window, wm.atoms.wm_state, xlib.XA_ATOM, 32, xlib.PropModeReplace, @ptrCast(&data), 2);
1780 1801 }
1781 1802
1782 -fn update_numlock_mask(display: *Display, wm: *WindowManager) void {
1803 +fn update_numlock_mask(wm: *WindowManager) void {
1804 + const display = &wm.display;
1783 1805 wm.numlock_mask = 0;
1784 1806 const modmap = xlib.XGetModifierMapping(display.handle);
1785 1807 if (modmap == null) return;
@@ -1799,8 +1821,9 @@ fn update_numlock_mask(display: *Display, wm: *WindowManager) void {
1799 1821 }
1800 1822 }
1801 1823
1802 -fn grabbuttons(display: *Display, client: *Client, focused: bool, wm: *WindowManager) void {
1803 - update_numlock_mask(display, wm);
1824 +fn grabbuttons(client: *Client, focused: bool, wm: *WindowManager) void {
1825 + const display = &wm.display;
1826 + update_numlock_mask(wm);
1804 1827 const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask };
1805 1828
1806 1829 _ = xlib.XUngrabButton(display.handle, xlib.AnyButton, xlib.AnyModifier, client.window);
@@ -1838,7 +1861,8 @@ fn grabbuttons(display: *Display, client: *Client, focused: bool, wm: *WindowMan
1838 1861 }
1839 1862 }
1840 1863
1841 -fn focus(display: *Display, target_client: ?*Client, wm: *WindowManager) void {
1864 +fn focus(target_client: ?*Client, wm: *WindowManager) void {
1865 + const display = &wm.display;
1842 1866 const selmon = monitor_mod.selected_monitor orelse return;
1843 1867
1844 1868 var focus_client = target_client;
@@ -1851,7 +1875,7 @@ fn focus(display: *Display, target_client: ?*Client, wm: *WindowManager) void {
1851 1875 }
1852 1876
1853 1877 if (selmon.sel != null and selmon.sel != focus_client) {
1854 - unfocus_client(display, selmon.sel, false, wm);
1878 + unfocus_client(selmon.sel, false, wm);
1855 1879 }
1856 1880
1857 1881 if (focus_client) |client| {
@@ -1859,17 +1883,17 @@ fn focus(display: *Display, target_client: ?*Client, wm: *WindowManager) void {
1859 1883 monitor_mod.selected_monitor = client.monitor;
1860 1884 }
1861 1885 if (client.is_urgent) {
1862 - set_urgent(display, client, false);
1886 + set_urgent(client, false, wm);
1863 1887 }
1864 1888 client_mod.detach_stack(client);
1865 1889 client_mod.attach_stack(client);
1866 - grabbuttons(display, client, true, wm);
1890 + grabbuttons(client, true, wm);
1867 1891 _ = xlib.XSetWindowBorder(display.handle, client.window, wm.config.border_focused);
1868 1892 if (!client.never_focus) {
1869 1893 _ = xlib.XSetInputFocus(display.handle, client.window, xlib.RevertToPointerRoot, xlib.CurrentTime);
1870 1894 _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_active_window, xlib.XA_WINDOW, 32, xlib.PropModeReplace, @ptrCast(&client.window), 1);
1871 1895 }
1872 - _ = send_event(display, client, wm.atoms.wm_take_focus, wm);
1896 + _ = send_event(client, wm.atoms.wm_take_focus, wm);
1873 1897 } else {
1874 1898 _ = xlib.XSetInputFocus(display.handle, display.root, xlib.RevertToPointerRoot, xlib.CurrentTime);
1875 1899 _ = xlib.XDeleteProperty(display.handle, display.root, wm.atoms.net_active_window);
@@ -1887,7 +1911,8 @@ fn focus(display: *Display, target_client: ?*Client, wm: *WindowManager) void {
1887 1911 wm.invalidate_bars();
1888 1912 }
1889 1913
1890 -fn restack(display: *Display, monitor: *Monitor, wm: *WindowManager) void {
1914 +fn restack(monitor: *Monitor, wm: *WindowManager) void {
1915 + const display = &wm.display;
1891 1916 wm.invalidate_bars();
1892 1917 const selected_client = monitor.sel orelse return;
1893 1918
@@ -1917,13 +1942,13 @@ fn restack(display: *Display, monitor: *Monitor, wm: *WindowManager) void {
1917 1942 }
1918 1943
1919 1944 fn arrange(monitor: *Monitor, wm: *WindowManager) void {
1920 - showhide(&wm.display, monitor, wm);
1945 + showhide(monitor, wm);
1921 1946 if (monitor.lt[monitor.sel_lt]) |layout| {
1922 1947 if (layout.arrange_fn) |arrange_fn| {
1923 1948 arrange_fn(monitor);
1924 1949 }
1925 1950 }
1926 - restack(&wm.display, monitor, wm);
1951 + restack(monitor, wm);
1927 1952 }
1928 1953
1929 1954 fn tick_animations(wm: *WindowManager) void {
@@ -1975,7 +2000,8 @@ fn scroll_to_window(client: *Client, animate: bool, wm: *WindowManager) void {
1975 2000 }
1976 2001 }
1977 2002
1978 -fn showhide_client(display: *Display, client: ?*Client, wm: *WindowManager) void {
2003 +fn showhide_client(client: ?*Client, wm: *WindowManager) void {
2004 + const display = &wm.display;
1979 2005 const target = client orelse return;
1980 2006 if (client_mod.is_visible(target)) {
1981 2007 _ = xlib.XMoveWindow(display.handle, target.window, target.x, target.y);
@@ -1983,19 +2009,20 @@ fn showhide_client(display: *Display, client: ?*Client, wm: *WindowManager) void
1983 2009 if ((monitor.lt[monitor.sel_lt] == null or target.is_floating) and !target.is_fullscreen) {
1984 2010 tiling.resize(target, target.x, target.y, target.width, target.height, false);
1985 2011 }
1986 - showhide_client(display, target.stack_next, wm);
2012 + showhide_client(target.stack_next, wm);
1987 2013 } else {
1988 - showhide_client(display, target.stack_next, wm);
2014 + showhide_client(target.stack_next, wm);
1989 2015 const client_width = target.width + 2 * target.border_width;
1990 2016 _ = xlib.XMoveWindow(display.handle, target.window, -2 * client_width, target.y);
1991 2017 }
1992 2018 }
1993 2019
1994 -fn showhide(display: *Display, monitor: *Monitor, wm: *WindowManager) void {
1995 - showhide_client(display, monitor.stack, wm);
2020 +fn showhide(monitor: *Monitor, wm: *WindowManager) void {
2021 + showhide_client(monitor.stack, wm);
1996 2022 }
1997 2023
1998 -fn update_size_hints(display: *Display, client: *Client) void {
2024 +fn update_size_hints(client: *Client, wm: *WindowManager) void {
2025 + const display = &wm.display;
1999 2026 var size_hints: xlib.XSizeHints = undefined;
2000 2027 var msize: c_long = 0;
2001 2028
@@ -2053,7 +2080,8 @@ fn update_size_hints(display: *Display, client: *Client) void {
2053 2080 client.hints_valid = true;
2054 2081 }
2055 2082
2056 -fn update_wm_hints(display: *Display, client: *Client) void {
2083 +fn update_wm_hints(client: *Client, wm: *WindowManager) void {
2084 + const display = &wm.display;
2057 2085 const wmh = xlib.XGetWMHints(display.handle, client.window);
2058 2086 if (wmh) |hints| {
2059 2087 defer _ = xlib.XFree(@ptrCast(hints));
@@ -2073,28 +2101,29 @@ fn update_wm_hints(display: *Display, client: *Client) void {
2073 2101 }
2074 2102 }
2075 2103
2076 -fn update_window_type(display: *Display, client: *Client, wm: *WindowManager) void {
2077 - const state = get_atom_prop(display, client, wm.atoms.net_wm_state);
2078 - const window_type = get_atom_prop(display, client, wm.atoms.net_wm_window_type);
2104 +fn update_window_type(client: *Client, wm: *WindowManager) void {
2105 + const state = get_atom_prop(client, wm.atoms.net_wm_state, wm);
2106 + const window_type = get_atom_prop(client, wm.atoms.net_wm_window_type, wm);
2079 2107
2080 2108 if (state == wm.atoms.net_wm_state_fullscreen) {
2081 - set_fullscreen(display, client, true, wm);
2109 + set_fullscreen(client, true, wm);
2082 2110 }
2083 2111 if (window_type == wm.atoms.net_wm_window_type_dialog) {
2084 2112 client.is_floating = true;
2085 2113 }
2086 2114 }
2087 2115
2088 -fn update_title(display: *Display, client: *Client, wm: *WindowManager) void {
2089 - if (!get_text_prop(display, client.window, wm.atoms.net_wm_name, &client.name)) {
2090 - _ = get_text_prop(display, client.window, xlib.XA_WM_NAME, &client.name);
2116 +fn update_title(client: *Client, wm: *WindowManager) void {
2117 + if (!get_text_prop(client.window, wm.atoms.net_wm_name, &client.name, wm)) {
2118 + _ = get_text_prop(client.window, xlib.XA_WM_NAME, &client.name, wm);
2091 2119 }
2092 2120 if (client.name[0] == 0) {
2093 2121 @memcpy(client.name[0..6], "broken");
2094 2122 }
2095 2123 }
2096 2124
2097 -fn get_atom_prop(display: *Display, client: *Client, prop: xlib.Atom) xlib.Atom {
2125 +fn get_atom_prop(client: *Client, prop: xlib.Atom, wm: *WindowManager) xlib.Atom {
2126 + const display = &wm.display;
2098 2127 var actual_type: xlib.Atom = undefined;
2099 2128 var actual_format: c_int = undefined;
2100 2129 var num_items: c_ulong = undefined;
@@ -2109,7 +2138,8 @@ fn get_atom_prop(display: *Display, client: *Client, prop: xlib.Atom) xlib.Atom
2109 2138 return 0;
2110 2139 }
2111 2140
2112 -fn get_text_prop(display: *Display, window: xlib.Window, atom: xlib.Atom, text: *[256]u8) bool {
2141 +fn get_text_prop(window: xlib.Window, atom: xlib.Atom, text: *[256]u8, wm: *WindowManager) bool {
2142 + const display = &wm.display;
2113 2143 var name: xlib.XTextProperty = undefined;
2114 2144 text[0] = 0;
2115 2145
@@ -2137,7 +2167,8 @@ fn get_text_prop(display: *Display, window: xlib.Window, atom: xlib.Atom, text:
2137 2167 return true;
2138 2168 }
2139 2169
2140 -fn apply_rules(display: *Display, client: *Client, wm: *WindowManager) void {
2170 +fn apply_rules(client: *Client, wm: *WindowManager) void {
2171 + const display = &wm.display;
2141 2172 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null };
2142 2173 _ = xlib.XGetClassHint(display.handle, client.window, &class_hint);
2143 2174
@@ -2190,12 +2221,13 @@ fn apply_rules(display: *Display, client: *Client, wm: *WindowManager) void {
2190 2221 const monitor_tagset = monitor.tagset[monitor.sel_tags];
2191 2222 const is_tag_focused = (monitor_tagset & client.tags) == client.tags;
2192 2223 if (!is_tag_focused) {
2193 - view(display, client.tags, wm);
2224 + view(client.tags, wm);
2194 2225 }
2195 2226 }
2196 2227 }
2197 2228
2198 -fn update_client_list(display: *Display, wm: *WindowManager) void {
2229 +fn update_client_list(wm: *WindowManager) void {
2230 + const display = &wm.display;
2199 2231 _ = xlib.XDeleteProperty(display.handle, display.root, wm.atoms.net_client_list);
2200 2232
2201 2233 var current_monitor = monitor_mod.monitors;
@@ -2209,7 +2241,8 @@ fn update_client_list(display: *Display, wm: *WindowManager) void {
2209 2241 }
2210 2242 }
2211 2243
2212 -fn send_event(display: *Display, client: *Client, protocol: xlib.Atom, wm: *WindowManager) bool {
2244 +fn send_event(client: *Client, protocol: xlib.Atom, wm: *WindowManager) bool {
2245 + const display = &wm.display;
2213 2246 var protocols: [*c]xlib.Atom = undefined;
2214 2247 var num_protocols: c_int = 0;
2215 2248 var exists = false;
@@ -2238,7 +2271,8 @@ fn send_event(display: *Display, client: *Client, protocol: xlib.Atom, wm: *Wind
2238 2271 return exists;
2239 2272 }
2240 2273
2241 -fn set_urgent(display: *Display, client: *Client, urgent: bool) void {
2274 +fn set_urgent(client: *Client, urgent: bool, wm: *WindowManager) void {
2275 + const display = &wm.display;
2242 2276 client.is_urgent = urgent;
2243 2277 const wmh = xlib.XGetWMHints(display.handle, client.window);
2244 2278 if (wmh) |hints| {