~oem-solutions-group/unity-2d/clutter-1.0

« back to all changes in this revision

Viewing changes to clutter/eglnative/clutter-event-egl.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2010-03-21 13:27:56 UTC
  • mto: (2.1.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100321132756-nf8yd30yxo3zzwcm
Tags: upstream-1.2.2
ImportĀ upstreamĀ versionĀ 1.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 * Lesser General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with this library; if not, write to the
18
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
 
 * Boston, MA 02111-1307, USA.
 
17
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 
18
 *
 
19
 *
20
20
 */
21
21
 
22
22
#ifdef HAVE_CONFIG_H
47
47
{
48
48
  GSource source;
49
49
 
50
 
  ClutterBackend *backend;
51
 
  GPollFD         event_poll_fd;
 
50
  ClutterBackendEGL *backend;
 
51
  GPollFD event_poll_fd;
 
52
 
52
53
#ifdef HAVE_TSLIB
53
54
  struct tsdev   *ts_device;
54
55
#endif
71
72
};
72
73
 
73
74
static GSource *
74
 
clutter_event_source_new (ClutterBackend *backend)
 
75
clutter_event_source_new (ClutterBackendEGL *backend)
75
76
{
76
77
  GSource *source = g_source_new (&event_funcs, sizeof (ClutterEventSource));
77
78
  ClutterEventSource *event_source = (ClutterEventSource *) source;
92
93
}
93
94
 
94
95
void
95
 
_clutter_events_init (ClutterBackend *backend)
 
96
_clutter_events_egl_init (ClutterBackendEGL *backend_egl)
96
97
{
97
 
  ClutterBackendEGL  *backend_egl = CLUTTER_BACKEND_EGL (backend);
98
 
  GSource            *source;
99
98
  ClutterEventSource *event_source;
 
99
  const char *device_name;
 
100
  GSource *source;
100
101
 
101
102
  CLUTTER_NOTE (EVENT, "Starting timer");
102
103
  g_assert (backend_egl->event_timer != NULL);
103
104
  g_timer_start (backend_egl->event_timer);
104
105
 
105
106
#ifdef HAVE_TSLIB
106
 
  /* FIXME LEAK on error paths */
107
 
  source = backend_egl->event_source = clutter_event_source_new (backend);
 
107
  source = backend_egl->event_source = clutter_event_source_new (backend_egl);
108
108
  event_source = (ClutterEventSource *) source;
109
109
 
110
 
  event_source->ts_device = ts_open (g_getenv ("TSLIB_TSDEVICE"), 0);
 
110
  device_name = g_getenv ("TSLIB_TSDEVICE");
 
111
  if (device_name == NULL || device_name[0] == '\0')
 
112
    {
 
113
      g_warning ("No device for TSLib has been defined; please set the "
 
114
                 "TSLIB_TSDEVICE environment variable to define a touch "
 
115
                 "screen device to be used with Clutter.");
 
116
      g_source_unref (source);
 
117
      return;
 
118
    }
111
119
 
 
120
  event_source->ts_device = ts_open (device_name, 0);
112
121
  if (event_source->ts_device)
113
122
    {
114
 
      CLUTTER_NOTE (EVENT, "Opened '%s'", g_getenv ("TSLIB_TSDEVICE"));
 
123
      CLUTTER_NOTE (EVENT, "Opened '%s'", device_name);
115
124
 
116
125
      if (ts_config (event_source->ts_device))
117
126
        {
118
 
          g_warning ("ts_config() failed");
 
127
          g_warning ("Closing device '%s': ts_config() failed", device_name);
119
128
          ts_close (event_source->ts_device);
 
129
          g_source_unref (source);
120
130
          return;
121
131
        }
122
132
 
123
133
      g_source_set_priority (source, CLUTTER_PRIORITY_EVENTS);
124
 
      event_source->event_poll_fd.fd = ts_fd(event_source->ts_device);
 
134
      event_source->event_poll_fd.fd = ts_fd (event_source->ts_device);
125
135
      event_source->event_poll_fd.events = G_IO_IN;
126
136
 
127
137
      event_sources = g_list_prepend (event_sources, event_source);
131
141
      g_source_attach (source, NULL);
132
142
    }
133
143
  else
134
 
    g_warning ("ts_open() failed opening %s'",
135
 
               g_getenv("TSLIB_TSDEVICE") ?
136
 
                 g_getenv("TSLIB_TSDEVICE") : "None, TSLIB_TSDEVICE not set");
137
 
#endif
 
144
    {
 
145
      g_warning ("Unable to open '%s'", device_name);
 
146
      g_source_unref (source);
 
147
    }
 
148
#endif /* HAVE_TSLIB */
138
149
}
139
150
 
140
151
void
141
 
_clutter_events_uninit (ClutterBackend *backend)
 
152
_clutter_events_egl_uninit (ClutterBackendEGL *backend_egl)
142
153
{
143
 
  ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
144
 
 
145
 
  if (backend_egl->event_timer)
 
154
  if (backend_egl->event_timer != NULL)
146
155
    {
147
156
      CLUTTER_NOTE (EVENT, "Stopping the timer");
148
157
      g_timer_stop (backend_egl->event_timer);
149
158
    }
150
159
 
151
 
  if (backend_egl->event_source)
 
160
  if (backend_egl->event_source != NULL)
152
161
    {
153
162
      CLUTTER_NOTE (EVENT, "Destroying the event source");
154
163
 
157
166
 
158
167
#ifdef HAVE_TSLIB
159
168
      ts_close (event_source->ts_device);
160
 
      event_sources = g_list_remove (event_sources,
161
 
                                     backend_egl->event_source);
162
 
#endif
 
169
      event_sources = g_list_remove (event_sources, backend_egl->event_source);
 
170
#endif /* HAVE_TSLIB */
 
171
 
163
172
      g_source_destroy (backend_egl->event_source);
164
173
      g_source_unref (backend_egl->event_source);
165
174
      backend_egl->event_source = NULL;
170
179
clutter_event_prepare (GSource *source,
171
180
                       gint    *timeout)
172
181
{
173
 
  ClutterBackend *backend = ((ClutterEventSource *) source)->backend;
174
182
  gboolean retval;
175
183
 
176
184
  clutter_threads_enter ();
187
195
clutter_event_check (GSource *source)
188
196
{
189
197
  ClutterEventSource *event_source = (ClutterEventSource *) source;
190
 
  ClutterBackend *backend = event_source->backend;
191
198
  gboolean retval;
192
199
 
193
200
  clutter_threads_enter ();
205
212
                        GSourceFunc  callback,
206
213
                        gpointer     user_data)
207
214
{
208
 
  ClutterBackend     *backend = ((ClutterEventSource *) source)->backend;
209
215
  ClutterEventSource *event_source = (ClutterEventSource *) source;
210
 
  ClutterEvent       *event;
 
216
  ClutterEvent *event;
211
217
#ifdef HAVE_TSLIB
212
218
  struct ts_sample    tsevent;
213
219
#endif
222
228
#ifdef HAVE_TSLIB
223
229
  /* FIXME while would be better here but need to deal with lockups */
224
230
  if ((!clutter_events_pending()) &&
225
 
        (ts_read(event_source->ts_device, &tsevent, 1) == 1))
 
231
      (ts_read(event_source->ts_device, &tsevent, 1) == 1))
226
232
    {
227
233
      /* Avoid sending too many events which are just pressure changes.
228
 
       * We dont current handle pressure in events (FIXME) and thus
 
234
       *
 
235
       * FIXME - We don't current handle pressure in events and thus
229
236
       * event_button_generate gets confused generating lots of double
230
237
       * and triple clicks.
231
238
      */
266
273
 
267
274
      g_queue_push_head (clutter_context->events_queue, event);
268
275
    }
269
 
#endif
 
276
#endif /* HAVE_TSLIB */
270
277
 
271
278
  /* Pop an event off the queue if any */
272
279
  event = clutter_event_get ();