filename | src/gtkui/gtk_hotkeys.c |
changeset | 1015:ad448bedc48a |
author | nkeynes |
date | Sat Jun 27 09:55:00 2009 +0000 (14 years ago) |
permissions | -rw-r--r-- |
last change | Ensure each VMU is only attached once Handle removal of sub-devices when detaching parent device |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/src/gtkui/gtk_hotkeys.c Sat Jun 27 09:55:00 2009 +00001.3 @@ -0,0 +1,187 @@1.4 +/**1.5 + * $Id: $1.6 + *1.7 + * GTK dialog for defining hotkeys1.8 + *1.9 + * Copyright (c) 2009 wahrhaft.1.10 + *1.11 + * This program is free software; you can redistribute it and/or modify1.12 + * it under the terms of the GNU General Public License as published by1.13 + * the Free Software Foundation; either version 2 of the License, or1.14 + * (at your option) any later version.1.15 + *1.16 + * This program is distributed in the hope that it will be useful,1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1.19 + * GNU General Public License for more details.1.20 + */1.21 +1.22 +#include <assert.h>1.23 +#include <string.h>1.24 +#include <gtk/gtk.h>1.25 +#include <gdk/gdkkeysyms.h>1.26 +1.27 +#include "lxdream.h"1.28 +#include "display.h"1.29 +#include "gtkui/gtkui.h"1.30 +#include "hotkeys.h"1.31 +1.32 +1.33 +1.34 +static void config_keysym_hook( void *data, const gchar *keysym )1.35 +{1.36 + GtkWidget *widget = (GtkWidget *)data;1.37 + gtk_entry_set_text( GTK_ENTRY(widget), keysym );1.38 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(FALSE) );1.39 + input_set_keysym_hook(NULL, NULL);1.40 +}1.41 +1.42 +static gboolean config_key_buttonpress( GtkWidget *widget, GdkEventButton *event, gpointer user_data )1.43 +{1.44 + gboolean keypress_mode = GPOINTER_TO_INT(g_object_get_data( G_OBJECT(widget), "keypress_mode"));1.45 + if( keypress_mode ) {1.46 + gchar *keysym = input_keycode_to_keysym( &system_mouse_driver, event->button);1.47 + if( keysym != NULL ) {1.48 + config_keysym_hook( widget, keysym );1.49 + g_free(keysym);1.50 + }1.51 + return TRUE;1.52 + } else {1.53 + gtk_entry_set_text( GTK_ENTRY(widget), _("<press key>") );1.54 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(TRUE) );1.55 + input_set_keysym_hook(config_keysym_hook, widget);1.56 + }1.57 + return FALSE;1.58 +}1.59 +1.60 +static gboolean config_key_keypress( GtkWidget *widget, GdkEventKey *event, gpointer user_data )1.61 +{1.62 + gboolean keypress_mode = GPOINTER_TO_INT(g_object_get_data( G_OBJECT(widget), "keypress_mode"));1.63 + if( keypress_mode ) {1.64 + if( event->keyval == GDK_Escape ) {1.65 + gtk_entry_set_text( GTK_ENTRY(widget), "" );1.66 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(FALSE) );1.67 + return TRUE;1.68 + }1.69 + GdkKeymap *keymap = gdk_keymap_get_default();1.70 + guint keyval;1.71 +1.72 + gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval,1.73 + NULL, NULL, NULL );1.74 + gtk_entry_set_text( GTK_ENTRY(widget), gdk_keyval_name(keyval) );1.75 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(FALSE) );1.76 + input_set_keysym_hook(NULL, NULL);1.77 + return TRUE;1.78 + } else {1.79 + switch( event->keyval ) {1.80 + case GDK_Return:1.81 + case GDK_KP_Enter:1.82 + gtk_entry_set_text( GTK_ENTRY(widget), _("<press key>") );1.83 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(TRUE) );1.84 + input_set_keysym_hook(config_keysym_hook, widget);1.85 + return TRUE;1.86 + case GDK_BackSpace:1.87 + case GDK_Delete:1.88 + gtk_entry_set_text( GTK_ENTRY(widget), "" );1.89 + return TRUE;1.90 + }1.91 + return FALSE;1.92 + }1.93 +1.94 +}1.95 +1.96 +void hotkeys_dialog_done( GtkWidget *panel, gboolean isOK )1.97 +{1.98 + if( isOK ) {1.99 + hotkeys_unregister_keys();1.100 + lxdream_config_entry_t conf = hotkeys_get_config();1.101 + int i;1.102 + for( i=0; conf[i].key != NULL; i++ ) {1.103 + char buf[64];1.104 + GtkWidget *entry1, *entry2;1.105 + const gchar *key1, *key2;1.106 + snprintf( buf, sizeof(buf), "%s.1", conf[i].key );1.107 + entry1 = GTK_WIDGET(g_object_get_qdata( G_OBJECT(panel), g_quark_from_string(buf)));1.108 + key1 = gtk_entry_get_text(GTK_ENTRY(entry1));1.109 + snprintf( buf, sizeof(buf), "%s.2", conf[i].key );1.110 + entry2 = GTK_WIDGET(g_object_get_qdata( G_OBJECT(panel), g_quark_from_string(buf)));1.111 + key2 = gtk_entry_get_text(GTK_ENTRY(entry2));1.112 + if( key1 == NULL || key1[0] == '\0') {1.113 + lxdream_set_config_value( &conf[i], key2 );1.114 + } else if( key2 == NULL || key2[0] == '\0') {1.115 + lxdream_set_config_value( &conf[i], key1 );1.116 + } else {1.117 + char buf[64];1.118 + snprintf( buf, sizeof(buf), "%s, %s", key1, key2 );1.119 + lxdream_set_config_value( &conf[i], buf );1.120 + }1.121 + }1.122 + lxdream_save_config();1.123 + hotkeys_register_keys();1.124 + }1.125 +}1.126 +1.127 +GtkWidget *hotkeys_panel_new()1.128 +{1.129 + lxdream_config_entry_t conf = hotkeys_get_config();1.130 + int count, i;1.131 + for( count=0; conf[count].key != NULL; count++ );1.132 +1.133 + GtkWidget *table = gtk_table_new( (count+1)>>1, 6, FALSE );1.134 + GList *focus_chain = NULL;1.135 + //gtk_object_set_data( GTK_OBJECT(table), "maple_device", device );1.136 + for( i=0; i<count; i++ ) {1.137 + GtkWidget *text, *text2;1.138 + char buf[64];1.139 + int x=0;1.140 + int y=i;1.141 + if( i >= (count+1)>>1 ) {1.142 + x = 3;1.143 + y -= (count+1)>>1;1.144 + }1.145 + gtk_table_attach( GTK_TABLE(table), gtk_label_new(gettext(conf[i].label)), x, x+1, y, y+1,1.146 + GTK_SHRINK, GTK_SHRINK, 0, 0 );1.147 + text = gtk_entry_new();1.148 + gtk_entry_set_width_chars( GTK_ENTRY(text), 11 );1.149 + gtk_entry_set_editable( GTK_ENTRY(text), FALSE );1.150 + g_signal_connect( text, "key_press_event",1.151 + G_CALLBACK(config_key_keypress), NULL );1.152 + g_signal_connect( text, "button_press_event",1.153 + G_CALLBACK(config_key_buttonpress), NULL );1.154 + snprintf( buf, sizeof(buf), "%s.1", conf[i].key );1.155 + g_object_set_data( G_OBJECT(text), "keypress_mode", GINT_TO_POINTER(FALSE) );1.156 + g_object_set_qdata( G_OBJECT(table), g_quark_from_string(buf), text );1.157 + gtk_table_attach_defaults( GTK_TABLE(table), text, x+1, x+2, y, y+1);1.158 + focus_chain = g_list_append( focus_chain, text );1.159 + text2 = gtk_entry_new();1.160 + gtk_entry_set_width_chars( GTK_ENTRY(text2), 11 );1.161 + gtk_entry_set_editable( GTK_ENTRY(text2), FALSE );1.162 + g_signal_connect( text2, "key_press_event",1.163 + G_CALLBACK(config_key_keypress), NULL );1.164 + g_signal_connect( text2, "button_press_event",1.165 + G_CALLBACK(config_key_buttonpress), NULL );1.166 + snprintf( buf, sizeof(buf), "%s.2", conf[i].key );1.167 + g_object_set_data( G_OBJECT(text2), "keypress_mode", GINT_TO_POINTER(FALSE) );1.168 + g_object_set_qdata( G_OBJECT(table), g_quark_from_string(buf), text2 );1.169 + gtk_table_attach_defaults( GTK_TABLE(table), text2, x+2, x+3, y, y+1);1.170 + focus_chain = g_list_append( focus_chain, text2 );1.171 + if( conf[i].value != NULL ) {1.172 + gchar **parts = g_strsplit(conf[i].value,",",3);1.173 + if( parts[0] != NULL ) {1.174 + gtk_entry_set_text( GTK_ENTRY(text), g_strstrip(parts[0]) );1.175 + if( parts[1] != NULL ) {1.176 + gtk_entry_set_text( GTK_ENTRY(text2), g_strstrip(parts[1]) );1.177 + }1.178 + }1.179 + g_strfreev(parts);1.180 + }1.181 + }1.182 + gtk_container_set_focus_chain( GTK_CONTAINER(table), focus_chain );1.183 +1.184 + return table;1.185 +}1.186 +1.187 +void hotkeys_dialog_run( )1.188 +{1.189 + gtk_gui_run_property_dialog( _("Hotkey Settings"), hotkeys_panel_new(), hotkeys_dialog_done );1.190 +}
.