Changeset 14885 in osm for applications


Ignore:
Timestamp:
2009-05-04T01:04:49+02:00 (16 years ago)
Author:
tomhughes
Message:

Updated version of webkit-image-gtk.c from original author. Closes #1429.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/webkit-image-gtk.c

    r12328 r14885  
     1/* There is no licence for this, I don't care what you do with it */
    12#include <stdio.h>
    23#include <stdlib.h>
    34
    4 #include <webkit.h>
     5#include <webkit/webkit.h>
    56
    67#define WIDTH 2000
    78
    89/* compile with:
    9 gcc -W webkit-image-gtk.cpp `pkg-config --libs --cflags WebKitGtk gtk+-2.0`
     10gcc `pkg-config --cflags --libs webkit-1.0` -o webkit-image-gtk webkit-image-gtk.c
    1011*/
    1112
     
    1314on_finished (WebKitWebView *view, WebKitWebFrame *frame)
    1415{
    15         GdkPixmap *pixmap;
    16         GdkColormap *cmap;
    17         GdkPixbuf *pixbuf;
    18         gchar *buffer;
    19         gsize size;
     16        GdkPixmap *pixmap;
     17        GdkColormap *cmap;
     18        GdkPixbuf *pixbuf;
     19        gchar *buffer;
     20        gsize size;
    2021
    21         pixmap = gtk_widget_get_snapshot (GTK_WIDGET (view), NULL);
    22         cmap = gdk_colormap_get_system ();
    23         pixbuf = gdk_pixbuf_get_from_drawable (NULL, GDK_DRAWABLE (pixmap), cmap,
    24                                                0, 0, 0, 0, WIDTH, WIDTH);
     22        pixmap = gtk_widget_get_snapshot (GTK_WIDGET (view), NULL);
     23        cmap = gdk_colormap_get_system ();
     24        pixbuf = gdk_pixbuf_get_from_drawable (NULL, GDK_DRAWABLE (pixmap), cmap,
     25                                               0, 0, 0, 0, WIDTH, WIDTH);
    2526
    26         gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &size, "png", NULL, NULL);
     27        gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &size, "png", NULL, NULL);
    2728
    28         fwrite (buffer, 1, size, stdout);
     29        fwrite (buffer, 1, size, stdout);
    2930
    30         exit (1);
     31        exit (1);
    3132}
    3233
    3334int main (int argc, char **argv)
    3435{
    35         GtkWidget *window;
    36         GtkWidget *view;
     36        GtkWidget *window;
     37        GtkWidget *view;
    3738
    38         if (argc != 2)
    39                 exit (20);
     39        if (argc != 2)
     40                exit (20);
    4041
    41         gtk_init (&argc, &argv);
     42        gtk_init (&argc, &argv);
    4243
    43         /* Horribly hacky */
    44         window = gtk_window_new (GTK_WINDOW_POPUP);
    45         gtk_window_set_opacity (GTK_WINDOW (window), 0.0);
     44        window = gtk_window_new (GTK_WINDOW_POPUP);
    4645
    47         view = webkit_web_view_new ();
    48         webkit_web_view_open (WEBKIT_WEB_VIEW (view), argv[1]);
    49         gtk_widget_set_size_request (view, WIDTH, WIDTH);
    50         gtk_container_add (GTK_CONTAINER (window), view);
     46        /* Check if compositing window manager is running, needs one for now */
     47        if (gtk_widget_is_composited (window))
     48                gtk_window_set_opacity (GTK_WINDOW (window), 0.0);
     49        else
     50                g_error ("This requires a compositing window manager for now");
    5151
    52         gtk_widget_show_all (window);
     52        view = webkit_web_view_new ();
     53        webkit_web_view_open (WEBKIT_WEB_VIEW (view), argv[1]);
     54        gtk_widget_set_size_request (view, WIDTH, WIDTH);
     55        gtk_container_add (GTK_CONTAINER (window), view);
    5356
    54         g_signal_connect (G_OBJECT (view), "load-finished",
    55                           G_CALLBACK (on_finished), NULL);
     57        gtk_widget_show_all (window);
    5658
    57         gtk_main ();
    58         return 0;
     59        g_signal_connect (G_OBJECT (view), "load-finished",
     60                          G_CALLBACK (on_finished), NULL);
     61
     62        gtk_main ();
     63        return 0;
    5964}
Note: See TracChangeset for help on using the changeset viewer.