Update of /cvsroot/morphix/keybconf/src
In directory sc8-pr-cvs1:/tmp/cvs-serv2668/src
Modified Files:
callbacks.c callbacks.h interface.c libkeyb.c libkeyb.h main.c
main.h
Log Message:
added changes so that keybconf actually does something
removed redundant keyboard.png file
Index: callbacks.c
===================================================================
RCS file: /cvsroot/morphix/keybconf/src/callbacks.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** callbacks.c 31 Oct 2003 00:43:20 -0000 1.1.1.1
--- callbacks.c 3 Nov 2003 00:20:30 -0000 1.2
***************
*** 14,17 ****
--- 14,19 ----
extern GtkWidget *MainWindow;
+ gboolean keymap_changed;
+
gboolean
on_treeview1_select_cursor_row (GtkTreeView *treeview,
***************
*** 36,40 ****
gpointer user_data)
{
!
}
--- 38,46 ----
gpointer user_data)
{
! if (keymap_changed) {
! write_X_keyboard_settings();
! set_X_keyboard_settings();
! }
! quit_keybconf();
}
***************
*** 48,51 ****
--- 54,65 ----
{
+ }
+
+
+ void
+ on_cancelbutton1_clicked (GtkButton *button,
+ gpointer user_data)
+ {
+ quit_keybconf();
}
Index: callbacks.h
===================================================================
RCS file: /cvsroot/morphix/keybconf/src/callbacks.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** callbacks.h 31 Oct 2003 00:43:20 -0000 1.1.1.1
--- callbacks.h 3 Nov 2003 00:20:30 -0000 1.2
***************
*** 18,19 ****
--- 18,23 ----
on_MainWindow_show (GtkWidget *widget,
gpointer user_data);
+
+ void
+ on_cancelbutton1_clicked (GtkButton *button,
+ gpointer user_data);
Index: interface.c
===================================================================
RCS file: /cvsroot/morphix/keybconf/src/interface.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** interface.c 31 Oct 2003 00:43:20 -0000 1.1.1.1
--- interface.c 3 Nov 2003 00:20:30 -0000 1.2
***************
*** 113,116 ****
--- 113,117 ----
gtk_widget_show (helpbutton1);
gtk_dialog_add_action_widget (GTK_DIALOG (MainWindow), helpbutton1, GTK_RESPONSE_HELP);
+ gtk_widget_set_sensitive (helpbutton1, FALSE);
GTK_WIDGET_SET_FLAGS (helpbutton1, GTK_CAN_DEFAULT);
***************
*** 132,136 ****
NULL);
g_signal_connect ((gpointer) cancelbutton1, "clicked",
! G_CALLBACK (gtk_main_quit),
NULL);
g_signal_connect ((gpointer) okbutton1, "clicked",
--- 133,137 ----
NULL);
g_signal_connect ((gpointer) cancelbutton1, "clicked",
! G_CALLBACK (on_cancelbutton1_clicked),
NULL);
g_signal_connect ((gpointer) okbutton1, "clicked",
Index: libkeyb.c
===================================================================
RCS file: /cvsroot/morphix/keybconf/src/libkeyb.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** libkeyb.c 31 Oct 2003 00:43:20 -0000 1.1.1.1
--- libkeyb.c 3 Nov 2003 00:20:31 -0000 1.2
***************
*** 1,7 ****
#include <gtk/gtk.h>
#include <dirent.h>
#include "libkeyb.h"
! gint keymaps_count;
// still need to be made before it does anything useful
--- 1,23 ----
#include <gtk/gtk.h>
#include <dirent.h>
+ #include <stdio.h>
#include "libkeyb.h"
+ #include "support.h"
! gboolean exec_command (gchar *command) {
! gchar *outbuffer;
! gchar cmdline[256];
! gint exitstatus;
!
! debug("Exec: %s\n",command);
! if (g_spawn_command_line_sync(command,&outbuffer,NULL,&exitstatus,NULL) == FALSE) {
! debug("Error occured executing command\n");
! return FALSE;
! }
! free(outbuffer);
! return TRUE;
! }
!
! // use /etc/X11/xkb for reading in types, rules for different keyboard layouts
// still need to be made before it does anything useful
***************
*** 9,17 ****
--- 25,102 ----
gboolean write_console_keyboard_settings() {
}
+
gboolean write_X_keyboard_settings() {
+ gchar *xlist = NULL;
+ gchar **x_array = NULL;
+ gint xlist_length;
+ gint i;
+ gchar *ret;
+ gboolean set_x = FALSE;
+ FILE *fp = NULL;
+ if (selected_keymapitem == NULL) {
+ debug("Can't call write_X_keyboard_settings if selected_keymap is NULL!\n");
+ return FALSE;
+ }
+ debug("Writing changes to XF86Config-4\n");
+ if (!g_file_get_contents(X_CONFIG_FILE,&xlist,&xlist_length,NULL)) {
+ return FALSE;;
+ }
+ x_array = g_strsplit(xlist,"\n",0);
+ fp = fopen(X_CONFIG_FILE,"w");
+ if (fp == NULL || x_array == NULL)
+ return FALSE;
+
+ for (i = 0; x_array[i] != NULL; i++) {
+ // should use sscanf for this one
+ ret = strstr(x_array[i],"\"XkbLayout\"");
+ if (ret == NULL) {
+ fprintf(fp,"%s\n",x_array[i]);
+ continue;
+ }
+ debug("\tOption\t\t\"XkbLayout\"\t\"%s\"\n",selected_keymapitem->code);
+ fprintf(fp,"\tOption\t\t\"XkbLayout\"\t\"%s\"\n",selected_keymapitem->code);
+ }
+ fclose(fp);
+ g_strfreev(x_array);
+ free(xlist);
+ return TRUE;
+ }
+
+ gboolean set_X_keyboard_settings() {
+ gchar cmdline[256];
+ if (selected_keymapitem == NULL) {
+ debug("Can't call set_X_keyboard_settings if selected_keymap is NULL!\n");
+ return FALSE;
+ }
+ debug("Setting changes using setxbdmap\n");
+ sprintf(cmdline,"setxkbmap %s",selected_keymapitem->code);
+ exec_command(cmdline);
+ return TRUE;
}
+
gboolean read_console_keyboard_settings() {
+ // TODO
}
gboolean read_X_keyboard_settings() {
+ gchar *xlist = NULL;
+ gchar **x_array = NULL;
+ gint xlist_length;
+ gint i, ret;
+ gboolean set_x = FALSE;
+ if (!g_file_get_contents(X_CONFIG_FILE,&xlist,&xlist_length,NULL)) {
+ return FALSE;
+ }
+ debug("Reading in X keyboard settings\n");
+ x_array = g_strsplit(xlist,"\n",0);
+ for (i = 0; x_array[i] != NULL; i++) {
+ ret = sscanf(x_array[i],"\tOption \"XkbLayout\" \"%15[^\"]\"",current_keymap);
+ if (ret != 1)
+ continue;
+ set_x = TRUE;
+ break;
+ }
+ g_strfreev(x_array);
+ free(xlist);
+ return set_x;
}
***************
*** 33,40 ****
struct dirent **ep;
gint n;
- gchar mappath[] = KEYMAP_LIST_DIR;
gint i, j, ret;
! n = scandir(mappath,&ep, 0,alphasort);
if (n >= 3) {
--- 118,129 ----
struct dirent **ep;
gint n;
gint i, j, ret;
! if (keymap_list_dir == NULL) {
! return FALSE;
! }
! debug("Reading in keymap list\n");
!
! n = scandir(keymap_list_dir,&ep, 0,alphasort);
if (n >= 3) {
***************
*** 54,58 ****
continue;
}
! sprintf(cmdline,"%s/%s",KEYMAP_LIST_DIR,ep[cnt]->d_name);
if (!g_file_get_contents(cmdline,&keymaplist,&keymaplist_length,NULL)) {
continue;
--- 143,147 ----
continue;
}
! sprintf(cmdline,"%s/%s",keymap_list_dir,ep[cnt]->d_name);
if (!g_file_get_contents(cmdline,&keymaplist,&keymaplist_length,NULL)) {
continue;
***************
*** 97,100 ****
void free_keymaps_list() {
! // TODO
}
--- 186,221 ----
void free_keymaps_list() {
! gint i, j;
!
! debug("Freeing keymap list\n");
!
! for (i = 0; i < keymaps_count; i++) {
! for (j = 0; j < keymaps[i].list_count; j++) {
! free(keymaps[i].list[j].code);
! free(keymaps[i].list[j].description);
! }
! free(keymaps[i].list);
! keymaps[i].list_count = 0;
! free(keymaps[i].name);
! }
! free(keymaps);
! }
!
!
! /*
! returns pointer to ki_struct if found (which is presumed to be unique),
! NULL otherwise
! */
!
! ki_struct* find_keymap_entry(gchar *desc) {
! gint i, j;
! ki_struct *kitem = NULL;
! for (i = 0; i < keymaps_count; i++) {
! for (j = 0; j < keymaps[i].list_count; j++) {
! if (strcmp(keymaps[i].list[j].description,desc) == 0) {
! kitem = &keymaps[i].list[j];
! }
! }
! }
! return kitem;
}
Index: libkeyb.h
===================================================================
RCS file: /cvsroot/morphix/keybconf/src/libkeyb.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** libkeyb.h 31 Oct 2003 00:43:20 -0000 1.1.1.1
--- libkeyb.h 3 Nov 2003 00:20:31 -0000 1.2
***************
*** 19,22 ****
--- 19,25 ----
typedef struct keymap_type_struct kt_struct;
+ gint keymaps_count;
+ gchar current_keymap[16];
+ ki_struct *selected_keymapitem;
#define DEBUG
***************
*** 28,34 ****
#endif
! #define KEYMAP_LIST_DIR "/home/alex/Projects/keybconfig/lists"
gboolean read_keymaps_list();
#endif
--- 31,43 ----
#endif
! gchar *keymap_list_dir;
! #define X_CONFIG_FILE "/etc/X11/XF86Config-4"
gboolean read_keymaps_list();
+ ki_struct* find_keymap_entry(gchar *desc);
+ gboolean read_X_keyboard_settings();
+ gboolean set_X_keyboard_settings();
+ gboolean write_X_keyboard_settings();
+ void free_keymaps_list();
#endif
Index: main.c
===================================================================
RCS file: /cvsroot/morphix/keybconf/src/main.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** main.c 31 Oct 2003 00:43:22 -0000 1.1.1.1
--- main.c 3 Nov 2003 00:20:31 -0000 1.2
***************
*** 16,22 ****
#include "libkeyb.h"
GtkWidget *MainWindow;
extern gint keymaps_count;
!
enum {
--- 16,26 ----
#include "libkeyb.h"
+ // #define LOCAL_BUILD
+
GtkWidget *MainWindow;
+ GtkTreeSelection *selector;
extern gint keymaps_count;
! extern gboolean keymap_changed;
! gboolean realized;
enum {
***************
*** 26,31 ****
--- 30,77 ----
};
+ void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data) {
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ gchar *loc_desc;
+
+ if (!realized)
+ return;
+
+ if (gtk_tree_selection_get_selected(selection,&model,&iter)) {
+ gtk_tree_model_get(model,&iter, LOCALE_COLUMN, &loc_desc, -1);
+ if (loc_desc == NULL) {
+ return;
+ }
+ if (strcmp(loc_desc,"") != 0) {
+ debug("Selection changed\n");
+ selected_keymapitem = find_keymap_entry(loc_desc);
+ keymap_changed = TRUE;
+ }
+ g_free(loc_desc);
+ }
+ }
+
+ /*
+ when you want to use this after make install, switch the comments below
+ */
+
void init_keybconf() {
+ #ifdef LOCAL_BUILD
+ gint length = strlen("../lists");
+ #else
+ gint length = strlen(PACKAGE_DATA_DIR "/" PACKAGE "/lists");
+ #endif
+ keymap_changed = FALSE;
+ realized = FALSE;
+ selected_keymapitem = NULL;
+ strcpy(current_keymap,"");
+ keymap_list_dir = (gchar *)malloc(length + 1);
+ #ifdef LOCAL_BUILD
+ strcpy(keymap_list_dir,"../lists");
+ #else
+ strcpy(keymap_list_dir, PACKAGE_DATA_DIR "/" PACKAGE "/lists");
+ #endif
+ debug("keymap_list_dir: %s\n",keymap_list_dir);
}
***************
*** 35,47 ****
read_keymaps_list();
! add_keymap_list();
! fp = fopen(KEYBPIX_LOC,"r");
! if (fp == NULL) {
! gtk_image_set_from_file(GTK_IMAGE(image),KEYBPIX_LOC_2);
! }
! else {
! fclose(fp);
! gtk_image_set_from_file(GTK_IMAGE(image),KEYBPIX_LOC);
! }
}
--- 81,103 ----
read_keymaps_list();
! add_keymap_list();
! setup_keymap_list_cb();
! read_X_keyboard_settings();
! select_current_keymap();
!
! gchar *kbd_pix;
! gint length = strlen(PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps/keyboard.png");
! kbd_pix = (gchar *)malloc(length);
! strcpy(kbd_pix,PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps/keyboard.png");
! gtk_image_set_from_file(GTK_IMAGE(image),kbd_pix);
! free(kbd_pix);
!
! realized = TRUE;
! }
!
! void quit_keybconf() {
! free_keymaps_list();
! free(keymap_list_dir);
! exit(0);
}
***************
*** 54,78 ****
}
#ifdef ENABLE_NLS
! bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
! bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
! textdomain (GETTEXT_PACKAGE);
#endif
! gtk_set_locale ();
! gtk_init (&argc, &argv);
! add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
! /*
! * The following code was added by Glade to create one of each component
! * (except popup menus), just so that you see something after building
! * the project. Delete any components that you don't want shown initially.
! */
! MainWindow = create_MainWindow ();
! init_keybconf();
! gtk_widget_show (MainWindow);
! setup_keybconf();
! gtk_main ();
! return 0;
}
--- 110,197 ----
}
#ifdef ENABLE_NLS
! bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
! bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
! textdomain (GETTEXT_PACKAGE);
#endif
! gtk_set_locale ();
! gtk_init (&argc, &argv);
!
! add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
! MainWindow = create_MainWindow ();
! init_keybconf();
! gtk_widget_show (MainWindow);
! setup_keybconf();
! gtk_main ();
! return 0;
! }
! gboolean select_current_keymap() {
! gint i, j;
! GtkTreeIter iter, iter_c;
! gboolean valid;
! GtkTreePath *path = NULL;
! GtkWidget *treeview = lookup_widget(MainWindow,"treeview1");
! GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
! GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
!
! if (strcmp(current_keymap,"") == 0) {
! return FALSE;
! }
! debug("finding %s\n",current_keymap);
! valid = gtk_tree_model_get_iter_first(model,&iter);
! for (i = 0; i < keymaps_count && valid == TRUE; i++) {
! for (j = 0; j < keymaps[i].list_count; j++) {
! gtk_tree_model_iter_nth_child(model,
! &iter_c,
! &iter,
! j);
! if (strcmp(keymaps[i].list[j].code,current_keymap) == 0) {
! path = gtk_tree_model_get_path(model,&iter_c);
! gtk_tree_selection_select_path(selection,path);
! gtk_tree_view_expand_to_path(GTK_TREE_VIEW(treeview),path);
! gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview),
! path,
! NULL,
! TRUE,
! 0.5,0.0);
! debug("found keymap at nr %d\n",j);
! break;
! }
! }
! valid = gtk_tree_model_iter_next(model,&iter);
! }
! if (valid == FALSE || i >= keymaps_count ) {
! valid = gtk_tree_model_get_iter_first(model,&iter);
! for (i = 0; i < keymaps_count && valid == TRUE; i++) {
! for (j = 0; j < keymaps[i].list_count; j++) {
! if (strcmp(keymaps[i].list[j].code,"us") == 0) {
! path = gtk_tree_model_get_path(model,&iter);
! gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview),
! path,
! NULL,
! TRUE,
! 0.5,0.0);
! gtk_tree_selection_select_iter(selection,&iter);
! break;
! }
! }
! valid = gtk_tree_model_iter_next(model,&iter);
! }
! }
! return TRUE;
! }
!
!
!
! void setup_keymap_list_cb() {
! GtkWidget *treeview = lookup_widget(MainWindow,"treeview1");
!
! selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
! gtk_tree_selection_set_mode(selector, GTK_SELECTION_SINGLE);
! g_signal_connect(G_OBJECT(selector),"changed",
! G_CALLBACK(tree_selection_changed_cb),
! NULL);
}
Index: main.h
===================================================================
RCS file: /cvsroot/morphix/keybconf/src/main.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** main.h 31 Oct 2003 00:43:22 -0000 1.1.1.1
--- main.h 3 Nov 2003 00:20:31 -0000 1.2
***************
*** 1,9 ****
#ifndef KEYBCONF_MAIN_H
#define KEYBCONF_MAIN_H
!
#define KEYBPIX_LOC "../pixmaps/keyboard.png"
#define KEYBPIX_LOC_2 "/usr/share/keybconf/keyboard.png"
!
void add_keymap_list();
#endif
--- 1,10 ----
#ifndef KEYBCONF_MAIN_H
#define KEYBCONF_MAIN_H
! /*
#define KEYBPIX_LOC "../pixmaps/keyboard.png"
#define KEYBPIX_LOC_2 "/usr/share/keybconf/keyboard.png"
! */
void add_keymap_list();
+ void setup_keymap_list_cb();
#endif
|