|
|
2f772bc |
diff -up allegro-4.4.2/src/x/xwin.c~ allegro-4.4.2/src/x/xwin.c
|
|
|
2f772bc |
--- allegro-4.4.2/src/x/xwin.c~ 2015-06-23 11:04:53.000000000 +0200
|
|
|
2f772bc |
+++ allegro-4.4.2/src/x/xwin.c 2015-06-23 11:09:33.010580738 +0200
|
|
|
2f772bc |
@@ -26,6 +26,7 @@
|
|
|
2f772bc |
#include "xwin.h"
|
|
|
2f772bc |
|
|
|
2f772bc |
#include <string.h>
|
|
|
2f772bc |
+#include <unistd.h>
|
|
|
2f772bc |
#include <X11/Xlib.h>
|
|
|
2f772bc |
#include <X11/Xutil.h>
|
|
|
2f772bc |
#include <X11/cursorfont.h>
|
|
|
2f772bc |
@@ -736,6 +736,8 @@ static void _xwin_private_setup_driver_d
|
|
|
2f772bc |
static BITMAP *_xwin_private_create_screen(GFX_DRIVER *drv, int w, int h,
|
|
|
2f772bc |
int vw, int vh, int depth, int fullscreen)
|
|
|
2f772bc |
{
|
|
|
2f772bc |
+ int i;
|
|
|
2f772bc |
+
|
|
|
2f772bc |
if (_xwin.window == None) {
|
|
|
2f772bc |
ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("No window"));
|
|
|
2f772bc |
return 0;
|
|
|
2f772bc |
@@ -816,8 +818,20 @@ static BITMAP *_xwin_private_create_scre
|
|
|
2f772bc |
XReparentWindow(_xwin.display, _xwin.window, _xwin.fs_window, 0, 0);
|
|
|
2f772bc |
|
|
|
2f772bc |
/* Grab the keyboard and mouse. */
|
|
|
2f772bc |
- if (XGrabKeyboard(_xwin.display, XDefaultRootWindow(_xwin.display), False,
|
|
|
2f772bc |
- GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess) {
|
|
|
2f772bc |
+
|
|
|
2f772bc |
+ /*
|
|
|
2f772bc |
+ * Sometimes the window-manager has grabbed the keyboard while it is
|
|
|
2f772bc |
+ * starting an allegro app, so if grabing fails retry for 2 seconds
|
|
|
2f772bc |
+ * before giving up.
|
|
|
2f772bc |
+ */
|
|
|
2f772bc |
+ for (i = 0; i < 20; i++) {
|
|
|
2f772bc |
+ if (XGrabKeyboard(_xwin.display, XDefaultRootWindow(_xwin.display), False,
|
|
|
2f772bc |
+ GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess)
|
|
|
2f772bc |
+ break;
|
|
|
2f772bc |
+
|
|
|
2f772bc |
+ usleep(100000); /* Sleep 100 ms before retrying */
|
|
|
2f772bc |
+ }
|
|
|
2f772bc |
+ if (i == 20) {
|
|
|
2f772bc |
ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Can not grab keyboard"));
|
|
|
2f772bc |
return 0;
|
|
|
2f772bc |
}
|