Search
lxdream.org :: lxdream :: r839:51f1c4195790
lxdream 0.9.1
released Jun 29
Download Now
changeset839:51f1c4195790
parent838:9abb2fa58934
child840:c6a778c228a6
authornkeynes
dateTue Sep 02 03:34:00 2008 +0000 (11 years ago)
Implement absolute positioning mouse mode when not grabbed
enable/disable grab on dreamcast start/stop where it's requested
by the controllers
src/cocoaui/cocoa_win.c
src/cocoaui/cocoaui.c
src/cocoaui/cocoaui.h
src/display.c
src/display.h
src/dreamcast.c
src/drivers/video_osx.c
src/gtkui/gtk_win.c
src/gtkui/gtkui.c
src/gui.h
src/maple/mouse.c
1.1 --- a/src/cocoaui/cocoa_win.c Tue Sep 02 00:42:43 2008 +0000
1.2 +++ b/src/cocoaui/cocoa_win.c Tue Sep 02 03:34:00 2008 +0000
1.3 @@ -132,6 +132,7 @@
1.4 backing: NSBackingStoreBuffered defer: NO ] == nil ) {
1.5 return nil;
1.6 } else {
1.7 + useGrab = NO;
1.8 isGrabbed = NO;
1.9 video = (LxdreamVideoView *)video_osx_create_drawable();
1.10 [video setFrameOrigin: NSMakePoint(0.0,STATUSBAR_HEIGHT)];
1.11 @@ -222,13 +223,27 @@
1.12 [video setIsGrabbed: isGrabbed];
1.13 }
1.14 }
1.15 -- (void)viewRequestedGrab: (id)sender
1.16 +- (void)setUseGrab:(BOOL)grab
1.17 {
1.18 - [self setIsGrabbed: YES];
1.19 + if( grab != useGrab ) {
1.20 + if( !grab && isGrabbed ) {
1.21 + [self setIsGrabbed: NO];
1.22 + }
1.23 + useGrab = grab;
1.24 + }
1.25 }
1.26 -- (void)viewRequestedUngrab: (id)sender
1.27 +
1.28 +- (id)viewRequestedGrab: (id)sender
1.29 +{
1.30 + if( useGrab ) {
1.31 + [self setIsGrabbed: YES];
1.32 + }
1.33 + return useGrab ? self : nil;
1.34 +}
1.35 +- (id)viewRequestedUngrab: (id)sender
1.36 {
1.37 [self setIsGrabbed: NO];
1.38 + return useGrab ? self : nil;
1.39 }
1.40 @end
1.41
2.1 --- a/src/cocoaui/cocoaui.c Tue Sep 02 00:42:43 2008 +0000
2.2 +++ b/src/cocoaui/cocoaui.c Tue Sep 02 03:34:00 2008 +0000
2.3 @@ -64,6 +64,7 @@
2.4 LxdreamMainWindow *window = (LxdreamMainWindow *)user_data;
2.5 [window updateTitle];
2.6 [pool release];
2.7 + return TRUE;
2.8 }
2.9
2.10 /**
2.11 @@ -335,6 +336,11 @@
2.12 cocoa_gui_update();
2.13 }
2.14
2.15 +void gui_set_use_grab( gboolean grab )
2.16 +{
2.17 + [((LxdreamMainWindow *)[NSApp mainWindow]) setUseGrab: (grab ? YES : NO)];
2.18 +}
2.19 +
2.20 gboolean gui_error_dialog( const char *msg, ... )
2.21 {
2.22 if( cocoa_gui_is_running ) {
3.1 --- a/src/cocoaui/cocoaui.h Tue Sep 02 00:42:43 2008 +0000
3.2 +++ b/src/cocoaui/cocoaui.h Tue Sep 02 03:34:00 2008 +0000
3.3 @@ -61,6 +61,7 @@
3.4 LxdreamVideoView *video;
3.5 NSTextField *status;
3.6 BOOL isGrabbed;
3.7 + BOOL useGrab;
3.8 }
3.9 - (id)initWithContentRect:(NSRect)contentRect;
3.10 - (void)setStatusText:(const gchar *)text;
3.11 @@ -68,6 +69,7 @@
3.12 - (void)setRunning:(BOOL)isRunning;
3.13 - (BOOL)isGrabbed;
3.14 - (void)setIsGrabbed:(BOOL)grab;
3.15 +- (void)setUseGrab: (BOOL)grab;
3.16 @end
3.17
3.18 @interface LxdreamPrefsPane : NSView
4.1 --- a/src/display.c Tue Sep 02 00:42:43 2008 +0000
4.2 +++ b/src/display.c Tue Sep 02 03:34:00 2008 +0000
4.3 @@ -351,11 +351,11 @@
4.4 }
4.5 }
4.6
4.7 -void input_event_mouse( uint32_t buttons, int32_t x, int32_t y )
4.8 +void input_event_mouse( uint32_t buttons, int32_t x, int32_t y, gboolean absolute )
4.9 {
4.10 mouse_entry_t ent = mousehooks;
4.11 while( ent != NULL ) {
4.12 - ent->callback(ent->data, buttons, x, y);
4.13 + ent->callback(ent->data, buttons, x, y, absolute);
4.14 ent = ent->next;
4.15 }
4.16 }
5.1 --- a/src/display.h Tue Sep 02 00:42:43 2008 +0000
5.2 +++ b/src/display.h Tue Sep 02 03:34:00 2008 +0000
5.3 @@ -224,8 +224,10 @@
5.4 * (in absolute mode).
5.5 * @param y Vertical movement since the last invocation (in relative mode) or window position
5.6 * (in absolute mode).
5.7 + * @param absolute If TRUE, x and y are the current window coordinates
5.8 + * of the mouse cursor. Otherwise, x and y are deltas from the previous mouse position.
5.9 */
5.10 -typedef void (*input_mouse_callback_t)( void *data, uint32_t buttons, int32_t x, int32_t y );
5.11 +typedef void (*input_mouse_callback_t)( void *data, uint32_t buttons, int32_t x, int32_t y, gboolean absolute );
5.12
5.13 gboolean input_register_key( const gchar *keysym, input_key_callback_t callback,
5.14 void *data, uint32_t value );
5.15 @@ -323,7 +325,16 @@
5.16
5.17 void input_event_keyup( input_driver_t input, uint16_t keycode, uint32_t pressure );
5.18
5.19 -void input_event_mouse( uint32_t buttons, int32_t x_axis, int32_t y_axis );
5.20 +/**
5.21 + * Receive an input mouse event. Normally these should be absolute events when
5.22 + * the mouse is not grabbed, and relative when it is.
5.23 + * @param buttons a bitmask of buttons currently held now (bit 0 = button 1, bit 1 = button 2, etc)
5.24 + * @param x_axis The relative or absolute position of the mouse cursor on the X axis
5.25 + * @param y_axis The relative or absolute position of the mouse cursor on the Y axis
5.26 + * @param absolute If TRUE, x_axis and y_axis are the current window coordinates
5.27 + * of the mouse cursor. Otherwise, x_axis and y_axis are deltas from the previous mouse position.
5.28 + */
5.29 +void input_event_mouse( uint32_t buttons, int32_t x_axis, int32_t y_axis, gboolean absolute );
5.30
5.31 /**
5.32 * Given a keycode and the originating input driver, return the corresponding
6.1 --- a/src/dreamcast.c Tue Sep 02 00:42:43 2008 +0000
6.2 +++ b/src/dreamcast.c Tue Sep 02 03:34:00 2008 +0000
6.3 @@ -170,6 +170,10 @@
6.4 modules[i]->start();
6.5 }
6.6 }
6.7 +
6.8 + if( maple_should_grab() ) {
6.9 + gui_set_use_grab(TRUE);
6.10 + }
6.11
6.12 dreamcast_state = STATE_RUNNING;
6.13
6.14 @@ -203,6 +207,8 @@
6.15 }
6.16 }
6.17
6.18 + gui_set_use_grab(FALSE);
6.19 +
6.20 for( i=0; i<num_modules; i++ ) {
6.21 if( modules[i]->stop != NULL )
6.22 modules[i]->stop();
7.1 --- a/src/drivers/video_osx.c Tue Sep 02 00:42:43 2008 +0000
7.2 +++ b/src/drivers/video_osx.c Tue Sep 02 03:34:00 2008 +0000
7.3 @@ -95,15 +95,17 @@
7.4 }
7.5 return nil;
7.6 }
7.7 -- (void)requestGrab
7.8 +- (BOOL)requestGrab
7.9 {
7.10 if( delegate && [delegate respondsToSelector: @selector(viewRequestedGrab:)] )
7.11 - [delegate performSelector: @selector(viewRequestedGrab:) withObject: self];
7.12 + return [delegate performSelector: @selector(viewRequestedGrab:) withObject: self] != nil;
7.13 + return NO;
7.14 }
7.15 -- (void)requestUngrab
7.16 +- (BOOL)requestUngrab
7.17 {
7.18 if( delegate && [delegate respondsToSelector: @selector(viewRequestedUngrab:)] )
7.19 - [delegate performSelector: @selector(viewRequestedUngrab:) withObject: self];
7.20 + return [delegate performSelector: @selector(viewRequestedUngrab:) withObject: self] != nil;
7.21 + return NO;
7.22 }
7.23 - (BOOL)isOpaque
7.24 {
7.25 @@ -153,63 +155,73 @@
7.26 flagsMask[keycode] = 0;
7.27 }
7.28 }
7.29 +- (void)emitButtonEvent: (NSEvent *)event buttons: (int)buttons
7.30 +{
7.31 + if( isGrabbed ) {
7.32 + input_event_mouse( buttons, 0, 0, FALSE );
7.33 + } else {
7.34 + NSPoint pt = [event locationInWindow];
7.35 + input_event_mouse( buttonMask, (int)pt.x, (int)pt.y, TRUE );
7.36 + }
7.37 +}
7.38 +
7.39 - (void)mouseDown: (NSEvent *) event
7.40 {
7.41 - if( isGrabbed ) {
7.42 - buttonMask |= 1;
7.43 - input_event_mouse( buttonMask, 0, 0 );
7.44 - } else {
7.45 - [self requestGrab];
7.46 + buttonMask |= 1;
7.47 + // If using grab but not grabbed yet, the first click should be consumed
7.48 + // by the grabber. In all other circumstances we process normally.
7.49 + if( isGrabbed || ![self requestGrab] ) {
7.50 + [self emitButtonEvent: event buttons: buttonMask];
7.51 }
7.52 }
7.53 - (void)mouseUp: (NSEvent *)event
7.54 {
7.55 buttonMask &= ~1;
7.56 - input_event_mouse( buttonMask, 0, 0 );
7.57 + [self emitButtonEvent: event buttons: buttonMask];
7.58 }
7.59
7.60 - (void)rightMouseDown: (NSEvent *) event
7.61 {
7.62 buttonMask |= 2;
7.63 - input_event_mouse( buttonMask, 0, 0 );
7.64 + [self emitButtonEvent: event buttons: buttonMask];
7.65 }
7.66 - (void)rightMouseUp: (NSEvent *)event
7.67 {
7.68 buttonMask &= ~2;
7.69 - input_event_mouse( buttonMask, 0, 0 );
7.70 + [self emitButtonEvent: event buttons: buttonMask];
7.71 }
7.72 - (void)otherMouseDown: (NSEvent *) event
7.73 {
7.74 buttonMask |= (1<< [event buttonNumber] );
7.75 - input_event_mouse( buttonMask, 0, 0 );
7.76 + [self emitButtonEvent: event buttons: buttonMask];
7.77 }
7.78 - (void)otherMouseUp: (NSEvent *) event
7.79 {
7.80 buttonMask &= ~(1<< [event buttonNumber] );
7.81 - input_event_mouse( buttonMask, 0, 0 );
7.82 + [self emitButtonEvent: event buttons: buttonMask];
7.83 }
7.84 - (void)mouseMoved: (NSEvent *) event
7.85 {
7.86 if( isGrabbed ) {
7.87 - input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE );
7.88 + input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE, FALSE );
7.89 }
7.90 }
7.91 - (void)mouseDragged: (NSEvent *) event
7.92 {
7.93 if( isGrabbed ) {
7.94 - input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE );
7.95 + input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE, FALSE );
7.96 }
7.97 }
7.98 - (void)rightMouseDragged: (NSEvent *) event
7.99 {
7.100 if( isGrabbed ) {
7.101 - input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE );
7.102 + input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE, FALSE );
7.103 }
7.104 }
7.105 - (void)otherMouseDragged: (NSEvent *) event
7.106 {
7.107 if( isGrabbed ) {
7.108 - input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE );
7.109 + input_event_mouse( buttonMask, [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE, FALSE );
7.110 }
7.111 }
7.112
8.1 --- a/src/gtkui/gtk_win.c Tue Sep 02 00:42:43 2008 +0000
8.2 +++ b/src/gtkui/gtk_win.c Tue Sep 02 03:34:00 2008 +0000
8.3 @@ -33,6 +33,7 @@
8.4 #include "lxdream.h"
8.5 #include "dreamcast.h"
8.6 #include "display.h"
8.7 +#include "gdrom/gdrom.h"
8.8 #include "gtkui/gtkui.h"
8.9
8.10
8.11 @@ -51,6 +52,13 @@
8.12
8.13 /******************** Video window **************************/
8.14
8.15 +#if !(GTK_CHECK_VERSION(2,8,0))
8.16 +void gdk_display_warp_pointer (GdkDisplay *display,
8.17 + GdkScreen *screen,
8.18 + gint x,
8.19 + gint y);
8.20 +#endif
8.21 +
8.22 /**
8.23 * Adjust the mouse pointer so that it appears in the center of the video
8.24 * window. Mainly used for when we have the mouse grab
8.25 @@ -125,7 +133,7 @@
8.26 if( win->is_grabbed &&
8.27 (x != win->mouse_x || y != win->mouse_y) ) {
8.28 uint32_t buttons = (event->state >> 8)&0x1F;
8.29 - input_event_mouse( buttons, x - win->mouse_x, y - win->mouse_y );
8.30 + input_event_mouse( buttons, x - win->mouse_x, y - win->mouse_y, FALSE );
8.31 video_window_center_pointer(win);
8.32 }
8.33 return TRUE;
8.34 @@ -135,10 +143,12 @@
8.35 gpointer user_data )
8.36 {
8.37 main_window_t win = (main_window_t)user_data;
8.38 + // Get the buttons from the event state, and add the pressed button
8.39 + uint32_t buttons = ((event->state >> 8) & 0x1F) | (1<<(event->button-1));
8.40 if( win->is_grabbed ) {
8.41 - // Get the buttons from the event state, and remove the released button
8.42 - uint32_t buttons = ((event->state >> 8) & 0x1F) | (1<<(event->button-1));
8.43 - input_event_mouse( buttons, 0, 0 );
8.44 + input_event_mouse( buttons, 0, 0, FALSE );
8.45 + } else {
8.46 + input_event_mouse( buttons, (int)event->x, (int)event->y, TRUE );
8.47 }
8.48 return TRUE;
8.49 }
8.50 @@ -147,13 +157,15 @@
8.51 gpointer user_data )
8.52 {
8.53 main_window_t win = (main_window_t)user_data;
8.54 + // Get the buttons from the event state, and remove the released button
8.55 + uint32_t buttons = ((event->state >> 8) & 0x1F) & (~(1<<(event->button-1)));
8.56 if( win->is_grabbed ) {
8.57 - // Get the buttons from the event state, and remove the released button
8.58 - uint32_t buttons = ((event->state >> 8) & 0x1F) & (~(1<<(event->button-1)));
8.59 - input_event_mouse( buttons, 0, 0 );
8.60 + input_event_mouse( buttons, 0, 0, FALSE );
8.61 } else if( win->use_grab) {
8.62 video_window_grab_display(win);
8.63 - }
8.64 + } else {
8.65 + input_event_mouse( buttons, (int)event->x, (int)event->y, TRUE );
8.66 + }
8.67 return TRUE;
8.68 }
8.69
9.1 --- a/src/gtkui/gtkui.c Tue Sep 02 00:42:43 2008 +0000
9.2 +++ b/src/gtkui/gtkui.c Tue Sep 02 03:34:00 2008 +0000
9.3 @@ -198,6 +198,7 @@
9.4 gboolean gtk_gui_disc_changed( gdrom_disc_t disc, const gchar *disc_name, void *ptr )
9.5 {
9.6 main_window_update_title( main_win );
9.7 + return TRUE;
9.8 }
9.9
9.10 gboolean gui_init( gboolean withDebug )
9.11 @@ -232,7 +233,6 @@
9.12 GtkWidget *gdrommenu = gdrom_menu_new();
9.13 gtk_menu_item_set_submenu( GTK_MENU_ITEM(gdrommenuitem), gdrommenu );
9.14 main_win = main_window_new( lxdream_package_name, menubar, toolbar, accel_group );
9.15 - main_window_set_use_grab(main_win, TRUE);
9.16 if( withDebug ) {
9.17 gtk_gui_show_debugger();
9.18 }
9.19 @@ -260,6 +260,11 @@
9.20 gtk_gui_update();
9.21 }
9.22
9.23 +void gui_set_use_grab( gboolean flag )
9.24 +{
9.25 + main_window_set_use_grab(main_win, TRUE);
9.26 +}
9.27 +
9.28 gboolean gui_error_dialog( const char *msg, ... )
9.29 {
9.30 if( main_win != NULL ) {
10.1 --- a/src/gui.h Tue Sep 02 00:42:43 2008 +0000
10.2 +++ b/src/gui.h Tue Sep 02 03:34:00 2008 +0000
10.3 @@ -63,6 +63,13 @@
10.4 void gui_update_state();
10.5
10.6 /**
10.7 + * Notify the GUI to enable/disable mouse grabs according to the flag value.
10.8 + * If the parameter is FALSE and the grab is currently active, the GUI should
10.9 + * immediately cancel the grab.
10.10 + */
10.11 +void gui_set_use_grab( gboolean grab );
10.12 +
10.13 +/**
10.14 * Notify the GUI of I/O activity.
10.15 * @param activity the type of IO activity being reported.
10.16 * @param active TRUE if the I/O device is becoming active, FALSE if inactive.
11.1 --- a/src/maple/mouse.c Tue Sep 02 00:42:43 2008 +0000
11.2 +++ b/src/maple/mouse.c Tue Sep 02 03:34:00 2008 +0000
11.3 @@ -84,24 +84,26 @@
11.4 return MAPLE_DEVICE(dev);
11.5 }
11.6
11.7 -void mouse_input_callback( void *mdev, uint32_t buttons, int32_t x, int32_t y )
11.8 +void mouse_input_callback( void *mdev, uint32_t buttons, int32_t x, int32_t y, gboolean absolute )
11.9 {
11.10 mouse_device_t dev = (mouse_device_t)mdev;
11.11 - dev->buttons = 0xFF;
11.12 - if( buttons & 0x01 ) {
11.13 - dev->buttons &= ~BUTTON_LEFT;
11.14 + if( !absolute ) {
11.15 + dev->buttons = 0xFF;
11.16 + if( buttons & 0x01 ) {
11.17 + dev->buttons &= ~BUTTON_LEFT;
11.18 + }
11.19 + if( buttons & 0x02 ) {
11.20 + dev->buttons &= ~BUTTON_MIDDLE;
11.21 + }
11.22 + if( buttons & 0x04 ) {
11.23 + dev->buttons &= ~BUTTON_RIGHT;
11.24 + }
11.25 + if( buttons & 0x08 ) {
11.26 + dev->buttons &= ~BUTTON_THUMB;
11.27 + }
11.28 + dev->axis[0] += x;
11.29 + dev->axis[1] += y;
11.30 }
11.31 - if( buttons & 0x02 ) {
11.32 - dev->buttons &= ~BUTTON_MIDDLE;
11.33 - }
11.34 - if( buttons & 0x04 ) {
11.35 - dev->buttons &= ~BUTTON_RIGHT;
11.36 - }
11.37 - if( buttons & 0x08 ) {
11.38 - dev->buttons &= ~BUTTON_THUMB;
11.39 - }
11.40 - dev->axis[0] += x;
11.41 - dev->axis[1] += y;
11.42 }
11.43
11.44 void mouse_attach( maple_device_t dev )
.