From 7a531ed272b71dff60a5291123f3e4c7905ba3fb Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Fri, 11 Oct 2024 13:25:28 +0200 Subject: [PATCH] [BOX32] Fixed some issues with X11 and XRandR 32bits wrapping --- src/libtools/my_x11_conv.c | 78 +++++++++++-------- src/libtools/my_x11_conv.h | 2 + src/wrapped32/generated/functions_list.txt | 1 + .../generated/wrappedlibx11types32.h | 1 + src/wrapped32/wrappedlibx11.c | 13 +++- src/wrapped32/wrappedlibx11_private.h | 2 +- src/wrapped32/wrappedlibxrandr.c | 8 +- 7 files changed, 65 insertions(+), 40 deletions(-) diff --git a/src/libtools/my_x11_conv.c b/src/libtools/my_x11_conv.c index 4ff5b4ae..6f8bd50d 100644 --- a/src/libtools/my_x11_conv.c +++ b/src/libtools/my_x11_conv.c @@ -485,12 +485,9 @@ void convert_XErrorEvent_to_64(void* d, void* s) } #define N_DISPLAY 4 -#define N_SCREENS 16 my_XDisplay_t* my32_Displays_64[N_DISPLAY] = {0}; struct my_XFreeFuncs_32 my32_free_funcs_32[N_DISPLAY] = {0}; struct my_XLockPtrs_32 my32_lock_fns_32[N_DISPLAY] = {0}; -my_Screen_32_t my32_screens[N_DISPLAY*N_SCREENS] = {0}; -int n_screeens = 0; my_XDisplay_32_t my32_Displays_32[N_DISPLAY] = {0}; void* getDisplay(void* d) @@ -522,7 +519,9 @@ void convert_Screen_to_32(void* d, void* s) dst->display = to_ptrv(FindDisplay(src->display)); dst->root = to_ulong(src->root); dst->width = src->width; + dst->height = src->height; dst->mwidth = src->mwidth; + dst->mheight = src->mheight; dst->ndepths = src->ndepths; dst->depths = to_ptrv(src->depths); dst->root_depth = src->root_depth; @@ -595,13 +594,10 @@ void* addDisplay(void* d) ret->default_screen = dpy->default_screen; ret->nscreens = dpy->nscreens; if(dpy->screens) { - ret->screens = to_ptrv(&my32_screens[n_screeens]); + my_Screen_32_t* screens = calloc(dpy->nscreens, sizeof(my_Screen_32_t)); + ret->screens = to_ptrv(screens); for(int i=0; inscreens; ++i) { - if(n_screeens==N_DISPLAY*N_SCREENS) { - printf_log(LOG_INFO, "BOX32: Warning, no more libX11 Screen slots!"); - break; - } - convert_Screen_to_32(&my32_screens[n_screeens++], &dpy->screens[i]); + convert_Screen_to_32(screens+i, dpy->screens+i); } } else ret->screens = 0; @@ -645,11 +641,31 @@ void delDisplay(void* d) // crude free of ressources... not perfect if(my32_Displays_64[i]==d) { my32_Displays_64[i] = NULL; + free(from_ptrv(my32_Displays_32[i].screens)); + my32_Displays_32[i].screens = 0; return; } } } +void refreshDisplay(void* dpy) +{ + // update some of the values now that the screen is locked + my_XDisplay_t* src = dpy; + my_XDisplay_32_t* dst = FindDisplay(dpy); + // sync last request + dst->request = src->request; + // sync screens + if(dst->nscreens!=src->nscreens) { + my_Screen_32_t* screens = from_ptrv(dst->screens); + dst->nscreens = src->nscreens; + screens = realloc(screens, dst->nscreens*sizeof(my_Screen_32_t)); + dst->screens = to_ptrv(screens); + for(int i=0; inscreens; ++i) + convert_Screen_to_32(screens+i, src->screens+i); + } +} + void convert_XWMints_to_64(void* d, void* s) { my_XWMHints_t* dst = d; @@ -1069,19 +1085,19 @@ void inplace_XRRScreenResources_shrink(void* s) my_XRRScreenResources_32_t *dst = s; my_XRRScreenResources_t *src = s; // shrinking, so forward... + for(int i=0; incrtc; ++i) + ((XID_32*)src->crtcs)[i] = to_ulong(src->crtcs[i]); + for(int i=0; inoutput; ++i) + ((XID_32*)src->outputs)[i] = to_ulong(src->outputs[i]); + for(int i=0; inmode; ++i) + convert_XRRModeInfo_to_32(&((my_XRRModeInfo_32_t*)src->modes)[i], &src->modes[i]); dst->timestamp = to_ulong(src->timestamp); dst->configTimestamp = to_ulong(src->configTimestamp); dst->ncrtc = src->ncrtc; - for(int i=0; incrtc; ++i) - ((XID_32*)src->crtcs)[i] = to_ulong(src->crtcs[i]); dst->crtcs = to_ptrv(src->crtcs); dst->noutput = src->noutput; - for(int i=0; inoutput; ++i) - ((XID_32*)src->outputs)[i] = to_ulong(src->outputs[i]); dst->outputs = to_ptrv(src->outputs); dst->nmode = src->nmode; - for(int i=0; inoutput; ++i) - convert_XRRModeInfo_to_32(&((my_XRRModeInfo_32_t*)src->modes)[i], &src->modes[i]); dst->modes = to_ptrv(src->modes); } @@ -1095,19 +1111,19 @@ void inplace_XRRScreenResources_enlarge(void* s) int noutput = src->noutput; int ncrtc = src->ncrtc; dst->modes = from_ptrv(src->modes); - for(int i=nmode-1; i>=0; --i) - convert_XRRModeInfo_to_64(&dst->modes[i], &((my_XRRModeInfo_32_t*)dst->modes)[i]); dst->nmode = src->nmode; dst->outputs = from_ptrv(src->outputs); - for(int i=noutput-1; i>=0; --i) - dst->outputs[i] = from_ulong(((XID_32*)dst->outputs)[i]); dst->noutput = src->noutput; dst->crtcs = from_ptrv(src->crtcs); - for(int i=ncrtc-1; i>=0; --i) - dst->crtcs[i] = from_ulong(((XID_32*)dst->crtcs)[i]); dst->ncrtc = src->ncrtc; dst->configTimestamp = to_ulong(src->configTimestamp); dst->timestamp = to_ulong(src->timestamp); + for(int i=nmode-1; i>=0; --i) + convert_XRRModeInfo_to_64(&dst->modes[i], &((my_XRRModeInfo_32_t*)dst->modes)[i]); + for(int i=noutput-1; i>=0; --i) + dst->outputs[i] = from_ulong(((XID_32*)dst->outputs)[i]); + for(int i=ncrtc-1; i>=0; --i) + dst->crtcs[i] = from_ulong(((XID_32*)dst->crtcs)[i]); } void inplace_XRRCrtcInfo_shrink(void* s) @@ -1115,6 +1131,10 @@ void inplace_XRRCrtcInfo_shrink(void* s) if(!s) return; my_XRRCrtcInfo_32_t *dst = s; my_XRRCrtcInfo_t *src = s; + for(int i=0; inoutput; ++i) + ((XID_32*)src->outputs)[i] = to_ulong(src->outputs[i]); + for(int i=0; inpossible; ++i) + ((XID_32*)src->possible)[i] = to_ulong(src->possible[i]); dst->timestamp = to_ulong(src->timestamp); dst->x = src->x; dst->y = src->y; @@ -1122,14 +1142,10 @@ void inplace_XRRCrtcInfo_shrink(void* s) dst->height = src->height; dst->mode = to_ulong(src->mode); dst->rotation = src->rotation; - for(int i=0; inoutput; ++i) - ((XID_32*)src->outputs)[i] = to_ulong(src->outputs[i]); dst->noutput = src->noutput; dst->outputs = to_ptrv(src->outputs); dst->rotations = src->rotations; dst->npossible = src->npossible; - for(int i=0; inpossible; ++i) - ((XID_32*)src->possible)[i] = to_ulong(src->possible[i]); dst->possible = to_ptrv(src->possible); } @@ -1138,6 +1154,12 @@ void inplace_XRROutputInfo_shrink(void* s) if(!s) return; my_XRROutputInfo_32_t *dst = s; my_XRROutputInfo_t *src = s; + for(int i=0; incrtc; ++i) + ((XID_32*)src->crtcs)[i] = to_ulong(src->crtcs[i]); + for(int i=0; inclone; ++i) + ((XID_32*)src->clones)[i] = to_ulong(src->clones[i]); + for(int i=0; inmode; ++i) + ((XID_32*)src->modes)[i] = to_ulong(src->modes[i]); dst->timestamp = to_ulong(src->timestamp); dst->crtc = src->crtc; dst->name = to_ptrv(src->name); @@ -1147,17 +1169,11 @@ void inplace_XRROutputInfo_shrink(void* s) dst->connection = src->connection; dst->subpixel_order = src->subpixel_order; dst->ncrtc = src->ncrtc; - for(int i=0; incrtc; ++i) - ((XID_32*)src->crtcs)[i] = to_ulong(src->crtcs[i]); dst->crtcs = to_ptrv(src->crtcs); dst->nclone = src->nclone; - for(int i=0; inclone; ++i) - ((XID_32*)src->clones)[i] = to_ulong(src->clones[i]); dst->clones = to_ptrv(src->clones); dst->nmode = src->nmode; dst->npreferred = src->npreferred; - for(int i=0; inmode; ++i) - ((XID_32*)src->modes)[i] = to_ulong(src->modes[i]); dst->modes = to_ptrv(src->modes); } diff --git a/src/libtools/my_x11_conv.h b/src/libtools/my_x11_conv.h index 1d758f8a..254c58bb 100644 --- a/src/libtools/my_x11_conv.h +++ b/src/libtools/my_x11_conv.h @@ -20,6 +20,8 @@ void* FindDisplay(void* d); void* getDisplay(void* d); // removed a 32bits Display and associated ressources void delDisplay(void* d); +// refresh the 32bits from the 64bits version +void refreshDisplay(void* dpy); void convert_Screen_to_32(void* d, void* s); diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt index 04d6defb..07bfddb8 100644 --- a/src/wrapped32/generated/functions_list.txt +++ b/src/wrapped32/generated/functions_list.txt @@ -2011,6 +2011,7 @@ wrappedlibx11: - _XInitImageFuncPtrs - iFX: - XCloseDisplay + - XGrabServer - pFp: - XSetErrorHandler - XSetIOErrorHandler diff --git a/src/wrapped32/generated/wrappedlibx11types32.h b/src/wrapped32/generated/wrappedlibx11types32.h index 599a0b42..1c148794 100644 --- a/src/wrapped32/generated/wrappedlibx11types32.h +++ b/src/wrapped32/generated/wrappedlibx11types32.h @@ -73,6 +73,7 @@ typedef uintptr_t (*LFXLiiuuuiupLp_t)(void*, uintptr_t, int32_t, int32_t, uint32 GO(XRefreshKeyboardMapping, iFp_t) \ GO(_XInitImageFuncPtrs, iFp_t) \ GO(XCloseDisplay, iFX_t) \ + GO(XGrabServer, iFX_t) \ GO(XSetErrorHandler, pFp_t) \ GO(XSetIOErrorHandler, pFp_t) \ GO(XGetModifierMapping, pFX_t) \ diff --git a/src/wrapped32/wrappedlibx11.c b/src/wrapped32/wrappedlibx11.c index 463e6cdc..15cf9e25 100644 --- a/src/wrapped32/wrappedlibx11.c +++ b/src/wrapped32/wrappedlibx11.c @@ -2151,10 +2151,15 @@ EXPORT void my32_XLockDisplay(x64emu_t* emu, void* dpy) { my->XLockDisplay(dpy); // update some of the values now that the screen is locked - my_XDisplay_t* src = dpy; - my_XDisplay_32_t* dst = FindDisplay(dpy); - // should do a full sync? - dst->request = src->request; + refreshDisplay(dpy); +} + +EXPORT int my32_XGrabServer(x64emu_t* emu, void* dpy) +{ + int ret = my->XGrabServer(dpy); + // update some of the values now that the server is grabbed + refreshDisplay(dpy); + return ret; } #define CUSTOM_INIT \ diff --git a/src/wrapped32/wrappedlibx11_private.h b/src/wrapped32/wrappedlibx11_private.h index 1aee969f..597e7594 100644 --- a/src/wrapped32/wrappedlibx11_private.h +++ b/src/wrapped32/wrappedlibx11_private.h @@ -428,7 +428,7 @@ GO(XGrabButton, iFXuuLiuiiLL) GO(XGrabKey, iFXiuLiii) GO(XGrabKeyboard, iFXLiiiL) GO(XGrabPointer, iFXLiuiiLLL) -GO(XGrabServer, iFX) +GOM(XGrabServer, iFEX) //DATAB(_XHeadOfDisplayList, 4) //GOM(XHeightMMOfScreen, iFEbpXLiiiiipippLLLiiiil_) //GOM(XHeightOfScreen, iFEbpXLiiiiipippLLLiiiil_) diff --git a/src/wrapped32/wrappedlibxrandr.c b/src/wrapped32/wrappedlibxrandr.c index 727e9113..db80bd9c 100644 --- a/src/wrapped32/wrappedlibxrandr.c +++ b/src/wrapped32/wrappedlibxrandr.c @@ -48,12 +48,12 @@ EXPORT void* my32_XRRGetScreenResourcesCurrent(x64emu_t* emu, void* dpy, XID win EXPORT int my32_XRRSetCrtcConfig(x64emu_t* emu, void* dpy, void* res, XID crtc, unsigned long timestamp, int x, int y, XID mode, uint16_t rotation, XID_32* outputs, int noutputs) { XID outputs_l[noutputs]; - memset(outputs_l, 0, sizeof(outputs_l)); + if(outputs) + for(int i=0; iXRRSetCrtcConfig(dpy, res, crtc, timestamp, x, y, mode, rotation, &outputs_l, noutputs); + int ret = my->XRRSetCrtcConfig(dpy, res, crtc, timestamp, x, y, mode, rotation, outputs?(&outputs_l):NULL, noutputs); inplace_XRRScreenResources_shrink(res); - for(int i=0; i