revision 849:bbe26d798fc2
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 849:bbe26d798fc2 |
parent | 848:34dc33c05106 |
child | 850:28782ebbd01d |
author | nkeynes |
date | Mon Sep 08 05:13:51 2008 +0000 (15 years ago) |
Refactor mouse event management - button events are now usable for controllers
1.1 --- a/src/cocoaui/cocoa_ctrl.c Sun Sep 07 11:08:10 2008 +00001.2 +++ b/src/cocoaui/cocoa_ctrl.c Mon Sep 08 05:13:51 2008 +00001.3 @@ -25,6 +25,8 @@1.5 #define MAX_DEVICES 41.7 +#define KEYBINDING_SIZE 1101.8 +1.9 static void cocoa_config_keysym_hook(void *data, const gchar *keysym);1.11 @interface KeyBindingEditor (Private)1.12 @@ -88,6 +90,14 @@1.13 [self fireBindingChanged];1.14 }1.15 }1.16 +- (void)updateMousesym: (int)button1.17 +{1.18 + gchar *keysym = input_keycode_to_keysym( &system_mouse_driver, (button+1) );1.19 + if( keysym != NULL ) {1.20 + [self updateKeysym: keysym ];1.21 + g_free(keysym);1.22 + }1.23 +}1.24 - (void)keyPressed: (int)keycode1.25 {1.26 gchar *keysym = input_keycode_to_keysym(NULL, keycode);1.27 @@ -102,8 +112,24 @@1.28 }1.29 - (void)mouseDown: (NSEvent *)event1.30 {1.31 - [self setPrimed: YES];1.32 - [super mouseDown: event];1.33 + if( isPrimed ) {1.34 + [self updateMousesym: 0];1.35 + } else {1.36 + [self setPrimed: YES];1.37 + [super mouseDown: event];1.38 + }1.39 +}1.40 +- (void)rightMouseDown: (NSEvent *)event1.41 +{1.42 + if( isPrimed ) {1.43 + [self updateMousesym: 1];1.44 + }1.45 +}1.46 +- (void)otherMouseDown: (NSEvent *)event1.47 +{1.48 + if( isPrimed ) {1.49 + [self updateMousesym: [event buttonNumber]];1.50 + }1.51 }1.52 - (void)keyDown: (NSEvent *) event1.53 {1.54 @@ -218,7 +244,7 @@1.56 for( count=0; config[count].key != NULL; count++ );1.57 x = TEXT_GAP;1.58 - NSSize size = NSMakeSize(85*3+TEXT_GAP*4, count*(TEXT_HEIGHT+TEXT_GAP)+TEXT_GAP);1.59 + NSSize size = NSMakeSize(85+KEYBINDING_SIZE*2+TEXT_GAP*4, count*(TEXT_HEIGHT+TEXT_GAP)+TEXT_GAP);1.60 [self setFrameSize: size];1.61 [self scrollRectToVisible: NSMakeRect(0,0,1,1)];1.62 y = TEXT_GAP;1.63 @@ -227,14 +253,14 @@1.64 NSTextField *label = cocoa_gui_add_label(self, NS_(config[i].label), frame);1.65 [label setAlignment: NSRightTextAlignment];1.67 - frame = NSMakeRect( x + 85 + TEXT_GAP, y, 85, TEXT_HEIGHT);1.68 + frame = NSMakeRect( x + 85 + TEXT_GAP, y, KEYBINDING_SIZE, TEXT_HEIGHT);1.69 field[i][0] = [[KeyBindingField alloc] initWithFrame: frame];1.70 [field[i][0] setAutoresizingMask: (NSViewMinYMargin|NSViewMaxXMargin)];1.71 [field[i][0] setTag: i];1.72 [field[i][0] setDelegate: self];1.73 [self addSubview: field[i][0]];1.75 - frame = NSMakeRect( x + (85*2) + (TEXT_GAP*2), y, 85, TEXT_HEIGHT);1.76 + frame = NSMakeRect( x + 85 + KEYBINDING_SIZE + (TEXT_GAP*2), y, KEYBINDING_SIZE, TEXT_HEIGHT);1.77 field[i][1] = [[KeyBindingField alloc] initWithFrame: frame];1.78 [field[i][1] setAutoresizingMask: (NSViewMinYMargin|NSViewMaxXMargin)];1.79 [field[i][1] setTag: i];
2.1 --- a/src/cocoaui/cocoa_prefs.c Sun Sep 07 11:08:10 2008 +00002.2 +++ b/src/cocoaui/cocoa_prefs.c Mon Sep 08 05:13:51 2008 +00002.3 @@ -68,7 +68,7 @@2.5 - (NSView *)createControlsPane2.6 {2.7 - NSView *pane = [[NSView alloc] initWithFrame: NSMakeRect(0,0,600,400)];2.8 + NSView *pane = [[NSView alloc] initWithFrame: NSMakeRect(0,0,640,400)];2.9 return pane;2.10 }2.12 @@ -184,7 +184,7 @@2.13 void cocoa_gui_show_preferences()2.14 {2.15 if( prefs_panel == NULL ) {2.16 - prefs_panel = [[LxdreamPrefsPanel alloc] initWithContentRect: NSMakeRect(0,0,600,400)];2.17 + prefs_panel = [[LxdreamPrefsPanel alloc] initWithContentRect: NSMakeRect(0,0,640,400)];2.18 }2.19 [prefs_panel makeKeyAndOrderFront: prefs_panel];2.20 }2.21 \ No newline at end of file
3.1 --- a/src/display.c Sun Sep 07 11:08:10 2008 +00003.2 +++ b/src/display.c Mon Sep 08 05:13:51 2008 +00003.3 @@ -94,7 +94,6 @@3.4 */3.5 static struct keymap_entry *root_keymap[65535];3.6 static struct keymap_entry *keyhooks = NULL;3.7 -static struct mouse_entry *mousehooks = NULL;3.8 static gboolean display_focused = TRUE;3.9 static GList *input_drivers= NULL;3.10 static display_keysym_callback_t display_keysym_hook = NULL;3.11 @@ -169,6 +168,7 @@3.12 return NULL;3.13 }3.14 return &root_keymap[keycode-1];3.15 +3.16 } else {3.17 char *id = g_strstrip(strv[0]);3.18 GList *ptr;3.19 @@ -284,7 +284,7 @@3.20 g_strfreev(strv);3.21 }3.23 -gboolean input_register_hook( input_key_callback_t callback,3.24 +gboolean input_register_keyboard_hook( input_key_callback_t callback,3.25 void *data )3.26 {3.27 keymap_entry_t key = malloc( sizeof( struct keymap_entry ) );3.28 @@ -296,7 +296,7 @@3.29 return TRUE;3.30 }3.32 -void input_unregister_hook( input_key_callback_t callback,3.33 +void input_unregister_keyboard_hook( input_key_callback_t callback,3.34 void *data )3.35 {3.36 keymap_entry_t key = keyhooks;3.37 @@ -318,6 +318,97 @@3.38 }3.39 }3.41 +gboolean input_is_key_valid( const gchar *keysym )3.42 +{3.43 + keymap_entry_t *ptr = input_entry_from_keysym(keysym);3.44 + return ptr != NULL;3.45 +}3.46 +3.47 +gboolean input_is_key_registered( const gchar *keysym )3.48 +{3.49 + keymap_entry_t *ptr = input_entry_from_keysym(keysym);3.50 + return ptr != NULL && *ptr != NULL;3.51 +}3.52 +3.53 +void input_event_keydown( input_driver_t driver, uint16_t keycode, uint32_t pressure )3.54 +{3.55 + if( display_focused ) {3.56 + keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);3.57 + if( entryp != NULL && *entryp != NULL ) {3.58 + (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, TRUE );3.59 + }3.60 + if( driver == NULL ) {3.61 + keymap_entry_t key = keyhooks;3.62 + while( key != NULL ) {3.63 + key->callback( key->data, keycode, pressure, TRUE );3.64 + key = key->next;3.65 + }3.66 + }3.67 + }3.68 + if( display_keysym_hook != NULL ) {3.69 + gchar *sym = input_keycode_to_keysym( driver, keycode );3.70 + if( sym != NULL ) {3.71 + display_keysym_hook(display_keysym_hook_data, sym);3.72 + g_free(sym);3.73 + }3.74 + }3.75 +}3.76 +3.77 +void input_event_keyup( input_driver_t driver, uint16_t keycode, uint32_t pressure )3.78 +{3.79 + if( display_focused ) {3.80 + keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);3.81 + if( entryp != NULL && *entryp != NULL ) {3.82 + (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, FALSE );3.83 + }3.84 +3.85 + if( driver == NULL ) {3.86 + keymap_entry_t key = keyhooks;3.87 + while( key != NULL ) {3.88 + key->callback( key->data, keycode, pressure, FALSE );3.89 + key = key->next;3.90 + }3.91 + }3.92 + }3.93 +}3.94 +3.95 +uint16_t input_keycode_to_dckeysym( uint16_t keycode )3.96 +{3.97 + return display_driver->convert_to_dckeysym(keycode);3.98 +}3.99 +3.100 +void input_set_keysym_hook( display_keysym_callback_t hook, void *data )3.101 +{3.102 + display_keysym_hook = hook;3.103 + display_keysym_hook_data = data;3.104 +}3.105 +3.106 +/***************** System mouse driver ****************/3.107 +3.108 +static struct keymap_entry *mouse_keymap[MAX_MOUSE_BUTTONS];3.109 +static struct mouse_entry *mousehooks = NULL;3.110 +static uint32_t mouse_x = -1, mouse_y = -1, mouse_buttons = 0;3.111 +3.112 +uint16_t mouse_resolve_keysym( struct input_driver *driver, const gchar *keysym )3.113 +{3.114 + if( strncasecmp( keysym, "Button", 6 ) == 0 ){3.115 + unsigned long button = strtoul( keysym+6, NULL, 10 );3.116 + if( button > MAX_MOUSE_BUTTONS ) {3.117 + return 0;3.118 + }3.119 + return (uint16_t)button;3.120 + }3.121 + return 0;3.122 +}3.123 +3.124 +gchar *mouse_get_keysym( struct input_driver *driver, uint16_t keycode )3.125 +{3.126 + return g_strdup_printf( "Button%d", (keycode) );3.127 +}3.128 +3.129 +struct input_driver system_mouse_driver = { "Mouse", mouse_resolve_keysym, NULL, mouse_get_keysym, NULL };3.130 +3.131 +3.132 gboolean input_register_mouse_hook( gboolean relative, input_mouse_callback_t callback,3.133 void *data )3.134 {3.135 @@ -351,7 +442,7 @@3.136 }3.137 }3.139 -void input_event_mouse( uint32_t buttons, int32_t x, int32_t y, gboolean absolute )3.140 +void input_event_run_mouse_hooks( uint32_t buttons, int32_t x, int32_t y, gboolean absolute )3.141 {3.142 mouse_entry_t ent = mousehooks;3.143 while( ent != NULL ) {3.144 @@ -360,60 +451,38 @@3.145 }3.146 }3.148 -gboolean input_is_key_valid( const gchar *keysym )3.149 +void input_event_mousedown( uint16_t button, int32_t x, int32_t y, gboolean absolute )3.150 {3.151 - keymap_entry_t *ptr = input_entry_from_keysym(keysym);3.152 - return ptr != NULL;3.153 + if( absolute ) {3.154 + mouse_x = x;3.155 + mouse_y = y;3.156 + }3.157 + mouse_buttons |= (1<<button);3.158 + input_event_keydown( &system_mouse_driver, button+1, 1 );3.159 + input_event_run_mouse_hooks( mouse_buttons, x, y, absolute );3.160 +}3.161 +3.162 +void input_event_mouseup( uint16_t button, int32_t x, int32_t y, gboolean absolute )3.163 +{3.164 + if( absolute ) {3.165 + mouse_x = x;3.166 + mouse_y = y;3.167 + }3.168 + mouse_buttons &= ~(1<<button);3.169 + input_event_keyup( &system_mouse_driver, button+1, 1 );3.170 + input_event_run_mouse_hooks( mouse_buttons, x, y, absolute );3.171 }3.173 -gboolean input_is_key_registered( const gchar *keysym )3.174 +void input_event_mousemove( int32_t x, int32_t y, gboolean absolute )3.175 {3.176 - keymap_entry_t *ptr = input_entry_from_keysym(keysym);3.177 - return ptr != NULL && *ptr != NULL;3.178 + if( absolute ) {3.179 + mouse_x = x;3.180 + mouse_y = y;3.181 + }3.182 + input_event_run_mouse_hooks( mouse_buttons, x, y, absolute );3.183 }3.185 -void input_event_keydown( input_driver_t driver, uint16_t keycode, uint32_t pressure )3.186 -{3.187 - if( display_focused ) {3.188 - keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);3.189 - if( entryp != NULL && *entryp != NULL ) {3.190 - (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, TRUE );3.191 - }3.192 - keymap_entry_t key = keyhooks;3.193 - while( key != NULL ) {3.194 - key->callback( key->data, keycode, pressure, TRUE );3.195 - key = key->next;3.196 - }3.197 - }3.198 - if( display_keysym_hook != NULL ) {3.199 - gchar *sym = input_keycode_to_keysym( driver, keycode );3.200 - if( sym != NULL ) {3.201 - display_keysym_hook(display_keysym_hook_data, sym);3.202 - g_free(sym);3.203 - }3.204 - }3.205 -}3.206 -3.207 -void input_event_keyup( input_driver_t driver, uint16_t keycode, uint32_t pressure )3.208 -{3.209 - if( display_focused ) {3.210 - keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);3.211 - if( entryp != NULL && *entryp != NULL ) {3.212 - (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, FALSE );3.213 - }3.214 -3.215 - keymap_entry_t key = keyhooks;3.216 - while( key != NULL ) {3.217 - key->callback( key->data, keycode, pressure, FALSE );3.218 - key = key->next;3.219 - }3.220 - }3.221 -}3.222 -3.223 -uint16_t input_keycode_to_dckeysym( uint16_t keycode )3.224 -{3.225 - return display_driver->convert_to_dckeysym(keycode);3.226 -}3.227 +/************************ Main display driver *************************/3.229 void print_display_drivers( FILE *out )3.230 {3.231 @@ -450,7 +519,9 @@3.232 display_driver = driver;3.233 if( driver->init_driver != NULL )3.234 rv = driver->init_driver();3.235 - if( !rv ) {3.236 + if( rv ) {3.237 + input_register_device(&system_mouse_driver, MAX_MOUSE_BUTTONS);3.238 + } else {3.239 display_driver = NULL;3.240 }3.241 return rv;3.242 @@ -460,9 +531,3 @@3.243 {3.244 display_focused = has_focus;3.245 }3.246 -3.247 -void input_set_keysym_hook( display_keysym_callback_t hook, void *data )3.248 -{3.249 - display_keysym_hook = hook;3.250 - display_keysym_hook_data = data;3.251 -}
4.1 --- a/src/display.h Sun Sep 07 11:08:10 2008 +00004.2 +++ b/src/display.h Mon Sep 08 05:13:51 2008 +00004.3 @@ -213,6 +213,8 @@4.5 /****************** Input methods **********************/4.7 +#define MAX_MOUSE_BUTTONS 324.8 +4.9 typedef void (*input_key_callback_t)( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown );4.11 /**4.12 @@ -236,10 +238,10 @@4.13 void *data, uint32_t value );4.15 /**4.16 - * Register a hook to receive all input events4.17 + * Register a hook to receive all keyboard input events4.18 */4.19 -gboolean input_register_hook( input_key_callback_t callback, void *data );4.20 -void input_unregister_hook( input_key_callback_t callback, void *data );4.21 +gboolean input_register_keyboard_hook( input_key_callback_t callback, void *data );4.22 +void input_unregister_keyboard_hook( input_key_callback_t callback, void *data );4.24 /**4.25 * Register a mouse event hook.4.26 @@ -292,6 +294,8 @@4.28 } *input_driver_t;4.30 +extern struct input_driver system_mouse_driver;4.31 +4.32 /**4.33 * Register a new input driver (which must have a unique name)4.34 * @param driver the driver to register4.35 @@ -326,15 +330,36 @@4.36 void input_event_keyup( input_driver_t input, uint16_t keycode, uint32_t pressure );4.38 /**4.39 - * Receive an input mouse event. Normally these should be absolute events when4.40 + * Receive an input mouse down event. Normally these should be absolute events when4.41 * the mouse is not grabbed, and relative when it is.4.42 - * @param buttons a bitmask of buttons currently held now (bit 0 = button 1, bit 1 = button 2, etc)4.43 + * @param button the button pressed, where 0 == first button4.44 * @param x_axis The relative or absolute position of the mouse cursor on the X axis4.45 * @param y_axis The relative or absolute position of the mouse cursor on the Y axis4.46 * @param absolute If TRUE, x_axis and y_axis are the current window coordinates4.47 * of the mouse cursor. Otherwise, x_axis and y_axis are deltas from the previous mouse position.4.48 */4.49 -void input_event_mouse( uint32_t buttons, int32_t x_axis, int32_t y_axis, gboolean absolute );4.50 +void input_event_mousedown( uint16_t button, int32_t x_axis, int32_t y_axis, gboolean absolute );4.51 +4.52 +/**4.53 + * Receive an input mouse up event. Normally these should be absolute events when4.54 + * the mouse is not grabbed, and relative when it is.4.55 + * @param button the button released, where 0 == first button4.56 + * @param x_axis The relative or absolute position of the mouse cursor on the X axis4.57 + * @param y_axis The relative or absolute position of the mouse cursor on the Y axis4.58 + * @param absolute If TRUE, x_axis and y_axis are the current window coordinates4.59 + * of the mouse cursor. Otherwise, x_axis and y_axis are deltas from the previous mouse position.4.60 + */4.61 +void input_event_mouseup( uint16_t button, int32_t x_axis, int32_t y_axis, gboolean absolute );4.62 +4.63 +/**4.64 + * Receive an input mouse motion event. Normally these should be absolute events when4.65 + * the mouse is not grabbed, and relative when it is.4.66 + * @param x_axis The relative or absolute position of the mouse cursor on the X axis4.67 + * @param y_axis The relative or absolute position of the mouse cursor on the Y axis4.68 + * @param absolute If TRUE, x_axis and y_axis are the current window coordinates4.69 + * of the mouse cursor. Otherwise, x_axis and y_axis are deltas from the previous mouse position.4.70 + */4.71 +void input_event_mousemove( int32_t x_axis, int32_t y_axis, gboolean absolute );4.73 /**4.74 * Given a keycode and the originating input driver, return the corresponding
5.1 --- a/src/gtkui/gtk_ctrl.c Sun Sep 07 11:08:10 2008 +00005.2 +++ b/src/gtkui/gtk_ctrl.c Mon Sep 08 05:13:51 2008 +00005.3 @@ -60,7 +60,14 @@5.4 static gboolean config_key_buttonpress( GtkWidget *widget, GdkEventButton *event, gpointer user_data )5.5 {5.6 gboolean keypress_mode = GPOINTER_TO_INT(g_object_get_data( G_OBJECT(widget), "keypress_mode"));5.7 - if( !keypress_mode ) {5.8 + if( keypress_mode ) {5.9 + gchar *keysym = input_keycode_to_keysym( &system_mouse_driver, event->button);5.10 + if( keysym != NULL ) {5.11 + config_keysym_hook( widget, keysym );5.12 + g_free(keysym);5.13 + }5.14 + return TRUE;5.15 + } else {5.16 gtk_entry_set_text( GTK_ENTRY(widget), _("<press key>") );5.17 g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(TRUE) );5.18 input_set_keysym_hook(config_keysym_hook, widget);
6.1 --- a/src/gtkui/gtk_win.c Sun Sep 07 11:08:10 2008 +00006.2 +++ b/src/gtkui/gtk_win.c Mon Sep 08 05:13:51 2008 +00006.3 @@ -132,9 +132,10 @@6.4 int32_t y = (int32_t)event->y;6.5 if( win->is_grabbed &&6.6 (x != win->mouse_x || y != win->mouse_y) ) {6.7 - uint32_t buttons = (event->state >> 8)&0x1F;6.8 - input_event_mouse( buttons, x - win->mouse_x, y - win->mouse_y, FALSE );6.9 + input_event_mousemove( x - win->mouse_x, y - win->mouse_y, FALSE );6.10 video_window_center_pointer(win);6.11 + } else {6.12 + input_event_mousemove( x, y, TRUE );6.13 }6.14 return TRUE;6.15 }6.16 @@ -143,12 +144,10 @@6.17 gpointer user_data )6.18 {6.19 main_window_t win = (main_window_t)user_data;6.20 - // Get the buttons from the event state, and add the pressed button6.21 - uint32_t buttons = ((event->state >> 8) & 0x1F) | (1<<(event->button-1));6.22 if( win->is_grabbed ) {6.23 - input_event_mouse( buttons, 0, 0, FALSE );6.24 + input_event_mousedown( event->button-1, 0, 0, FALSE );6.25 } else {6.26 - input_event_mouse( buttons, (int)event->x, (int)event->y, TRUE );6.27 + input_event_mousedown( event->button-1, (int32_t)event->x, (int32_t)event->y, TRUE );6.28 }6.29 return TRUE;6.30 }6.31 @@ -157,14 +156,12 @@6.32 gpointer user_data )6.33 {6.34 main_window_t win = (main_window_t)user_data;6.35 - // Get the buttons from the event state, and remove the released button6.36 - uint32_t buttons = ((event->state >> 8) & 0x1F) & (~(1<<(event->button-1)));6.37 if( win->is_grabbed ) {6.38 - input_event_mouse( buttons, 0, 0, FALSE );6.39 + input_event_mouseup( event->button-1, 0, 0, FALSE );6.40 } else if( win->use_grab) {6.41 video_window_grab_display(win);6.42 } else {6.43 - input_event_mouse( buttons, (int)event->x, (int)event->y, TRUE );6.44 + input_event_mouseup( event->button-1, (int32_t)event->x, (int32_t)event->y, TRUE );6.45 }6.46 return TRUE;6.47 }
7.1 --- a/src/maple/kbd.c Sun Sep 07 11:08:10 2008 +00007.2 +++ b/src/maple/kbd.c Mon Sep 08 05:13:51 2008 +00007.3 @@ -140,12 +140,12 @@7.4 */7.5 void keyboard_attach( maple_device_t mdev )7.6 {7.7 - input_register_hook( keyboard_input_hook, mdev );7.8 + input_register_keyboard_hook( keyboard_input_hook, mdev );7.9 }7.11 void keyboard_detach( maple_device_t mdev )7.12 {7.13 - input_unregister_hook( keyboard_input_hook, mdev );7.14 + input_unregister_keyboard_hook( keyboard_input_hook, mdev );7.15 }
.