Lagrange [work/v1.7]

Wayland: Disable X11-specific code and features known to not work

=> 89b0c96982370eb7fa4c43eb1080163dedcc4b0a

diff --git a/src/app.c b/src/app.c
index 5abfdb4e..63c32e8a 100644
--- a/src/app.c
+++ b/src/app.c
@@ -2243,6 +2243,19 @@ static int resizeWatcher_(void *user, SDL_Event *event) {
     return 0;
 }
 
+iLocalDef iBool isResizeDrawEnabled_(void) {
+#if defined (LAGRANGE_ENABLE_RESIZE_DRAW)
+#   if defined (LAGRANGE_ENABLE_X11_XLIB)
+    if (!isXSession_X11()) {
+        return iFalse; /* not on Wayland */
+    }
+#   endif
+    return iTrue;
+#else
+    return iFalse;
+#endif    
+}
+
 static int run_App_(iApp *d) {
     /* Initial arrangement. */
     iForIndices(i, d->window->roots) {
@@ -2252,9 +2265,9 @@ static int run_App_(iApp *d) {
     }
     d->isRunning = iTrue;
     SDL_EventState(SDL_DROPFILE, SDL_ENABLE); /* open files via drag'n'drop */
-#if defined (LAGRANGE_ENABLE_RESIZE_DRAW)
-    SDL_AddEventWatch(resizeWatcher_, d); /* redraw window during resizing */
-#endif
+    if (isResizeDrawEnabled_()) {
+        SDL_AddEventWatch(resizeWatcher_, d); /* redraw window during resizing */
+    }
     while (d->isRunning) {
         processEvents_App(waitForNewEvents_AppEventMode);
         runTickers_App_(d);
diff --git a/src/ui/util.c b/src/ui/util.c
index 296aedba..21e9d490 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -51,6 +51,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 #   include "macos.h"
 #endif
 
+#if defined (LAGRANGE_ENABLE_X11_XLIB)
+#   include "x11.h"
+#endif
+
 #include 
 #include 
 #include 
@@ -1220,6 +1224,11 @@ void unselectAllNativeMenuItems_Widget(iWidget *menu) {
 
 iLocalDef iBool isUsingMenuPopupWindows_(void) {
 #if defined (LAGRANGE_ENABLE_POPUP_MENUS) && !defined (iPlatformTerminal)
+#   if defined (LAGRANGE_ENABLE_X11_XLIB)
+    if (!isXSession_X11()) {
+        return iFalse; /* popup windows not supported on Wayland */
+    }
+#   endif
     return deviceType_App() == desktop_AppDeviceType;
 #else
     return iFalse;
@@ -1268,64 +1277,64 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) {
             }
         }
     }
-#if defined (LAGRANGE_ENABLE_POPUP_MENUS) && !defined (iPlatformTerminal)
-    /* Determine total display bounds where the popup may appear. */
-    iRect displayRect = zero_Rect(); 
-    for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
-        SDL_Rect dispBounds;
-        SDL_GetDisplayUsableBounds(i, &dispBounds);
-        displayRect = union_Rect(
-            displayRect, init_Rect(dispBounds.x, dispBounds.y, dispBounds.w, dispBounds.h));
-    }
-    iRect winRect;
-    SDL_Window *sdlWin = get_Window()->win;
-    const float pixelRatio = get_Window()->pixelRatio;
-    iInt2 winPos;
-    SDL_GetWindowPosition(sdlWin, &winPos.x, &winPos.y);
-    winRect = rootRect;
-    winRect.pos.x /= pixelRatio;
-    winRect.pos.y /= pixelRatio;
-    winRect.size.x /= pixelRatio;
-    winRect.size.y /= pixelRatio;
-    addv_I2(&winRect.pos, winPos);
-    iRect visibleWinRect = intersect_Rect(winRect, displayRect);
-    /* Only use a popup window if the menu can't fit inside the main window. */
-    if (height_Widget(d) / pixelRatio > visibleWinRect.size.y && isUsingMenuPopupWindows_()) {
-        if (postCommands) {
-            postCommand_Widget(d, "menu.opened");
-        }
-        updateMenuItemFonts_Widget_(d);
-        iRoot *oldRoot = current_Root();
-        setFlags_Widget(d, keepOnTop_WidgetFlag, iFalse);
-        setUserData_Object(d, parent_Widget(d));
-        iAssert(userData_Object(d));
-        removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */
+    if (isUsingMenuPopupWindows_()) {
+        /* Determine total display bounds where the popup may appear. */
+        iRect displayRect = zero_Rect(); 
+        for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
+            SDL_Rect dispBounds;
+            SDL_GetDisplayUsableBounds(i, &dispBounds);
+            displayRect = union_Rect(
+                displayRect, init_Rect(dispBounds.x, dispBounds.y, dispBounds.w, dispBounds.h));
+        }
+        iRect winRect;
+        SDL_Window *sdlWin = get_Window()->win;
+        const float pixelRatio = get_Window()->pixelRatio;
         iInt2 winPos;
         SDL_GetWindowPosition(sdlWin, &winPos.x, &winPos.y);
-        iInt2 menuPos = add_I2(winPos,
-                               divf_I2(sub_I2(windowCoord, divi_I2(gap2_UI, 2)), pixelRatio));
-        /* Check display bounds. */ {
-            iInt2 menuSize = divf_I2(d->rect.size, pixelRatio);
-            if (menuOpenFlags & center_MenuOpenFlags) {
-                iInt2 winSize;
-                SDL_GetWindowSize(sdlWin, &winSize.x, &winSize.y);
-                menuPos = sub_I2(add_I2(winPos, divi_I2(winSize, 2)), divi_I2(menuSize, 2));
+        winRect = rootRect;
+        winRect.pos.x /= pixelRatio;
+        winRect.pos.y /= pixelRatio;
+        winRect.size.x /= pixelRatio;
+        winRect.size.y /= pixelRatio;
+        addv_I2(&winRect.pos, winPos);
+        iRect visibleWinRect = intersect_Rect(winRect, displayRect);
+        /* Only use a popup window if the menu can't fit inside the main window. */
+        if (height_Widget(d) / pixelRatio > visibleWinRect.size.y && isUsingMenuPopupWindows_()) {
+            if (postCommands) {
+                postCommand_Widget(d, "menu.opened");
             }
-            menuPos.x = iMin(menuPos.x, right_Rect(displayRect) - menuSize.x);
-            menuPos.y = iMax(0, iMin(menuPos.y, bottom_Rect(displayRect) - menuSize.y));
+            updateMenuItemFonts_Widget_(d);
+            iRoot *oldRoot = current_Root();
+            setFlags_Widget(d, keepOnTop_WidgetFlag, iFalse);
+            setUserData_Object(d, parent_Widget(d));
+            iAssert(userData_Object(d));
+            removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */
+            iInt2 winPos;
+            SDL_GetWindowPosition(sdlWin, &winPos.x, &winPos.y);
+            iInt2 menuPos = add_I2(winPos,
+                                   divf_I2(sub_I2(windowCoord, divi_I2(gap2_UI, 2)), pixelRatio));
+            /* Check display bounds. */ {
+                iInt2 menuSize = divf_I2(d->rect.size, pixelRatio);
+                if (menuOpenFlags & center_MenuOpenFlags) {
+                    iInt2 winSize;
+                    SDL_GetWindowSize(sdlWin, &winSize.x, &winSize.y);
+                    menuPos = sub_I2(add_I2(winPos, divi_I2(winSize, 2)), divi_I2(menuSize, 2));
+                }
+                menuPos.x = iMin(menuPos.x, right_Rect(displayRect) - menuSize.x);
+                menuPos.y = iMax(0, iMin(menuPos.y, bottom_Rect(displayRect) - menuSize.y));
+            }
+            iWindow *win = newPopup_Window(menuPos, d); /* window takes the widget */
+            setCurrent_Window(win);
+            SDL_SetWindowTitle(win->win, "Menu");
+            arrange_Widget(d);
+            addPopup_App(win);
+            SDL_ShowWindow(win->win);
+            draw_Window(win);
+            setCurrent_Window(mainWindow_App());
+            setCurrent_Root(oldRoot);
+            return;
         }
-        iWindow *win = newPopup_Window(menuPos, d); /* window takes the widget */
-        setCurrent_Window(win);
-        SDL_SetWindowTitle(win->win, "Menu");
-        arrange_Widget(d);
-        addPopup_App(win);
-        SDL_ShowWindow(win->win);
-        draw_Window(win);
-        setCurrent_Window(mainWindow_App());
-        setCurrent_Root(oldRoot);
-        return;
     }
-#endif
     raise_Widget(d);
     if (deviceType_App() != desktop_AppDeviceType) {
         setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, 
diff --git a/src/x11.c b/src/x11.c
index 40878c30..94f6701a 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -30,7 +30,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 #include 
 #include 
 
+iBool isXSession_X11(void) {
+    const char *driver = SDL_GetCurrentVideoDriver();
+    if (driver && !iCmpStr(driver, "wayland")) {
+        return iFalse;
+    }
+    return iTrue; /* assume yes if this source file is being used */
+}
+
 void setDarkWindowTheme_SDLWindow(SDL_Window *d, iBool setDark) {
+    if (!isXSession_X11()) {
+        return;
+    }
     SDL_SysWMinfo wmInfo;
     SDL_VERSION(&wmInfo.version);
     if (SDL_GetWindowWMInfo(d, &wmInfo)) {
@@ -45,6 +56,9 @@ void setDarkWindowTheme_SDLWindow(SDL_Window *d, iBool setDark) {
 }
 
 void handleCommand_X11(const char *cmd) {
+    if (!isXSession_X11()) {
+        return;
+    }
     if (equal_Command(cmd, "theme.changed")) {        
         iConstForEach(PtrArray, iter, mainWindows_App()) {
             iMainWindow *mw = iter.ptr;
diff --git a/src/x11.h b/src/x11.h
index 2eb195ad..c25a212a 100644
--- a/src/x11.h
+++ b/src/x11.h
@@ -25,6 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 #include 
 #include 
 
+iBool   isXSession_X11                  (void);
 void    setDarkWindowTheme_SDLWindow    (SDL_Window *, iBool setDark);
 void    handleCommand_X11               (const char *cmd);
 
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.7/cdiff/89b0c96982370eb7fa4c43eb1080163dedcc4b0a
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
74.485891 milliseconds
Gemini-to-HTML Time
0.466317 milliseconds

This content has been proxied by September (ba2dc).