summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdel Gadllah <adel.gadllah@gmail.com>2009-02-20 22:57:15 +0100
committerAdel Gadllah <adel.gadllah@gmail.com>2009-02-20 22:57:15 +0100
commit9ed8ad91b66c12f538eff1c1e7a9e4b5eb5e45aa (patch)
tree7a692f9d6a0017408d4f3de5cf0cbd38f4c8ecae
Initial commit
-rw-r--r--Makefile12
-rw-r--r--fedora-setup-keyboard.c127
-rw-r--r--get_layouts.py35
3 files changed, 174 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..dccb048
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,12 @@
+CC=gcc
+CFLAGS=
+
+all:
+ python get_layouts.py > keyboards.h
+ $(CC) fedora-setup-keyboard.c `pkg-config --cflags --libs hal glib-2.0` $(CFLAGS) -o fedora-setup-keyboard
+
+install:
+ install -m 755 fedora-setup-keyboard $(DESTDIR)/fedora-setup-keyboard
+
+clean:
+ rm -f fedora-setup-keyboard keyboards.h
diff --git a/fedora-setup-keyboard.c b/fedora-setup-keyboard.c
new file mode 100644
index 0000000..e656983
--- /dev/null
+++ b/fedora-setup-keyboard.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright © 2009 Adel Gadllah
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *
+ */
+
+#include <libhal.h>
+#include <glib.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define KBDCONFIG "/etc/sysconfig/keyboard"
+
+gchar* remove_quotes(gchar *str) {
+ gchar *tmp;
+ gboolean s_offset = FALSE;
+
+ if(str == NULL)
+ return NULL;
+
+ if(str[0] == '"') {
+ str++;
+ s_offset = TRUE;
+ }
+ if(str[strlen(str) - 1] == '"')
+ str[strlen(str) - 1] = 0;
+
+ tmp = g_strdup(str);
+
+ if(s_offset)
+ str--;
+ g_free(str);
+ return tmp;
+}
+
+int main() {
+ GKeyFile *cfg_file;
+ gchar *buffer, *conf;
+
+ gchar *map[] = { "layout", "model", "variant", "options" };
+ GHashTable* kbd_models;
+ gchar *keytable;
+ gchar *property;
+ guint n, i;
+ gchar **list;
+ gchar *key, *udi, *tmp;
+
+ /* connect to HAL */
+ LibHalContext *hal_ctx;
+
+ if((udi = getenv("UDI")) == NULL)
+ return 1;
+
+ if((hal_ctx = libhal_ctx_init_direct(NULL)) == NULL) {
+ if((hal_ctx = libhal_ctx_new()) == NULL)
+ return 1;
+
+ if(!libhal_ctx_set_dbus_connection(hal_ctx, dbus_bus_get(DBUS_BUS_SYSTEM, NULL)))
+ return 1;
+
+ if(!libhal_ctx_init(hal_ctx, NULL))
+ return 1;
+ }
+
+
+ /* Parse the config file */
+ cfg_file = g_key_file_new();
+ g_file_get_contents(KBDCONFIG, &buffer, NULL, NULL);
+ conf = g_strdup_printf("[kbd]\n%s", buffer);
+ g_free(buffer);
+ g_key_file_load_from_data(cfg_file, conf, strlen(conf), G_KEY_FILE_NONE, NULL);
+ property = remove_quotes(g_key_file_get_value(cfg_file, "kbd", "KEYTABLE", NULL));
+ if(property == NULL)
+ return 1;
+
+ /* Generate model database */
+ kbd_models = g_hash_table_new(g_str_hash, g_str_equal);
+#include "keyboards.h"
+
+ /* Read and apply user config */
+ 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++) {
+ /* 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);
+
+ if(property != NULL)
+ g_free(property);
+ g_free(key);
+
+ }
+
+ /* cleanup */
+ g_free(conf);
+ g_free(list);
+ libhal_ctx_free(hal_ctx);
+ g_hash_table_destroy(kbd_models);
+
+ return 0;
+}
diff --git a/get_layouts.py b/get_layouts.py
new file mode 100644
index 0000000..500f14a
--- /dev/null
+++ b/get_layouts.py
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+"""
+ Copyright © 2009 Adel Gadllah
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice (including the next
+ paragraph) shall be included in all copies or substantial portions of the
+ Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+"""
+
+
+import rhpl.keyboard_models
+
+kbd_models = rhpl.keyboard_models.KeyboardModels().get_models()
+
+for key in kbd_models:
+ (layout, model, variant, options) = tuple(kbd_models.get(key, ['', '', '', '', ''])[1:])
+ tmp = "%s %s %s %s" % (layout, model, variant, options)
+ print "g_hash_table_insert(kbd_models, \"%s\", \"%s\");" % (key, tmp.strip())
+