// File: /workspace/github_cpp_makefile_star2_O2/kazzmir[P]xborder/src/main.cpp
// Function: OptionWindow::handleEvent(_XEvent*, int*)
void handleEvent(XEvent * event, int * glow){
        if (event->xany.window == this->window){
            bool redraw = false;
            switch (event->type){
                case ClientMessage: {
                    Atom wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", false);
                    Atom wm_protocols_atom = XInternAtom(display, "WM_PROTOCOLS", true);

                    if (event->xclient.message_type == wm_protocols_atom &&
                        (Atom) event->xclient.data.l[0] == wm_delete_window){

                        destroy = true;
                        /*
                        XFreeGC(display, graphics);
                        graphics = NULL;
                        XUnmapWindow(display, option_window);
                        XDestroyWindow(display, option_window);
                        option_window = 0;
                        */
                    }
                    break;
                }
                case Expose: {
                    redraw = true;
                    break;
                }
                case MotionNotify: {
                    if (left_button_pressed){
                        int x = event->xmotion.x;
                        int use = (x - glow_line_x) / glow_line_step;
                        if (use < 0){
                            use = 0;
                        }
                        if (use > glow_max_speed){
                            use = glow_max_speed;
                        }
                        *glow = use;
                        glow_value = *glow;
                        redraw = true;
                    }
                    break;
                }
                case ButtonPress: {
                    int x = event->xbutton.x;
                    int y = event->xbutton.y;
                    if (y >= palette_start_y && y < palette_start_y + (palette_y + 1) * palette_size_block &&
                        x >= 0 && x < (palette_x + 1) * palette_size_block){

                        change_background_color(display, xborder_window, get_rgb(x / palette_size_block, (y - palette_start_y) / palette_size_block));
                    } else if (y >= glow_line_y - glow_line_height / 2 &&
                               y <= glow_line_y + glow_line_height / 2 &&
                               x >= glow_line_x &&
                               x <= glow_line_x + glow_line_width){
                        *glow = (x - glow_line_x) / glow_line_step;
                        if (*glow >= glow_max_speed){
                            *glow = glow_max_speed;
                        }
                        glow_value = *glow;
                        left_button_pressed = true;
                        redraw = true;
                    }
                    break;
                }
                case ButtonRelease: {
                    /* FIXME: check for left button */
                    left_button_pressed = false;
                    break;
                }
                case KeyPress: {
                    KeySym sym = XLookupKeysym(&event->xkey, 0);
                    if (sym == XK_BackSpace){
                        redraw = true;
                        if (window_title.length() > 0){
                            window_title = window_title.substr(0, window_title.size() - 1);
                        }
                    } else {
                        char * ascii = XKeysymToString(sym);
                        /* FIXME: handle shift, ctrl-w, ctrl-u */
                        if (ascii != NULL){
                            std::string add;
                            if (std::string(ascii) == "space"){
                                add = " ";
                            } else if (strlen(ascii) == 1){
                                add = ascii;
                            }

                            if (add != ""){
                                window_title += add;
                                redraw = true;
                            }
                        }
                    }
                    XStoreName(display, xborder_window, window_title.c_str());
                    break;
                }
            }

            if (redraw){
                draw(glow);
            }
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq 0x20(%rsi), %rax
cmpq 0x8(%rdi), %rax
jne 0x4f09
movq %rsi, %r15
movq %rdi, %rbx
movl (%rsi), %ecx
leal -0x2(%rcx), %eax
cmpl $0xa, %eax
ja 0x4cd4
movq %rdx, %r14
leaq 0x13f3(%rip), %rcx      # 0x6070
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
xorl %esi, %esi
callq 0x3390
cmpq $0xff08, %rax           # imm = 0xFF08
jne 0x4e2e
movq 0x38(%rbx), %rcx
testq %rcx, %rcx
je 0x4eed
leaq 0x30(%rbx), %r15
decq %rcx
leaq -0x50(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x3300
movq %r15, %rdi
movq %r12, %rsi
callq 0x3350
movq %r12, %rdi
jmp 0x4ee8
cmpl $0x21, %ecx
jne 0x4f09
movq 0x20(%rbx), %rdi
leaq 0x15df(%rip), %rsi      # 0x62c7
xorl %edx, %edx
callq 0x31f0
movq %rax, %r14
movq 0x20(%rbx), %rdi
leaq 0x15db(%rip), %rsi      # 0x62d8
pushq $0x1
popq %rdx
callq 0x31f0
cmpq %rax, 0x28(%r15)
jne 0x4f09
cmpq %r14, 0x38(%r15)
jne 0x4f09
movb $0x1, 0x28(%rbx)
jmp 0x4f09
cmpb $0x1, 0x50(%rbx)
jne 0x4f09
movl 0x40(%r15), %eax
subl 0x5c(%rbx), %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
cmpl $0x64, %ecx
pushq $0x64
popq %rax
cmovll %ecx, %eax
movl %eax, (%r14)
movl %eax, 0x64(%rbx)
jmp 0x4efe
movl 0x40(%r15), %ecx
movl 0x44(%r15), %esi
leal -0x28(%rsi), %edi
cmpl $0x69, %edi
setb %al
cmpl $0x13b, %ecx            # imm = 0x13B
setb %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x4dcf
movq 0x10(%rbx), %r14
movq 0x20(%rbx), %rbx
movw $0xf, %si
movl %ecx, %eax
xorl %edx, %edx
divw %si
movzwl %ax, %esi
movzbl %dil, %eax
movb $0xf, %cl
divb %cl
movzbl %al, %edx
leaq -0x88(%rbp), %r15
movq %r15, %rdi
callq 0x3bd6
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3da2
jmp 0x4f09
movb $0x0, 0x50(%rbx)
jmp 0x4f09
movl 0x54(%rbx), %r8d
movl 0x58(%rbx), %eax
pushq $0x2
popq %rdi
cltd
idivl %edi
movl %r8d, %edx
subl %eax, %edx
cmpl %edx, %esi
setl %dl
addl %r8d, %eax
cmpl %eax, %esi
setg %al
orb %dl, %al
jne 0x4f09
movl 0x5c(%rbx), %eax
movl %ecx, %esi
subl %eax, %esi
jl 0x4f09
addl 0x60(%rbx), %eax
cmpl %eax, %ecx
jg 0x4f09
movl %esi, %eax
cltd
idivl %edi
cmpl $0xc8, %esi
pushq $0x64
popq %rcx
cmovll %eax, %ecx
movl %ecx, (%r14)
movl %ecx, 0x64(%rbx)
movb $0x1, 0x50(%rbx)
jmp 0x4efe
movq %rax, %rdi
callq 0x3550
testq %rax, %rax
je 0x4e8a
movq %rax, %r15
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x70(%rbp), %rdi
leaq -0x29(%rbp), %rdx
movq %r15, %rsi
callq 0x4bf8
leaq 0x14df(%rip), %rsi      # 0x6344
leaq -0x70(%rbp), %r12
movq %r12, %rdi
callq 0x4c33
movl %eax, %r13d
movq %r12, %rdi
callq 0x3130
testb %r13b, %r13b
je 0x4ea9
leaq 0x14f2(%rip), %r15      # 0x637a
jmp 0x4eb7
movq 0x10(%rbx), %rsi
movq 0x20(%rbx), %rdi
movq 0x30(%rbx), %rdx
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3050
movq %r15, %rdi
callq 0x3120
cmpq $0x1, %rax
jne 0x4ec3
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0x3590
leaq 0x1264(%rip), %rsi      # 0x612e
leaq -0x50(%rbp), %rdi
callq 0x5097
testb %al, %al
je 0x4f18
leaq 0x30(%rbx), %rdi
leaq -0x50(%rbp), %rsi
callq 0x35b0
leaq -0x50(%rbp), %rdi
callq 0x3130
movq 0x10(%rbx), %rsi
movq 0x20(%rbx), %rdi
movq 0x30(%rbx), %rdx
callq 0x3050
movq %rbx, %rdi
movq %r14, %rsi
callq 0x50a4
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x3130
movq 0x10(%rbx), %rsi
movq 0x20(%rbx), %rdi
movq 0x30(%rbx), %rdx
callq 0x3050
jmp 0x4f09
jmp 0x4f36
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x3510