aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-07-17 11:24:27 -0400
committerWilliam Hua <william.hua@canonical.com>2013-07-17 11:24:27 -0400
commit4d097b8eb4b6f527ec53b2faf778f0693cac0fa3 (patch)
tree36a751ba8274e5cfae7514266e48a0d9b2e243a9
parent6061e1de2a680b14b1a6e1eb2642d0a643910a73 (diff)
downloadayatana-indicator-keyboard-4d097b8eb4b6f527ec53b2faf778f0693cac0fa3.tar.gz
ayatana-indicator-keyboard-4d097b8eb4b6f527ec53b2faf778f0693cac0fa3.tar.bz2
ayatana-indicator-keyboard-4d097b8eb4b6f527ec53b2faf778f0693cac0fa3.zip
Add --use-gtk flag.
-rw-r--r--.pc/default-icon-colour.patch/lib/main.vala189
-rw-r--r--data/Makefile.am6
-rw-r--r--debian/patches/default-icon-colour.patch14
-rw-r--r--lib/main.vala191
-rw-r--r--po/indicator-keyboard.pot8
-rw-r--r--tests/indicator-keyboard-service.in2
6 files changed, 226 insertions, 184 deletions
diff --git a/.pc/default-icon-colour.patch/lib/main.vala b/.pc/default-icon-colour.patch/lib/main.vala
index 5461814b..56fc21e8 100644
--- a/.pc/default-icon-colour.patch/lib/main.vala
+++ b/.pc/default-icon-colour.patch/lib/main.vala
@@ -1,6 +1,7 @@
[DBus (name = "com.canonical.indicator.keyboard")]
public class Indicator.Keyboard.Service : Object {
+ private bool use_gtk;
private MainLoop? loop;
private Settings indicator_settings;
private Settings source_settings;
@@ -21,7 +22,7 @@ public class Indicator.Keyboard.Service : Object {
private uint[]? icon_string_subscripts;
[DBus (visible = false)]
- public Service (bool force) {
+ public Service (bool force, bool use_gtk) {
Bus.own_name (BusType.SESSION,
"com.canonical.indicator.keyboard",
BusNameOwnerFlags.ALLOW_REPLACEMENT | (force ? BusNameOwnerFlags.REPLACE : 0),
@@ -29,6 +30,8 @@ public class Indicator.Keyboard.Service : Object {
null,
this.handle_name_lost);
+ this.use_gtk = use_gtk;
+
this.indicator_settings = new Settings ("com.canonical.indicator.keyboard");
this.indicator_settings.changed["visible"].connect (this.handle_changed_visible);
@@ -158,99 +161,112 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
- private Gtk.StyleContext get_style_context () {
- var context = new Gtk.StyleContext ();
+ private Gtk.StyleContext? get_style_context () {
+ Gtk.StyleContext? context = null;
+ Gdk.Screen? screen = Gdk.Screen.get_default ();
- context.set_screen (Gdk.Screen.get_default ());
+ if (screen != null) {
+ context = new Gtk.StyleContext ();
+ ((!) context).set_screen ((!) screen);
- var path = new Gtk.WidgetPath ();
- path.append_type (typeof (Gtk.MenuItem));
- context.set_path (path);
+ 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, uint subscript) {
- const int W = 22;
- const int H = 22;
- const int w = 20;
- const int h = 20;
- const double R = 2.0;
- const double TEXT_SIZE = 12.0;
- const double SUBSCRIPT_SIZE = 8.0;
-
- 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, W, H);
- var context = new Cairo.Context (surface);
-
- context.translate (0.5 * (W - w), 0.5 * (H - h));
-
- context.new_sub_path ();
- context.arc (R, R, R, Math.PI, -0.5 * Math.PI);
- context.arc (w - R, R, R, -0.5 * Math.PI, 0);
- context.arc (w - R, h - R, R, 0, 0.5 * Math.PI);
- context.arc (R, h - R, R, 0.5 * Math.PI, Math.PI);
- context.close_path ();
-
- context.set_source_rgba (colour.red, colour.green, colour.blue, colour.alpha);
- context.fill ();
- context.set_operator (Cairo.Operator.CLEAR);
-
- if (text != null) {
- var text_layout = Pango.cairo_create_layout (context);
- text_layout.set_alignment (Pango.Alignment.CENTER);
- description.set_absolute_size (Pango.units_from_double (TEXT_SIZE));
- text_layout.set_font_description (description);
- text_layout.set_text ((!) text, -1);
- Pango.cairo_update_layout (context, text_layout);
- int text_width;
- int text_height;
- text_layout.get_pixel_size (out text_width, out text_height);
-
- if (subscript > 0) {
- var subscript_layout = Pango.cairo_create_layout (context);
- subscript_layout.set_alignment (Pango.Alignment.CENTER);
- description.set_absolute_size (Pango.units_from_double (SUBSCRIPT_SIZE));
- subscript_layout.set_font_description (description);
- subscript_layout.set_text (@"$subscript", -1);
- Pango.cairo_update_layout (context, subscript_layout);
- int subscript_width;
- int subscript_height;
- subscript_layout.get_pixel_size (out subscript_width, out subscript_height);
-
- context.save ();
- context.translate ((w - (text_width + subscript_width)) / 2, (h - text_height) / 2);
- Pango.cairo_layout_path (context, text_layout);
- context.fill ();
- context.restore ();
+ protected virtual Icon? create_icon (string? text, uint subscript) {
+ Icon? icon = null;
- context.save ();
- context.translate ((w + (text_width - subscript_width)) / 2, (h + text_height) / 2 - subscript_height);
- Pango.cairo_layout_path (context, subscript_layout);
- context.fill ();
- context.restore ();
- } else {
- context.save ();
- context.translate ((w - text_width) / 2, (h - text_height) / 2);
- Pango.cairo_layout_path (context, text_layout);
+ if (this.use_gtk) {
+ var style = get_style_context ();
+
+ if (style != null) {
+ const int W = 22;
+ const int H = 22;
+ const int w = 20;
+ const int h = 20;
+ const double R = 2.0;
+ const double TEXT_SIZE = 12.0;
+ const double SUBSCRIPT_SIZE = 8.0;
+
+ Pango.FontDescription description;
+ 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, W, H);
+ var context = new Cairo.Context (surface);
+
+ context.translate (0.5 * (W - w), 0.5 * (H - h));
+
+ context.new_sub_path ();
+ context.arc (R, R, R, Math.PI, -0.5 * Math.PI);
+ context.arc (w - R, R, R, -0.5 * Math.PI, 0);
+ context.arc (w - R, h - R, R, 0, 0.5 * Math.PI);
+ context.arc (R, h - R, R, 0.5 * Math.PI, Math.PI);
+ context.close_path ();
+
+ context.set_source_rgba (colour.red, colour.green, colour.blue, colour.alpha);
context.fill ();
- context.restore ();
- }
- }
+ context.set_operator (Cairo.Operator.CLEAR);
+
+ if (text != null) {
+ var text_layout = Pango.cairo_create_layout (context);
+ text_layout.set_alignment (Pango.Alignment.CENTER);
+ description.set_absolute_size (Pango.units_from_double (TEXT_SIZE));
+ text_layout.set_font_description (description);
+ text_layout.set_text ((!) text, -1);
+ Pango.cairo_update_layout (context, text_layout);
+ int text_width;
+ int text_height;
+ text_layout.get_pixel_size (out text_width, out text_height);
+
+ if (subscript > 0) {
+ var subscript_layout = Pango.cairo_create_layout (context);
+ subscript_layout.set_alignment (Pango.Alignment.CENTER);
+ description.set_absolute_size (Pango.units_from_double (SUBSCRIPT_SIZE));
+ subscript_layout.set_font_description (description);
+ subscript_layout.set_text (@"$subscript", -1);
+ Pango.cairo_update_layout (context, subscript_layout);
+ int subscript_width;
+ int subscript_height;
+ subscript_layout.get_pixel_size (out subscript_width, out subscript_height);
+
+ context.save ();
+ context.translate ((w - (text_width + subscript_width)) / 2, (h - text_height) / 2);
+ Pango.cairo_layout_path (context, text_layout);
+ context.fill ();
+ context.restore ();
+
+ context.save ();
+ context.translate ((w + (text_width - subscript_width)) / 2, (h + text_height) / 2 - subscript_height);
+ Pango.cairo_layout_path (context, subscript_layout);
+ context.fill ();
+ context.restore ();
+ } else {
+ context.save ();
+ context.translate ((w - text_width) / 2, (h - text_height) / 2);
+ Pango.cairo_layout_path (context, text_layout);
+ context.fill ();
+ context.restore ();
+ }
+ }
- var buffer = new ByteArray ();
+ var buffer = new ByteArray ();
- surface.write_to_png_stream ((data) => {
- buffer.append (data);
- return Cairo.Status.SUCCESS;
- });
+ surface.write_to_png_stream ((data) => {
+ buffer.append (data);
+ return Cairo.Status.SUCCESS;
+ });
- return new BytesIcon (ByteArray.free_to_bytes ((owned) buffer));
+ icon = new BytesIcon (ByteArray.free_to_bytes ((owned) buffer));
+ }
+ }
+
+ return icon;
}
[DBus (visible = false)]
@@ -717,8 +733,13 @@ public class Indicator.Keyboard.Service : Object {
[DBus (visible = false)]
public static int main (string[] args) {
- Gtk.init (ref args);
- new Service ("--force" in args);
+ var force = "--force" in args;
+ var use_gtk = "--use-gtk" in args;
+
+ if (use_gtk)
+ use_gtk = Gtk.init_check (ref args);
+
+ new Service (force, use_gtk);
return 0;
}
}
diff --git a/data/Makefile.am b/data/Makefile.am
index 6157e491..98b32f02 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -34,9 +34,9 @@ servicedir = $(DBUS_SERVICE_DIR)
dist_service_DATA = indicator-keyboard.service
indicator-keyboard.service:
- $(AM_V_GEN) (echo '[D-BUS Service]'; \
- echo 'Name=com.canonical.indicator.keyboard'; \
- echo 'Exec=${libexecdir}/indicator-keyboard-service') > $@.tmp && \
+ $(AM_V_GEN) (echo '[D-BUS Service]'; \
+ echo 'Name=com.canonical.indicator.keyboard'; \
+ echo 'Exec=${libexecdir}/indicator-keyboard-service --use-gtk') > $@.tmp && \
mv $@.tmp $@
indicatordir = $(INDICATOR_DIR)
diff --git a/debian/patches/default-icon-colour.patch b/debian/patches/default-icon-colour.patch
index 0f1de6c0..e2591ff4 100644
--- a/debian/patches/default-icon-colour.patch
+++ b/debian/patches/default-icon-colour.patch
@@ -1,10 +1,10 @@
--- a/lib/main.vala
+++ b/lib/main.vala
-@@ -183,6 +183,7 @@
- Pango.FontDescription description;
- var style = get_style_context ();
- var colour = style.get_color (Gtk.StateFlags.NORMAL);
-+ colour = { 0.5, 0.5, 0.5, 1.0 };
- style.get (Gtk.StateFlags.NORMAL, Gtk.STYLE_PROPERTY_FONT, out description);
+@@ -195,6 +195,7 @@
- var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, W, H);
+ Pango.FontDescription description;
+ var colour = ((!) style).get_color (Gtk.StateFlags.NORMAL);
++ colour = { 0.5, 0.5, 0.5, 1.0 };
+ ((!) style).get (Gtk.StateFlags.NORMAL, Gtk.STYLE_PROPERTY_FONT, out description);
+
+ var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, W, H);
diff --git a/lib/main.vala b/lib/main.vala
index 7e2a6f32..e429c9ea 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -1,6 +1,7 @@
[DBus (name = "com.canonical.indicator.keyboard")]
public class Indicator.Keyboard.Service : Object {
+ private bool use_gtk;
private MainLoop? loop;
private Settings indicator_settings;
private Settings source_settings;
@@ -21,7 +22,7 @@ public class Indicator.Keyboard.Service : Object {
private uint[]? icon_string_subscripts;
[DBus (visible = false)]
- public Service (bool force) {
+ public Service (bool force, bool use_gtk) {
Bus.own_name (BusType.SESSION,
"com.canonical.indicator.keyboard",
BusNameOwnerFlags.ALLOW_REPLACEMENT | (force ? BusNameOwnerFlags.REPLACE : 0),
@@ -29,6 +30,8 @@ public class Indicator.Keyboard.Service : Object {
null,
this.handle_name_lost);
+ this.use_gtk = use_gtk;
+
this.indicator_settings = new Settings ("com.canonical.indicator.keyboard");
this.indicator_settings.changed["visible"].connect (this.handle_changed_visible);
@@ -158,100 +161,113 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
- private Gtk.StyleContext get_style_context () {
- var context = new Gtk.StyleContext ();
+ private Gtk.StyleContext? get_style_context () {
+ Gtk.StyleContext? context = null;
+ Gdk.Screen? screen = Gdk.Screen.get_default ();
- context.set_screen (Gdk.Screen.get_default ());
+ if (screen != null) {
+ context = new Gtk.StyleContext ();
+ ((!) context).set_screen ((!) screen);
- var path = new Gtk.WidgetPath ();
- path.append_type (typeof (Gtk.MenuItem));
- context.set_path (path);
+ 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, uint subscript) {
- const int W = 22;
- const int H = 22;
- const int w = 20;
- const int h = 20;
- const double R = 2.0;
- const double TEXT_SIZE = 12.0;
- const double SUBSCRIPT_SIZE = 8.0;
-
- Pango.FontDescription description;
- var style = get_style_context ();
- var colour = style.get_color (Gtk.StateFlags.NORMAL);
- colour = { 0.5, 0.5, 0.5, 1.0 };
- style.get (Gtk.StateFlags.NORMAL, Gtk.STYLE_PROPERTY_FONT, out description);
-
- var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, W, H);
- var context = new Cairo.Context (surface);
-
- context.translate (0.5 * (W - w), 0.5 * (H - h));
-
- context.new_sub_path ();
- context.arc (R, R, R, Math.PI, -0.5 * Math.PI);
- context.arc (w - R, R, R, -0.5 * Math.PI, 0);
- context.arc (w - R, h - R, R, 0, 0.5 * Math.PI);
- context.arc (R, h - R, R, 0.5 * Math.PI, Math.PI);
- context.close_path ();
-
- context.set_source_rgba (colour.red, colour.green, colour.blue, colour.alpha);
- context.fill ();
- context.set_operator (Cairo.Operator.CLEAR);
-
- if (text != null) {
- var text_layout = Pango.cairo_create_layout (context);
- text_layout.set_alignment (Pango.Alignment.CENTER);
- description.set_absolute_size (Pango.units_from_double (TEXT_SIZE));
- text_layout.set_font_description (description);
- text_layout.set_text ((!) text, -1);
- Pango.cairo_update_layout (context, text_layout);
- int text_width;
- int text_height;
- text_layout.get_pixel_size (out text_width, out text_height);
-
- if (subscript > 0) {
- var subscript_layout = Pango.cairo_create_layout (context);
- subscript_layout.set_alignment (Pango.Alignment.CENTER);
- description.set_absolute_size (Pango.units_from_double (SUBSCRIPT_SIZE));
- subscript_layout.set_font_description (description);
- subscript_layout.set_text (@"$subscript", -1);
- Pango.cairo_update_layout (context, subscript_layout);
- int subscript_width;
- int subscript_height;
- subscript_layout.get_pixel_size (out subscript_width, out subscript_height);
-
- context.save ();
- context.translate ((w - (text_width + subscript_width)) / 2, (h - text_height) / 2);
- Pango.cairo_layout_path (context, text_layout);
- context.fill ();
- context.restore ();
+ protected virtual Icon? create_icon (string? text, uint subscript) {
+ Icon? icon = null;
- context.save ();
- context.translate ((w + (text_width - subscript_width)) / 2, (h + text_height) / 2 - subscript_height);
- Pango.cairo_layout_path (context, subscript_layout);
- context.fill ();
- context.restore ();
- } else {
- context.save ();
- context.translate ((w - text_width) / 2, (h - text_height) / 2);
- Pango.cairo_layout_path (context, text_layout);
+ if (this.use_gtk) {
+ var style = get_style_context ();
+
+ if (style != null) {
+ const int W = 22;
+ const int H = 22;
+ const int w = 20;
+ const int h = 20;
+ const double R = 2.0;
+ const double TEXT_SIZE = 12.0;
+ const double SUBSCRIPT_SIZE = 8.0;
+
+ Pango.FontDescription description;
+ var colour = ((!) style).get_color (Gtk.StateFlags.NORMAL);
+ colour = { 0.5, 0.5, 0.5, 1.0 };
+ ((!) style).get (Gtk.StateFlags.NORMAL, Gtk.STYLE_PROPERTY_FONT, out description);
+
+ var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, W, H);
+ var context = new Cairo.Context (surface);
+
+ context.translate (0.5 * (W - w), 0.5 * (H - h));
+
+ context.new_sub_path ();
+ context.arc (R, R, R, Math.PI, -0.5 * Math.PI);
+ context.arc (w - R, R, R, -0.5 * Math.PI, 0);
+ context.arc (w - R, h - R, R, 0, 0.5 * Math.PI);
+ context.arc (R, h - R, R, 0.5 * Math.PI, Math.PI);
+ context.close_path ();
+
+ context.set_source_rgba (colour.red, colour.green, colour.blue, colour.alpha);
context.fill ();
- context.restore ();
- }
- }
+ context.set_operator (Cairo.Operator.CLEAR);
+
+ if (text != null) {
+ var text_layout = Pango.cairo_create_layout (context);
+ text_layout.set_alignment (Pango.Alignment.CENTER);
+ description.set_absolute_size (Pango.units_from_double (TEXT_SIZE));
+ text_layout.set_font_description (description);
+ text_layout.set_text ((!) text, -1);
+ Pango.cairo_update_layout (context, text_layout);
+ int text_width;
+ int text_height;
+ text_layout.get_pixel_size (out text_width, out text_height);
+
+ if (subscript > 0) {
+ var subscript_layout = Pango.cairo_create_layout (context);
+ subscript_layout.set_alignment (Pango.Alignment.CENTER);
+ description.set_absolute_size (Pango.units_from_double (SUBSCRIPT_SIZE));
+ subscript_layout.set_font_description (description);
+ subscript_layout.set_text (@"$subscript", -1);
+ Pango.cairo_update_layout (context, subscript_layout);
+ int subscript_width;
+ int subscript_height;
+ subscript_layout.get_pixel_size (out subscript_width, out subscript_height);
+
+ context.save ();
+ context.translate ((w - (text_width + subscript_width)) / 2, (h - text_height) / 2);
+ Pango.cairo_layout_path (context, text_layout);
+ context.fill ();
+ context.restore ();
+
+ context.save ();
+ context.translate ((w + (text_width - subscript_width)) / 2, (h + text_height) / 2 - subscript_height);
+ Pango.cairo_layout_path (context, subscript_layout);
+ context.fill ();
+ context.restore ();
+ } else {
+ context.save ();
+ context.translate ((w - text_width) / 2, (h - text_height) / 2);
+ Pango.cairo_layout_path (context, text_layout);
+ context.fill ();
+ context.restore ();
+ }
+ }
- var buffer = new ByteArray ();
+ var buffer = new ByteArray ();
- surface.write_to_png_stream ((data) => {
- buffer.append (data);
- return Cairo.Status.SUCCESS;
- });
+ surface.write_to_png_stream ((data) => {
+ buffer.append (data);
+ return Cairo.Status.SUCCESS;
+ });
- return new BytesIcon (ByteArray.free_to_bytes ((owned) buffer));
+ icon = new BytesIcon (ByteArray.free_to_bytes ((owned) buffer));
+ }
+ }
+
+ return icon;
}
[DBus (visible = false)]
@@ -718,8 +734,13 @@ public class Indicator.Keyboard.Service : Object {
[DBus (visible = false)]
public static int main (string[] args) {
- Gtk.init (ref args);
- new Service ("--force" in args);
+ var force = "--force" in args;
+ var use_gtk = "--use-gtk" in args;
+
+ if (use_gtk)
+ use_gtk = Gtk.init_check (ref args);
+
+ new Service (force, use_gtk);
return 0;
}
}
diff --git a/po/indicator-keyboard.pot b/po/indicator-keyboard.pot
index c76a057b..f7e98de5 100644
--- a/po/indicator-keyboard.pot
+++ b/po/indicator-keyboard.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-07-04 00:11-0400\n"
+"POT-Creation-Date: 2013-07-17 11:23-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,14 +17,14 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
-#: ../lib/main.c:2209 ../lib/main.vala:501
+#: ../lib/main.c:2244 ../lib/main.vala:517
msgid "Character Map"
msgstr ""
-#: ../lib/main.c:2211 ../lib/main.vala:502
+#: ../lib/main.c:2246 ../lib/main.vala:518
msgid "Keyboard Layout Chart"
msgstr ""
-#: ../lib/main.c:2213 ../lib/main.vala:503
+#: ../lib/main.c:2248 ../lib/main.vala:519
msgid "Text Entry Settings..."
msgstr ""
diff --git a/tests/indicator-keyboard-service.in b/tests/indicator-keyboard-service.in
index a1f7d573..52a31988 100644
--- a/tests/indicator-keyboard-service.in
+++ b/tests/indicator-keyboard-service.in
@@ -2,4 +2,4 @@
PATH="@abs_top_builddir@/tests/execute:$PATH"
DCONF_PROFILE="@abs_top_builddir@/tests/profiles/indicator-keyboard-test"
-@abs_top_builddir@/lib/indicator-keyboard-service
+@abs_top_builddir@/lib/indicator-keyboard-service "$@"