VirtualBox

Changeset 18793 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 6, 2009 8:04:49 PM (16 years ago)
Author:
vboxsync
Message:

FE/SDL: properly handle a failure of SDL_GetWMInfo()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r18788 r18793  
    187187static BOOL gfGuestScrollLockPressed = FALSE;
    188188static BOOL gfACPITerm = FALSE;
     189static BOOL gfXCursorEnabled = TRUE;
    189190static int  gcGuestNumLockAdaptions = 2;
    190191static int  gcGuestCapsLockAdaptions = 2;
     
    21432144    if (!SDL_GetWMInfo(&gSdlInfo))
    21442145    {
    2145         RTPrintf("Error: could not get SDL Window Manager info!\n");
    2146         goto leave;
     2146        RTPrintf("Error: could not get SDL Window Manager info -- no Xcursor support!\n");
     2147        gfXCursorEnabled = FALSE;
    21472148    }
    21482149
     
    21502151    /* SDL uses its own (plain) default cursor. Use the left arrow cursor instead which might look
    21512152     * much better if a mouse cursor theme is installed. */
    2152     gpDefaultOrigX11Cursor = *(Cursor*)gpDefaultCursor->wm_cursor;
    2153     *(Cursor*)gpDefaultCursor->wm_cursor = XCreateFontCursor(gSdlInfo.info.x11.display, XC_left_ptr);
    2154     SDL_SetCursor(gpDefaultCursor);
     2153    if (gfXCursorEnabled)
     2154    {
     2155        gpDefaultOrigX11Cursor = *(Cursor*)gpDefaultCursor->wm_cursor;
     2156        *(Cursor*)gpDefaultCursor->wm_cursor = XCreateFontCursor(gSdlInfo.info.x11.display, XC_left_ptr);
     2157        SDL_SetCursor(gpDefaultCursor);
     2158    }
    21552159# endif
    21562160#endif /* VBOXSDL_WITH_X11 */
     
    28472851        SDL_SetCursor(gpDefaultCursor);
    28482852#if defined(VBOXSDL_WITH_X11) && !defined(VBOX_WITHOUT_XCURSOR)
    2849         XFreeCursor(gSdlInfo.info.x11.display, pDefaultTempX11Cursor);
    2850 #endif /* VBOXSDL_WITH_X11 */
     2853        if (gfXCursorEnabled)
     2854            XFreeCursor(gSdlInfo.info.x11.display, pDefaultTempX11Cursor);
     2855#endif /* VBOXSDL_WITH_X11 && !VBOX_WITHOUT_XCURSOR */
    28512856    }
    28522857
     
    28612866            ::DestroyCursor(*(HCURSOR *) pCustomTempWMCursor);
    28622867#elif defined (VBOXSDL_WITH_X11) && !defined (VBOX_WITHOUT_XCURSOR)
    2863             XFreeCursor(gSdlInfo.info.x11.display, *(Cursor *) pCustomTempWMCursor);
    2864 #endif
     2868            if (gfXCursorEnabled)
     2869                XFreeCursor(gSdlInfo.info.x11.display, *(Cursor *) pCustomTempWMCursor);
     2870#endif /* VBOXSDL_WITH_X11 && !VBOX_WITHOUT_XCURSOR */
    28652871            free(pCustomTempWMCursor);
    28662872        }
     
    44584464#elif defined (VBOXSDL_WITH_X11) && !defined (VBOX_WITHOUT_XCURSOR)
    44594465
    4460         XcursorImage *img = XcursorImageCreate (data->width, data->height);
    4461         Assert (img);
    4462         if (img)
    4463         {
    4464             img->xhot = data->xHot;
    4465             img->yhot = data->yHot;
    4466 
    4467             XcursorPixel *dstShapePtr = img->pixels;
    4468 
    4469             for (uint32_t y = 0; y < data->height; y ++)
    4470             {
    4471                 memcpy (dstShapePtr, srcShapePtr, srcShapePtrScan);
    4472 
    4473                 if (!data->alpha)
     4466        if (gfXCursorEnabled)
     4467        {
     4468            XcursorImage *img = XcursorImageCreate (data->width, data->height);
     4469            Assert (img);
     4470            if (img)
     4471            {
     4472                img->xhot = data->xHot;
     4473                img->yhot = data->yHot;
     4474
     4475                XcursorPixel *dstShapePtr = img->pixels;
     4476
     4477                for (uint32_t y = 0; y < data->height; y ++)
    44744478                {
    4475                     // convert AND mask to the alpha channel
    4476                     uint8_t byte = 0;
    4477                     for (uint32_t x = 0; x < data->width; x ++)
     4479                    memcpy (dstShapePtr, srcShapePtr, srcShapePtrScan);
     4480
     4481                    if (!data->alpha)
    44784482                    {
    4479                         if (!(x % 8))
    4480                             byte = *(srcAndMaskPtr ++);
    4481                         else
    4482                             byte <<= 1;
    4483 
    4484                         if (byte & 0x80)
     4483                        // convert AND mask to the alpha channel
     4484                        uint8_t byte = 0;
     4485                        for (uint32_t x = 0; x < data->width; x ++)
    44854486                        {
    4486                             // Linux doesn't support inverted pixels (XOR ops,
    4487                             // to be exact) in cursor shapes, so we detect such
    4488                             // pixels and always replace them with black ones to
    4489                             // make them visible at least over light colors
    4490                             if (dstShapePtr [x] & 0x00FFFFFF)
    4491                                 dstShapePtr [x] = 0xFF000000;
     4487                            if (!(x % 8))
     4488                                byte = *(srcAndMaskPtr ++);
    44924489                            else
    4493                                 dstShapePtr [x] = 0x00000000;
     4490                                byte <<= 1;
     4491
     4492                            if (byte & 0x80)
     4493                            {
     4494                                // Linux doesn't support inverted pixels (XOR ops,
     4495                                // to be exact) in cursor shapes, so we detect such
     4496                                // pixels and always replace them with black ones to
     4497                                // make them visible at least over light colors
     4498                                if (dstShapePtr [x] & 0x00FFFFFF)
     4499                                    dstShapePtr [x] = 0xFF000000;
     4500                                else
     4501                                    dstShapePtr [x] = 0x00000000;
     4502                            }
     4503                            else
     4504                                dstShapePtr [x] |= 0xFF000000;
    44944505                        }
    4495                         else
    4496                             dstShapePtr [x] |= 0xFF000000;
    44974506                    }
     4507
     4508                    srcShapePtr += srcShapePtrScan;
     4509                    dstShapePtr += data->width;
    44984510                }
    44994511
    4500                 srcShapePtr += srcShapePtrScan;
    4501                 dstShapePtr += data->width;
    4502             }
    4503 
    4504             Cursor cur = XcursorImageLoadCursor (gSdlInfo.info.x11.display, img);
    4505             Assert (cur);
    4506             if (cur)
    4507             {
    4508                 // here we do a dirty trick by substituting a Window Manager's
    4509                 // cursor handle with the handle we created
    4510 
    4511                 WMcursor *pCustomTempWMCursor = gpCustomCursor->wm_cursor;
    4512 
    4513                 // see SDL12/src/video/x11/SDL_x11mouse.c
    4514                 void *wm_cursor = malloc (sizeof (Cursor));
    4515                 *(Cursor *) wm_cursor = cur;
    4516 
    4517                 gpCustomCursor->wm_cursor = (WMcursor *) wm_cursor;
    4518                 SDL_SetCursor (gpCustomCursor);
    4519                 SDL_ShowCursor (SDL_ENABLE);
    4520 
    4521                 if (pCustomTempWMCursor)
     4512                Cursor cur = XcursorImageLoadCursor (gSdlInfo.info.x11.display, img);
     4513                Assert (cur);
     4514                if (cur)
    45224515                {
    4523                     XFreeCursor (gSdlInfo.info.x11.display, *(Cursor *) pCustomTempWMCursor);
    4524                     free (pCustomTempWMCursor);
     4516                    // here we do a dirty trick by substituting a Window Manager's
     4517                    // cursor handle with the handle we created
     4518
     4519                    WMcursor *pCustomTempWMCursor = gpCustomCursor->wm_cursor;
     4520
     4521                    // see SDL12/src/video/x11/SDL_x11mouse.c
     4522                    void *wm_cursor = malloc (sizeof (Cursor));
     4523                    *(Cursor *) wm_cursor = cur;
     4524
     4525                    gpCustomCursor->wm_cursor = (WMcursor *) wm_cursor;
     4526                    SDL_SetCursor (gpCustomCursor);
     4527                    SDL_ShowCursor (SDL_ENABLE);
     4528
     4529                    if (pCustomTempWMCursor)
     4530                    {
     4531                        XFreeCursor (gSdlInfo.info.x11.display, *(Cursor *) pCustomTempWMCursor);
     4532                        free (pCustomTempWMCursor);
     4533                    }
     4534
     4535                    ok = true;
    45254536                }
    4526 
    4527                 ok = true;
    4528             }
    4529 
     4537            }
    45304538            XcursorImageDestroy (img);
    45314539        }
    45324540
    4533 #endif
     4541#endif /* VBOXSDL_WITH_X11 && !VBOX_WITHOUT_XCURSOR */
    45344542
    45354543        if (!ok)
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