VirtualBox

Changeset 100216 in vbox


Ignore:
Timestamp:
Jun 19, 2023 5:31:13 PM (22 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157926
Message:

GuestHost: VBGHDisplayServerTypeDetect: Do not rely on environment variables when detecting X11/XWayland/Wayland, bugref:10427.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/DisplayServerType.cpp

    r100214 r100216  
    200200    LogRel2(("Detected via connection: %s\n", VBGHDisplayServerTypeToStr(retSessionType)));
    201201
    202     /* If retSessionType is set, we assume we're done here;
    203      * otherwise try the environment variables as a fallback. */
    204     if (retSessionType != VBGHDISPLAYSERVERTYPE_NONE)
    205         return retSessionType;
    206 
    207     /*
    208      * XDG_SESSION_TYPE is a systemd(1) environment variable and is unlikely
    209      * set in non-systemd environments or remote logins.
    210      * Therefore we check the Wayland specific display environment variable first.
    211      */
    212     VBGHDISPLAYSERVERTYPE waylandDisplayType = VBGHDISPLAYSERVERTYPE_NONE;
    213     const char *const pWaylandDisplayType = RTEnvGet(VBGH_ENV_WAYLAND_DISPLAY);
    214     if (pWaylandDisplayType != NULL)
    215         waylandDisplayType = VBGHDISPLAYSERVERTYPE_PURE_WAYLAND;
    216 
    217     LogRel2(("Wayland display type is: %s\n", VBGHDisplayServerTypeToStr(waylandDisplayType)));
    218 
    219     VBGHDISPLAYSERVERTYPE xdgSessionType = VBGHDISPLAYSERVERTYPE_NONE;
    220     const char *pSessionType = RTEnvGet(VBGH_ENV_XDG_SESSION_TYPE);
    221     if (pSessionType)
    222     {
    223         if (RTStrIStartsWith(pSessionType, "wayland"))
    224             xdgSessionType = VBGHDISPLAYSERVERTYPE_PURE_WAYLAND;
    225         else if (RTStrIStartsWith(pSessionType, "x11"))
    226             xdgSessionType = VBGHDISPLAYSERVERTYPE_X11;
    227     }
    228 
    229     LogRel2(("XDG session type is: %s\n", VBGHDisplayServerTypeToStr(xdgSessionType)));
    230 
    231     VBGHDISPLAYSERVERTYPE xdgCurrentDesktopType = VBGHDISPLAYSERVERTYPE_NONE;
    232 
    233     const char *pszCurDesktop = RTEnvGet(VBGH_ENV_XDG_CURRENT_DESKTOP);
    234     if (pszCurDesktop)
    235     {
    236         if (RTStrIStr(pszCurDesktop, "wayland"))
    237             xdgCurrentDesktopType = VBGHDISPLAYSERVERTYPE_PURE_WAYLAND;
    238         else if (RTStrIStr(pszCurDesktop, "x11"))
    239             xdgCurrentDesktopType = VBGHDISPLAYSERVERTYPE_X11;
    240     }
    241 
    242     LogRel2(("XDG current desktop type is: %s\n", VBGHDisplayServerTypeToStr(xdgCurrentDesktopType)));
    243 
    244     /* Set the returning type according to the precedence. */
    245     if      (waylandDisplayType    != VBGHDISPLAYSERVERTYPE_NONE) retSessionType = waylandDisplayType;
    246     else if (xdgSessionType        != VBGHDISPLAYSERVERTYPE_NONE) retSessionType = xdgSessionType;
    247     else if (xdgCurrentDesktopType != VBGHDISPLAYSERVERTYPE_NONE) retSessionType = xdgCurrentDesktopType;
    248     else                                                    retSessionType = VBGHDISPLAYSERVERTYPE_NONE;
    249 
    250     /* Try to detect any mismatches between the variables above.
    251      * This might indicate a misconfigred / broken system, and we can warn the user then. */
    252 #define COMPARE_SESSION_TYPES(a_Type1, a_Type2) \
    253     if (   (a_Type1 != VBGHDISPLAYSERVERTYPE_NONE) \
    254         && (a_Type2 != VBGHDISPLAYSERVERTYPE_NONE) \
    255         && (a_Type1 != a_Type2)) \
    256         { \
    257             LogRel(("Unable to reliably detect desktop environment:\n")); \
    258             LogRel(("Mismatch between %s (%s) and %s (%s) detected! This might indicate a misconfigured and/or broken system!\n", \
    259                     #a_Type1, VBGHDisplayServerTypeToStr(a_Type1), #a_Type2, VBGHDisplayServerTypeToStr(a_Type2))); \
    260             LogRel(("Use --session-type to override this detection.\n")); \
    261             retSessionType = VBGHDISPLAYSERVERTYPE_NONE; \
    262         }
    263 
    264     COMPARE_SESSION_TYPES(waylandDisplayType, xdgSessionType);
    265     COMPARE_SESSION_TYPES(waylandDisplayType, xdgCurrentDesktopType);
    266     COMPARE_SESSION_TYPES(xdgSessionType, xdgCurrentDesktopType);
    267 
    268 #undef COMPARE_SESSION_TYPES
    269 
    270202    return retSessionType;
    271203}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette