summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--battstat/battstat-upower.c6
-rw-r--r--battstat/battstat.h2
-rw-r--r--battstat/battstat_applet.c183
-rw-r--r--battstat/properties.c2
4 files changed, 193 insertions, 0 deletions
diff --git a/battstat/battstat-upower.c b/battstat/battstat-upower.c
index f42de3fd..b0838176 100644
--- a/battstat/battstat-upower.c
+++ b/battstat/battstat-upower.c
@@ -325,9 +325,15 @@ error_dialog( const char *fmt , ...)
dialog = gtk_message_dialog_new( NULL, 0, GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK, "%s", str);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_signal_connect_swapped( G_OBJECT (dialog), "response",
+ G_CALLBACK (gtk_widget_destroy),
+ G_OBJECT (dialog) );
+#else
g_signal_connect_swapped( GTK_OBJECT (dialog), "response",
G_CALLBACK (gtk_widget_destroy),
GTK_OBJECT (dialog) );
+#endif
gtk_widget_show_all( dialog );
}
diff --git a/battstat/battstat.h b/battstat/battstat.h
index a48dd121..16fb84b0 100644
--- a/battstat/battstat.h
+++ b/battstat/battstat.h
@@ -114,8 +114,10 @@ typedef struct _ProgressData {
/* label changed type (% <-> h:mm) and must be refreshed */
gboolean refresh_label;
+#if !GTK_CHECK_VERSION (3, 0, 0)
/* so we don't have to alloc/dealloc this every refresh */
GdkGC *pixgc;
+#endif
/* the main table that contains the visual elements */
GtkWidget *table;
diff --git a/battstat/battstat_applet.c b/battstat/battstat_applet.c
index 6a452433..52cc9f3c 100644
--- a/battstat/battstat_applet.c
+++ b/battstat/battstat_applet.c
@@ -73,8 +73,12 @@ static const GtkActionEntry battstat_menu_actions [] = {
#define DC_POWER_STRING _("System is running on battery power")
/* The icons for Battery, Critical, AC and Charging */
+#if GTK_CHECK_VERSION (3, 0, 0)
+static GdkPixbuf *statusimage[STATUS_PIXMAP_NUM];
+#else
static GdkPixmap *statusimage[STATUS_PIXMAP_NUM];
static GdkBitmap *statusmask[STATUS_PIXMAP_NUM];
+#endif
/* Assuming a horizontal battery, the colour is drawn into it one horizontal
line at a time as a vertical gradient. The following arrays decide where
@@ -218,31 +222,54 @@ static GdkColor darkred[] = {
static void
initialise_global_pixmaps( void )
{
+#if !GTK_CHECK_VERSION (3, 0, 0)
GdkDrawable *defaults;
defaults = gdk_screen_get_root_window( gdk_screen_get_default() );
+#endif
statusimage[STATUS_PIXMAP_BATTERY] =
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gdk_pixbuf_new_from_xpm_data ((const char **) battery_small_xpm);
+#else
gdk_pixmap_create_from_xpm_d( defaults, &statusmask[STATUS_PIXMAP_BATTERY],
NULL, battery_small_xpm );
+#endif
statusimage[STATUS_PIXMAP_METER] =
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gdk_pixbuf_new_from_xpm_data ((const char **) battery_small_meter_xpm);
+#else
gdk_pixmap_create_from_xpm_d( defaults, &statusmask[STATUS_PIXMAP_METER],
NULL, battery_small_meter_xpm );
+#endif
statusimage[STATUS_PIXMAP_AC] =
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gdk_pixbuf_new_from_xpm_data ((const char **) ac_small_xpm);
+#else
gdk_pixmap_create_from_xpm_d( defaults, &statusmask[STATUS_PIXMAP_AC],
NULL, ac_small_xpm );
+#endif
statusimage[STATUS_PIXMAP_CHARGE] =
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gdk_pixbuf_new_from_xpm_data ((const char **) charge_small_xpm);
+#else
gdk_pixmap_create_from_xpm_d( defaults, &statusmask[STATUS_PIXMAP_CHARGE],
NULL, charge_small_xpm );
+#endif
statusimage[STATUS_PIXMAP_WARNING] =
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gdk_pixbuf_new_from_xpm_data ((const char **) warning_small_xpm);
+#else
gdk_pixmap_create_from_xpm_d( defaults, &statusmask[STATUS_PIXMAP_WARNING],
NULL, warning_small_xpm );
+#endif
}
+#if !GTK_CHECK_VERSION (3, 0, 0)
/* For non-truecolour displays, each GdkColor has to have a palette entry
allocated for it. This should only be done once for the entire display.
*/
@@ -267,6 +294,7 @@ allocate_battery_colours( void )
gdk_colormap_alloc_color( colourmap, &green[i], FALSE, TRUE );
}
}
+#endif
/* Our backends may be either event driven or poll-based.
* If they are event driven then we know this the first time we
@@ -318,7 +346,9 @@ static_global_initialisation (int no_hal, ProgressData *battstat)
if (!first_time)
return NULL;
+#if !GTK_CHECK_VERSION (3, 0, 0)
allocate_battery_colours();
+#endif
initialise_global_pixmaps();
err = power_management_initialise (no_hal, status_change_callback);
@@ -352,9 +382,15 @@ battstat_error_dialog( GtkWidget *applet, const char *msg )
gtk_window_set_screen( GTK_WINDOW (dialog),
gtk_widget_get_screen (GTK_WIDGET (applet)) );
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_signal_connect_swapped( G_OBJECT (dialog), "response",
+ G_CALLBACK (gtk_widget_destroy),
+ G_OBJECT (dialog) );
+#else
g_signal_connect_swapped( GTK_OBJECT (dialog), "response",
G_CALLBACK (gtk_widget_destroy),
GTK_OBJECT (dialog) );
+#endif
gtk_widget_show_all( dialog );
}
@@ -477,12 +513,20 @@ battery_full_dialog (GtkWidget *applet)
GTK_STOCK_OK,
GTK_RESPONSE_ACCEPT,
NULL);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_signal_connect_swapped (G_OBJECT (dialog), "response",
+ G_CALLBACK (gtk_widget_destroy),
+ G_OBJECT (dialog));
+#else
g_signal_connect_swapped (GTK_OBJECT (dialog), "response",
G_CALLBACK (gtk_widget_destroy),
GTK_OBJECT (dialog));
+#endif
gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
+#if !GTK_CHECK_VERSION (3, 0, 0)
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+#endif
hbox = gtk_hbox_new (FALSE, 6);
pixbuf = gtk_icon_theme_load_icon (
gtk_icon_theme_get_default (),
@@ -636,15 +680,21 @@ battery_low_dialog( ProgressData *battery, BatteryStatus *info )
gtk_dialog_set_default_response( GTK_DIALOG (battery->battery_low_dialog),
GTK_RESPONSE_ACCEPT );
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_signal_connect_swapped( G_OBJECT (battery->battery_low_dialog),
+#else
g_signal_connect_swapped( GTK_OBJECT (battery->battery_low_dialog),
+#endif
"response",
G_CALLBACK (battery_low_dialog_destroy),
battery );
gtk_container_set_border_width (GTK_CONTAINER (battery->battery_low_dialog),
6);
+#if !GTK_CHECK_VERSION (3, 0, 0)
gtk_dialog_set_has_separator (GTK_DIALOG (battery->battery_low_dialog),
FALSE);
+#endif
hbox = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
@@ -713,14 +763,61 @@ update_tooltip( ProgressData *battstat, BatteryStatus *info )
g_free (tiptext);
}
+#if GTK_CHECK_VERSION (3, 0, 0)
+static void
+pixbuf_draw_line( GdkPixbuf *pixbuf, GdkColor *colour, int x1, int y1, int x2, int y2)
+{
+ guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
+ int stride = gdk_pixbuf_get_rowstride (pixbuf);
+ int channels = gdk_pixbuf_get_n_channels (pixbuf);
+ guchar r, g, b, a;
+ int i, n;
+
+ r = colour->red >> 8;
+ g = colour->green >> 8;
+ b = colour->blue >> 8;
+ a = 0xFF;
+
+ pixels += stride * y1 + 4 * x1;
+
+ if (x1 == x2)
+ {
+ /* stride = gdk_pixbuf_get_rowstride (pixbuf); */
+ n = y2 - y1;
+ }
+ else if (y1 == y2)
+ {
+ stride = gdk_pixbuf_get_n_channels (pixbuf);
+ n = x2 - x1;
+ }
+ else
+ g_assert_not_reached ();
+
+ for (i = 0; i < n; i++)
+ {
+ pixels[0] = r;
+ pixels[1] = g;
+ pixels[2] = b;
+ if (channels == 4)
+ pixels[3] = a;
+
+ pixels += stride;
+ }
+}
+#endif
+
/* Redraw the battery meter image.
*/
static void
update_battery_image (ProgressData *battstat, int batt_percent, int batt_time)
{
GdkColor *color, *darkcolor;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkPixbuf *pixbuf;
+#else
GdkPixmap *pixmap;
GdkBitmap *pixmask;
+#endif
guint progress_value;
gint i, x;
int batt_life;
@@ -751,6 +848,7 @@ update_battery_image (ProgressData *battstat, int batt_percent, int batt_time)
darkcolor = darkgreen;
}
+#if !GTK_CHECK_VERSION (3, 0, 0)
/* We keep this pixgc allocated so we don't have to alloc/free it every
time. A widget has to be realized before it has a valid ->window so
we do that here for battstat->applet just in case it's not already done.
@@ -760,16 +858,25 @@ update_battery_image (ProgressData *battstat, int batt_percent, int batt_time)
gtk_widget_realize( battstat->applet );
battstat->pixgc = gdk_gc_new( gtk_widget_get_window (battstat->applet) );
}
+#endif
/* Depending on if the meter is horizontally oriented start out with the
appropriate XPM image (from pixmaps.h)
*/
if (battstat->horizont)
+#if GTK_CHECK_VERSION (3, 0, 0)
+ pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) battery_gray_xpm);
+#else
pixmap = gdk_pixmap_create_from_xpm_d( gtk_widget_get_window (battstat->applet), &pixmask,
NULL, battery_gray_xpm );
+#endif
else
+#if GTK_CHECK_VERSION (3, 0, 0)
+ pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) battery_y_gray_xpm);
+#else
pixmap = gdk_pixmap_create_from_xpm_d( gtk_widget_get_window (battstat->applet), &pixmask,
NULL, battery_y_gray_xpm );
+#endif
/* The core code responsible for painting the battery meter. For each
colour in our gradient array, draw a vertical or horizontal line
@@ -780,13 +887,23 @@ update_battery_image (ProgressData *battstat, int batt_percent, int batt_time)
for( i = 0; i < G_N_ELEMENTS( orange ); i++ )
{
+#if !GTK_CHECK_VERSION (3, 0, 0)
gdk_gc_set_foreground (battstat->pixgc, &color[i]);
+#endif
if (battstat->horizont)
+#if GTK_CHECK_VERSION (3, 0, 0)
+ pixbuf_draw_line (pixbuf, &color[i], pixel_offset_top[i], i + 2,
+#else
gdk_draw_line (pixmap, battstat->pixgc, pixel_offset_top[i], i + 2,
+#endif
pixel_offset_top[i] + progress_value, i + 2);
else
+#if GTK_CHECK_VERSION (3, 0, 0)
+ pixbuf_draw_line (pixbuf, &color[i], i + 2, pixel_offset_top[i],
+#else
gdk_draw_line (pixmap, battstat->pixgc, i + 2, pixel_offset_top[i],
+#endif
i + 2, pixel_offset_top[i] + progress_value);
}
}
@@ -796,13 +913,23 @@ update_battery_image (ProgressData *battstat, int batt_percent, int batt_time)
for( i = 0; i < G_N_ELEMENTS( orange ); i++)
{
+#if !GTK_CHECK_VERSION (3, 0, 0)
gdk_gc_set_foreground (battstat->pixgc, &color[i]);
+#endif
if (battstat->horizont)
+#if GTK_CHECK_VERSION (3, 0, 0)
+ pixbuf_draw_line (pixbuf, &color[i], pixel_offset_bottom[i], i + 2,
+#else
gdk_draw_line (pixmap, battstat->pixgc, pixel_offset_bottom[i], i + 2,
+#endif
pixel_offset_bottom[i] - progress_value, i + 2);
else
+#if GTK_CHECK_VERSION (3, 0, 0)
+ pixbuf_draw_line (pixbuf, &color[i], i + 2,
+#else
gdk_draw_line (pixmap, battstat->pixgc, i + 2,
+#endif
pixel_offset_bottom[i] - 1, i + 2,
pixel_offset_bottom[i] - progress_value);
}
@@ -815,14 +942,24 @@ update_battery_image (ProgressData *battstat, int batt_percent, int batt_time)
if (progress_value < 33)
{
+#if !GTK_CHECK_VERSION (3, 0, 0)
gdk_gc_set_foreground (battstat->pixgc, &darkcolor[i]);
+#endif
if (battstat->horizont)
+#if GTK_CHECK_VERSION (3, 0, 0)
+ pixbuf_draw_line (pixbuf, &darkcolor[i],
+#else
gdk_draw_line (pixmap, battstat->pixgc,
+#endif
pixel_offset_bottom[i] - progress_value - 1,
i + 2, x, i + 2);
else
+#if GTK_CHECK_VERSION (3, 0, 0)
+ pixbuf_draw_line (pixbuf, &darkcolor[i], i + 2,
+#else
gdk_draw_line (pixmap, battstat->pixgc, i + 2,
+#endif
pixel_offset_bottom[i] - progress_value - 1,
i + 2, x);
}
@@ -832,15 +969,24 @@ update_battery_image (ProgressData *battstat, int batt_percent, int batt_time)
/* Store our newly created pixmap into the GtkImage. This results in
the last reference to the old pixmap/mask being dropped.
*/
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_image_set_from_pixbuf( GTK_IMAGE(battstat->battery),
+ pixbuf);
+#else
gtk_image_set_from_pixmap( GTK_IMAGE(battstat->battery),
pixmap, pixmask );
+#endif
/* The GtkImage does not assume a reference to the pixmap or mask;
you still need to unref them if you own references. GtkImage will
add its own reference rather than adopting yours.
*/
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_object_unref( G_OBJECT(pixbuf) );
+#else
g_object_unref( G_OBJECT(pixmap) );
g_object_unref( G_OBJECT(pixmask) );
+#endif
}
/* Update the text label that either shows the percentage of time left.
@@ -871,6 +1017,7 @@ update_percent_label( ProgressData *battstat, BatteryStatus *info )
g_free (new_label);
}
+#if !GTK_CHECK_VERSION (3, 0, 0)
/* Utility function to create a copy of a GdkPixmap */
static GdkPixmap *
copy_gdk_pixmap( GdkPixmap *src, GdkGC *gc )
@@ -892,6 +1039,7 @@ copy_gdk_pixmap( GdkPixmap *src, GdkGC *gc )
return dest;
}
+#endif
/* Determine what status icon we ought to be displaying and change the
status icon to display it if it is different from what we are currently
@@ -938,10 +1086,15 @@ possibly_update_status_icon( ProgressData *battstat, BatteryStatus *info )
battstat->last_pixmap_index != STATUS_PIXMAP_METER) )
{
GdkColor *colour;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkPixbuf *meter;
+#else
GdkPixmap *meter;
+#endif
guint progress_value;
gint i, x;
+#if !GTK_CHECK_VERSION (3, 0, 0)
/* We keep this pixgc allocated so we don't have to alloc/free it every
time. A widget has to be realized before it has a valid ->window so
we do that here for battstat->applet just in case it's not already done.
@@ -951,13 +1104,18 @@ possibly_update_status_icon( ProgressData *battstat, BatteryStatus *info )
gtk_widget_realize( battstat->applet );
battstat->pixgc = gdk_gc_new( gtk_widget_get_window (battstat->applet) );
}
+#endif
/* Pull in a clean version of the icons so that we don't paint over
top of the same icon over and over. We neglect to free/update the
statusmask here since it will always stay the same.
*/
+#if GTK_CHECK_VERSION (3, 0, 0)
+ meter = gdk_pixbuf_copy ( statusimage[STATUS_PIXMAP_METER]);
+#else
meter = copy_gdk_pixmap( statusimage[STATUS_PIXMAP_METER],
battstat->pixgc );
+#endif
if (batt_life <= battstat->red_val)
{
@@ -980,21 +1138,31 @@ possibly_update_status_icon( ProgressData *battstat, BatteryStatus *info )
for( i = 0; i < 10; i++ )
{
+#if !GTK_CHECK_VERSION (3, 0, 0)
gdk_gc_set_foreground( battstat->pixgc, &colour[(i * 13 / 10)] );
+#endif
if( i >= 2 && i <= 7 )
x = 17;
else
x = 16;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ pixbuf_draw_line( meter, &colour[(i * 13 / 10)],
+#else
gdk_draw_line( meter, battstat->pixgc,
+#endif
i + 1, x - progress_value,
i + 1, x );
}
/* force a redraw immediately */
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_image_set_from_pixbuf( GTK_IMAGE (battstat->status), meter);
+#else
gtk_image_set_from_pixmap( GTK_IMAGE (battstat->status),
meter, statusmask[STATUS_PIXMAP_METER] );
+#endif
/* free our private pixmap copy */
g_object_unref( G_OBJECT( meter ) );
@@ -1002,9 +1170,14 @@ possibly_update_status_icon( ProgressData *battstat, BatteryStatus *info )
}
else if( pixmap_index != battstat->last_pixmap_index )
{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_image_set_from_pixbuf (GTK_IMAGE (battstat->status),
+ statusimage[pixmap_index]);
+#else
gtk_image_set_from_pixmap (GTK_IMAGE (battstat->status),
statusimage[pixmap_index],
statusmask[pixmap_index]);
+#endif
battstat->last_pixmap_index = pixmap_index;
}
}
@@ -1168,8 +1341,10 @@ destroy_applet( GtkWidget *widget, ProgressData *battstat )
if (battstat->timeout_id)
g_source_remove (battstat->timeout_id);
+#if !GTK_CHECK_VERSION (3, 0, 0)
if( battstat->pixgc )
g_object_unref( G_OBJECT(battstat->pixgc) );
+#endif
g_object_unref( G_OBJECT(battstat->status) );
g_object_unref( G_OBJECT(battstat->percent) );
@@ -1579,9 +1754,15 @@ create_layout(ProgressData *battstat)
g_object_ref( battstat->status );
g_object_ref( battstat->percent );
g_object_ref( battstat->battery );
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_object_ref_sink( G_OBJECT( battstat->status ) );
+ g_object_ref_sink( G_OBJECT( battstat->percent ) );
+ g_object_ref_sink( G_OBJECT( battstat->battery ) );
+#else
g_object_ref_sink( GTK_OBJECT( battstat->status ) );
g_object_ref_sink( GTK_OBJECT( battstat->percent ) );
g_object_ref_sink( GTK_OBJECT( battstat->battery ) );
+#endif
/* Let reconfigure_layout know that the table is currently empty. */
battstat->layout.status = LAYOUT_NONE;
@@ -1645,7 +1826,9 @@ battstat_applet_fill (MatePanelApplet *applet)
battstat->horizont = TRUE;
battstat->battery_low_dialog = NULL;
battstat->battery_low_label = NULL;
+#if !GTK_CHECK_VERSION (3, 0, 0)
battstat->pixgc = NULL;
+#endif
battstat->timeout = -1;
battstat->timeout_id = 0;
diff --git a/battstat/properties.c b/battstat/properties.c
index 8242ccee..634290ce 100644
--- a/battstat/properties.c
+++ b/battstat/properties.c
@@ -411,7 +411,9 @@ prop_cb (GtkAction *action,
gtk_dialog_set_default_response (GTK_DIALOG (battstat->prop_win),
GTK_RESPONSE_CLOSE);
gtk_window_set_resizable (GTK_WINDOW (battstat->prop_win), FALSE);
+#if !GTK_CHECK_VERSION (3, 0, 0)
gtk_dialog_set_has_separator (GTK_DIALOG (battstat->prop_win), FALSE);
+#endif
g_signal_connect (G_OBJECT (battstat->prop_win), "response",
G_CALLBACK (response_cb), battstat);