| 641 | XFreeCursor(x11_display, x11_cursor); |
| 642 | } |
| 643 | void input_detection() { |
| 644 | XEvent x11_event; |
| 645 | while(running) { |
| 646 | XNextEvent(x11_display, &x11_event); |
| 647 | if(!x11_cursor_movement_captured&&x11_event.type==MotionNotify) { // to avoid cursor movement being captured before cursor has been centered |
| 648 | camera.input_mouse_moved((int)x11_event.xmotion.x, (int)x11_event.xmotion.y); |
| 649 | x11_cursor_movement_captured = true; |
| 650 | } else if(x11_event.type==ButtonPress) { // counterpart: ButtonRelease |
| 651 | const int x11_button = x11_event.xbutton.button; |
| 652 | if(x11_button==Button4) { // scroll up |
| 653 | camera.input_scroll_up(); |
| 654 | } else if(x11_button==Button5) { // scroll down |
| 655 | camera.input_scroll_down(); |
| 656 | } else if(x11_button==Button1||x11_button==Button2||x11_button==Button3) { |
| 657 | if(!camera.lockmouse) { |
| 658 | show_cursor(); |
| 659 | } else { |
| 660 | hide_cursor(); |
| 661 | XWarpPointer(x11_display, x11_window, x11_window, 0, 0, camera.width, camera.height, (int)camera.width/2, (int)camera.height/2); // reset cursor |
| 662 | } |
| 663 | camera.input_key('U'); |
| 664 | } |
| 665 | } else if(x11_event.type==KeyPress) { |
| 666 | const int key = key_linux((int)x11_event.xkey.keycode); |
| 667 | if(key=='U') { |
| 668 | if(!camera.lockmouse) { |
| 669 | show_cursor(); |
| 670 | } else { |
| 671 | hide_cursor(); |
| 672 | XWarpPointer(x11_display, x11_window, x11_window, 0, 0, camera.width, camera.height, (int)camera.width/2, (int)camera.height/2); // reset cursor |
| 673 | } |
| 674 | } |
| 675 | camera.set_key_state(key, true); |
| 676 | key_bindings(key); |
| 677 | } else if(x11_event.type==KeyRelease) { |
| 678 | const int key = key_linux((int)x11_event.xkey.keycode); |
| 679 | camera.set_key_state(key, false); |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | int main(int argc, char* argv[]) { |
| 684 | main_arguments = get_main_arguments(argc, argv); |
| 685 |
nothing calls this directly
no test coverage detected