diff options
author | Stefano Karapetsas <[email protected]> | 2014-01-17 14:00:31 +0100 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2014-01-17 14:00:31 +0100 |
commit | 09dade79ca3eae57c7e7c67b1ba5b19d38e09719 (patch) | |
tree | cc051e4c1a6bf747ac294e5a4815561ff9ce623b /applets/inhibit | |
parent | 7c67131606ad0172720317beda93f9819741cfaa (diff) | |
download | mate-power-manager-09dade79ca3eae57c7e7c67b1ba5b19d38e09719.tar.bz2 mate-power-manager-09dade79ca3eae57c7e7c67b1ba5b19d38e09719.tar.xz |
applets: Add GTK3 support
Diffstat (limited to 'applets/inhibit')
-rw-r--r-- | applets/inhibit/inhibit-applet.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/applets/inhibit/inhibit-applet.c b/applets/inhibit/inhibit-applet.c index 3f70ec4..b8c8823 100644 --- a/applets/inhibit/inhibit-applet.c +++ b/applets/inhibit/inhibit-applet.c @@ -48,6 +48,10 @@ #define GPM_IS_INHIBIT_APPLET_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_INHIBIT_APPLET)) #define GPM_INHIBIT_APPLET_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_INHIBIT_APPLET, GpmInhibitAppletClass)) +#if GTK_CHECK_VERSION (3, 0, 0) +#define GtkObject GtkWidget +#endif + typedef struct{ MatePanelApplet parent; /* applet state */ @@ -283,17 +287,26 @@ static gboolean gpm_applet_draw_cb (GpmInhibitApplet *applet) { gint w, h, bg_type; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; + cairo_t *cr; + cairo_pattern_t *pattern; + GtkStyleContext *context; +#else GdkColor color; GdkGC *gc; GdkPixmap *background; +#endif GtkAllocation allocation; if (gtk_widget_get_window (GTK_WIDGET(applet)) == NULL) { return FALSE; } +#if !GTK_CHECK_VERSION (3, 0, 0) /* Clear the window so we can draw on it later */ gdk_window_clear(gtk_widget_get_window (GTK_WIDGET (applet))); +#endif /* retrieve applet size */ gpm_applet_get_icon (applet); @@ -311,27 +324,58 @@ gpm_applet_draw_cb (GpmInhibitApplet *applet) w = allocation.width; h = allocation.height; +#if GTK_CHECK_VERSION (3, 0, 0) + cr = gdk_cairo_create (gtk_widget_get_window (GTK_WIDGET(applet))); +#else gc = gdk_gc_new (gtk_widget_get_window (GTK_WIDGET(applet))); +#endif /* draw pixmap background */ +#if GTK_CHECK_VERSION (3, 0, 0) + bg_type = mate_panel_applet_get_background (MATE_PANEL_APPLET (applet), &color, &pattern); +#else bg_type = mate_panel_applet_get_background (MATE_PANEL_APPLET (applet), &color, &background); +#endif if (bg_type == PANEL_PIXMAP_BACKGROUND) { /* fill with given background pixmap */ +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_set_source (cr, pattern); + cairo_rectangle (cr, 0, 0, w, h); + cairo_fill (cr); +#else gdk_draw_drawable (gtk_widget_get_window (GTK_WIDGET(applet)), gc, background, 0, 0, 0, 0, w, h); +#endif } /* draw color background */ if (bg_type == PANEL_COLOR_BACKGROUND) { +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); + cairo_rectangle (cr, 0, 0, w, h); + cairo_fill (cr); +#else gdk_gc_set_rgb_fg_color (gc,&color); gdk_gc_set_fill (gc,GDK_SOLID); gdk_draw_rectangle (gtk_widget_get_window (GTK_WIDGET(applet)), gc, TRUE, 0, 0, w, h); +#endif } /* draw icon at center */ +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_pixbuf (cr, applet->icon, (w - applet->icon_width)/2, (h - applet->icon_height)/2); + cairo_paint (cr); +#else gdk_draw_pixbuf (gtk_widget_get_window (GTK_WIDGET(applet)), gc, applet->icon, 0, 0, (w - applet->icon_width)/2, (h - applet->icon_height)/2, applet->icon_width, applet->icon_height, GDK_RGB_DITHER_NONE, 0, 0); +#endif + +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_destroy (cr); +#else + g_object_unref (gc); +#endif return TRUE; } @@ -344,7 +388,12 @@ gpm_applet_draw_cb (GpmInhibitApplet *applet) static void gpm_applet_change_background_cb (GpmInhibitApplet *applet, MatePanelAppletBackgroundType arg1, - GdkColor *arg2, GdkPixmap *arg3, gpointer data) +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_pattern_t *arg2, +#else + GdkColor *arg2, GdkPixmap *arg3, +#endif + gpointer data) { gtk_widget_queue_draw (GTK_WIDGET (applet)); } |