// File: /workspace/github_cpp_makefile_star2_O1/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 0x4c65
movq %rdi, %rbx
movabsq $0x100000001, %rax      # imm = 0x100000001
leaq 0x8(%rdi), %r15
leaq 0xd0(%rdi), %rcx
movq %rcx, -0x48(%rbp)
leaq 0x80(%rdi), %rcx
movq %rcx, -0x40(%rbp)
leaq -0x120(%rbp), %r13
leaq -0x38(%rbp), %r14
leaq 0x1(%rax), %rcx
movq %rcx, -0x60(%rbp)
addq $0x2, %rax
movq %rax, -0x58(%rbp)
movq %r15, -0x50(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x552e
testl %eax, %eax
jne 0x4c65
movl -0x120(%rbp), %r12d
movl %r12d, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x4c58
movq %r14, %r15
movzbl -0xcc(%rbp), %esi
movq 0x120(%rbx), %rdi
xorl %edx, %edx
callq 0x30b0
movq %rax, %rdi
callq 0x33b0
movq %rax, %r13
movq %rax, %rdi
leaq 0x3c21(%rip), %rsi      # 0x868e
callq 0x32d0
testl %eax, %eax
je 0x4c42
movq %r13, %rdi
leaq 0x3c0c(%rip), %rsi      # 0x8690
callq 0x32d0
testl %eax, %eax
jne 0x4ac6
cmpl $0x2, %r12d
movl $0x1, %eax
movabsq $0x100000001, %rcx      # imm = 0x100000001
cmoveq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movq %r15, %r14
movq %r15, %rsi
callq 0x5724
movq %r14, %rdi
callq 0x68fe
movq %r13, %rdi
leaq 0x3bf6(%rip), %rsi      # 0x86c6
callq 0x32d0
testl %eax, %eax
jne 0x4b09
cmpl $0x2, %r12d
movl $0x2, %eax
cmoveq -0x60(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movq %r15, %r14
movq %r15, %rsi
callq 0x5724
movq %r14, %rdi
callq 0x68fe
movq %r13, %rdi
leaq 0x3b7f(%rip), %rsi      # 0x8692
callq 0x32d0
testl %eax, %eax
jne 0x4b4c
cmpl $0x2, %r12d
movl $0x3, %eax
cmoveq -0x58(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movq %r15, %r14
movq %r15, %rsi
callq 0x5724
movq %r14, %rdi
callq 0x68fe
movq %r13, %rdi
leaq 0x3b3e(%rip), %rsi      # 0x8694
callq 0x32d0
testl %eax, %eax
jne 0x4b7a
cmpl $0x2, %r12d
movl $0x2, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x58b2
movq %r13, %rdi
leaq 0x3b12(%rip), %rsi      # 0x8696
callq 0x32d0
testl %eax, %eax
jne 0x4ba8
cmpl $0x2, %r12d
movl $0x3, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x58b2
movq %r13, %rdi
leaq 0x3ae6(%rip), %rsi      # 0x8698
callq 0x32d0
testl %eax, %eax
jne 0x4bd6
cmpl $0x2, %r12d
movl $0x0, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x58b2
movq %r13, %rdi
leaq 0x3aba(%rip), %rsi      # 0x869a
callq 0x32d0
testl %eax, %eax
jne 0x4c04
cmpl $0x2, %r12d
movl $0x1, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x58b2
movq %r13, %rdi
leaq 0x3a8e(%rip), %rsi      # 0x869c
callq 0x32d0
testl %eax, %eax
leaq -0x120(%rbp), %r13
movq %r15, %r14
movq -0x50(%rbp), %r15
jne 0x4c58
cmpl $0x2, %r12d
movl $0x7, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x58b2
jmp 0x4c58
movq %rbx, %rdi
callq 0x4c90
leaq -0x120(%rbp), %r13
movq %r15, %r14
movq -0x50(%rbp), %r15
cmpb $0x0, 0x12c(%rbx)
jne 0x4a17
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4c7b
jmp 0x4c7b
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x68fe
movq %rbx, %rdi
callq 0x3380
nop