VisualID
classpath_jawt_get_visualID (JNIEnv* env, jobject canvas)
{
  GtkWidget *widget;
  Visual *visual;
  void *ptr;
  jobject peer;
  jclass class_id;
  jmethodID method_id;

  class_id = (*env)->GetObjectClass (env, canvas);

  method_id = (*env)->GetMethodID (env, class_id,
				   "getPeer",
				   "()Ljava/awt/peer/ComponentPeer;");

  peer = (*env)->CallObjectMethod (env, canvas, method_id);

  ptr = NSA_GET_PTR (env, peer);

  gdk_threads_enter ();

  widget = GTK_WIDGET (ptr);

  g_assert (GTK_WIDGET_REALIZED (widget));

  visual = gdk_x11_visual_get_xvisual (gtk_widget_get_visual (widget));
  g_assert (visual != NULL);

  gdk_threads_leave ();

  return visual->visualid;
}
Пример #2
0
void background_info_set_background_by_drawable(BackgroundInfo* info,
        guint32 drawable)
{
    gint x, y;
    guint border,depth, width=0, height=0;
    Display* dpy = gdk_x11_get_default_xdisplay();
    gdk_error_trap_push();
    //TODO:
    //we shoul use xatom_name window to set events instead of root window
    //because the monitors changed signal will came before root window rect changed
    //so the Xroot window rect maybe keep old rect in update_bg function and in Display DBus signal "PrimaryChanged"
    Window root;
    XGetGeometry(dpy, drawable, &root, &x, &y, &width, &height, &border,
                 &depth);
    g_debug("[%s] width: %d, height: %d, x: %d y: %d\n", __func__,
            width, height, x, y);
    if (gdk_error_trap_pop()) {
        g_warning("[%s] invalid drawable %d \n", __func__, drawable);
        return;
    }

    g_mutex_lock(&info->m);
    if (info->bg != NULL) {
        cairo_surface_destroy(info->bg);
        info->bg = NULL;
    }
    info->bg = cairo_xlib_surface_create(dpy, drawable,
                                         gdk_x11_visual_get_xvisual(gdk_visual_get_system()), width, height);
    g_mutex_unlock(&info->m);

    if (gtk_widget_get_realized(info->container)) {
        gdk_window_invalidate_rect(gtk_widget_get_window(info->container),
                                   NULL, TRUE);
    }
}
static void
init_graphics2d_as_renderable (struct graphics2d *gr)
{
  Drawable draw;
  Display * dpy;
  Visual * vis;
  
  g_assert (gr != NULL);
  g_assert (gr->drawable != NULL);

  gr->drawbuf = NULL;
  
  if (gr->debug) printf ("initializing graphics2d as renderable\n");
  draw = gdk_x11_drawable_get_xid (gr->drawable);
  
  dpy = gdk_x11_drawable_get_xdisplay (gr->drawable);
  g_assert (dpy != NULL);
  
  vis = gdk_x11_visual_get_xvisual (gdk_drawable_get_visual (gr->drawable));
  g_assert (vis != NULL);
  
  gr->surface = cairo_xlib_surface_create (dpy, draw, vis, 
					   CAIRO_FORMAT_ARGB32,
					   DefaultColormap (dpy, DefaultScreen (dpy)));
  g_assert (gr->surface != NULL);
  g_assert (gr->cr != NULL);
  cairo_set_target_surface (gr->cr, gr->surface);
}
Пример #4
0
static void setup_imlib_for_drawable(GdkDrawable * d)
{
  imlib_context_set_dither(1); /* dither for depths < 24bpp */
  imlib_context_set_display(
    gdk_x11_drawable_get_xdisplay(d));
  imlib_context_set_visual(
    gdk_x11_visual_get_xvisual(gdk_drawable_get_visual(d)));
  imlib_context_set_colormap(
    gdk_x11_colormap_get_xcolormap(gdk_drawable_get_colormap(d)));
  imlib_context_set_drawable(
    gdk_x11_drawable_get_xid(d));
}
Пример #5
0
void
gfxGdkNativeRenderer::Draw(gfxContext* ctx, nsIntSize size,
                           PRUint32 flags, GdkColormap* colormap)
{
    mColormap = colormap;

    Visual* visual =
        gdk_x11_visual_get_xvisual(gdk_colormap_get_visual(colormap));
    Screen* screen =
        gdk_x11_screen_get_xscreen(gdk_colormap_get_screen(colormap));

    gfxXlibNativeRenderer::Draw(ctx, size, flags, screen, visual, nsnull);
}
Пример #6
0
static void
draw_image_warp(struct graphics_priv *gr, struct graphics_gc_priv *fg, struct point *p, int count, char *data)
{
#if 0
	void *image;
	int w,h;
	printf("draw_image_warp data=%s\n", data);
	image = imlib_load_image(data);
	imlib_context_set_display(gdk_x11_drawable_get_xdisplay(gr->widget->window));
	imlib_context_set_colormap(gdk_x11_colormap_get_xcolormap(gtk_widget_get_colormap(gr->widget)));
	imlib_context_set_visual(gdk_x11_visual_get_xvisual(gtk_widget_get_visual(gr->widget)));
	imlib_context_set_drawable(gdk_x11_drawable_get_xid(gr->drawable));
	imlib_context_set_image(image);
	w = imlib_image_get_width();
	h = imlib_image_get_height();
	if (count == 3) {
		imlib_render_image_on_drawable_skewed(0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, p[1].y-p[0].y, p[2].x-p[0].x, p[2].y-p[0].y);
	}
	if (count == 2) {
		imlib_render_image_on_drawable_skewed(0, 0, w, h, p[0].x, p[0].y, p[1].x-p[0].x, 0, 0, p[1].y-p[0].y);
	}
#endif
}
Пример #7
0
static cairo_t *_mt_cairo_begin(MT_TOOLKIT *mt, MT_WINDOW *win, MT_RECTANGLE *area, int x, int y, int width, int height)
{
   GdkWindow *window = (GdkWindow *)win;
   GdkDrawable *drawable;
   cairo_t *cr;
   gint xoff, yoff;
   gint w, h;

   /* revert to rendering to GdkPixbuf (needed for Gecko based applications): */
   if (!window || !GDK_IS_WINDOW(window)) {
      return _mt_cairo_begin_pixbuf(mt, win, area, x, y, width, height);
   }

   gdk_window_get_internal_paint_info(window, &drawable, &xoff, &yoff);

   if (!drawable) {
      return _mt_cairo_begin_pixbuf(mt, win, area, x, y, width, height);
   }

   gdk_drawable_get_size(drawable, &w, &h);
   _cairo_surface = cairo_xlib_surface_create(gdk_x11_drawable_get_xdisplay(drawable),
                                              gdk_x11_drawable_get_xid(drawable),
                                              gdk_x11_visual_get_xvisual(gdk_drawable_get_visual(drawable)),
                                              w, h);
   cr = cairo_create(_cairo_surface);
   
   cairo_translate(cr, -xoff + x, -yoff + y);

   if (area) {
      cairo_rectangle(cr, area->x - x, area->y - y, area->width, area->height);
      cairo_clip(cr);
      cairo_rectangle(cr, 0, 0, width, height);
      cairo_clip(cr);
   }

   return cr;
}
Пример #8
0
/* XXX: Make this more general */
static GdkPixbuf* preview_menu(RrTheme *theme)
{
    RrAppearance *title;
    RrAppearance *title_text;

    RrAppearance *menu;
    RrAppearance *background;

    RrAppearance *normal;
    RrAppearance *disabled;
    RrAppearance *selected;
    RrAppearance *bullet; /* for submenu */

    cairo_surface_t *surface;
    GdkScreen *screen;
    Display *xdisplay;
    Visual *xvisual;
    GdkPixbuf *pixbuf, *tmp_pixbuf;

    /* width and height of the whole menu */
    gint width, height;
    gint x, y;
    gint title_h;
    gint tw, th;
    gint bw, bh;
    gint unused;

    screen = gdk_screen_get_default();
    xdisplay = gdk_x11_get_default_xdisplay();
    xvisual = gdk_x11_visual_get_xvisual(gdk_screen_get_system_visual(screen));

    /* set up appearances */
    title = theme->a_menu_title;

    title_text = theme->a_menu_text_title;
    title_text->surface.parent = title;
    title_text->texture[0].data.text.string = "Menu";

    normal = theme->a_menu_text_normal;
    normal->texture[0].data.text.string = "Normal";

    disabled = theme->a_menu_text_disabled;
    disabled->texture[0].data.text.string = "Disabled";

    selected = theme->a_menu_text_selected;
    selected->texture[0].data.text.string = "Selected";

    bullet = theme->a_menu_bullet_normal;

    /* determine window size */
    RrMinSize(normal, &width, &th);
    width += th + PADDING; /* make space for the bullet */

    width += 2*theme->mbwidth + 2*PADDING;

    /* get minimum title size */
    RrMinSize(title, &tw, &title_h);

    /* size of background behind each text line */
    bw = width - 2*theme->mbwidth;
    //title_h += 2*PADDING;
    title_h = theme->menu_title_height;

    RrMinSize(normal, &unused, &th);
    bh = th + 2*PADDING;

    height = title_h + 3*bh + 3*theme->mbwidth;

    /* set border */
    pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height);
    gdk_pixbuf_fill(pixbuf, rr_color_pixel(theme->menu_border_color));
    tmp_pixbuf = gdk_pixbuf_copy(pixbuf);

    /* menu appears after inside the border */
    x = y = theme->mbwidth;

    /* fill in menu appearance, used as the parent to every menu item's bg */
    menu = theme->a_menu;
    th = height - 2 * theme->mbwidth;
    theme_pixmap_paint(menu, bw, th);

    /* draw title, it appears at the top of the menu background */
    title->surface.parent = theme->a_menu;
    title->surface.parentx = 0;
    title->surface.parenty = 0;
    theme_pixmap_paint(title, bw, title_h);

    /* draw title text */
    title_text->surface.parentx = 0;
    title_text->surface.parenty = 0;

    theme_pixmap_paint(title_text, bw, title_h);

    surface = cairo_xlib_surface_create(xdisplay, title_text->pixmap,
                                        xvisual,
                                        bw, title_h);
    tmp_pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, bw, title_h);
    cairo_surface_destroy(surface);
    gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, bw, title_h, pixbuf, x, y);

    y += title_h + theme->mbwidth;

    /* fill in background appearance, used as the parent to text items */
    background = theme->a_menu_normal;
    background->surface.parent = menu;
    background->surface.parentx = x - theme->mbwidth;
    background->surface.parenty = y - theme->mbwidth;

    /* draw background for normal entry */
    theme_pixmap_paint(background, bw, bh);
    surface = cairo_xlib_surface_create(xdisplay, background->pixmap,
                                        xvisual,
                                        bw, bh);
    tmp_pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, bw, bh);
    cairo_surface_destroy(surface);
    gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, bw, bh, pixbuf, x, y);

    /* draw normal entry */
    normal->surface.parent = background;
    normal->surface.parentx = PADDING;
    normal->surface.parenty = PADDING;
    RrMinSize(normal, &tw, &th);
    theme_pixmap_paint(normal, tw, th);
    surface = cairo_xlib_surface_create(xdisplay, normal->pixmap,
                                        xvisual,
                                        tw, th);
    tmp_pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, tw, th);
    cairo_surface_destroy(surface);
    gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, tw, th, pixbuf,
                         x + PADDING, y + PADDING);

    /* draw bullet */
    RrMinSize(normal, &tw, &th);
    bullet->surface.parent = background;
    bullet->surface.parentx = bw - th;
    bullet->surface.parenty = PADDING;
    theme_pixmap_paint(bullet, th, th);
    surface = cairo_xlib_surface_create(xdisplay, bullet->pixmap,
                                        xvisual,
                                        th, th);
    tmp_pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, th, th);
    cairo_surface_destroy(surface);
    gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, th, th, pixbuf,
                         width - theme->mbwidth - th, y + PADDING);

    y += th + 2*PADDING;

    /* draw background for disabled entry */
    background->surface.parent = menu;
    background->surface.parentx = x - theme->mbwidth;
    background->surface.parenty = y - theme->mbwidth;
    theme_pixmap_paint(background, bw, bh);
    surface = cairo_xlib_surface_create(xdisplay, background->pixmap,
                                        xvisual,
                                        bw, bh);
    tmp_pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, bw, bh);
    cairo_surface_destroy(surface);
    gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, bw, bh, pixbuf, x, y);

    /* draw disabled entry */
    RrMinSize(disabled, &tw, &th);
    disabled->surface.parent = background;
    disabled->surface.parentx = PADDING;
    disabled->surface.parenty = PADDING;
    theme_pixmap_paint(disabled, tw, th);
    surface = cairo_xlib_surface_create(xdisplay, disabled->pixmap,
                                        xvisual,
                                        tw, th);
    tmp_pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, tw, th);
    cairo_surface_destroy(surface);
    gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, tw, th, pixbuf,
                         x + PADDING, y + PADDING);

    y += th + 2*PADDING;

    /* draw background for selected entry */
    background = theme->a_menu_selected;
    background->surface.parent = menu;
    background->surface.parentx = x - theme->mbwidth;
    background->surface.parenty = y - theme->mbwidth;

    theme_pixmap_paint(background, bw, bh);
    surface = cairo_xlib_surface_create(xdisplay, background->pixmap,
                                        xvisual,
                                        bw, bh);
    tmp_pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, bw, bh);
    cairo_surface_destroy(surface);
    gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, bw, bh, pixbuf, x, y);

    /* draw selected entry */
    RrMinSize(selected, &tw, &th);
    selected->surface.parent = background;
    selected->surface.parentx = PADDING;
    selected->surface.parenty = PADDING;
    theme_pixmap_paint(selected, tw, th);
    surface = cairo_xlib_surface_create(xdisplay, selected->pixmap,
                                        xvisual,
                                        tw, th);
    tmp_pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, tw, th);
    cairo_surface_destroy(surface);
    gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, tw, th, pixbuf,
                         x + PADDING, y + PADDING);
    g_object_unref(tmp_pixbuf);

    return pixbuf;
}
Пример #9
0
static GdkPixbuf* preview_window(RrTheme *theme, const gchar *titlelayout,
                                 gboolean focus, gint width, gint height)
{
    RrAppearance *title;
    RrAppearance *handle;
    RrAppearance *a;

    cairo_surface_t *surface;
    GdkScreen *screen;
    Display *xdisplay;
    Visual *xvisual;
    GdkPixbuf *pixbuf = NULL, *tmp_pixbuf = NULL;
    GdkPixbuf *scratch;

    gint w, label_w, h, x, y;

    const gchar *layout;

    screen = gdk_screen_get_default();
    xdisplay = gdk_x11_get_default_xdisplay();
    xvisual = gdk_x11_visual_get_xvisual(gdk_screen_get_system_visual(screen));

    title = focus ? theme->a_focused_title : theme->a_unfocused_title;

    /* set border */
    pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
    gdk_pixbuf_fill(pixbuf,
                    rr_color_pixel(focus ?
                                   theme->frame_focused_border_color :
                                   theme->frame_unfocused_border_color));
    tmp_pixbuf = gdk_pixbuf_copy(pixbuf);

    /* title */
    w = width - 2*theme->fbwidth;
    h = theme->title_height;
    theme_pixmap_paint(title, w, h);

    x = y = theme->fbwidth;
    surface = cairo_xlib_surface_create(xdisplay, title->pixmap,
                                        xvisual,
                                        w, h);
    tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
                                             0, 0, w, h);
    cairo_surface_destroy(surface);
    gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);

    /* calculate label width */
    label_w = width - (theme->paddingx + theme->fbwidth + 1) * 2;

    for (layout = titlelayout; *layout; layout++) {
        switch (*layout) {
        case 'N':
            label_w -= theme->button_size + 2 + theme->paddingx + 1;
            break;
        case 'D':
        case 'S':
        case 'I':
        case 'M':
        case 'C':
            label_w -= theme->button_size + theme->paddingx + 1;
            break;
        default:
            break;
        }
    }

    x = theme->paddingx + theme->fbwidth + 1;
    y += theme->paddingy;
    for (layout = titlelayout; *layout; layout++) {
        /* icon */
        if (*layout == 'N') {
            a = theme->a_icon;
            /* set default icon */
            a->texture[0].type = RR_TEXTURE_RGBA;
            a->texture[0].data.rgba.width = 48;
            a->texture[0].data.rgba.height = 48;
            a->texture[0].data.rgba.alpha = 0xff;
            a->texture[0].data.rgba.data = theme->def_win_icon;

            a->surface.parent = title;
            a->surface.parentx = x - theme->fbwidth;
            a->surface.parenty = theme->paddingy;

            w = h = theme->button_size + 2;

            theme_pixmap_paint(a, w, h);
            surface = cairo_xlib_surface_create(xdisplay, a->pixmap,
                                                xvisual,
                                                w, h);
            tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
                                                     0, 0, w, h);
            cairo_surface_destroy(surface);
            gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);

            x += theme->button_size + 2 + theme->paddingx + 1;
        } else if (*layout == 'L') { /* label */
            a = focus ? theme->a_focused_label : theme->a_unfocused_label;
            a->texture[0].data.text.string = focus ? "Active" : "Inactive";

            a->surface.parent = title;
            a->surface.parentx = x - theme->fbwidth;
            a->surface.parenty = theme->paddingy;
            w = label_w;
            h = theme->label_height;

            theme_pixmap_paint(a, w, h);
            surface = cairo_xlib_surface_create(xdisplay, a->pixmap,
                                                xvisual,
                                                w, h);
            tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
                                                     0, 0, w, h);
            cairo_surface_destroy(surface);
            gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);

            x += w + theme->paddingx + 1;
        } else {
            /* buttons */
            switch (*layout) {
            case 'D':
                a = focus ?
                    theme->btn_desk->a_focused_unpressed :
                    theme->btn_desk->a_unfocused_unpressed;
                break;
            case 'S':
                a = focus ?
                    theme->btn_shade->a_focused_unpressed :
                    theme->btn_shade->a_unfocused_unpressed;
                break;
            case 'I':
                a = focus ?
                    theme->btn_iconify->a_focused_unpressed :
                    theme->btn_iconify->a_unfocused_unpressed;
                break;
            case 'M':
                a = focus ?
                    theme->btn_max->a_focused_unpressed :
                    theme->btn_max->a_unfocused_unpressed;
                break;
            case 'C':
                a = focus ?
                    theme->btn_close->a_focused_unpressed :
                    theme->btn_close->a_unfocused_unpressed;
                break;
            default:
                continue;
            }

            a->surface.parent = title;
            a->surface.parentx = x - theme->fbwidth;
            a->surface.parenty = theme->paddingy + 1;

            w = theme->button_size;
            h = theme->button_size;

            theme_pixmap_paint(a, w, h);
            surface = cairo_xlib_surface_create(xdisplay, a->pixmap,
                                                xvisual,
                                                w, h);
            /* use y + 1 because these buttons should be centered wrt the label
             */
            tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
                                                     0, 0, w, h);
            cairo_surface_destroy(surface);
            gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y + 1);

            x += theme->button_size + theme->paddingx + 1;
        }
    }

    if (theme->handle_height) {
        /* handle */
        handle = focus ? theme->a_focused_handle : theme->a_unfocused_handle;
        x = 2*theme->fbwidth + theme->grip_width;
        y = height - theme->fbwidth - theme->handle_height;
        w = width - 4*theme->fbwidth - 2*theme->grip_width;
        h = theme->handle_height;

        theme_pixmap_paint(handle, w, h);
        surface = cairo_xlib_surface_create(xdisplay, handle->pixmap,
                                            xvisual,
                                            w, h);
        tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
                                                 0, 0, w, h);
        cairo_surface_destroy(surface);
        gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);

        /* openbox handles this drawing stuff differently (it fills the bottom
         * of the window with the handle), so it avoids this bug where
         * parentrelative grips are not fully filled. i'm avoiding it slightly
         * differently. */

        theme_pixmap_paint(handle, width, h);

        /* grips */
        a = focus ? theme->a_focused_grip : theme->a_unfocused_grip;
        a->surface.parent = handle;

        x = theme->fbwidth;
        /* same y and h as handle */
        w = theme->grip_width;

        theme_pixmap_paint(a, w, h);
        surface = cairo_xlib_surface_create(xdisplay, a->pixmap,
                                            xvisual, w, h);
        tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
                                                 0, 0, w, h);
        gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);

        /* right grip */
        x = width - theme->fbwidth - theme->grip_width;
        tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
                                                 0, 0, w, h);
        cairo_surface_destroy(surface);
        gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);
    }

    /* title separator colour */
    x = theme->fbwidth;
    y = theme->fbwidth + theme->title_height;
    w = width - 2*theme->fbwidth;
    h = theme->fbwidth;

    scratch = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
    gdk_pixbuf_fill(scratch, rr_color_pixel(focus ?
                                            theme->title_separator_focused_color :
                                            theme->title_separator_unfocused_color));

    gdk_pixbuf_copy_area(scratch, 0, 0, w, h, pixbuf, x, y);

    /* retarded way of adding client colour */
    x = theme->fbwidth;
    y = theme->title_height + 2*theme->fbwidth;
    w = width - 2*theme->fbwidth;
    h = height - theme->title_height - 3*theme->fbwidth -
        (theme->handle_height ? (theme->fbwidth + theme->handle_height) : 0);

    scratch = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
    gdk_pixbuf_fill(scratch, rr_color_pixel(focus ?
                                            theme->cb_focused_color :
                                            theme->cb_unfocused_color));

    gdk_pixbuf_copy_area(scratch, 0, 0, w, h, pixbuf, x, y);

    /* clear (no alpha!) the area where the client resides */
    gdk_pixbuf_fill(scratch, 0xffffffff);
    gdk_pixbuf_copy_area(scratch, 0, 0,
                         w - 2*theme->cbwidthx,
                         h - 2*theme->cbwidthy,
                         pixbuf,
                         x + theme->cbwidthx,
                         y + theme->cbwidthy);
    g_object_unref(scratch);

    return pixbuf;
}