VirtualBox

Ignore:
Timestamp:
Jul 24, 2014 8:15:59 PM (10 years ago)
Author:
vboxsync
Message:

Additions/x11/VBoxClient: make remembering screen size between sessions work for multiple monitors, first take.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibVideo.cpp

    r44528 r52177  
    2929*   Header Files                                                               *
    3030*******************************************************************************/
     31#include "VBGLR3Internal.h"
     32
     33#include <VBox/log.h>
     34#include <VBox/HostServices/GuestPropertySvc.h>  /* For Save and RetrieveVideoMode */
    3135#include <iprt/assert.h>
    3236#ifndef VBOX_VBGLR3_XFREE86
     
    3438#endif
    3539#include <iprt/string.h>
    36 #include <VBox/log.h>
    37 #include <VBox/HostServices/GuestPropertySvc.h>  /* For Save and RetrieveVideoMode */
    38 
    39 #include "VBGLR3Internal.h"
     40
     41#include <stdio.h>
    4042
    4143#ifdef VBOX_VBGLR3_XFREE86
     
    276278
    277279/**
    278  * Save video mode parameters to the registry.
     280 * Save video mode parameters to the guest property store.
    279281 *
    280282 * @returns iprt status value
    281  * @param   pszName the name to save the mode parameters under
    282  * @param   cx      mode width
    283  * @param   cy      mode height
    284  * @param   cBits   bits per pixel for the mode
    285  */
    286 VBGLR3DECL(int) VbglR3SaveVideoMode(const char *pszName, uint32_t cx, uint32_t cy, uint32_t cBits)
     283 * @param   cScreen   virtual screen number
     284 * @param   cx        mode width
     285 * @param   cy        mode height
     286 * @param   cBits     bits per pixel for the mode
     287 * @param   x         virtual screen X offset
     288 * @param   y         virtual screen Y offset
     289 * @param   fEnabled  is this virtual screen enabled?
     290 */
     291VBGLR3DECL(int) VbglR3SaveVideoMode(unsigned cScreen, unsigned cx, unsigned cy,
     292                                    unsigned cBits, unsigned x, unsigned y,
     293                                    bool fEnabled)
    287294{
    288295#if defined(VBOX_WITH_GUEST_PROPS)
     
    292299    char szModeParms[MAX_VALUE_LEN];
    293300    uint32_t u32ClientId = 0;
    294     RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName);
    295     RTStrPrintf(szModeParms, sizeof(szModeParms), "%dx%dx%d", cx, cy, cBits);
     301    unsigned cx2, cy2, cBits2, x2, y2;
     302    bool fEnabled2;
     303
     304    RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%u", cScreen);
     305    RTStrPrintf(szModeParms, sizeof(szModeParms), "%ux%ux%u,%ux%u,%u", cx, cy,
     306                cBits, x, y, (unsigned) fEnabled);
    296307    int rc = VbglR3GuestPropConnect(&u32ClientId);
    297308    if (RT_SUCCESS(rc))
     
    299310    if (u32ClientId != 0)
    300311        VbglR3GuestPropDisconnect(u32ClientId);  /* Return value ignored, because what can we do anyway? */
     312    if (RT_SUCCESS(rc))
     313    {
     314        rc = VbglR3RetrieveVideoMode(cScreen, &cx2, &cy2, &cBits2, &x2, &y2,
     315                                     &fEnabled2);
     316        if (   RT_SUCCESS(rc)
     317            && (   cx != cx2 || cy != cy2 || cBits != cBits2
     318                || x != x2 || y != y2 || fEnabled != fEnabled2))
     319            rc = VERR_WRITE_ERROR;
     320    }
    301321    return rc;
    302322#else /* !VBOX_WITH_GUEST_PROPS */
     
    310330 *
    311331 * @returns iprt status value
    312  * @param   pszName the name under which the mode parameters are saved
    313  * @param   pcx     where to store the mode width
    314  * @param   pcy     where to store the mode height
    315  * @param   pcBits  where to store the bits per pixel for the mode
    316  */
    317 VBGLR3DECL(int) VbglR3RetrieveVideoMode(const char *pszName, uint32_t *pcx, uint32_t *pcy, uint32_t *pcBits)
     332 * @param   cScreen    the virtual screen number
     333 * @param   pcx        where to store the mode width
     334 * @param   pcy        where to store the mode height
     335 * @param   pcBits     where to store the bits per pixel for the mode
     336 * @param   px         where to store the virtual screen X offset
     337 * @param   py         where to store the virtual screen Y offset
     338 * @param   pfEnabled  where to store whether this virtual screen is enabled
     339 */
     340VBGLR3DECL(int) VbglR3RetrieveVideoMode(unsigned cScreen,
     341                                        unsigned *pcx, unsigned *pcy,
     342                                        unsigned *pcBits,
     343                                        unsigned *px, unsigned *py,
     344                                        bool *pfEnabled)
    318345{
    319346#if defined(VBOX_WITH_GUEST_PROPS)
     
    326353    /* The buffer for VbglR3GuestPropReadValue.  If this is too small then
    327354     * something is wrong with the data stored in the property. */
     355    char szModeName[MAX_NAME_LEN];
    328356    char szModeParms[1024];
    329357    uint32_t u32ClientId = 0;
    330     uint32_t cx, cy, cBits;
    331 
     358    int cMatches;
     359    unsigned cx, cy, cBits, x, y, fEnabled;
     360
     361    /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */
     362    RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%u", cScreen);
    332363    int rc = VbglR3GuestPropConnect(&u32ClientId);
    333364    if (RT_SUCCESS(rc))
    334     {
    335         char szModeName[MAX_NAME_LEN];
    336         RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX"%s", pszName);
    337         /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */
    338365        rc = VbglR3GuestPropReadValue(u32ClientId, szModeName, szModeParms,
    339366                                      sizeof(szModeParms), NULL);
    340     }
     367    if (u32ClientId != 0)
     368        VbglR3GuestPropDisconnect(u32ClientId);  /* Return value ignored, because what can we do anyway? */
    341369
    342370/*
    343371 * Now we convert the string returned to numeric values.
    344372 */
    345     char *pszNext;
    346     if (RT_SUCCESS(rc))
    347         /* Extract the width from the string */
    348         rc = RTStrToUInt32Ex(szModeParms, &pszNext, 10, &cx);
    349     if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
     373    cMatches = sscanf(szModeParms, "%ux%ux%u,%ux%u,%u\n", &cx, &cy, &cBits, &x,
     374                      &y, &fEnabled);
     375    if (cMatches == 6)
     376        rc = VINF_SUCCESS;
     377    else if (cMatches < 0)
     378        rc = VERR_READ_ERROR;
     379    else
    350380        rc = VERR_PARSE_ERROR;
    351     if (RT_SUCCESS(rc))
    352     {
    353         /* Extract the height from the string */
    354         ++pszNext;
    355         rc = RTStrToUInt32Ex(pszNext, &pszNext, 10, &cy);
    356     }
    357     if ((rc != VWRN_TRAILING_CHARS) || (*pszNext != 'x'))
    358         rc = VERR_PARSE_ERROR;
    359     if (RT_SUCCESS(rc))
    360     {
    361         /* Extract the bpp from the string */
    362         ++pszNext;
    363         rc = RTStrToUInt32Full(pszNext, 10, &cBits);
    364     }
    365     if (rc != VINF_SUCCESS)
    366         rc = VERR_PARSE_ERROR;
    367 
    368381/*
    369382 * And clean up and return the values if we successfully obtained them.
    370383 */
    371     if (u32ClientId != 0)
    372         VbglR3GuestPropDisconnect(u32ClientId);  /* Return value ignored, because what can we do anyway? */
    373     if (RT_SUCCESS(rc))
    374     {
    375         *pcx = cx;
    376         *pcy = cy;
    377         *pcBits = cBits;
     384    if (RT_SUCCESS(rc))
     385    {
     386        if (pcx)
     387            *pcx = cx;
     388        if (pcy)
     389            *pcy = cy;
     390        if (pcBits)
     391            *pcBits = cBits;
     392        if (px)
     393            *px = x;
     394        if (py)
     395            *py = y;
     396        if (pfEnabled)
     397            *pfEnabled = RT_BOOL(fEnabled);
    378398    }
    379399    return rc;
Note: See TracChangeset for help on using the changeset viewer.

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