diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2010-02-05 17:29:25 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2010-02-08 16:45:13 +1000 |
commit | 6b7e98914f2aada63e2e962f7920fff810d6af9a (patch) | |
tree | 5326d0ed9476f1db3cebfded2769046368e8e34a | |
parent | 451860c34decad4442f6bf88645d75b7d3640d4a (diff) |
Move to xorg.conf snippet generation.udev
Principle works the same as before, parse /etc/sysconfig/keyboard, then take
a simple template for XKB options and write it to
/etc/xorg.conf.d/99-fedora-setup-keyboard.conf.
Any XKB options not set in /etc/sysconfig/keyboard simply ignore by
commenting out the matching line in the section.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | fedora-setup-keyboard.c | 69 |
1 files changed, 47 insertions, 22 deletions
diff --git a/fedora-setup-keyboard.c b/fedora-setup-keyboard.c index 212c12a..0cf98b1 100644 --- a/fedora-setup-keyboard.c +++ b/fedora-setup-keyboard.c @@ -24,12 +24,34 @@ * */ +/** + * Read /etc/sysconfig/keyboard and convert the contents into an XKB + * description. Save this configuration as an xorg.conf.d snippet. + */ + + #include <glib.h> +#include <glib/gstdio.h> #include <string.h> #include <stdlib.h> +#include <unistd.h> #define KBDCONFIG "/etc/sysconfig/keyboard" #define KEY_OPTIONS "input.xkb.options" +#define CONFIG_DIR "/etc/xorg.conf.d" +#define CONFIG_FILE "99-fedora-setup-keyboard.conf" + +const char *config_snippet = +"# This file is autogenerated by fedora-setup-keyboard. Any \n" \ +"# modifications will be lost.\n\n" \ +"Section \"InputClass\"\n" \ +" Identifier \"fedora-setup-keyboard\"\n" \ +" MatchIsKeyboard \"on\"\n" \ +"%s Option \"XkbLayout\" \"%s\"\n" \ +"%s Option \"XkbVariant\" \"%s\"\n" \ +"%s Option \"XkbModel\" \"%s\"\n" \ +"%s Option \"XkbOptions\" \"%s\"\n" \ +"EndSection\n"; gchar* remove_quotes(gchar *str) { gchar *tmp; @@ -57,13 +79,19 @@ int main() { GKeyFile *cfg_file; gchar *buffer, *conf; - gchar *map[] = { "layout", "model", "variant", "options" }; + gchar *model, *layout, *variant, *options; GHashTable* kbd_models; gchar *keytable; gchar *property; - guint n, i; - gchar **list; - gchar *key, *udi, *tmp; + FILE *file; + + /* Check if the directory even exists */ + if (g_access(CONFIG_DIR, W_OK | X_OK)) + return 1; + + file = g_fopen(CONFIG_DIR "/" CONFIG_FILE, "w"); + if (!file) + return 1; /* Parse the config file */ cfg_file = g_key_file_new(); @@ -83,27 +111,24 @@ int main() { keytable = g_hash_table_lookup(kbd_models, (gpointer) property); g_free(property); - 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]); - - if(property != NULL) - g_free(property); - g_free(value); - g_free(key); - - } + model = remove_quotes(g_key_file_get_value(cfg_file, "kbd", "MODEL", NULL)); + layout = remove_quotes(g_key_file_get_value(cfg_file, "kbd", "LAYOUT", NULL)); + variant = remove_quotes(g_key_file_get_value(cfg_file, "kbd", "VARIANT", NULL)); + options = remove_quotes(g_key_file_get_value(cfg_file, "kbd", "OPTIONS", NULL)); + + /* if a value is not present, comment out the line.*/ + g_fprintf(file, config_snippet, model ? "" : "#", model, + layout ? "" : "#", layout, + variant ? "" : "#", variant, + options ? "" : "#", options); + fclose(file); /* cleanup */ + g_free(model); + g_free(layout); + g_free(variant); + g_free(options); g_free(conf); - g_free(list); g_hash_table_destroy(kbd_models); return 0; |