void cairo_close_x11_surface(cairo_surface_t *sfc) { Display *dsp = cairo_xlib_surface_get_display(sfc); cairo_surface_destroy(sfc); XCloseDisplay(dsp); }
GdkWindow *clg_gdk_cairo_surface_get_window (cairo_surface_t *surface) { /* If 'surface_info_key' had been public we would have had a portable way to find the GdkWindow of a Cairo surface. */ #ifdef GDK_WINDOWING_X11 g_return_if_fail (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB); Display* display = cairo_xlib_surface_get_display (surface); if (display) { Drawable window = cairo_xlib_surface_get_drawable (surface); if (window) return gdk_window_lookup_for_display (window, display); } return NULL; #elif defined (G_OS_WIN32) HDC hdc = (HDC)cairo_win32_surface_get_dc (surface); if (hdc) return gdk_window_lookup ((GdkNativeWindow)hdc); else return NULL; #else return NULL; #endif }
gfxXlibSurface::gfxXlibSurface(cairo_surface_t *csurf) : mPixmapTaken(PR_FALSE), mSize(-1.0, -1.0) { mDrawable = cairo_xlib_surface_get_drawable(csurf); mDisplay = cairo_xlib_surface_get_display(csurf); Init(csurf, PR_TRUE); }
static cairo_surface_t * _create_temp_xlib_surface (cairo_t *cr, Display *dpy, int width, int height, cairo_xlib_drawing_support_t capabilities) { /* base the temp surface on the *screen* surface, not any intermediate * group surface, because the screen surface is more likely to have * characteristics that the xlib-using code is likely to be happy with */ cairo_surface_t *target = cairo_get_target (cr); Drawable target_drawable = cairo_xlib_surface_get_drawable (target); int screen_index = DefaultScreen (dpy); Drawable drawable = RootWindow (dpy, screen_index); Screen *screen = DefaultScreenOfDisplay (dpy); Visual *visual = DefaultVisual (dpy, screen_index); int depth = DefaultDepth (dpy, screen_index); Pixmap pixmap; cairo_surface_t *result; pixmap_free_struct *pfs; /* make the temporary surface match target_drawable to the extent supported by the native rendering code */ if (target_drawable) { Screen *target_screen = cairo_xlib_surface_get_screen (target); Visual *target_visual = cairo_xlib_surface_get_visual (target); if ((target_screen == screen || (capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN)) && target_visual && (target_visual == DefaultVisualOfScreen (target_screen) || (capabilities & CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL))) { drawable = target_drawable; dpy = cairo_xlib_surface_get_display (target); visual = target_visual; depth = cairo_xlib_surface_get_depth (target); } } pfs = malloc (sizeof(pixmap_free_struct)); if (pfs == NULL) return NULL; pixmap = XCreatePixmap (dpy, drawable, width, height, depth); if (!pixmap) { free (pfs); return NULL; } pfs->dpy = dpy; pfs->pixmap = pixmap; result = cairo_xlib_surface_create (dpy, pixmap, visual, width, height); if (cairo_surface_status (result) != CAIRO_STATUS_SUCCESS) { pixmap_free_func (pfs); return NULL; } cairo_surface_set_user_data (result, &pixmap_free_key, pfs, pixmap_free_func); return result; }
void destroy(cairo_surface_t *sfc) { Display *dsp = cairo_xlib_surface_get_display(sfc); cairo_surface_destroy(sfc); cairo_debug_reset_static_data(); XCloseDisplay(dsp); }
void RedirectedXCompositeWindow::cleanupPixmapAndPixmapSurface() { if (!m_pixmap) return; XFreePixmap(cairo_xlib_surface_get_display(m_surface.get()), m_pixmap); m_pixmap = 0; m_surface = nullptr; }
gfxXlibSurface::gfxXlibSurface(cairo_surface_t *csurf) : mPixmapTaken(PR_FALSE), mSize(cairo_xlib_surface_get_width(csurf), cairo_xlib_surface_get_height(csurf)) { NS_PRECONDITION(cairo_surface_status(csurf) == 0, "Not expecting an error surface"); mDrawable = cairo_xlib_surface_get_drawable(csurf); mDisplay = cairo_xlib_surface_get_display(csurf); Init(csurf, PR_TRUE); }
// Respond properly to events. int check_x_event(cairo_surface_t *sfc, int *position, int block) { XEvent event; for (;;) { // If there is nothing in the event cue, XNextEvent will block the program. // If we want to block, then we can. if (block || XPending(cairo_xlib_surface_get_display(sfc))) XNextEvent(cairo_xlib_surface_get_display(sfc), &event); else return 0; // Check it out. switch (event.type) { // This event shouldn't really happen that much (we should always be exposed). case Expose: return -3053; // 3xp053 // -event.xbutton.button -- less likely to be taken? case ButtonPress: //fprintf(stderr, "the button is: %d\n", -event.xbutton.button); *position = event.xbutton.y; return -event.xbutton.button; case KeyPress: return event.xkey.keycode; // This event is a bit weird: https://lists.cairographics.org/archives/cairo/2014-August/025534.html case 65: break; // We don't know the event, drop. default: //fprintf(stderr, "Dropping unhandled XEvent.type = %d.\n", event.type); break; } } }
int cairo_check_event(cairo_surface_t *sfc, int block) { char keybuf[8]; KeySym key; XEvent e; for (;;) { if (block || XPending(cairo_xlib_surface_get_display(sfc))) XNextEvent(cairo_xlib_surface_get_display(sfc), &e); else return 0; switch (e.type) { case ButtonPress: return -e.xbutton.button; case KeyPress: XLookupString(&e.xkey, keybuf, sizeof(keybuf), &key, NULL); return key; default: fprintf(stderr, "Dropping unhandled XEevent.type = %d.\n", e.type); } } }
/* Vladimir Vukicevic reported that surfaces were being created with * mismatching Visuals and XRenderPictFormats. */ static cairo_bool_t surface_compare_visual_and_format (cairo_surface_t *surface) { Display *dpy; Visual *visual; XRenderPictFormat *format; dpy = cairo_xlib_surface_get_display (surface); visual = cairo_xlib_surface_get_visual (surface); if (visual == NULL) return TRUE; format = cairo_xlib_surface_get_xrender_format (surface); if (format == NULL) return TRUE; return format == XRenderFindVisualFormat (dpy, visual); }
static void free_background_surface (EelBackground *self) { cairo_surface_t *surface; surface = self->details->bg_surface; if (surface != NULL) { /* If we created a root surface and didn't set it as background it will live forever, so we need to kill it manually. If set as root background it will be killed next time the background is changed. */ if (self->details->unset_root_surface) { XKillClient (cairo_xlib_surface_get_display (surface), cairo_xlib_surface_get_drawable (surface)); } cairo_surface_destroy (surface); self->details->bg_surface = NULL; } }
/* * croX11Pause() * * Mechanism by which the X11 workstation's windows remain visible until the user * clicks a mouse button or types a key. * */ void croX11Pause(cairo_surface_t* surface) { XEvent event; Display* display = cairo_xlib_surface_get_display(surface); if (!display) return; /* * discard all events that a impatient user * may have acquired while waiting for a plot to finnish */ cairo_surface_flush(surface); while(XCheckMaskEvent(display,ButtonPressMask|KeyPressMask,&event)) { /* loop until false */ } /* * wait for next buttonpress or keypress */ XMaskEvent(display,ButtonPressMask|KeyPressMask,&event); return; }
static cairo_surface_t * _cairo_boilerplate_xlib_create_similar (cairo_surface_t *other, cairo_content_t content, int width, int height) { XRenderPictFormat *xrender_format; uint32_t format; struct similar *similar; cairo_surface_t *surface; similar = malloc (sizeof (*similar)); similar->dpy = cairo_xlib_surface_get_display (other); switch (content) { default: case CAIRO_CONTENT_COLOR_ALPHA: format = PictStandardARGB32; break; case CAIRO_CONTENT_COLOR: format = PictStandardRGB24; break; case CAIRO_CONTENT_ALPHA: format = PictStandardA8; break; } xrender_format = XRenderFindStandardFormat (similar->dpy, format); similar->pixmap = XCreatePixmap (similar->dpy, DefaultRootWindow (similar->dpy), width, height, xrender_format->depth); surface = cairo_xlib_surface_create_with_xrender_format (similar->dpy, similar->pixmap, DefaultScreenOfDisplay (similar->dpy), xrender_format, width, height); cairo_surface_set_user_data (surface, &key, similar, _destroy_similar); return surface; }
static cairo_test_status_t test_cairo_xlib_surface_get_display (cairo_surface_t *surface) { Display *display = cairo_xlib_surface_get_display (surface); return display == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR; }
void croActivateX11(CROddp *psa, cairo_surface_t* surface) { static int initBack = 1; /* code for this function was heavily barrowed from the original X11 driver --RLB */ XWindowAttributes xwa; /* Get window attributes */ CoordSpace square_screen; Display *dpy = cairo_xlib_surface_get_display(surface); Window win = cairo_xlib_surface_get_drawable(surface); if (initBack) { /* We want to set the window's background/border to the * workstation's background color, but can't do it at window * creation time because the workstation color map is not * available then. We do it once here, on the first activation. */ cairo_surface_flush(surface); XSetWindowBackground(dpy, win, psa->ctable[0]); XSetWindowBorder(dpy, win, psa->ctable[0]); initBack = 0; } XSync(dpy, False); /* * Find out how big the window is; calculate the * coordinate translation macros. */ if (XGetWindowAttributes(dpy, win, &xwa) == 0) { ESprintf(ERR_WIN_ATTRIB, "XGetWindowAttributes(,,)"); return; } square_screen = ComputeLargestSquare( (double) 0.0, (double) (xwa.height - 1), (double) (xwa.width - 1), (double) 0.0 ); psa->image_width = xwa.width; /*square_screen.urx; */ psa->image_height = xwa.height; /*square_screen.lly;*/ psa->dspace.llx = square_screen.llx; psa->dspace.urx = square_screen.urx; psa->dspace.lly = square_screen.ury; /* note flip of y-axis */ psa->dspace.ury = square_screen.lly; /* " */ psa->dspace.xspan = ((psa->dspace.urx) - (psa->dspace.llx)); psa->dspace.yspan = ((psa->dspace.ury) - (psa->dspace.lly)); if (psa->cro_clip.null == FALSE) { psa->cro_clip.llx = psa->dspace.llx; psa->cro_clip.lly = psa->dspace.lly; psa->cro_clip.urx = psa->dspace.urx; psa->cro_clip.ury = psa->dspace.ury; } cairo_xlib_surface_set_size(surface, xwa.width, xwa.height); return; }
void croFreeNativeSurface(cairo_surface_t* surface) { /* free all X11 resources... */ XCloseDisplay(cairo_xlib_surface_get_display(surface)); }