| 1 |
/* |
| 2 |
* Clutter. |
| 3 |
* |
| 4 |
* An OpenGL based 'interactive canvas' library. |
| 5 |
* |
| 6 |
* Copyright (C) 2010 Intel Corporation. |
| 7 |
* |
| 8 |
* This library is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Lesser General Public |
| 10 |
* License as published by the Free Software Foundation; either |
| 11 |
* version 2 of the License, or (at your option) any later version. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public |
| 19 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
* Authors: |
| 22 |
* Matthew Allum |
| 23 |
* Robert Bragg |
| 24 |
* Kristian Høgsberg |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifdef HAVE_CONFIG_H |
| 28 |
#include "config.h" |
| 29 |
#endif |
| 30 |
|
| 31 |
#include <stdint.h> |
| 32 |
#include <stdlib.h> |
| 33 |
#include <wayland-client.h> |
| 34 |
|
| 35 |
#include "clutter-event.h" |
| 36 |
#include "clutter-main.h" |
| 37 |
#include "clutter-private.h" |
| 38 |
#include "clutter-stage-private.h" |
| 39 |
|
| 40 |
#include "clutter-event-wayland.h" |
| 41 |
|
| 42 |
typedef struct _ClutterEventSourceWayland |
| 43 |
{ |
| 44 |
GSource source; |
| 45 |
struct wl_display *display; |
| 46 |
} ClutterEventSourceWayland; |
| 47 |
|
| 48 |
static gboolean |
| 49 |
clutter_event_source_wayland_prepare (GSource *base, gint *timeout) |
| 50 |
{ |
| 51 |
ClutterEventSourceWayland *source = (ClutterEventSourceWayland *) base; |
| 52 |
gboolean retval; |
| 53 |
|
| 54 |
_clutter_threads_acquire_lock (); |
| 55 |
|
| 56 |
*timeout = -1; |
| 57 |
|
| 58 |
/* We have to add/remove the GPollFD if we want to update our |
| 59 |
* poll event mask dynamically. Instead, let's just flush all |
| 60 |
* writes on idle */ |
| 61 |
wl_display_flush (source->display); |
| 62 |
|
| 63 |
retval = clutter_events_pending (); |
| 64 |
|
| 65 |
_clutter_threads_release_lock (); |
| 66 |
|
| 67 |
return retval; |
| 68 |
} |
| 69 |
|
| 70 |
static gboolean |
| 71 |
clutter_event_source_wayland_check (GSource *base) |
| 72 |
{ |
| 73 |
gboolean retval; |
| 74 |
|
| 75 |
_clutter_threads_acquire_lock (); |
| 76 |
|
| 77 |
retval = clutter_events_pending (); |
| 78 |
|
| 79 |
_clutter_threads_release_lock (); |
| 80 |
|
| 81 |
return retval; |
| 82 |
} |
| 83 |
|
| 84 |
static gboolean |
| 85 |
clutter_event_source_wayland_dispatch (GSource *base, |
| 86 |
GSourceFunc callback, |
| 87 |
gpointer data) |
| 88 |
{ |
| 89 |
ClutterEvent *event; |
| 90 |
|
| 91 |
_clutter_threads_acquire_lock (); |
| 92 |
|
| 93 |
event = clutter_event_get (); |
| 94 |
|
| 95 |
if (event) |
| 96 |
{ |
| 97 |
/* forward the event into clutter for emission etc. */ |
| 98 |
_clutter_stage_queue_event (event->any.stage, event, FALSE); |
| 99 |
} |
| 100 |
|
| 101 |
_clutter_threads_release_lock (); |
| 102 |
|
| 103 |
return TRUE; |
| 104 |
} |
| 105 |
|
| 106 |
static GSourceFuncs clutter_event_source_wayland_funcs = { |
| 107 |
clutter_event_source_wayland_prepare, |
| 108 |
clutter_event_source_wayland_check, |
| 109 |
clutter_event_source_wayland_dispatch, |
| 110 |
NULL |
| 111 |
}; |
| 112 |
|
| 113 |
|
| 114 |
GSource * |
| 115 |
_clutter_event_source_wayland_new (struct wl_display *display) |
| 116 |
{ |
| 117 |
ClutterEventSourceWayland *source; |
| 118 |
|
| 119 |
source = (ClutterEventSourceWayland *) |
| 120 |
g_source_new (&clutter_event_source_wayland_funcs, |
| 121 |
sizeof (ClutterEventSourceWayland)); |
| 122 |
source->display = display; |
| 123 |
|
| 124 |
return &source->source; |
| 125 |
} |