Stealing usability from Apple

Apple’s OS X, which I use for most things at home, has a cool feature on its ‘dashboard’ which allows a webpage or fragment thereof to be displayed as a ‘widget’.  Ubuntu comes with a similar ‘dashboard’ thing; Compiz fusion knows it as ‘Widget Later’.  I was unable to find a web-viewing widget installed with Ubuntu, so I wrote my own.

It mimics Apple’s to the following extent: it can display any web page, and it updates each time it is displayed.  It’s deficient compared to Apple’s in that it can only view complete web pages and it isn’t integrated into a convenient browser button. It’s also difficult to resize unless you know the mouse shortcuts for that – Super Key + Middle Button on my system.

To build it you will need to install the libwebkitgtk-dev package and a standard GTK+ development environment.  To use it you will need Compiz Fusion with the Widget Layer plugin enabled and set so that it treats any window with a ‘role’ of ‘widget’ as a widget.

Build command is:

gcc -Wall -W -std=gnu99 `pkg-config --cflags WebKitGtk gtk+-2.0` `pkg-config --libs WebKitGtk gtk+-2.0` -o webwidget webwidget.c

The code for webwidget.c is:

#include <gtk/gtk.h>
#include <glib.h>
#include <WebKit/webkit.h>

static gboolean visibility_event( GtkWidget *, GdkEvent  *, gpointer);

int
main (int argc, char **argv)
{
  GtkWidget *window;
  GtkWidget *webview;

  gtk_init(&argc, &argv);

  webview = webkit_web_view_new();

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
  gtk_window_set_decorated(GTK_WINDOW (window), FALSE);
  gtk_window_set_default_size(GTK_WINDOW (window), 320, 480);
  gtk_container_add (GTK_CONTAINER (window), webview);
  gtk_window_set_role(GTK_WINDOW(window), "widget");

  g_signal_connect (G_OBJECT (webview), "visibility-notify-event", G_CALLBACK (visibility_event), (argc > 1) ? argv[1] : "http://m.google.com/");

  gtk_widget_show_all(window);
  gtk_main();

  return 0;
}

static gboolean
visibility_event( GtkWidget *widget
                , GdkEvent  *event
		, gpointer data
                )
{
  if (((GdkEventVisibility*)event)->state != GDK_VISIBILITY_FULLY_OBSCURED)
    webkit_web_view_open(WEBKIT_WEB_VIEW(widget), (gchar *)data);
  return TRUE;
}

3 Responses to “Stealing usability from Apple”

  1. nishit

    HI,

    There is one file in WebKit source named WebKit/gtk/webkit/webkitwebview.cpp in which the function
    GtkWidget* webkit_web_view_new(void) is called and in this a function is called in this which is
    WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, NULL));

    which is given as
    #define WEBKIT_TYPE_WEB_VIEW (webkit_web_view_get_type())

    which i am unable to find out. I am stucking in this function when i run WebKit.

    Can anybody help me in finding out the definition of this function.

    Thanks and Regards
    Nishit

    Reply

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>