aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-04-05 12:01:48 -0400
committerWilliam Hua <william.hua@canonical.com>2013-04-05 12:01:48 -0400
commit125fbd0aefd1c636fcc1c4af4740d83416181893 (patch)
treefea68d3928e832355b6a0ad55adbe1a8a83dc8f1 /lib
parent0aa2d2eba11ba136ec220a550a28ac77e06aa240 (diff)
downloadayatana-indicator-keyboard-125fbd0aefd1c636fcc1c4af4740d83416181893.tar.gz
ayatana-indicator-keyboard-125fbd0aefd1c636fcc1c4af4740d83416181893.tar.bz2
ayatana-indicator-keyboard-125fbd0aefd1c636fcc1c4af4740d83416181893.zip
Generate icons.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am9
-rw-r--r--lib/main.vala57
2 files changed, 64 insertions, 2 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index d716aaa2..17e8f2dc 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,3 +1,4 @@
+AM_LDFLAGS = -lm
AM_VALAFLAGS = --metadatadir $(top_srcdir)/deps \
--vapidir $(top_srcdir)/deps
@@ -5,16 +6,20 @@ libexec_PROGRAMS = indicator-keyboard-service
indicator_keyboard_service_SOURCES = main.vala
indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \
+ --pkg posix \
+ --pkg pangocairo \
--pkg gtk+-3.0 \
- --pkg ibus-1.0 \
+ --pkg Xkl-1.0 \
--pkg libgnomekbd \
- --pkg Xkl-1.0
+ --pkg ibus-1.0
indicator_keyboard_service_CFLAGS = $(GTK_CFLAGS) \
+ $(PANGOCAIRO_CFLAGS) \
$(LIBXKLAVIER_CFLAGS) \
$(LIBGNOMEKBD_CFLAGS) \
$(IBUS_CFLAGS) \
$(AM_CFLAGS)
indicator_keyboard_service_LDFLAGS = $(GTK_LIBS) \
+ $(PANGOCAIRO_LIBS) \
$(LIBXKLAVIER_LIBS) \
$(LIBGNOMEKBD_LIBS) \
$(IBUS_LIBS) \
diff --git a/lib/main.vala b/lib/main.vala
index 0990b95c..23e4b861 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -23,6 +23,49 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
+ private Gtk.StyleContext get_style_context () {
+ var context = new Gtk.StyleContext ();
+
+ context.set_screen (Gdk.Screen.get_default ());
+
+ var path = new Gtk.WidgetPath ();
+ path.append_type (typeof (Gtk.MenuItem));
+ context.set_path (path);
+
+ return context;
+ }
+
+ [DBus (visible = false)]
+ protected virtual Icon create_icon (string text) {
+ Pango.FontDescription description;
+ var style = get_style_context ();
+ var colour = style.get_color (Gtk.StateFlags.NORMAL);
+ style.get (Gtk.StateFlags.NORMAL, Gtk.STYLE_PROPERTY_FONT, out description);
+
+ var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 20, 20);
+ var context = new Cairo.Context (surface);
+
+ context.set_source_rgba (colour.red, colour.green, colour.blue, colour.alpha);
+ context.set_source_rgba (1.0, 0.0, 0.0, 1.0);
+ context.paint ();
+
+ context.set_operator (Cairo.Operator.CLEAR);
+ var layout = Pango.cairo_create_layout (context);
+ layout.set_alignment (Pango.Alignment.CENTER);
+ layout.set_font_description (description);
+ layout.set_text (text, -1);
+ Pango.cairo_update_layout (context, layout);
+ int width;
+ int height;
+ layout.get_pixel_size (out width, out height);
+ context.translate (Posix.floor (10.0 - 0.5 * width), Posix.floor (10.0 - 0.5 * height));
+ Pango.cairo_layout_path (context, layout);
+ context.fill ();
+
+ return Gdk.pixbuf_get_from_surface (surface, 0, 0, 20, 20);
+ }
+
+ [DBus (visible = false)]
private void handle_activate_map (Variant? parameter) {
try {
Process.spawn_command_line_async ("gucharmap");
@@ -63,6 +106,15 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
+ private void handle_activate_foo (Variant? parameter) {
+ var window = new Gtk.Window ();
+
+ window.add (new Gtk.Image.from_gicon (create_icon ("US"), Gtk.IconSize.INVALID));
+
+ window.show_all ();
+ }
+
+ [DBus (visible = false)]
private IBus.Bus get_ibus () {
if (this.ibus == null) {
IBus.init ();
@@ -95,6 +147,10 @@ public class Indicator.Keyboard.Service : Object {
action.activate.connect (this.handle_activate_settings);
group.insert (action);
+ action = new SimpleAction ("foo", null);
+ action.activate.connect (this.handle_activate_foo);
+ group.insert (action);
+
return group;
}
@@ -154,6 +210,7 @@ public class Indicator.Keyboard.Service : Object {
section.append ("Character Map", "indicator.map");
section.append ("Keyboard Layout Chart", "indicator.chart");
section.append ("Text Entry Settings...", "indicator.settings");
+ section.append ("foo", "indicator.foo");
submenu.append_section (null, section);
var indicator = new MenuItem.submenu ("x", submenu);