// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdi, %rbx
movabsq $0x100000001, %rax      # imm = 0x100000001
leaq 0x8(%rdi), %rcx
movq %rcx, -0x60(%rbp)
leaq 0xd0(%rdi), %rcx
movq %rcx, -0x48(%rbp)
leaq 0x80(%rdi), %rcx
movq %rcx, -0x40(%rbp)
leaq -0x38(%rbp), %r14
leaq 0x1(%rax), %rcx
movq %rcx, -0x58(%rbp)
addq $0x2, %rax
movq %rax, -0x50(%rbp)
cmpb $0x1, 0x12c(%rbx)
jne 0x48d5
movq -0x60(%rbp), %rdi
movq %r14, %r13
leaq -0x120(%rbp), %rsi
callq 0x5170
testl %eax, %eax
jne 0x48d5
movl -0x120(%rbp), %r15d
movl %r15d, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x4695
movzbl -0xcc(%rbp), %esi
movq 0x120(%rbx), %rdi
xorl %edx, %edx
callq 0x30f0
movq %rax, %rdi
callq 0x33c0
movq %rax, %r12
movzbl (%rax), %eax
cmpl $0x66, %eax
je 0x4714
cmpl $0x71, %eax
movq %r13, %r14
jne 0x475b
cmpb $0x0, 0x1(%r12)
jne 0x4695
movq %rbx, %rdi
callq 0x4900
movq %r13, %r14
jmp 0x4695
cmpb $0x0, 0x1(%r12)
movq %r13, %r14
jne 0x4695
cmpl $0x2, %r15d
pushq $0x1
popq %rax
movabsq $0x100000001, %rcx      # imm = 0x100000001
cmoveq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movq %r14, %rsi
callq 0x52bc
movq %r14, %rdi
callq 0x6282
movb (%r12), %al
cmpb $0x64, %al
jne 0x479a
cmpb $0x0, 0x1(%r12)
jne 0x4695
cmpl $0x2, %r15d
pushq $0x2
popq %rax
cmoveq -0x58(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movq %r14, %rsi
callq 0x52bc
movq %r14, %rdi
callq 0x6282
movb (%r12), %al
cmpb $0x73, %al
jne 0x47d9
cmpb $0x0, 0x1(%r12)
jne 0x4695
cmpl $0x2, %r15d
pushq $0x3
popq %rax
cmoveq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movq %r14, %rsi
callq 0x52bc
movq %r14, %rdi
callq 0x6282
movb (%r12), %al
cmpb $0x68, %al
jne 0x480b
cmpb $0x0, 0x1(%r12)
jne 0x4695
cmpl $0x2, %r15d
movl $0x2, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0x5416
movq %r13, %r14
movb (%r12), %al
cmpb $0x6c, %al
jne 0x483d
cmpb $0x0, 0x1(%r12)
jne 0x4695
cmpl $0x2, %r15d
movl $0x3, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0x5416
movq %r13, %r14
movb (%r12), %al
cmpb $0x6b, %al
jne 0x486c
cmpb $0x0, 0x1(%r12)
jne 0x4695
andl $0x0, -0x38(%rbp)
cmpl $0x2, %r15d
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0x5416
movq %r13, %r14
movb (%r12), %al
cmpb $0x6a, %al
jne 0x489e
cmpb $0x0, 0x1(%r12)
jne 0x4695
cmpl $0x2, %r15d
movl $0x1, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0x5416
movq %r13, %r14
movb (%r12), %al
cmpb $0x61, %al
jne 0x4695
cmpb $0x0, 0x1(%r12)
jne 0x4695
cmpl $0x2, %r15d
movl $0x7, -0x38(%rbp)
sete -0x34(%rbp)
movq -0x40(%rbp), %rdi
movq %r13, %rsi
callq 0x5416
movq %r13, %r14
jmp 0x4695
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x48eb
jmp 0x48eb
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x6282
movq %rbx, %rdi
callq 0x33a0
nop