static void
update_shape (GtkWidget* window,
	      gint       radius,
	      gint       shadow_size)
{
	if (g_composited)
	{		
		/* remove any current shape-mask */
		gtk_widget_input_shape_combine_region (window, NULL);
		return;
	}

	int width;
	int height;
	gtk_widget_get_size_request (window, &width, &height);
	const cairo_rectangle_int_t rects[] = {{2, 0, width - 4, height},
										   {1, 1, width - 2, height - 2},
										   {0, 2, width, height - 4}};
	cairo_region_t* region = NULL;

	region = cairo_region_create_rectangles (rects, 3);
	if (cairo_region_status (region) == CAIRO_STATUS_SUCCESS)
	{
		gtk_widget_shape_combine_region (window, NULL);
		gtk_widget_shape_combine_region (window, region);
	}
}
static void
maybe_update_shape (GtkWidget *widget)
{
	cairo_t *cr;
	cairo_surface_t *surface;
	cairo_region_t *region;

	/* fallback to XShape only for non-composited clients */
	if (gtk_widget_is_composited (widget)) {
		gtk_widget_shape_combine_region (widget, NULL);
		return;
	}

	surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
						     CAIRO_CONTENT_COLOR_ALPHA,
						     gtk_widget_get_allocated_width (widget),
						     gtk_widget_get_allocated_height (widget));

	cr = cairo_create (surface);
	label_draw_background_and_frame (widget, cr, TRUE);
	cairo_destroy (cr);

	region = gdk_cairo_region_create_from_surface (surface);
	gtk_widget_shape_combine_region (widget, region);

	cairo_surface_destroy (surface);
	cairo_region_destroy (region);
}
Пример #3
0
static void
maybe_update_shape (GtkTooltip *tooltip)
{
  cairo_t *cr;
  cairo_surface_t *surface;
  cairo_region_t *region;

  /* fallback to XShape only for non-composited clients */
  if (gtk_widget_is_composited (tooltip->window))
    {
      gtk_widget_shape_combine_region (tooltip->window, NULL);
      return;
    }

  surface = gdk_window_create_similar_surface (gtk_widget_get_window (tooltip->window),
                                               CAIRO_CONTENT_COLOR_ALPHA,
                                               gtk_widget_get_allocated_width (tooltip->window),
                                               gtk_widget_get_allocated_height (tooltip->window));

  cr = cairo_create (surface);
  paint_background_and_frame (tooltip, cr);
  cairo_destroy (cr);

  region = gdk_cairo_region_create_from_surface (surface);
  gtk_widget_shape_combine_region (tooltip->window, region);

  cairo_surface_destroy (surface);
  cairo_region_destroy (region);
}
Пример #4
0
static void
update_shape_region (cairo_surface_t *surface,
		     WindowData      *windata)
{
	if (windata->width == windata->last_width && windata->height == windata->last_height)
	{
		return;
	}

	if (windata->width == 0 || windata->height == 0)
	{
		GtkAllocation allocation;
		gtk_widget_get_allocation (windata->win, &allocation);

		windata->width = MAX (allocation.width, 1);
		windata->height = MAX (allocation.height, 1);
	}

	if (!windata->composited) {
		cairo_region_t *region;

		region = gdk_cairo_region_create_from_surface (surface);
		gtk_widget_shape_combine_region (windata->win, region);
		cairo_region_destroy (region);
	} else {
		gtk_widget_shape_combine_region (windata->win, NULL);
		return;
	}

	windata->last_width = windata->width;
	windata->last_height = windata->height;
}
Пример #5
0
static gboolean on_draw(GtkWidget *widget, gpointer data)
{
    cairo_t *cr;
    GtkAllocation alloc;
    gtk_widget_get_allocation(widget, &alloc);
    gint width = alloc.width;
    gint height = alloc.height;
    gint r = 5;

    cr = gdk_cairo_create(gtk_widget_get_window(widget));
    cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
                                                          width,
                                                          height);
    cairo_t *cr2 = cairo_create(surface);
    draw_round_rectangle(cr2, 0, 0, width, height, r);
    cairo_stroke_preserve(cr2);
    cairo_fill(cr2) ;
    cairo_destroy(cr2);

    cairo_region_t *region = gdk_cairo_region_create_from_surface(surface);
    gtk_widget_shape_combine_region(widget, region);

    cairo_set_line_width(cr, 0.3);
    cairo_set_source_rgb(cr, 0.78, 0.78, 0.78);
    draw_round_rectangle(cr, 0, 0, width, height, r);
    cairo_stroke(cr);

    cairo_region_destroy(region);
    cairo_surface_destroy(surface);
    cairo_destroy(cr);
}
Пример #6
0
void on_composited_changed ( GdkScreen *screen,
			   gpointer   user_data)
{
  GromitData *data = (GromitData *) user_data;

  if(data->debug)
    g_printerr("DEBUG: got composited-changed event\n");

  data->composited = gdk_screen_is_composited (data->screen);

  if(data->composited)
    {
      // undo shape
      gtk_widget_shape_combine_region(data->win, NULL);
      // re-apply transparency
      gtk_window_set_opacity(GTK_WINDOW(data->win), 0.75);
    }

  // set anti-aliasing
  GHashTableIter it;
  gpointer value;
  g_hash_table_iter_init (&it, data->tool_config);
  while (g_hash_table_iter_next (&it, NULL, &value)) 
    {
      GromitPaintContext *context = value;
      cairo_set_antialias(context->paint_ctx, data->composited ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
    }
      

  GdkRectangle rect = {0, 0, data->width, data->height};
  gdk_window_invalidate_rect(gtk_widget_get_window(data->win), &rect, 0); 
}
Пример #7
0
static void
gtk_bubble_window_update_shape (GtkBubbleWindow *window)
{
  cairo_surface_t *surface;
  cairo_region_t *region;
  GdkWindow *win;
  cairo_t *cr;

  win = gtk_widget_get_window (GTK_WIDGET (window));
  surface =
    gdk_window_create_similar_surface (win,
                                       CAIRO_CONTENT_COLOR_ALPHA,
                                       gdk_window_get_width (win),
                                       gdk_window_get_height (win));

  cr = cairo_create (surface);
  gtk_bubble_window_apply_border_path (window, cr);
  cairo_fill (cr);
  cairo_destroy (cr);

  region = gdk_cairo_region_create_from_surface (surface);
  cairo_surface_destroy (surface);

  if (!gtk_widget_is_composited (GTK_WIDGET (window)))
    gtk_widget_shape_combine_region (GTK_WIDGET (window), region);

  gtk_widget_input_shape_combine_region (GTK_WIDGET (window), region);
  cairo_region_destroy (region);
}
Пример #8
0
static void
dnd_hints_realized_cb(GtkWidget *window, GtkWidget *pix)
{
	GdkPixbuf *pixbuf;
	cairo_surface_t *surface;
	cairo_region_t *region;
	cairo_t *cr;

	pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(pix));

	surface = cairo_image_surface_create(CAIRO_FORMAT_A1,
	                                     gdk_pixbuf_get_width(pixbuf),
	                                     gdk_pixbuf_get_height(pixbuf));

	cr = cairo_create(surface);
	gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
	cairo_paint(cr);
	cairo_destroy(cr);

	region = gdk_cairo_region_create_from_surface(surface);
	gtk_widget_shape_combine_region(window, region);
	cairo_region_destroy(region);

	cairo_surface_destroy(surface);
}
Пример #9
0
void on_monitors_changed ( GdkScreen *screen,
			   gpointer   user_data) 
{
  GromitData *data = (GromitData *) user_data;

  if(data->debug)
    g_printerr("DEBUG: screen size changed!\n");

  // get new sizes
  data->width = gdk_screen_get_width (data->screen);
  data->height = gdk_screen_get_height (data->screen);

  // change size
  gtk_widget_set_size_request(GTK_WIDGET(data->win), data->width, data->height);
  // try to set transparent for input
  cairo_region_t* r =  cairo_region_create();
  gtk_widget_input_shape_combine_region(data->win, r);
  cairo_region_destroy(r);

  /* recreate the shape surface */
  cairo_surface_t *new_shape = cairo_image_surface_create(CAIRO_FORMAT_ARGB32 ,data->width, data->height);
  cairo_t *cr = cairo_create (new_shape);
  cairo_set_source_surface (cr, data->backbuffer, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);
  cairo_surface_destroy(data->backbuffer);
  data->backbuffer = new_shape;
 
  /*
     these depend on the shape surface
  */
  GHashTableIter it;
  gpointer value;
  g_hash_table_iter_init (&it, data->tool_config);
  while (g_hash_table_iter_next (&it, NULL, &value)) 
    paint_context_free(value);
  g_hash_table_remove_all(data->tool_config);


  parse_config(data); // also calls paint_context_new() :-(


  data->default_pen = paint_context_new (data, GROMIT_PEN,
					 data->red, 7, 0, 1);
  data->default_eraser = paint_context_new (data, GROMIT_ERASER,
					    data->red, 75, 0, 1);

  if(!data->composited) // set shape
    {
      cairo_region_t* r = gdk_cairo_region_create_from_surface(data->backbuffer);
      gtk_widget_shape_combine_region(data->win, r);
      cairo_region_destroy(r);
    }

  setup_input_devices(data);


  gtk_widget_show_all (data->win);
}
Пример #10
0
static void
hud_update_shape(GtkWidget *widget)
{
    cairo_region_t *shape;
    shape = curved_rect_mask(widget);
    if (shape != NULL)
    {
        gtk_widget_shape_combine_region(widget, shape);
        cairo_region_destroy(shape);
    }
}
Пример #11
0
Файл: frapi.c Проект: 91he/Test
static void plug_mask(struct FRPlugin *plug, struct Rgn *rgn){
    cairo_region_t *crgn = NULL;

    if(plug->rgn != rgn && rgn){
        if(plug->rgn) free(plug->rgn);
        plug->rgn = malloc(sizeof(struct Rgn) + rgn->num * sizeof(cairo_rectangle_int_t));
        memcpy(plug->rgn, rgn, sizeof(struct Rgn) + rgn->num * sizeof(cairo_rectangle_int_t));
    }

    crgn = make_region(rgn);

    gtk_widget_shape_combine_region(plug->view, crgn);
    gtk_widget_show(plug->view);
}
Пример #12
0
gboolean on_draw(GtkWidget *widget, gpointer data)
{
    GtkAllocation alloc;
    gint x, y, width, height, r;
    gtk_widget_get_allocation(widget, &alloc);
    x = alloc.x;
    y = alloc.y;
    width = alloc.width;
    height = alloc.height;
    r = 5;

    cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));

    cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
    cairo_t *cr2 = cairo_create(surface);

    cairo_move_to(cr2, r, 0);
    cairo_line_to(cr2, width-r, 0);

	cairo_move_to(cr2, width, r);
	cairo_line_to(cr2, width, height-r);

	cairo_move_to(cr2, width-r, height);
	cairo_move_to(cr2, r, height);

	cairo_move_to(cr2, 0, height-r);
	cairo_line_to(cr2, 0, r);

	cairo_arc(cr2, r, r, r, G_PI, 3 * G_PI / 2.0 );
	cairo_arc(cr2, width-r, r, r, 3 * G_PI /2.0, 2 * G_PI);
	cairo_arc(cr2, width-r, height-r, r, 0, G_PI / 2);
	cairo_arc(cr2, r, height-r, r, G_PI / 2, G_PI);
    cairo_fill(cr2);

    cairo_set_source_rgba(cr, 0, 0, 0, 0);
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint(cr);
 
    cairo_region_t *region = gdk_cairo_region_create_from_surface(surface);
    gtk_widget_shape_combine_region(widget, region);

    cairo_destroy(cr2);
    cairo_destroy(cr);
    cairo_region_destroy(region);
    cairo_surface_destroy(surface);

    return FALSE;
}
Пример #13
0
static int gtkDialogSetOpacityImageAttrib(Ihandle *ih, const char *value)
{
  GdkPixbuf* pixbuf = iupImageGetImage(value, ih, 0);
  if (pixbuf)
  {
#if GTK_CHECK_VERSION(3, 0, 0)
    GdkWindow* window = iupgtkGetWindow(ih->handle);
    if (window)
    {
      cairo_region_t *shape;

#if GTK_CHECK_VERSION(3, 10, 0)
      cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(pixbuf, 0, window);
#else
      int width = gdk_pixbuf_get_width(pixbuf);
      int height = gdk_pixbuf_get_height(pixbuf);
      cairo_surface_t* surface = gdk_window_create_similar_surface(window, CAIRO_CONTENT_COLOR_ALPHA, width, height);
      cairo_t* cr = cairo_create(surface);
      gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
      cairo_paint(cr);
      cairo_destroy(cr);
#endif

      shape = gdk_cairo_region_create_from_surface(surface);
      cairo_surface_destroy(surface);

      gtk_widget_shape_combine_region(ih->handle, shape);
      cairo_region_destroy(shape);
    }
#else
    GdkBitmap* mask = NULL;
    gdk_pixbuf_render_pixmap_and_mask(pixbuf, NULL, &mask, 255);
    if (mask) 
    {
      gtk_widget_shape_combine_mask(ih->handle, mask, 0, 0);
      g_object_unref(mask);
    }
#endif
    return 1;
  }
  return 0;
}
Пример #14
0
void wxDropSource::PrepareIcon( int action, GdkDragContext *context )
{
    // get the right icon to display
    wxIcon *icon = NULL;
    if ( action & GDK_ACTION_MOVE )
        icon = &m_iconMove;
    else if ( action & GDK_ACTION_COPY )
        icon = &m_iconCopy;
    else
        icon = &m_iconNone;

#ifndef __WXGTK3__
    GdkBitmap *mask;
    if ( icon->GetMask() )
        mask = *icon->GetMask();
    else
        mask = NULL;

    GdkPixmap *pixmap = icon->GetPixmap();

    GdkColormap *colormap = gtk_widget_get_colormap( m_widget );
    gtk_widget_push_colormap (colormap);
#endif

    m_iconWindow = gtk_window_new (GTK_WINDOW_POPUP);
    gtk_widget_set_events (m_iconWindow, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
    gtk_widget_set_app_paintable (m_iconWindow, TRUE);

#ifdef __WXGTK3__
    gtk_widget_set_visual(m_iconWindow, gtk_widget_get_visual(m_widget));
#else
    gtk_widget_pop_colormap ();
#endif

    gtk_widget_set_size_request (m_iconWindow, icon->GetWidth(), icon->GetHeight());
    gtk_widget_realize (m_iconWindow);

    g_signal_connect (m_iconWindow, "configure_event",
                      G_CALLBACK (gtk_dnd_window_configure_callback), this);

#ifdef __WXGTK3__
    cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(m_iconWindow));
    icon->SetSourceSurface(cr, 0, 0);
    cairo_pattern_t* pattern = cairo_get_source(cr);
    gdk_window_set_background_pattern(gtk_widget_get_window(m_iconWindow), pattern);
    cairo_destroy(cr);
    cairo_surface_t* mask = NULL;
    if (icon->GetMask())
        mask = *icon->GetMask();
    if (mask)
    {
        cairo_region_t* region = gdk_cairo_region_create_from_surface(mask);
        gtk_widget_shape_combine_region(m_iconWindow, region);
        cairo_region_destroy(region);
    }
#else
    gdk_window_set_back_pixmap(gtk_widget_get_window(m_iconWindow), pixmap, false);

    if (mask)
        gtk_widget_shape_combine_mask (m_iconWindow, mask, 0, 0);
#endif

    gtk_drag_set_icon_widget( context, m_iconWindow, 0, 0 );
}
Пример #15
0
/* We double buffer the image.  It looks nice and it enables
 * grabbing the graph with the pointer and translating it.
 * We draw on our own larger surface and then copy part of that
 * to the gdk surface.
 *
 * We assume that this function is drawing to an exposed/showing
 * drawing area, so the status update will reflect the current
 * exposed/showing drawing area. */
void qp_graph_draw(struct qp_graph *gr, cairo_t *gdk_cr)
{
  GtkAllocation allocation;

  if(gr->waiting_to_resize_draw && !gr->qp->shape)
  {
    //WARN("gr=%p gr->name=\"%s\" gr->ref_count=%d\n", gr, gr->name, gr->ref_count);
    cairo_set_source_rgba(gdk_cr, gr->background_color.r,
      gr->background_color.g, gr->background_color.b,
      gr->background_color.a);

    cairo_paint(gdk_cr);

    g_idle_add_full(G_PRIORITY_LOW, idle_callback, gr, NULL);
    /* fight qp_graph_destroy() race condition with flag */
    ++gr->ref_count;
    /* We draw after the other widgets are drawn, in case drawing
     * takes a long time.  This waiting also gives a chance
     * for the watch cursor to show.  But that seems to only
     * show if the window had focus at the right time. */
    return;
  }

  gtk_widget_get_allocation(gr->drawing_area, &allocation);
  
  if(gr->pixbuf_needs_draw)
  {
    cairo_t *db_cr; /* double buffer cr */

    db_cr = cairo_create(gr->pixbuf_surface);
    graph_draw(gr, db_cr, gr->pixbuf_x, gr->pixbuf_y,
                  gr->pixbuf_width, gr->pixbuf_height);
    cairo_destroy(db_cr);
    // debuging
    //cairo_surface_write_to_png(gr->pixbuf_surface, "x.png");
    qp_win_set_status(gr->qp);
  }

  /* the GTK cairo_t *gdk_cr has no alpha bits so all the
   * alpha drawn to it will be smushed. */
  //WARN("content=0x%lx\n", (unsigned long)cairo_get_target(gdk_cr));


  if(!gr->qp->shape)
  {
    /* Not using the shape X11 extension */

    /* This is where we go from the back buffer to the drawing area */
    draw_from_pixbuf(gdk_cr, gr, allocation.width, allocation.height);

    if(gr->draw_zoom_box == 1)
      draw_zoom_box(gdk_cr, gr);
    if(gr->draw_value_pick)
      draw_value_pick_line(gdk_cr, gr, allocation.width, allocation.height);


    if(gr->pixbuf_needs_draw)
    {
      gdk_window_set_cursor(gtk_widget_get_window(gr->qp->window), NULL);
      gr->pixbuf_needs_draw = 0;
      // gr->qp->wait_warning_showing = 0;
    }
  }
  else
  {
    /* Use the X11 shape extension */


    /* TODO: This is a resource pig.  Fix it. */

    cairo_region_t *reg_draw_area, *window_region;
    /* empty flag */ 
    int empty;
    cairo_surface_t *mask_surface;
    GtkAllocation all;

    /* Make sure the surface is up to date */
    //cairo_surface_flush(gr->pixbuf_surface);

    /* make a sub surface that is the size of the graph drawing area */
    mask_surface = cairo_surface_create_for_rectangle(gr->pixbuf_surface,
        INT(gr->pixbuf_x+gr->grab_x),
        INT(gr->pixbuf_y+gr->grab_y),
        allocation.width, allocation.height);
    
    reg_draw_area = get_cairo_region_create_from_surface(gr,
        mask_surface, allocation.width, allocation.height);

    cairo_surface_destroy(mask_surface);

    cairo_region_translate(reg_draw_area, allocation.x, allocation.y);

    gtk_widget_get_allocation(gr->qp->window, &all);
    all.x = all.y = 0;

    window_region = cairo_region_create_rectangle(&all);

    cairo_region_subtract_rectangle(window_region, &allocation);

    empty = cairo_region_is_empty(reg_draw_area);

    if(!empty)  
      cairo_region_union(window_region, reg_draw_area);

    cairo_region_destroy(reg_draw_area);

    /* window_region is a region with a hole in it the
     * size of the drawing area with the graph and grid added back. */


    if(gr->draw_zoom_box && !empty)
    {
      cairo_rectangle_int_t rec;
      rec.x = allocation.x + gr->z_x;
      rec.y = allocation.y + gr->z_y;
      rec.width = gr->z_w;
      rec.height = gr->z_h;
      /* regions do not like negitive values or
       * maybe shapes do not like negitive values
       * in any case we keep width and height
       * positive */
      if(rec.width < 0)
      {
        rec.width *= -1;
        rec.x -= rec.width;
      }
      if(rec.height < 0)
      {
        rec.height *= -1;
        rec.y -= rec.height;
      }
        
      cairo_region_union_rectangle(window_region, &rec);
      /* now we have the zoom box added to window_region */
    }


    /* This is where we go from the back buffer to the drawing area */
    draw_from_pixbuf(gdk_cr, gr, allocation.width, allocation.height);
    if(gr->draw_zoom_box)
      draw_zoom_box(gdk_cr, gr);
    if(gr->draw_value_pick)
      draw_value_pick_line(gdk_cr, gr, allocation.width, allocation.height);


    if(empty)
    {
      /* we have nothing to make a shape with */
      if(gr->qp->last_shape_region)
      {
        cairo_region_destroy(gr->qp->last_shape_region);
        gr->qp->last_shape_region = NULL;
      }
      cairo_region_destroy(window_region);
      /* remove the old shape region */
      gtk_widget_shape_combine_region(gr->qp->window, NULL);
    }
    else if(!gr->qp->last_shape_region ||
        !cairo_region_equal(gr->qp->last_shape_region, window_region))
    {
      // DEBUG("creating new shape region\n");
      
      /* We need to undo the old shape first */
      gtk_widget_shape_combine_region(gr->qp->window, NULL);

      gtk_widget_shape_combine_region(gr->qp->window, window_region);

      if(gr->qp->last_shape_region)
        cairo_region_destroy(gr->qp->last_shape_region);

      gr->qp->last_shape_region = window_region;
    }
    else
      cairo_region_destroy(window_region);


    gr->pixbuf_needs_draw = 0;

    gdk_window_set_cursor(gtk_widget_get_window(gr->qp->window), NULL);
    // debuging
    //cairo_surface_write_to_png(cairo_get_target(gdk_cr), "y.png");
  }

  if(gr->qp->update_graph_detail && gr->qp->graph_detail)
  {
    gr->qp->update_graph_detail = 0;
    /* make the graph configure window show stuff about this graph */
    qp_win_graph_detail_init(gr->qp);
  }
}
Пример #16
0
void equalizerwin_set_shape (void)
{
    gint id = config.equalizer_shaded ? SKIN_MASK_EQ_SHADE : SKIN_MASK_EQ;
    gtk_widget_shape_combine_region (equalizerwin, active_skin->masks[id]);
}
Пример #17
0
static void create_win_message(char *icon, char *text, int duration)
{
  GtkWidget *gwin_message = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_has_resize_grip(GTK_WINDOW(gwin_message), FALSE);
  gtk_container_set_border_width (GTK_CONTAINER (gwin_message), 0);
  gtk_widget_realize (gwin_message);
  GdkWindow *gdkwin = gtk_widget_get_window(gwin_message);
  set_no_focus(gwin_message);

  GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (gwin_message), hbox);

  if (icon[0] != '-') {
    GtkWidget *image = gtk_image_new_from_file(icon);
    if (text[0] == '-') {
#if GTK_CHECK_VERSION(2,91,0)
      GdkPixbuf *pixbuf = NULL;
      GdkPixbufAnimation *anime = NULL;
      switch(gtk_image_get_storage_type(GTK_IMAGE(image))) {
        case GTK_IMAGE_PIXBUF:
          pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
          break;
        case GTK_IMAGE_ANIMATION:
          anime = gtk_image_get_animation(GTK_IMAGE(image));
          pixbuf = gdk_pixbuf_animation_get_static_image(anime);
          break;
        default:
          break;
      }
      cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
      cairo_t *cr = cairo_create(img);
      gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
      cairo_paint(cr);
      cairo_region_t *mask = gdk_cairo_region_create_from_surface(img);
      gtk_widget_shape_combine_region(gwin_message, mask);
      cairo_region_destroy(mask);
      cairo_destroy(cr);
      cairo_surface_destroy(img);
#else
      GdkBitmap *bitmap = NULL;
      gdk_pixbuf_render_pixmap_and_mask(gdk_pixbuf_new_from_file(icon, NULL), NULL, &bitmap, 128);
      gtk_widget_shape_combine_mask(gwin_message, bitmap, 0, 0);
#endif
    }
    gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
  }

  if (text[0] != '-') {
    GtkWidget *label = gtk_label_new(text);
    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  }

  gtk_widget_show_all(gwin_message);

  int width, height;
  get_win_size(gwin_message, &width, &height);

  int ox=-1, oy;
  int szx, szy;
  if (tray_da_win) {
    gdk_window_get_origin  (tray_da_win, &ox, &oy);
#if !GTK_CHECK_VERSION(2,91,0)
    gdk_drawable_get_size(tray_da_win, &szx, &szy);
#else
    szx = gdk_window_get_width(tray_da_win);
    szy = gdk_window_get_height(tray_da_win);
#endif

    if (oy<height) {
      oy = szy;
    } else {
      oy -= height;
      if (oy + height > dpy_yl)
        oy = dpy_yl - height;
      if (oy < 0)
        oy = 0;
    }

    if (ox + width > dpy_xl)
      ox = dpy_xl - width;
    if (ox < 0)
      ox = 0;
  } else
  if (icon_main) {
    GdkRectangle rect;
    GtkOrientation ori;
    if (gtk_status_icon_get_geometry(icon_main, NULL, &rect, &ori)) {
      dbg("rect %d,%d\n", rect.x, rect.y, rect.width, rect.height);
      if (ori==GTK_ORIENTATION_HORIZONTAL) {
        ox=rect.x;
        if (rect.y > 100)
          oy=rect.y - height;
        else
          oy=rect.y + rect.height;
      } else {
        oy=rect.y;
        if (rect.x > 100)
          ox=rect.x - width;
        else
          ox=rect.x + rect.width;
      }
    }
  }

  if (ox < 0) {
    ox = dpy_xl - width;
    oy = dpy_yl - height;
  }

  gtk_window_move(GTK_WINDOW(gwin_message), ox, oy);

  g_timeout_add(duration, (GSourceFunc)timeout_destroy_window, gwin_message);
}
Пример #18
0
static void
cw_window_init (CWWindow *cw_window)
{

	CWWindowPrivate *priv   = CW_WINDOW_GET_PRIVATE(cw_window);
	cw_window_screen_changed(GTK_WIDGET(cw_window), NULL, NULL);

	//gtk_window_set_type_hint(GTK_WINDOW(cw_window),
	//GDK_WINDOW_TYPE_HINT_DOCK);

	gtk_window_set_decorated(GTK_WINDOW(cw_window), FALSE);
	//gtk_window_set_resizable(GTK_WINDOW(cw_window), FALSE);
	//gtk_window_set_position(GTK_WINDOW(cw_window), GTK_WIN_POS_CENTER_ALWAYS);
	//gtk_window_set_skip_taskbar_hint(GTK_WINDOW(cw_window), FALSE);
	//gtk_window_set_skip_pager_hint(GTK_WINDOW(cw_window), FALSE);
	//gtk_window_set_default_size(GTK_WINDOW(cw_window), 800, 480);
	cw_window_set_pos_size(GTK_WIDGET(cw_window), priv);
	//gtk_window_maximize(GTK_WINDOW(cw_window));

	gtk_widget_add_events(GTK_WIDGET(cw_window),
			GDK_POINTER_MOTION_MASK
			| GDK_KEY_RELEASE_MASK
			| GDK_BUTTON_PRESS_MASK
			| GDK_BUTTON_RELEASE_MASK);


	priv->picture_window = cw_picture_window_new();
	//priv->picture_alignment = gtk_alignment_new(0.5, 0.5, 1, 1);
	//gtk_alignment_set_padding(
			//GTK_ALIGNMENT(priv->picture_alignment),
			//0, 0, 0, 0);

	//gtk_container_add(
			//GTK_CONTAINER(priv->picture_alignment),
			//priv->picture_window);

	priv->thumbnails_window = cw_thumbnails_window_new();
	priv->thumbnails_alignment = gtk_alignment_new(0.5, 0.5, 1, 1);
	gtk_alignment_set_padding(
			GTK_ALIGNMENT(priv->thumbnails_alignment),
			THUMBNAIL_WINDOW_SIDE_SIZE,
			THUMBNAIL_WINDOW_SIDE_SIZE,
			THUMBNAIL_WINDOW_SIDE_SIZE,
			THUMBNAIL_WINDOW_SIDE_SIZE);

	gtk_container_add(
			GTK_CONTAINER(priv->thumbnails_alignment),
			priv->thumbnails_window);

	priv->main_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
	gtk_box_pack_end(
			GTK_BOX(priv->main_box),
			priv->thumbnails_alignment,
			TRUE,
			TRUE,
			0);

	gtk_box_pack_end(
			GTK_BOX(priv->main_box),
			priv->picture_window,
			TRUE,
			TRUE,
			0);

	gtk_container_add(
		GTK_CONTAINER(cw_window),
		priv->main_box);

	GdkRGBA rgba = { 1, 1, 1, 0.0};
	gtk_widget_override_background_color(GTK_WIDGET(cw_window),
			GTK_STATE_FLAG_NORMAL, &rgba);

	gtk_widget_override_background_color(GTK_WIDGET(priv->main_box),
			GTK_STATE_FLAG_NORMAL, &rgba);

	gtk_widget_show_all(GTK_WIDGET (priv->thumbnails_alignment));
	gtk_widget_show(GTK_WIDGET (priv->main_box));
	gtk_widget_show(GTK_WIDGET (cw_window));

	cw_window_set_child_window(GTK_WIDGET(cw_window), priv);

	gtk_widget_shape_combine_region(GTK_WIDGET(cw_window), NULL);

	g_signal_connect(
			priv->picture_window,
			"picture-switch",
			G_CALLBACK(cw_thumbnails_window_on_picture_switch),
			priv->thumbnails_window);

	g_signal_connect(
			priv->thumbnails_window,
			"active_large_image",
			G_CALLBACK(cw_window_active_large_image),
			cw_window);

	/* TODO: Add initialization code here */
}