VirtualBox

Changeset 78583 in vbox for trunk/src


Ignore:
Timestamp:
May 18, 2019 5:09:25 PM (6 years ago)
Author:
vboxsync
Message:

Shared Clipboard/URI: Backed out clipboard-x11.cpp changes from r130636 -- the logic wrt the format / target handling needs a major overhaul first and is far too convoluted (and misleading). Sigh.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp

    r78582 r78583  
    7575*   Structures and Typedefs                                                                                                      *
    7676*********************************************************************************************************************************/
    77 /** The different X11 clipboard format targets. */
    78 typedef enum _CLIPX11FORMATTARGET
    79 {
    80     CLIPX11FORMATTARGET_INVALID = 0,
    81     CLIPX11FORMATTARGET_TARGETS,
    82     CLIPX11FORMATTARGET_TEXT,  /* Treat this as Utf8, but it may really be ascii */
    83     CLIPX11FORMATTARGET_UTF8,
    84     CLIPX11FORMATTARGET_BMP,
    85     CLIPX11FORMATTARGET_HTML
    86 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    87     , CLIPX11FORMATTARGET_URI_LIST
    88 #endif
    89 } CLIPX11FORMATTARGET;
    90 
    91 /** Index into the format array. */
    92 typedef unsigned CLIPX11FORMATIDX;
     77/** The different clipboard formats which we support. */
     78enum CLIPFORMAT
     79{
     80    INVALID = 0,
     81    TARGETS,
     82    TEXT,  /* Treat this as Utf8, but it may really be ascii */
     83    UTF8,
     84    BMP,
     85    HTML
     86};
     87
     88typedef unsigned CLIPX11FORMAT;
    9389
    9490
     
    105101/** The table mapping X11 names to data formats and to the corresponding
    106102 * VBox clipboard formats (currently only Unicode) */
    107 static struct _CLIPX11FORMATTABLE
    108 {
    109     /** The X11 atom name of the format (several names can match one format) */
     103static struct _CLIPFORMATTABLE
     104{
     105    /** The X11 atom name of the format (several names can match one format)
     106     */
    110107    const char *pcszAtom;
    111     /** The format target corresponding to the atom name */
    112     CLIPX11FORMATTARGET enmTarget;
     108    /** The format corresponding to the name */
     109    CLIPFORMAT  enmFormat;
    113110    /** The corresponding VBox clipboard format */
    114     VBOXCLIPBOARDFORMAT vboxFormat;
     111    uint32_t    u32VBoxFormat;
    115112} g_aFormats[] =
    116113{
    117     { "INVALID", CLIPX11FORMATTARGET_INVALID, 0 },
    118     { "UTF8_STRING", CLIPX11FORMATTARGET_UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    119     { "text/plain;charset=UTF-8", CLIPX11FORMATTARGET_UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    120     { "text/plain;charset=utf-8", CLIPX11FORMATTARGET_UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    121     { "STRING", CLIPX11FORMATTARGET_TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    122     { "TEXT", CLIPX11FORMATTARGET_TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    123     { "text/plain", CLIPX11FORMATTARGET_TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
    124     { "text/html", CLIPX11FORMATTARGET_HTML, VBOX_SHARED_CLIPBOARD_FMT_HTML },
    125     { "text/html;charset=utf-8", CLIPX11FORMATTARGET_HTML, VBOX_SHARED_CLIPBOARD_FMT_HTML },
    126     { "image/bmp", CLIPX11FORMATTARGET_BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP },
    127     { "image/x-bmp", CLIPX11FORMATTARGET_BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP },
    128     { "image/x-MS-bmp", CLIPX11FORMATTARGET_BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP },
    129 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    130     { "text/uri-list", CLIPX11FORMATTARGET_URI_LIST, VBOX_SHARED_CLIPBOARD_FMT_URI_LIST },
    131     { "x-special/gnome-copied-files", CLIPX11FORMATTARGET_URI_LIST, VBOX_SHARED_CLIPBOARD_FMT_URI_LIST }
    132 #endif
     114    { "INVALID", INVALID, 0 },
     115    { "UTF8_STRING", UTF8, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
     116    { "text/plain;charset=UTF-8", UTF8,
     117      VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
     118    { "text/plain;charset=utf-8", UTF8,
     119      VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
     120    { "STRING", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
     121    { "TEXT", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
     122    { "text/plain", TEXT, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT },
     123    { "text/html", HTML, VBOX_SHARED_CLIPBOARD_FMT_HTML },
     124    { "text/html;charset=utf-8", HTML,
     125      VBOX_SHARED_CLIPBOARD_FMT_HTML },
     126    { "image/bmp", BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP },
     127    { "image/x-bmp", BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP },
     128    { "image/x-MS-bmp", BMP, VBOX_SHARED_CLIPBOARD_FMT_BITMAP }
     129
     130
    133131    /** @todo Inkscape exports image/png but not bmp... */
    134132};
     
    136134enum
    137135{
    138     CLIPX11FORMATIDX_NIL = 0,
    139     CLIPX11FORMATIDX_MAX = RT_ELEMENTS(g_aFormats)
     136    NIL_CLIPX11FORMAT = 0,
     137    MAX_CLIP_X11_FORMATS = RT_ELEMENTS(g_aFormats)
    140138};
    141139
    142140
    143 /** Returnx the atom name corresponding to a supported X11 format index.
     141/** Return the atom corresponding to a supported X11 format.
    144142 * @param widget a valid Xt widget
    145143 */
    146 static Atom clipGetAtomFromFmtIdx(CLIPBACKEND *pCtx, CLIPX11FORMATIDX formatIdx)
    147 {
    148     return clipGetAtom(pCtx, g_aFormats[formatIdx].pcszAtom);
    149 }
    150 
    151 /** Returns the format target corresponding to a supported X11 format index. */
    152 static CLIPX11FORMATTARGET clipGetTargetFmtFromFmtIdx(CLIPX11FORMATIDX formatIdx)
    153 {
    154     return g_aFormats[formatIdx].enmTarget;
    155 }
    156 
    157 /** Returns the VBox format corresponding to a supported X11 format index. */
    158 static VBOXCLIPBOARDFORMAT clipGetVBoxFmtFromFmtIdx(CLIPX11FORMATIDX formatIdx)
    159 {
    160     return g_aFormats[formatIdx].vboxFormat;
    161 }
    162 
    163 /**
    164  * Looks up the X11 format index matching a given X11 atom.
    165  *
    166  * @returns the format on success, CLIPX11FORMATIDX_NIL on failure.
     144static Atom clipAtomForX11Format(CLIPBACKEND *pCtx, CLIPX11FORMAT format)
     145{
     146    return clipGetAtom(pCtx, g_aFormats[format].pcszAtom);
     147}
     148
     149/** Return the CLIPFORMAT corresponding to a supported X11 format. */
     150static CLIPFORMAT clipRealFormatForX11Format(CLIPX11FORMAT format)
     151{
     152    return g_aFormats[format].enmFormat;
     153}
     154
     155/** Return the atom corresponding to a supported X11 format. */
     156static uint32_t clipVBoxFormatForX11Format(CLIPX11FORMAT format)
     157{
     158    return g_aFormats[format].u32VBoxFormat;
     159}
     160
     161/** Lookup the X11 format matching a given X11 atom.
     162 * @returns the format on success, NIL_CLIPX11FORMAT on failure
    167163 * @param   widget a valid Xt widget
    168164 */
    169 static CLIPX11FORMATIDX clipGetFmtIdxFromAtom(CLIPBACKEND *pCtx, Atom atomFormat)
     165static CLIPX11FORMAT clipFindX11FormatByAtom(CLIPBACKEND *pCtx, Atom atomFormat)
    170166{
    171167    for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i)
    172         if (clipGetAtomFromFmtIdx(pCtx, i) == atomFormat)
     168        if (clipAtomForX11Format(pCtx, i) == atomFormat)
    173169            return i;
    174     return CLIPX11FORMATIDX_NIL;
     170    return NIL_CLIPX11FORMAT;
    175171}
    176172
    177173#ifdef TESTCASE
    178174/** Lookup the X11 format matching a given X11 atom text.
    179  * @returns the format on success, NIL_CLIPX11FORMATTARGET on failure
     175 * @returns the format on success, NIL_CLIPX11FORMAT on failure
    180176 * @param   widget a valid Xt widget
    181177 */
    182 static CLIPX11FORMATIDX clipGetFmtIdxFromAtomText(const char *pcsz)
     178static CLIPX11FORMAT clipFindX11FormatByAtomText(const char *pcsz)
    183179{
    184180    for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i)
    185181        if (!strcmp(g_aFormats[i].pcszAtom, pcsz))
    186182            return i;
    187     return CLIPX11FORMATIDX_NIL;
     183    return NIL_CLIPX11FORMAT;
    188184}
    189185#endif
    190186
    191187/**
    192  * Enumerates supported X11 clipboard formats corresponding to a given VBox format.
    193  *
    194  * @returns the next matching X11 format in the list, or NIL_CLIPX11FORMATTARGET if
     188 * Enumerates supported X11 clipboard formats corresponding to a given VBox
     189 * format.
     190 * @returns the next matching X11 format in the list, or NIL_CLIPX11FORMAT if
    195191 *          there are no more
    196  * @param lastFmtIdx  The format index returned from the last call of this function.
    197  *                    Use CLIPX11FORMATIDX_NIL to start the enumeration.
    198  */
    199 static CLIPX11FORMATIDX clipEnumFmtIdxForVBoxFmt(VBOXCLIPBOARDFORMAT vboxFormat,
    200                                                  CLIPX11FORMATIDX lastFmtIdx)
    201 {
    202     for (unsigned i = lastFmtIdx + 1; i < RT_ELEMENTS(g_aFormats); ++i)
    203         if (vboxFormat & clipGetVBoxFmtFromFmtIdx(i))
     192 * @param lastFormat  The value returned from the last call of this function.
     193 *                    Use NIL_CLIPX11FORMAT to start the enumeration.
     194 */
     195static CLIPX11FORMAT clipEnumX11Formats(uint32_t u32VBoxFormats,
     196                                        CLIPX11FORMAT lastFormat)
     197{
     198    for (unsigned i = lastFormat + 1; i < RT_ELEMENTS(g_aFormats); ++i)
     199        if (u32VBoxFormats & clipVBoxFormatForX11Format(i))
    204200            return i;
    205     return CLIPX11FORMATIDX_NIL;
     201    return NIL_CLIPX11FORMAT;
    206202}
    207203
     
    226222    /** The best text format X11 has to offer, as an index into the formats
    227223     * table */
    228     CLIPX11FORMATIDX X11TextFmtIdx;
     224    CLIPX11FORMAT X11TextFormat;
    229225    /** The best bitmap format X11 has to offer, as an index into the formats
    230226     * table */
    231     CLIPX11FORMATIDX X11BitmapFmtIdx;
     227    CLIPX11FORMAT X11BitmapFormat;
    232228    /** The best HTML format X11 has to offer, as an index into the formats
    233229     * table */
    234     CLIPX11FORMATIDX X11HTMLFmtIdx;
    235 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    236     /** The best URI list format X11 has to offer, as an index into the formats
    237      * table */
    238     CLIPX11FORMATIDX X11URListFmtIdx;
    239 #endif
     230    CLIPX11FORMAT X11HTMLFormat;
    240231    /** What formats does VBox have on offer? */
    241     VBOXCLIPBOARDFORMATS vboxFormats;
     232    uint32_t vboxFormats;
    242233    /** Cache of the last unicode data that we received */
    243234    void *pvUnicodeCache;
     
    367358                    (XtPointer)client_data);
    368359    ssize_t cbWritten = write(pCtx->wakeupPipeWrite, WAKE_UP_STRING, WAKE_UP_STRING_LEN);
    369     RT_NOREF(cbWritten);
     360    NOREF(cbWritten);
    370361#else
    371     RT_NOREF(pCtx);
     362    RT_NOREF1(pCtx);
    372363    testQueueToEventThread(proc, client_data);
    373364#endif
     
    379370static void clipReportFormatsToVBox(CLIPBACKEND *pCtx)
    380371{
    381     VBOXCLIPBOARDFORMATS vboxFormats = clipGetVBoxFmtFromFmtIdx(pCtx->X11TextFmtIdx);
    382     vboxFormats |= clipGetVBoxFmtFromFmtIdx(pCtx->X11BitmapFmtIdx);
    383     vboxFormats |= clipGetVBoxFmtFromFmtIdx(pCtx->X11HTMLFmtIdx);
    384 
    385     LogRelFlowFunc(("clipReportFormatsToVBox formats: 0x%x\n", vboxFormats));
    386     LogRelFlowFunc(("clipReportFormatsToVBox txt: %d, bitm: %d, html:%d, vboxFormat: %d\n",
    387                     pCtx->X11TextFmtIdx, pCtx->X11BitmapFmtIdx, pCtx->X11HTMLFmtIdx,
    388                     vboxFormats));
    389 
    390     ClipReportX11Formats(pCtx->pFrontend, vboxFormats);
     372    uint32_t u32VBoxFormats = clipVBoxFormatForX11Format(pCtx->X11TextFormat);
     373    u32VBoxFormats |= clipVBoxFormatForX11Format(pCtx->X11BitmapFormat);
     374    u32VBoxFormats |= clipVBoxFormatForX11Format(pCtx->X11HTMLFormat);
     375    LogRelFlowFunc(("clipReportFormatsToVBox format: %d\n", u32VBoxFormats));
     376    LogRelFlowFunc(("clipReportFormatsToVBox txt: %d, bitm: %d, html:%d, u32VBoxFormats: %d\n",
     377                    pCtx->X11TextFormat, pCtx->X11BitmapFormat, pCtx->X11HTMLFormat,
     378                    u32VBoxFormats ));
     379    ClipReportX11Formats(pCtx->pFrontend, u32VBoxFormats);
    391380}
    392381
     
    396385static void clipResetX11Formats(CLIPBACKEND *pCtx)
    397386{
    398     pCtx->X11TextFmtIdx   = CLIPX11FORMATIDX_NIL;
    399     pCtx->X11BitmapFmtIdx = CLIPX11FORMATIDX_NIL;
    400     pCtx->X11HTMLFmtIdx   = CLIPX11FORMATIDX_NIL;
    401 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    402     pCtx->X11URListFmtIdx = CLIPX11FORMATIDX_NIL;
    403 #endif
     387    pCtx->X11TextFormat = INVALID;
     388    pCtx->X11BitmapFormat = INVALID;
     389    pCtx->X11HTMLFormat = INVALID;
    404390}
    405391
     
    411397}
    412398
     399/**
     400 * Go through an array of X11 clipboard targets to see if they contain a text
     401 * format we can support, and if so choose the ones we prefer (e.g. we like
     402 * Utf8 better than plain text).
     403 * @param  pCtx      the clipboard backend context structure
     404 * @param  pTargets  the list of targets
     405 * @param  cTargets  the size of the list in @a pTargets
     406 */
     407static CLIPX11FORMAT clipGetTextFormatFromTargets(CLIPBACKEND *pCtx,
     408                                                  CLIPX11FORMAT *pTargets,
     409                                                  size_t cTargets)
     410{
     411    CLIPX11FORMAT bestTextFormat = NIL_CLIPX11FORMAT;
     412    CLIPFORMAT enmBestTextTarget = INVALID;
     413    AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
     414    AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);
     415    for (unsigned i = 0; i < cTargets; ++i)
     416    {
     417        CLIPX11FORMAT format = pTargets[i];
     418        if (format != NIL_CLIPX11FORMAT)
     419        {
     420            if (   (clipVBoxFormatForX11Format(format)
     421                            == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
     422                    && enmBestTextTarget < clipRealFormatForX11Format(format))
     423            {
     424                enmBestTextTarget = clipRealFormatForX11Format(format);
     425                bestTextFormat = format;
     426            }
     427        }
     428    }
     429    return bestTextFormat;
     430}
     431
    413432#ifdef TESTCASE
    414433static bool clipTestTextFormatConversion(CLIPBACKEND *pCtx)
    415434{
    416435    bool success = true;
    417     CLIPX11FORMATTARGET targets[2];
    418     CLIPX11FORMATTARGET x11Format;
    419     targets[0] = clipGetFmtIdxFromAtomText("text/plain");
    420     targets[1] = clipGetFmtIdxFromAtomText("image/bmp");
     436    CLIPX11FORMAT targets[2];
     437    CLIPX11FORMAT x11Format;
     438    targets[0] = clipFindX11FormatByAtomText("text/plain");
     439    targets[1] = clipFindX11FormatByAtomText("image/bmp");
    421440    x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2);
    422     if (clipGetTargetFmtFromFmtIdx(x11Format) != TEXT)
     441    if (clipRealFormatForX11Format(x11Format) != TEXT)
    423442        success = false;
    424     targets[0] = clipGetFmtIdxFromAtomText("UTF8_STRING");
    425     targets[1] = clipGetFmtIdxFromAtomText("text/plain");
     443    targets[0] = clipFindX11FormatByAtomText("UTF8_STRING");
     444    targets[1] = clipFindX11FormatByAtomText("text/plain");
    426445    x11Format = clipGetTextFormatFromTargets(pCtx, targets, 2);
    427     if (clipGetTargetFmtFromFmtIdx(x11Format) != UTF8)
     446    if (clipRealFormatForX11Format(x11Format) != UTF8)
    428447        success = false;
    429448    return success;
     
    435454 * format we can support, and if so choose the ones we prefer (e.g. we like
    436455 * BMP better than PNG because we don't have to convert).
    437  *
    438456 * @param  pCtx      the clipboard backend context structure
    439457 * @param  pTargets  the list of targets
    440458 * @param  cTargets  the size of the list in @a pTargets
    441459 */
    442 static CLIPX11FORMATIDX clipGetBestFmtIdxFromTargets(CLIPBACKEND *pCtx,
    443                                                      VBOXCLIPBOARDFORMAT vboxFormat,
    444                                                      CLIPX11FORMATIDX   *paTargets, size_t cTargets)
    445 {
    446     AssertPtrReturn(pCtx, CLIPX11FORMATIDX_NIL);
    447     AssertReturn(VALID_PTR(paTargets) || cTargets == 0, CLIPX11FORMATIDX_NIL);
    448 
    449     CLIPX11FORMATIDX    bestFmtIdx    = CLIPX11FORMATIDX_NIL;
    450     CLIPX11FORMATTARGET enmBestTarget = CLIPX11FORMATTARGET_INVALID;
    451 
     460static CLIPX11FORMAT clipGetBitmapFormatFromTargets(CLIPBACKEND *pCtx,
     461                                                    CLIPX11FORMAT *pTargets,
     462                                                    size_t cTargets)
     463{
     464    CLIPX11FORMAT bestBitmapFormat = NIL_CLIPX11FORMAT;
     465    CLIPFORMAT enmBestBitmapTarget = INVALID;
     466    AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
     467    AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);
    452468    for (unsigned i = 0; i < cTargets; ++i)
    453469    {
    454         CLIPX11FORMATIDX format = paTargets[i];
    455         if (format != CLIPX11FORMATIDX_NIL)
     470        CLIPX11FORMAT format = pTargets[i];
     471        if (format != NIL_CLIPX11FORMAT)
    456472        {
    457             if (   (clipGetVBoxFmtFromFmtIdx(format) == vboxFormat)
    458                 && enmBestTarget < clipGetTargetFmtFromFmtIdx(format))
     473            if (   (clipVBoxFormatForX11Format(format)
     474                            == VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
     475                    && enmBestBitmapTarget < clipRealFormatForX11Format(format))
    459476            {
    460                 enmBestTarget = clipGetTargetFmtFromFmtIdx(format);
    461                 bestFmtIdx = format;
     477                enmBestBitmapTarget = clipRealFormatForX11Format(format);
     478                bestBitmapFormat = format;
    462479            }
    463480        }
    464481    }
    465     return bestFmtIdx;
    466 }
     482    return bestBitmapFormat;
     483}
     484
     485/**
     486 * Go through an array of X11 clipboard targets to see if they contain a HTML
     487 * format we can support, and if so choose the ones we prefer
     488 * @param  pCtx      the clipboard backend context structure
     489 * @param  pTargets  the list of targets
     490 * @param  cTargets  the size of the list in @a pTargets
     491 */
     492static CLIPX11FORMAT clipGetHtmlFormatFromTargets(CLIPBACKEND *pCtx,
     493                                                  CLIPX11FORMAT *pTargets,
     494                                                  size_t cTargets)
     495{
     496    CLIPX11FORMAT bestHTMLFormat = NIL_CLIPX11FORMAT;
     497    CLIPFORMAT enmBestHtmlTarget = INVALID;
     498    AssertPtrReturn(pCtx, NIL_CLIPX11FORMAT);
     499    AssertReturn(VALID_PTR(pTargets) || cTargets == 0, NIL_CLIPX11FORMAT);
     500    for (unsigned i = 0; i < cTargets; ++i)
     501    {
     502        CLIPX11FORMAT format = pTargets[i];
     503        if (format != NIL_CLIPX11FORMAT)
     504        {
     505            if (   (clipVBoxFormatForX11Format(format) == VBOX_SHARED_CLIPBOARD_FMT_HTML)
     506                && enmBestHtmlTarget < clipRealFormatForX11Format(format))
     507            {
     508                enmBestHtmlTarget = clipRealFormatForX11Format(format);
     509                bestHTMLFormat = format;
     510            }
     511        }
     512    }
     513    return bestHTMLFormat;
     514}
     515
    467516
    468517/**
     
    470519 * of them and if relevant to choose the ones we prefer (e.g. we like Utf8
    471520 * better than plain text).
    472  *
    473521 * @param  pCtx      the clipboard backend context structure
    474522 * @param  pTargets  the list of targets
     
    476524 */
    477525static void clipGetFormatsFromTargets(CLIPBACKEND *pCtx,
    478                                       CLIPX11FORMATIDX *paTargets, size_t cTargets)
     526                                      CLIPX11FORMAT *pTargets, size_t cTargets)
    479527{
    480528    AssertPtrReturnVoid(pCtx);
    481     AssertPtrReturnVoid(paTargets);
    482 
    483     CLIPX11FORMATIDX bestFmtIdx = clipGetBestFmtIdxFromTargets(pCtx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT,
    484                                                                paTargets, cTargets);
    485     if (pCtx->X11TextFmtIdx != bestFmtIdx)
    486         pCtx->X11TextFmtIdx = bestFmtIdx;
    487 
    488     pCtx->X11BitmapFmtIdx = CLIPX11FORMATIDX_NIL;  /* not yet supported */
    489     bestFmtIdx = clipGetBestFmtIdxFromTargets(pCtx, VBOX_SHARED_CLIPBOARD_FMT_BITMAP, paTargets, cTargets);
    490     if (pCtx->X11BitmapFmtIdx != bestFmtIdx)
    491         pCtx->X11BitmapFmtIdx = bestFmtIdx;
    492 
    493     bestFmtIdx = clipGetBestFmtIdxFromTargets(pCtx, VBOX_SHARED_CLIPBOARD_FMT_HTML, paTargets, cTargets);
    494     if(pCtx->X11HTMLFmtIdx != bestFmtIdx)
    495         pCtx->X11HTMLFmtIdx = bestFmtIdx;
    496 
    497 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    498     bestFmtIdx = clipGetBestFmtIdxFromTargets(pCtx, VBOX_SHARED_CLIPBOARD_FMT_URI_LIST, paTargets, cTargets);
    499     if(pCtx->X11URListFmtIdx != bestFmtIdx)
    500         pCtx->X11URListFmtIdx = bestFmtIdx;
    501 #endif
     529    AssertPtrReturnVoid(pTargets);
     530    CLIPX11FORMAT bestTextFormat;
     531    CLIPX11FORMAT bestBitmapFormat;
     532    CLIPX11FORMAT bestHtmlFormat;
     533    bestTextFormat = clipGetTextFormatFromTargets(pCtx, pTargets, cTargets);
     534    if (pCtx->X11TextFormat != bestTextFormat)
     535    {
     536        pCtx->X11TextFormat = bestTextFormat;
     537    }
     538    pCtx->X11BitmapFormat = INVALID;  /* not yet supported */
     539    bestBitmapFormat = clipGetBitmapFormatFromTargets(pCtx, pTargets, cTargets);
     540    if (pCtx->X11BitmapFormat != bestBitmapFormat)
     541    {
     542        pCtx->X11BitmapFormat = bestBitmapFormat;
     543    }
     544    bestHtmlFormat = clipGetHtmlFormatFromTargets(pCtx, pTargets, cTargets);
     545    if(pCtx->X11HTMLFormat != bestHtmlFormat)
     546    {
     547        pCtx->X11HTMLFormat = bestHtmlFormat;
     548    }
    502549}
    503550
     
    507554 * Update the context's information about targets currently supported by X11,
    508555 * based on an array of X11 atoms.
    509  *
    510556 * @param  pCtx      the context to be updated
    511557 * @param  pTargets  the array of atoms describing the targets supported
    512558 * @param  cTargets  the size of the array @a pTargets
    513559 */
    514 static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMATIDX *paTargetFmtIdx, size_t cTargets)
    515 {
    516     LogRel2(("Shared clipboard: clipUpdateX11Targets called\n"));
    517 
     560static void clipUpdateX11Targets(CLIPBACKEND *pCtx, CLIPX11FORMAT *pTargets,
     561                                 size_t cTargets)
     562{
     563    LogRel2 (("%s: called\n", __FUNCTION__));
    518564#ifndef VBOX_AFTER_5_2
    519565    pCtx->fBusy = false;
     
    526572    }
    527573#endif
    528 
    529     if (paTargetFmtIdx == NULL)
    530     {
     574    if (pTargets == NULL) {
    531575        /* No data available */
    532576        clipReportEmptyX11CB(pCtx);
    533577        return;
    534578    }
    535 
    536     clipGetFormatsFromTargets(pCtx, paTargetFmtIdx, cTargets);
     579    clipGetFormatsFromTargets(pCtx, pTargets, cTargets);
    537580    clipReportFormatsToVBox(pCtx);
    538581}
     
    545588 *        unit test.  So keep it simple, be paranoid and log everything.
    546589 */
    547 static void clipConvertX11Targets(Widget widget, XtPointer pSvcCtxData,
     590static void clipConvertX11Targets(Widget widget, XtPointer pClientData,
    548591                                  Atom * /* selection */, Atom *atomType,
    549592                                  XtPointer pValue, long unsigned int *pcLen,
    550593                                  int *piFormat)
    551594{
    552     RT_NOREF(piFormat);
    553 
    554     CLIPBACKEND *pCtx = reinterpret_cast<CLIPBACKEND *>(pSvcCtxData);
     595    RT_NOREF1(piFormat);
     596    CLIPBACKEND *pCtx = reinterpret_cast<CLIPBACKEND *>(pClientData);
    555597    Atom *pAtoms = (Atom *)pValue;
    556598    unsigned i, j;
    557 
    558     LogRel2(("Shared clipboard: pValue=%p, *pcLen=%u, *atomType=%d%s\n",
     599    LogRel2(("%s: pValue=%p, *pcLen=%u, *atomType=%d%s\n", __FUNCTION__,
    559600             pValue, *pcLen, *atomType,
    560601             *atomType == XT_CONVERT_FAIL ? " (XT_CONVERT_FAIL)" : ""));
    561 
    562     CLIPX11FORMATIDX *paFmtIdx = NULL;
    563 
     602    CLIPX11FORMAT *pFormats = NULL;
    564603    if (*pcLen && pValue && (*atomType != XT_CONVERT_FAIL /* time out */))
    565         paFmtIdx = (CLIPX11FORMATIDX *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMATIDX));
    566 
     604        pFormats = (CLIPX11FORMAT *)RTMemAllocZ(*pcLen * sizeof(CLIPX11FORMAT));
    567605#if defined(DEBUG) && !defined(TESTCASE)
    568606    if (pValue)
    569607    {
    570608        for (i = 0; i < *pcLen; ++i)
    571         {
    572609            if (pAtoms[i])
    573610            {
    574611                char *pszName = XGetAtomName(XtDisplay(widget), pAtoms[i]);
    575                 LogRel(("Shared clipboard: Found target %s\n", pszName));
     612                LogRel2(("%s: found target %s\n", __FUNCTION__,
     613                         pszName));
    576614                XFree(pszName);
    577615            }
    578616            else
    579                 LogRel(("Shared clipboard: Found empty target\n"));
    580         }
     617                LogRel2(("%s: found empty target.\n", __FUNCTION__));
    581618    }
    582619#endif
    583 
    584     if (paFmtIdx)
     620    if (pFormats)
    585621    {
    586622        for (i = 0; i < *pcLen; ++i)
     
    588624            for (j = 0; j < RT_ELEMENTS(g_aFormats); ++j)
    589625            {
    590                 Atom target = XInternAtom(XtDisplay(widget), g_aFormats[j].pcszAtom, False);
     626                Atom target = XInternAtom(XtDisplay(widget),
     627                                          g_aFormats[j].pcszAtom, False);
    591628                if (*(pAtoms + i) == target)
    592                     paFmtIdx[i] = j;
     629                    pFormats[i] = j;
    593630            }
    594631#if defined(DEBUG) && !defined(TESTCASE)
    595             LogRel(("Shared clipboard: Reporting format %d (%s)\n",
    596                     paFmtIdx[i], g_aFormats[paFmtIdx[i]].pcszAtom));
     632            LogRel2(("%s: reporting format %d (%s)\n", __FUNCTION__,
     633                     pFormats[i], g_aFormats[pFormats[i]].pcszAtom));
    597634#endif
    598635        }
    599636    }
    600637    else
    601         LogRel2(("Shared clipboard: Reporting empty targets (none reported or allocation failure)\n"));
    602 
    603     clipUpdateX11Targets(pCtx, paFmtIdx, *pcLen);
    604 
    605     RTMemFree(paFmtIdx);
     638        LogRel2(("%s: reporting empty targets (none reported or allocation failure).\n",
     639                 __FUNCTION__));
     640    clipUpdateX11Targets(pCtx, pFormats, *pcLen);
     641    RTMemFree(pFormats);
    606642    XtFree(reinterpret_cast<char *>(pValue));
    607643}
     
    616652static void clipQueryX11CBFormats(CLIPBACKEND *pCtx)
    617653{
    618     LogRel2 (("Shared clipboard: Requesting the targets that the X11 clipboard offers\n"));
    619 
     654    LogRel2 (("%s: requesting the targets that the X11 clipboard offers\n",
     655           __PRETTY_FUNCTION__));
    620656#ifndef VBOX_AFTER_5_2
    621657    if (pCtx->fBusy)
     
    682718static DECLCALLBACK(int) clipEventThread(RTTHREAD hThreadSelf, void *pvUser)
    683719{
    684     RT_NOREF(hThreadSelf);
    685 
     720    RT_NOREF1(hThreadSelf);
    686721    LogRel(("Shared clipboard: Starting shared clipboard thread\n"));
    687722
     
    690725    if (pCtx->fGrabClipboardOnStart)
    691726        clipQueryX11CBFormats(pCtx);
    692 
    693727    while (XtAppGetExitFlag(pCtx->appContext) == FALSE)
    694728    {
     
    696730        XtAppProcessEvent(pCtx->appContext, XtIMAll);
    697731    }
    698 
    699732    LogRel(("Shared clipboard: Shared clipboard thread terminated successfully\n"));
    700733    return VINF_SUCCESS;
     
    731764static void clipStopEventThreadWorker(void *pUserData, void *)
    732765{
     766
    733767    CLIPBACKEND *pCtx = (CLIPBACKEND *)pUserData;
    734768
     
    795829#endif
    796830
    797 /**
    798  * This is the callback which is scheduled when data is available on the
    799  * wakeup pipe.  It simply reads all data from the pipe.
    800  */
     831/** This is the callback which is scheduled when data is available on the
     832 * wakeup pipe.  It simply reads all data from the pipe. */
    801833static void clipDrainWakeupPipe(XtPointer pUserData, int *, XtInputId *)
    802834{
     
    804836    char acBuf[WAKE_UP_STRING_LEN];
    805837
    806     LogRel2(("Shared clipboard: clipDrainWakeupPipe called\n"));
    807 
     838    LogRel2(("clipDrainWakeupPipe: called\n"));
    808839    while (read(pCtx->wakeupPipeRead, acBuf, sizeof(acBuf)) > 0) {}
    809840}
    810841
    811 /**
    812  * X11 specific initialisation for the shared clipboard.
    813  *
     842/** X11 specific initialisation for the shared clipboard.
    814843 * @note  X11 backend code.
    815844 */
     
    832861    if (NULL == pDisplay)
    833862    {
    834         LogRel(("Shared clipboard: Failed to connect to the X11 clipboard - the window system may not be running\n"));
     863        LogRel(("Shared clipboard: Failed to connect to the X11 clipboard - the window system may not be running.\n"));
    835864        rc = VERR_NOT_SUPPORTED;
    836865    }
     
    840869        rc = clipLoadXFixes(pDisplay, pCtx);
    841870        if (RT_FAILURE(rc))
    842            LogRel(("Shared clipboard: Failed to load the XFIXES extension\n"));
     871           LogRel(("Shared clipboard: Failed to load the XFIXES extension.\n"));
    843872    }
    844873#endif
     
    851880        if (NULL == pCtx->widget)
    852881        {
    853             LogRel(("Shared clipboard: Failed to construct the X11 window for the shared clipboard manager\n"));
     882            LogRel(("Shared clipboard: Failed to construct the X11 window for the shared clipboard manager.\n"));
    854883            rc = VERR_NO_MEMORY;
    855884        }
     
    882911            rc = RTErrConvertFromErrno(errno);
    883912        if (RT_FAILURE(rc))
    884             LogRel(("Shared clipboard: Failed to setup the termination mechanism\n"));
     913            LogRel(("Shared clipboard: Failed to setup the termination mechanism.\n"));
    885914    }
    886915    else
     
    894923
    895924/**
    896  * Constructs the X11 backend of the shared clipboard.
    897  *
     925 * Construct the X11 backend of the shared clipboard.
    898926 * @note  X11 backend code
    899927 */
     
    909937         * This is important for VBoxHeadless.
    910938         */
    911         LogRel(("Shared clipboard: X11 DISPLAY variable not set -- disabling Shared Clipboard\n"));
     939        LogRelFunc(("X11 DISPLAY variable not set -- disabling shared clipboard\n"));
    912940        pCtx->fHaveX11 = false;
    913941        return pCtx;
     
    917945
    918946    LogRel(("Shared clipboard: Initializing X11 clipboard backend\n"));
    919 
    920947    if (pCtx)
    921948        pCtx->pFrontend = pFrontend;
     
    924951
    925952/**
    926  * Destructs the shared clipboard X11 backend.
    927  *
     953 * Destruct the shared clipboard X11 backend.
    928954 * @note  X11 backend code
    929955 */
     
    939965
    940966/**
    941  * Announces to the X11 backend that we are ready to start.
    942  *
     967 * Announce to the X11 backend that we are ready to start.
    943968 * @param  grab  whether we should try to grab the shared clipboard at once
    944969 */
     
    946971{
    947972    int rc = VINF_SUCCESS;
    948 
    949     LogRel2(("Shared clipboard: Starting\n"));
    950 
     973    LogRelFlowFunc(("\n"));
    951974    /*
    952975     * Immediately return if we are not connected to the X server.
     
    968991        if (RT_FAILURE(rc))
    969992        {
    970             LogRel(("Shared clipboard: Failed to start the shared clipboard thread, rc=%Rrc\n", rc));
     993            LogRel(("Shared clipboard: Failed to start the shared clipboard thread.\n"));
    971994            clipUninit(pCtx);
    972995        }
     
    9771000
    9781001/**
    979  * Shuts down the shared clipboard X11 backend.
    980  *
    981  * @note  X11 backend code.
     1002 * Shut down the shared clipboard X11 backend.
     1003 * @note  X11 backend code
    9821004 * @note  Any requests from this object to get clipboard data from VBox
    9831005 *        *must* have completed or aborted before we are called, as
     
    9951017        return VINF_SUCCESS;
    9961018
    997     LogRel(("Shared clipboard: Stopping X11 backend\n"));
    998 
     1019    LogRelFunc(("stopping the shared clipboard X11 backend\n"));
    9991020    /* Write to the "stop" pipe */
    10001021    clipQueueToEventThread(pCtx, clipStopEventThreadWorker, (XtPointer) pCtx);
     
    10141035        AssertRC(rcThread);
    10151036    else
    1016         LogRel(("Shared clipboard: Stopping X11 backend failed with rc=%Rrc\n", rc));
    1017 
     1037        LogRelFunc(("rc=%Rrc\n", rc));
    10181038    clipUninit(pCtx);
    1019 
     1039    LogRelFlowFunc(("returning %Rrc.\n", rc));
    10201040    RT_NOREF_PV(rcThread);
    10211041    return rc;
     
    10251045 * Satisfy a request from X11 for clipboard targets supported by VBox.
    10261046 *
    1027  * @returns IPRT status code.
    1028  * @param  atomTypeReturn The type of the data we are returning.
     1047 * @returns iprt status code
     1048 * @param  atomTypeReturn The type of the data we are returning
    10291049 * @param  pValReturn     A pointer to the data we are returning.  This
    10301050 *                        should be set to memory allocated by XtMalloc,
    10311051 *                        which will be freed later by the Xt toolkit.
    1032  * @param  pcLenReturn    The length of the data we are returning.
     1052 * @param  pcLenReturn    The length of the data we are returning
    10331053 * @param  piFormatReturn The format (8bit, 16bit, 32bit) of the data we are
    1034  *                        returning.
    1035  *
     1054 *                        returning
    10361055 * @note  X11 backend code, called by the XtOwnSelection callback.
    10371056 */
     
    10411060                                int *piFormatReturn)
    10421061{
    1043     Atom *atomTargets = (Atom *)XtMalloc((CLIPX11FORMATIDX_MAX + 3) * sizeof(Atom));
     1062    Atom *atomTargets = (Atom *)XtMalloc(  (MAX_CLIP_X11_FORMATS + 3)
     1063                                         * sizeof(Atom));
    10441064    unsigned cTargets = 0;
    1045 
    10461065    LogRelFlowFunc (("called\n"));
    1047 
    1048     CLIPX11FORMATIDX fmtIdx = CLIPX11FORMATIDX_NIL;
    1049 
     1066    CLIPX11FORMAT format = NIL_CLIPX11FORMAT;
    10501067    do
    10511068    {
    1052         fmtIdx = clipEnumFmtIdxForVBoxFmt(pCtx->vboxFormats, fmtIdx);
    1053         if (fmtIdx != CLIPX11FORMATIDX_NIL)
     1069        format = clipEnumX11Formats(pCtx->vboxFormats, format);
     1070        if (format != NIL_CLIPX11FORMAT)
    10541071        {
    1055             atomTargets[cTargets] = clipGetAtomFromFmtIdx(pCtx, fmtIdx);
     1072            atomTargets[cTargets] = clipAtomForX11Format(pCtx, format);
    10561073            ++cTargets;
    10571074        }
    1058     } while (fmtIdx != CLIPX11FORMATIDX_NIL);
    1059 
     1075    } while (format != NIL_CLIPX11FORMAT);
    10601076    /* We always offer these */
    1061     atomTargets[cTargets]     = clipGetAtom(pCtx, "TARGETS");
     1077    atomTargets[cTargets] = clipGetAtom(pCtx, "TARGETS");
    10621078    atomTargets[cTargets + 1] = clipGetAtom(pCtx, "MULTIPLE");
    10631079    atomTargets[cTargets + 2] = clipGetAtom(pCtx, "TIMESTAMP");
    1064 
    10651080    *atomTypeReturn = XA_ATOM;
    10661081    *pValReturn = (XtPointer)atomTargets;
    10671082    *pcLenReturn = cTargets + 3;
    10681083    *piFormatReturn = 32;
    1069 
    10701084    return VINF_SUCCESS;
    10711085}
    10721086
    1073 /**
    1074  * This is a wrapper around ClipRequestDataForX11 that will cache the
     1087/** This is a wrapper around ClipRequestDataForX11 that will cache the
    10751088 * data returned.
    10761089 */
    1077 static int clipReadVBoxClipboard(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMAT vboxFormat,
     1090static int clipReadVBoxClipboard(CLIPBACKEND *pCtx, uint32_t u32Format,
    10781091                                 void **ppv, uint32_t *pcb)
    10791092{
    10801093    int rc = VINF_SUCCESS;
    1081     LogRelFlowFunc(("pCtx=%p, vboxFormat=%02X, ppv=%p, pcb=%p\n", pCtx,
    1082                  vboxFormat, ppv, pcb));
    1083     if (vboxFormat == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
     1094    LogRelFlowFunc(("pCtx=%p, u32Format=%02X, ppv=%p, pcb=%p\n", pCtx,
     1095                 u32Format, ppv, pcb));
     1096    if (u32Format == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
    10841097    {
    10851098        if (pCtx->pvUnicodeCache == NULL)
    1086             rc = ClipRequestDataForX11(pCtx->pFrontend, vboxFormat,
     1099            rc = ClipRequestDataForX11(pCtx->pFrontend, u32Format,
    10871100                                              &pCtx->pvUnicodeCache,
    10881101                                              &pCtx->cbUnicodeCache);
     
    10961109    }
    10971110    else
    1098         rc = ClipRequestDataForX11(pCtx->pFrontend, vboxFormat,
     1111        rc = ClipRequestDataForX11(pCtx->pFrontend, u32Format,
    10991112                                          ppv, pcb);
    11001113    LogRelFlowFunc(("returning %Rrc\n", rc));
     
    11051118
    11061119/**
    1107  * Calculates a buffer size large enough to hold the source Windows format
    1108  * text converted into Unix Utf8, including the null terminator.
    1109  *
    1110  * @returns IPRT status code.
    1111  * @param  pwsz       the source text in UCS-2 with Windows EOLs.
     1120 * Calculate a buffer size large enough to hold the source Windows format
     1121 * text converted into Unix Utf8, including the null terminator
     1122 * @returns iprt status code
     1123 * @param  pwsz       the source text in UCS-2 with Windows EOLs
    11121124 * @param  cwc        the size in USC-2 elements of the source text, with or
    1113  *                    without the terminator.
    1114  * @param  pcbActual  where to store the buffer size needed.
     1125 *                    without the terminator
     1126 * @param  pcbActual  where to store the buffer size needed
    11151127 */
    11161128static int clipWinTxtBufSizeForUtf8(PRTUTF16 pwsz, size_t cwc,
     
    11251137
    11261138/**
    1127  * Converts text from Windows format (UCS-2 with CRLF line endings) to standard
     1139 * Convert text from Windows format (UCS-2 with CRLF line endings) to standard
    11281140 * Utf-8.
    11291141 *
    1130  * @returns IPRT status code.
    1131  * @param  pwszSrc    the text to be converted.
    1132  * @param  cbSrc      the length of @a pwszSrc in bytes.
    1133  * @param  pszBuf     where to write the converted string.
    1134  * @param  cbBuf      the size of the buffer pointed to by @a pszBuf.
     1142 * @returns iprt status code
     1143 *
     1144 * @param  pwszSrc    the text to be converted
     1145 * @param  cbSrc      the length of @a pwszSrc in bytes
     1146 * @param  pszBuf     where to write the converted string
     1147 * @param  cbBuf      the size of the buffer pointed to by @a pszBuf
    11351148 * @param  pcbActual  where to store the size of the converted string.
    11361149 *                    optional.
     
    11661179    LogRelFlowFunc(("returning %Rrc\n", rc));
    11671180    if (RT_SUCCESS(rc))
    1168         LogRelFlowFunc (("converted string is %.*s. Returning\n", cbDest,
     1181        LogRelFlowFunc (("converted string is %.*s. Returning.\n", cbDest,
    11691182                      pszBuf));
    11701183    return rc;
     
    11721185
    11731186/**
    1174  * Satisfies a request from X11 to convert the clipboard text to Utf-8.  We
     1187 * Satisfy a request from X11 to convert the clipboard text to Utf-8.  We
    11751188 * return null-terminated text, but can cope with non-null-terminated input.
    11761189 *
    1177  * @returns IPRT status code.
     1190 * @returns iprt status code
    11781191 * @param  pDisplay        an X11 display structure, needed for conversions
    1179  *                         performed by Xlib.
    1180  * @param  pv              the text to be converted (UCS-2 with Windows EOLs).
    1181  * @param  cb              the length of the text in @cb in bytes.
     1192 *                         performed by Xlib
     1193 * @param  pv              the text to be converted (UCS-2 with Windows EOLs)
     1194 * @param  cb              the length of the text in @cb in bytes
    11821195 * @param  atomTypeReturn  where to store the atom for the type of the data
    1183  *                         we are returning.
     1196 *                         we are returning
    11841197 * @param  pValReturn      where to store the pointer to the data we are
    11851198 *                         returning.  This should be to memory allocated by
     
    11871200 *                         later.
    11881201 * @param  pcLenReturn     where to store the length of the data we are
    1189  *                         returning.
     1202 *                         returning
    11901203 * @param  piFormatReturn  where to store the bit width (8, 16, 32) of the
    1191  *                         data we are returning.
     1204 *                         data we are returning
    11921205 */
    11931206static int clipWinTxtToUtf8ForX11CB(Display *pDisplay, PRTUTF16 pwszSrc,
     
    11981211                                    int *piFormatReturn)
    11991212{
    1200     RT_NOREF(pDisplay, pcLenReturn);
     1213    RT_NOREF2(pDisplay, pcLenReturn);
    12011214
    12021215    /* This may slightly overestimate the space needed. */
     
    12221235
    12231236/**
    1224  * Satisfies a request from X11 to convert the clipboard HTML fragment to Utf-8.  We
     1237 * Satisfy a request from X11 to convert the clipboard HTML fragment to Utf-8.  We
    12251238 * return null-terminated text, but can cope with non-null-terminated input.
    12261239 *
    1227  * @returns IPRT status code.
     1240 * @returns iprt status code
    12281241 * @param  pDisplay        an X11 display structure, needed for conversions
    1229  *                         performed by Xlib.
    1230  * @param  pv              the text to be converted (UTF8 with Windows EOLs).
    1231  * @param  cb              the length of the text in @cb in bytes.
     1242 *                         performed by Xlib
     1243 * @param  pv              the text to be converted (UTF8 with Windows EOLs)
     1244 * @param  cb              the length of the text in @cb in bytes
    12321245 * @param  atomTypeReturn  where to store the atom for the type of the data
    1233  *                         we are returning.
     1246 *                         we are returning
    12341247 * @param  pValReturn      where to store the pointer to the data we are
    12351248 *                         returning.  This should be to memory allocated by
     
    12371250 *                         later.
    12381251 * @param  pcLenReturn     where to store the length of the data we are
    1239  *                         returning.
     1252 *                         returning
    12401253 * @param  piFormatReturn  where to store the bit width (8, 16, 32) of the
    1241  *                         data we are returning.
     1254 *                         data we are returning
    12421255 */
    12431256static int clipWinHTMLToUtf8ForX11CB(Display *pDisplay, const char *pszSrc,
     
    12481261                                    int *piFormatReturn)
    12491262{
    1250     RT_NOREF(pDisplay, pValReturn);
     1263    RT_NOREF2(pDisplay, pValReturn);
    12511264
    12521265    /* This may slightly overestimate the space needed. */
     
    12671280}
    12681281
     1282
    12691283/**
    12701284 * Does this atom correspond to one of the two selection types we support?
    1271  *
    12721285 * @param  widget   a valid Xt widget
    12731286 * @param  selType  the atom in question
     
    12801293
    12811294/**
    1282  * Removes a trailing nul character from a string by adjusting the string
     1295 * Remove a trailing nul character from a string by adjusting the string
    12831296 * length.  Some X11 applications don't like zero-terminated text...
    1284  *
    12851297 * @param  pText   the text in question
    12861298 * @param  pcText  the length of the text, adjusted on return
     
    12881300 */
    12891301static void clipTrimTrailingNul(XtPointer pText, unsigned long *pcText,
    1290                                 CLIPX11FORMATTARGET format)
     1302                                CLIPFORMAT format)
    12911303{
    12921304    AssertPtrReturnVoid(pText);
    12931305    AssertPtrReturnVoid(pcText);
    1294     AssertReturnVoid(   (format == CLIPX11FORMATTARGET_UTF8)
    1295                      || (format == CLIPX11FORMATTARGET_TEXT)
    1296                      || (format == CLIPX11FORMATTARGET_HTML));
     1306    AssertReturnVoid((format == UTF8) || (format == TEXT) || (format == HTML));
    12971307    if (((char *)pText)[*pcText - 1] == '\0')
    12981308       --(*pcText);
     
    13061316{
    13071317    int rc = VINF_SUCCESS;
    1308 
    1309     CLIPX11FORMATIDX    fmtIdx = clipGetFmtIdxFromAtom(pCtx, *atomTarget);
    1310     CLIPX11FORMATTARGET fmtTgt = clipGetTargetFmtFromFmtIdx(fmtIdx);
    1311 
    1312     if (   ((fmtTgt == CLIPX11FORMATTARGET_UTF8) || (fmtTgt == CLIPX11FORMATTARGET_TEXT))
     1318    CLIPX11FORMAT x11Format = clipFindX11FormatByAtom(pCtx, *atomTarget);
     1319    CLIPFORMAT format = clipRealFormatForX11Format(x11Format);
     1320    if (   ((format == UTF8) || (format == TEXT))
    13131321        && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT))
    13141322    {
    13151323        void *pv = NULL;
    13161324        uint32_t cb = 0;
    1317         rc = clipReadVBoxClipboard(pCtx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, &pv, &cb);
     1325        rc = clipReadVBoxClipboard(pCtx,
     1326                                   VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT,
     1327                                   &pv, &cb);
    13181328        if (RT_SUCCESS(rc) && (cb == 0))
    13191329            rc = VERR_NO_DATA;
    1320 
    1321         if (RT_SUCCESS(rc) && (   (fmtTgt == CLIPX11FORMATTARGET_UTF8)
    1322                                || (fmtTgt == CLIPX11FORMATTARGET_TEXT)))
    1323         {
     1330        if (RT_SUCCESS(rc) && ((format == UTF8) || (format == TEXT)))
    13241331            rc = clipWinTxtToUtf8ForX11CB(XtDisplay(pCtx->widget),
    13251332                                          (PRTUTF16)pv, cb, atomTarget,
    13261333                                          atomTypeReturn, pValReturn,
    13271334                                          pcLenReturn, piFormatReturn);
    1328         }
    1329 
    13301335        if (RT_SUCCESS(rc))
    1331             clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, fmtTgt);
    1332 
     1336            clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, format);
    13331337        RTMemFree(pv);
    13341338    }
    1335     else if (   (fmtTgt == CLIPX11FORMATTARGET_BMP)
     1339    else if (   (format == BMP)
    13361340             && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP))
    13371341    {
    13381342        void *pv = NULL;
    13391343        uint32_t cb = 0;
    1340         rc = clipReadVBoxClipboard(pCtx, VBOX_SHARED_CLIPBOARD_FMT_BITMAP, &pv, &cb);
     1344        rc = clipReadVBoxClipboard(pCtx,
     1345                                   VBOX_SHARED_CLIPBOARD_FMT_BITMAP,
     1346                                   &pv, &cb);
    13411347        if (RT_SUCCESS(rc) && (cb == 0))
    13421348            rc = VERR_NO_DATA;
    1343 
    1344         if (RT_SUCCESS(rc) && (fmtTgt == CLIPX11FORMATTARGET_BMP))
     1349        if (RT_SUCCESS(rc) && (format == BMP))
    13451350        {
    1346             /* Create a full BMP from it. */
     1351            /* Create a full BMP from it */
    13471352            rc = vboxClipboardDibToBmp(pv, cb, (void **)pValReturn,
    13481353                                       (size_t *)pcLenReturn);
     
    13561361            *piFormatReturn = 8;
    13571362        }
    1358 
    13591363        RTMemFree(pv);
    13601364    }
    1361     else if (   (fmtTgt == CLIPX11FORMATTARGET_HTML)
    1362              && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_HTML))
     1365    else if ( (format == HTML)
     1366            && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_HTML))
    13631367    {
    13641368        void *pv = NULL;
    13651369        uint32_t cb = 0;
    1366         rc = clipReadVBoxClipboard(pCtx, VBOX_SHARED_CLIPBOARD_FMT_HTML, &pv, &cb);
     1370        rc = clipReadVBoxClipboard(pCtx,
     1371                                   VBOX_SHARED_CLIPBOARD_FMT_HTML,
     1372                                   &pv, &cb);
    13671373        if (RT_SUCCESS(rc) && (cb == 0))
    13681374            rc = VERR_NO_DATA;
    1369 
    13701375        if (RT_SUCCESS(rc))
    13711376        {
     
    13791384            */
    13801385            rc = clipWinHTMLToUtf8ForX11CB(XtDisplay(pCtx->widget),
    1381                                            (const char*)pv, cb, atomTarget,
    1382                                            atomTypeReturn, pValReturn,
    1383                                            pcLenReturn, piFormatReturn);
     1386                (const char*)pv, cb, atomTarget,
     1387                atomTypeReturn, pValReturn,
     1388                pcLenReturn, piFormatReturn);
     1389
     1390
    13841391            if (RT_SUCCESS(rc))
    1385                 clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, fmtTgt);
    1386 
     1392                clipTrimTrailingNul(*(XtPointer *)pValReturn, pcLenReturn, format);
    13871393            RTMemFree(pv);
    13881394        }
    13891395    }
    1390 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    1391     else if (   (fmtTgt == CLIPX11FORMATTARGET_URI_LIST)
    1392              && (pCtx->vboxFormats & VBOX_SHARED_CLIPBOARD_FMT_URI_LIST))
    1393     {
    1394         /** Nothing to do here yet. */
    1395     }
    1396 #endif
    13971396    else
    13981397        rc = VERR_NOT_SUPPORTED;
     
    14011400
    14021401/**
    1403  * Returns VBox's clipboard data for an X11 client.
    1404  *
    1405  * @note  X11 backend code, callback for XtOwnSelection.
     1402 * Return VBox's clipboard data for an X11 client.
     1403 * @note  X11 backend code, callback for XtOwnSelection
    14061404 */
    14071405static Boolean clipXtConvertSelectionProc(Widget widget, Atom *atomSelection,
     
    14361434    CLIPBACKEND *pCtx;
    14371435    /** Formats supported by VBox */
    1438     VBOXCLIPBOARDFORMATS vboxFormats;
     1436    uint32_t formats;
    14391437} CLIPNEWVBOXFORMATS;
    14401438
     
    14501448
    14511449/**
    1452  * Takes possession of the X11 clipboard (and middle-button selection).
    1453  */
    1454 static void clipGrabX11CB(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMATS vboxFormats)
     1450 * Take possession of the X11 clipboard (and middle-button selection).
     1451 */
     1452static void clipGrabX11CB(CLIPBACKEND *pCtx, uint32_t u32Formats)
    14551453{
    14561454    if (XtOwnSelection(pCtx->widget, clipGetAtom(pCtx, "CLIPBOARD"),
    14571455                       CurrentTime, clipXtConvertSelectionProc, NULL, 0))
    14581456    {
    1459         pCtx->vboxFormats = vboxFormats;
    1460 
     1457        pCtx->vboxFormats = u32Formats;
    14611458        /* Grab the middle-button paste selection too. */
    14621459        XtOwnSelection(pCtx->widget, clipGetAtom(pCtx, "PRIMARY"),
     
    14781475 * Worker function for ClipAnnounceFormatToX11 which runs on the
    14791476 * event thread.
    1480  *
    14811477 * @param pUserData  Pointer to a CLIPNEWVBOXFORMATS structure containing
    14821478 *                   information about the VBox formats available and the
    14831479 *                   clipboard context data.  Must be freed by the worker.
    14841480 */
    1485 static void clipNewVBoxFormatsWorker(void *pUserData, void * /* interval */)
     1481static void clipNewVBoxFormatsWorker(void *pUserData,
     1482                                     void * /* interval */)
    14861483{
    14871484    CLIPNEWVBOXFORMATS *pFormats = (CLIPNEWVBOXFORMATS *)pUserData;
    1488 
    14891485    CLIPBACKEND *pCtx = pFormats->pCtx;
    1490     VBOXCLIPBOARDFORMAT vboxFormat = pFormats->vboxFormats;
    1491 
     1486    uint32_t u32Formats = pFormats->formats;
    14921487    RTMemFree(pFormats);
    1493 
    1494     LogRelFlowFunc (("vboxFormat=%RU32\n", vboxFormat));
    1495 
     1488    LogRelFlowFunc (("u32Formats=%d\n", u32Formats));
    14961489    clipInvalidateVBoxCBCache(pCtx);
    1497     clipGrabX11CB(pCtx, vboxFormat);
     1490    clipGrabX11CB(pCtx, u32Formats);
    14981491    clipResetX11Formats(pCtx);
    1499 
    15001492    LogRelFlowFunc(("returning\n"));
    15011493}
     
    15041496 * VBox is taking possession of the shared clipboard.
    15051497 *
    1506  * @param vboxFormats Clipboard formats that VBox is offering
     1498 * @param u32Formats Clipboard formats that VBox is offering
    15071499 * @note  X11 backend code
    15081500 */
    1509 int ClipAnnounceFormatToX11(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMATS vboxFormats)
     1501int ClipAnnounceFormatToX11(CLIPBACKEND *pCtx, uint32_t u32Formats)
    15101502{
    15111503    /*
     
    15151507        return VINF_SUCCESS;
    15161508
    1517     int rc;
    1518 
    15191509    /* This must be freed by the worker callback */
    15201510    CLIPNEWVBOXFORMATS *pFormats =
    15211511        (CLIPNEWVBOXFORMATS *) RTMemAlloc(sizeof(CLIPNEWVBOXFORMATS));
    1522 
    15231512    if (pFormats != NULL)  /* if it is we will soon have other problems */
    15241513    {
    15251514        pFormats->pCtx = pCtx;
    1526         pFormats->vboxFormats = vboxFormats;
     1515        pFormats->formats = u32Formats;
    15271516        clipQueueToEventThread(pCtx, clipNewVBoxFormatsWorker,
    15281517                               (XtPointer) pFormats);
    1529         rc = VINF_SUCCESS;
    1530     }
    1531     else
    1532         rc = VERR_NO_MEMORY;
    1533 
    1534     return rc;
    1535 }
    1536 
    1537 /**
    1538  * Massages generic Utf16 with CR end-of-lines into the format Windows expects
     1518    }
     1519
     1520    return VINF_SUCCESS;
     1521}
     1522
     1523/**
     1524 * Massage generic Utf16 with CR end-of-lines into the format Windows expects
    15391525 * and return the result in a RTMemAlloc allocated buffer.
    1540  *
    1541  * @returns IPRT status code.
    1542  * @param  pwcSrc     The source Utf16.
     1526 * @returns  IPRT status code
     1527 * @param  pwcSrc     The source Utf16
    15431528 * @param  cwcSrc     The number of 16bit elements in @a pwcSrc, not counting
    1544  *                    the terminating zero.
    1545  * @param  ppwszDest  Where to store the buffer address.
     1529 *                    the terminating zero
     1530 * @param  ppwszDest  Where to store the buffer address
    15461531 * @param  pcbDest    On success, where to store the number of bytes written.
    1547  *                    Undefined otherwise.  Optional.
     1532 *                    Undefined otherwise.  Optional
    15481533 */
    15491534static int clipUtf16ToWinTxt(RTUTF16 *pwcSrc, size_t cwcSrc,
     
    15841569
    15851570/**
    1586  * Converts Utf-8 text with CR end-of-lines into Utf-16 as Windows expects it
     1571 * Convert Utf-8 text with CR end-of-lines into Utf-16 as Windows expects it
    15871572 * and return the result in a RTMemAlloc allocated buffer.
    1588  *
    1589  * @returns  IPRT status code.
    1590  * @param  pcSrc      The source Utf-8.
     1573 * @returns  IPRT status code
     1574 * @param  pcSrc      The source Utf-8
    15911575 * @param  cbSrc      The size of the source in bytes, not counting the
    1592  *                    terminating zero.
    1593  * @param  ppwszDest  Where to store the buffer address.
     1576 *                    terminating zero
     1577 * @param  ppwszDest  Where to store the buffer address
    15941578 * @param  pcbDest    On success, where to store the number of bytes written.
    1595  *                    Undefined otherwise.  Optional.
     1579 *                    Undefined otherwise.  Optional
    15961580 */
    15971581static int clipUtf8ToWinTxt(const char *pcSrc, unsigned cbSrc,
     
    16181602
    16191603/**
    1620  * Converts Latin-1 text with CR end-of-lines into Utf-16 as Windows expects
     1604 * Convert Latin-1 text with CR end-of-lines into Utf-16 as Windows expects
    16211605 * it and return the result in a RTMemAlloc allocated buffer.
    1622  *
    1623  * @returns IPRT status code.
    1624  * @param  pcSrc      The source text.
     1606 * @returns  IPRT status code
     1607 * @param  pcSrc      The source text
    16251608 * @param  cbSrc      The size of the source in bytes, not counting the
    1626  *                    terminating zero.
    1627  * @param  ppwszDest  Where to store the buffer address.
     1609 *                    terminating zero
     1610 * @param  ppwszDest  Where to store the buffer address
    16281611 * @param  pcbDest    On success, where to store the number of bytes written.
    1629  *                    Undefined otherwise.  Optional.
     1612 *                    Undefined otherwise.  Optional
    16301613 */
    16311614static int clipLatin1ToWinTxt(char *pcSrc, unsigned cbSrc,
     
    16811664
    16821665/**
    1683  * Converts Utf16 text into UTF8 as Windows expects
    1684  * it and return the result in a RTMemAlloc allocated buffer.
    1685  *
    1686  * @returns  IPRT status code.
    1687  * @param  pcSrc      The source text.
    1688  * @param  cbSrc      The size of the source in bytes, not counting the
    1689  *                    terminating zero.
    1690  * @param  ppwszDest  Where to store the buffer address.
    1691  * @param  pcbDest    On success, where to store the number of bytes written.
    1692  *                    Undefined otherwise.  Optional.
    1693  */
     1666* Convert Utf16 text into UTF8 as Windows expects
     1667* it and return the result in a RTMemAlloc allocated buffer.
     1668* @returns  IPRT status code
     1669* @param  pcSrc      The source text
     1670* @param  cbSrc      The size of the source in bytes, not counting the
     1671*                    terminating zero
     1672* @param  ppwszDest  Where to store the buffer address
     1673* @param  pcbDest    On success, where to store the number of bytes written.
     1674*                    Undefined otherwise.  Optional
     1675*/
    16941676int  clipUTF16ToWinHTML(RTUTF16 *pwcBuf, size_t cb, char **ppszOut, uint32_t *pcOut)
    16951677{
     
    17521734}
    17531735
     1736
     1737
    17541738/** A structure containing information about where to store a request
    17551739 * for the X11 clipboard contents. */
    17561740struct _CLIPREADX11CBREQ
    17571741{
    1758     /** @todo r=andy Why all those different CLIPX11FORMATTARGET members? Shouldn't be one enough? */
    1759 
    17601742    /** The format VBox would like the data in */
    1761     VBOXCLIPBOARDFORMAT mFormat;
     1743    uint32_t mFormat;
    17621744    /** The text format we requested from X11 if we requested text */
    1763     CLIPX11FORMATIDX mTextFmtIdx;
     1745    CLIPX11FORMAT mTextFormat;
    17641746    /** The bitmap format we requested from X11 if we requested bitmap */
    1765     CLIPX11FORMATIDX mBitmapFmtIdx;
     1747    CLIPX11FORMAT mBitmapFormat;
    17661748    /** The HTML format we requested from X11 if we requested HTML */
    1767     CLIPX11FORMATIDX mHtmlFmtIdx;
    1768 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    1769     /** The URI list format we requested from X11 if we requested URI list */
    1770     CLIPX11FORMATIDX mURIListFmtIdx;
    1771 #endif
     1749    CLIPX11FORMAT mHtmlFormat;
    17721750    /** The clipboard context this request is associated with */
    17731751    CLIPBACKEND *mCtx;
     
    17791757
    17801758/**
    1781  * Converts the data obtained from the X11 clipboard to the required format,
     1759 * Convert the data obtained from the X11 clipboard to the required format,
    17821760 * place it in the buffer supplied and signal that data has arrived.
    17831761 * Convert the text obtained UTF-16LE with Windows EOLs.
    17841762 * Convert full BMP data to DIB format.
    1785  *
    17861763 * @note  X11 backend code, callback for XtGetSelectionValue, for use when
    17871764 *        the X11 clipboard contains a format we understand.
    17881765 */
    1789 static void clipConvertX11CB(void *pSvcCtxData, void *pvSrc, unsigned cbSrc)
    1790 {
    1791     CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *) pSvcCtxData;
     1766static void clipConvertX11CB(void *pClientData, void *pvSrc, unsigned cbSrc)
     1767{
     1768    CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *) pClientData;
    17921769    LogRelFlowFunc(("pReq->mFormat=%02X, pReq->mTextFormat=%u, "
    17931770                "pReq->mBitmapFormat=%u, pReq->mHtmlFormat=%u, pReq->mCtx=%p\n",
    1794                  pReq->mFormat, pReq->mTextFmtIdx, pReq->mBitmapFmtIdx,
    1795                  pReq->mHtmlFmtIdx, pReq->mCtx));
     1771                 pReq->mFormat, pReq->mTextFormat, pReq->mBitmapFormat,
     1772                 pReq->mHtmlFormat, pReq->mCtx));
    17961773    AssertPtr(pReq->mCtx);
    17971774    Assert(pReq->mFormat != 0);  /* sanity */
     
    18141791    {
    18151792        /* In which format is the clipboard data? */
    1816         switch (clipGetTargetFmtFromFmtIdx(pReq->mTextFmtIdx))
     1793        switch (clipRealFormatForX11Format(pReq->mTextFormat))
    18171794        {
    1818             case CLIPX11FORMATTARGET_UTF8:
    1819             case CLIPX11FORMATTARGET_TEXT:
     1795            case UTF8:
     1796            case TEXT:
    18201797            {
    18211798                /* If we are given broken Utf-8, we treat it as Latin1.  Is
     
    18371814    {
    18381815        /* In which format is the clipboard data? */
    1839         switch (clipGetTargetFmtFromFmtIdx(pReq->mBitmapFmtIdx))
     1816        switch (clipRealFormatForX11Format(pReq->mBitmapFormat))
    18401817        {
    1841             case CLIPX11FORMATTARGET_BMP:
     1818            case BMP:
    18421819            {
    18431820                const void *pDib;
     
    18651842    {
    18661843        /* In which format is the clipboard data? */
    1867         switch (clipGetTargetFmtFromFmtIdx(pReq->mHtmlFmtIdx))
     1844        switch (clipRealFormatForX11Format(pReq->mHtmlFormat))
    18681845        {
    1869             case CLIPX11FORMATTARGET_HTML:
     1846            case HTML:
    18701847            {
    18711848                /* The common VBox HTML encoding will be - Utf8
     
    19141891        }
    19151892    }
    1916 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    1917     else if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_URI_LIST)
    1918     {
    1919         // @todo
    1920     }
    1921 #endif
    19221893    else
    19231894        rc = VERR_NOT_IMPLEMENTED;
     
    19311902#ifndef TESTCASE
    19321903/**
    1933  * Converts the data obtained from the X11 clipboard to the required format,
     1904 * Convert the data obtained from the X11 clipboard to the required format,
    19341905 * place it in the buffer supplied and signal that data has arrived.
    19351906 * Convert the text obtained UTF-16LE with Windows EOLs.
    19361907 * Convert full BMP data to DIB format.
    1937  *
    19381908 * @note  X11 backend code, callback for XtGetSelectionValue, for use when
    19391909 *        the X11 clipboard contains a format we understand.
    19401910 */
    1941 static void cbConvertX11CB(Widget widget, XtPointer pSvcCtxData,
     1911static void cbConvertX11CB(Widget widget, XtPointer pClientData,
    19421912                           Atom * /* selection */, Atom *atomType,
    19431913                           XtPointer pvSrc, long unsigned int *pcLen,
    19441914                           int *piFormat)
    19451915{
    1946     RT_NOREF(widget);
     1916    RT_NOREF1(widget);
    19471917    if (*atomType == XT_CONVERT_FAIL) /* Xt timeout */
    1948         clipConvertX11CB(pSvcCtxData, NULL, 0);
     1918        clipConvertX11CB(pClientData, NULL, 0);
    19491919    else
    1950         clipConvertX11CB(pSvcCtxData, pvSrc, (*pcLen) * (*piFormat) / 8);
     1920        clipConvertX11CB(pClientData, pvSrc, (*pcLen) * (*piFormat) / 8);
    19511921
    19521922    XtFree((char *)pvSrc);
     
    19551925
    19561926#ifdef TESTCASE
    1957 static void testRequestData(CLIPBACKEND* pCtx, CLIPX11FORMATTARGET target,
     1927static void testRequestData(CLIPBACKEND* pCtx, CLIPX11FORMAT target,
    19581928                            void *closure);
    19591929#endif
    19601930
    1961 static void getSelectionValue(CLIPBACKEND *pCtx, CLIPX11FORMATIDX format,
     1931static void getSelectionValue(CLIPBACKEND *pCtx, CLIPX11FORMAT format,
    19621932                              CLIPREADX11CBREQ *pReq)
    19631933{
    19641934#ifndef TESTCASE
    19651935    XtGetSelectionValue(pCtx->widget, clipGetAtom(pCtx, "CLIPBOARD"),
    1966                         clipGetAtomFromFmtIdx(pCtx, format),
     1936                        clipAtomForX11Format(pCtx, format),
    19671937                        cbConvertX11CB,
    19681938                        reinterpret_cast<XtPointer>(pReq),
     
    19751945/** Worker function for ClipRequestDataFromX11 which runs on the event
    19761946 * thread. */
    1977 static void vboxClipboardReadX11Worker(void *pUserData, void * /* interval */)
     1947static void vboxClipboardReadX11Worker(void *pUserData,
     1948                                       void * /* interval */)
    19781949{
    19791950    CLIPREADX11CBREQ *pReq = (CLIPREADX11CBREQ *)pUserData;
     
    19861957    pCtx->fBusy = true;
    19871958    if (fBusy)
    1988     {
    19891959        /* If the clipboard is busy just fend off the request. */
    19901960        rc = VERR_TRY_AGAIN;
    1991     }
    19921961    else
    19931962#endif
     
    19971966         * VBox wants to read data in the given format.
    19981967         */
    1999         pReq->mTextFmtIdx = pCtx->X11TextFmtIdx;
    2000         if (pReq->mTextFmtIdx == CLIPX11FORMATIDX_NIL)
    2001         {
     1968        pReq->mTextFormat = pCtx->X11TextFormat;
     1969        if (pReq->mTextFormat == INVALID)
    20021970            /* VBox thinks we have data and we don't */
    20031971            rc = VERR_NO_DATA;
    2004         }
    2005         else
    2006         {
    2007             /* Send out a request for the data to the current clipboard owner */
    2008             getSelectionValue(pCtx, pCtx->X11TextFmtIdx, pReq);
    2009         }
    2010     }
    2011     else if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
    2012     {
    2013         pReq->mBitmapFmtIdx = pCtx->X11BitmapFmtIdx;
    2014         if (pReq->mBitmapFmtIdx == CLIPX11FORMATIDX_NIL)
    2015         {
    2016             /* VBox thinks we have data and we don't */
    2017             rc = VERR_NO_DATA;
    2018         }
    2019         else
    2020         {
    2021             /* Send out a request for the data to the current clipboard
    2022              * owner */
    2023             getSelectionValue(pCtx, pCtx->X11BitmapFmtIdx, pReq);
    2024         }
    2025     }
    2026     else if(pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_HTML)
    2027     {
    2028         /* Send out a request for the data to the current clipboard owner */
    2029         pReq->mHtmlFmtIdx = pCtx->X11HTMLFmtIdx;
    2030         if(pReq->mHtmlFmtIdx == CLIPX11FORMATIDX_NIL)
    2031         {
    2032              /* VBox thinks we have data and we don't */
    2033             rc = VERR_NO_DATA;
    2034         }
    20351972        else
    20361973            /* Send out a request for the data to the current clipboard
    20371974             * owner */
    2038             getSelectionValue(pCtx, pCtx->X11HTMLFmtIdx, pReq);
    2039     }
    2040 #ifdef VBOX_WITH_SHARED_CLIPBOARD_URI_LIST
    2041     else if(pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_URI_LIST)
    2042     {
    2043         /* Send out a request for the data to the current clipboard owner */
    2044         pReq->mURIListFmtIdx = pCtx->X11URListFmtIdx;
    2045         if(pReq->mURIListFmtIdx == CLIPX11FORMATIDX_NIL)
    2046         {
     1975            getSelectionValue(pCtx, pCtx->X11TextFormat, pReq);
     1976    }
     1977    else if (pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
     1978    {
     1979        pReq->mBitmapFormat = pCtx->X11BitmapFormat;
     1980        if (pReq->mBitmapFormat == INVALID)
     1981            /* VBox thinks we have data and we don't */
     1982            rc = VERR_NO_DATA;
     1983        else
     1984            /* Send out a request for the data to the current clipboard
     1985             * owner */
     1986            getSelectionValue(pCtx, pCtx->X11BitmapFormat, pReq);
     1987    }
     1988    else if(pReq->mFormat == VBOX_SHARED_CLIPBOARD_FMT_HTML)
     1989    {
     1990        /* Send out a request for the data to the current clipboard
     1991             * owner */
     1992        pReq->mHtmlFormat = pCtx->X11HTMLFormat;
     1993        if(pReq->mHtmlFormat == INVALID)
    20471994                    /* VBox thinks we have data and we don't */
    20481995            rc = VERR_NO_DATA;
    2049         }
    20501996        else
    2051         {
    2052             /* Send out a request for the data to the current clipboard owner */
    2053             getSelectionValue(pCtx, pCtx->X11HTMLFmtIdx, pReq);
    2054         }
    2055     }
    2056 #endif
     1997            /* Send out a request for the data to the current clipboard
     1998             * owner */
     1999            getSelectionValue(pCtx, pCtx->X11HTMLFormat, pReq);
     2000    }
    20572001    else
    20582002    {
     
    20622006#endif
    20632007    }
    2064 
    20652008    if (RT_FAILURE(rc))
    20662009    {
     
    20712014        RTMemFree(pReq);
    20722015    }
    2073 
    20742016    LogRelFlowFunc(("status %Rrc\n", rc));
    20752017}
     
    20782020 * Called when VBox wants to read the X11 clipboard.
    20792021 *
    2080  * @returns IPRT status code.
    2081  * @param  pCtx      Context data for the clipboard backend.
    2082  * @param  vboxFormat The format that the VBox would like to receive the data in.
    2083  * @param  pv        Where to write the data to.
    2084  * @param  cb        The size of the buffer to write the data to.
    2085  * @param  pcbActual Where to write the actual size of the written data.
    2086  *
    2087  * @note   We allocate a request structure which must be freed by the worker.
    2088  */
    2089 int ClipRequestDataFromX11(CLIPBACKEND *pCtx, VBOXCLIPBOARDFORMAT vboxFormat,
     2022 * @returns iprt status code
     2023 * @param  pCtx      Context data for the clipboard backend
     2024 * @param  u32Format The format that the VBox would like to receive the data
     2025 *                   in
     2026 * @param  pv        Where to write the data to
     2027 * @param  cb        The size of the buffer to write the data to
     2028 * @param  pcbActual Where to write the actual size of the written data
     2029 * @note   We allocate a request structure which must be freed by the worker
     2030 */
     2031int ClipRequestDataFromX11(CLIPBACKEND *pCtx, uint32_t u32Format,
    20902032                           CLIPREADCBREQ *pReq)
    20912033{
     
    21022044    else
    21032045    {
    2104         pX11Req->mFormat = vboxFormat;
     2046        pX11Req->mFormat = u32Format;
    21052047        pX11Req->mCtx = pCtx;
    21062048        pX11Req->mReq = pReq;
     
    21762118
    21772119/* Return the data in the simulated VBox clipboard. */
    2178 int ClipRequestDataForX11(VBOXCLIPBOARDCONTEXT *pCtx, VBOXCLIPBOARDFORMAT vboxFormat, void **ppv, uint32_t *pcb)
    2179 {
    2180     RT_NOREF(pCtx, vboxFormat);
     2120int ClipRequestDataForX11(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format, void **ppv, uint32_t *pcb)
     2121{
     2122    RT_NOREF2(pCtx, u32Format);
    21812123    *pcb = g_vboxDatacb;
    21822124    if (g_vboxDatapv != NULL)
     
    21912133
    21922134Display *XtDisplay(Widget w)
    2193 { RT_NOREF(w); return (Display *) 0xffff; }
    2194 
    2195 void XtAppSetExitFlag(XtAppContext app_context) { RT_NOREF(app_context); }
    2196 
    2197 void XtDestroyWidget(Widget w) { RT_NOREF(w); }
     2135{ NOREF(w); return (Display *) 0xffff; }
     2136
     2137void XtAppSetExitFlag(XtAppContext app_context) { NOREF(app_context); }
     2138
     2139void XtDestroyWidget(Widget w) { NOREF(w); }
    21982140
    21992141XtAppContext XtCreateApplicationContext(void) { return (XtAppContext)0xffff; }
    22002142
    2201 void XtDestroyApplicationContext(XtAppContext app_context) { RT_NOREF(app_context); }
     2143void XtDestroyApplicationContext(XtAppContext app_context) { NOREF(app_context); }
    22022144
    22032145void XtToolkitInitialize(void) {}
     
    22232165}
    22242166
    2225 void XtSetMappedWhenManaged(Widget widget, _XtBoolean mapped_when_managed) { RT_NOREF(widget, mapped_when_managed); }
    2226 
    2227 void XtRealizeWidget(Widget widget) { RT_NOREF(widget); }
     2167void XtSetMappedWhenManaged(Widget widget, _XtBoolean mapped_when_managed) { RT_NOREF2(widget, mapped_when_managed); }
     2168
     2169void XtRealizeWidget(Widget widget) { NOREF(widget); }
    22282170
    22292171XtInputId XtAppAddInput(XtAppContext app_context, int source, XtPointer condition, XtInputCallbackProc proc, XtPointer closure)
     
    22552197
    22562198/* Take a request for the targets we are currently offering. */
    2257 static CLIPX11FORMATTARGET g_selTargets[10] = { 0 };
     2199static CLIPX11FORMAT g_selTargets[10] = { 0 };
    22582200static size_t g_cTargets = 0;
    22592201
     
    22702212static int g_selFormat = 0;
    22712213
    2272 void testRequestData(CLIPBACKEND *pCtx, CLIPX11FORMATTARGET target, void *closure)
    2273 {
    2274     RT_NOREF(pCtx);
     2214void testRequestData(CLIPBACKEND *pCtx, CLIPX11FORMAT target, void *closure)
     2215{
     2216    RT_NOREF1(pCtx);
    22752217    unsigned long count = 0;
    22762218    int format = 0;
     
    22992241void ClipReportX11Formats(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Formats)
    23002242{
    2301     RT_NOREF(pCtx);
     2243    RT_NOREF1(pCtx);
    23022244    g_fX11Formats = u32Formats;
    23032245}
     
    23282270                       XtSelectionDoneProc done)
    23292271{
    2330     RT_NOREF(widget, time);
     2272    RT_NOREF2(widget, time);
    23312273    if (selection != XInternAtom(NULL, "CLIPBOARD", 0))
    23322274        return True;  /* We don't really care about this. */
     
    23792321{
    23802322    Atom clipAtom = XInternAtom(NULL, "CLIPBOARD", 0);
    2381     g_selTargets[0] = clipGetFmtIdxFromAtomText(pcszTarget);
     2323    g_selTargets[0] = clipFindX11FormatByAtomText(pcszTarget);
    23822324    g_cTargets = 1;
    23832325    g_selType = type;
     
    24052347char *XGetAtomName(Display *display, Atom atom)
    24062348{
    2407     RT_NOREF(display);
     2349    RT_NOREF1(display);
    24082350    AssertReturn((unsigned)atom < RT_ELEMENTS(g_aFormats) + 1, NULL);
    24092351    const char *pcszName = NULL;
     
    24472389void ClipCompleteDataRequestFromX11(VBOXCLIPBOARDCONTEXT *pCtx, int rc, CLIPREADCBREQ *pReq, void *pv, uint32_t cb)
    24482390{
    2449     RT_NOREF(pCtx);
     2391    RT_NOREF1(pCtx);
    24502392    if (cb <= MAX_BUF_SIZE)
    24512393    {
     
    26002542static void testStringFromVBox(RTTEST hTest, CLIPBACKEND *pCtx, const char *pcszTarget, Atom typeExp,  const char *valueExp)
    26012543{
    2602     RT_NOREF(pCtx);
     2544    RT_NOREF1(pCtx);
    26032545    bool retval = false;
    26042546    Atom type;
     
    26412583static void testStringFromVBoxFailed(RTTEST hTest, CLIPBACKEND *pCtx, const char *pcszTarget)
    26422584{
    2643     RT_NOREF(pCtx);
     2585    RT_NOREF1(pCtx);
    26442586    Atom type;
    26452587    XtPointer value = NULL;
     
    26562598static void testNoSelectionOwnership(CLIPBACKEND *pCtx, const char *pcszTestCtx)
    26572599{
    2658     RT_NOREF(pCtx);
     2600    RT_NOREF1(pCtx);
    26592601    RTTESTI_CHECK_MSG(!g_ownsSel, ("context: %s\n", pcszTestCtx));
    26602602}
     
    26822624        clipSendTargetUpdate(pCtx);
    26832625        if (clipQueryFormats() == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
    2684             RTTestFailed(hTest, "Failed to report targets after bad host request\n");
     2626            RTTestFailed(hTest, "Failed to report targets after bad host request.\n");
    26852627    }
    26862628}
     
    29492891void ClipReportX11Formats(VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Formats)
    29502892{
    2951     RT_NOREF(pCtx, u32Formats);
     2893    RT_NOREF2(pCtx, u32Formats);
    29522894}
    29532895
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