From 89b0c96982370eb7fa4c43eb1080163dedcc4b0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= jaakko.keranen@iki.fi
Date: Fri, 28 Apr 2023 14:17:14 +0300
Subject: [PATCH 1/1] Wayland: Disable X11-specific code and features known to
not work
IssueID #575
src/app.c | 19 +++++++--
src/ui/util.c | 115 +++++++++++++++++++++++++++-----------------------
src/x11.c | 14 ++++++
src/x11.h | 1 +
4 files changed, 93 insertions(+), 56 deletions(-)
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)
return iFalse; /* not on Wayland */
+# endif
+#else
+#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)
-#endif
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. */
#endif
+#if defined (LAGRANGE_ENABLE_X11_XLIB)
+# include "x11.h"
+#endif
#include <the_Foundation/math.h>
#include <the_Foundation/path.h>
#include <SDL_timer.h>
@@ -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)
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)
SDL_Rect dispBounds;
SDL_GetDisplayUsableBounds(i, &dispBounds);
displayRect = union_Rect(
displayRect, init_Rect(dispBounds.x, dispBounds.y, dispBounds.w, dispBounds.h));
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 */
/* 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 <X11/Xlib.h>
#include <X11/Xatom.h>
+iBool isXSession_X11(void) {
return iFalse;
+}
void setDarkWindowTheme_SDLWindow(SDL_Window *d, iBool setDark) {
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) {
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 <the_Foundation/defs.h>
#include <SDL_video.h>
+iBool isXSession_X11 (void);
void setDarkWindowTheme_SDLWindow (SDL_Window *, iBool setDark);
void handleCommand_X11 (const char *cmd);
--
2.25.1
text/plain
This content has been proxied by September (3851b).