コード例 #1
0
static cairo_t *
gdk_cairo_create (GdkDrawable *drawable)
{
    int width, height;
    cairo_t *cr = NULL;
    cairo_surface_t *surface = NULL;
    GdkVisual *visual = gdk_drawable_get_visual (drawable);

    gdk_drawable_get_size (drawable, &width, &height);
    if (visual)
	surface = cairo_xlib_surface_create (GDK_DRAWABLE_XDISPLAY (drawable),
					     GDK_DRAWABLE_XID (drawable),
					     GDK_VISUAL_XVISUAL (visual),
					     width, height);
    else if (gdk_drawable_get_depth (drawable) == 1)
	surface = cairo_xlib_surface_create_for_bitmap
	    (GDK_PIXMAP_XDISPLAY (drawable),
	     GDK_PIXMAP_XID (drawable),
	     GDK_SCREEN_XSCREEN (gdk_drawable_get_screen (drawable)),
	     width, height);
    else {
	g_warning ("Using Cairo rendering requires the drawable argument to\n"
		   "have a specified colormap. All windows have a colormap,\n"
		   "however, pixmaps only have colormap by default if they\n"
		   "were created with a non-NULL window argument. Otherwise\n"
		   "a colormap must be set on them with "
		   "gdk_drawable_set_colormap");
	return NULL;
    }
    if (surface) {
	cr = cairo_create (surface);
	cairo_surface_destroy (surface);
    }
    return cr;
}
コード例 #2
0
void setup_plot_drawable( App *a )
{
    struct
    {
        Display  *display;
        Drawable drawable;
    }     xinfo;

    PLFLT x[3] = { 1, 3, 4 };
    PLFLT y[3] = { 3, 2, 5 };

    plsdev( "xcairo" );
    plsetopt( "drvopt", "external_drawable" );
    plinit();

  #if TO_PIXMAP == 1
    // Here we set up to draw to a pixmap
    xinfo.display  = GDK_PIXMAP_XDISPLAY( a->plotwindow_pixmap );
    xinfo.drawable = GDK_PIXMAP_XID( a->plotwindow_pixmap );
  #else
    // Alternatively, we can do direct to a visible X Window
    xinfo.display  = GDK_WINDOW_XDISPLAY( a->plotwindow->window );
    xinfo.drawable = GDK_WINDOW_XID( a->plotwindow->window );
  #endif

    pl_cmd( PLESC_DEVINIT, &xinfo );
    plenv( 0, 5, 0, 5, 0, 0 );

    plline( 3, x, y );
    plend();
}
コード例 #3
0
ファイル: dialog.c プロジェクト: 0p1pp1/mplayer
/**
 * @brief Initialize the GTK user interface.
 *
 * @param display_name name of the X display to use or NULL (using the DISPLAY environment variable)
 */
void gtkInit(char *display_name)
{
    int argc = 0;
    char *arg[3], **argv = arg;
    char *env;
    GtkIconTheme *theme;
    GdkPixmap *gdkIcon;
    GdkBitmap *gdkIconMask;

    mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n");

    arg[argc++] = gmplayer;

    if (display_name) {             // MPlayer option '-display' was given
        arg[argc++] = "--display";  // Pass corresponding command line arguments to GTK,
        arg[argc++] = display_name; // to open the requested display for the GUI, too.
    }

    gtk_disable_setlocale();

    env = getenv("G_FILENAME_ENCODING");

    if ((!env && getenv("G_BROKEN_FILENAMES")) || (gstrncmp(env, "@locale", 7) == 0))
        mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_GUI_MSG_LocaleEncoding);

    gtk_init(&argc, &argv);
    wsSetErrorHandler();      // GDK has just set its own handler

    theme = gtk_icon_theme_get_default();

    if (gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask)) {
        guiIcon.small      = GDK_PIXMAP_XID(gdkIcon);
        guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask);
    }

    if (gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask)) {
        guiIcon.normal      = GDK_PIXMAP_XID(gdkIcon);
        guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask);
    }

    gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask);

    gtkInitialized = True;
}
コード例 #4
0
ファイル: gdkdrawable-x11.c プロジェクト: chipx86/gtk
static void
gdk_x11_drawable_update_picture_clip (GdkDrawable *drawable,
				      GdkGC       *gc)
{
  GdkDrawableImplX11 *impl = GDK_DRAWABLE_IMPL_X11 (drawable);
  Display *xdisplay = GDK_SCREEN_XDISPLAY (impl->screen);
  Picture picture = gdk_x11_drawable_get_picture (drawable);
  GdkRegion *clip_region = gc ? _gdk_gc_get_clip_region (gc) : NULL;

  if (clip_region)
    {
      GdkRegionBox *boxes = clip_region->rects;
      gint n_boxes = clip_region->numRects;
      XRectangle *rects = g_new (XRectangle, n_boxes);
      int i;

      for (i=0; i < n_boxes; i++)
	{
	  rects[i].x = CLAMP (boxes[i].x1 + gc->clip_x_origin, G_MINSHORT, G_MAXSHORT);
	  rects[i].y = CLAMP (boxes[i].y1 + gc->clip_y_origin, G_MINSHORT, G_MAXSHORT);
	  rects[i].width = CLAMP (boxes[i].x2 + gc->clip_x_origin, G_MINSHORT, G_MAXSHORT) - rects[i].x;
	  rects[i].height = CLAMP (boxes[i].y2 + gc->clip_y_origin, G_MINSHORT, G_MAXSHORT) - rects[i].y;
	}
      
      XRenderSetPictureClipRectangles (xdisplay, picture,
				       0, 0, rects, n_boxes);
      
      g_free (rects);
    }
  else
    {
      XRenderPictureAttributes pa;
      GdkBitmap *mask;
      gulong pa_mask;

      pa_mask = CPClipMask;
      if (gc && (mask = _gdk_gc_get_clip_mask (gc)))
	{
	  pa.clip_mask = GDK_PIXMAP_XID (mask);
	  pa.clip_x_origin = gc->clip_x_origin;
	  pa.clip_y_origin = gc->clip_y_origin;
	  pa_mask |= CPClipXOrigin | CPClipYOrigin;
	}
      else
	pa.clip_mask = None;

      XRenderChangePicture (xdisplay, picture,
			    pa_mask, &pa);
    }
}
コード例 #5
0
ファイル: WorkraveApplet.c プロジェクト: jonolumb/workrave
static void
change_background(PanelApplet * widget,
                  PanelAppletBackgroundType type,
                  GdkColor * color,
                  GdkPixmap * pixmap,
                  void *data)
{
  static GdkPixmap *keep = NULL;
  long xid = 0;
  GValueArray *val = g_value_array_new(4);

  if (type == PANEL_NO_BACKGROUND)
    {
      GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(widget));

      if (style->bg_pixmap[GTK_STATE_NORMAL])
        {
          pixmap = style->bg_pixmap[GTK_STATE_NORMAL];
          type = PANEL_PIXMAP_BACKGROUND;
        }
      else
        {
          color = &style->bg[GTK_STATE_NORMAL];
          if (color != NULL)
            {
              type = PANEL_COLOR_BACKGROUND;
            }
        }
    }
  
  if (type == PANEL_COLOR_BACKGROUND && color != NULL)
    {
      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 0), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 0), color->pixel);
 
      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 1), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 1), color->red);
      
      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 2), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 2), color->green);

      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 3), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 3), color->blue);
    }
  else
    {
      int i;
      for (i = 0; i < 4; i++)
        {
          g_value_array_prepend(val, NULL);
          g_value_init(g_value_array_get_nth(val, 0), G_TYPE_UINT);
          g_value_set_uint(g_value_array_get_nth(val, 0), 0);
        }
    }
  
  if (type == PANEL_PIXMAP_BACKGROUND)
    {
      if (keep != NULL)
        {
          gdk_pixmap_unref(keep);
          keep = pixmap;
        }
      if (pixmap != NULL)
        {
          gdk_pixmap_ref(pixmap);
        }

      xid = GDK_PIXMAP_XID(pixmap);
    }

  if (g_applet->support != NULL && workrave_is_running())
    {
      dbus_g_proxy_begin_call(g_applet->support, "SetBackground", dbus_callback, NULL, NULL,
                              G_TYPE_UINT, type,
                              G_TYPE_VALUE_ARRAY, val,
                              G_TYPE_UINT, xid,
                              G_TYPE_INVALID);
      

    }

  g_value_array_free(val);
}
コード例 #6
0
gboolean
update_window_decoration_size (WnckWindow *win)
{
    decor_t           *d;
    GdkPixmap         *pixmap, *buffer_pixmap = NULL;
    Picture           picture;
    Display           *xdisplay;
    XRenderPictFormat *format;

    if (win == NULL)
	return FALSE;

    d = g_object_get_data (G_OBJECT (win), "decor");

    if (!d->decorated)
	return FALSE;

    xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());

    gdk_error_trap_push ();

    /* Get the correct depth for the frame window in reparenting mode, otherwise
     * enforce 32 */
    if (d->frame_window)
	pixmap = create_native_pixmap_and_wrap (d->width, d->height, d->frame->style_window_rgb);
    else
	pixmap = create_native_pixmap_and_wrap (d->width, d->height, d->frame->style_window_rgba);

    gdk_flush ();

    /* Handle failure */
    if (!pixmap || gdk_error_trap_pop ())
    {
	memset (pixmap, 0, sizeof (*pixmap));
	return FALSE;
    }

    gdk_error_trap_push ();

    if (d->frame_window)
	buffer_pixmap = create_pixmap (d->width, d->height, d->frame->style_window_rgb);
    else
	buffer_pixmap = create_pixmap (d->width, d->height, d->frame->style_window_rgba);

    gdk_flush ();

    /* Handle failure */
    if (!buffer_pixmap || gdk_error_trap_pop ())
    {
	memset (buffer_pixmap, 0, sizeof (*buffer_pixmap));
	g_object_unref (G_OBJECT (pixmap));
	return FALSE;
    }

    /* Create XRender context */
    format = get_format_for_drawable (d, GDK_DRAWABLE (buffer_pixmap));
    picture = XRenderCreatePicture (xdisplay, GDK_PIXMAP_XID (buffer_pixmap),
				    format, 0, NULL);

    /* Destroy the old pixmaps and pictures */
    if (d->pixmap)
	g_object_unref (d->pixmap);

    if (d->x11Pixmap)
	decor_post_delete_pixmap (xdisplay,
				  wnck_window_get_xid (d->win),
				  d->x11Pixmap);

    if (d->buffer_pixmap)
	g_object_unref (G_OBJECT (d->buffer_pixmap));

    if (d->picture)
	XRenderFreePicture (xdisplay, d->picture);

    if (d->cr)
	cairo_destroy (d->cr);

    /* Assign new pixmaps and pictures */
    d->pixmap	     = pixmap;
    d->x11Pixmap     = GDK_PIXMAP_XID (d->pixmap);
    d->buffer_pixmap = buffer_pixmap;
    d->cr	     = gdk_cairo_create (pixmap);

    d->picture = picture;

    d->prop_xid = wnck_window_get_xid (win);

    update_window_decoration_name (win);

    /* Redraw decoration on idle */
    queue_decor_draw (d);

    return TRUE;
}
コード例 #7
0
/*
 * update_default_decorations
 *
 * Description: update the default decorations
 */
void
update_default_decorations (GdkScreen *screen)
{
    long	    *data;
    Window	    xroot;
    GdkDisplay	    *gdkdisplay = gdk_display_get_default ();
    Display	    *xdisplay = gdk_x11_display_get_xdisplay (gdkdisplay);
    Atom	    bareAtom, activeAtom;
    decor_frame_t   *frame;
    decor_frame_t   *bare_frame = gwd_get_decor_frame ("bare");
    decor_extents_t extents;
    unsigned int    i;

    xroot = RootWindowOfScreen (gdk_x11_screen_get_xscreen (screen));

    bareAtom   = XInternAtom (xdisplay, DECOR_BARE_ATOM_NAME, FALSE);
    activeAtom = XInternAtom (xdisplay, DECOR_ACTIVE_ATOM_NAME, FALSE);

    if (bare_frame->border_shadow_active)
    {
	decor_layout_t layout;
	unsigned int   frame_type = 0;
	unsigned int   frame_state = 0;
	unsigned int   frame_actions = 0;
	unsigned int   nQuad;
	decor_quad_t   quads[N_QUADS_MAX];

	long *data = decor_alloc_property (1, WINDOW_DECORATION_TYPE_PIXMAP);

	decor_get_default_layout (&bare_frame->window_context_active, 1, 1, &layout);

	nQuad = decor_set_lSrStSbS_window_quads (quads, &bare_frame->window_context_active,
						 &layout);

	decor_quads_to_property (data, 0, bare_frame->border_shadow_active->pixmap,
				 &bare_frame->win_extents, &bare_frame->win_extents,
				 &bare_frame->win_extents, &bare_frame->win_extents,
				 0, 0, quads, nQuad, frame_type, frame_state, frame_actions);

	XChangeProperty (xdisplay, xroot,
			 bareAtom,
			 XA_INTEGER,
			 32, PropModeReplace, (guchar *) data,
			 PROP_HEADER_SIZE + BASE_PROP_SIZE + QUAD_PROP_SIZE * N_QUADS_MAX);

	if (minimal)
	{
	    XChangeProperty (xdisplay, xroot,
			     activeAtom,
			     XA_INTEGER,
			     32, PropModeReplace, (guchar *) data,
			     PROP_HEADER_SIZE + BASE_PROP_SIZE + QUAD_PROP_SIZE * N_QUADS_MAX);
	}

        free (data);
    }
    else
    {
	XDeleteProperty (xdisplay, xroot, bareAtom);

	if (minimal)
	{
	    XDeleteProperty (xdisplay, xroot, activeAtom);
	}
    }

    if (minimal)
    {
	gwd_decor_frame_unref (bare_frame);
	return;
    }

    XDeleteProperty (xdisplay, xroot,
                     activeAtom);

    data = decor_alloc_property (WINDOW_TYPE_FRAMES_NUM * 2, WINDOW_DECORATION_TYPE_PIXMAP);

    /* All active states and all inactive states */
    for (i = 0; i < WINDOW_TYPE_FRAMES_NUM * 2; ++i)
    {
        frame = gwd_get_decor_frame (default_frames[i].name);
        extents = frame->win_extents;

        if (default_frames[i].d)
        {
            if (default_frames[i].d->pixmap)
                g_object_unref (G_OBJECT (default_frames[i].d->pixmap));

            free (default_frames[i].d);
        }

        default_frames[i].d = calloc (1, sizeof (decor_t));

        default_frames[i].d->context = i < WINDOW_TYPE_FRAMES_NUM ? &frame->window_context_active : &frame->window_context_inactive;
        default_frames[i].d->shadow  =  i < WINDOW_TYPE_FRAMES_NUM ? frame->border_shadow_active : frame->border_shadow_inactive;
        default_frames[i].d->layout  = pango_layout_new (frame->pango_context);

        decor_get_default_layout (default_frames[i].d->context, 1, 1, &default_frames[i].d->border_layout);

        default_frames[i].d->width  = default_frames[i].d->border_layout.width;
        default_frames[i].d->height = default_frames[i].d->border_layout.height;

        default_frames[i].d->frame = frame;
        default_frames[i].d->active = i < WINDOW_TYPE_FRAMES_NUM ? TRUE : FALSE;

        extents.top += frame->titlebar_height;

        default_frames[i].d->draw = theme_draw_window_decoration;
	default_frames[i].d->pixmap = create_native_pixmap_and_wrap (default_frames[i].d->width,
								     default_frames[i].d->height,
								     frame->style_window_rgba);

	unsigned int j, k;

	for (j = 0; j < 3; ++j)
	{
	    for (k = 0; k < 3; k++)
	    {
		default_frames[i].d->event_windows[j][k].window = None;
	    }
	}

	for (j = 0; j < BUTTON_NUM; ++j)
	{
	    default_frames[i].d->button_windows[j].window = None;
	    default_frames[i].d->button_states[j] = 0;
	}

        if (default_frames[i].d->pixmap)
        {
            gint	    nQuad;
            unsigned int   frame_type = populate_frame_type (default_frames[i].d);
            unsigned int   frame_state = populate_frame_state (default_frames[i].d);
            unsigned int   frame_actions = populate_frame_actions (default_frames[i].d);
            decor_quad_t    quads[N_QUADS_MAX];

            nQuad = decor_set_lSrStSbS_window_quads (quads, default_frames[i].d->context,
                                                     &default_frames[i].d->border_layout);

            default_frames[i].d->picture = XRenderCreatePicture (xdisplay,
                                                                          GDK_PIXMAP_XID (default_frames[i].d->pixmap),
                                                                          xformat_rgba, 0, NULL);

            (*default_frames[i].d->draw) (default_frames[i].d);

            decor_quads_to_property (data, i, GDK_PIXMAP_XID (default_frames[i].d->pixmap),
                                     &extents, &extents,
                                     &extents, &extents, 0, 0, quads, nQuad, frame_type, frame_state, frame_actions);
        }

        gwd_decor_frame_unref (frame);
    }

    XChangeProperty (xdisplay, xroot,
                     activeAtom,
                     XA_INTEGER,
                     32, PropModeAppend, (guchar *) data,
                     PROP_HEADER_SIZE + (WINDOW_TYPE_FRAMES_NUM * 2) * (BASE_PROP_SIZE + QUAD_PROP_SIZE * N_QUADS_MAX));

    free (data);

    gwd_decor_frame_unref (bare_frame);
}