From b7da52ec5711e999963df218d4fad69a8025daeb Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 18 Sep 2020 16:05:14 +0300 Subject: Added build options for X11 Build option to use software rendering if running under X11, and another option to set the position of a window only after the window has been shown. The latter is a workaround for an SDL bug regarding window borders affecting the initial position. --- src/app.c | 10 +++++++++- src/ui/window.c | 11 +++++++++++ src/ui/window.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index 285036cb..84e57ce2 100644 --- a/src/app.c +++ b/src/app.c @@ -547,7 +547,15 @@ iBool forceLineWrap_App(void) { } iBool forceSoftwareRender_App(void) { - return app_.forceSoftwareRender; + if (app_.forceSoftwareRender) { + return iTrue; + } +#if defined (LAGRANGE_ENABLE_X11_SWRENDER) + if (getenv("DISPLAY")) { + return iTrue; + } +#endif + return iFalse; } enum iColorTheme colorTheme_App(void) { diff --git a/src/ui/window.c b/src/ui/window.c index b43e8421..8ebb67a8 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -506,6 +506,7 @@ iBool create_Window_(iWindow *d, iRect rect, uint32_t flags) { void init_Window(iWindow *d, iRect rect) { theWindow_ = d; iZap(d->cursors); + d->initialPos = rect.pos; d->pendingCursor = NULL; d->isDrawFrozen = iTrue; uint32_t flags = 0; @@ -597,6 +598,16 @@ SDL_Renderer *renderer_Window(const iWindow *d) { static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { switch (ev->event) { +#if defined (LAGRANGE_ENABLE_WINDOWPOS_FIX) + case SDL_WINDOWEVENT_EXPOSED: + if (d->initialPos.x >= 0) { + int bx, by; + SDL_GetWindowBordersSize(d->win, &by, &bx, NULL, NULL); + SDL_SetWindowPosition(d->win, d->initialPos.x + bx, d->initialPos.y + by); + d->initialPos = init1_I2(-1); + } + return iFalse; +#endif case SDL_WINDOWEVENT_MOVED: /* No need to do anything. */ return iTrue; diff --git a/src/ui/window.h b/src/ui/window.h index 4aec2fa7..b067d30e 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -34,6 +34,7 @@ iDeclareTypeConstructionArgs(Window, iRect rect) struct Impl_Window { SDL_Window * win; + iInt2 initialPos; iBool isDrawFrozen; /* avoids premature draws while restoring window state */ SDL_Renderer *render; iWidget * root; -- cgit v1.2.3