summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--applets/fish/fish.c144
1 files changed, 132 insertions, 12 deletions
diff --git a/applets/fish/fish.c b/applets/fish/fish.c
index 01b9ed6c..ac3c196d 100644
--- a/applets/fish/fish.c
+++ b/applets/fish/fish.c
@@ -32,11 +32,15 @@
#include <time.h>
#include <cairo.h>
+#include <cairo-xlib.h>
#include <glib/gi18n.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
+#if GTK_CHECK_VERSION (3, 0, 0)
+#include <gdk/gdkkeysyms-compat.h>
+#endif
#include <gio/gio.h>
#include <mate-panel-applet.h>
@@ -79,7 +83,11 @@ typedef struct {
GtkWidget *drawing_area;
GtkRequisition requisition;
GdkRectangle prev_allocation;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_surface_t *surface;
+#else
GdkPixmap *pixmap;
+#endif
guint timeout;
int current_frame;
gboolean in_applet;
@@ -791,6 +799,17 @@ static gboolean fish_read_output(GIOChannel* source, GIOCondition condition, gpo
return (status != G_IO_STATUS_EOF);
}
+#if GTK_CHECK_VERSION (3, 0, 0)
+/*
+ * Set the DISPLAY variable, to be use by g_spawn_async.
+ */
+static void
+set_environment (gpointer display)
+{
+ g_setenv ("DISPLAY", display, TRUE);
+}
+#endif
+
static void display_fortune_dialog(FishApplet* fish)
{
GError *error = NULL;
@@ -799,6 +818,10 @@ static void display_fortune_dialog(FishApplet* fish)
const char *charset;
int argc;
char **argv;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkScreen *screen;
+ char *display;
+#endif
/* if there is still a pipe, close it */
if (fish->source_id)
@@ -826,8 +849,10 @@ static void display_fortune_dialog(FishApplet* fish)
gtk_window_set_icon_name (GTK_WINDOW (fish->fortune_dialog),
FISH_ICON);
+#if !GTK_CHECK_VERSION (3, 0, 0)
gtk_dialog_set_has_separator (
GTK_DIALOG (fish->fortune_dialog), FALSE);
+#endif
gtk_dialog_set_default_response (
GTK_DIALOG (fish->fortune_dialog), GTK_RESPONSE_CLOSE);
@@ -918,11 +943,28 @@ static void display_fortune_dialog(FishApplet* fish)
clear_fortune_text (fish);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ screen = gtk_widget_get_screen (GTK_WIDGET (fish));
+ display = gdk_screen_make_display_name (screen);
+ g_spawn_async_with_pipes (NULL, /* working directory */
+ argv,
+ NULL, /* envp */
+ G_SPAWN_SEARCH_PATH|G_SPAWN_STDERR_TO_DEV_NULL,
+ set_environment,
+ &display,
+ NULL, /* child pid */
+ NULL, /* stdin */
+ &output,
+ NULL, /* stderr */
+ &error);
+ g_free (display);
+#else
gdk_spawn_on_screen_with_pipes (gtk_widget_get_screen (GTK_WIDGET (fish)),
NULL, argv, NULL,
G_SPAWN_SEARCH_PATH|G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL, NULL, NULL, &output, NULL,
&error);
+#endif
if (error) {
char *message;
@@ -1357,21 +1399,37 @@ static void update_pixmap(FishApplet* fish)
}
}
+ gtk_widget_set_size_request (fish->drawing_area,
+ fish->requisition.width,
+ fish->requisition.height);
+
g_assert (width != -1 && height != -1);
if (width == 0 || height == 0)
return;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ if (fish->surface)
+ cairo_surface_destroy (fish->surface);
+ fish->surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
+ CAIRO_CONTENT_COLOR_ALPHA,
+ width, height);
+#else
if (fish->pixmap)
g_object_unref (fish->pixmap);
fish->pixmap = gdk_pixmap_new (gtk_widget_get_window (widget),
width, height, -1);
+#endif
gtk_widget_queue_resize (widget);
g_assert (pixbuf_width != -1 && pixbuf_height != -1);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cr = cairo_create (fish->surface);
+#else
cr = gdk_cairo_create (fish->pixmap);
+#endif
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_paint (cr);
@@ -1418,7 +1476,11 @@ static void update_pixmap(FishApplet* fish)
cairo_destroy (cr);
}
+#if GTK_CHECK_VERSION (3, 0, 0)
+static gboolean fish_applet_draw(GtkWidget* widget, cairo_t *cr, FishApplet* fish)
+#else
static gboolean fish_applet_expose_event(GtkWidget* widget, GdkEventExpose* event, FishApplet* fish)
+#endif
{
GdkWindow *window;
GtkStyle *style;
@@ -1426,7 +1488,11 @@ static gboolean fish_applet_expose_event(GtkWidget* widget, GdkEventExpose* even
int width, height;
int src_x, src_y;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_return_val_if_fail (fish->surface != NULL, FALSE);
+#else
g_return_val_if_fail (fish->pixmap != NULL, FALSE);
+#endif
g_assert (fish->n_frames > 0);
@@ -1434,16 +1500,16 @@ static gboolean fish_applet_expose_event(GtkWidget* widget, GdkEventExpose* even
style = gtk_widget_get_style (widget);
state = gtk_widget_get_state (widget);
- #if GTK_CHECK_VERSION(3, 0, 0)
- width = gdk_window_get_width(fish->pixmap);
- height = gdk_window_get_height(fish->pixmap);
- #else
- gdk_drawable_get_size(fish->pixmap, &width, &height);
- #endif
-
-
+#if GTK_CHECK_VERSION(3, 0, 0)
+ width = cairo_xlib_surface_get_width (fish->surface);
+ height = cairo_xlib_surface_get_height (fish->surface);
+ src_x = 0;
+ src_y = 0;
+#else
+ gdk_drawable_get_size(fish->pixmap, &width, &height);
src_x = event->area.x;
src_y = event->area.y;
+#endif
if (fish->rotate) {
if (fish->orientation == MATE_PANEL_APPLET_ORIENT_RIGHT)
@@ -1455,20 +1521,29 @@ static gboolean fish_applet_expose_event(GtkWidget* widget, GdkEventExpose* even
} else
src_x += ((width * fish->current_frame) / fish->n_frames);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_save (cr);
+ cairo_set_source_surface (cr, fish->surface, -src_x, -src_y);
+ cairo_paint (cr);
+ cairo_restore (cr);
+#else
gdk_draw_drawable (window,
style->fg_gc [state],
fish->pixmap,
src_x, src_y,
event->area.x, event->area.y,
event->area.width, event->area.height);
+#endif
return FALSE;
}
+#if !GTK_CHECK_VERSION (3, 0, 0)
static void fish_applet_size_request(GtkWidget* widget, GtkRequisition* requisition, FishApplet* fish)
{
*requisition = fish->requisition;
}
+#endif
static void fish_applet_size_allocate(GtkWidget* widget, GtkAllocation* allocation, FishApplet* fish)
{
@@ -1485,15 +1560,25 @@ static void fish_applet_size_allocate(GtkWidget* widget, GtkAllocation* allocati
static void fish_applet_realize(GtkWidget* widget, FishApplet* fish)
{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ if (!fish->surface)
+#else
if (!fish->pixmap)
+#endif
update_pixmap (fish);
}
static void fish_applet_unrealize(GtkWidget* widget, FishApplet* fish)
{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ if (fish->surface)
+ cairo_surface_destroy (fish->surface);
+ fish->surface = NULL;
+#else
if (fish->pixmap)
g_object_unref (fish->pixmap);
fish->pixmap = NULL;
+#endif
}
static void fish_applet_change_orient(MatePanelApplet* applet, MatePanelAppletOrient orientation)
@@ -1505,7 +1590,11 @@ static void fish_applet_change_orient(MatePanelApplet* applet, MatePanelAppletOr
fish->orientation = orientation;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ if (fish->surface)
+#else
if (fish->pixmap)
+#endif
update_pixmap (fish);
}
@@ -1624,12 +1713,17 @@ static void setup_fish_widget(FishApplet* fish)
G_CALLBACK (fish_applet_realize), fish);
g_signal_connect (fish->drawing_area, "unrealize",
G_CALLBACK (fish_applet_unrealize), fish);
- g_signal_connect (fish->drawing_area, "size-request",
- G_CALLBACK (fish_applet_size_request), fish);
g_signal_connect (fish->drawing_area, "size-allocate",
G_CALLBACK (fish_applet_size_allocate), fish);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_signal_connect (fish->drawing_area, "draw",
+ G_CALLBACK (fish_applet_draw), fish);
+#else
g_signal_connect (fish->drawing_area, "expose-event",
G_CALLBACK (fish_applet_expose_event), fish);
+ g_signal_connect (fish->drawing_area, "size-request",
+ G_CALLBACK (fish_applet_size_request), fish);
+#endif
gtk_widget_add_events (widget, GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK |
@@ -1745,7 +1839,11 @@ static gboolean fishy_factory(MatePanelApplet* applet, const char* iid, gpointer
return retval;
}
+#if GTK_CHECK_VERSION (3, 0, 0)
+static void fish_applet_dispose (GObject *object)
+#else
static void fish_applet_destroy(GtkObject* object)
+#endif
{
FishApplet* fish = (FishApplet*) object;
@@ -1776,9 +1874,15 @@ static void fish_applet_destroy(GtkObject* object)
g_free (fish->command);
fish->command = NULL;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ if (fish->surface)
+ cairo_surface_destroy (fish->surface);
+ fish->surface = NULL;
+#else
if (fish->pixmap)
g_object_unref (fish->pixmap);
fish->pixmap = NULL;
+#endif
if (fish->pixbuf)
g_object_unref (fish->pixbuf);
@@ -1798,7 +1902,11 @@ static void fish_applet_destroy(GtkObject* object)
fish_close_channel (fish);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+#else
GTK_OBJECT_CLASS (parent_class)->destroy (object);
+#endif
}
static void fish_applet_instance_init(FishApplet* fish, FishAppletClass* klass)
@@ -1814,7 +1922,11 @@ static void fish_applet_instance_init(FishApplet* fish, FishAppletClass* klass)
fish->frame = NULL;
fish->drawing_area = NULL;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ fish->surface = NULL;
+#else
fish->pixmap = NULL;
+#endif
fish->timeout = 0;
fish->current_frame = 0;
fish->in_applet = FALSE;
@@ -1857,14 +1969,22 @@ static void fish_applet_instance_init(FishApplet* fish, FishAppletClass* klass)
static void fish_applet_class_init(FishAppletClass* klass)
{
- MatePanelAppletClass* applet_class = (MatePanelAppletClass*) klass;
- GtkObjectClass* gtkobject_class = (GtkObjectClass*) klass;
+ MatePanelAppletClass* applet_class = (MatePanelAppletClass*) klass;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GObjectClass *gobject_class = (GObjectClass *) klass;
+#else
+ GtkObjectClass* gtkobject_class = (GtkObjectClass*) klass;
+#endif
parent_class = g_type_class_peek_parent(klass);
applet_class->change_orient = fish_applet_change_orient;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gobject_class->dispose = fish_applet_dispose;
+#else
gtkobject_class->destroy = fish_applet_destroy;
+#endif
init_fools_day();
}