src/video/wayland/SDL_waylandclipboard.c
author Ryan C. Gordon
Mon, 23 Jan 2017 12:06:10 -0500
changeset 10837 c2f241c2f6ad
parent 10737 3406a0f8b041
child 11811 5d94cb6b24d3
permissions -rw-r--r--
audio: Fix same bug as last commit, but for _mm_bslli_si128 vs _mm_slli_si128.
slouken@10583
     1
/*
slouken@10583
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@10583
     4
slouken@10583
     5
  This software is provided 'as-is', without any express or implied
slouken@10583
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@10583
     7
  arising from the use of this software.
slouken@10583
     8
slouken@10583
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@10583
    10
  including commercial applications, and to alter it and redistribute it
slouken@10583
    11
  freely, subject to the following restrictions:
slouken@10583
    12
slouken@10583
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@10583
    14
     claim that you wrote the original software. If you use this software
slouken@10583
    15
     in a product, an acknowledgment in the product documentation would be
slouken@10583
    16
     appreciated but is not required.
slouken@10583
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@10583
    18
     misrepresented as being the original software.
slouken@10583
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@10583
    20
*/
slouken@10583
    21
#include "../../SDL_internal.h"
slouken@10583
    22
slouken@10583
    23
#if SDL_VIDEO_DRIVER_WAYLAND
slouken@10583
    24
slouken@10583
    25
#include "SDL_waylanddatamanager.h"
slouken@10583
    26
#include "SDL_waylandevents_c.h"
slouken@10583
    27
slouken@10583
    28
int
slouken@10583
    29
Wayland_SetClipboardText(_THIS, const char *text)
slouken@10583
    30
{
slouken@10583
    31
    SDL_VideoData *video_data = NULL;
slouken@10583
    32
    SDL_WaylandDataDevice *data_device = NULL;
slouken@10583
    33
    
slouken@10583
    34
    int status = 0;
slouken@10583
    35
 
slouken@10583
    36
    if (_this == NULL || _this->driverdata == NULL) {
slouken@10583
    37
        status = SDL_SetError("Video driver uninitialized");
slouken@10583
    38
    } else {
slouken@10583
    39
        video_data = _this->driverdata;
slouken@10583
    40
        /* TODO: Support more than one seat */ 
slouken@10583
    41
        data_device = Wayland_get_data_device(video_data->input);
slouken@10583
    42
        if (text[0] != '\0') {
slouken@10583
    43
            SDL_WaylandDataSource* source = Wayland_data_source_create(_this);
slouken@10583
    44
            Wayland_data_source_add_data(source, TEXT_MIME, text,
slouken@10583
    45
                                         strlen(text) + 1); 
slouken@10583
    46
slouken@10583
    47
            status = Wayland_data_device_set_selection(data_device, source);
slouken@10583
    48
            if (status != 0) {
slouken@10583
    49
                Wayland_data_source_destroy(source);
slouken@10583
    50
            }
slouken@10583
    51
        } else {
slouken@10583
    52
            status = Wayland_data_device_clear_selection(data_device);
slouken@10583
    53
        }
slouken@10583
    54
    }
slouken@10583
    55
slouken@10583
    56
    return status;
slouken@10583
    57
}
slouken@10583
    58
slouken@10583
    59
char *
slouken@10583
    60
Wayland_GetClipboardText(_THIS)
slouken@10583
    61
{
slouken@10583
    62
    SDL_VideoData *video_data = NULL;
slouken@10583
    63
    SDL_WaylandDataDevice *data_device = NULL;
slouken@10583
    64
slouken@10583
    65
    char *text = NULL;
slouken@10583
    66
slouken@10583
    67
    void *buffer = NULL;
slouken@10583
    68
    size_t length = 0;
slouken@10583
    69
 
slouken@10583
    70
    if (_this == NULL || _this->driverdata == NULL) {
slouken@10583
    71
        SDL_SetError("Video driver uninitialized");
slouken@10583
    72
    } else {
slouken@10583
    73
        video_data = _this->driverdata;
slouken@10583
    74
        /* TODO: Support more than one seat */ 
slouken@10583
    75
        data_device = Wayland_get_data_device(video_data->input);
slouken@10583
    76
        if (data_device->selection_offer != NULL) {
slouken@10583
    77
            buffer = Wayland_data_offer_receive(data_device->selection_offer,
slouken@10583
    78
                                                &length, TEXT_MIME, SDL_TRUE);
slouken@10583
    79
            if (length > 0) {
slouken@10583
    80
                text = (char*) buffer;
slouken@10583
    81
            } 
slouken@10583
    82
        } else if (data_device->selection_source != NULL) {
slouken@10583
    83
            buffer = Wayland_data_source_get_data(data_device->selection_source,
slouken@10583
    84
                                                  &length, TEXT_MIME, SDL_TRUE);
slouken@10583
    85
            if (length > 0) {
slouken@10583
    86
                text = (char*) buffer;
slouken@10583
    87
            } 
slouken@10583
    88
        }
slouken@10583
    89
    }
slouken@10583
    90
slouken@10583
    91
    if (text == NULL) {
slouken@10583
    92
        text = SDL_strdup("");
slouken@10583
    93
    }
slouken@10583
    94
slouken@10583
    95
    return text;
slouken@10583
    96
}
slouken@10583
    97
slouken@10583
    98
SDL_bool
slouken@10583
    99
Wayland_HasClipboardText(_THIS)
slouken@10583
   100
{
slouken@10583
   101
    SDL_VideoData *video_data = NULL;
slouken@10583
   102
    SDL_WaylandDataDevice *data_device = NULL;
slouken@10583
   103
slouken@10583
   104
    SDL_bool result = SDL_FALSE;    
slouken@10583
   105
    if (_this == NULL || _this->driverdata == NULL) {
slouken@10583
   106
        SDL_SetError("Video driver uninitialized");
slouken@10583
   107
    } else {
slouken@10583
   108
        video_data = _this->driverdata;
slouken@10583
   109
        data_device = Wayland_get_data_device(video_data->input);
slouken@10583
   110
        if (data_device != NULL && Wayland_data_offer_has_mime(
slouken@10583
   111
                data_device->selection_offer, TEXT_MIME)) {
slouken@10583
   112
            result = SDL_TRUE;
slouken@10583
   113
        } else if(data_device != NULL && Wayland_data_source_has_mime(
slouken@10583
   114
                data_device->selection_source, TEXT_MIME)) {
slouken@10583
   115
            result = SDL_TRUE;
slouken@10583
   116
        }
slouken@10583
   117
    }
slouken@10583
   118
    return result;
slouken@10583
   119
}
slouken@10583
   120
slouken@10583
   121
#endif /* SDL_VIDEO_DRIVER_WAYLAND */
slouken@10583
   122
slouken@10583
   123
/* vi: set ts=4 sw=4 expandtab: */