// File: /workspace/github_cpp_makefile_star2_O3/blak3mill3r[P]mouser/src/mouser.cpp
// Function: Mouser::xevent_handler()
void Mouser::xevent_handler() {
  XEvent ev;
  while (_running && channel_op_status::success == _xevent_channel.pop(ev) ) {
    switch(ev.type) {
    case KeyPress:
    case KeyRelease:
      bool is_down = (KeyPress == ev.type);
      char *s;
      unsigned int kc;

      kc = ((XKeyPressedEvent*)&ev)->keycode;
      s = XKeysymToString(XKeycodeToKeysym(_d, kc, 0));

      //if(s) printf("KEY: %s\n", s);
      if(!strcmp(s, "q")) { stop(); break; }

      // probably cleaner to make KeyboardActions out of the button presses too...
      if(!strcmp(s, "f"))          _xtest_action_channel.push(CmdButton(1,   is_down));
      if(!strcmp(s, "d"))          _xtest_action_channel.push(CmdButton(2,   is_down));
      if(!strcmp(s, "s"))          _xtest_action_channel.push(CmdButton(3,   is_down));
      if(!strcmp(s, "h"))          _keyboard_action_channel.push(KeyboardAction(k_left,    is_down));
      if(!strcmp(s, "l"))          _keyboard_action_channel.push(KeyboardAction(k_right,   is_down));
      if(!strcmp(s, "k"))          _keyboard_action_channel.push(KeyboardAction(k_up,      is_down));
      if(!strcmp(s, "j"))          _keyboard_action_channel.push(KeyboardAction(k_down,    is_down));
      if(!strcmp(s, "a"))          _keyboard_action_channel.push(KeyboardAction(k_brakes,  is_down));
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
cmpb $0x1, 0x12c(%rdi)
jne 0x4b84
movq %rdi, %rbx
movabsq $0x100000001, %rax      # imm = 0x100000001
leaq 0x8(%rdi), %r14
leaq 0xd0(%rdi), %rcx
movq %rcx, -0x48(%rbp)
leaq 0x80(%rdi), %rcx
movq %rcx, -0x40(%rbp)
leaq -0x118(%rbp), %r13
leaq 0x1(%rax), %rcx
movq %rcx, -0x58(%rbp)
addq $0x2, %rax
movq %rax, -0x50(%rbp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x53ca
testl %eax, %eax
jne 0x4b84
movl -0x118(%rbp), %r15d
movl %r15d, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x4b77
movzbl -0xc4(%rbp), %esi
movq 0x120(%rbx), %rdi
xorl %edx, %edx
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movq %rax, %r12
movzbl (%rax), %eax
cmpl $0x66, %eax
je 0x49ae
cmpl $0x71, %eax
jne 0x49ff
cmpb $0x0, 0x1(%r12)
jne 0x4b77
movq %rbx, %rdi
callq 0x4bae
jmp 0x4b77
cmpb $0x0, 0x1(%r12)
jne 0x4b77
cmpl $0x2, %r15d
movl $0x1, %eax
movabsq $0x100000001, %rcx      # imm = 0x100000001
cmoveq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %r13
movq %r13, %rsi
callq 0x5596
movq %r13, %rdi
callq 0x6758
movb (%r12), %al
leaq -0x118(%rbp), %r13
cmpb $0x64, %al
jne 0x4a4b
cmpb $0x0, 0x1(%r12)
jne 0x4b77
cmpl $0x2, %r15d
movl $0x2, %eax
cmoveq -0x58(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %r13
movq %r13, %rsi
callq 0x5596
movq %r13, %rdi
callq 0x6758
movb (%r12), %al
leaq -0x118(%rbp), %r13
cmpb $0x73, %al
jne 0x4a97
cmpb $0x0, 0x1(%r12)
jne 0x4b77
cmpl $0x2, %r15d
movl $0x3, %eax
cmoveq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %r13
movq %r13, %rsi
callq 0x5596
movq %r13, %rdi
callq 0x6758
movb (%r12), %al
leaq -0x118(%rbp), %r13
cmpb $0x68, %al
jne 0x4ac7
cmpb $0x0, 0x1(%r12)
jne 0x4b77
cmpl $0x2, %r15d
movl $0x2, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x571c
movb (%r12), %al
cmpb $0x6c, %al
jne 0x4af7
cmpb $0x0, 0x1(%r12)
jne 0x4b77
cmpl $0x2, %r15d
movl $0x3, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x571c
movb (%r12), %al
cmpb $0x6b, %al
jne 0x4b23
cmpb $0x0, 0x1(%r12)
jne 0x4b77
cmpl $0x2, %r15d
movl $0x0, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x571c
movb (%r12), %al
cmpb $0x6a, %al
jne 0x4b4f
cmpb $0x0, 0x1(%r12)
jne 0x4b77
cmpl $0x2, %r15d
movl $0x1, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x571c
movb (%r12), %al
cmpb $0x61, %al
jne 0x4b77
cmpb $0x0, 0x1(%r12)
jne 0x4b77
cmpl $0x2, %r15d
movl $0x7, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x571c
cmpb $0x0, 0x12c(%rbx)
jne 0x493f
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4b9a
jmp 0x4b9a
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x6758
movq %rbx, %rdi
callq 0x3370