refactor: remove `Display` param from wm functions and use `wm.Display` directly
Browse files
+203 −169 src/main.zig Large diff collapsed, click to expand
| @@ -200,8 +200,8 @@ pub fn main() !void { | |||
| 200 | std.debug.print("successfully became window manager\n", .{}); | 200 | std.debug.print("successfully became window manager\n", .{}); |
| 201 | std.debug.print("atoms initialized with EWMH support\n", .{}); | 201 | std.debug.print("atoms initialized with EWMH support\n", .{}); |
| 202 | 202 | ||
| 203 | - grab_keybinds(&wm.display, &wm); | 203 | + grab_keybinds(&wm); |
| 204 | - scan_existing_windows(&wm.display, &wm); | 204 | + scan_existing_windows(&wm); |
| 205 | 205 | ||
| 206 | try run_autostart_commands(allocator, wm.config.autostart.items); | 206 | try run_autostart_commands(allocator, wm.config.autostart.items); |
| 207 | std.debug.print("entering event loop\n", .{}); | 207 | std.debug.print("entering event loop\n", .{}); |
| @@ -271,8 +271,9 @@ fn initialize_default_config(cfg: *config_mod.Config) void { | |||
| 271 | cfg.add_button(.{ .click = .client_win, .mod_mask = mod_key, .button = 3, .action = .resize_mouse }) catch {}; | 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 { | 274 | +fn grab_keybinds(wm: *WindowManager) void { |
| 275 | - update_numlock_mask(display, wm); | 275 | + const display = &wm.display; |
| 276 | + update_numlock_mask(wm); | ||
| 276 | const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask }; | 277 | const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask }; |
| 277 | 278 | ||
| 278 | _ = xlib.XUngrabKey(display.handle, xlib.AnyKey, xlib.AnyModifier, display.root); | 279 | _ = xlib.XUngrabKey(display.handle, xlib.AnyKey, xlib.AnyModifier, display.root); |
| @@ -318,7 +319,8 @@ fn grab_keybinds(display: *Display, wm: *WindowManager) void { | |||
| 318 | std.debug.print("grabbed {d} keybinds from config\n", .{wm.config.keybinds.items.len}); | 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 | var actual_type: xlib.Atom = 0; | 324 | var actual_type: xlib.Atom = 0; |
| 323 | var actual_format: c_int = 0; | 325 | var actual_format: c_int = 0; |
| 324 | var num_items: c_ulong = 0; | 326 | var num_items: c_ulong = 0; |
| @@ -352,7 +354,8 @@ fn get_state(display: *Display, window: xlib.Window, wm: *WindowManager) c_long | |||
| 352 | return state; | 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 | var root_return: xlib.Window = undefined; | 359 | var root_return: xlib.Window = undefined; |
| 357 | var parent_return: xlib.Window = undefined; | 360 | var parent_return: xlib.Window = undefined; |
| 358 | var children: [*c]xlib.Window = undefined; | 361 | var children: [*c]xlib.Window = undefined; |
| @@ -375,8 +378,8 @@ fn scan_existing_windows(display: *Display, wm: *WindowManager) void { | |||
| 375 | if (xlib.XGetTransientForHint(display.handle, children[index], &trans) != 0) { | 378 | if (xlib.XGetTransientForHint(display.handle, children[index], &trans) != 0) { |
| 376 | continue; | 379 | continue; |
| 377 | } | 380 | } |
| 378 | - if (window_attrs.map_state == IsViewable or get_state(display, children[index], wm) == IconicState) { | 381 | + if (window_attrs.map_state == IsViewable or get_state(children[index], wm) == IconicState) { |
| 379 | - manage(display, children[index], &window_attrs, wm); | 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 | var trans: xlib.Window = 0; | 392 | var trans: xlib.Window = 0; |
| 390 | if (xlib.XGetTransientForHint(display.handle, children[index], &trans) != 0) { | 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) { | 394 | + if (window_attrs.map_state == IsViewable or get_state(children[index], wm) == IconicState) { |
| 392 | - manage(display, children[index], &window_attrs, wm); | 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 | while (wm.running) { | 412 | while (wm.running) { |
| 410 | while (xlib.XPending(wm.display.handle) > 0) { | 413 | while (xlib.XPending(wm.display.handle) > 0) { |
| 411 | var event = wm.display.next_event(); | 414 | var event = wm.display.next_event(); |
| 412 | - handle_event(&wm.display, &event, wm); | 415 | + handle_event(&event, wm); |
| 413 | } | 416 | } |
| 414 | 417 | ||
| 415 | tick_animations(wm); | 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 | const event_type = events.get_event_type(event); | 433 | const event_type = events.get_event_type(event); |
| 431 | 434 | ||
| 432 | if (event_type == .button_press) { | 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 | switch (event_type) { | 439 | switch (event_type) { |
| 437 | - .map_request => handle_map_request(display, &event.xmaprequest, wm), | 440 | + .map_request => handle_map_request(&event.xmaprequest, wm), |
| 438 | - .configure_request => handle_configure_request(display, &event.xconfigurerequest, wm), | 441 | + .configure_request => handle_configure_request(&event.xconfigurerequest, wm), |
| 439 | - .key_press => handle_key_press(display, &event.xkey, wm), | 442 | + .key_press => handle_key_press(&event.xkey, wm), |
| 440 | - .destroy_notify => handle_destroy_notify(display, &event.xdestroywindow, wm), | 443 | + .destroy_notify => handle_destroy_notify(&event.xdestroywindow, wm), |
| 441 | - .unmap_notify => handle_unmap_notify(display, &event.xunmap, wm), | 444 | + .unmap_notify => handle_unmap_notify(&event.xunmap, wm), |
| 442 | - .enter_notify => handle_enter_notify(display, &event.xcrossing, wm), | 445 | + .enter_notify => handle_enter_notify(&event.xcrossing, wm), |
| 443 | - .focus_in => handle_focus_in(display, &event.xfocus, wm), | 446 | + .focus_in => handle_focus_in(&event.xfocus, wm), |
| 444 | - .motion_notify => handle_motion_notify(display, &event.xmotion, wm), | 447 | + .motion_notify => handle_motion_notify(&event.xmotion, wm), |
| 445 | - .client_message => handle_client_message(display, &event.xclient, wm), | 448 | + .client_message => handle_client_message(&event.xclient, wm), |
| 446 | - .button_press => handle_button_press(display, &event.xbutton, wm), | 449 | + .button_press => handle_button_press(&event.xbutton, wm), |
| 447 | - .expose => handle_expose(display, &event.xexpose, wm), | 450 | + .expose => handle_expose(&event.xexpose, wm), |
| 448 | - .property_notify => handle_property_notify(display, &event.xproperty, wm), | 451 | + .property_notify => handle_property_notify(&event.xproperty, wm), |
| 449 | else => {}, | 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 | std.debug.print("map_request: window=0x{x}\n", .{event.window}); | 458 | std.debug.print("map_request: window=0x{x}\n", .{event.window}); |
| 455 | 459 | ||
| 456 | var window_attributes: xlib.XWindowAttributes = undefined; | 460 | var window_attributes: xlib.XWindowAttributes = undefined; |
| @@ -464,10 +468,11 @@ fn handle_map_request(display: *Display, event: *xlib.XMapRequestEvent, wm: *Win | |||
| 464 | return; | 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 | const client = client_mod.create(gpa.allocator(), win) orelse return; | 476 | const client = client_mod.create(gpa.allocator(), win) orelse return; |
| 472 | var trans: xlib.Window = 0; | 477 | var trans: xlib.Window = 0; |
| 473 | 478 | ||
| @@ -482,7 +487,7 @@ fn manage(display: *Display, win: xlib.Window, window_attrs: *xlib.XWindowAttrib | |||
| 482 | client.old_border_width = window_attrs.border_width; | 487 | client.old_border_width = window_attrs.border_width; |
| 483 | client.border_width = wm.config.border_width; | 488 | client.border_width = wm.config.border_width; |
| 484 | 489 | ||
| 485 | - update_title(display, client, wm); | 490 | + update_title(client, wm); |
| 486 | 491 | ||
| 487 | if (xlib.XGetTransientForHint(display.handle, win, &trans) != 0) { | 492 | if (xlib.XGetTransientForHint(display.handle, win, &trans) != 0) { |
| 488 | if (client_mod.window_to_client(monitor_mod.monitors, trans)) |transient_client| { | 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 | if (client.monitor == null) { | 499 | if (client.monitor == null) { |
| 495 | client.monitor = monitor_mod.selected_monitor; | 500 | client.monitor = monitor_mod.selected_monitor; |
| 496 | - apply_rules(display, client, wm); | 501 | + apply_rules(client, wm); |
| 497 | } | 502 | } |
| 498 | 503 | ||
| 499 | const monitor = client.monitor orelse return; | 504 | const monitor = client.monitor orelse return; |
| @@ -511,16 +516,16 @@ fn manage(display: *Display, win: xlib.Window, window_attrs: *xlib.XWindowAttrib | |||
| 511 | _ = xlib.XSetWindowBorder(display.handle, win, wm.config.border_unfocused); | 516 | _ = xlib.XSetWindowBorder(display.handle, win, wm.config.border_unfocused); |
| 512 | tiling.send_configure(client); | 517 | tiling.send_configure(client); |
| 513 | 518 | ||
| 514 | - update_window_type(display, client, wm); | 519 | + update_window_type(client, wm); |
| 515 | - update_size_hints(display, client); | 520 | + update_size_hints(client, wm); |
| 516 | - update_wm_hints(display, client); | 521 | + update_wm_hints(client, wm); |
| 517 | 522 | ||
| 518 | _ = xlib.XSelectInput( | 523 | _ = xlib.XSelectInput( |
| 519 | display.handle, | 524 | display.handle, |
| 520 | win, | 525 | win, |
| 521 | xlib.EnterWindowMask | xlib.FocusChangeMask | xlib.PropertyChangeMask | xlib.StructureNotifyMask, | 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 | if (!client.is_floating) { | 530 | if (!client.is_floating) { |
| 526 | client.is_floating = trans != 0 or client.is_fixed; | 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 | _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_client_list, xlib.XA_WINDOW, 32, xlib.PropModeAppend, @ptrCast(&client.window), 1); | 541 | _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_client_list, xlib.XA_WINDOW, 32, xlib.PropModeAppend, @ptrCast(&client.window), 1); |
| 537 | _ = xlib.XMoveResizeWindow(display.handle, client.window, client.x + 2 * display.screen_width(), client.y, @intCast(client.width), @intCast(client.height)); | 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 | if (client.monitor == monitor_mod.selected_monitor) { | 545 | if (client.monitor == monitor_mod.selected_monitor) { |
| 541 | const selmon = monitor_mod.selected_monitor orelse return; | 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 | monitor.sel = client; | 549 | monitor.sel = client; |
| 545 | 550 | ||
| @@ -549,11 +554,11 @@ fn manage(display: *Display, win: xlib.Window, window_attrs: *xlib.XWindowAttrib | |||
| 549 | 554 | ||
| 550 | arrange(monitor, wm); | 555 | arrange(monitor, wm); |
| 551 | _ = xlib.XMapWindow(display.handle, win); | 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 { | 560 | +fn handle_configure_request(event: *xlib.XConfigureRequestEvent, wm: *WindowManager) void { |
| 556 | - _ = wm; | 561 | + const display = &wm.display; |
| 557 | const client = client_mod.window_to_client(monitor_mod.monitors, event.window); | 562 | const client = client_mod.window_to_client(monitor_mod.monitors, event.window); |
| 558 | 563 | ||
| 559 | if (client) |managed_client| { | 564 | if (client) |managed_client| { |
| @@ -608,7 +613,8 @@ fn handle_configure_request(display: *Display, event: *xlib.XConfigureRequestEve | |||
| 608 | _ = xlib.XSync(display.handle, xlib.False); | 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 | const keysym = xlib.XKeycodeToKeysym(display.handle, @intCast(event.keycode), 0); | 618 | const keysym = xlib.XKeycodeToKeysym(display.handle, @intCast(event.keycode), 0); |
| 613 | 619 | ||
| 614 | if (wm.overlay) |overlay| { | 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 | if (matches) { | 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 | wm.chord.reset(display.handle); | 647 | wm.chord.reset(display.handle); |
| 642 | return; | 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 | switch (action) { | 680 | switch (action) { |
| 675 | .spawn_terminal => spawn_terminal(wm), | 681 | .spawn_terminal => spawn_terminal(wm), |
| 676 | .spawn => { | 682 | .spawn => { |
| 677 | if (str_arg) |cmd| spawn_command(cmd); | 683 | if (str_arg) |cmd| spawn_command(cmd); |
| 678 | }, | 684 | }, |
| 679 | - .kill_client => kill_focused(display, wm), | 685 | + .kill_client => kill_focused(wm), |
| 680 | .quit => { | 686 | .quit => { |
| 681 | std.debug.print("quit keybind pressed\n", .{}); | 687 | std.debug.print("quit keybind pressed\n", .{}); |
| 682 | wm.running = false; | 688 | wm.running = false; |
| 683 | }, | 689 | }, |
| 684 | - .reload_config => reload_config(display, wm), | 690 | + .reload_config => reload_config(wm), |
| 685 | - .restart => reload_config(display, wm), | 691 | + .restart => reload_config(wm), |
| 686 | .show_keybinds => { | 692 | .show_keybinds => { |
| 687 | if (wm.overlay) |overlay| { | 693 | if (wm.overlay) |overlay| { |
| 688 | const mon = wm.selected_monitor orelse wm.monitors; | 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), | 700 | + .focus_next => focusstack(1, wm), |
| 695 | - .focus_prev => focusstack(display, -1, wm), | 701 | + .focus_prev => focusstack(-1, wm), |
| 696 | - .move_next => movestack(display, 1, wm), | 702 | + .move_next => movestack(1, wm), |
| 697 | - .move_prev => movestack(display, -1, wm), | 703 | + .move_prev => movestack(-1, wm), |
| 698 | .resize_master => setmfact(@as(f32, @floatFromInt(int_arg)) / 1000.0, wm), | 704 | .resize_master => setmfact(@as(f32, @floatFromInt(int_arg)) / 1000.0, wm), |
| 699 | .inc_master => incnmaster(1, wm), | 705 | .inc_master => incnmaster(1, wm), |
| 700 | .dec_master => incnmaster(-1, wm), | 706 | .dec_master => incnmaster(-1, wm), |
| 701 | - .toggle_floating => toggle_floating(display, wm), | 707 | + .toggle_floating => toggle_floating(wm), |
| 702 | - .toggle_fullscreen => toggle_fullscreen(display, wm), | 708 | + .toggle_fullscreen => toggle_fullscreen(wm), |
| 703 | .toggle_gaps => toggle_gaps(wm), | 709 | .toggle_gaps => toggle_gaps(wm), |
| 704 | .cycle_layout => cycle_layout(wm), | 710 | .cycle_layout => cycle_layout(wm), |
| 705 | .set_layout => set_layout(str_arg, wm), | 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 | .set_layout_floating => set_layout_index(2, wm), | 713 | .set_layout_floating => set_layout_index(2, wm), |
| 708 | .view_tag => { | 714 | .view_tag => { |
| 709 | const tag_mask: u32 = @as(u32, 1) << @intCast(int_arg); | 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), | 718 | + .view_next_tag => view_adjacent_tag(1, wm), |
| 713 | - .view_prev_tag => view_adjacent_tag(display, -1, wm), | 719 | + .view_prev_tag => view_adjacent_tag(-1, wm), |
| 714 | - .view_next_nonempty_tag => view_adjacent_nonempty_tag(display, 1, wm), | 720 | + .view_next_nonempty_tag => view_adjacent_nonempty_tag(1, wm), |
| 715 | - .view_prev_nonempty_tag => view_adjacent_nonempty_tag(display, -1, wm), | 721 | + .view_prev_nonempty_tag => view_adjacent_nonempty_tag(-1, wm), |
| 716 | .move_to_tag => { | 722 | .move_to_tag => { |
| 717 | const tag_mask: u32 = @as(u32, 1) << @intCast(int_arg); | 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 | .toggle_view_tag => { | 726 | .toggle_view_tag => { |
| 721 | const tag_mask: u32 = @as(u32, 1) << @intCast(int_arg); | 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 | .toggle_tag => { | 730 | .toggle_tag => { |
| 725 | const tag_mask: u32 = @as(u32, 1) << @intCast(int_arg); | 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), | 734 | + .focus_monitor => focusmon(int_arg, wm), |
| 729 | - .send_to_monitor => sendmon(display, int_arg, wm), | 735 | + .send_to_monitor => sendmon(int_arg, wm), |
| 730 | .scroll_left => scroll_layout(-1, wm), | 736 | .scroll_left => scroll_layout(-1, wm), |
| 731 | .scroll_right => scroll_layout(1, wm), | 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 | std.debug.print("reloading config...\n", .{}); | 743 | std.debug.print("reloading config...\n", .{}); |
| 737 | 744 | ||
| 738 | - ungrab_keybinds(display); | 745 | + ungrab_keybinds(wm); |
| 739 | 746 | ||
| 740 | wm.config.keybinds.clearRetainingCapacity(); | 747 | wm.config.keybinds.clearRetainingCapacity(); |
| 741 | wm.config.buttons.clearRetainingCapacity(); | 748 | wm.config.buttons.clearRetainingCapacity(); |
| @@ -766,7 +773,7 @@ fn reload_config(display: *Display, wm: *WindowManager) void { | |||
| 766 | wm.setup_bars(); | 773 | wm.setup_bars(); |
| 767 | rebuild_bar_blocks(wm); | 774 | rebuild_bar_blocks(wm); |
| 768 | 775 | ||
| 769 | - grab_keybinds(display, wm); | 776 | + grab_keybinds(wm); |
| 770 | } | 777 | } |
| 771 | 778 | ||
| 772 | fn rebuild_bar_blocks(wm: *WindowManager) void { | 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 | _ = xlib.XUngrabKey(display.handle, xlib.AnyKey, xlib.AnyModifier, display.root); | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 841 | const monitor = monitor_mod.selected_monitor orelse return; |
| 834 | const current = monitor.sel orelse return; | 842 | const current = monitor.sel orelse return; |
| 835 | 843 | ||
| @@ -887,12 +895,12 @@ fn movestack(display: *Display, direction: i32, wm: *WindowManager) void { | |||
| 887 | if (swap_client != current) { | 895 | if (swap_client != current) { |
| 888 | client_mod.swap_clients(current, swap_client); | 896 | client_mod.swap_clients(current, swap_client); |
| 889 | arrange(monitor, wm); | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 904 | const monitor = monitor_mod.selected_monitor orelse return; |
| 897 | const new_tags = monitor.tagset[monitor.sel_tags] ^ tag_mask; | 905 | const new_tags = monitor.tagset[monitor.sel_tags] ^ tag_mask; |
| 898 | if (new_tags != 0) { | 906 | if (new_tags != 0) { |
| @@ -916,19 +924,19 @@ fn toggle_view(display: *Display, tag_mask: u32, wm: *WindowManager) void { | |||
| 916 | monitor.mfact = monitor.pertag.mfacts[monitor.pertag.curtag]; | 924 | monitor.mfact = monitor.pertag.mfacts[monitor.pertag.curtag]; |
| 917 | monitor.sel_lt = monitor.pertag.sellts[monitor.pertag.curtag]; | 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 | arrange(monitor, wm); | 928 | arrange(monitor, wm); |
| 921 | wm.invalidate_bars(); | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 934 | const monitor = monitor_mod.selected_monitor orelse return; |
| 927 | const client = monitor.sel orelse return; | 935 | const client = monitor.sel orelse return; |
| 928 | const new_tags = client.tags ^ tag_mask; | 936 | const new_tags = client.tags ^ tag_mask; |
| 929 | if (new_tags != 0) { | 937 | if (new_tags != 0) { |
| 930 | client.tags = new_tags; | 938 | client.tags = new_tags; |
| 931 | - focus_top_client(display, monitor, wm); | 939 | + focus_top_client(monitor, wm); |
| 932 | arrange(monitor, wm); | 940 | arrange(monitor, wm); |
| 933 | wm.invalidate_bars(); | 941 | wm.invalidate_bars(); |
| 934 | } | 942 | } |
| @@ -950,12 +958,13 @@ fn toggle_gaps(wm: *WindowManager) void { | |||
| 950 | arrange(monitor, wm); | 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 | const selected = monitor_mod.selected_monitor orelse return; | 963 | const selected = monitor_mod.selected_monitor orelse return; |
| 955 | const client = selected.sel orelse return; | 964 | const client = selected.sel orelse return; |
| 956 | std.debug.print("killing window: 0x{x}\n", .{client.window}); | 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 | _ = xlib.XGrabServer(display.handle); | 968 | _ = xlib.XGrabServer(display.handle); |
| 960 | _ = xlib.XKillClient(display.handle, client.window); | 969 | _ = xlib.XKillClient(display.handle, client.window); |
| 961 | _ = xlib.XSync(display.handle, xlib.False); | 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 | const selected = monitor_mod.selected_monitor orelse return; | 976 | const selected = monitor_mod.selected_monitor orelse return; |
| 968 | const client = selected.sel orelse return; | 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 | const monitor = client.monitor orelse return; | 983 | const monitor = client.monitor orelse return; |
| 974 | 984 | ||
| 975 | if (fullscreen and !client.is_fullscreen) { | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 1037 | const monitor = monitor_mod.selected_monitor orelse return; |
| 1028 | if (tag_mask == monitor.tagset[monitor.sel_tags]) { | 1038 | if (tag_mask == monitor.tagset[monitor.sel_tags]) { |
| 1029 | return; | 1039 | return; |
| @@ -1052,13 +1062,13 @@ fn view(display: *Display, tag_mask: u32, wm: *WindowManager) void { | |||
| 1052 | monitor.mfact = monitor.pertag.mfacts[monitor.pertag.curtag]; | 1062 | monitor.mfact = monitor.pertag.mfacts[monitor.pertag.curtag]; |
| 1053 | monitor.sel_lt = monitor.pertag.sellts[monitor.pertag.curtag]; | 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 | arrange(monitor, wm); | 1066 | arrange(monitor, wm); |
| 1057 | wm.invalidate_bars(); | 1067 | wm.invalidate_bars(); |
| 1058 | std.debug.print("view: tag_mask={d}\n", .{monitor.tagset[monitor.sel_tags]}); | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 1072 | const monitor = monitor_mod.selected_monitor orelse return; |
| 1063 | const current_tag = monitor.pertag.curtag; | 1073 | const current_tag = monitor.pertag.curtag; |
| 1064 | var new_tag: i32 = @intCast(current_tag); | 1074 | var new_tag: i32 = @intCast(current_tag); |
| @@ -1068,10 +1078,10 @@ fn view_adjacent_tag(display: *Display, direction: i32, wm: *WindowManager) void | |||
| 1068 | if (new_tag > 9) new_tag = 1; | 1078 | if (new_tag > 9) new_tag = 1; |
| 1069 | 1079 | ||
| 1070 | const tag_mask: u32 = @as(u32, 1) << @intCast(new_tag - 1); | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 1085 | const monitor = monitor_mod.selected_monitor orelse return; |
| 1076 | const current_tag = monitor.pertag.curtag; | 1086 | const current_tag = monitor.pertag.curtag; |
| 1077 | var new_tag: i32 = @intCast(current_tag); | 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 | const tag_mask: u32 = @as(u32, 1) << @intCast(new_tag - 1); | 1095 | const tag_mask: u32 = @as(u32, 1) << @intCast(new_tag - 1); |
| 1086 | if (has_clients_on_tag(monitor, tag_mask)) { | 1096 | if (has_clients_on_tag(monitor, tag_mask)) { |
| 1087 | - view(display, tag_mask, wm); | 1097 | + view(tag_mask, wm); |
| 1088 | return; | 1098 | return; |
| 1089 | } | 1099 | } |
| 1090 | } | 1100 | } |
| @@ -1101,24 +1111,25 @@ fn has_clients_on_tag(monitor: *monitor_mod.Monitor, tag_mask: u32) bool { | |||
| 1101 | return false; | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 1115 | const monitor = monitor_mod.selected_monitor orelse return; |
| 1106 | const client = monitor.sel orelse return; | 1116 | const client = monitor.sel orelse return; |
| 1107 | if (tag_mask == 0) { | 1117 | if (tag_mask == 0) { |
| 1108 | return; | 1118 | return; |
| 1109 | } | 1119 | } |
| 1110 | client.tags = tag_mask; | 1120 | client.tags = tag_mask; |
| 1111 | - focus_top_client(display, monitor, wm); | 1121 | + focus_top_client(monitor, wm); |
| 1112 | arrange(monitor, wm); | 1122 | arrange(monitor, wm); |
| 1113 | wm.invalidate_bars(); | 1123 | wm.invalidate_bars(); |
| 1114 | std.debug.print("tag_client: window=0x{x} tag_mask={d}\n", .{ client.window, tag_mask }); | 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 | var visible_client = monitor.stack; | 1129 | var visible_client = monitor.stack; |
| 1119 | while (visible_client) |client| { | 1130 | while (visible_client) |client| { |
| 1120 | if (client_mod.is_visible(client)) { | 1131 | if (client_mod.is_visible(client)) { |
| 1121 | - focus(display, client, wm); | 1132 | + focus(client, wm); |
| 1122 | return; | 1133 | return; |
| 1123 | } | 1134 | } |
| 1124 | visible_client = client.stack_next; | 1135 | visible_client = client.stack_next; |
| @@ -1127,7 +1138,7 @@ fn focus_top_client(display: *Display, monitor: *Monitor, wm: *WindowManager) vo | |||
| 1127 | _ = xlib.XSetInputFocus(display.handle, display.root, xlib.RevertToPointerRoot, xlib.CurrentTime); | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 1142 | const monitor = monitor_mod.selected_monitor orelse return; |
| 1132 | const current = monitor.sel orelse return; | 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 | if (next_client) |client| { | 1188 | if (next_client) |client| { |
| 1178 | - focus(display, client, wm); | 1189 | + focus(client, wm); |
| 1179 | if (client.monitor) |client_monitor| { | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 1197 | const monitor = monitor_mod.selected_monitor orelse return; |
| 1187 | const client = monitor.sel orelse return; | 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 | const selmon = monitor_mod.selected_monitor orelse return; | 1296 | const selmon = monitor_mod.selected_monitor orelse return; |
| 1286 | const target = monitor_mod.dir_to_monitor(direction) orelse return; | 1297 | const target = monitor_mod.dir_to_monitor(direction) orelse return; |
| 1287 | if (target == selmon) { | 1298 | if (target == selmon) { |
| 1288 | return; | 1299 | return; |
| 1289 | } | 1300 | } |
| 1290 | - unfocus_client(display, selmon.sel, false, wm); | 1301 | + unfocus_client(selmon.sel, false, wm); |
| 1291 | monitor_mod.selected_monitor = target; | 1302 | monitor_mod.selected_monitor = target; |
| 1292 | - focus(display, null, wm); | 1303 | + focus(null, wm); |
| 1293 | std.debug.print("focusmon: monitor {d}\n", .{target.num}); | 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 | const source_monitor = monitor_mod.selected_monitor orelse return; | 1308 | const source_monitor = monitor_mod.selected_monitor orelse return; |
| 1298 | const client = source_monitor.sel orelse return; | 1309 | const client = source_monitor.sel orelse return; |
| 1299 | const target = monitor_mod.dir_to_monitor(direction) orelse return; | 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 | client_mod.attach_aside(client); | 1320 | client_mod.attach_aside(client); |
| 1310 | client_mod.attach_stack(client); | 1321 | client_mod.attach_stack(client); |
| 1311 | 1322 | ||
| 1312 | - focus_top_client(display, source_monitor, wm); | 1323 | + focus_top_client(source_monitor, wm); |
| 1313 | arrange(source_monitor, wm); | 1324 | arrange(source_monitor, wm); |
| 1314 | arrange(target, wm); | 1325 | arrange(target, wm); |
| 1315 | 1326 | ||
| @@ -1336,7 +1347,8 @@ fn snap_y(client: *Client, new_y: i32, monitor: *Monitor) i32 { | |||
| 1336 | return new_y; | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 1352 | const monitor = monitor_mod.selected_monitor orelse return; |
| 1341 | const client = monitor.sel orelse return; | 1353 | const client = monitor.sel orelse return; |
| 1342 | 1354 | ||
| @@ -1344,7 +1356,7 @@ fn movemouse(display: *Display, wm: *WindowManager) void { | |||
| 1344 | return; | 1356 | return; |
| 1345 | } | 1357 | } |
| 1346 | 1358 | ||
| 1347 | - restack(display, monitor, wm); | 1359 | + restack(monitor, wm); |
| 1348 | 1360 | ||
| 1349 | const was_floating = client.is_floating; | 1361 | const was_floating = client.is_floating; |
| 1350 | if (!client.is_floating) { | 1362 | if (!client.is_floating) { |
| @@ -1422,7 +1434,7 @@ fn movemouse(display: *Display, wm: *WindowManager) void { | |||
| 1422 | client_mod.attach_aside(client); | 1434 | client_mod.attach_aside(client); |
| 1423 | client_mod.attach_stack(client); | 1435 | client_mod.attach_stack(client); |
| 1424 | monitor_mod.selected_monitor = new_mon; | 1436 | monitor_mod.selected_monitor = new_mon; |
| 1425 | - focus(display, client, wm); | 1437 | + focus(client, wm); |
| 1426 | arrange(monitor, wm); | 1438 | arrange(monitor, wm); |
| 1427 | arrange(new_mon.?, wm); | 1439 | arrange(new_mon.?, wm); |
| 1428 | } else { | 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 | const monitor = monitor_mod.selected_monitor orelse return; | 1460 | const monitor = monitor_mod.selected_monitor orelse return; |
| 1448 | const client = monitor.sel orelse return; | 1461 | const client = monitor.sel orelse return; |
| 1449 | 1462 | ||
| @@ -1451,7 +1464,7 @@ fn resizemouse(display: *Display, wm: *WindowManager) void { | |||
| 1451 | return; | 1464 | return; |
| 1452 | } | 1465 | } |
| 1453 | 1466 | ||
| 1454 | - restack(display, monitor, wm); | 1467 | + restack(monitor, wm); |
| 1455 | 1468 | ||
| 1456 | if (!client.is_floating) { | 1469 | if (!client.is_floating) { |
| 1457 | client.is_floating = true; | 1470 | client.is_floating = true; |
| @@ -1516,7 +1529,8 @@ fn resizemouse(display: *Display, wm: *WindowManager) void { | |||
| 1516 | arrange(monitor, wm); | 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 | if (event.count != 0) return; | 1534 | if (event.count != 0) return; |
| 1521 | if (bar_mod.window_to_bar(wm.bars, event.window)) |bar| { | 1535 | if (bar_mod.window_to_bar(wm.bars, event.window)) |bar| { |
| 1522 | bar.invalidate(); | 1536 | bar.invalidate(); |
| @@ -1536,17 +1550,18 @@ fn clean_mask(mask: c_uint, wm: *WindowManager) c_uint { | |||
| 1536 | return mask & ~(lock | wm.numlock_mask) & (shift | ctrl | mod1 | mod2 | mod3 | mod4 | mod5); | 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 | std.debug.print("button_press: window=0x{x} subwindow=0x{x}\n", .{ event.window, event.subwindow }); | 1555 | std.debug.print("button_press: window=0x{x} subwindow=0x{x}\n", .{ event.window, event.subwindow }); |
| 1541 | 1556 | ||
| 1542 | const clicked_monitor = monitor_mod.window_to_monitor(display.handle, display.root, event.window); | 1557 | const clicked_monitor = monitor_mod.window_to_monitor(display.handle, display.root, event.window); |
| 1543 | if (clicked_monitor) |monitor| { | 1558 | if (clicked_monitor) |monitor| { |
| 1544 | if (monitor != monitor_mod.selected_monitor) { | 1559 | if (monitor != monitor_mod.selected_monitor) { |
| 1545 | if (monitor_mod.selected_monitor) |selmon| { | 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 | monitor_mod.selected_monitor = monitor; | 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 | const clicked_tag = bar.handle_click(display.handle, event.x, wm.config); | 1569 | const clicked_tag = bar.handle_click(display.handle, event.x, wm.config); |
| 1555 | if (clicked_tag) |tag_index| { | 1570 | if (clicked_tag) |tag_index| { |
| 1556 | const tag_mask: u32 = @as(u32, 1) << @intCast(tag_index); | 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 | return; | 1574 | return; |
| 1560 | } | 1575 | } |
| 1561 | 1576 | ||
| 1562 | const click_client = client_mod.window_to_client(monitor_mod.monitors, event.window); | 1577 | const click_client = client_mod.window_to_client(monitor_mod.monitors, event.window); |
| 1563 | if (click_client) |found_client| { | 1578 | if (click_client) |found_client| { |
| 1564 | - focus(display, found_client, wm); | 1579 | + focus(found_client, wm); |
| 1565 | if (monitor_mod.selected_monitor) |selmon| { | 1580 | if (monitor_mod.selected_monitor) |selmon| { |
| 1566 | - restack(display, selmon, wm); | 1581 | + restack(selmon, wm); |
| 1567 | } | 1582 | } |
| 1568 | _ = xlib.XAllowEvents(display.handle, xlib.ReplayPointer, xlib.CurrentTime); | 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 | const button_clean_mask = clean_mask(button.mod_mask, wm); | 1589 | const button_clean_mask = clean_mask(button.mod_mask, wm); |
| 1575 | if (clean_state == button_clean_mask and event.button == button.button) { | 1590 | if (clean_state == button_clean_mask and event.button == button.button) { |
| 1576 | switch (button.action) { | 1591 | switch (button.action) { |
| 1577 | - .move_mouse => movemouse(display, wm), | 1592 | + .move_mouse => movemouse(wm), |
| 1578 | - .resize_mouse => resizemouse(display, wm), | 1593 | + .resize_mouse => resizemouse(wm), |
| 1579 | .toggle_floating => { | 1594 | .toggle_floating => { |
| 1580 | if (click_client) |found_client| { | 1595 | if (click_client) |found_client| { |
| 1581 | found_client.is_floating = !found_client.is_floating; | 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 | const client = client_mod.window_to_client(monitor_mod.monitors, event.window) orelse return; | 1609 | const client = client_mod.window_to_client(monitor_mod.monitors, event.window) orelse return; |
| 1595 | 1610 | ||
| 1596 | if (event.message_type == wm.atoms.net_wm_state) { | 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 | const net_wm_state_toggle = 2; | 1619 | const net_wm_state_toggle = 2; |
| 1605 | 1620 | ||
| 1606 | if (action == net_wm_state_add) { | 1621 | if (action == net_wm_state_add) { |
| 1607 | - set_fullscreen(display, client, true, wm); | 1622 | + set_fullscreen(client, true, wm); |
| 1608 | } else if (action == net_wm_state_remove) { | 1623 | } else if (action == net_wm_state_remove) { |
| 1609 | - set_fullscreen(display, client, false, wm); | 1624 | + set_fullscreen(client, false, wm); |
| 1610 | } else if (action == net_wm_state_toggle) { | 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 | } else if (event.message_type == wm.atoms.net_active_window) { | 1629 | } else if (event.message_type == wm.atoms.net_active_window) { |
| 1615 | const selected = monitor_mod.selected_monitor orelse return; | 1630 | const selected = monitor_mod.selected_monitor orelse return; |
| 1616 | if (client != selected.sel and !client.is_urgent) { | 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 | const client = client_mod.window_to_client(monitor_mod.monitors, event.window) orelse return; | 1638 | const client = client_mod.window_to_client(monitor_mod.monitors, event.window) orelse return; |
| 1624 | std.debug.print("destroy_notify: window=0x{x}\n", .{event.window}); | 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 | const client = client_mod.window_to_client(monitor_mod.monitors, event.window) orelse return; | 1644 | const client = client_mod.window_to_client(monitor_mod.monitors, event.window) orelse return; |
| 1630 | std.debug.print("unmap_notify: window=0x{x}\n", .{event.window}); | 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 | const client_monitor = client.monitor; | 1650 | const client_monitor = client.monitor; |
| 1636 | 1651 | ||
| 1637 | var next_focus: ?*Client = null; | 1652 | var next_focus: ?*Client = null; |
| @@ -1671,16 +1686,17 @@ fn unmanage(display: *Display, client: *Client, wm: *WindowManager) void { | |||
| 1671 | 1686 | ||
| 1672 | if (client_monitor) |monitor| { | 1687 | if (client_monitor) |monitor| { |
| 1673 | if (monitor.sel) |selected| { | 1688 | if (monitor.sel) |selected| { |
| 1674 | - focus(display, selected, wm); | 1689 | + focus(selected, wm); |
| 1675 | } | 1690 | } |
| 1676 | } | 1691 | } |
| 1677 | 1692 | ||
| 1678 | client_mod.destroy(gpa.allocator(), client); | 1693 | client_mod.destroy(gpa.allocator(), client); |
| 1679 | - update_client_list(display, wm); | 1694 | + update_client_list(wm); |
| 1680 | wm.invalidate_bars(); | 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 | if ((event.mode != xlib.NotifyNormal or event.detail == xlib.NotifyInferior) and event.window != display.root) { | 1700 | if ((event.mode != xlib.NotifyNormal or event.detail == xlib.NotifyInferior) and event.window != display.root) { |
| 1685 | return; | 1701 | return; |
| 1686 | } | 1702 | } |
| @@ -1691,7 +1707,7 @@ fn handle_enter_notify(display: *Display, event: *xlib.XCrossingEvent, wm: *Wind | |||
| 1691 | 1707 | ||
| 1692 | if (target_mon != selmon) { | 1708 | if (target_mon != selmon) { |
| 1693 | if (selmon) |sel| { | 1709 | if (selmon) |sel| { |
| 1694 | - unfocus_client(display, sel.sel, true, wm); | 1710 | + unfocus_client(sel.sel, true, wm); |
| 1695 | } | 1711 | } |
| 1696 | monitor_mod.selected_monitor = target_mon; | 1712 | monitor_mod.selected_monitor = target_mon; |
| 1697 | } else if (client == null) { | 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 | const selmon = monitor_mod.selected_monitor orelse return; | 1725 | const selmon = monitor_mod.selected_monitor orelse return; |
| 1710 | const selected = selmon.sel orelse return; | 1726 | const selected = selmon.sel orelse return; |
| 1711 | if (event.window != selected.window) { | 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 | if (!client.never_focus) { | 1734 | if (!client.never_focus) { |
| 1718 | _ = xlib.XSetInputFocus(display.handle, client.window, xlib.RevertToPointerRoot, xlib.CurrentTime); | 1735 | _ = xlib.XSetInputFocus(display.handle, client.window, xlib.RevertToPointerRoot, xlib.CurrentTime); |
| 1719 | _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_active_window, xlib.XA_WINDOW, 32, xlib.PropModeReplace, @ptrCast(&client.window), 1); | 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 | if (event.window != display.root) return; | 1743 | if (event.window != display.root) return; |
| 1726 | 1744 | ||
| 1727 | const target_mon = monitor_mod.rect_to_monitor(event.x_root, event.y_root, 1, 1); | 1745 | const target_mon = monitor_mod.rect_to_monitor(event.x_root, event.y_root, 1, 1); |
| 1728 | if (target_mon != wm.last_motion_monitor and wm.last_motion_monitor != null) { | 1746 | if (target_mon != wm.last_motion_monitor and wm.last_motion_monitor != null) { |
| 1729 | if (monitor_mod.selected_monitor) |selmon| { | 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 | monitor_mod.selected_monitor = target_mon; | 1750 | monitor_mod.selected_monitor = target_mon; |
| 1733 | - focus(display, null, wm); | 1751 | + focus(null, wm); |
| 1734 | } | 1752 | } |
| 1735 | wm.last_motion_monitor = target_mon; | 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 | if (event.state == xlib.PropertyDelete) { | 1758 | if (event.state == xlib.PropertyDelete) { |
| 1740 | return; | 1759 | return; |
| 1741 | } | 1760 | } |
| @@ -1755,18 +1774,19 @@ fn handle_property_notify(display: *Display, event: *xlib.XPropertyEvent, wm: *W | |||
| 1755 | } else if (event.atom == xlib.XA_WM_NORMAL_HINTS) { | 1774 | } else if (event.atom == xlib.XA_WM_NORMAL_HINTS) { |
| 1756 | client.hints_valid = false; | 1775 | client.hints_valid = false; |
| 1757 | } else if (event.atom == xlib.XA_WM_HINTS) { | 1776 | } else if (event.atom == xlib.XA_WM_HINTS) { |
| 1758 | - update_wm_hints(display, client); | 1777 | + update_wm_hints(client, wm); |
| 1759 | wm.invalidate_bars(); | 1778 | wm.invalidate_bars(); |
| 1760 | } else if (event.atom == xlib.XA_WM_NAME or event.atom == wm.atoms.net_wm_name) { | 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 | } else if (event.atom == wm.atoms.net_wm_window_type) { | 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 | const unfocus_target = client orelse return; | 1788 | const unfocus_target = client orelse return; |
| 1769 | - grabbuttons(display, unfocus_target, false, wm); | 1789 | + grabbuttons(unfocus_target, false, wm); |
| 1770 | _ = xlib.XSetWindowBorder(display.handle, unfocus_target.window, wm.config.border_unfocused); | 1790 | _ = xlib.XSetWindowBorder(display.handle, unfocus_target.window, wm.config.border_unfocused); |
| 1771 | if (reset_input_focus) { | 1791 | if (reset_input_focus) { |
| 1772 | _ = xlib.XSetInputFocus(display.handle, display.root, xlib.RevertToPointerRoot, xlib.CurrentTime); | 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 | var data: [2]c_long = .{ state, xlib.None }; | 1799 | var data: [2]c_long = .{ state, xlib.None }; |
| 1779 | _ = xlib.c.XChangeProperty(display.handle, client.window, wm.atoms.wm_state, xlib.XA_ATOM, 32, xlib.PropModeReplace, @ptrCast(&data), 2); | 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 | wm.numlock_mask = 0; | 1805 | wm.numlock_mask = 0; |
| 1784 | const modmap = xlib.XGetModifierMapping(display.handle); | 1806 | const modmap = xlib.XGetModifierMapping(display.handle); |
| 1785 | if (modmap == null) return; | 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 { | 1824 | +fn grabbuttons(client: *Client, focused: bool, wm: *WindowManager) void { |
| 1803 | - update_numlock_mask(display, wm); | 1825 | + const display = &wm.display; |
| 1826 | + update_numlock_mask(wm); | ||
| 1804 | const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask }; | 1827 | const modifiers = [_]c_uint{ 0, xlib.LockMask, wm.numlock_mask, wm.numlock_mask | xlib.LockMask }; |
| 1805 | 1828 | ||
| 1806 | _ = xlib.XUngrabButton(display.handle, xlib.AnyButton, xlib.AnyModifier, client.window); | 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 | const selmon = monitor_mod.selected_monitor orelse return; | 1866 | const selmon = monitor_mod.selected_monitor orelse return; |
| 1843 | 1867 | ||
| 1844 | var focus_client = target_client; | 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 | if (selmon.sel != null and selmon.sel != focus_client) { | 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 | if (focus_client) |client| { | 1881 | if (focus_client) |client| { |
| @@ -1859,17 +1883,17 @@ fn focus(display: *Display, target_client: ?*Client, wm: *WindowManager) void { | |||
| 1859 | monitor_mod.selected_monitor = client.monitor; | 1883 | monitor_mod.selected_monitor = client.monitor; |
| 1860 | } | 1884 | } |
| 1861 | if (client.is_urgent) { | 1885 | if (client.is_urgent) { |
| 1862 | - set_urgent(display, client, false); | 1886 | + set_urgent(client, false, wm); |
| 1863 | } | 1887 | } |
| 1864 | client_mod.detach_stack(client); | 1888 | client_mod.detach_stack(client); |
| 1865 | client_mod.attach_stack(client); | 1889 | client_mod.attach_stack(client); |
| 1866 | - grabbuttons(display, client, true, wm); | 1890 | + grabbuttons(client, true, wm); |
| 1867 | _ = xlib.XSetWindowBorder(display.handle, client.window, wm.config.border_focused); | 1891 | _ = xlib.XSetWindowBorder(display.handle, client.window, wm.config.border_focused); |
| 1868 | if (!client.never_focus) { | 1892 | if (!client.never_focus) { |
| 1869 | _ = xlib.XSetInputFocus(display.handle, client.window, xlib.RevertToPointerRoot, xlib.CurrentTime); | 1893 | _ = xlib.XSetInputFocus(display.handle, client.window, xlib.RevertToPointerRoot, xlib.CurrentTime); |
| 1870 | _ = xlib.XChangeProperty(display.handle, display.root, wm.atoms.net_active_window, xlib.XA_WINDOW, 32, xlib.PropModeReplace, @ptrCast(&client.window), 1); | 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 | } else { | 1897 | } else { |
| 1874 | _ = xlib.XSetInputFocus(display.handle, display.root, xlib.RevertToPointerRoot, xlib.CurrentTime); | 1898 | _ = xlib.XSetInputFocus(display.handle, display.root, xlib.RevertToPointerRoot, xlib.CurrentTime); |
| 1875 | _ = xlib.XDeleteProperty(display.handle, display.root, wm.atoms.net_active_window); | 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 | wm.invalidate_bars(); | 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 | wm.invalidate_bars(); | 1916 | wm.invalidate_bars(); |
| 1892 | const selected_client = monitor.sel orelse return; | 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 | fn arrange(monitor: *Monitor, wm: *WindowManager) void { | 1944 | fn arrange(monitor: *Monitor, wm: *WindowManager) void { |
| 1920 | - showhide(&wm.display, monitor, wm); | 1945 | + showhide(monitor, wm); |
| 1921 | if (monitor.lt[monitor.sel_lt]) |layout| { | 1946 | if (monitor.lt[monitor.sel_lt]) |layout| { |
| 1922 | if (layout.arrange_fn) |arrange_fn| { | 1947 | if (layout.arrange_fn) |arrange_fn| { |
| 1923 | arrange_fn(monitor); | 1948 | arrange_fn(monitor); |
| 1924 | } | 1949 | } |
| 1925 | } | 1950 | } |
| 1926 | - restack(&wm.display, monitor, wm); | 1951 | + restack(monitor, wm); |
| 1927 | } | 1952 | } |
| 1928 | 1953 | ||
| 1929 | fn tick_animations(wm: *WindowManager) void { | 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 | const target = client orelse return; | 2005 | const target = client orelse return; |
| 1980 | if (client_mod.is_visible(target)) { | 2006 | if (client_mod.is_visible(target)) { |
| 1981 | _ = xlib.XMoveWindow(display.handle, target.window, target.x, target.y); | 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 | if ((monitor.lt[monitor.sel_lt] == null or target.is_floating) and !target.is_fullscreen) { | 2009 | if ((monitor.lt[monitor.sel_lt] == null or target.is_floating) and !target.is_fullscreen) { |
| 1984 | tiling.resize(target, target.x, target.y, target.width, target.height, false); | 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 | } else { | 2013 | } else { |
| 1988 | - showhide_client(display, target.stack_next, wm); | 2014 | + showhide_client(target.stack_next, wm); |
| 1989 | const client_width = target.width + 2 * target.border_width; | 2015 | const client_width = target.width + 2 * target.border_width; |
| 1990 | _ = xlib.XMoveWindow(display.handle, target.window, -2 * client_width, target.y); | 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 { | 2020 | +fn showhide(monitor: *Monitor, wm: *WindowManager) void { |
| 1995 | - showhide_client(display, monitor.stack, wm); | 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 | var size_hints: xlib.XSizeHints = undefined; | 2026 | var size_hints: xlib.XSizeHints = undefined; |
| 2000 | var msize: c_long = 0; | 2027 | var msize: c_long = 0; |
| 2001 | 2028 | ||
| @@ -2053,7 +2080,8 @@ fn update_size_hints(display: *Display, client: *Client) void { | |||
| 2053 | client.hints_valid = true; | 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 | const wmh = xlib.XGetWMHints(display.handle, client.window); | 2085 | const wmh = xlib.XGetWMHints(display.handle, client.window); |
| 2058 | if (wmh) |hints| { | 2086 | if (wmh) |hints| { |
| 2059 | defer _ = xlib.XFree(@ptrCast(hints)); | 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 { | 2104 | +fn update_window_type(client: *Client, wm: *WindowManager) void { |
| 2077 | - const state = get_atom_prop(display, client, wm.atoms.net_wm_state); | 2105 | + const state = get_atom_prop(client, wm.atoms.net_wm_state, wm); |
| 2078 | - const window_type = get_atom_prop(display, client, wm.atoms.net_wm_window_type); | 2106 | + const window_type = get_atom_prop(client, wm.atoms.net_wm_window_type, wm); |
| 2079 | 2107 | ||
| 2080 | if (state == wm.atoms.net_wm_state_fullscreen) { | 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 | if (window_type == wm.atoms.net_wm_window_type_dialog) { | 2111 | if (window_type == wm.atoms.net_wm_window_type_dialog) { |
| 2084 | client.is_floating = true; | 2112 | client.is_floating = true; |
| 2085 | } | 2113 | } |
| 2086 | } | 2114 | } |
| 2087 | 2115 | ||
| 2088 | -fn update_title(display: *Display, client: *Client, wm: *WindowManager) void { | 2116 | +fn update_title(client: *Client, wm: *WindowManager) void { |
| 2089 | - if (!get_text_prop(display, client.window, wm.atoms.net_wm_name, &client.name)) { | 2117 | + if (!get_text_prop(client.window, wm.atoms.net_wm_name, &client.name, wm)) { |
| 2090 | - _ = get_text_prop(display, client.window, xlib.XA_WM_NAME, &client.name); | 2118 | + _ = get_text_prop(client.window, xlib.XA_WM_NAME, &client.name, wm); |
| 2091 | } | 2119 | } |
| 2092 | if (client.name[0] == 0) { | 2120 | if (client.name[0] == 0) { |
| 2093 | @memcpy(client.name[0..6], "broken"); | 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 | var actual_type: xlib.Atom = undefined; | 2127 | var actual_type: xlib.Atom = undefined; |
| 2099 | var actual_format: c_int = undefined; | 2128 | var actual_format: c_int = undefined; |
| 2100 | var num_items: c_ulong = undefined; | 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 | return 0; | 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 | var name: xlib.XTextProperty = undefined; | 2143 | var name: xlib.XTextProperty = undefined; |
| 2114 | text[0] = 0; | 2144 | text[0] = 0; |
| 2115 | 2145 | ||
| @@ -2137,7 +2167,8 @@ fn get_text_prop(display: *Display, window: xlib.Window, atom: xlib.Atom, text: | |||
| 2137 | return true; | 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 | var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null }; | 2172 | var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null }; |
| 2142 | _ = xlib.XGetClassHint(display.handle, client.window, &class_hint); | 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 | const monitor_tagset = monitor.tagset[monitor.sel_tags]; | 2221 | const monitor_tagset = monitor.tagset[monitor.sel_tags]; |
| 2191 | const is_tag_focused = (monitor_tagset & client.tags) == client.tags; | 2222 | const is_tag_focused = (monitor_tagset & client.tags) == client.tags; |
| 2192 | if (!is_tag_focused) { | 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 | _ = xlib.XDeleteProperty(display.handle, display.root, wm.atoms.net_client_list); | 2231 | _ = xlib.XDeleteProperty(display.handle, display.root, wm.atoms.net_client_list); |
| 2200 | 2232 | ||
| 2201 | var current_monitor = monitor_mod.monitors; | 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 | var protocols: [*c]xlib.Atom = undefined; | 2246 | var protocols: [*c]xlib.Atom = undefined; |
| 2214 | var num_protocols: c_int = 0; | 2247 | var num_protocols: c_int = 0; |
| 2215 | var exists = false; | 2248 | var exists = false; |
| @@ -2238,7 +2271,8 @@ fn send_event(display: *Display, client: *Client, protocol: xlib.Atom, wm: *Wind | |||
| 2238 | return exists; | 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 | client.is_urgent = urgent; | 2276 | client.is_urgent = urgent; |
| 2243 | const wmh = xlib.XGetWMHints(display.handle, client.window); | 2277 | const wmh = xlib.XGetWMHints(display.handle, client.window); |
| 2244 | if (wmh) |hints| { | 2278 | if (wmh) |hints| { |