Search
lxdream.org :: lxdream :: r1019:87f191f92f8f
lxdream 0.9.1
released Jun 29
Download Now
changeset1019:87f191f92f8f
parent1018:5942a162e5ef
child1020:04e622ab1635
authornkeynes
dateWed Jun 03 10:29:16 2009 +0000 (14 years ago)
Allow multiple input hooks to be registered for the same key - useful to allow
eg binding the same hotkey for run/stop so that it works as a toggle.
src/cocoaui/cocoaui.m
src/display.c
src/gtkui/gtkui.c
src/gui.h
src/hotkeys.c
1.1 --- a/src/cocoaui/cocoaui.m Wed Jun 03 04:08:59 2009 +0000
1.2 +++ b/src/cocoaui/cocoaui.m Wed Jun 03 10:29:16 2009 +0000
1.3 @@ -35,7 +35,6 @@
1.4 void cocoa_gui_update( void );
1.5 void cocoa_gui_start( void );
1.6 void cocoa_gui_stop( void );
1.7 -void cocoa_gui_run_later( void );
1.8 uint32_t cocoa_gui_run_slice( uint32_t nanosecs );
1.9
1.10 struct dreamcast_module cocoa_gui_module = { "gui", NULL,
1.11 @@ -179,7 +178,7 @@
1.12 {
1.13 if( cocoa_gui_autorun ) {
1.14 cocoa_gui_autorun = NO;
1.15 - gui_run_later();
1.16 + gui_do_later(dreamcast_run);
1.17 }
1.18 }
1.19 - (void)windowDidBecomeKey: (NSNotification *)notice
1.20 @@ -196,7 +195,7 @@
1.21 const gchar *cname = [filename UTF8String];
1.22 if( file_load_magic(cname) ) {
1.23 // Queue up a run event
1.24 - gui_run_later();
1.25 + gui_do_later(dreamcast_run);
1.26 return YES;
1.27 } else {
1.28 return NO;
1.29 @@ -274,14 +273,9 @@
1.30 - (void) run_action: (id)sender
1.31 {
1.32 if( !dreamcast_is_running() ) {
1.33 - gui_run_later();
1.34 + gui_do_later(dreamcast_run);
1.35 }
1.36 }
1.37 -- (void) run_immediate
1.38 -{
1.39 - dreamcast_run();
1.40 - [mainWindow setRunning: NO];
1.41 -}
1.42 - (void) gdrom_list_action: (id)sender
1.43 {
1.44 gdrom_list_set_selection( [sender tag] );
1.45 @@ -432,13 +426,33 @@
1.46 [mainWindow setRunning: NO];
1.47 }
1.48
1.49 +@interface DoLaterStub : NSObject
1.50 +{
1.51 + do_later_callback_t func;
1.52 +}
1.53 +@end
1.54 +
1.55 +@implementation DoLaterStub
1.56 +- (id) init: (do_later_callback_t)f
1.57 +{
1.58 + [super init];
1.59 + func = f;
1.60 + return self;
1.61 +}
1.62 +- (void) do
1.63 +{
1.64 + func();
1.65 +}
1.66 +@end
1.67 +
1.68 /**
1.69 * Queue a dreamcast_run() to execute after the currently event(s)
1.70 */
1.71 -void gui_run_later( void )
1.72 +void gui_do_later( do_later_callback_t func )
1.73 {
1.74 - [[NSRunLoop currentRunLoop] performSelector: @selector(run_immediate)
1.75 - target: [NSApp delegate] argument: nil order: 1
1.76 + DoLaterStub *stub = [[[DoLaterStub alloc] init: func] autorelease];
1.77 + [[NSRunLoop currentRunLoop] performSelector: @selector(do)
1.78 + target: stub argument: nil order: 1
1.79 modes: [NSArray arrayWithObject: NSDefaultRunLoopMode] ];
1.80 }
1.81
2.1 --- a/src/display.c Wed Jun 03 04:08:59 2009 +0000
2.2 +++ b/src/display.c Wed Jun 03 10:29:16 2009 +0000
2.3 @@ -251,10 +251,12 @@
2.4 while( *s != NULL ) {
2.5 keymap_entry_t *entryp = input_entry_from_keysym(*s);
2.6 if( entryp != NULL ) {
2.7 - *entryp = g_malloc0(sizeof(struct keymap_entry));
2.8 - (*entryp)->callback = callback;
2.9 - (*entryp)->data = data;
2.10 - (*entryp)->value = value;
2.11 + keymap_entry_t newentry = g_malloc0(sizeof(struct keymap_entry));
2.12 + newentry->next = *entryp;
2.13 + newentry->callback = callback;
2.14 + newentry->data = data;
2.15 + newentry->value = value;
2.16 + *entryp = newentry;
2.17 keys++;
2.18 }
2.19 s++;
2.20 @@ -274,10 +276,17 @@
2.21 gchar **s = strv;
2.22 while( *s != NULL ) {
2.23 keymap_entry_t *entryp = input_entry_from_keysym(*s);
2.24 - if( entryp != NULL && *entryp != NULL && (*entryp)->callback == callback &&
2.25 - (*entryp)->data == data && (*entryp)->value == value ) {
2.26 - g_free( *entryp );
2.27 - *entryp = NULL;
2.28 + if( entryp != NULL ) {
2.29 + while( *entryp != NULL ) {
2.30 + if( (*entryp)->callback == callback &&
2.31 + (*entryp)->data == data && (*entryp)->value == value ) {
2.32 + keymap_entry_t next = (*entryp)->next;
2.33 + g_free( *entryp );
2.34 + *entryp = next;
2.35 + break;
2.36 + }
2.37 + entryp = &(*entryp)->next; // Yes, really
2.38 + }
2.39 }
2.40 s++;
2.41 }
2.42 @@ -334,8 +343,12 @@
2.43 {
2.44 if( display_focused ) {
2.45 keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
2.46 - if( entryp != NULL && *entryp != NULL ) {
2.47 - (*entryp)->callback( (*entryp)->data, (*entryp)->value, pressure, TRUE );
2.48 + if( entryp != NULL ) {
2.49 + keymap_entry_t key = *entryp;
2.50 + while( key != NULL ) {
2.51 + key->callback( key->data, key->value, pressure, TRUE );
2.52 + key = key->next;
2.53 + }
2.54 }
2.55 if( driver == NULL ) {
2.56 keymap_entry_t key = keyhooks;
2.57 @@ -358,8 +371,12 @@
2.58 {
2.59 if( display_focused ) {
2.60 keymap_entry_t *entryp = input_entry_from_keycode(driver,keycode);
2.61 - if( entryp != NULL && *entryp != NULL ) {
2.62 - (*entryp)->callback( (*entryp)->data, (*entryp)->value, 0, FALSE );
2.63 + if( entryp != NULL ) {
2.64 + keymap_entry_t key = *entryp;
2.65 + while( key != NULL ) {
2.66 + key->callback( key->data, key->value, 0, FALSE );
2.67 + key = key->next;
2.68 + }
2.69 }
2.70
2.71 if( driver == NULL ) {
3.1 --- a/src/gtkui/gtkui.c Wed Jun 03 04:08:59 2009 +0000
3.2 +++ b/src/gtkui/gtkui.c Wed Jun 03 10:29:16 2009 +0000
3.3 @@ -301,15 +301,16 @@
3.4
3.5 }
3.6
3.7 -static gboolean gtk_run_later_callback( gpointer unused )
3.8 +static gboolean gtk_do_later_callback( gpointer ptr )
3.9 {
3.10 - dreamcast_run();
3.11 + do_later_callback_t func = (do_later_callback_t)ptr;
3.12 + func();
3.13 return FALSE;
3.14 }
3.15
3.16 -void gui_run_later(void)
3.17 +void gui_do_later( do_later_callback_t func )
3.18 {
3.19 - g_timeout_add_seconds(0, gtk_run_later_callback, NULL);
3.20 + g_timeout_add_seconds(0, gtk_do_later_callback, func);
3.21 }
3.22
3.23 void gtk_gui_show_debugger()
4.1 --- a/src/gui.h Wed Jun 03 04:08:59 2009 +0000
4.2 +++ b/src/gui.h Wed Jun 03 10:29:16 2009 +0000
4.3 @@ -77,11 +77,12 @@
4.4 */
4.5 void gui_update_io_activity( io_activity_type activity, gboolean active );
4.6
4.7 +typedef void (*do_later_callback_t)(void);
4.8 /**
4.9 - * Queue an event to call dreamcast_run() at the next opportunity (used to
4.10 - * avoid invoking dreamcast_run() directly from the middle of things.
4.11 + * Queue an event to call a function at the next opportunity (used to
4.12 + * avoid invoking eg dreamcast_run directly from the middle of other processing).
4.13 */
4.14 -void gui_run_later(void);
4.15 +void gui_do_later( do_later_callback_t func );
4.16
4.17 #ifdef __cplusplus
4.18 }
5.1 --- a/src/hotkeys.c Wed Jun 03 04:08:59 2009 +0000
5.2 +++ b/src/hotkeys.c Wed Jun 03 10:29:16 2009 +0000
5.3 @@ -112,14 +112,14 @@
5.4 static void hotkey_resume_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
5.5 {
5.6 if (isKeyDown && !dreamcast_is_running() ) {
5.7 - gui_run_later();
5.8 + gui_do_later(dreamcast_run);
5.9 }
5.10 }
5.11
5.12 static void hotkey_stop_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
5.13 {
5.14 if (isKeyDown && dreamcast_is_running() ) {
5.15 - dreamcast_stop();
5.16 + gui_do_later(dreamcast_stop);
5.17 }
5.18 }
5.19
.