Module: SDL2::Clipboard

Defined in:
clipboard.c,
clipboard.c

Overview

This module has clipboard manipulating functions.

Class Method Summary collapse

Class Method Details

.has_text?Boolean

Return true if the clipboard has any text.

Returns:

  • (Boolean)


49
50
51
52
# File 'clipboard.c', line 49

static VALUE Clipboard_s_has_text_p(VALUE self)
{
    return INT2BOOL(SDL_HasClipboardText());
}

.textString?

Get the text from the clipboard.

Returns:

  • (String)

    a string in the clipboard

  • (nil)

    if the clipboard is empty



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'clipboard.c', line 17

static VALUE Clipboard_s_text(VALUE self)
{
    if (SDL_HasClipboardText()) {
        char* text = SDL_GetClipboardText();
        VALUE str;
        if (!text)
            SDL_ERROR();
        str = utf8str_new_cstr(text);
        SDL_free(text);
        return str;
    } else {
        return Qnil;
    }
}

.text=(text) ⇒ String

Set the text in the clipboard.

Parameters:

  • text (String)

    a new text

Returns:

  • (String)

    text



39
40
41
42
43
# File 'clipboard.c', line 39

static VALUE Clipboard_s_set_text(VALUE self, VALUE text)
{
    HANDLE_ERROR(SDL_SetClipboardText(StringValueCStr(text)));
    return text;
}