73
73
#define DC_POWER_STRING _("System is running on battery power")
75
75
/* The icons for Battery, Critical, AC and Charging */
76
static GdkPixmap *statusimage[STATUS_PIXMAP_NUM];
77
static GdkBitmap *statusmask[STATUS_PIXMAP_NUM];
76
static GdkPixbuf *statusimage[STATUS_PIXMAP_NUM];
79
78
/* Assuming a horizontal battery, the colour is drawn into it one horizontal
80
79
line at a time as a vertical gradient. The following arrays decide where
219
218
initialise_global_pixmaps( void )
221
GdkDrawable *defaults;
223
defaults = gdk_screen_get_root_window( gdk_screen_get_default() );
225
220
statusimage[STATUS_PIXMAP_BATTERY] =
226
gdk_pixmap_create_from_xpm_d( defaults, &statusmask[STATUS_PIXMAP_BATTERY],
227
NULL, battery_small_xpm );
221
gdk_pixbuf_new_from_xpm_data ((const char **) battery_small_xpm);
229
223
statusimage[STATUS_PIXMAP_METER] =
230
gdk_pixmap_create_from_xpm_d( defaults, &statusmask[STATUS_PIXMAP_METER],
231
NULL, battery_small_meter_xpm );
224
gdk_pixbuf_new_from_xpm_data ((const char **) battery_small_meter_xpm);
233
226
statusimage[STATUS_PIXMAP_AC] =
234
gdk_pixmap_create_from_xpm_d( defaults, &statusmask[STATUS_PIXMAP_AC],
235
NULL, ac_small_xpm );
227
gdk_pixbuf_new_from_xpm_data ((const char **) ac_small_xpm);
237
229
statusimage[STATUS_PIXMAP_CHARGE] =
238
gdk_pixmap_create_from_xpm_d( defaults, &statusmask[STATUS_PIXMAP_CHARGE],
239
NULL, charge_small_xpm );
230
gdk_pixbuf_new_from_xpm_data ((const char **) charge_small_xpm);
241
232
statusimage[STATUS_PIXMAP_WARNING] =
242
gdk_pixmap_create_from_xpm_d( defaults, &statusmask[STATUS_PIXMAP_WARNING],
243
NULL, warning_small_xpm );
246
/* For non-truecolour displays, each GdkColor has to have a palette entry
247
allocated for it. This should only be done once for the entire display.
250
allocate_battery_colours( void )
252
GdkColormap *colourmap;
255
colourmap = gdk_colormap_get_system();
257
/* assumed: all the colour arrays have the same number of elements */
258
for( i = 0; i < G_N_ELEMENTS( orange ); i++ )
260
gdk_colormap_alloc_color( colourmap, &darkorange[i], FALSE, TRUE );
261
gdk_colormap_alloc_color( colourmap, &darkyellow[i], FALSE, TRUE );
262
gdk_colormap_alloc_color( colourmap, &darkred[i], FALSE, TRUE );
263
gdk_colormap_alloc_color( colourmap, &darkgreen[i], FALSE, TRUE );
264
gdk_colormap_alloc_color( colourmap, &orange[i], FALSE, TRUE );
265
gdk_colormap_alloc_color( colourmap, &yellow[i], FALSE, TRUE );
266
gdk_colormap_alloc_color( colourmap, &red[i], FALSE, TRUE );
267
gdk_colormap_alloc_color( colourmap, &green[i], FALSE, TRUE );
233
gdk_pixbuf_new_from_xpm_data ((const char **) warning_small_xpm);
271
236
/* Our backends may be either event driven or poll-based.
352
316
gtk_window_set_screen( GTK_WINDOW (dialog),
353
317
gtk_widget_get_screen (GTK_WIDGET (applet)) );
355
g_signal_connect_swapped( GTK_OBJECT (dialog), "response",
319
g_signal_connect_swapped( G_OBJECT (dialog), "response",
356
320
G_CALLBACK (gtk_widget_destroy),
357
GTK_OBJECT (dialog) );
359
323
gtk_widget_show_all( dialog );
435
399
GTK_ICON_LOOKUP_USE_BUILTIN,
438
NotifyNotification *n = notify_notification_new (_("Your battery is now fully recharged"), "", /* "battery" */ NULL, applet);
402
NotifyNotification *n = notify_notification_new (_("Your battery is now fully recharged"), "", /* "battery" */ NULL);
440
404
/* XXX: it would be nice to pass this as a named icon */
441
405
notify_notification_set_icon_from_pixbuf (n, icon);
478
442
GTK_RESPONSE_ACCEPT,
480
g_signal_connect_swapped (GTK_OBJECT (dialog), "response",
444
g_signal_connect_swapped (G_OBJECT (dialog), "response",
481
445
G_CALLBACK (gtk_widget_destroy),
482
GTK_OBJECT (dialog));
484
448
gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
485
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
486
449
hbox = gtk_hbox_new (FALSE, 6);
487
450
pixbuf = gtk_icon_theme_load_icon (
488
451
gtk_icon_theme_get_default (),
636
599
gtk_dialog_set_default_response( GTK_DIALOG (battery->battery_low_dialog),
637
600
GTK_RESPONSE_ACCEPT );
639
g_signal_connect_swapped( GTK_OBJECT (battery->battery_low_dialog),
602
g_signal_connect_swapped( G_OBJECT (battery->battery_low_dialog),
641
604
G_CALLBACK (battery_low_dialog_destroy),
644
607
gtk_container_set_border_width (GTK_CONTAINER (battery->battery_low_dialog),
646
gtk_dialog_set_has_separator (GTK_DIALOG (battery->battery_low_dialog),
648
609
hbox = gtk_hbox_new (FALSE, 6);
649
610
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
650
611
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
713
674
g_free (tiptext);
678
pixbuf_draw_line( GdkPixbuf *pixbuf, GdkColor *colour, int x1, int y1, int x2, int y2)
680
guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
681
int stride = gdk_pixbuf_get_rowstride (pixbuf);
682
int channels = gdk_pixbuf_get_n_channels (pixbuf);
686
r = colour->red >> 8;
687
g = colour->green >> 8;
688
b = colour->blue >> 8;
691
pixels += stride * y1 + 4 * x1;
695
/* stride = gdk_pixbuf_get_rowstride (pixbuf); */
700
stride = gdk_pixbuf_get_n_channels (pixbuf);
704
g_assert_not_reached ();
706
for (i = 0; i < n; i++)
716
718
/* Redraw the battery meter image.
719
721
update_battery_image (ProgressData *battstat, int batt_percent, int batt_time)
721
723
GdkColor *color, *darkcolor;
724
725
guint progress_value;
751
752
darkcolor = darkgreen;
754
/* We keep this pixgc allocated so we don't have to alloc/free it every
755
time. A widget has to be realized before it has a valid ->window so
756
we do that here for battstat->applet just in case it's not already done.
758
if( battstat->pixgc == NULL )
760
gtk_widget_realize( battstat->applet );
761
battstat->pixgc = gdk_gc_new( gtk_widget_get_window (battstat->applet) );
764
755
/* Depending on if the meter is horizontally oriented start out with the
765
756
appropriate XPM image (from pixmaps.h)
767
758
if (battstat->horizont)
768
pixmap = gdk_pixmap_create_from_xpm_d( gtk_widget_get_window (battstat->applet), &pixmask,
769
NULL, battery_gray_xpm );
759
pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) battery_gray_xpm);
771
pixmap = gdk_pixmap_create_from_xpm_d( gtk_widget_get_window (battstat->applet), &pixmask,
772
NULL, battery_y_gray_xpm );
761
pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) battery_y_gray_xpm);
774
763
/* The core code responsible for painting the battery meter. For each
775
764
colour in our gradient array, draw a vertical or horizontal line
781
770
for( i = 0; i < G_N_ELEMENTS( orange ); i++ )
783
gdk_gc_set_foreground (battstat->pixgc, &color[i]);
785
772
if (battstat->horizont)
786
gdk_draw_line (pixmap, battstat->pixgc, pixel_offset_top[i], i + 2,
773
pixbuf_draw_line (pixbuf, &color[i], pixel_offset_top[i], i + 2,
787
774
pixel_offset_top[i] + progress_value, i + 2);
789
gdk_draw_line (pixmap, battstat->pixgc, i + 2, pixel_offset_top[i],
776
pixbuf_draw_line (pixbuf, &color[i], i + 2, pixel_offset_top[i],
790
777
i + 2, pixel_offset_top[i] + progress_value);
797
784
for( i = 0; i < G_N_ELEMENTS( orange ); i++)
799
gdk_gc_set_foreground (battstat->pixgc, &color[i]);
801
786
if (battstat->horizont)
802
gdk_draw_line (pixmap, battstat->pixgc, pixel_offset_bottom[i], i + 2,
803
pixel_offset_bottom[i] - progress_value, i + 2);
787
pixbuf_draw_line (pixbuf, &color[i], pixel_offset_bottom[i], i + 2,
788
pixel_offset_bottom[i] - progress_value, i + 2);
805
gdk_draw_line (pixmap, battstat->pixgc, i + 2,
806
pixel_offset_bottom[i] - 1, i + 2,
807
pixel_offset_bottom[i] - progress_value);
790
pixbuf_draw_line (pixbuf, &color[i], i + 2,
791
pixel_offset_bottom[i] - 1, i + 2,
792
pixel_offset_bottom[i] - progress_value);
810
795
for( i = 0; i < G_N_ELEMENTS( orange ); i++ )
816
801
if (progress_value < 33)
818
gdk_gc_set_foreground (battstat->pixgc, &darkcolor[i]);
820
803
if (battstat->horizont)
821
gdk_draw_line (pixmap, battstat->pixgc,
822
pixel_offset_bottom[i] - progress_value - 1,
804
pixbuf_draw_line (pixbuf, &darkcolor[i],
805
pixel_offset_bottom[i] - progress_value - 1,
825
gdk_draw_line (pixmap, battstat->pixgc, i + 2,
826
pixel_offset_bottom[i] - progress_value - 1,
808
pixbuf_draw_line (pixbuf, &darkcolor[i], i + 2,
809
pixel_offset_bottom[i] - progress_value - 1,
832
815
/* Store our newly created pixmap into the GtkImage. This results in
833
816
the last reference to the old pixmap/mask being dropped.
835
gtk_image_set_from_pixmap( GTK_IMAGE(battstat->battery),
818
gtk_image_set_from_pixbuf( GTK_IMAGE(battstat->battery),
838
821
/* The GtkImage does not assume a reference to the pixmap or mask;
839
822
you still need to unref them if you own references. GtkImage will
840
823
add its own reference rather than adopting yours.
842
g_object_unref( G_OBJECT(pixmap) );
843
g_object_unref( G_OBJECT(pixmask) );
825
g_object_unref( G_OBJECT(pixbuf) );
846
828
/* Update the text label that either shows the percentage of time left.
871
853
g_free (new_label);
874
/* Utility function to create a copy of a GdkPixmap */
876
copy_gdk_pixmap( GdkPixmap *src, GdkGC *gc )
881
gdk_drawable_get_size( GDK_DRAWABLE( src ), &width, &height );
883
dest = gdk_pixmap_new( GDK_DRAWABLE( src ), width, height, -1 );
885
gdk_draw_drawable( GDK_DRAWABLE( dest ), gc, GDK_DRAWABLE( src ),
886
0, 0, 0, 0, width, height );
891
856
/* Determine what status icon we ought to be displaying and change the
892
857
status icon to display it if it is different from what we are currently
933
898
battstat->last_pixmap_index != STATUS_PIXMAP_METER) )
935
900
GdkColor *colour;
937
902
guint progress_value;
940
/* We keep this pixgc allocated so we don't have to alloc/free it every
941
time. A widget has to be realized before it has a valid ->window so
942
we do that here for battstat->applet just in case it's not already done.
944
if( battstat->pixgc == NULL )
946
gtk_widget_realize( battstat->applet );
947
battstat->pixgc = gdk_gc_new( gtk_widget_get_window (battstat->applet) );
950
905
/* Pull in a clean version of the icons so that we don't paint over
951
top of the same icon over and over. We neglect to free/update the
952
statusmask here since it will always stay the same.
906
top of the same icon over and over.
954
meter = copy_gdk_pixmap( statusimage[STATUS_PIXMAP_METER],
908
meter = gdk_pixbuf_copy ( statusimage[STATUS_PIXMAP_METER]);
957
910
if (batt_life <= battstat->red_val)
976
929
for( i = 0; i < 10; i++ )
978
gdk_gc_set_foreground( battstat->pixgc, &colour[(i * 13 / 10)] );
980
931
if( i >= 2 && i <= 7 )
985
gdk_draw_line( meter, battstat->pixgc,
986
i + 1, x - progress_value,
936
pixbuf_draw_line( meter, &colour[(i * 13 / 10)],
937
i + 1, x - progress_value,
990
941
/* force a redraw immediately */
991
gtk_image_set_from_pixmap( GTK_IMAGE (battstat->status),
992
meter, statusmask[STATUS_PIXMAP_METER] );
942
gtk_image_set_from_pixbuf( GTK_IMAGE (battstat->status),
994
945
/* free our private pixmap copy */
995
946
g_object_unref( G_OBJECT( meter ) );
998
949
else if( pixmap_index != battstat->last_pixmap_index )
1000
gtk_image_set_from_pixmap (GTK_IMAGE (battstat->status),
1001
statusimage[pixmap_index],
1002
statusmask[pixmap_index]);
951
gtk_image_set_from_pixbuf (GTK_IMAGE (battstat->status),
952
statusimage[pixmap_index]);
1003
953
battstat->last_pixmap_index = pixmap_index;
1573
1520
g_object_ref( battstat->status );
1574
1521
g_object_ref( battstat->percent );
1575
1522
g_object_ref( battstat->battery );
1576
g_object_ref_sink( GTK_OBJECT( battstat->status ) );
1577
g_object_ref_sink( GTK_OBJECT( battstat->percent ) );
1578
g_object_ref_sink( GTK_OBJECT( battstat->battery ) );
1523
g_object_ref_sink( G_OBJECT( battstat->status ) );
1524
g_object_ref_sink( G_OBJECT( battstat->percent ) );
1525
g_object_ref_sink( G_OBJECT( battstat->battery ) );
1580
1527
/* Let reconfigure_layout know that the table is currently empty. */
1581
1528
battstat->layout.status = LAYOUT_NONE;