// File: /workspace/github_c_makefile_star2_O0/comfies[P]custard/src/wm/handlers.c
// Function: handle_window_click
void handle_window_click(xcb_generic_event_t *generic_event) {
    xcb_button_press_event_t *event;
    event = (xcb_button_press_event_t*)generic_event;

    xcb_window_t window_id = event->event;
    log_debug("Window(%08x) clicked", window_id);

    window_t *window;
    if (windows) {
        while ((window = vector_iterator(windows))) {
            // Redirect border window click as necessary
            if (window->parent == window_id) {
                window_id = window->id;
                break;
            }
        }

        reset_vector_iterator(windows);
    }

    if (focused_window == window_id)
        return;

    xcb_window_t previous_window = focused_window;
    focused_window = window_id;

    /* Is the newly focused window managed? */
    if (window_is_managed(focused_window)) {
        window = get_window_by_id(focused_window);
        xcb_ungrab_button(xcb_connection,
            XCB_BUTTON_INDEX_ANY, window_id, XCB_MOD_MASK_ANY);
        raise_window(window->parent);
        decorate(window);
    } else {
        raise_window(window_id);
    }
    focus_window(window_id);

    /* Is the previously focused window managed? */
    if (window_is_managed(previous_window)) {
        window = get_window_by_id(previous_window);
        xcb_grab_button(xcb_connection, 0, previous_window,
            XCB_EVENT_MASK_BUTTON_PRESS,
            XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
            XCB_NONE, XCB_NONE,
            XCB_BUTTON_INDEX_ANY ^ XCB_BUTTON_INDEX_4 ^ XCB_BUTTON_INDEX_5,
            XCB_MOD_MASK_ANY);
        decorate(window);
    }

    apply();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %r9d
movl $0x3, %edi
leaq 0x32d0(%rip), %rsi      # 0xa63e
leaq 0x32db(%rip), %rdx      # 0xa650
movl $0x85, %ecx
leaq 0x32e3(%rip), %r8       # 0xa664
movb $0x0, %al
callq 0x5bf0
leaq 0x6559(%rip), %rax      # 0xd8e8
cmpq $0x0, (%rax)
je 0x73d8
jmp 0x7397
leaq 0x654a(%rip), %rax      # 0xd8e8
movq (%rax), %rdi
callq 0x38c0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x73c9
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x73c7
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x73c9
jmp 0x7397
leaq 0x6518(%rip), %rax      # 0xd8e8
movq (%rax), %rdi
callq 0x3970
leaq 0x6511(%rip), %rax      # 0xd8f0
movl (%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x73eb
jmp 0x74d8
leaq 0x64fe(%rip), %rax      # 0xd8f0
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x14(%rbp), %ecx
leaq 0x64ef(%rip), %rax      # 0xd8f0
movl %ecx, (%rax)
leaq 0x64e6(%rip), %rax      # 0xd8f0
movl (%rax), %edi
callq 0x8050
cmpw $0x0, %ax
je 0x745c
leaq 0x64d2(%rip), %rax      # 0xd8f0
movl (%rax), %edi
callq 0x8090
movq %rax, -0x20(%rbp)
leaq 0x64c8(%rip), %rax      # 0xd8f8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
xorl %esi, %esi
movl $0x8000, %ecx           # imm = 0x8000
callq 0x3510
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x9030
movq -0x20(%rbp), %rdi
callq 0x6430
jmp 0x7464
movl -0x14(%rbp), %edi
callq 0x9030
movl -0x14(%rbp), %edi
callq 0x8f60
movl -0x24(%rbp), %edi
callq 0x8050
cmpw $0x0, %ax
je 0x74d3
movl -0x24(%rbp), %edi
callq 0x8090
movq %rax, -0x20(%rbp)
leaq 0x646b(%rip), %rax      # 0xd8f8
movq (%rax), %rdi
movl -0x24(%rbp), %edx
xorl %esi, %esi
movl $0x4, %ecx
movl $0x1, %r9d
movl %r9d, %r8d
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movl $0x8000, 0x18(%rsp)     # imm = 0x8000
callq 0x3370
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
callq 0x6430
callq 0x8ac0
addq $0x50, %rsp
popq %rbp
retq
nop