Example #1
0
File: imlib2.c Project: rdebath/sgt
void image_to_pixmap(image *img, GdkPixmap *pm, int w, int h)
{
    int realw, realh;
    int need_free;

    imlib_context_set_image(img->image);
    realw = imlib_image_get_width();
    realh = imlib_image_get_height();
    if (w != realw || h != realh) {
	Imlib_Image newimg;

	newimg = imlib_create_cropped_scaled_image(0, 0, realw, realh, w, h);
	imlib_context_set_image(newimg);
	need_free = TRUE;
    } else
	need_free = FALSE;

    imlib_context_set_display(GDK_WINDOW_XDISPLAY(pm));
    imlib_context_set_visual(GDK_VISUAL_XVISUAL(gdk_visual_get_system()));
    imlib_context_set_colormap
	(GDK_COLORMAP_XCOLORMAP(gdk_colormap_get_system()));
    imlib_context_set_drawable(GDK_WINDOW_XWINDOW(pm));
    imlib_context_set_blend(1);
    imlib_render_image_on_drawable(0, 0);

    if (need_free)
	imlib_free_image();
}
nsresult nsPluginNativeWindowGtk2::CreateXEmbedWindow() {
  NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");

  GdkWindow *parent_win = gdk_window_lookup((XID)window);
  mSocketWidget = gtk_socket_new();

  //attach the socket to the container widget
  gtk_widget_set_parent_window(mSocketWidget, parent_win);

  // Make sure to handle the plug_removed signal.  If we don't the
  // socket will automatically be destroyed when the plug is
  // removed, which means we're destroying it more than once.
  // SYNTAX ERROR.
  g_signal_connect(mSocketWidget, "plug_removed",
                   G_CALLBACK(plug_removed_cb), NULL);

  g_signal_connect(mSocketWidget, "unrealize",
                   G_CALLBACK(socket_unrealize_cb), NULL);

  g_signal_connect(mSocketWidget, "destroy",
                   G_CALLBACK(gtk_widget_destroyed), &mSocketWidget);

  gpointer user_data = NULL;
  gdk_window_get_user_data(parent_win, &user_data);

  GtkContainer *container = GTK_CONTAINER(user_data);
  gtk_container_add(container, mSocketWidget);
  gtk_widget_realize(mSocketWidget);

  // The GtkSocket has a visible window, but the plugin's XEmbed plug will
  // cover this window.  Normally GtkSockets let the X server paint their
  // background and this would happen immediately (before the plug is
  // created).  Setting the background to None prevents the server from
  // painting this window, avoiding flicker.
  gdk_window_set_back_pixmap(mSocketWidget->window, NULL, FALSE);

  // Resize before we show
  SetAllocation();

  gtk_widget_show(mSocketWidget);

  gdk_flush();
  window = (void*)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));

  // Fill out the ws_info structure.
  // (The windowless case is done in nsObjectFrame.cpp.)
  GdkWindow *gdkWindow = gdk_window_lookup((XID)window);
  if(!gdkWindow)
    return NS_ERROR_FAILURE;

  mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow);
  mWsInfo.colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow));
  GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow);
  mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual);
  mWsInfo.depth = gdkVisual->depth;

  return NS_OK;
}
Example #3
0
GtkWidget*
gtk_xtbin_new (GdkWindow *parent_window, String * f)
{
  GtkXtBin *xtbin;
  gpointer user_data;

  assert(parent_window != NULL);
  xtbin = g_object_new (GTK_TYPE_XTBIN, NULL);

  if (!xtbin)
    return (GtkWidget*)NULL;

  if (f)
    fallback = f;

  /* Initialize the Xt toolkit */
  xtbin->parent_window = parent_window;

  xt_client_init(&(xtbin->xtclient), 
      GDK_VISUAL_XVISUAL(gdk_rgb_get_visual()),
      GDK_COLORMAP_XCOLORMAP(gdk_rgb_get_colormap()),
      gdk_rgb_get_visual()->depth);

  if (!xtbin->xtclient.xtdisplay) {
    /* If XtOpenDisplay failed, we can't go any further.
     *  Bail out.
     */
#ifdef DEBUG_XTBIN
    printf("gtk_xtbin_init: XtOpenDisplay() returned NULL.\n");
#endif
    g_free (xtbin);
    return (GtkWidget *)NULL;
  }

  /* Launch X event loop */
  xt_client_xloop_create();

  /* Build the hierachy */
  xtbin->xtdisplay = xtbin->xtclient.xtdisplay;
  gtk_widget_set_parent_window(GTK_WIDGET(xtbin), parent_window);
  gdk_window_get_user_data(xtbin->parent_window, &user_data);
  if (user_data)
    gtk_container_add(GTK_CONTAINER(user_data), GTK_WIDGET(xtbin));

  /* This GtkSocket has a visible window, but the Xt plug will cover this
   * window.  Normally GtkSockets let the X server paint their background and
   * this would happen immediately (before the plug is mapped).  Setting the
   * background to None prevents the server from painting this window,
   * avoiding flicker.
   */
  gtk_widget_realize(GTK_WIDGET(xtbin));
  gdk_window_set_back_pixmap(GTK_WIDGET(xtbin)->window, NULL, FALSE);

  return GTK_WIDGET (xtbin);
}
// Look for an existing Colormap that known to be associated with visual.
static Colormap
LookupColormapForVisual(const Screen* screen, const Visual* visual)
{
    // common case
    if (visual == DefaultVisualOfScreen(screen))
        return DefaultColormapOfScreen(screen);

#ifdef MOZ_WIDGET_GTK2
    // I wish there were a gdk_x11_display_lookup_screen.
    Display* dpy = DisplayOfScreen(screen);
    GdkDisplay* gdkDpy = gdk_x11_lookup_xdisplay(dpy);
    if (gdkDpy) {
        gint screen_num = 0;
        for (int s = 0; s < ScreenCount(dpy); ++s) {
            if (ScreenOfDisplay(dpy, s) == screen) {
                screen_num = s;
                break;
            }
        }
        GdkScreen* gdkScreen = gdk_display_get_screen(gdkDpy, screen_num);

        GdkColormap* gdkColormap = NULL;
        if (visual ==
            GDK_VISUAL_XVISUAL(gdk_screen_get_rgb_visual(gdkScreen))) {
            // widget/src/gtk2/mozcontainer.c uses gdk_rgb_get_colormap()
            // which is inherited by child widgets, so this is the visual
            // expected when drawing directly to widget surfaces or surfaces
            // created using cairo_surface_create_similar with
            // CAIRO_CONTENT_COLOR.
            // gdk_screen_get_rgb_colormap is the generalization of
            // gdk_rgb_get_colormap for any screen.
            gdkColormap = gdk_screen_get_rgb_colormap(gdkScreen);
        }
        else if (visual ==
             GDK_VISUAL_XVISUAL(gdk_screen_get_rgba_visual(gdkScreen))) {
            // This is the visual expected on displays with the Composite
            // extension enabled when the surface has been created using
            // cairo_surface_create_similar with CAIRO_CONTENT_COLOR_ALPHA,
            // as happens with non-unit opacity.
            gdkColormap = gdk_screen_get_rgba_colormap(gdkScreen);
        }
        if (gdkColormap != NULL)
            return GDK_COLORMAP_XCOLORMAP(gdkColormap);
    }
#endif

    return None;
}
Example #5
0
GtkWidget*
gtk_xtbin_new (GdkWindow *parent_window, String * f)
{
  GtkXtBin *xtbin;
  gpointer user_data;

  assert(parent_window != NULL);
  xtbin = gtk_type_new (GTK_TYPE_XTBIN);

  if (!xtbin)
    return (GtkWidget*)NULL;

  if (f)
    fallback = f;

  /* Initialize the Xt toolkit */
  xtbin->parent_window = parent_window;

  xt_client_init(&(xtbin->xtclient), 
      GDK_VISUAL_XVISUAL(gdk_window_get_visual(parent_window )),
      GDK_COLORMAP_XCOLORMAP(gdk_window_get_colormap(parent_window)),
      gdk_window_get_visual(parent_window )->depth);

  if (!xtbin->xtclient.xtdisplay) {
    /* If XtOpenDisplay failed, we can't go any further.
     *  Bail out.
     */
#ifdef DEBUG_XTBIN
    printf("gtk_xtbin_init: XtOpenDisplay() returned NULL.\n");
#endif
    g_free (xtbin);
    return (GtkWidget *)NULL;
  }

  /* If this is the first running widget, hook this display into the
     mainloop */
  if (0 == num_widgets) {
    int           cnumber;
    /*
     * hook Xt event loop into the glib event loop.
     */

    /* the assumption is that gtk_init has already been called */
    GSource* gs = g_source_new(&xt_event_funcs, sizeof(GSource));
      if (!gs) {
       return NULL;
      }
    
    g_source_set_priority(gs, GDK_PRIORITY_EVENTS);
    g_source_set_can_recurse(gs, TRUE);
    tag = g_source_attach(gs, (GMainContext*)NULL);
#ifdef VMS
    cnumber = XConnectionNumber(xtdisplay);
#else
    cnumber = ConnectionNumber(xtdisplay);
#endif
    xt_event_poll_fd.fd = cnumber;
    xt_event_poll_fd.events = G_IO_IN; 
    xt_event_poll_fd.revents = 0;    /* hmm... is this correct? */

    g_main_context_add_poll ((GMainContext*)NULL, 
                             &xt_event_poll_fd, 
                             G_PRIORITY_LOW);
    /* add a timer so that we can poll and process Xt timers */
    xt_polling_timer_id =
      gtk_timeout_add(25,
                      (GtkFunction)xt_event_polling_timer_callback,
                      xtdisplay);
  }

  /* Bump up our usage count */
  num_widgets++;

  /* Build the hierachy */
  xtbin->xtdisplay = xtbin->xtclient.xtdisplay;
  gtk_widget_set_parent_window(GTK_WIDGET(xtbin), parent_window);
  gdk_window_get_user_data(xtbin->parent_window, &user_data);
  if (user_data)
    gtk_container_add(GTK_CONTAINER(user_data), GTK_WIDGET(xtbin));

  return GTK_WIDGET (xtbin);
}
static void setup_font_sample(GtkWidget* darea, Antialiasing antialiasing, Hinting hinting)
{
	const char* string1 = "abcfgop AO ";
	const char* string2 = "abcfgop";

	XftColor black, white;
	XRenderColor rendcolor;

	Display* xdisplay = gdk_x11_get_default_xdisplay();

#if GTK_CHECK_VERSION (3, 0, 0)
	Colormap xcolormap = DefaultColormap(xdisplay, 0);
#else
	GdkColormap* colormap = gdk_rgb_get_colormap();
	Colormap xcolormap = GDK_COLORMAP_XCOLORMAP(colormap);
#endif

#if GTK_CHECK_VERSION (3, 0, 0)
	GdkVisual* visual = gdk_visual_get_system ();
#else
	GdkVisual* visual = gdk_colormap_get_visual(colormap);
#endif
	Visual* xvisual = GDK_VISUAL_XVISUAL(visual);

	FcPattern* pattern;
	XftFont* font1;
	XftFont* font2;
	XGlyphInfo extents1 = { 0 };
	XGlyphInfo extents2 = { 0 };
#if !GTK_CHECK_VERSION (3, 0, 0)
	GdkPixmap* pixmap;
#endif
	XftDraw* draw;
	GdkPixbuf* tmp_pixbuf;
	GdkPixbuf* pixbuf;

	int width, height;
	int ascent, descent;

	pattern = FcPatternBuild (NULL,
		FC_FAMILY, FcTypeString, "Serif",
		FC_SLANT, FcTypeInteger, FC_SLANT_ROMAN,
		FC_SIZE, FcTypeDouble, 18.,
		NULL);
	font1 = open_pattern (pattern, antialiasing, hinting);
	FcPatternDestroy (pattern);

	pattern = FcPatternBuild (NULL,
		FC_FAMILY, FcTypeString, "Serif",
		FC_SLANT, FcTypeInteger, FC_SLANT_ITALIC,
		FC_SIZE, FcTypeDouble, 20.,
		NULL);
	font2 = open_pattern (pattern, antialiasing, hinting);
	FcPatternDestroy (pattern);

	ascent = 0;
	descent = 0;
	
	if (font1)
	{
		XftTextExtentsUtf8 (xdisplay, font1, (unsigned char*) string1,
		strlen (string1), &extents1);
		ascent = MAX (ascent, font1->ascent);
		descent = MAX (descent, font1->descent);
	}

	if (font2)
	{
		XftTextExtentsUtf8 (xdisplay, font2, (unsigned char*) string2, strlen (string2), &extents2);
		ascent = MAX (ascent, font2->ascent);
		descent = MAX (descent, font2->descent);
	}

	width = extents1.xOff + extents2.xOff + 4;
	height = ascent + descent + 2;

#if !GTK_CHECK_VERSION (3, 0, 0)
	pixmap = gdk_pixmap_new (NULL, width, height, visual->depth);
#endif

#if GTK_CHECK_VERSION (3, 0, 0)
	draw = XftDrawCreate (xdisplay, GDK_WINDOW_XID (gdk_screen_get_root_window (gdk_screen_get_default ())), xvisual, xcolormap);
#else
	draw = XftDrawCreate (xdisplay, GDK_DRAWABLE_XID (pixmap), xvisual, xcolormap);
#endif

	rendcolor.red = 0;
	rendcolor.green = 0;
	rendcolor.blue = 0;
	rendcolor.alpha = 0xffff;
	
	XftColorAllocValue(xdisplay, xvisual, xcolormap, &rendcolor, &black);

	rendcolor.red = 0xffff;
	rendcolor.green = 0xffff;
	rendcolor.blue = 0xffff;
	rendcolor.alpha = 0xffff;
	
	XftColorAllocValue(xdisplay, xvisual, xcolormap, &rendcolor, &white);
	XftDrawRect(draw, &white, 0, 0, width, height);
	
	if (font1)
	{
		XftDrawStringUtf8(draw, &black, font1, 2, 2 + ascent, (unsigned char*) string1, strlen(string1));
	}
	
	if (font2)
	{
		XftDrawStringUtf8(draw, &black, font2, 2 + extents1.xOff, 2 + ascent, (unsigned char*) string2, strlen(string2));
	}

	XftDrawDestroy(draw);

	if (font1)
	{
		XftFontClose(xdisplay, font1);
	}
	
	if (font2)
	{
		XftFontClose(xdisplay, font2);
	}

#if GTK_CHECK_VERSION (3, 0, 0)
	tmp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,8, width, height);
#else
	tmp_pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, colormap, 0, 0, 0, 0, width, height);
#endif
	pixbuf = gdk_pixbuf_scale_simple(tmp_pixbuf, 1 * width, 1 * height, GDK_INTERP_TILES);

#if !GTK_CHECK_VERSION (3, 0, 0)
	g_object_unref(pixmap);
#endif
	g_object_unref(tmp_pixbuf);

	g_object_set_data_full(G_OBJECT(darea), "sample-pixbuf", pixbuf, (GDestroyNotify) g_object_unref);

#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_set_size_request  (GTK_WIDGET(darea), width + 2, height + 2);
	g_signal_connect(darea, "draw", G_CALLBACK(sample_draw), NULL);
#else
	g_signal_connect(darea, "size_request", G_CALLBACK(sample_size_request), NULL);
	g_signal_connect(darea, "expose_event", G_CALLBACK(sample_expose), NULL);
#endif
}
Example #7
0
nsresult nsPluginNativeWindowGtk::CreateXEmbedWindow(bool aEnableXtFocus) {
    NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");
    GdkDisplay *display = gdk_display_get_default();
    GdkWindow *parent_win = gdk_x11_window_lookup_for_display(display, GetWindow());
    mSocketWidget = gtk_socket_new();

    //attach the socket to the container widget
    gtk_widget_set_parent_window(mSocketWidget, parent_win);

    // enable/disable focus event handlers,
    // see plugin_window_filter_func() for details
    g_object_set_data(G_OBJECT(mSocketWidget), "enable-xt-focus", (void *)aEnableXtFocus);

    // Make sure to handle the plug_removed signal.  If we don't the
    // socket will automatically be destroyed when the plug is
    // removed, which means we're destroying it more than once.
    // SYNTAX ERROR.
    g_signal_connect(mSocketWidget, "plug_removed",
                     G_CALLBACK(plug_removed_cb), nullptr);

    g_signal_connect(mSocketWidget, "unrealize",
                     G_CALLBACK(socket_unrealize_cb), nullptr);

    g_signal_connect(mSocketWidget, "destroy",
                     G_CALLBACK(gtk_widget_destroyed), &mSocketWidget);

    gpointer user_data = nullptr;
    gdk_window_get_user_data(parent_win, &user_data);

    GtkContainer *container = GTK_CONTAINER(user_data);
    gtk_container_add(container, mSocketWidget);
    gtk_widget_realize(mSocketWidget);

    // The GtkSocket has a visible window, but the plugin's XEmbed plug will
    // cover this window.  Normally GtkSockets let the X server paint their
    // background and this would happen immediately (before the plug is
    // created).  Setting the background to None prevents the server from
    // painting this window, avoiding flicker.
    // TODO GTK3
#if (MOZ_WIDGET_GTK == 2)
    gdk_window_set_back_pixmap(gtk_widget_get_window(mSocketWidget), nullptr, FALSE);
#endif

    // Resize before we show
    SetAllocation();

    gtk_widget_show(mSocketWidget);

    gdk_flush();
    SetWindow(gtk_socket_get_id(GTK_SOCKET(mSocketWidget)));

    // Fill out the ws_info structure.
    // (The windowless case is done in nsPluginFrame.cpp.)
    GdkWindow *gdkWindow = gdk_x11_window_lookup_for_display(display, GetWindow());
    if(!gdkWindow)
        return NS_ERROR_FAILURE;

    mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow);
#if (MOZ_WIDGET_GTK == 2)
    mWsInfo.colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow));
    GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow);
    mWsInfo.depth = gdkVisual->depth;
#else
    mWsInfo.colormap = None;
    GdkVisual* gdkVisual = gdk_window_get_visual(gdkWindow);
    mWsInfo.depth = gdk_visual_get_depth(gdkVisual);
#endif
    mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual);

    return NS_OK;
}
static GdkPixmap *
create_text_pixmap(GtkWidget *drawing_area, FT_Face face)
{
    gint i, pixmap_width, pixmap_height, pos_y, textlen;
    GdkPixmap *pixmap = NULL;
    const gchar *text;
    Display *xdisplay;
    Drawable xdrawable;
    Visual *xvisual;
    Colormap xcolormap;
    XftDraw *draw;
    XftColor colour;
    XGlyphInfo extents;
    XftFont *font;
    gint *sizes = NULL, n_sizes, alpha_size;
    FcCharSet *charset = NULL;
    cairo_t *cr;
    GdkWindow *window = gtk_widget_get_window (drawing_area);

    text = pango_language_get_sample_string(NULL);
    if (! check_font_contain_text (face, text))
	{
	    pango_language_get_sample_string (pango_language_from_string ("en_US"));
	}

    textlen = strlen(text);

    /* create the XftDraw */
    xdisplay = GDK_PIXMAP_XDISPLAY(window);

	#if GTK_CHECK_VERSION(3, 0, 0)
		xvisual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window));
	#else
		xvisual = GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(window));
	#endif

    xcolormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(window));
    XftColorAllocName(xdisplay, xvisual, xcolormap, "black", &colour);

    /* work out what sizes to render */
    if (FT_IS_SCALABLE(face)) {
	n_sizes = 8;
	sizes = g_new(gint, n_sizes);
	sizes[0] = 8;
	sizes[1] = 10;
	sizes[2] = 12;
	sizes[3] = 18;
	sizes[4] = 24;
	sizes[5] = 36;
	sizes[6] = 48;
	sizes[7] = 72;
	alpha_size = 24;
    } else {
	/* use fixed sizes */
	n_sizes = face->num_fixed_sizes;
	sizes = g_new(gint, n_sizes);
	alpha_size = 0;
	for (i = 0; i < face->num_fixed_sizes; i++) {
	    sizes[i] = face->available_sizes[i].height;

	    /* work out which font size to render */
	    if (face->available_sizes[i].height <= 24)
		alpha_size = face->available_sizes[i].height;
	}
    }

    /* calculate size of pixmap to use (with 4 pixels padding) ... */
    pixmap_width = 8;
    pixmap_height = 8;

    font = get_font(xdisplay, face, alpha_size, charset);
    charset = FcCharSetCopy (font->charset);
    XftTextExtentsUtf8(xdisplay, font,
		       (guchar *)lowercase_text, strlen(lowercase_text), &extents);
    pixmap_height += extents.height + 4;
    pixmap_width = MAX(pixmap_width, 8 + extents.width);
    XftTextExtentsUtf8(xdisplay, font,
		       (guchar *)uppercase_text, strlen(uppercase_text), &extents);
    pixmap_height += extents.height + 4;
    pixmap_width = MAX(pixmap_width, 8 + extents.width);
    XftTextExtentsUtf8(xdisplay, font,
		       (guchar *)punctuation_text, strlen(punctuation_text), &extents);
    pixmap_height += extents.height + 4;
    pixmap_width = MAX(pixmap_width, 8 + extents.width);
    XftFontClose(xdisplay, font);

    pixmap_height += 8;

    for (i = 0; i < n_sizes; i++) {
	font = get_font(xdisplay, face, sizes[i], charset);
	if (!font) continue;
	XftTextExtentsUtf8(xdisplay, font, (guchar *)text, textlen, &extents);
	pixmap_height += extents.height + 4;
	pixmap_width = MAX(pixmap_width, 8 + extents.width);
	XftFontClose(xdisplay, font);
    }

    /* create pixmap */
    gtk_widget_set_size_request(drawing_area, pixmap_width, pixmap_height);
    pixmap = gdk_pixmap_new(window,
			    pixmap_width, pixmap_height, -1);
    if (!pixmap)
	goto end;
    cr = gdk_cairo_create (pixmap);
    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);
    cairo_destroy (cr);

    xdrawable = GDK_DRAWABLE_XID(pixmap);
    draw = XftDrawCreate(xdisplay, xdrawable, xvisual, xcolormap);

    /* draw text */
    pos_y = 4;
    font = get_font(xdisplay, face, alpha_size, charset);
    draw_string(xdisplay, draw, font, &colour, lowercase_text, &pos_y);
    draw_string(xdisplay, draw, font, &colour, uppercase_text, &pos_y);
    draw_string(xdisplay, draw, font, &colour, punctuation_text, &pos_y);
    XftFontClose(xdisplay, font);

    pos_y += 8;
    for (i = 0; i < n_sizes; i++) {
	font = get_font(xdisplay, face, sizes[i], charset);
	if (!font) continue;
	draw_string(xdisplay, draw, font, &colour, text, &pos_y);
	XftFontClose(xdisplay, font);
    }

    g_signal_connect(drawing_area, "expose-event", G_CALLBACK(expose_event),
                     pixmap);

 end:
    g_free(sizes);
    FcCharSetDestroy (charset);
    return pixmap;
}
nsresult nsPluginNativeWindowGtk2::CreateXCompositedWindow() {
  NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");

  mParentWindow = gtk_window_new(GTK_WINDOW_POPUP);
  mSocketWidget = gtk_socket_new();
  GdkWindow *parent_win = mParentWindow->window;

  //attach the socket to the container widget
  gtk_widget_set_parent_window(mSocketWidget, parent_win);

  // Make sure to handle the plug_removed signal.  If we don't the
  // socket will automatically be destroyed when the plug is
  // removed, which means we're destroying it more than once.
  // SYNTAX ERROR.
  g_signal_connect(mSocketWidget, "plug_removed",
                   G_CALLBACK(plug_removed_cb), NULL);

  g_signal_connect(mSocketWidget, "destroy",
                   G_CALLBACK(gtk_widget_destroyed), &mSocketWidget);

  /*gpointer user_data = NULL;
  gdk_window_get_user_data(parent_win, &user_data);
  */
  GtkContainer *container = GTK_CONTAINER(mParentWindow);
  gtk_container_add(container, mSocketWidget);
  gtk_widget_realize(mSocketWidget);

  // Resize before we show
  SetAllocation();
  gtk_widget_set_size_request (mSocketWidget, width, height);
  /* move offscreen */
  gtk_window_move (GTK_WINDOW(mParentWindow), width+1000, height+1000);


  gtk_widget_show(mSocketWidget);
  gtk_widget_show_all(mParentWindow);

  /* store away a reference to the socketwidget */
  mPlugWindow = (mSocketWidget);

  gdk_flush();
  window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));

  /* This is useful if we still have the plugin window inline
   * i.e. firefox vs. fennec */
  // gdk_window_set_composited(mSocketWidget->window, TRUE);

  if (!mDamage) {
    /* we install a general handler instead of one specific to a particular window
     * because we don't have a GdkWindow for the plugin window */
    gdk_window_add_filter (parent_win, plugin_composite_filter_func, this);

    int junk;
    if (!XDamageQueryExtension (GDK_DISPLAY (), &xdamage_event_base, &junk))
      printf ("This requires the XDamage extension");

    mDamage = XDamageCreate(GDK_DISPLAY(), (Drawable)window, XDamageReportNonEmpty);
    XCompositeRedirectWindow (GDK_DISPLAY(),
        (Drawable)window,
        CompositeRedirectManual);

    /* this is a hack to avoid having flash causing a crash when it is unloaded.
     * libplayback sets up dbus_connection_filters. When flash is unloaded it takes
     * libplayback with it, however the connection filters are not removed
     * which causes a crash when dbus tries to execute them. dlopening libplayback
     * ensures that those functions stay around even after flash is gone. */
    static void *libplayback_handle;
    if (!libplayback_handle) {
      libplayback_handle = dlopen("libplayback-1.so.0", RTLD_NOW);
    }

  }

  // Fill out the ws_info structure.
  // (The windowless case is done in nsObjectFrame.cpp.)
  GdkWindow *gdkWindow = gdk_window_lookup((XID)window);
  mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow);
  mWsInfo.colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow));
  GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow);
  mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual);
  mWsInfo.depth = gdkVisual->depth;

  return NS_OK;
}
Example #10
0
ScreenInfo *
myScreenInit (DisplayInfo *display_info, GdkScreen *gscr, unsigned long event_mask, gboolean replace_wm)
{
#ifdef ENABLE_KDE_SYSTRAY_PROXY
    gchar selection[32];
#endif
    ScreenInfo *screen_info;
    GdkWindow *event_win;
    PangoLayout *layout;
    long desktop_visible;
    int i, j;

    g_return_val_if_fail (display_info, NULL);
    g_return_val_if_fail (GDK_IS_SCREEN (gscr), NULL);
    TRACE ("entering myScreenInit");

    screen_info = g_new0 (ScreenInfo, 1);
    screen_info->params = g_new0 (XfwmParams, 1);

    screen_info->display_info = display_info;
    screen_info->gscr = gscr;
    desktop_visible = 0;
    layout = NULL;

    /* Create a GTK window so that we are just like any other GTK application */
    screen_info->gtk_win = gtk_window_new (GTK_WINDOW_POPUP);
    gtk_window_set_screen (GTK_WINDOW (screen_info->gtk_win), gscr);
    gtk_window_resize (GTK_WINDOW (screen_info->gtk_win), 5, 5);
    gtk_window_move (GTK_WINDOW (screen_info->gtk_win), -1000, -1000);
    gtk_widget_set_name (screen_info->gtk_win, "xfwm");
    gtk_widget_show_now (screen_info->gtk_win);

    /*
     * The first time the first Gtk application on a display uses pango,
     * pango grabs the XServer while it creates the font cache window.
     * Therefore, force the cache window to be created now instead of
     * trying to do it while we have another grab and deadlocking the server.
     */
    layout = gtk_widget_create_pango_layout (screen_info->gtk_win, "-");
    pango_layout_get_pixel_extents (layout, NULL, NULL);
    g_object_unref (G_OBJECT (layout));

    screen_info->xscreen = gdk_x11_screen_get_xscreen (gscr);
    screen_info->xroot = (Window) GDK_DRAWABLE_XID(gdk_screen_get_root_window (gscr));
    screen_info->screen = gdk_screen_get_number (gscr);
    screen_info->cmap = GDK_COLORMAP_XCOLORMAP(gdk_screen_get_rgb_colormap (gscr));
    screen_info->depth = DefaultDepth (display_info->dpy, screen_info->screen);
    screen_info->visual = DefaultVisual (display_info->dpy, screen_info->screen);
    screen_info->shape_win = (Window) None;
    myScreenComputeSize (screen_info);

    screen_info->xfwm4_win = GDK_WINDOW_XWINDOW (screen_info->gtk_win->window);
    if (!myScreenSetWMAtom (screen_info, replace_wm))
    {
        gtk_widget_destroy (screen_info->gtk_win);
        g_free (screen_info);
        return NULL;
    }

    event_win = eventFilterAddWin (gscr, event_mask);
    if (!event_win)
    {
        gtk_widget_destroy (screen_info->gtk_win);
        g_free (screen_info);
        return NULL;
    }
    gdk_window_set_user_data (event_win, screen_info->gtk_win);

    screen_info->current_ws = 0;
    screen_info->previous_ws = 0;
    screen_info->current_ws = 0;
    screen_info->previous_ws = 0;

    screen_info->margins[STRUTS_TOP] = screen_info->gnome_margins[STRUTS_TOP] = 0;
    screen_info->margins[STRUTS_LEFT] = screen_info->gnome_margins[STRUTS_LEFT] = 0;
    screen_info->margins[STRUTS_RIGHT] = screen_info->gnome_margins[STRUTS_RIGHT] = 0;
    screen_info->margins[STRUTS_BOTTOM] = screen_info->gnome_margins[STRUTS_BOTTOM] = 0;

    screen_info->workspace_count = 0;
    screen_info->workspace_names = NULL;
    screen_info->workspace_names_items = 0;

    screen_info->windows_stack = NULL;
    screen_info->last_raise = NULL;
    screen_info->windows = NULL;
    screen_info->clients = NULL;
    screen_info->client_count = 0;
    screen_info->client_serial = 0L;
    screen_info->button_handler_id = 0L;

    screen_info->key_grabs = 0;
    screen_info->pointer_grabs = 0;

    getHint (display_info, screen_info->xroot, NET_SHOWING_DESKTOP, &desktop_visible);
    screen_info->show_desktop = (desktop_visible != 0);

    /* Create the side windows to detect edge movement */

    /*left*/
    xfwmWindowTemp (screen_info,
                    NULL, 0,
                    screen_info->xroot,
                    &screen_info->sidewalk[0],
                    0, 0,
                    1, screen_info->height,
                    EnterWindowMask,
                    TRUE);

    /*right*/
    xfwmWindowTemp (screen_info,
                    NULL, 0,
                    screen_info->xroot,
                    &screen_info->sidewalk[1],
                    screen_info->width - 1, 0,
                    1, screen_info->height,
                    EnterWindowMask,
                    TRUE);

    /*top*/
    xfwmWindowTemp (screen_info,
                    NULL, 0,
                    screen_info->xroot,
                    &screen_info->sidewalk[2],
                    0, 0,
                    screen_info->width, 1,
                    EnterWindowMask,
                    TRUE);

    /*bottom*/
    xfwmWindowTemp (screen_info,
                    NULL, 0,
                    screen_info->xroot,
                    &screen_info->sidewalk[3],
                    0, screen_info->height - 1,
                    screen_info->width, 1,
                    EnterWindowMask,
                    TRUE);

#ifdef ENABLE_KDE_SYSTRAY_PROXY
    g_snprintf (selection, sizeof (selection), "_NET_SYSTEM_TRAY_S%d", screen_info->screen);
    screen_info->net_system_tray_selection = XInternAtom (display_info->dpy, selection, FALSE);
    screen_info->systray = getSystrayWindow (display_info, screen_info->net_system_tray_selection);
#endif

    screen_info->font_height = 0;
    screen_info->box_gc = None;
    screen_info->black_gc = NULL;
    screen_info->white_gc = NULL;
    screen_info->title_colors[ACTIVE].gc = NULL;
    screen_info->title_colors[ACTIVE].allocated = FALSE;
    screen_info->title_colors[INACTIVE].gc = NULL;
    screen_info->title_colors[INACTIVE].allocated = FALSE;
    screen_info->title_shadow_colors[ACTIVE].gc = NULL;
    screen_info->title_shadow_colors[ACTIVE].allocated = FALSE;
    screen_info->title_shadow_colors[INACTIVE].gc = NULL;
    screen_info->title_shadow_colors[INACTIVE].allocated = FALSE;

    for (i = 0; i < SIDE_COUNT; i++)
    {
        xfwmPixmapInit (screen_info, &screen_info->sides[i][ACTIVE]);
        xfwmPixmapInit (screen_info, &screen_info->sides[i][INACTIVE]);
    }
    for (i = 0; i < CORNER_COUNT; i++)
    {
        xfwmPixmapInit (screen_info, &screen_info->corners[i][ACTIVE]);
        xfwmPixmapInit (screen_info, &screen_info->corners[i][INACTIVE]);
    }
    for (i = 0; i < BUTTON_COUNT; i++)
    {
        for (j = 0; j < STATE_COUNT; j++)
        {
            xfwmPixmapInit (screen_info, &screen_info->buttons[i][j]);
        }
    }
    for (i = 0; i < TITLE_COUNT; i++)
    {
        xfwmPixmapInit (screen_info, &screen_info->title[i][ACTIVE]);
        xfwmPixmapInit (screen_info, &screen_info->title[i][INACTIVE]);
        xfwmPixmapInit (screen_info, &screen_info->top[i][ACTIVE]);
        xfwmPixmapInit (screen_info, &screen_info->top[i][INACTIVE]);
    }

    screen_info->monitors_index = NULL;
    myScreenInvalidateMonitorCache (screen_info);
    myScreenRebuildMonitorIndex (screen_info);

    return (screen_info);
}