static void clutter_stage_gdk_set_gdk_geometry (ClutterStageGdk *stage) { GdkGeometry geometry; ClutterStage *wrapper = CLUTTER_STAGE_COGL (stage)->wrapper; gboolean resize = clutter_stage_get_user_resizable (wrapper); if (!resize) { geometry.min_width = geometry.max_width = gdk_window_get_width (stage->window); geometry.min_height = geometry.max_height = gdk_window_get_height (stage->window); gdk_window_set_geometry_hints (stage->window, &geometry, GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); } else { clutter_stage_get_minimum_size (wrapper, (guint *)&geometry.min_width, (guint *)&geometry.min_height); gdk_window_set_geometry_hints (stage->window, &geometry, GDK_HINT_MIN_SIZE); } }
static gboolean clutter_stage_wayland_realize (ClutterStageWindow *stage_window) { ClutterStageWayland *stage_wayland = CLUTTER_STAGE_WAYLAND (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window); struct wl_surface *wl_surface; struct wl_shell_surface *wl_shell_surface; clutter_stage_window_parent_iface->realize (stage_window); wl_surface = cogl_wayland_onscreen_get_surface (stage_cogl->onscreen); wl_surface_set_user_data (wl_surface, stage_wayland); wl_shell_surface = cogl_wayland_onscreen_get_shell_surface (stage_cogl->onscreen); wl_shell_surface_add_listener (wl_shell_surface, &shell_surface_listener, stage_wayland); stage_wayland->wayland_surface = wl_surface; stage_wayland->wayland_shell_surface = wl_shell_surface; if (stage_wayland->fullscreen) clutter_stage_wayland_set_fullscreen (stage_window, TRUE); return TRUE; }
static inline void set_wm_title (ClutterStageX11 *stage_x11) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); if (stage_x11->xwin == None || stage_x11->is_foreign_xwin) return; if (stage_x11->title == NULL) { XDeleteProperty (backend_x11->xdpy, stage_x11->xwin, backend_x11->atom_NET_WM_NAME); } else { XChangeProperty (backend_x11->xdpy, stage_x11->xwin, backend_x11->atom_NET_WM_NAME, backend_x11->atom_UTF8_STRING, 8, PropModeReplace, (unsigned char *) stage_x11->title, (int) strlen (stage_x11->title)); } }
gboolean _clutter_stage_x11_get_root_coords (ClutterStageX11 *stage_x11, gint *root_x, gint *root_y) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); gint return_val; Window child; gint tx, ty; return_val = XTranslateCoordinates (backend_x11->xdpy, stage_x11->xwin, backend_x11->xwin_root, 0, 0, &tx, &ty, &child); if (root_x) *root_x = tx; if (root_y) *root_y = ty; return (return_val == 0); }
static void clutter_stage_x11_get_geometry (ClutterStageWindow *stage_window, cairo_rectangle_int_t *geometry) { ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); geometry->x = geometry->y = 0; /* If we're fullscreen, return the size of the display. * * FIXME - this is utterly broken for anything that is not a single * head set up; the window manager will give us the right size in a * ConfigureNotify, but between the fullscreen signal emission on the * stage and the following frame, the size returned by the stage will * be wrong. */ if (_clutter_stage_is_fullscreen (stage_cogl->wrapper) && stage_x11->fullscreening) { geometry->width = DisplayWidth (backend_x11->xdpy, backend_x11->xscreen_num); geometry->height = DisplayHeight (backend_x11->xdpy, backend_x11->xscreen_num); return; } geometry->width = stage_x11->xwin_width; geometry->height = stage_x11->xwin_height; }
void _clutter_stage_x11_set_user_time (ClutterStageX11 *stage_x11, guint32 user_time) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); set_user_time (backend_x11, stage_x11, user_time); }
static void clutter_stage_x11_dispose (GObject *gobject) { ClutterEventTranslator *translator = CLUTTER_EVENT_TRANSLATOR (gobject); ClutterBackend *backend = CLUTTER_STAGE_COGL (gobject)->backend; _clutter_backend_remove_event_translator (backend, translator); G_OBJECT_CLASS (clutter_stage_x11_parent_class)->dispose (gobject); }
static void clutter_stage_gdk_hide (ClutterStageWindow *stage_window) { ClutterStageGdk *stage_gdk = CLUTTER_STAGE_GDK (stage_window); g_return_if_fail (stage_gdk->window != NULL); clutter_actor_unmap (CLUTTER_ACTOR (CLUTTER_STAGE_COGL (stage_gdk)->wrapper)); gdk_window_hide (stage_gdk->window); }
/** * clutter_gdk_get_stage_from_window: * @window: a #GtkWindow * * Gets the stage for a particular X window. * * Return value: (transfer none): A #ClutterStage, or% NULL if a stage * does not exist for the window * * Since: 1.10 */ ClutterStage * clutter_gdk_get_stage_from_window (GdkWindow *window) { ClutterStageGdk *stage_gdk = g_object_get_data (G_OBJECT (window), "clutter-stage-window"); if (stage_gdk != NULL && CLUTTER_IS_STAGE_GDK (stage_gdk)) return CLUTTER_STAGE_COGL (stage_gdk)->wrapper; return NULL; }
static void clutter_stage_x11_fix_window_size (ClutterStageX11 *stage_x11, gint new_width, gint new_height) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); if (stage_x11->xwin != None && !stage_x11->is_foreign_xwin) { guint min_width, min_height; XSizeHints *size_hints; gboolean resize; resize = clutter_stage_get_user_resizable (stage_cogl->wrapper); size_hints = XAllocSizeHints(); clutter_stage_get_minimum_size (stage_cogl->wrapper, &min_width, &min_height); if (new_width <= 0) new_width = min_width; if (new_height <= 0) new_height = min_height; size_hints->flags = 0; /* If we are going fullscreen then we don't want any restrictions on the window size */ if (!stage_x11->fullscreening) { if (resize) { size_hints->min_width = min_width; size_hints->min_height = min_height; size_hints->flags = PMinSize; } else { size_hints->min_width = new_width; size_hints->min_height = new_height; size_hints->max_width = new_width; size_hints->max_height = new_height; size_hints->flags = PMinSize | PMaxSize; } } XSetWMNormalHints (backend_x11->xdpy, stage_x11->xwin, size_hints); XFree(size_hints); } }
static void clutter_stage_x11_set_wm_protocols (ClutterStageX11 *stage_x11) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); Atom protocols[2]; int n = 0; protocols[n++] = backend_x11->atom_WM_DELETE_WINDOW; protocols[n++] = backend_x11->atom_NET_WM_PING; XSetWMProtocols (backend_x11->xdpy, stage_x11->xwin, protocols, n); }
static void stage_events_device_added (ClutterDeviceManager *device_manager, ClutterInputDevice *device, gpointer user_data) { ClutterStageWindow *stage_window = user_data; ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window); int event_flags = CLUTTER_STAGE_X11_EVENT_MASK; if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_FLOATING) _clutter_device_manager_select_stage_events (device_manager, stage_cogl->wrapper, event_flags); }
static void clutter_stage_wayland_resize (ClutterStageWindow *stage_window, gint width, gint height) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window); /* Resize preserving top left */ if (stage_cogl->onscreen) { cogl_wayland_onscreen_resize (stage_cogl->onscreen, width, height, 0, 0); _clutter_stage_window_redraw (stage_window); } }
static void clutter_stage_wayland_show (ClutterStageWindow *stage_window, gboolean do_raise) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window); clutter_stage_window_parent_iface->show (stage_window, do_raise); /* We need to queue a redraw after the stage is shown because all of * the other queue redraws up to this point will have been ignored * because the actor was not visible. The other backends do not need * to do this because they will get expose events at some point, but * that does not happen for Wayland. */ clutter_actor_queue_redraw (CLUTTER_ACTOR (stage_cogl->wrapper)); }
static void clutter_stage_gdk_show (ClutterStageWindow *stage_window, gboolean do_raise) { ClutterStageGdk *stage_gdk = CLUTTER_STAGE_GDK (stage_window); g_return_if_fail (stage_gdk->window != NULL); clutter_actor_map (CLUTTER_ACTOR (CLUTTER_STAGE_COGL (stage_gdk)->wrapper)); if (do_raise) gdk_window_show (stage_gdk->window); else gdk_window_show_unraised (stage_gdk->window); }
void _clutter_stage_x11_events_device_changed (ClutterStageX11 *stage_x11, ClutterInputDevice *device, ClutterDeviceManager *device_manager) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); int event_flags = 0; if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_FLOATING) event_flags = CLUTTER_STAGE_X11_EVENT_MASK; _clutter_device_manager_select_stage_events (device_manager, stage_cogl->wrapper, event_flags); }
static void clutter_stage_wayland_set_fullscreen (ClutterStageWindow *stage_window, gboolean fullscreen) { ClutterStageWayland *stage_wayland = CLUTTER_STAGE_WAYLAND (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window); ClutterBackend *backend = CLUTTER_BACKEND (stage_cogl->backend); ClutterBackendWayland *backend_wayland = CLUTTER_BACKEND_WAYLAND (backend); ClutterActor *stage = _clutter_stage_window_get_wrapper (stage_window); stage_wayland->fullscreen = fullscreen; if (!stage_wayland->wayland_shell_surface) /* Not realized yet */ return; if (fullscreen) { _clutter_stage_update_state (stage_cogl->wrapper, 0, CLUTTER_STAGE_STATE_FULLSCREEN); /* FIXME: In future versions of the Wayland protocol we'll get a * configure with the dimensions we can use - but for now we have to * use the dimensions from the output's mode */ clutter_actor_set_size (stage, backend_wayland->output_width, backend_wayland->output_height); /* FIXME: And we must force a redraw so that new sized buffer gets * attached */ _clutter_stage_window_redraw (stage_window); wl_shell_surface_set_fullscreen (stage_wayland->wayland_shell_surface, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, NULL); } else { _clutter_stage_update_state (stage_cogl->wrapper, CLUTTER_STAGE_STATE_FULLSCREEN, 0); wl_shell_surface_set_toplevel (stage_wayland->wayland_shell_surface); } }
static inline void set_cursor_visible (ClutterStageX11 *stage_x11) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); if (stage_x11->xwin == None) return; CLUTTER_NOTE (BACKEND, "setting cursor state ('%s') over stage window (%u)", stage_x11->is_cursor_visible ? "visible" : "invisible", (unsigned int) stage_x11->xwin); if (stage_x11->is_cursor_visible) { #if HAVE_XFIXES if (stage_x11->cursor_hidden_xfixes) { XFixesShowCursor (backend_x11->xdpy, stage_x11->xwin); stage_x11->cursor_hidden_xfixes = FALSE; } #else XUndefineCursor (backend_x11->xdpy, stage_x11->xwin); #endif /* HAVE_XFIXES */ } else { #if HAVE_XFIXES XFixesHideCursor (backend_x11->xdpy, stage_x11->xwin); stage_x11->cursor_hidden_xfixes = TRUE; #else XColor col; Pixmap pix; Cursor curs; pix = XCreatePixmap (backend_x11->xdpy, stage_x11->xwin, 1, 1, 1); memset (&col, 0, sizeof (col)); curs = XCreatePixmapCursor (backend_x11->xdpy, pix, pix, &col, &col, 1, 1); XFreePixmap (backend_x11->xdpy, pix); XDefineCursor (backend_x11->xdpy, stage_x11->xwin, curs); #endif /* HAVE_XFIXES */ } }
static gboolean handle_wm_protocols_event (ClutterBackendX11 *backend_x11, ClutterStageX11 *stage_x11, XEvent *xevent) { Atom atom = (Atom) xevent->xclient.data.l[0]; if (atom == backend_x11->atom_WM_DELETE_WINDOW && xevent->xany.window == stage_x11->xwin) { #ifdef CLUTTER_ENABLE_DEBUG ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); /* the WM_DELETE_WINDOW is a request: we do not destroy * the window right away, as it might contain vital data; * we relay the event to the application and we let it * handle the request */ CLUTTER_NOTE (EVENT, "Delete stage %s[%p], win:0x%x", _clutter_actor_get_debug_name (CLUTTER_ACTOR (stage_cogl->wrapper)), stage_cogl->wrapper, (unsigned int) stage_x11->xwin); #endif /* CLUTTER_ENABLE_DEBUG */ set_user_time (backend_x11, stage_x11, xevent->xclient.data.l[1]); return TRUE; } else if (atom == backend_x11->atom_NET_WM_PING && xevent->xany.window == stage_x11->xwin) { XClientMessageEvent xclient = xevent->xclient; xclient.window = backend_x11->xwin_root; XSendEvent (backend_x11->xdpy, xclient.window, False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *) &xclient); return FALSE; } /* do not send any of the WM_PROTOCOLS events to the queue */ return FALSE; }
static inline void update_wm_hints (ClutterStageX11 *stage_x11) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); XWMHints wm_hints; if (stage_x11->wm_state & STAGE_X11_WITHDRAWN) return; if (stage_x11->is_foreign_xwin) return; wm_hints.flags = StateHint | InputHint; wm_hints.initial_state = NormalState; wm_hints.input = stage_x11->accept_focus ? True : False; XSetWMHints (backend_x11->xdpy, stage_x11->xwin, &wm_hints); }
static void clutter_stage_gdk_set_fullscreen (ClutterStageWindow *stage_window, gboolean is_fullscreen) { ClutterStageGdk *stage_gdk = CLUTTER_STAGE_GDK (stage_window); ClutterStage *stage = CLUTTER_STAGE_COGL (stage_window)->wrapper; if (stage == NULL || CLUTTER_ACTOR_IN_DESTRUCTION (stage)) return; if (stage_gdk->window == NULL) return; CLUTTER_NOTE (BACKEND, "%ssetting fullscreen", is_fullscreen ? "" : "un"); if (is_fullscreen) gdk_window_fullscreen (stage_gdk->window); else gdk_window_unfullscreen (stage_gdk->window); }
static void clutter_stage_x11_hide (ClutterStageWindow *stage_window) { ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); if (stage_x11->xwin != None) { if (STAGE_X11_IS_MAPPED (stage_x11)) set_stage_x11_state (stage_x11, 0, STAGE_X11_WITHDRAWN); g_assert (!STAGE_X11_IS_MAPPED (stage_x11)); clutter_actor_unmap (CLUTTER_ACTOR (stage_cogl->wrapper)); if (!stage_x11->is_foreign_xwin) XWithdrawWindow (backend_x11->xdpy, stage_x11->xwin, 0); } }
static void clutter_stage_x11_show (ClutterStageWindow *stage_window, gboolean do_raise) { ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); if (stage_x11->xwin != None) { if (do_raise && !stage_x11->is_foreign_xwin) { CLUTTER_NOTE (BACKEND, "Raising stage[%lu]", (unsigned long) stage_x11->xwin); XRaiseWindow (backend_x11->xdpy, stage_x11->xwin); } if (!STAGE_X11_IS_MAPPED (stage_x11)) { CLUTTER_NOTE (BACKEND, "Mapping stage[%lu]", (unsigned long) stage_x11->xwin); set_stage_x11_state (stage_x11, STAGE_X11_WITHDRAWN, 0); update_wm_hints (stage_x11); if (stage_x11->fullscreening) clutter_stage_x11_set_fullscreen (stage_window, TRUE); else clutter_stage_x11_set_fullscreen (stage_window, FALSE); } g_assert (STAGE_X11_IS_MAPPED (stage_x11)); clutter_actor_map (CLUTTER_ACTOR (stage_cogl->wrapper)); if (!stage_x11->is_foreign_xwin) XMapWindow (backend_x11->xdpy, stage_x11->xwin); } }
static void handle_configure (void *data, struct wl_shell_surface *shell_surface, uint32_t edges, int32_t width, int32_t height) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL(data); CoglFramebuffer *fb = COGL_FRAMEBUFFER (stage_cogl->onscreen); if (cogl_framebuffer_get_width (fb) != width || cogl_framebuffer_get_height (fb) != height) clutter_actor_queue_relayout (CLUTTER_ACTOR (stage_cogl->wrapper)); clutter_actor_set_size (CLUTTER_ACTOR (stage_cogl->wrapper), width, height); /* the resize process is complete, so we can ask the stage * to set up the GL viewport with the new size */ clutter_stage_ensure_viewport (stage_cogl->wrapper); }
static void set_foreign_window_callback (ClutterActor *actor, void *data) { ForeignWindowData *fwd = data; ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (fwd->stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); CLUTTER_NOTE (BACKEND, "Setting foreign window (0x%x)", (unsigned int) fwd->xwindow); if (fwd->destroy_old_xwindow && fwd->stage_x11->xwin != None) { CLUTTER_NOTE (BACKEND, "Destroying previous window (0x%x)", (unsigned int) fwd->xwindow); XDestroyWindow (backend_x11->xdpy, fwd->stage_x11->xwin); } fwd->stage_x11->xwin = fwd->xwindow; fwd->stage_x11->is_foreign_xwin = TRUE; fwd->stage_x11->xwin_width = fwd->geom.width; fwd->stage_x11->xwin_height = fwd->geom.height; clutter_actor_set_size (actor, fwd->geom.width, fwd->geom.height); if (clutter_stages_by_xid == NULL) clutter_stages_by_xid = g_hash_table_new (NULL, NULL); g_hash_table_insert (clutter_stages_by_xid, GINT_TO_POINTER (fwd->stage_x11->xwin), fwd->stage_x11); /* calling this with the stage unrealized will unset the stage * from the GL context; once the stage is realized the GL context * will be set again */ clutter_stage_ensure_current (CLUTTER_STAGE (actor)); }
static inline void set_wm_pid (ClutterStageX11 *stage_x11) { ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); long pid; if (stage_x11->xwin == None || stage_x11->is_foreign_xwin) return; /* this will take care of WM_CLIENT_MACHINE and WM_LOCALE_NAME */ XSetWMProperties (backend_x11->xdpy, stage_x11->xwin, NULL, NULL, NULL, 0, NULL, NULL, NULL); pid = getpid (); XChangeProperty (backend_x11->xdpy, stage_x11->xwin, backend_x11->atom_NET_WM_PID, XA_CARDINAL, 32, PropModeReplace, (guchar *) &pid, 1); }
static void clutter_stage_x11_set_fullscreen (ClutterStageWindow *stage_window, gboolean is_fullscreen) { ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); ClutterStage *stage = stage_cogl->wrapper; gboolean was_fullscreen; if (stage == NULL || CLUTTER_ACTOR_IN_DESTRUCTION (stage)) return; was_fullscreen = _clutter_stage_is_fullscreen (stage); is_fullscreen = !!is_fullscreen; if (was_fullscreen == is_fullscreen) return; CLUTTER_NOTE (BACKEND, "%ssetting fullscreen", is_fullscreen ? "" : "un"); if (is_fullscreen) { #if 0 int width, height; /* FIXME: this will do the wrong thing for dual-headed displays. This will return the size of the combined display but Metacity (at least) will fullscreen to only one of the displays. This will cause the actor to report the wrong size until the ConfigureNotify for the correct size is received */ width = DisplayWidth (backend_x11->xdpy, backend_x11->xscreen_num); height = DisplayHeight (backend_x11->xdpy, backend_x11->xscreen_num); #endif /* Set the fullscreen hint so we can retain the old size of the window. */ stage_x11->fullscreening = TRUE; if (stage_x11->xwin != None) { /* if the actor is not mapped we resize the stage window to match * the size of the screen; this is useful for e.g. EGLX to avoid * a resize when calling clutter_stage_fullscreen() before showing * the stage */ if (!STAGE_X11_IS_MAPPED (stage_x11)) { CLUTTER_NOTE (BACKEND, "Fullscreening unmapped stage"); update_state (stage_x11, backend_x11, &backend_x11->atom_NET_WM_STATE_FULLSCREEN, TRUE); } else { CLUTTER_NOTE (BACKEND, "Fullscreening mapped stage"); /* We need to fix the window size so that it will remove the maximum and minimum window hints. Otherwise metacity will honour the restrictions and not fullscreen correctly. */ clutter_stage_x11_fix_window_size (stage_x11, -1, -1); send_wmspec_change_state (backend_x11, stage_x11->xwin, backend_x11->atom_NET_WM_STATE_FULLSCREEN, TRUE); } } else stage_x11->fullscreen_on_realize = TRUE; } else { stage_x11->fullscreening = FALSE; if (stage_x11->xwin != None) { if (!STAGE_X11_IS_MAPPED (stage_x11)) { CLUTTER_NOTE (BACKEND, "Un-fullscreening unmapped stage"); update_state (stage_x11, backend_x11, &backend_x11->atom_NET_WM_STATE_FULLSCREEN, FALSE); } else { CLUTTER_NOTE (BACKEND, "Un-fullscreening mapped stage"); send_wmspec_change_state (backend_x11, stage_x11->xwin, backend_x11->atom_NET_WM_STATE_FULLSCREEN, FALSE); /* Fix the window size to restore the minimum/maximum restriction */ clutter_stage_x11_fix_window_size (stage_x11, stage_x11->xwin_width, stage_x11->xwin_height); } } else stage_x11->fullscreen_on_realize = FALSE; } /* XXX: Note we rely on the ConfigureNotify mechanism as the common * mechanism to handle notifications of new X window sizes from the * X server so we don't actively change the stage viewport here or * queue a relayout etc. */ }
static void clutter_stage_x11_resize (ClutterStageWindow *stage_window, gint width, gint height) { ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_x11); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (stage_cogl->backend); if (stage_x11->is_foreign_xwin) { /* If this is a foreign window we won't get a ConfigureNotify, * so we need to manually set the size and queue a relayout on the * stage here (as is normally done in response to ConfigureNotify). */ stage_x11->xwin_width = width; stage_x11->xwin_height = height; clutter_actor_queue_relayout (CLUTTER_ACTOR (stage_cogl->wrapper)); return; } /* If we're going fullscreen, don't mess with the size */ if (stage_x11->fullscreening) return; if (width == 0 || height == 0) { /* Should not happen, if this turns up we need to debug it and * determine the cleanest way to fix. */ g_warning ("X11 stage not allowed to have 0 width or height"); width = 1; height = 1; } CLUTTER_NOTE (BACKEND, "New size received: (%d, %d)", width, height); if (stage_x11->xwin != None) { clutter_stage_x11_fix_window_size (stage_x11, width, height); if (width != stage_x11->xwin_width || height != stage_x11->xwin_height) { CLUTTER_NOTE (BACKEND, "%s: XResizeWindow[%x] (%d, %d)", G_STRLOC, (unsigned int) stage_x11->xwin, width, height); CLUTTER_SET_PRIVATE_FLAGS (stage_cogl->wrapper, CLUTTER_IN_RESIZE); /* XXX: in this case we can rely on a subsequent * ConfigureNotify that will result in the stage * being reallocated so we don't actively do anything * to affect the stage allocation here. */ XResizeWindow (backend_x11->xdpy, stage_x11->xwin, width, height); } } }
static gboolean clutter_stage_gdk_realize (ClutterStageWindow *stage_window) { ClutterStageGdk *stage_gdk = CLUTTER_STAGE_GDK (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window); ClutterBackend *backend = CLUTTER_BACKEND (stage_cogl->backend); ClutterBackendGdk *backend_gdk = CLUTTER_BACKEND_GDK (backend); GdkWindowAttr attributes; gboolean cursor_visible; gboolean use_alpha; gfloat width, height; if (stage_gdk->foreign_window) { width = gdk_window_get_width (stage_gdk->window); height = gdk_window_get_height (stage_gdk->window); } else { if (stage_gdk->window != NULL) { /* complete realizing the stage */ cairo_rectangle_int_t geometry; clutter_stage_gdk_get_geometry (stage_window, &geometry); clutter_actor_set_size (CLUTTER_ACTOR (stage_cogl->wrapper), geometry.width, geometry.height); gdk_window_ensure_native (stage_gdk->window); gdk_window_set_events (stage_gdk->window, CLUTTER_STAGE_GDK_EVENT_MASK); return TRUE; } else { attributes.title = NULL; g_object_get (stage_cogl->wrapper, "cursor-visible", &cursor_visible, "title", &attributes.title, "width", &width, "height", &height, "use-alpha", &use_alpha, NULL); attributes.width = width; attributes.height = height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.window_type = GDK_WINDOW_TOPLEVEL; attributes.event_mask = CLUTTER_STAGE_GDK_EVENT_MASK; attributes.cursor = NULL; if (!cursor_visible) { if (stage_gdk->blank_cursor == NULL) stage_gdk->blank_cursor = gdk_cursor_new_for_display (backend_gdk->display, GDK_BLANK_CURSOR); attributes.cursor = stage_gdk->blank_cursor; } attributes.visual = NULL; if (use_alpha) { attributes.visual = gdk_screen_get_rgba_visual (backend_gdk->screen); if (attributes.visual == NULL) clutter_stage_set_use_alpha (stage_cogl->wrapper, FALSE); } if (attributes.visual == NULL) { /* This could still be an RGBA visual, although normally it's not */ attributes.visual = gdk_screen_get_system_visual (backend_gdk->screen); } stage_gdk->foreign_window = FALSE; stage_gdk->window = gdk_window_new (NULL, &attributes, GDK_WA_TITLE | GDK_WA_CURSOR | GDK_WA_VISUAL); g_free (attributes.title); } clutter_stage_gdk_set_gdk_geometry (stage_gdk); } gdk_window_ensure_native (stage_gdk->window); g_object_set_data (G_OBJECT (stage_gdk->window), "clutter-stage-window", stage_gdk); stage_cogl->onscreen = cogl_onscreen_new (backend->cogl_context, width, height); #if defined(GDK_WINDOWING_X11) && defined(COGL_HAS_XLIB_SUPPORT) if (GDK_IS_X11_WINDOW (stage_gdk->window)) { cogl_x11_onscreen_set_foreign_window_xid (stage_cogl->onscreen, GDK_WINDOW_XID (stage_gdk->window), clutter_stage_gdk_update_foreign_event_mask, stage_gdk); } else #endif #if defined(GDK_WINDOWING_WAYLAND) && defined(COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT) if (GDK_IS_WAYLAND_WINDOW (stage_gdk->window)) { cogl_wayland_onscreen_set_foreign_surface (stage_cogl->onscreen, gdk_wayland_window_get_wl_surface (stage_gdk->window)); } else #endif #if defined(GDK_WINDOWING_WIN32) && defined(COGL_HAS_WIN32_SUPPORT) if (GDK_IS_WIN32_WINDOW (stage_gdk->window)) { cogl_win32_onscreen_set_foreign_window (stage_cogl->onscreen, gdk_win32_window_get_handle (stage_gdk->window)); } else #endif { g_warning ("Cannot find an appropriate CoglWinsys for a " "GdkWindow of type %s", G_OBJECT_TYPE_NAME (stage_gdk->window)); cogl_object_unref (stage_cogl->onscreen); stage_cogl->onscreen = NULL; if (!stage_gdk->foreign_window) gdk_window_destroy (stage_gdk->window); stage_gdk->window = NULL; return FALSE; } return clutter_stage_window_parent_iface->realize (stage_window); }
static gboolean clutter_stage_x11_realize (ClutterStageWindow *stage_window) { ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window); ClutterBackend *backend = CLUTTER_BACKEND (stage_cogl->backend); ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend); ClutterDeviceManager *device_manager; int event_flags; gfloat width, height; clutter_actor_get_size (CLUTTER_ACTOR (stage_cogl->wrapper), &width, &height); stage_cogl->onscreen = cogl_onscreen_new (backend->cogl_context, width, height); /* We just created a window of the size of the actor. No need to fix the size of the stage, just update it. */ stage_x11->xwin_width = width; stage_x11->xwin_height = height; if (stage_x11->xwin != None) { cogl_x11_onscreen_set_foreign_window_xid (stage_cogl->onscreen, stage_x11->xwin, _clutter_stage_x11_update_foreign_event_mask, stage_x11); } /* Chain to the parent class now. ClutterStageCogl will call cogl_framebuffer_allocate, which will create the X Window we need */ if (!(clutter_stage_window_parent_iface->realize (stage_window))) return FALSE; if (stage_x11->xwin == None) stage_x11->xwin = cogl_x11_onscreen_get_window_xid (stage_cogl->onscreen); if (clutter_stages_by_xid == NULL) clutter_stages_by_xid = g_hash_table_new (NULL, NULL); g_hash_table_insert (clutter_stages_by_xid, GINT_TO_POINTER (stage_x11->xwin), stage_x11); set_wm_pid (stage_x11); set_wm_title (stage_x11); set_cursor_visible (stage_x11); /* the masks for the events we want to select on a stage window; * KeyPressMask and KeyReleaseMask are necessary even with XI1 * because key events are broken with that extension, and will * be fixed by XI2 */ event_flags = CLUTTER_STAGE_X11_EVENT_MASK; /* we unconditionally select input events even with event retrieval * disabled because we need to guarantee that the Clutter internal * state is maintained when calling clutter_x11_handle_event() without * requiring applications or embedding toolkits to select events * themselves. if we did that, we'd have to document the events to be * selected, and also update applications and embedding toolkits each * time we added a new mask, or a new class of events. * * see: http://bugzilla.clutter-project.org/show_bug.cgi?id=998 * for the rationale of why we did conditional selection. it is now * clear that a compositor should clear out the input region, since * it cannot assume a perfectly clean slate coming from us. * * see: http://bugzilla.clutter-project.org/show_bug.cgi?id=2228 * for an example of things that break if we do conditional event * selection. */ XSelectInput (backend_x11->xdpy, stage_x11->xwin, event_flags); /* input events also depent on the actual device, so we need to * use the device manager to let every device select them, using * the event mask we passed to XSelectInput as the template */ device_manager = clutter_device_manager_get_default (); if (G_UNLIKELY (device_manager != NULL)) { _clutter_device_manager_select_stage_events (device_manager, stage_cogl->wrapper, event_flags); g_signal_connect (device_manager, "device-added", G_CALLBACK (stage_events_device_added), stage_window); } clutter_stage_x11_fix_window_size (stage_x11, stage_x11->xwin_width, stage_x11->xwin_height); clutter_stage_x11_set_wm_protocols (stage_x11); if (stage_x11->fullscreen_on_realize) { stage_x11->fullscreen_on_realize = FALSE; clutter_stage_x11_set_fullscreen (stage_window, TRUE); } CLUTTER_NOTE (BACKEND, "Successfully realized stage"); return TRUE; }