// File: /workspace/github_cpp_makefile_star2_O2/nishalkulkarni[P]fluid-wm/fluid_wm.cpp
// Function: WindowManager::OnKeyPress(XKeyEvent const&)
void WindowManager::OnKeyPress(const XKeyEvent& e)
{
    if ((e.state & MODKEY) && (e.keycode == XKeysymToKeycode(display_, XK_F4))) {
        // alt + f4: Close window.
        std::cout << "fewnlkewlhntkerjnhtrkjhntkrjnhktrnhj\n\n\n";
        Atom* supported_protocols;
        int num_supported_protocols;
        if (XGetWMProtocols(display_,
                e.window,
                &supported_protocols,
                &num_supported_protocols)
            && (::std::find(supported_protocols,
                    supported_protocols + num_supported_protocols,
                    WM_DELETE_WINDOW)
                != supported_protocols + num_supported_protocols)) {
            std::cout << "Gracefully deleting window " << e.window;

            XEvent msg;
            memset(&msg, 0, sizeof(msg));
            msg.xclient.type = ClientMessage;
            msg.xclient.message_type = WM_PROTOCOLS;
            msg.xclient.window = e.window;
            msg.xclient.format = 32;
            msg.xclient.data.l[0] = WM_DELETE_WINDOW;

            assert(XSendEvent(display_, e.window, false, 0, &msg));
        } else {
            std::cout << "Killing window " << e.window;
            XKillClient(display_, e.window);
        }
    } else if ((e.state & MODKEY) && (e.keycode == XKeysymToKeycode(display_, XK_Tab))) {
        // alt + tab: Switch window.
        auto i = clients_.find(e.window);
        assert(i != clients_.end());
        ++i;
        if (i == clients_.end()) {
            i = clients_.begin();
        }

        XRaiseWindow(display_, i->second);
        XSetInputFocus(display_, i->first, RevertToPointerRoot, CurrentTime);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xd8, %rsp
testb $0x8, 0x50(%rsi)
je 0x72ac
movq %rsi, %r14
movq %rdi, %rbx
movl 0x54(%rsi), %ebp
movq (%rdi), %rdi
movl $0xffc1, %esi           # imm = 0xFFC1
callq 0x2120
movzbl %al, %eax
cmpl %eax, %ebp
jne 0x7213
movq 0x6ead(%rip), %rdi      # 0xdfd8
leaq 0x2057(%rip), %rsi      # 0x9189
callq 0x2200
movq (%rbx), %rdi
movq 0x20(%r14), %rsi
leaq 0x10(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x2250
testl %eax, %eax
je 0x7281
movq 0x10(%rsp), %rdi
movslq 0xc(%rsp), %rax
leaq (%rdi,%rax,8), %rsi
leaq 0x70(%rbx), %rdx
callq 0x7a52
movslq 0xc(%rsp), %rcx
shlq $0x3, %rcx
addq 0x10(%rsp), %rcx
cmpq %rcx, %rax
je 0x7281
movq 0x6e4e(%rip), %rdi      # 0xdfd8
leaq 0x2020(%rip), %rsi      # 0x91b1
callq 0x2200
movq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x2150
leaq 0x18(%rsp), %r15
movl $0xc0, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x2100
movl $0x21, (%r15)
movq 0x68(%rbx), %rax
movq %rax, 0x28(%r15)
movq 0x20(%r14), %rsi
movq %rsi, 0x20(%r15)
movl $0x20, 0x30(%r15)
movq 0x70(%rbx), %rax
movq %rax, 0x38(%r15)
movq (%rbx), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2050
testl %eax, %eax
jne 0x72ac
leaq 0x1fd2(%rip), %rdi      # 0x91cd
leaq 0x1c79(%rip), %rsi      # 0x8e7b
leaq 0x1ff3(%rip), %rcx      # 0x91fc
movl $0x18e, %edx            # imm = 0x18E
callq 0x2140
testb $0x8, 0x50(%r14)
je 0x72ac
movl 0x54(%r14), %ebp
movq (%rbx), %rdi
movl $0xff09, %esi           # imm = 0xFF09
callq 0x2120
movzbl %al, %eax
cmpl %eax, %ebp
jne 0x72ac
leaq 0x10(%rbx), %rdi
addq $0x20, %r14
movq %r14, %rsi
callq 0x7adc
testq %rax, %rax
je 0x72ba
movq (%rax), %r14
testq %r14, %r14
jne 0x7257
movq 0x20(%rbx), %r14
movq (%rbx), %rdi
movq 0x10(%r14), %rsi
callq 0x2270
movq (%rbx), %rdi
movq 0x8(%r14), %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
addq $0xd8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2190
movq 0x6d50(%rip), %rdi      # 0xdfd8
leaq 0x1f9f(%rip), %rsi      # 0x922e
callq 0x2200
movq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x2150
movq (%rbx), %rdi
movq 0x20(%r14), %rsi
callq 0x2410
addq $0xd8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1f7d(%rip), %rdi      # 0x923e
leaq 0x1bb3(%rip), %rsi      # 0x8e7b
leaq 0x1f2d(%rip), %rcx      # 0x91fc
movl $0x196, %edx            # imm = 0x196
callq 0x2140
nop