641
708
/* Input device event handling.. */
642
709
if (not_yet_handled)
644
if (!clutter_x11_has_xinput ())
711
device = clutter_device_manager_get_core_device (manager,
712
CLUTTER_POINTER_DEVICE);
714
/* Regular X event */
715
switch (xevent->type)
646
/* Regular X event */
647
switch (xevent->type)
718
switch (xevent->xbutton.button)
649
/* KeyPress / KeyRelease should reside here if XInput
653
switch (xevent->xbutton.button)
659
event->scroll.type = event->type = CLUTTER_SCROLL;
661
if (xevent->xbutton.button == 4)
662
event->scroll.direction = CLUTTER_SCROLL_UP;
663
else if (xevent->xbutton.button == 5)
664
event->scroll.direction = CLUTTER_SCROLL_DOWN;
665
else if (xevent->xbutton.button == 6)
666
event->scroll.direction = CLUTTER_SCROLL_LEFT;
668
event->scroll.direction = CLUTTER_SCROLL_RIGHT;
670
event->scroll.time = xevent->xbutton.time;
671
event->scroll.x = xevent->xbutton.x;
672
event->scroll.y = xevent->xbutton.y;
673
event->scroll.modifier_state = xevent->xbutton.state;
677
event->button.type = event->type = CLUTTER_BUTTON_PRESS;
678
event->button.time = xevent->xbutton.time;
679
event->button.x = xevent->xbutton.x;
680
event->button.y = xevent->xbutton.y;
681
event->button.modifier_state = xevent->xbutton.state;
682
event->button.button = xevent->xbutton.button;
687
set_user_time (backend_x11, &xwindow, event->button.time);
724
event->scroll.type = event->type = CLUTTER_SCROLL;
726
if (xevent->xbutton.button == 4)
727
event->scroll.direction = CLUTTER_SCROLL_UP;
728
else if (xevent->xbutton.button == 5)
729
event->scroll.direction = CLUTTER_SCROLL_DOWN;
730
else if (xevent->xbutton.button == 6)
731
event->scroll.direction = CLUTTER_SCROLL_LEFT;
733
event->scroll.direction = CLUTTER_SCROLL_RIGHT;
735
event->scroll.time = xevent->xbutton.time;
736
event->scroll.x = xevent->xbutton.x;
737
event->scroll.y = xevent->xbutton.y;
738
event->scroll.modifier_state = xevent->xbutton.state;
739
event->scroll.device = device;
691
/* scroll events don't have a corresponding release */
692
if (xevent->xbutton.button == 4 ||
693
xevent->xbutton.button == 5 ||
694
xevent->xbutton.button == 6 ||
695
xevent->xbutton.button == 7)
701
event->button.type = event->type = CLUTTER_BUTTON_RELEASE;
743
event->button.type = event->type = CLUTTER_BUTTON_PRESS;
702
744
event->button.time = xevent->xbutton.time;
703
745
event->button.x = xevent->xbutton.x;
704
746
event->button.y = xevent->xbutton.y;
705
747
event->button.modifier_state = xevent->xbutton.state;
706
748
event->button.button = xevent->xbutton.button;
710
event->motion.type = event->type = CLUTTER_MOTION;
711
event->motion.time = xevent->xmotion.time;
712
event->motion.x = xevent->xmotion.x;
713
event->motion.y = xevent->xmotion.y;
714
event->motion.modifier_state = xevent->xmotion.state;
718
/* Convert enter notifies to motion events because X
719
doesn't emit the corresponding motion notify */
720
event->motion.type = event->type = CLUTTER_MOTION;
721
event->motion.time = xevent->xcrossing.time;
722
event->motion.x = xevent->xcrossing.x;
723
event->motion.y = xevent->xcrossing.y;
724
event->motion.modifier_state = xevent->xcrossing.state;
728
event->crossing.type = event->type = CLUTTER_LEAVE;
729
event->crossing.time = xevent->xcrossing.time;
730
event->crossing.x = xevent->xcrossing.x;
731
event->crossing.y = xevent->xcrossing.y;
735
/* ignore every other event */
749
event->button.device = device;
753
set_user_time (backend_x11, &xwindow, event->button.time);
759
/* scroll events don't have a corresponding release */
760
if (xevent->xbutton.button == 4 ||
761
xevent->xbutton.button == 5 ||
762
xevent->xbutton.button == 6 ||
763
xevent->xbutton.button == 7)
769
event->button.type = event->type = CLUTTER_BUTTON_RELEASE;
770
event->button.time = xevent->xbutton.time;
771
event->button.x = xevent->xbutton.x;
772
event->button.y = xevent->xbutton.y;
773
event->button.modifier_state = xevent->xbutton.state;
774
event->button.button = xevent->xbutton.button;
775
event->button.device = device;
781
event->motion.type = event->type = CLUTTER_MOTION;
782
event->motion.time = xevent->xmotion.time;
783
event->motion.x = xevent->xmotion.x;
784
event->motion.y = xevent->xmotion.y;
785
event->motion.modifier_state = xevent->xmotion.state;
786
event->motion.device = device;
792
/* we know that we are entering the stage here */
793
_clutter_input_device_set_stage (device, stage);
794
CLUTTER_NOTE (EVENT, "Entering the stage");
796
/* Convert enter notifies to motion events because X
797
doesn't emit the corresponding motion notify */
798
event->motion.type = event->type = CLUTTER_MOTION;
799
event->motion.time = xevent->xcrossing.time;
800
event->motion.x = xevent->xcrossing.x;
801
event->motion.y = xevent->xcrossing.y;
802
event->motion.modifier_state = xevent->xcrossing.state;
803
event->motion.source = CLUTTER_ACTOR (stage);
804
event->motion.device = device;
810
if (device->stage == NULL)
813
"Discarding LeaveNotify for ButtonRelease "
819
/* we know that we are leaving the stage here */
820
_clutter_input_device_set_stage (device, NULL);
821
CLUTTER_NOTE (EVENT, "Leaving the stage (time:%u)",
822
event->crossing.time);
824
event->crossing.type = event->type = CLUTTER_LEAVE;
825
event->crossing.time = xevent->xcrossing.time;
826
event->crossing.x = xevent->xcrossing.x;
827
event->crossing.y = xevent->xcrossing.y;
828
event->crossing.source = CLUTTER_ACTOR (stage);
829
event->crossing.device = device;
741
{ /* XInput fun.. Needs clean up. */
840
if (!res && clutter_x11_has_xinput ())
742
842
#ifdef HAVE_XINPUT
743
int *ev_types = backend_x11->event_types;
745
CLUTTER_NOTE (EVENT, "XInput event type: %d", xevent->type);
747
if (xevent->type == ev_types [CLUTTER_X11_XINPUT_BUTTON_PRESS_EVENT])
749
XDeviceButtonEvent *xbev = (XDeviceButtonEvent *) xevent;
751
CLUTTER_NOTE (EVENT, "XINPUT Button press event for %li at %d, %d",
756
switch (xbev->button)
762
event->scroll.type = event->type = CLUTTER_SCROLL;
764
if (xbev->button == 4)
765
event->scroll.direction = CLUTTER_SCROLL_UP;
766
else if (xbev->button == 5)
767
event->scroll.direction = CLUTTER_SCROLL_DOWN;
768
else if (xbev->button == 6)
769
event->scroll.direction = CLUTTER_SCROLL_LEFT;
771
event->scroll.direction = CLUTTER_SCROLL_RIGHT;
773
event->scroll.time = xbev->time;
774
event->scroll.x = xbev->x;
775
event->scroll.y = xbev->y;
776
event->scroll.modifier_state = xbev->state;
777
event->scroll.device = _clutter_x11_get_device_for_xid (xbev->deviceid);
781
event->button.type = event->type = CLUTTER_BUTTON_PRESS;
782
event->button.time = xbev->time;
783
event->button.x = xbev->x;
784
event->button.y = xbev->y;
785
event->button.modifier_state = xbev->state;
786
event->button.button = xbev->button;
787
event->button.device = _clutter_x11_get_device_for_xid (xbev->deviceid);
791
set_user_time (backend_x11, &xwindow, xbev->time);
793
else if (xevent->type
794
== ev_types[CLUTTER_X11_XINPUT_BUTTON_RELEASE_EVENT])
796
XDeviceButtonEvent *xbev = (XDeviceButtonEvent *)xevent;
798
CLUTTER_NOTE (EVENT, "XINPUT Button release event for %li at %d, %d",
803
/* scroll events don't have a corresponding release */
804
if (xbev->button == 4 ||
812
event->button.type = event->type = CLUTTER_BUTTON_RELEASE;
843
int *ev_types = backend_x11->event_types;
844
int button_press, button_release;
845
int key_press, key_release;
848
button_press = ev_types[CLUTTER_X11_XINPUT_BUTTON_PRESS_EVENT];
849
button_release = ev_types[CLUTTER_X11_XINPUT_BUTTON_RELEASE_EVENT];
850
motion_notify = ev_types[CLUTTER_X11_XINPUT_MOTION_NOTIFY_EVENT];
851
key_press = ev_types[CLUTTER_X11_XINPUT_KEY_PRESS_EVENT];
852
key_release = ev_types[CLUTTER_X11_XINPUT_KEY_RELEASE_EVENT];
854
CLUTTER_NOTE (EVENT, "XInput event type: %d", xevent->type);
856
if (xevent->type == button_press)
858
XDeviceButtonEvent *xbev = (XDeviceButtonEvent *) xevent;
860
device = _clutter_x11_get_device_for_xid (xbev->deviceid);
861
_clutter_input_device_set_stage (device, stage);
864
"XI ButtonPress for %li ('%s') at %d, %d",
870
switch (xbev->button)
876
event->scroll.type = event->type = CLUTTER_SCROLL;
878
if (xbev->button == 4)
879
event->scroll.direction = CLUTTER_SCROLL_UP;
880
else if (xbev->button == 5)
881
event->scroll.direction = CLUTTER_SCROLL_DOWN;
882
else if (xbev->button == 6)
883
event->scroll.direction = CLUTTER_SCROLL_LEFT;
885
event->scroll.direction = CLUTTER_SCROLL_RIGHT;
887
event->scroll.time = xbev->time;
888
event->scroll.x = xbev->x;
889
event->scroll.y = xbev->y;
890
event->scroll.modifier_state = xbev->state;
891
event->scroll.device = device;
895
event->button.type = event->type = CLUTTER_BUTTON_PRESS;
813
896
event->button.time = xbev->time;
814
897
event->button.x = xbev->x;
815
898
event->button.y = xbev->y;
816
899
event->button.modifier_state = xbev->state;
817
900
event->button.button = xbev->button;
818
event->button.device = _clutter_x11_get_device_for_xid (xbev->deviceid);
820
else if (xevent->type
821
== ev_types [CLUTTER_X11_XINPUT_MOTION_NOTIFY_EVENT])
823
XDeviceMotionEvent *xmev = (XDeviceMotionEvent *)xevent;
825
CLUTTER_NOTE(EVENT, "XINPUT Motion event for %li at %d, %d",
830
event->motion.type = event->type = CLUTTER_MOTION;
831
event->motion.time = xmev->time;
832
event->motion.x = xmev->x;
833
event->motion.y = xmev->y;
834
event->motion.modifier_state = xmev->state;
835
event->motion.device = _clutter_x11_get_device_for_xid (xmev->deviceid);
838
/* the Xinput handling of key presses/releases disabled for now since
839
* it makes keyrepeat, and key presses and releases outside the window
840
* not generate events even when the window has focus
843
else if (xevent->type
844
== ev_types [CLUTTER_X11_XINPUT_KEY_PRESS_EVENT])
846
XEvent xevent_converted;
847
XDeviceKeyEvent *xkev = (XDeviceKeyEvent *)xevent;
849
convert_xdevicekey_to_xkey (xkev, &xevent_converted);
851
event->key.type = event->type = CLUTTER_KEY_PRESS;
852
translate_key_event (backend, event, &xevent_converted);
854
set_user_time (backend_x11, &xwindow, xkev->time);
856
else if (xevent->type
857
== ev_types [CLUTTER_X11_XINPUT_KEY_RELEASE_EVENT])
859
XEvent xevent_converted;
860
XDeviceKeyEvent *xkev = (XDeviceKeyEvent *)xevent;
862
convert_xdevicekey_to_xkey (xkev, &xevent_converted);
864
event->key.type = event->type = CLUTTER_KEY_RELEASE;
865
translate_key_event (backend, event, &xevent_converted);
901
event->button.device = device;
905
set_user_time (backend_x11, &xwindow, xbev->time);
909
else if (xevent->type == button_release)
911
XDeviceButtonEvent *xbev = (XDeviceButtonEvent *)xevent;
913
device = _clutter_x11_get_device_for_xid (xbev->deviceid);
914
_clutter_input_device_set_stage (device, stage);
916
CLUTTER_NOTE (EVENT, "XI ButtonRelease for %li ('%s') at %d, %d",
922
/* scroll events don't have a corresponding release */
923
if (xbev->button == 4 ||
932
event->button.type = event->type = CLUTTER_BUTTON_RELEASE;
933
event->button.time = xbev->time;
934
event->button.x = xbev->x;
935
event->button.y = xbev->y;
936
event->button.modifier_state = xbev->state;
937
event->button.button = xbev->button;
938
event->button.device = device;
942
else if (xevent->type == motion_notify)
944
XDeviceMotionEvent *xmev = (XDeviceMotionEvent *)xevent;
946
device = _clutter_x11_get_device_for_xid (xmev->deviceid);
947
_clutter_input_device_set_stage (device, stage);
949
CLUTTER_NOTE (EVENT, "XI Motion for %li ('%s') at %d, %d",
955
event->motion.type = event->type = CLUTTER_MOTION;
956
event->motion.time = xmev->time;
957
event->motion.x = xmev->x;
958
event->motion.y = xmev->y;
959
event->motion.modifier_state = xmev->state;
960
event->motion.device = device;
964
else if (xevent->type == key_press || xevent->type == key_release)
966
/* the XInput 1.x handling of key presses/releases is broken:
967
* it makes key repeat, key presses and releases outside the
968
* window not generate events even when the window has focus
970
XDeviceKeyEvent *xkev = (XDeviceKeyEvent *) xevent;
971
XEvent xevent_converted;
973
convert_xdevicekey_to_xkey (xkev, &xevent_converted);
975
event->key.type = event->type = (xevent->type == key_press)
977
: CLUTTER_KEY_RELEASE;
979
translate_key_event (backend, event, &xevent_converted);
981
if (xevent->type == key_press)
982
set_user_time (backend_x11, &xwindow, xkev->time);
869
985
#endif /* HAVE_XINPUT */
871
CLUTTER_NOTE (EVENT, "Uknown Event");
987
CLUTTER_NOTE (EVENT, "Uknown Event");