summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey V. Udaltsov <svu@gnome.org>2009-12-20 23:13:16 +0000
committerSergey V. Udaltsov <svu@gnome.org>2009-12-20 23:13:16 +0000
commitbec935f1fd73e62c64c35d533e14db3d1c0156ac (patch)
treed1951a820537212beea29f45e06768bbc6891265
parent3584dc898c8212f154cd9ae22185c5d8aa7b4218 (diff)
downloadlibgnomekbd-bec935f1fd73e62c64c35d533e14db3d1c0156ac.tar.gz
First implementation of label in the status icon
-rw-r--r--ChangeLog5
-rw-r--r--libgnomekbd/gkbd-status.c179
2 files changed, 148 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 434aeab..76d32b7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-12-20 svu
+
+ * libgnomekbd/gkbd-status.c: initial implementation of "labels" in
+ status icon
+
2009-12-14 svu
* configure.in, NEWS: release 2.28.2
diff --git a/libgnomekbd/gkbd-status.c b/libgnomekbd/gkbd-status.c
index 7e70088..0e95881 100644
--- a/libgnomekbd/gkbd-status.c
+++ b/libgnomekbd/gkbd-status.c
@@ -120,6 +120,67 @@ gkbd_status_activate (GkbdStatus * gki)
gkbd_desktop_config_lock_next_group (&globals.cfg);
}
+static void
+gkbd_status_render_cairo (cairo_t * cr, int group)
+{
+ cairo_text_extents_t te;
+ gchar *lbl = globals.short_group_names[group];
+
+ cairo_set_source_rgba (cr, 0, 1 - group, group, 1);
+ cairo_rectangle (cr, globals.current_size >> 2,
+ globals.current_size >> 2,
+ globals.current_size >> 1,
+ globals.current_size >> 1);
+ cairo_fill (cr);
+
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+/*cairo_select_font_face (cr, "Georgia",
+ CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+cairo_set_font_size (cr, 10);*/
+ cairo_text_extents (cr, lbl, &te);
+ cairo_move_to (cr,
+ (globals.current_size >> 1) - te.width / 2 -
+ te.x_bearing,
+ (globals.current_size >> 1) - te.height / 2 -
+ te.y_bearing);
+ cairo_show_text (cr, lbl);
+
+ cairo_destroy (cr);
+}
+
+static inline guint8
+convert_color_channel (guint8 src, guint8 alpha)
+{
+ return alpha ? ((((guint) src) << 8) - src) / alpha : 0;
+}
+
+static void
+convert_bgra_to_rgba (guint8 const *src,
+ guint8 * dst, int width, int height)
+{
+ guint8 const *src_pixel = src;
+ guint8 *dst_pixel = dst;
+ int x, y;
+
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ dst_pixel[0] = convert_color_channel (src_pixel[2],
+ src_pixel
+ [3]);
+ dst_pixel[1] =
+ convert_color_channel (src_pixel[1],
+ src_pixel[3]);
+ dst_pixel[2] =
+ convert_color_channel (src_pixel[0],
+ src_pixel[3]);
+ dst_pixel[3] = src_pixel[3];
+
+ dst_pixel += 4;
+ src_pixel += 4;
+ }
+ }
+}
+
static GdkPixbuf *
gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
{
@@ -130,43 +191,89 @@ gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
if (globals.current_size == 0)
return NULL;
- image_filename = (char *) g_slist_nth_data (globals.ind_cfg.image_filenames,
- group);
-
- image = gdk_pixbuf_new_from_file_at_size (image_filename,
- globals.current_size,
- globals.current_size,
- &gerror);
-
- if (image == NULL) {
- GtkWidget *dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _
- ("There was an error loading an image: %s"),
- gerror ==
- NULL ?
- "Unknown" :
- gerror->
- message);
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (gtk_widget_destroy), NULL);
-
- gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-
- gtk_widget_show (dialog);
- g_error_free (gerror);
-
- return NULL;
+ if (globals.ind_cfg.show_flags) {
+
+ image_filename =
+ (char *) g_slist_nth_data (globals.ind_cfg.
+ image_filenames, group);
+
+ image = gdk_pixbuf_new_from_file_at_size (image_filename,
+ globals.
+ current_size,
+ globals.
+ current_size,
+ &gerror);
+
+ if (image == NULL) {
+ GtkWidget *dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _
+ ("There was an error loading an image: %s"),
+ gerror
+ ==
+ NULL ?
+ "Unknown"
+ :
+ gerror->message);
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
+
+ gtk_window_set_resizable (GTK_WINDOW (dialog),
+ FALSE);
+
+ gtk_widget_show (dialog);
+ g_error_free (gerror);
+
+ return NULL;
+ }
+ xkl_debug (150,
+ "Image %d[%s] loaded -> %p[%dx%d], alpha: %d\n",
+ group, image_filename, image,
+ gdk_pixbuf_get_width (image),
+ gdk_pixbuf_get_height (image),
+ gdk_pixbuf_get_has_alpha (image));
+
+ return image;
+ } else {
+ cairo_surface_t *cs =
+ cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ globals.current_size,
+ globals.current_size);
+ unsigned char *cairo_data;
+ guchar *pixbuf_data;
+ gkbd_status_render_cairo (cairo_create (cs), group);
+ cairo_data = cairo_image_surface_get_data (cs);
+ pixbuf_data =
+ g_new0 (guchar,
+ 4 * globals.current_size *
+ globals.current_size);
+ convert_bgra_to_rgba (cairo_data, pixbuf_data,
+ globals.current_size,
+ globals.current_size);
+
+ cairo_surface_destroy (cs);
+
+ image = gdk_pixbuf_new_from_data (pixbuf_data,
+ GDK_COLORSPACE_RGB,
+ TRUE,
+ 8,
+ globals.current_size,
+ globals.current_size,
+ globals.current_size * 4,
+ (GdkPixbufDestroyNotify)
+ g_free, NULL);
+ xkl_debug (150,
+ "Image %d created -> %p[%dx%d], alpha: %d\n",
+ group, image, gdk_pixbuf_get_width (image),
+ gdk_pixbuf_get_height (image),
+ gdk_pixbuf_get_has_alpha (image));
+
+ return image;
}
- xkl_debug (150,
- "Image %d[%s] loaded -> %p[%dx%d]\n",
- group, image_filename, image,
- gdk_pixbuf_get_width (image),
- gdk_pixbuf_get_height (image));
-
- return image;
+ return NULL;
}
static void