Mercurial > mplayer.hg
comparison libvo/x11_common.c @ 36166:a6263abe514f
Handle X events even while waiting for a map event.
author | reimar |
---|---|
date | Thu, 09 May 2013 14:06:17 +0000 |
parents | 9514b53f6f04 |
children | 29fb09ef97b9 |
comparison
equal
deleted
inserted
replaced
36165:9514b53f6f04 | 36166:a6263abe514f |
---|---|
824 return v; | 824 return v; |
825 err: | 825 err: |
826 return 0; | 826 return 0; |
827 } | 827 } |
828 | 828 |
829 int vo_x11_check_events(Display * mydisplay) | 829 static int handle_x11_event(Display *mydisplay, XEvent *event) |
830 { | 830 { |
831 int ret = 0; | |
832 XEvent Event; | |
833 uint8_t buf[16] = {0}; | 831 uint8_t buf[16] = {0}; |
834 KeySym keySym; | 832 KeySym keySym; |
835 static XComposeStatus stat; | 833 static XComposeStatus stat; |
836 static int ctrl_state; | 834 static int ctrl_state; |
837 | |
838 if (vo_mouse_autohide && mouse_waiting_hide && | |
839 (GetTimerMS() - mouse_timer >= 1000)) { | |
840 vo_hidecursor(mydisplay, vo_window); | |
841 mouse_waiting_hide = 0; | |
842 } | |
843 | |
844 if (WinID > 0) | |
845 ret |= check_resize(); | |
846 while (XPending(mydisplay)) | |
847 { | |
848 XNextEvent(mydisplay, &Event); | |
849 #ifdef CONFIG_GUI | 835 #ifdef CONFIG_GUI |
850 if (use_gui) | 836 if (use_gui) |
851 { | 837 { |
852 gui(GUI_HANDLE_X_EVENT, &Event); | 838 gui(GUI_HANDLE_X_EVENT, event); |
853 if (vo_window != Event.xany.window) | 839 if (vo_window != event->xany.window) |
854 continue; | 840 return 0; |
855 } | 841 } |
856 #endif | 842 #endif |
857 switch (Event.type) | 843 switch (event->type) |
858 { | 844 { |
859 case Expose: | 845 case Expose: |
860 ret |= VO_EVENT_EXPOSE; | 846 return VO_EVENT_EXPOSE; |
861 break; | |
862 case ConfigureNotify: | 847 case ConfigureNotify: |
863 if (vo_window == None) | 848 if (vo_window == None) |
864 break; | 849 break; |
865 ret |= check_resize(); | 850 return check_resize(); |
866 break; | |
867 case KeyPress: | 851 case KeyPress: |
868 case KeyRelease: | 852 case KeyRelease: |
869 { | 853 { |
870 int key, utf8; | 854 int key, utf8; |
871 | 855 |
872 #ifdef CONFIG_GUI | 856 #ifdef CONFIG_GUI |
873 if ( use_gui ) { break; } | 857 if ( use_gui ) { break; } |
874 #endif | 858 #endif |
875 | 859 |
876 XLookupString(&Event.xkey, buf, sizeof(buf), &keySym, | 860 XLookupString(&event->xkey, buf, sizeof(buf), &keySym, |
877 &stat); | 861 &stat); |
878 key = | 862 key = |
879 ((keySym & 0xff00) != | 863 ((keySym & 0xff00) != |
880 0 ? ((keySym & 0x00ff) + 256) : (keySym)); | 864 0 ? ((keySym & 0x00ff) + 256) : (keySym)); |
881 utf8 = buf[0] > 0xc0 ? to_utf8(buf) : 0; | 865 utf8 = buf[0] > 0xc0 ? to_utf8(buf) : 0; |
882 if (utf8) key = 0; | 866 if (utf8) key = 0; |
883 if (key == wsLeftCtrl || key == wsRightCtrl) { | 867 if (key == wsLeftCtrl || key == wsRightCtrl) { |
884 ctrl_state = Event.type == KeyPress; | 868 ctrl_state = event->type == KeyPress; |
885 mplayer_put_key(KEY_CTRL | | 869 mplayer_put_key(KEY_CTRL | |
886 (ctrl_state ? MP_KEY_DOWN : 0)); | 870 (ctrl_state ? MP_KEY_DOWN : 0)); |
887 } else if (Event.type == KeyRelease) { | 871 } else if (event->type == KeyRelease) { |
888 break; | 872 break; |
889 } | 873 } |
890 // Attempt to fix if somehow our state got out of | 874 // Attempt to fix if somehow our state got out of |
891 // sync with reality. | 875 // sync with reality. |
892 // This usually happens when a shortcut involving CTRL | 876 // This usually happens when a shortcut involving CTRL |
893 // was used to switch to a different window/workspace. | 877 // was used to switch to a different window/workspace. |
894 if (ctrl_state != !!(Event.xkey.state & 4)) { | 878 if (ctrl_state != !!(event->xkey.state & 4)) { |
895 ctrl_state = !!(Event.xkey.state & 4); | 879 ctrl_state = !!(event->xkey.state & 4); |
896 mplayer_put_key(KEY_CTRL | | 880 mplayer_put_key(KEY_CTRL | |
897 (ctrl_state ? MP_KEY_DOWN : 0)); | 881 (ctrl_state ? MP_KEY_DOWN : 0)); |
898 } | 882 } |
899 if (!vo_x11_putkey_ext(keySym)) { | 883 if (!vo_x11_putkey_ext(keySym)) { |
900 if (utf8) mplayer_put_key(utf8); | 884 if (utf8) mplayer_put_key(utf8); |
901 else vo_x11_putkey(key); | 885 else vo_x11_putkey(key); |
902 } | 886 } |
903 ret |= VO_EVENT_KEYPRESS; | 887 return VO_EVENT_KEYPRESS; |
904 } | 888 } |
905 break; | 889 break; |
906 case MotionNotify: | 890 case MotionNotify: |
907 vo_mouse_movement(Event.xmotion.x, Event.xmotion.y); | 891 vo_mouse_movement(event->xmotion.x, event->xmotion.y); |
908 | 892 |
909 if (vo_mouse_autohide) | 893 if (vo_mouse_autohide) |
910 { | 894 { |
911 vo_showcursor(mydisplay, vo_window); | 895 vo_showcursor(mydisplay, vo_window); |
912 mouse_waiting_hide = 1; | 896 mouse_waiting_hide = 1; |
920 mouse_waiting_hide = 1; | 904 mouse_waiting_hide = 1; |
921 mouse_timer = GetTimerMS(); | 905 mouse_timer = GetTimerMS(); |
922 } | 906 } |
923 #ifdef CONFIG_GUI | 907 #ifdef CONFIG_GUI |
924 // Ignore mouse button 1-3 under GUI. | 908 // Ignore mouse button 1-3 under GUI. |
925 if (use_gui && (Event.xbutton.button >= 1) | 909 if (use_gui && (event->xbutton.button >= 1) |
926 && (Event.xbutton.button <= 3)) | 910 && (event->xbutton.button <= 3)) |
927 break; | 911 break; |
928 #endif | 912 #endif |
929 mplayer_put_key((MOUSE_BTN0 + Event.xbutton.button - | 913 mplayer_put_key((MOUSE_BTN0 + event->xbutton.button - |
930 1) | MP_KEY_DOWN); | 914 1) | MP_KEY_DOWN); |
931 break; | 915 break; |
932 case ButtonRelease: | 916 case ButtonRelease: |
933 if (vo_mouse_autohide) | 917 if (vo_mouse_autohide) |
934 { | 918 { |
936 mouse_waiting_hide = 1; | 920 mouse_waiting_hide = 1; |
937 mouse_timer = GetTimerMS(); | 921 mouse_timer = GetTimerMS(); |
938 } | 922 } |
939 #ifdef CONFIG_GUI | 923 #ifdef CONFIG_GUI |
940 // Ignore mouse button 1-3 under GUI. | 924 // Ignore mouse button 1-3 under GUI. |
941 if (use_gui && (Event.xbutton.button >= 1) | 925 if (use_gui && (event->xbutton.button >= 1) |
942 && (Event.xbutton.button <= 3)) | 926 && (event->xbutton.button <= 3)) |
943 break; | 927 break; |
944 #endif | 928 #endif |
945 mplayer_put_key(MOUSE_BTN0 + Event.xbutton.button - 1); | 929 mplayer_put_key(MOUSE_BTN0 + event->xbutton.button - 1); |
946 break; | 930 break; |
947 case PropertyNotify: | 931 case PropertyNotify: |
948 { | 932 { |
949 char *name = | 933 char *name = |
950 XGetAtomName(mydisplay, Event.xproperty.atom); | 934 XGetAtomName(mydisplay, event->xproperty.atom); |
951 | 935 |
952 if (!name) | 936 if (!name) |
953 break; | 937 break; |
954 | 938 |
955 XFree(name); | 939 XFree(name); |
965 case DestroyNotify: | 949 case DestroyNotify: |
966 mp_msg(MSGT_VO, MSGL_WARN, "Our window was destroyed, exiting\n"); | 950 mp_msg(MSGT_VO, MSGL_WARN, "Our window was destroyed, exiting\n"); |
967 mplayer_put_key(KEY_CLOSE_WIN); | 951 mplayer_put_key(KEY_CLOSE_WIN); |
968 break; | 952 break; |
969 case ClientMessage: | 953 case ClientMessage: |
970 if (Event.xclient.message_type == XAWM_PROTOCOLS && | 954 if (event->xclient.message_type == XAWM_PROTOCOLS && |
971 Event.xclient.data.l[0] == XAWM_DELETE_WINDOW) | 955 event->xclient.data.l[0] == XAWM_DELETE_WINDOW) |
972 mplayer_put_key(KEY_CLOSE_WIN); | 956 mplayer_put_key(KEY_CLOSE_WIN); |
973 break; | 957 break; |
974 } | 958 } |
959 return 0; | |
960 } | |
961 | |
962 int vo_x11_check_events(Display * mydisplay) | |
963 { | |
964 int ret = 0; | |
965 XEvent Event; | |
966 | |
967 if (vo_mouse_autohide && mouse_waiting_hide && | |
968 (GetTimerMS() - mouse_timer >= 1000)) { | |
969 vo_hidecursor(mydisplay, vo_window); | |
970 mouse_waiting_hide = 0; | |
971 } | |
972 | |
973 if (WinID > 0) | |
974 ret |= check_resize(); | |
975 while (XPending(mydisplay)) | |
976 { | |
977 XNextEvent(mydisplay, &Event); | |
978 ret |= handle_x11_event(mydisplay, &Event); | |
975 } | 979 } |
976 return ret; | 980 return ret; |
977 } | 981 } |
978 | 982 |
979 /** | 983 /** |
1174 // map window | 1178 // map window |
1175 XMapWindow(mDisplay, vo_window); | 1179 XMapWindow(mDisplay, vo_window); |
1176 // wait for map | 1180 // wait for map |
1177 do { | 1181 do { |
1178 XNextEvent(mDisplay, &xev); | 1182 XNextEvent(mDisplay, &xev); |
1183 handle_x11_event(mDisplay, &xev); | |
1179 } while (xev.type != MapNotify || xev.xmap.event != vo_window); | 1184 } while (xev.type != MapNotify || xev.xmap.event != vo_window); |
1180 vo_x11_clearwindow(mDisplay, vo_window); | 1185 vo_x11_clearwindow(mDisplay, vo_window); |
1181 vo_x11_selectinput_witherr(mDisplay, vo_window, | 1186 vo_x11_selectinput_witherr(mDisplay, vo_window, |
1182 StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | | 1187 StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | |
1183 ButtonPressMask | ButtonReleaseMask | ExposureMask); | 1188 ButtonPressMask | ButtonReleaseMask | ExposureMask); |