aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac4
-rw-r--r--lib/Makefile.am9
-rw-r--r--lib/main.vala57
3 files changed, 68 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 1e2ad1e2..c0ffbb33 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,10 @@ PKG_CHECK_MODULES([GTK], [gtk+-3.0])
AC_SUBST([GTK_CFLAGS])
AC_SUBST([GTK_LIBS])
+PKG_CHECK_MODULES([PANGOCAIRO], [pangocairo])
+AC_SUBST([PANGOCAIRO_CFLAGS])
+AC_SUBST([PANGOCAIRO_LIBS])
+
PKG_CHECK_MODULES([LIBXKLAVIER], [libxklavier])
AC_SUBST([LIBXKLAVIER_CFLAGS])
AC_SUBST([LIBXKLAVIER_LIBS])
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);