xshm: fix compatibility with x input

This commit is contained in:
Vladimir Serbinenko 2020-05-24 03:52:13 +02:00
parent cfe68a4c2d
commit c4b4961ed1

View File

@ -32,15 +32,14 @@
#include "../../menu/menu_driver.h"
#endif
#include "../../configuration.h"
#include "../font_driver.h"
#include "../common/x11_common.h"
typedef struct xshm
{
Display* display;
Window wndw;
int width;
int height;
@ -57,20 +56,20 @@ static void *xshm_gfx_init(const video_info_t *video,
XInitThreads();
xshm->display = XOpenDisplay(NULL);
g_x11_dpy = XOpenDisplay(NULL);
#ifdef RARCH_INTERNAL
parent = DefaultRootWindow(xshm->display);
parent = DefaultRootWindow(g_x11_dpy);
#else
parent = video->parent;
#endif
XSetWindowAttributes attributes;
attributes.border_pixel=0;
xshm->wndw = XCreateWindow(xshm->display, parent,
0, 0, video->width, video->height,
0, 24, CopyFromParent, NULL, CWBorderPixel, &attributes);
XSetWindowBackground(xshm->display, xshm->wndw, 0);
XMapWindow(xshm->display, xshm->wndw);
g_x11_win = XCreateWindow(g_x11_dpy, parent,
0, 0, video->width, video->height,
0, 24, CopyFromParent, NULL, CWBorderPixel, &attributes);
XSetWindowBackground(g_x11_dpy, g_x11_win, 0);
XMapWindow(g_x11_dpy, g_x11_win);
xshm->shmInfo.shmid = shmget(IPC_PRIVATE, sizeof(uint32_t) * video->width * video->height,
IPC_CREAT|0600);
@ -78,20 +77,37 @@ static void *xshm_gfx_init(const video_info_t *video,
xshm->shmInfo.shmaddr = (char*)shmat(xshm->shmInfo.shmid, 0, 0);
xshm->shmInfo.readOnly = False;
XShmAttach(xshm->display, &xshm->shmInfo);
XSync(xshm->display, False);//no idea why this is required, but I get weird errors without it
xshm->image = XShmCreateImage(xshm->display, NULL, 24, ZPixmap,
XShmAttach(g_x11_dpy, &xshm->shmInfo);
XSync(g_x11_dpy, False);//no idea why this is required, but I get weird errors without it
xshm->image = XShmCreateImage(g_x11_dpy, NULL, 24, ZPixmap,
xshm->shmInfo.shmaddr, &xshm->shmInfo, video->width, video->height);
xshm->gc = XCreateGC(xshm->display, xshm->wndw, 0, NULL);
xshm->gc = XCreateGC(g_x11_dpy, g_x11_win, 0, NULL);
xshm->width = video->width;
xshm->height = video->height;
if (input) *input = NULL;
if (input_data) *input_data = NULL;
if (!x11_input_ctx_new(true))
goto error;
if (input && input_data)
{
void *xinput = NULL;
settings_t *settings = config_get_ptr();
xinput = input_x.init(settings->arrays.input_joypad_driver);
if (xinput)
{
*input = &input_x;
*input_data = xinput;
}
else
*input = NULL;
}
return xshm;
error:
free (xshm);
return NULL;
}
static bool xshm_gfx_frame(void *data, const void *frame, unsigned width,
@ -110,9 +126,9 @@ static bool xshm_gfx_frame(void *data, const void *frame, unsigned width,
menu_driver_frame(menu_is_alive, video_info);
#endif
XShmPutImage(xshm->display, xshm->wndw, xshm->gc, xshm->image,
XShmPutImage(g_x11_dpy, g_x11_win, xshm->gc, xshm->image,
0, 0, 0, 0, xshm->width, xshm->height, False);
XFlush(xshm->display);
XFlush(g_x11_dpy);
return true;
}