Skip to content

Commit

Permalink
xshm: fix compatibility with x input
Browse files Browse the repository at this point in the history
  • Loading branch information
phcoder committed May 24, 2020
1 parent cfe68a4 commit c4b4961
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions gfx/drivers/xshm_gfx.c
Expand Up @@ -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;

Expand All @@ -57,41 +56,58 @@ 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);
if (xshm->shmInfo.shmid<0) abort();//seems like an out of memory situation... let's just blow up

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,
Expand All @@ -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;
}
Expand Down

0 comments on commit c4b4961

Please sign in to comment.