// File: nishalkulkarni[P]fluid-wm/fluid_wm.cpp
// Function: WindowManager::OnMotionNotify(XMotionEvent const&)
void WindowManager::OnMotionNotify(const XMotionEvent& e)
{
    assert(clients_.count(e.window));
    const Window frame = clients_[e.window];
    const Position<int> drag_pos(e.x_root, e.y_root);
    const Vector2D<int> delta = drag_pos - drag_start_pos_;

    if (e.state & Button1Mask) {
        // alt + left button: Move window.
        const Position<int> dest_frame_pos = drag_start_frame_pos_ + delta;
        XMoveWindow(
            display_,
            frame,
            dest_frame_pos.x, dest_frame_pos.y);
    } else if (e.state & Button3Mask) {
        // alt + right button: Resize window.
        // Window dimensions cannot be negative.
        const Vector2D<int> size_delta(
            std::max(delta.x, -drag_start_frame_size_.width),
            std::max(delta.y, -drag_start_frame_size_.height));
        const Size<int> dest_frame_size = drag_start_frame_size_ + size_delta;
        // 1. Resize frame.
        XResizeWindow(
            display_,
            frame,
            dest_frame_size.width, dest_frame_size.height);
        // 2. Resize client window.
        XResizeWindow(
            display_,
            e.window,
            dest_frame_size.width, dest_frame_size.height);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x50(%rbp)
addq $0x10, %rdi
movq -0x10(%rbp), %rsi
addq $0x20, %rsi
callq 0x13200
cmpq $0x0, %rax
je 0x12b01
jmp 0x12b20
leaq 0x532c(%rip), %rdi      # 0x17e34
leaq 0x5100(%rip), %rsi      # 0x17c0f
movl $0x155, %edx            # imm = 0x155
leaq 0x53c9(%rip), %rcx      # 0x17ee4
callq 0x4170
movq -0x50(%rbp), %rdi
addq $0x10, %rdi
movq -0x10(%rbp), %rsi
addq $0x20, %rsi
callq 0x13310
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x48(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %edx
leaq -0x20(%rbp), %rdi
callq 0x62b0
movq -0x50(%rbp), %rsi
addq $0x50, %rsi
leaq -0x20(%rbp), %rdi
callq 0x134d0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x12bac
movq -0x50(%rbp), %rdi
addq $0x58, %rdi
leaq -0x28(%rbp), %rsi
callq 0x13510
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x30(%rbp)
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
callq 0x41f0
jmp 0x12c54
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x12c52
movq -0x50(%rbp), %rcx
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
subl 0x60(%rcx), %eax
movl %eax, -0x3c(%rbp)
leaq -0x3c(%rbp), %rsi
callq 0x13550
movq -0x50(%rbp), %rcx
movl (%rax), %eax
movl %eax, -0x54(%rbp)
leaq -0x28(%rbp), %rdi
addq $0x4, %rdi
xorl %eax, %eax
subl 0x64(%rcx), %eax
movl %eax, -0x40(%rbp)
leaq -0x40(%rbp), %rsi
callq 0x13550
movl -0x54(%rbp), %esi
movl (%rax), %edx
leaq -0x38(%rbp), %rdi
callq 0x13590
movq -0x50(%rbp), %rdi
addq $0x60, %rdi
leaq -0x38(%rbp), %rsi
callq 0x135b0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x48(%rbp)
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x48(%rbp), %edx
movl -0x44(%rbp), %ecx
callq 0x4400
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movl -0x48(%rbp), %edx
movl -0x44(%rbp), %ecx
callq 0x4400
jmp 0x12c54
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)