| 1 |
/* Clutter. |
| 2 |
* An OpenGL based 'interactive canvas' library. |
| 3 |
* Authored By Matthew Allum <[email protected]> |
| 4 |
* Copyright (C) 2006-2007 OpenedHand |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifdef HAVE_CONFIG_H |
| 23 |
#include "config.h" |
| 24 |
#endif |
| 25 |
|
| 26 |
#include <glib/gi18n-lib.h> |
| 27 |
|
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#include <unistd.h> |
| 31 |
|
| 32 |
#include <sys/ioctl.h> |
| 33 |
#include <sys/stat.h> |
| 34 |
#include <sys/types.h> |
| 35 |
|
| 36 |
#include <fcntl.h> |
| 37 |
|
| 38 |
#include <errno.h> |
| 39 |
|
| 40 |
#include "clutter-backend-x11.h" |
| 41 |
#include "clutter-device-manager-core-x11.h" |
| 42 |
#include "clutter-device-manager-xi2.h" |
| 43 |
#include "clutter-settings-x11.h" |
| 44 |
#include "clutter-stage-x11.h" |
| 45 |
#include "clutter-x11.h" |
| 46 |
|
| 47 |
#include "xsettings/xsettings-common.h" |
| 48 |
|
| 49 |
#if HAVE_XCOMPOSITE |
| 50 |
#include <X11/extensions/Xcomposite.h> |
| 51 |
#endif |
| 52 |
|
| 53 |
#if HAVE_XINPUT_2 |
| 54 |
#include <X11/extensions/XInput2.h> |
| 55 |
#endif |
| 56 |
|
| 57 |
#include <cogl/cogl.h> |
| 58 |
#include <cogl/cogl-xlib.h> |
| 59 |
|
| 60 |
#include "clutter-backend.h" |
| 61 |
#include "clutter-debug.h" |
| 62 |
#include "clutter-device-manager-private.h" |
| 63 |
#include "clutter-event-private.h" |
| 64 |
#include "clutter-main.h" |
| 65 |
#include "clutter-private.h" |
| 66 |
#include "clutter-settings-private.h" |
| 67 |
|
| 68 |
G_DEFINE_TYPE (ClutterBackendX11, clutter_backend_x11, CLUTTER_TYPE_BACKEND) |
| 69 |
|
| 70 |
GType |
| 71 |
clutter_x11_filter_return_get_type (void) |
| 72 |
{ |
| 73 |
static volatile gsize g_define_type__volatile; |
| 74 |
|
| 75 |
if (g_once_init_enter (&g_define_type__volatile)) |
| 76 |
{ |
| 77 |
static const GEnumValue values[] = { |
| 78 |
{ CLUTTER_X11_FILTER_CONTINUE, "CLUTTER_X11_FILTER_CONTINUE", "continue" }, |
| 79 |
{ CLUTTER_X11_FILTER_TRANSLATE, "CLUTTER_X11_FILTER_TRANSLATE", "translate" }, |
| 80 |
{ CLUTTER_X11_FILTER_REMOVE, "CLUTTER_X11_FILTER_REMOVE", "remove" }, |
| 81 |
{ 0, NULL, NULL }, |
| 82 |
}; |
| 83 |
|
| 84 |
GType g_define_type = |
| 85 |
g_enum_register_static (g_intern_static_string ("ClutterX11FilterReturn"), values); |
| 86 |
|
| 87 |
g_once_init_leave (&g_define_type__volatile, g_define_type); |
| 88 |
} |
| 89 |
|
| 90 |
return g_define_type__volatile; |
| 91 |
} |
| 92 |
|
| 93 |
/* atoms; remember to add the code that assigns the atom value to |
| 94 |
* the member of the ClutterBackendX11 structure if you add an |
| 95 |
* atom name here. do not change the order! |
| 96 |
*/ |
| 97 |
static const gchar *atom_names[] = { |
| 98 |
"_NET_WM_PID", |
| 99 |
"_NET_WM_PING", |
| 100 |
"_NET_WM_STATE", |
| 101 |
"_NET_WM_STATE_FULLSCREEN", |
| 102 |
"_NET_WM_USER_TIME", |
| 103 |
"WM_PROTOCOLS", |
| 104 |
"WM_DELETE_WINDOW", |
| 105 |
"_XEMBED", |
| 106 |
"_XEMBED_INFO", |
| 107 |
"_NET_WM_NAME", |
| 108 |
"UTF8_STRING", |
| 109 |
}; |
| 110 |
|
| 111 |
#define N_ATOM_NAMES G_N_ELEMENTS (atom_names) |
| 112 |
|
| 113 |
/* various flags corresponding to pre init setup calls */ |
| 114 |
static gboolean _no_xevent_retrieval = FALSE; |
| 115 |
static gboolean clutter_enable_xinput = TRUE; |
| 116 |
static gboolean clutter_enable_argb = FALSE; |
| 117 |
static gboolean clutter_enable_stereo = FALSE; |
| 118 |
static Display *_foreign_dpy = NULL; |
| 119 |
|
| 120 |
/* options */ |
| 121 |
static gchar *clutter_display_name = NULL; |
| 122 |
static gint clutter_screen = -1; |
| 123 |
static gboolean clutter_synchronise = FALSE; |
| 124 |
|
| 125 |
/* X error trap */ |
| 126 |
static int TrappedErrorCode = 0; |
| 127 |
static int (* old_error_handler) (Display *, XErrorEvent *); |
| 128 |
|
| 129 |
static ClutterX11FilterReturn |
| 130 |
xsettings_filter (XEvent *xevent, |
| 131 |
ClutterEvent *event, |
| 132 |
gpointer data) |
| 133 |
{ |
| 134 |
ClutterBackendX11 *backend_x11 = data; |
| 135 |
|
| 136 |
_clutter_xsettings_client_process_event (backend_x11->xsettings, xevent); |
| 137 |
|
| 138 |
/* we always want the rest of the stack to get XSettings events, even |
| 139 |
* if Clutter already handled them |
| 140 |
*/ |
| 141 |
|
| 142 |
return CLUTTER_X11_FILTER_CONTINUE; |
| 143 |
} |
| 144 |
|
| 145 |
static ClutterX11FilterReturn |
| 146 |
cogl_xlib_filter (XEvent *xevent, |
| 147 |
ClutterEvent *event, |
| 148 |
gpointer data) |
| 149 |
{ |
| 150 |
ClutterBackend *backend = data; |
| 151 |
ClutterX11FilterReturn retval; |
| 152 |
CoglFilterReturn ret; |
| 153 |
|
| 154 |
ret = cogl_xlib_renderer_handle_event (backend->cogl_renderer, xevent); |
| 155 |
switch (ret) |
| 156 |
{ |
| 157 |
case COGL_FILTER_REMOVE: |
| 158 |
retval = CLUTTER_X11_FILTER_REMOVE; |
| 159 |
break; |
| 160 |
|
| 161 |
case COGL_FILTER_CONTINUE: |
| 162 |
default: |
| 163 |
retval = CLUTTER_X11_FILTER_CONTINUE; |
| 164 |
break; |
| 165 |
} |
| 166 |
|
| 167 |
return retval; |
| 168 |
} |
| 169 |
|
| 170 |
static void |
| 171 |
clutter_backend_x11_xsettings_notify (const char *name, |
| 172 |
XSettingsAction action, |
| 173 |
XSettingsSetting *setting, |
| 174 |
void *cb_data) |
| 175 |
{ |
| 176 |
ClutterSettings *settings = clutter_settings_get_default (); |
| 177 |
gint i; |
| 178 |
|
| 179 |
if (name == NULL || *name == '\0') |
| 180 |
return; |
| 181 |
|
| 182 |
if (setting == NULL) |
| 183 |
return; |
| 184 |
|
| 185 |
g_object_freeze_notify (G_OBJECT (settings)); |
| 186 |
|
| 187 |
for (i = 0; i < _n_clutter_settings_map; i++) |
| 188 |
{ |
| 189 |
if (g_strcmp0 (name, CLUTTER_SETTING_X11_NAME (i)) == 0) |
| 190 |
{ |
| 191 |
GValue value = G_VALUE_INIT; |
| 192 |
|
| 193 |
switch (setting->type) |
| 194 |
{ |
| 195 |
case XSETTINGS_TYPE_INT: |
| 196 |
g_value_init (&value, G_TYPE_INT); |
| 197 |
g_value_set_int (&value, setting->data.v_int); |
| 198 |
break; |
| 199 |
|
| 200 |
case XSETTINGS_TYPE_STRING: |
| 201 |
g_value_init (&value, G_TYPE_STRING); |
| 202 |
g_value_set_string (&value, setting->data.v_string); |
| 203 |
break; |
| 204 |
|
| 205 |
case XSETTINGS_TYPE_COLOR: |
| 206 |
{ |
| 207 |
ClutterColor color; |
| 208 |
|
| 209 |
color.red = (guint8) ((float) setting->data.v_color.red |
| 210 |
/ 65535.0 * 255); |
| 211 |
color.green = (guint8) ((float) setting->data.v_color.green |
| 212 |
/ 65535.0 * 255); |
| 213 |
color.blue = (guint8) ((float) setting->data.v_color.blue |
| 214 |
/ 65535.0 * 255); |
| 215 |
color.alpha = (guint8) ((float) setting->data.v_color.alpha |
| 216 |
/ 65535.0 * 255); |
| 217 |
|
| 218 |
g_value_init (&value, G_TYPE_BOXED); |
| 219 |
clutter_value_set_color (&value, &color); |
| 220 |
} |
| 221 |
break; |
| 222 |
} |
| 223 |
|
| 224 |
CLUTTER_NOTE (BACKEND, |
| 225 |
"Mapping XSETTING '%s' to 'ClutterSettings:%s'", |
| 226 |
CLUTTER_SETTING_X11_NAME (i), |
| 227 |
CLUTTER_SETTING_PROPERTY (i)); |
| 228 |
|
| 229 |
clutter_settings_set_property_internal (settings, |
| 230 |
CLUTTER_SETTING_PROPERTY (i), |
| 231 |
&value); |
| 232 |
|
| 233 |
g_value_unset (&value); |
| 234 |
|
| 235 |
break; |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
g_object_thaw_notify (G_OBJECT (settings)); |
| 240 |
} |
| 241 |
|
| 242 |
static void |
| 243 |
clutter_backend_x11_create_device_manager (ClutterBackendX11 *backend_x11) |
| 244 |
{ |
| 245 |
ClutterEventTranslator *translator; |
| 246 |
ClutterBackend *backend; |
| 247 |
|
| 248 |
#ifdef HAVE_XINPUT_2 |
| 249 |
if (clutter_enable_xinput) |
| 250 |
{ |
| 251 |
int event_base, first_event, first_error; |
| 252 |
|
| 253 |
if (XQueryExtension (backend_x11->xdpy, "XInputExtension", |
| 254 |
&event_base, |
| 255 |
&first_event, |
| 256 |
&first_error)) |
| 257 |
{ |
| 258 |
int major = 2; |
| 259 |
int minor = 3; |
| 260 |
|
| 261 |
if (XIQueryVersion (backend_x11->xdpy, &major, &minor) != BadRequest) |
| 262 |
{ |
| 263 |
CLUTTER_NOTE (BACKEND, "Creating XI2 device manager"); |
| 264 |
backend_x11->has_xinput = TRUE; |
| 265 |
backend_x11->device_manager = |
| 266 |
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_XI2, |
| 267 |
"backend", backend_x11, |
| 268 |
"opcode", event_base, |
| 269 |
NULL); |
| 270 |
|
| 271 |
backend_x11->xi_minor = minor; |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
if (backend_x11->device_manager == NULL) |
| 277 |
#endif /* HAVE_XINPUT_2 */ |
| 278 |
{ |
| 279 |
CLUTTER_NOTE (BACKEND, "Creating Core device manager"); |
| 280 |
backend_x11->has_xinput = FALSE; |
| 281 |
backend_x11->device_manager = |
| 282 |
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_X11, |
| 283 |
"backend", backend_x11, |
| 284 |
NULL); |
| 285 |
|
| 286 |
backend_x11->xi_minor = -1; |
| 287 |
} |
| 288 |
|
| 289 |
backend = CLUTTER_BACKEND (backend_x11); |
| 290 |
backend->device_manager = backend_x11->device_manager; |
| 291 |
|
| 292 |
translator = CLUTTER_EVENT_TRANSLATOR (backend_x11->device_manager); |
| 293 |
_clutter_backend_add_event_translator (backend, translator); |
| 294 |
} |
| 295 |
|
| 296 |
static void |
| 297 |
clutter_backend_x11_create_keymap (ClutterBackendX11 *backend_x11) |
| 298 |
{ |
| 299 |
if (backend_x11->keymap == NULL) |
| 300 |
{ |
| 301 |
ClutterEventTranslator *translator; |
| 302 |
ClutterBackend *backend; |
| 303 |
|
| 304 |
backend_x11->keymap = |
| 305 |
g_object_new (CLUTTER_TYPE_KEYMAP_X11, |
| 306 |
"backend", backend_x11, |
| 307 |
NULL); |
| 308 |
|
| 309 |
backend = CLUTTER_BACKEND (backend_x11); |
| 310 |
translator = CLUTTER_EVENT_TRANSLATOR (backend_x11->keymap); |
| 311 |
_clutter_backend_add_event_translator (backend, translator); |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
static gboolean |
| 316 |
clutter_backend_x11_pre_parse (ClutterBackend *backend, |
| 317 |
GError **error) |
| 318 |
{ |
| 319 |
const gchar *env_string; |
| 320 |
|
| 321 |
/* we don't fail here if DISPLAY is not set, as the user |
| 322 |
* might pass the --display command line switch |
| 323 |
*/ |
| 324 |
env_string = g_getenv ("DISPLAY"); |
| 325 |
if (env_string) |
| 326 |
{ |
| 327 |
clutter_display_name = g_strdup (env_string); |
| 328 |
env_string = NULL; |
| 329 |
} |
| 330 |
|
| 331 |
env_string = g_getenv ("CLUTTER_DISABLE_ARGB_VISUAL"); |
| 332 |
if (env_string) |
| 333 |
{ |
| 334 |
clutter_enable_argb = FALSE; |
| 335 |
env_string = NULL; |
| 336 |
} |
| 337 |
|
| 338 |
env_string = g_getenv ("CLUTTER_DISABLE_XINPUT"); |
| 339 |
if (env_string) |
| 340 |
{ |
| 341 |
clutter_enable_xinput = FALSE; |
| 342 |
env_string = NULL; |
| 343 |
} |
| 344 |
|
| 345 |
return TRUE; |
| 346 |
} |
| 347 |
|
| 348 |
static gboolean |
| 349 |
clutter_backend_x11_post_parse (ClutterBackend *backend, |
| 350 |
GError **error) |
| 351 |
{ |
| 352 |
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend); |
| 353 |
ClutterSettings *settings; |
| 354 |
Atom atoms[N_ATOM_NAMES]; |
| 355 |
double dpi; |
| 356 |
|
| 357 |
if (_foreign_dpy) |
| 358 |
backend_x11->xdpy = _foreign_dpy; |
| 359 |
|
| 360 |
/* Only open connection if not already set by prior call to |
| 361 |
* clutter_x11_set_display() |
| 362 |
*/ |
| 363 |
if (backend_x11->xdpy == NULL) |
| 364 |
{ |
| 365 |
if (clutter_display_name != NULL && |
| 366 |
*clutter_display_name != '\0') |
| 367 |
{ |
| 368 |
CLUTTER_NOTE (BACKEND, "XOpenDisplay on '%s'", clutter_display_name); |
| 369 |
|
| 370 |
backend_x11->xdpy = XOpenDisplay (clutter_display_name); |
| 371 |
if (backend_x11->xdpy == NULL) |
| 372 |
{ |
| 373 |
g_set_error (error, CLUTTER_INIT_ERROR, |
| 374 |
CLUTTER_INIT_ERROR_BACKEND, |
| 375 |
"Unable to open display '%s'", |
| 376 |
clutter_display_name); |
| 377 |
return FALSE; |
| 378 |
} |
| 379 |
} |
| 380 |
else |
| 381 |
{ |
| 382 |
g_set_error_literal (error, CLUTTER_INIT_ERROR, |
| 383 |
CLUTTER_INIT_ERROR_BACKEND, |
| 384 |
"Unable to open display. You have to set the " |
| 385 |
"DISPLAY environment variable, or use the " |
| 386 |
"--display command line argument"); |
| 387 |
return FALSE; |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
g_assert (backend_x11->xdpy != NULL); |
| 392 |
|
| 393 |
CLUTTER_NOTE (BACKEND, "Getting the X screen"); |
| 394 |
|
| 395 |
settings = clutter_settings_get_default (); |
| 396 |
|
| 397 |
/* add event filter for Cogl events */ |
| 398 |
clutter_x11_add_filter (cogl_xlib_filter, backend); |
| 399 |
|
| 400 |
if (clutter_screen == -1) |
| 401 |
backend_x11->xscreen = DefaultScreenOfDisplay (backend_x11->xdpy); |
| 402 |
else |
| 403 |
backend_x11->xscreen = ScreenOfDisplay (backend_x11->xdpy, |
| 404 |
clutter_screen); |
| 405 |
|
| 406 |
backend_x11->xscreen_num = XScreenNumberOfScreen (backend_x11->xscreen); |
| 407 |
backend_x11->xscreen_width = WidthOfScreen (backend_x11->xscreen); |
| 408 |
backend_x11->xscreen_height = HeightOfScreen (backend_x11->xscreen); |
| 409 |
|
| 410 |
backend_x11->xwin_root = RootWindow (backend_x11->xdpy, |
| 411 |
backend_x11->xscreen_num); |
| 412 |
|
| 413 |
backend_x11->display_name = g_strdup (clutter_display_name); |
| 414 |
|
| 415 |
dpi = (((double) DisplayHeight (backend_x11->xdpy, backend_x11->xscreen_num) * 25.4) |
| 416 |
/ (double) DisplayHeightMM (backend_x11->xdpy, backend_x11->xscreen_num)); |
| 417 |
|
| 418 |
g_object_set (settings, "font-dpi", (int) dpi * 1024, NULL); |
| 419 |
|
| 420 |
/* create XSETTINGS client */ |
| 421 |
backend_x11->xsettings = |
| 422 |
_clutter_xsettings_client_new (backend_x11->xdpy, |
| 423 |
backend_x11->xscreen_num, |
| 424 |
clutter_backend_x11_xsettings_notify, |
| 425 |
NULL, |
| 426 |
backend_x11); |
| 427 |
|
| 428 |
/* add event filter for XSETTINGS events */ |
| 429 |
clutter_x11_add_filter (xsettings_filter, backend_x11); |
| 430 |
|
| 431 |
if (clutter_synchronise) |
| 432 |
XSynchronize (backend_x11->xdpy, True); |
| 433 |
|
| 434 |
XInternAtoms (backend_x11->xdpy, |
| 435 |
(char **) atom_names, N_ATOM_NAMES, |
| 436 |
False, atoms); |
| 437 |
|
| 438 |
backend_x11->atom_NET_WM_PID = atoms[0]; |
| 439 |
backend_x11->atom_NET_WM_PING = atoms[1]; |
| 440 |
backend_x11->atom_NET_WM_STATE = atoms[2]; |
| 441 |
backend_x11->atom_NET_WM_STATE_FULLSCREEN = atoms[3]; |
| 442 |
backend_x11->atom_NET_WM_USER_TIME = atoms[4]; |
| 443 |
backend_x11->atom_WM_PROTOCOLS = atoms[5]; |
| 444 |
backend_x11->atom_WM_DELETE_WINDOW = atoms[6]; |
| 445 |
backend_x11->atom_XEMBED = atoms[7]; |
| 446 |
backend_x11->atom_XEMBED_INFO = atoms[8]; |
| 447 |
backend_x11->atom_NET_WM_NAME = atoms[9]; |
| 448 |
backend_x11->atom_UTF8_STRING = atoms[10]; |
| 449 |
|
| 450 |
g_free (clutter_display_name); |
| 451 |
|
| 452 |
CLUTTER_NOTE (BACKEND, |
| 453 |
"X Display '%s'[%p] opened (screen:%d, root:%u, dpi:%f)", |
| 454 |
backend_x11->display_name, |
| 455 |
backend_x11->xdpy, |
| 456 |
backend_x11->xscreen_num, |
| 457 |
(unsigned int) backend_x11->xwin_root, |
| 458 |
clutter_backend_get_resolution (backend)); |
| 459 |
|
| 460 |
return TRUE; |
| 461 |
} |
| 462 |
|
| 463 |
void |
| 464 |
_clutter_backend_x11_events_init (ClutterBackend *backend) |
| 465 |
{ |
| 466 |
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend); |
| 467 |
|
| 468 |
CLUTTER_NOTE (EVENT, "initialising the event loop"); |
| 469 |
|
| 470 |
/* the event source is optional */ |
| 471 |
if (!_no_xevent_retrieval) |
| 472 |
{ |
| 473 |
GSource *source; |
| 474 |
|
| 475 |
source = _clutter_x11_event_source_new (backend_x11); |
| 476 |
|
| 477 |
/* default priority for events |
| 478 |
* |
| 479 |
* XXX - at some point we'll have a common EventSource API that |
| 480 |
* is created by the backend, and this code will most likely go |
| 481 |
* into the default implementation of ClutterBackend |
| 482 |
*/ |
| 483 |
g_source_set_priority (source, CLUTTER_PRIORITY_EVENTS); |
| 484 |
|
| 485 |
/* attach the source to the default context, and transfer the |
| 486 |
* ownership to the GMainContext itself |
| 487 |
*/ |
| 488 |
g_source_attach (source, NULL); |
| 489 |
g_source_unref (source); |
| 490 |
|
| 491 |
backend_x11->event_source = source; |
| 492 |
} |
| 493 |
|
| 494 |
/* create the device manager; we need this because we can effectively |
| 495 |
* choose between core+XI1 and XI2 input events |
| 496 |
*/ |
| 497 |
clutter_backend_x11_create_device_manager (backend_x11); |
| 498 |
|
| 499 |
/* register keymap; unless we create a generic Keymap object, I'm |
| 500 |
* afraid this will have to stay |
| 501 |
*/ |
| 502 |
clutter_backend_x11_create_keymap (backend_x11); |
| 503 |
} |
| 504 |
|
| 505 |
static const GOptionEntry entries[] = |
| 506 |
{ |
| 507 |
{ |
| 508 |
"display", 0, |
| 509 |
G_OPTION_FLAG_IN_MAIN, |
| 510 |
G_OPTION_ARG_STRING, &clutter_display_name, |
| 511 |
N_("X display to use"), "DISPLAY" |
| 512 |
}, |
| 513 |
{ |
| 514 |
"screen", 0, |
| 515 |
G_OPTION_FLAG_IN_MAIN, |
| 516 |
G_OPTION_ARG_INT, &clutter_screen, |
| 517 |
N_("X screen to use"), "SCREEN" |
| 518 |
}, |
| 519 |
{ "synch", 0, |
| 520 |
0, |
| 521 |
G_OPTION_ARG_NONE, &clutter_synchronise, |
| 522 |
N_("Make X calls synchronous"), NULL |
| 523 |
}, |
| 524 |
#ifdef HAVE_XINPUT_2 |
| 525 |
{ |
| 526 |
"disable-xinput", 0, |
| 527 |
G_OPTION_FLAG_REVERSE, |
| 528 |
G_OPTION_ARG_NONE, &clutter_enable_xinput, |
| 529 |
N_("Disable XInput support"), NULL |
| 530 |
}, |
| 531 |
#endif /* HAVE_XINPUT_2 */ |
| 532 |
{ NULL } |
| 533 |
}; |
| 534 |
|
| 535 |
static void |
| 536 |
clutter_backend_x11_add_options (ClutterBackend *backend, |
| 537 |
GOptionGroup *group) |
| 538 |
{ |
| 539 |
g_option_group_add_entries (group, entries); |
| 540 |
} |
| 541 |
|
| 542 |
static void |
| 543 |
clutter_backend_x11_finalize (GObject *gobject) |
| 544 |
{ |
| 545 |
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (gobject); |
| 546 |
|
| 547 |
g_free (backend_x11->display_name); |
| 548 |
|
| 549 |
clutter_x11_remove_filter (cogl_xlib_filter, gobject); |
| 550 |
|
| 551 |
clutter_x11_remove_filter (xsettings_filter, backend_x11); |
| 552 |
_clutter_xsettings_client_destroy (backend_x11->xsettings); |
| 553 |
|
| 554 |
XCloseDisplay (backend_x11->xdpy); |
| 555 |
|
| 556 |
G_OBJECT_CLASS (clutter_backend_x11_parent_class)->finalize (gobject); |
| 557 |
} |
| 558 |
|
| 559 |
static void |
| 560 |
clutter_backend_x11_dispose (GObject *gobject) |
| 561 |
{ |
| 562 |
G_OBJECT_CLASS (clutter_backend_x11_parent_class)->dispose (gobject); |
| 563 |
} |
| 564 |
|
| 565 |
static ClutterFeatureFlags |
| 566 |
clutter_backend_x11_get_features (ClutterBackend *backend) |
| 567 |
{ |
| 568 |
ClutterFeatureFlags flags = CLUTTER_FEATURE_STAGE_USER_RESIZE |
| 569 |
| CLUTTER_FEATURE_STAGE_CURSOR; |
| 570 |
|
| 571 |
flags |= CLUTTER_BACKEND_CLASS (clutter_backend_x11_parent_class)->get_features (backend); |
| 572 |
|
| 573 |
return flags; |
| 574 |
} |
| 575 |
|
| 576 |
static void |
| 577 |
update_last_event_time (ClutterBackendX11 *backend_x11, |
| 578 |
XEvent *xevent) |
| 579 |
{ |
| 580 |
Time current_time = CurrentTime; |
| 581 |
Time last_time = backend_x11->last_event_time; |
| 582 |
|
| 583 |
switch (xevent->type) |
| 584 |
{ |
| 585 |
case KeyPress: |
| 586 |
case KeyRelease: |
| 587 |
current_time = xevent->xkey.time; |
| 588 |
break; |
| 589 |
|
| 590 |
case ButtonPress: |
| 591 |
case ButtonRelease: |
| 592 |
current_time = xevent->xbutton.time; |
| 593 |
break; |
| 594 |
|
| 595 |
case MotionNotify: |
| 596 |
current_time = xevent->xmotion.time; |
| 597 |
break; |
| 598 |
|
| 599 |
case EnterNotify: |
| 600 |
case LeaveNotify: |
| 601 |
current_time = xevent->xcrossing.time; |
| 602 |
break; |
| 603 |
|
| 604 |
case PropertyNotify: |
| 605 |
current_time = xevent->xproperty.time; |
| 606 |
break; |
| 607 |
|
| 608 |
default: |
| 609 |
break; |
| 610 |
} |
| 611 |
|
| 612 |
/* only change the current event time if it's after the previous event |
| 613 |
* time, or if it is at least 30 seconds earlier - in case the system |
| 614 |
* clock was changed |
| 615 |
*/ |
| 616 |
if ((current_time != CurrentTime) && |
| 617 |
(current_time > last_time || (last_time - current_time > (30 * 1000)))) |
| 618 |
backend_x11->last_event_time = current_time; |
| 619 |
} |
| 620 |
|
| 621 |
static gboolean |
| 622 |
clutter_backend_x11_translate_event (ClutterBackend *backend, |
| 623 |
gpointer native, |
| 624 |
ClutterEvent *event) |
| 625 |
{ |
| 626 |
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend); |
| 627 |
ClutterBackendClass *parent_class; |
| 628 |
XEvent *xevent = native; |
| 629 |
|
| 630 |
/* X11 filter functions have a higher priority */ |
| 631 |
if (backend_x11->event_filters != NULL) |
| 632 |
{ |
| 633 |
GSList *node = backend_x11->event_filters; |
| 634 |
|
| 635 |
while (node != NULL) |
| 636 |
{ |
| 637 |
ClutterX11EventFilter *filter = node->data; |
| 638 |
|
| 639 |
switch (filter->func (xevent, event, filter->data)) |
| 640 |
{ |
| 641 |
case CLUTTER_X11_FILTER_CONTINUE: |
| 642 |
break; |
| 643 |
|
| 644 |
case CLUTTER_X11_FILTER_TRANSLATE: |
| 645 |
return TRUE; |
| 646 |
|
| 647 |
case CLUTTER_X11_FILTER_REMOVE: |
| 648 |
return FALSE; |
| 649 |
|
| 650 |
default: |
| 651 |
break; |
| 652 |
} |
| 653 |
|
| 654 |
node = node->next; |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
/* we update the event time only for events that can |
| 659 |
* actually reach Clutter's event queue |
| 660 |
*/ |
| 661 |
update_last_event_time (backend_x11, xevent); |
| 662 |
|
| 663 |
/* chain up to the parent implementation, which will handle |
| 664 |
* event translators |
| 665 |
*/ |
| 666 |
parent_class = CLUTTER_BACKEND_CLASS (clutter_backend_x11_parent_class); |
| 667 |
return parent_class->translate_event (backend, native, event); |
| 668 |
} |
| 669 |
|
| 670 |
static CoglRenderer * |
| 671 |
clutter_backend_x11_get_renderer (ClutterBackend *backend, |
| 672 |
GError **error) |
| 673 |
{ |
| 674 |
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend); |
| 675 |
Display *xdisplay = backend_x11->xdpy; |
| 676 |
CoglRenderer *renderer; |
| 677 |
|
| 678 |
CLUTTER_NOTE (BACKEND, "Creating a new Xlib renderer"); |
| 679 |
|
| 680 |
renderer = cogl_renderer_new (); |
| 681 |
|
| 682 |
cogl_renderer_add_constraint (renderer, COGL_RENDERER_CONSTRAINT_USES_X11); |
| 683 |
|
| 684 |
/* set the display object we're using */ |
| 685 |
cogl_xlib_renderer_set_foreign_display (renderer, xdisplay); |
| 686 |
|
| 687 |
return renderer; |
| 688 |
} |
| 689 |
|
| 690 |
static gboolean |
| 691 |
check_onscreen_template (CoglRenderer *renderer, |
| 692 |
CoglSwapChain *swap_chain, |
| 693 |
CoglOnscreenTemplate *onscreen_template, |
| 694 |
CoglBool enable_argb, |
| 695 |
CoglBool enable_stereo, |
| 696 |
GError **error) |
| 697 |
{ |
| 698 |
GError *internal_error = NULL; |
| 699 |
|
| 700 |
cogl_swap_chain_set_has_alpha (swap_chain, enable_argb); |
| 701 |
cogl_onscreen_template_set_stereo_enabled (onscreen_template, |
| 702 |
clutter_enable_stereo); |
| 703 |
|
| 704 |
/* cogl_renderer_check_onscreen_template() is actually just a |
| 705 |
* shorthand for creating a CoglDisplay, and calling |
| 706 |
* cogl_display_setup() on it, then throwing the display away. If we |
| 707 |
* could just return that display, then it would be more efficient |
| 708 |
* not to use cogl_renderer_check_onscreen_template(). However, the |
| 709 |
* backend API requires that we return an CoglDisplay that has not |
| 710 |
* yet been setup, so one way or the other we'll have to discard the |
| 711 |
* first display and make a new fresh one. |
| 712 |
*/ |
| 713 |
if (cogl_renderer_check_onscreen_template (renderer, onscreen_template, &internal_error)) |
| 714 |
{ |
| 715 |
clutter_enable_argb = enable_argb; |
| 716 |
clutter_enable_stereo = enable_stereo; |
| 717 |
|
| 718 |
return TRUE; |
| 719 |
} |
| 720 |
else |
| 721 |
{ |
| 722 |
if (enable_argb || enable_stereo) /* More possibilities to try */ |
| 723 |
CLUTTER_NOTE (BACKEND, |
| 724 |
"Creation of a CoglDisplay with alpha=%s, stereo=%s failed: %s", |
| 725 |
enable_argb ? "enabled" : "disabled", |
| 726 |
enable_stereo ? "enabled" : "disabled", |
| 727 |
internal_error != NULL |
| 728 |
? internal_error->message |
| 729 |
: "Unknown reason"); |
| 730 |
else |
| 731 |
g_set_error_literal (error, CLUTTER_INIT_ERROR, |
| 732 |
CLUTTER_INIT_ERROR_BACKEND, |
| 733 |
internal_error != NULL |
| 734 |
? internal_error->message |
| 735 |
: "Creation of a CoglDisplay failed"); |
| 736 |
|
| 737 |
g_clear_error (&internal_error); |
| 738 |
|
| 739 |
return FALSE; |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
static CoglDisplay * |
| 744 |
clutter_backend_x11_get_display (ClutterBackend *backend, |
| 745 |
CoglRenderer *renderer, |
| 746 |
CoglSwapChain *swap_chain, |
| 747 |
GError **error) |
| 748 |
{ |
| 749 |
CoglOnscreenTemplate *onscreen_template; |
| 750 |
CoglDisplay *display = NULL; |
| 751 |
gboolean res = FALSE; |
| 752 |
|
| 753 |
CLUTTER_NOTE (BACKEND, "Creating CoglDisplay, alpha=%s, stereo=%s", |
| 754 |
clutter_enable_argb ? "enabled" : "disabled", |
| 755 |
clutter_enable_stereo ? "enabled" : "disabled"); |
| 756 |
|
| 757 |
onscreen_template = cogl_onscreen_template_new (swap_chain); |
| 758 |
|
| 759 |
/* It's possible that the current renderer doesn't support transparency |
| 760 |
* or doesn't support stereo, so we try the different combinations. |
| 761 |
*/ |
| 762 |
if (clutter_enable_argb && clutter_enable_stereo) |
| 763 |
res = check_onscreen_template (renderer, swap_chain, onscreen_template, |
| 764 |
TRUE, TRUE, error); |
| 765 |
|
| 766 |
/* Prioritize stereo over alpha */ |
| 767 |
if (!res && clutter_enable_stereo) |
| 768 |
res = check_onscreen_template (renderer, swap_chain, onscreen_template, |
| 769 |
FALSE, TRUE, error); |
| 770 |
|
| 771 |
if (!res && clutter_enable_argb) |
| 772 |
res = check_onscreen_template (renderer, swap_chain, onscreen_template, |
| 773 |
TRUE, FALSE, error); |
| 774 |
|
| 775 |
if (!res) |
| 776 |
res = check_onscreen_template (renderer, swap_chain, onscreen_template, |
| 777 |
FALSE, FALSE, error); |
| 778 |
|
| 779 |
if (res) |
| 780 |
display = cogl_display_new (renderer, onscreen_template); |
| 781 |
|
| 782 |
cogl_object_unref (onscreen_template); |
| 783 |
|
| 784 |
return display; |
| 785 |
} |
| 786 |
|
| 787 |
static ClutterStageWindow * |
| 788 |
clutter_backend_x11_create_stage (ClutterBackend *backend, |
| 789 |
ClutterStage *wrapper, |
| 790 |
GError **error) |
| 791 |
{ |
| 792 |
ClutterEventTranslator *translator; |
| 793 |
ClutterStageWindow *stage; |
| 794 |
|
| 795 |
stage = g_object_new (CLUTTER_TYPE_STAGE_X11, |
| 796 |
"backend", backend, |
| 797 |
"wrapper", wrapper, |
| 798 |
NULL); |
| 799 |
|
| 800 |
/* the X11 stage does event translation */ |
| 801 |
translator = CLUTTER_EVENT_TRANSLATOR (stage); |
| 802 |
_clutter_backend_add_event_translator (backend, translator); |
| 803 |
|
| 804 |
CLUTTER_NOTE (BACKEND, "X11 stage created (display:%p, screen:%d, root:%u)", |
| 805 |
CLUTTER_BACKEND_X11 (backend)->xdpy, |
| 806 |
CLUTTER_BACKEND_X11 (backend)->xscreen_num, |
| 807 |
(unsigned int) CLUTTER_BACKEND_X11 (backend)->xwin_root); |
| 808 |
|
| 809 |
return stage; |
| 810 |
} |
| 811 |
|
| 812 |
static PangoDirection |
| 813 |
clutter_backend_x11_get_keymap_direction (ClutterBackend *backend) |
| 814 |
{ |
| 815 |
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend); |
| 816 |
|
| 817 |
if (G_UNLIKELY (backend_x11->keymap == NULL)) |
| 818 |
return PANGO_DIRECTION_NEUTRAL; |
| 819 |
|
| 820 |
return _clutter_keymap_x11_get_direction (backend_x11->keymap); |
| 821 |
} |
| 822 |
|
| 823 |
static void |
| 824 |
clutter_backend_x11_class_init (ClutterBackendX11Class *klass) |
| 825 |
{ |
| 826 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
| 827 |
ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass); |
| 828 |
|
| 829 |
gobject_class->dispose = clutter_backend_x11_dispose; |
| 830 |
gobject_class->finalize = clutter_backend_x11_finalize; |
| 831 |
|
| 832 |
backend_class->stage_window_type = CLUTTER_TYPE_STAGE_X11; |
| 833 |
|
| 834 |
backend_class->pre_parse = clutter_backend_x11_pre_parse; |
| 835 |
backend_class->post_parse = clutter_backend_x11_post_parse; |
| 836 |
backend_class->add_options = clutter_backend_x11_add_options; |
| 837 |
backend_class->get_features = clutter_backend_x11_get_features; |
| 838 |
|
| 839 |
backend_class->translate_event = clutter_backend_x11_translate_event; |
| 840 |
|
| 841 |
backend_class->get_renderer = clutter_backend_x11_get_renderer; |
| 842 |
backend_class->get_display = clutter_backend_x11_get_display; |
| 843 |
backend_class->create_stage = clutter_backend_x11_create_stage; |
| 844 |
|
| 845 |
backend_class->get_keymap_direction = clutter_backend_x11_get_keymap_direction; |
| 846 |
} |
| 847 |
|
| 848 |
static void |
| 849 |
clutter_backend_x11_init (ClutterBackendX11 *backend_x11) |
| 850 |
{ |
| 851 |
backend_x11->last_event_time = CurrentTime; |
| 852 |
} |
| 853 |
|
| 854 |
ClutterBackend * |
| 855 |
clutter_backend_x11_new (void) |
| 856 |
{ |
| 857 |
return g_object_new (CLUTTER_TYPE_BACKEND_X11, NULL); |
| 858 |
} |
| 859 |
|
| 860 |
static int |
| 861 |
error_handler(Display *xdpy, |
| 862 |
XErrorEvent *error) |
| 863 |
{ |
| 864 |
TrappedErrorCode = error->error_code; |
| 865 |
return 0; |
| 866 |
} |
| 867 |
|
| 868 |
/** |
| 869 |
* clutter_x11_trap_x_errors: |
| 870 |
* |
| 871 |
* Traps every X error until clutter_x11_untrap_x_errors() is called. |
| 872 |
* |
| 873 |
* Since: 0.6 |
| 874 |
*/ |
| 875 |
void |
| 876 |
clutter_x11_trap_x_errors (void) |
| 877 |
{ |
| 878 |
TrappedErrorCode = 0; |
| 879 |
old_error_handler = XSetErrorHandler (error_handler); |
| 880 |
} |
| 881 |
|
| 882 |
/** |
| 883 |
* clutter_x11_untrap_x_errors: |
| 884 |
* |
| 885 |
* Removes the X error trap and returns the current status. |
| 886 |
* |
| 887 |
* Return value: the trapped error code, or 0 for success |
| 888 |
* |
| 889 |
* Since: 0.4 |
| 890 |
*/ |
| 891 |
gint |
| 892 |
clutter_x11_untrap_x_errors (void) |
| 893 |
{ |
| 894 |
XSetErrorHandler (old_error_handler); |
| 895 |
|
| 896 |
return TrappedErrorCode; |
| 897 |
} |
| 898 |
|
| 899 |
/** |
| 900 |
* clutter_x11_get_default_display: |
| 901 |
* |
| 902 |
* Retrieves the pointer to the default display. |
| 903 |
* |
| 904 |
* Return value: (transfer none): the default display |
| 905 |
* |
| 906 |
* Since: 0.6 |
| 907 |
*/ |
| 908 |
Display * |
| 909 |
clutter_x11_get_default_display (void) |
| 910 |
{ |
| 911 |
ClutterBackend *backend = clutter_get_default_backend (); |
| 912 |
|
| 913 |
if (backend == NULL) |
| 914 |
{ |
| 915 |
g_critical ("The Clutter backend has not been initialised"); |
| 916 |
return NULL; |
| 917 |
} |
| 918 |
|
| 919 |
if (!CLUTTER_IS_BACKEND_X11 (backend)) |
| 920 |
{ |
| 921 |
g_critical ("The Clutter backend is not a X11 backend"); |
| 922 |
return NULL; |
| 923 |
} |
| 924 |
|
| 925 |
return CLUTTER_BACKEND_X11 (backend)->xdpy; |
| 926 |
} |
| 927 |
|
| 928 |
/** |
| 929 |
* clutter_x11_set_display: |
| 930 |
* @xdpy: pointer to a X display connection. |
| 931 |
* |
| 932 |
* Sets the display connection Clutter should use; must be called |
| 933 |
* before clutter_init(), clutter_init_with_args() or other functions |
| 934 |
* pertaining Clutter's initialization process. |
| 935 |
* |
| 936 |
* If you are parsing the command line arguments by retrieving Clutter's |
| 937 |
* #GOptionGroup with clutter_get_option_group() and calling |
| 938 |
* g_option_context_parse() yourself, you should also call |
| 939 |
* clutter_x11_set_display() before g_option_context_parse(). |
| 940 |
* |
| 941 |
* Since: 0.8 |
| 942 |
*/ |
| 943 |
void |
| 944 |
clutter_x11_set_display (Display *xdpy) |
| 945 |
{ |
| 946 |
if (_clutter_context_is_initialized ()) |
| 947 |
{ |
| 948 |
g_warning ("%s() can only be used before calling clutter_init()", |
| 949 |
G_STRFUNC); |
| 950 |
return; |
| 951 |
} |
| 952 |
|
| 953 |
_foreign_dpy= xdpy; |
| 954 |
} |
| 955 |
|
| 956 |
/** |
| 957 |
* clutter_x11_enable_xinput: |
| 958 |
* |
| 959 |
* Enables the use of the XInput extension if present on connected |
| 960 |
* XServer and support built into Clutter. XInput allows for multiple |
| 961 |
* pointing devices to be used. |
| 962 |
* |
| 963 |
* This function must be called before clutter_init(). |
| 964 |
* |
| 965 |
* Since XInput might not be supported by the X server, you might |
| 966 |
* want to use clutter_x11_has_xinput() to see if support was enabled. |
| 967 |
* |
| 968 |
* Since: 0.8 |
| 969 |
* |
| 970 |
* Deprecated: 1.14: This function does not do anything; XInput support |
| 971 |
* is enabled by default in Clutter. Use the CLUTTER_DISABLE_XINPUT |
| 972 |
* environment variable to disable XInput support and use Xlib core |
| 973 |
* events instead. |
| 974 |
*/ |
| 975 |
void |
| 976 |
clutter_x11_enable_xinput (void) |
| 977 |
{ |
| 978 |
} |
| 979 |
|
| 980 |
/** |
| 981 |
* clutter_x11_disable_event_retrieval: |
| 982 |
* |
| 983 |
* Disables the internal polling of X11 events in the main loop. |
| 984 |
* |
| 985 |
* Libraries or applications calling this function will be responsible of |
| 986 |
* polling all X11 events. |
| 987 |
* |
| 988 |
* You also must call clutter_x11_handle_event() to let Clutter process |
| 989 |
* events and maintain its internal state. |
| 990 |
* |
| 991 |
* This function can only be called before calling clutter_init(). |
| 992 |
* |
| 993 |
* Even with event handling disabled, Clutter will still select |
| 994 |
* all the events required to maintain its internal state on the stage |
| 995 |
* Window; compositors using Clutter and input regions to pass events |
| 996 |
* through to application windows should not rely on an empty input |
| 997 |
* region, and should instead clear it themselves explicitly using the |
| 998 |
* XFixes extension. |
| 999 |
* |
| 1000 |
* This function should not be normally used by applications. |
| 1001 |
* |
| 1002 |
* Since: 0.8 |
| 1003 |
*/ |
| 1004 |
void |
| 1005 |
clutter_x11_disable_event_retrieval (void) |
| 1006 |
{ |
| 1007 |
if (_clutter_context_is_initialized ()) |
| 1008 |
{ |
| 1009 |
g_warning ("%s() can only be used before calling clutter_init()", |
| 1010 |
G_STRFUNC); |
| 1011 |
return; |
| 1012 |
} |
| 1013 |
|
| 1014 |
_no_xevent_retrieval = TRUE; |
| 1015 |
} |
| 1016 |
|
| 1017 |
/** |
| 1018 |
* clutter_x11_has_event_retrieval: |
| 1019 |
* |
| 1020 |
* Queries the X11 backend to check if event collection has been disabled. |
| 1021 |
* |
| 1022 |
* Return value: TRUE if event retrival has been disabled. FALSE otherwise. |
| 1023 |
* |
| 1024 |
* Since: 0.8 |
| 1025 |
*/ |
| 1026 |
gboolean |
| 1027 |
clutter_x11_has_event_retrieval (void) |
| 1028 |
{ |
| 1029 |
return !_no_xevent_retrieval; |
| 1030 |
} |
| 1031 |
|
| 1032 |
/** |
| 1033 |
* clutter_x11_get_default_screen: |
| 1034 |
* |
| 1035 |
* Gets the number of the default X Screen object. |
| 1036 |
* |
| 1037 |
* Return value: the number of the default screen |
| 1038 |
* |
| 1039 |
* Since: 0.6 |
| 1040 |
*/ |
| 1041 |
int |
| 1042 |
clutter_x11_get_default_screen (void) |
| 1043 |
{ |
| 1044 |
ClutterBackend *backend = clutter_get_default_backend (); |
| 1045 |
|
| 1046 |
if (backend == NULL) |
| 1047 |
{ |
| 1048 |
g_critical ("The Clutter backend has not been initialised"); |
| 1049 |
return 0; |
| 1050 |
} |
| 1051 |
|
| 1052 |
if (!CLUTTER_IS_BACKEND_X11 (backend)) |
| 1053 |
{ |
| 1054 |
g_critical ("The Clutter backend is not a X11 backend"); |
| 1055 |
return 0; |
| 1056 |
} |
| 1057 |
|
| 1058 |
return CLUTTER_BACKEND_X11 (backend)->xscreen_num; |
| 1059 |
} |
| 1060 |
|
| 1061 |
/** |
| 1062 |
* clutter_x11_get_root_window: (skip) |
| 1063 |
* |
| 1064 |
* Retrieves the root window. |
| 1065 |
* |
| 1066 |
* Return value: the id of the root window |
| 1067 |
* |
| 1068 |
* Since: 0.6 |
| 1069 |
*/ |
| 1070 |
Window |
| 1071 |
clutter_x11_get_root_window (void) |
| 1072 |
{ |
| 1073 |
ClutterBackend *backend = clutter_get_default_backend (); |
| 1074 |
|
| 1075 |
if (backend == NULL) |
| 1076 |
{ |
| 1077 |
g_critical ("The Clutter backend has not been initialised"); |
| 1078 |
return None; |
| 1079 |
} |
| 1080 |
|
| 1081 |
if (!CLUTTER_IS_BACKEND_X11 (backend)) |
| 1082 |
{ |
| 1083 |
g_critical ("The Clutter backend is not a X11 backend"); |
| 1084 |
return None; |
| 1085 |
} |
| 1086 |
|
| 1087 |
return CLUTTER_BACKEND_X11 (backend)->xwin_root; |
| 1088 |
} |
| 1089 |
|
| 1090 |
/** |
| 1091 |
* clutter_x11_add_filter: (skip) |
| 1092 |
* @func: a filter function |
| 1093 |
* @data: user data to be passed to the filter function, or %NULL |
| 1094 |
* |
| 1095 |
* Adds an event filter function. |
| 1096 |
* |
| 1097 |
* Since: 0.6 |
| 1098 |
*/ |
| 1099 |
void |
| 1100 |
clutter_x11_add_filter (ClutterX11FilterFunc func, |
| 1101 |
gpointer data) |
| 1102 |
{ |
| 1103 |
ClutterX11EventFilter *filter; |
| 1104 |
ClutterBackend *backend = clutter_get_default_backend (); |
| 1105 |
ClutterBackendX11 *backend_x11; |
| 1106 |
|
| 1107 |
g_return_if_fail (func != NULL); |
| 1108 |
|
| 1109 |
if (backend == NULL) |
| 1110 |
{ |
| 1111 |
g_critical ("The Clutter backend has not been initialised"); |
| 1112 |
return; |
| 1113 |
} |
| 1114 |
|
| 1115 |
if (!CLUTTER_IS_BACKEND_X11 (backend)) |
| 1116 |
{ |
| 1117 |
g_critical ("The Clutter backend is not a X11 backend"); |
| 1118 |
return; |
| 1119 |
} |
| 1120 |
|
| 1121 |
backend_x11 = CLUTTER_BACKEND_X11 (backend); |
| 1122 |
|
| 1123 |
filter = g_new0 (ClutterX11EventFilter, 1); |
| 1124 |
filter->func = func; |
| 1125 |
filter->data = data; |
| 1126 |
|
| 1127 |
backend_x11->event_filters = |
| 1128 |
g_slist_append (backend_x11->event_filters, filter); |
| 1129 |
|
| 1130 |
return; |
| 1131 |
} |
| 1132 |
|
| 1133 |
/** |
| 1134 |
* clutter_x11_remove_filter: (skip) |
| 1135 |
* @func: a filter function |
| 1136 |
* @data: user data to be passed to the filter function, or %NULL |
| 1137 |
* |
| 1138 |
* Removes the given filter function. |
| 1139 |
* |
| 1140 |
* Since: 0.6 |
| 1141 |
*/ |
| 1142 |
void |
| 1143 |
clutter_x11_remove_filter (ClutterX11FilterFunc func, |
| 1144 |
gpointer data) |
| 1145 |
{ |
| 1146 |
GSList *tmp_list, *this; |
| 1147 |
ClutterX11EventFilter *filter; |
| 1148 |
ClutterBackend *backend = clutter_get_default_backend (); |
| 1149 |
ClutterBackendX11 *backend_x11; |
| 1150 |
|
| 1151 |
g_return_if_fail (func != NULL); |
| 1152 |
|
| 1153 |
if (backend == NULL) |
| 1154 |
{ |
| 1155 |
g_critical ("The Clutter backend has not been initialised"); |
| 1156 |
return; |
| 1157 |
} |
| 1158 |
|
| 1159 |
if (!CLUTTER_IS_BACKEND_X11 (backend)) |
| 1160 |
{ |
| 1161 |
g_critical ("The Clutter backend is not a X11 backend"); |
| 1162 |
return; |
| 1163 |
} |
| 1164 |
|
| 1165 |
backend_x11 = CLUTTER_BACKEND_X11 (backend); |
| 1166 |
|
| 1167 |
tmp_list = backend_x11->event_filters; |
| 1168 |
|
| 1169 |
while (tmp_list) |
| 1170 |
{ |
| 1171 |
filter = tmp_list->data; |
| 1172 |
this = tmp_list; |
| 1173 |
tmp_list = tmp_list->next; |
| 1174 |
|
| 1175 |
if (filter->func == func && filter->data == data) |
| 1176 |
{ |
| 1177 |
backend_x11->event_filters = |
| 1178 |
g_slist_remove_link (backend_x11->event_filters, this); |
| 1179 |
|
| 1180 |
g_slist_free_1 (this); |
| 1181 |
g_free (filter); |
| 1182 |
|
| 1183 |
return; |
| 1184 |
} |
| 1185 |
} |
| 1186 |
} |
| 1187 |
|
| 1188 |
/** |
| 1189 |
* clutter_x11_get_input_devices: |
| 1190 |
* |
| 1191 |
* Retrieves a pointer to the list of input devices |
| 1192 |
* |
| 1193 |
* Deprecated: 1.2: Use clutter_device_manager_peek_devices() instead |
| 1194 |
* |
| 1195 |
* Since: 0.8 |
| 1196 |
* |
| 1197 |
* Return value: (transfer none) (element-type Clutter.InputDevice): a |
| 1198 |
* pointer to the internal list of input devices; the returned list is |
| 1199 |
* owned by Clutter and should not be modified or freed |
| 1200 |
*/ |
| 1201 |
const GSList * |
| 1202 |
clutter_x11_get_input_devices (void) |
| 1203 |
{ |
| 1204 |
ClutterDeviceManager *manager; |
| 1205 |
|
| 1206 |
manager = clutter_device_manager_get_default (); |
| 1207 |
if (manager == NULL) |
| 1208 |
return NULL; |
| 1209 |
|
| 1210 |
return clutter_device_manager_peek_devices (manager); |
| 1211 |
} |
| 1212 |
|
| 1213 |
/** |
| 1214 |
* clutter_x11_has_xinput: |
| 1215 |
* |
| 1216 |
* Gets whether Clutter has XInput support. |
| 1217 |
* |
| 1218 |
* Return value: %TRUE if Clutter was compiled with XInput support |
| 1219 |
* and XInput support is available at run time. |
| 1220 |
* |
| 1221 |
* Since: 0.8 |
| 1222 |
*/ |
| 1223 |
gboolean |
| 1224 |
clutter_x11_has_xinput (void) |
| 1225 |
{ |
| 1226 |
#ifdef HAVE_XINPUT_2 |
| 1227 |
ClutterBackend *backend = clutter_get_default_backend (); |
| 1228 |
|
| 1229 |
if (backend == NULL) |
| 1230 |
{ |
| 1231 |
g_critical ("The Clutter backend has not been initialised"); |
| 1232 |
return FALSE; |
| 1233 |
} |
| 1234 |
|
| 1235 |
if (!CLUTTER_IS_BACKEND_X11 (backend)) |
| 1236 |
{ |
| 1237 |
g_critical ("The Clutter backend is not a X11 backend."); |
| 1238 |
return FALSE; |
| 1239 |
} |
| 1240 |
|
| 1241 |
return CLUTTER_BACKEND_X11 (backend)->has_xinput; |
| 1242 |
#else |
| 1243 |
return FALSE; |
| 1244 |
#endif |
| 1245 |
} |
| 1246 |
|
| 1247 |
/** |
| 1248 |
* clutter_x11_has_composite_extension: |
| 1249 |
* |
| 1250 |
* Retrieves whether Clutter is running on an X11 server with the |
| 1251 |
* XComposite extension |
| 1252 |
* |
| 1253 |
* Return value: %TRUE if the XComposite extension is available |
| 1254 |
*/ |
| 1255 |
gboolean |
| 1256 |
clutter_x11_has_composite_extension (void) |
| 1257 |
{ |
| 1258 |
#if HAVE_XCOMPOSITE |
| 1259 |
static gboolean have_composite = FALSE, done_check = FALSE; |
| 1260 |
int error = 0, event = 0; |
| 1261 |
Display *dpy; |
| 1262 |
|
| 1263 |
if (done_check) |
| 1264 |
return have_composite; |
| 1265 |
|
| 1266 |
if (!_clutter_context_is_initialized ()) |
| 1267 |
{ |
| 1268 |
g_critical ("X11 backend has not been initialised"); |
| 1269 |
return FALSE; |
| 1270 |
} |
| 1271 |
|
| 1272 |
dpy = clutter_x11_get_default_display(); |
| 1273 |
if (dpy == NULL) |
| 1274 |
return FALSE; |
| 1275 |
|
| 1276 |
if (XCompositeQueryExtension (dpy, &event, &error)) |
| 1277 |
{ |
| 1278 |
int major = 0, minor = 0; |
| 1279 |
if (XCompositeQueryVersion (dpy, &major, &minor)) |
| 1280 |
{ |
| 1281 |
if (major >= 0 && minor >= 3) |
| 1282 |
have_composite = TRUE; |
| 1283 |
} |
| 1284 |
} |
| 1285 |
|
| 1286 |
done_check = TRUE; |
| 1287 |
|
| 1288 |
return have_composite; |
| 1289 |
#else |
| 1290 |
return FALSE; |
| 1291 |
#endif /* HAVE_XCOMPOSITE */ |
| 1292 |
} |
| 1293 |
|
| 1294 |
/** |
| 1295 |
* clutter_x11_set_use_argb_visual: |
| 1296 |
* @use_argb: %TRUE if ARGB visuals should be requested by default |
| 1297 |
* |
| 1298 |
* Sets whether the Clutter X11 backend should request ARGB visuals by default |
| 1299 |
* or not. |
| 1300 |
* |
| 1301 |
* By default, Clutter requests RGB visuals. |
| 1302 |
* |
| 1303 |
* If no ARGB visuals are found, the X11 backend will fall back to |
| 1304 |
* requesting a RGB visual instead. |
| 1305 |
* |
| 1306 |
* ARGB visuals are required for the #ClutterStage:use-alpha property to work. |
| 1307 |
* |
| 1308 |
* This function can only be called once, and before clutter_init() is |
| 1309 |
* called. |
| 1310 |
* |
| 1311 |
* Since: 1.2 |
| 1312 |
*/ |
| 1313 |
void |
| 1314 |
clutter_x11_set_use_argb_visual (gboolean use_argb) |
| 1315 |
{ |
| 1316 |
if (_clutter_context_is_initialized ()) |
| 1317 |
{ |
| 1318 |
g_warning ("%s() can only be used before calling clutter_init()", |
| 1319 |
G_STRFUNC); |
| 1320 |
return; |
| 1321 |
} |
| 1322 |
|
| 1323 |
CLUTTER_NOTE (BACKEND, "ARGB visuals are %s", |
| 1324 |
use_argb ? "enabled" : "disabled"); |
| 1325 |
|
| 1326 |
clutter_enable_argb = use_argb; |
| 1327 |
} |
| 1328 |
|
| 1329 |
/** |
| 1330 |
* clutter_x11_get_use_argb_visual: |
| 1331 |
* |
| 1332 |
* Retrieves whether the Clutter X11 backend is using ARGB visuals by default |
| 1333 |
* |
| 1334 |
* Return value: %TRUE if ARGB visuals are queried by default |
| 1335 |
* |
| 1336 |
* Since: 1.2 |
| 1337 |
*/ |
| 1338 |
gboolean |
| 1339 |
clutter_x11_get_use_argb_visual (void) |
| 1340 |
{ |
| 1341 |
return clutter_enable_argb; |
| 1342 |
} |
| 1343 |
|
| 1344 |
/** |
| 1345 |
* clutter_x11_set_use_stereo_stage: |
| 1346 |
* @use_stereo: %TRUE if the stereo stages should be used if possible. |
| 1347 |
* |
| 1348 |
* Sets whether the backend object for Clutter stages, will, |
| 1349 |
* if possible, be created with the ability to support stereo drawing |
| 1350 |
* (drawing separate images for the left and right eyes). |
| 1351 |
* |
| 1352 |
* This function must be called before clutter_init() is called. |
| 1353 |
* During paint callbacks, cogl_framebuffer_is_stereo() can be called |
| 1354 |
* on the framebuffer retrieved by cogl_get_draw_framebuffer() to |
| 1355 |
* determine if stereo support was successfully enabled, and |
| 1356 |
* cogl_framebuffer_set_stereo_mode() to determine which buffers |
| 1357 |
* will be drawn to. |
| 1358 |
* |
| 1359 |
* Note that this function *does not* cause the stage to be drawn |
| 1360 |
* multiple times with different perspective transformations and thus |
| 1361 |
* appear in 3D, it simply enables individual ClutterActors to paint |
| 1362 |
* different images for the left and and right eye. |
| 1363 |
* |
| 1364 |
* Since: 1.22 |
| 1365 |
*/ |
| 1366 |
void |
| 1367 |
clutter_x11_set_use_stereo_stage (gboolean use_stereo) |
| 1368 |
{ |
| 1369 |
if (_clutter_context_is_initialized ()) |
| 1370 |
{ |
| 1371 |
g_warning ("%s() can only be used before calling clutter_init()", |
| 1372 |
G_STRFUNC); |
| 1373 |
return; |
| 1374 |
} |
| 1375 |
|
| 1376 |
CLUTTER_NOTE (BACKEND, "STEREO stages are %s", |
| 1377 |
use_stereo ? "enabled" : "disabled"); |
| 1378 |
|
| 1379 |
clutter_enable_stereo = use_stereo; |
| 1380 |
} |
| 1381 |
|
| 1382 |
/** |
| 1383 |
* clutter_x11_get_use_stereo_stage: |
| 1384 |
* |
| 1385 |
* Retrieves whether the Clutter X11 backend will create stereo |
| 1386 |
* stages if possible. |
| 1387 |
* |
| 1388 |
* Return value: %TRUE if stereo stages are used if possible |
| 1389 |
* |
| 1390 |
* Since: 1.22 |
| 1391 |
*/ |
| 1392 |
gboolean |
| 1393 |
clutter_x11_get_use_stereo_stage (void) |
| 1394 |
{ |
| 1395 |
return clutter_enable_stereo; |
| 1396 |
} |
| 1397 |
|
| 1398 |
XVisualInfo * |
| 1399 |
_clutter_backend_x11_get_visual_info (ClutterBackendX11 *backend_x11) |
| 1400 |
{ |
| 1401 |
return cogl_clutter_winsys_xlib_get_visual_info (); |
| 1402 |
} |
| 1403 |
|
| 1404 |
/** |
| 1405 |
* clutter_x11_get_visual_info: (skip) |
| 1406 |
* |
| 1407 |
* Retrieves the `XVisualInfo` used by the Clutter X11 backend. |
| 1408 |
* |
| 1409 |
* Return value: (transfer full): a `XVisualInfo`, or `None`. |
| 1410 |
* The returned value should be freed using `XFree()` when done |
| 1411 |
* |
| 1412 |
* Since: 1.2 |
| 1413 |
*/ |
| 1414 |
XVisualInfo * |
| 1415 |
clutter_x11_get_visual_info (void) |
| 1416 |
{ |
| 1417 |
ClutterBackendX11 *backend_x11; |
| 1418 |
ClutterBackend *backend; |
| 1419 |
|
| 1420 |
backend = clutter_get_default_backend (); |
| 1421 |
if (!CLUTTER_IS_BACKEND_X11 (backend)) |
| 1422 |
{ |
| 1423 |
g_critical ("The Clutter backend is not a X11 backend."); |
| 1424 |
return NULL; |
| 1425 |
} |
| 1426 |
|
| 1427 |
backend_x11 = CLUTTER_BACKEND_X11 (backend); |
| 1428 |
|
| 1429 |
return _clutter_backend_x11_get_visual_info (backend_x11); |
| 1430 |
} |
| 1431 |
|
| 1432 |
gboolean |
| 1433 |
_clutter_x11_input_device_translate_screen_coord (ClutterInputDevice *device, |
| 1434 |
gint stage_root_x, |
| 1435 |
gint stage_root_y, |
| 1436 |
guint index_, |
| 1437 |
gdouble value, |
| 1438 |
gdouble *axis_value) |
| 1439 |
{ |
| 1440 |
ClutterAxisInfo *info; |
| 1441 |
ClutterBackendX11 *backend_x11; |
| 1442 |
gdouble width, scale, offset; |
| 1443 |
|
| 1444 |
backend_x11 = CLUTTER_BACKEND_X11 (device->backend); |
| 1445 |
|
| 1446 |
if (device->axes == NULL || index_ >= device->axes->len) |
| 1447 |
return FALSE; |
| 1448 |
|
| 1449 |
info = &g_array_index (device->axes, ClutterAxisInfo, index_); |
| 1450 |
if (!(info->axis == CLUTTER_INPUT_AXIS_X || info->axis == CLUTTER_INPUT_AXIS_Y)) |
| 1451 |
return FALSE; |
| 1452 |
|
| 1453 |
width = info->max_value - info->min_value; |
| 1454 |
|
| 1455 |
if (info->axis == CLUTTER_INPUT_AXIS_X) |
| 1456 |
{ |
| 1457 |
if (width > 0) |
| 1458 |
scale = backend_x11->xscreen_width / width; |
| 1459 |
else |
| 1460 |
scale = 1; |
| 1461 |
|
| 1462 |
offset = - stage_root_x; |
| 1463 |
} |
| 1464 |
else |
| 1465 |
{ |
| 1466 |
if (width > 0) |
| 1467 |
scale = backend_x11->xscreen_height / width; |
| 1468 |
else |
| 1469 |
scale = 1; |
| 1470 |
|
| 1471 |
offset = - stage_root_y; |
| 1472 |
} |
| 1473 |
|
| 1474 |
if (axis_value) |
| 1475 |
*axis_value = offset + scale * (value - info->min_value); |
| 1476 |
|
| 1477 |
return TRUE; |
| 1478 |
} |