diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2009-04-09 11:04:37 +1000 |
---|---|---|
committer | Adel Gadllah <adel.gadllah@gmail.com> | 2009-04-09 11:54:16 +0200 |
commit | b01976b616ce8dbe2d73260267c9dc4295c9c71e (patch) | |
tree | 0c4ddb0e02dec68e470ad84c49881582132fb217 | |
parent | 34b792312ecd9ba8f01ff60fd2361e085c98af5c (diff) |
Merge input.xkb.options terminate:ctrl_alt_bksp by default.
Prepend to options already existing if necessary.
-rw-r--r-- | 10-x11-keymap.fdi | 1 | ||||
-rw-r--r-- | fedora-setup-keyboard.c | 36 |
2 files changed, 36 insertions, 1 deletions
diff --git a/10-x11-keymap.fdi b/10-x11-keymap.fdi index c78f05b..3c86017 100644 --- a/10-x11-keymap.fdi +++ b/10-x11-keymap.fdi @@ -2,6 +2,7 @@ <deviceinfo version="0.2"> <device> <match key="info.capabilities" contains="input.keyboard"> + <merge key="input.xkb.options" type="string">terminate:ctrl_alt_bksp</merge> <append key="info.callouts.add" type="strlist">fedora-setup-keyboard</append> </match> </device> diff --git a/fedora-setup-keyboard.c b/fedora-setup-keyboard.c index e656983..8c1e6b7 100644 --- a/fedora-setup-keyboard.c +++ b/fedora-setup-keyboard.c @@ -29,6 +29,7 @@ #include <stdlib.h> #define KBDCONFIG "/etc/sysconfig/keyboard" +#define KEY_OPTIONS "input.xkb.options" gchar* remove_quotes(gchar *str) { gchar *tmp; @@ -52,6 +53,34 @@ gchar* remove_quotes(gchar *str) { return tmp; } +/** + * Append the given value to the current value of matching key. + * Memory for the returned string must be freed by the caller. + * + * Only mergess input.xkb.options ATM + */ +gchar *merge_key(LibHalContext *hal_ctx, gchar *udi, gchar* key, gchar *value) { + gchar *xkb_opts; + gchar *merged = NULL; + + /* We only need to merge xkb.options */ + if (strcmp(key, KEY_OPTIONS) != 0) + return g_strdup(value); + xkb_opts = libhal_device_get_property_string(hal_ctx, udi, + KEY_OPTIONS, NULL); + if (!xkb_opts || strlen(xkb_opts) == 0) + merged = g_strdup(value); + else if (!value || strlen(value) == 0) + merged = g_strdup(xkb_opts); + else + merged = g_strdup_printf("%s,%s", xkb_opts, value); + + if (xkb_opts) + libhal_free_string(xkb_opts); + + return merged; +} + int main() { GKeyFile *cfg_file; gchar *buffer, *conf; @@ -103,16 +132,21 @@ int main() { list = g_strsplit(keytable, " ", 4); n = g_strv_length(list); for ( i = 0; i < n; i++) { + gchar *value; /* honor user setting */ tmp = g_ascii_strup(map[i], -1); property = remove_quotes(g_key_file_get_value(cfg_file, "kbd", tmp, NULL)); g_free(tmp); key = g_strdup_printf("input.xkb.%s", map[i]); - libhal_device_set_property_string(hal_ctx, udi, key, (property != NULL) ? property : list[i], NULL); + + value = merge_key(hal_ctx, udi, key, + (property != NULL) ? property : list[i]); + libhal_device_set_property_string(hal_ctx, udi, key, value, NULL); if(property != NULL) g_free(property); + g_free(value); g_free(key); } |