Event Handling Makeover

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@12461 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
nplourde 2004-05-12 20:47:14 +00:00
parent 10d5f3100c
commit dfcce55634
1 changed files with 158 additions and 167 deletions

View File

@ -10,16 +10,12 @@
MPlayer Mac OSX Quartz video out module. MPlayer Mac OSX Quartz video out module.
todo: -'plist' resource todo: -'plist' resource
-Redo event handling.
-Choose fullscreen display device (-xineramascreen / -multiscreen). -Choose fullscreen display device (-xineramascreen / -multiscreen).
-resize black bar without CGContext -resize black bar without CGContext
-rootwin -rootwin
-screen overlay output
-non-blocking event -non-blocking event
-(add sugestion here) -(add sugestion here)
Direct YUV support is functional, and is now enabled
by default. To constrain what format should be used,
use the format=XXX video filter (i.e. -vf format=uyvy).
*/ */
//SYS //SYS
@ -104,9 +100,7 @@ void window_resized();
void window_ontop(); void window_ontop();
void window_fullscreen(); void window_fullscreen();
static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); static OSStatus MainEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
static OSStatus MainKeyboardEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
static OSStatus MainMouseEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride)
{ {
@ -130,16 +124,20 @@ static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigne
} }
//default window event handler //default window event handler
static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) static OSStatus MainEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
{ {
OSStatus err = noErr; OSStatus err = noErr;
WindowRef window;
Rect rectPort = {0,0,0,0};
OSStatus result = eventNotHandledErr; OSStatus result = eventNotHandledErr;
UInt32 class = GetEventClass (event); UInt32 class = GetEventClass (event);
UInt32 kind = GetEventKind (event); UInt32 kind = GetEventKind (event);
if(class == kEventClassWindow)
{
WindowRef window;
Rect rectPort = {0,0,0,0};
GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
if(window) if(window)
{ {
GetWindowPortBounds (window, &rectPort); GetWindowPortBounds (window, &rectPort);
@ -149,7 +147,6 @@ static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef
{ {
//close window //close window
case kEventWindowClosed: case kEventWindowClosed:
HideWindow(window);
mplayer_put_key(KEY_ESC); mplayer_put_key(KEY_ESC);
break; break;
@ -163,19 +160,18 @@ static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef
err = eventNotHandledErr; err = eventNotHandledErr;
break; break;
} }
}
return err; else if(class == kEventClassKeyboard)
} {
char macCharCodes;
//keyboard event handler
static OSStatus MainKeyboardEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
{
OSStatus err = noErr;
UInt32 macKeyCode; UInt32 macKeyCode;
UInt32 macKeyModifiers;
GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(macCharCodes), NULL, &macCharCodes);
GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(macKeyCode), NULL, &macKeyCode); GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(macKeyCode), NULL, &macKeyCode);
GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(macKeyModifiers), NULL, &macKeyModifiers);
switch (GetEventKind (event)) switch (kind)
{ {
case kEventRawKeyDown: case kEventRawKeyDown:
{ {
@ -183,7 +179,6 @@ static OSStatus MainKeyboardEventHandler(EventHandlerCallRef nextHandler, EventR
{ {
case QZ_RETURN: mplayer_put_key(KEY_ENTER);break; case QZ_RETURN: mplayer_put_key(KEY_ENTER);break;
case QZ_ESCAPE: mplayer_put_key(KEY_ESC);break; case QZ_ESCAPE: mplayer_put_key(KEY_ESC);break;
case QZ_q: mplayer_put_key('q');break;
case QZ_F1: mplayer_put_key(KEY_F+1);break; case QZ_F1: mplayer_put_key(KEY_F+1);break;
case QZ_F2: mplayer_put_key(KEY_F+2);break; case QZ_F2: mplayer_put_key(KEY_F+2);break;
case QZ_F3: mplayer_put_key(KEY_F+3);break; case QZ_F3: mplayer_put_key(KEY_F+3);break;
@ -196,9 +191,6 @@ static OSStatus MainKeyboardEventHandler(EventHandlerCallRef nextHandler, EventR
case QZ_F10: mplayer_put_key(KEY_F+10);break; case QZ_F10: mplayer_put_key(KEY_F+10);break;
case QZ_F11: mplayer_put_key(KEY_F+11);break; case QZ_F11: mplayer_put_key(KEY_F+11);break;
case QZ_F12: mplayer_put_key(KEY_F+12);break; case QZ_F12: mplayer_put_key(KEY_F+12);break;
case QZ_o: mplayer_put_key('o');break;
case QZ_SPACE: mplayer_put_key(' ');break;
case QZ_p: mplayer_put_key('p');break;
//case QZ_7: mplayer_put_key(shift_key?'/':'7'); //case QZ_7: mplayer_put_key(shift_key?'/':'7');
//case QZ_PLUS: mplayer_put_key(shift_key?'*':'+'); //case QZ_PLUS: mplayer_put_key(shift_key?'*':'+');
case QZ_KP_PLUS: mplayer_put_key('+');break; case QZ_KP_PLUS: mplayer_put_key('+');break;
@ -211,9 +203,6 @@ static OSStatus MainKeyboardEventHandler(EventHandlerCallRef nextHandler, EventR
case QZ_DOWN: mplayer_put_key(KEY_DOWN);break; case QZ_DOWN: mplayer_put_key(KEY_DOWN);break;
case QZ_LEFT: mplayer_put_key(KEY_LEFT);break; case QZ_LEFT: mplayer_put_key(KEY_LEFT);break;
case QZ_RIGHT: mplayer_put_key(KEY_RIGHT);break; case QZ_RIGHT: mplayer_put_key(KEY_RIGHT);break;
//case QZ_LESS: mplayer_put_key(shift_key?'>':'<'); break;
//case QZ_GREATER: mplayer_put_key('>'); break;
//case QZ_ASTERISK:
case QZ_KP_MULTIPLY: mplayer_put_key('*'); break; case QZ_KP_MULTIPLY: mplayer_put_key('*'); break;
case QZ_SLASH: case QZ_SLASH:
case QZ_KP_DIVIDE: mplayer_put_key('/'); break; case QZ_KP_DIVIDE: mplayer_put_key('/'); break;
@ -231,48 +220,74 @@ static OSStatus MainKeyboardEventHandler(EventHandlerCallRef nextHandler, EventR
case QZ_KP_ENTER: mplayer_put_key(KEY_KPENTER); break; case QZ_KP_ENTER: mplayer_put_key(KEY_KPENTER); break;
case QZ_LEFTBRACKET: SetWindowAlpha(theWindow, winAlpha-=0.05);break; case QZ_LEFTBRACKET: SetWindowAlpha(theWindow, winAlpha-=0.05);break;
case QZ_RIGHTBRACKET: SetWindowAlpha(theWindow, winAlpha+=0.05);break; case QZ_RIGHTBRACKET: SetWindowAlpha(theWindow, winAlpha+=0.05);break;
case QZ_f: mplayer_put_key('f'); break;
case QZ_t: mplayer_put_key('T'); break; default:mplayer_put_key(macCharCodes);break;
default:
break;
} }
} }
break;
default: default:
err = eventNotHandledErr; err = eventNotHandledErr;
break; break;
} }
}
return err; else if(class == kEventClassMouse)
} {
//Mouse event handler
static OSStatus MainMouseEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
{
OSStatus err = noErr;
WindowPtr tmpWin; WindowPtr tmpWin;
Point mousePos; Point mousePos;
GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, 0, sizeof(Point), 0, &mousePos); GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, 0, sizeof(Point), 0, &mousePos);
switch (GetEventKind (event)) switch (kind)
{ {
case kEventMouseDown: case kEventMouseDown:
{ {
EventMouseButton button;
GetEventParameter(event, kEventParamMouseButton, typeMouseButton, 0, sizeof(EventMouseButton), 0, &button);
short part = FindWindow(mousePos,&tmpWin); short part = FindWindow(mousePos,&tmpWin);
if(part == inMenuBar) if(part == inMenuBar)
{ {
MenuSelect(mousePos); MenuSelect(mousePos);
HiliteMenu(0);
}
else if(part == inContent)
{
switch(button)
{
case 1: mplayer_put_key(MOUSE_BTN0);break;
case 2: mplayer_put_key(MOUSE_BTN2);break;
case 3: mplayer_put_key(MOUSE_BTN1);break;
default:break;
}
} }
} }
break; break;
case kEventMouseWheelMoved:
{
int wheel;
GetEventParameter(event, kEventParamMouseWheelDelta, typeSInt32, 0, sizeof(int), 0, &wheel);
short part = FindWindow(mousePos,&tmpWin);
if(part == inContent)
{
if(wheel > 0)
mplayer_put_key(MOUSE_BTN3);
else
mplayer_put_key(MOUSE_BTN4);
}
}
break;
default: default:
err = eventNotHandledErr; err = eventNotHandledErr;
break; break;
} }
}
HiliteMenu(0);
return err; return err;
} }
@ -341,14 +356,14 @@ static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32
CFRelease(windowTitle); CFRelease(windowTitle);
//Install event handler //Install event handler
const EventTypeSpec winEvents[] = { { kEventClassWindow, kEventWindowClosed }, { kEventClassWindow, kEventWindowBoundsChanged } }; const EventTypeSpec winEvents[] = { { kEventClassKeyboard, kEventRawKeyDown },
const EventTypeSpec keyEvents[] = { { kEventClassKeyboard, kEventRawKeyDown } }; { kEventClassMouse, kEventMouseDown },
const EventTypeSpec mouseEvents[] = { { kEventClassMouse, kEventMouseDown } }; { kEventClassMouse, kEventMouseWheelMoved },
{ kEventClassWindow, kEventWindowClosed },
InstallWindowEventHandler (theWindow, NewEventHandlerUPP (MainWindowEventHandler), GetEventTypeCount(winEvents), winEvents, theWindow, NULL); { kEventClassWindow, kEventWindowBoundsChanged } };
InstallWindowEventHandler (theWindow, NewEventHandlerUPP (MainKeyboardEventHandler), GetEventTypeCount(keyEvents), keyEvents, theWindow, NULL);
InstallApplicationEventHandler (NewEventHandlerUPP (MainMouseEventHandler), GetEventTypeCount(mouseEvents), mouseEvents, 0, NULL);
//InstallWindowEventHandler (theWindow, NewEventHandlerUPP (MainEventHandler), GetEventTypeCount(winEvents), winEvents, theWindow, NULL);
InstallApplicationEventHandler (NewEventHandlerUPP (MainEventHandler), GetEventTypeCount(winEvents), winEvents, 0, NULL);
if (!EnterMoviesDone) if (!EnterMoviesDone)
{ {
qterr = EnterMovies(); qterr = EnterMovies();
@ -779,8 +794,8 @@ static uint32_t control(uint32_t request, void *data, ...)
{ {
case VOCTRL_PAUSE: return (int_pause=1); case VOCTRL_PAUSE: return (int_pause=1);
case VOCTRL_RESUME: return (int_pause=0); case VOCTRL_RESUME: return (int_pause=0);
case VOCTRL_FULLSCREEN: window_fullscreen(); return VO_TRUE; case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); window_fullscreen(); return VO_TRUE;
case VOCTRL_ONTOP: window_ontop(); return VO_TRUE; case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); window_ontop(); return VO_TRUE;
case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data)); case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data));
case VOCTRL_GET_IMAGE: case VOCTRL_GET_IMAGE:
switch (image_format) switch (image_format)
@ -865,33 +880,19 @@ void window_ontop()
SetWindowClass( theWindow, kUtilityWindowClass); SetWindowClass( theWindow, kUtilityWindowClass);
else else
SetWindowClass( theWindow, kDocumentWindowClass); SetWindowClass( theWindow, kDocumentWindowClass);
vo_ontop = (!(vo_ontop));
} }
void window_fullscreen() void window_fullscreen()
{ {
static Rect oldRect; static Rect oldRect;
static Ptr *restoreState = nil;
short width=640;
short height=480;
RGBColor black={0,0,0};
GDHandle deviceHdl; GDHandle deviceHdl;
Rect deviceRect; Rect deviceRect;
//go fullscreen //go fullscreen
if(vo_fs) if(vo_fs)
{ {
//BeginFullScreen( &restoreState,nil,&width,&height,nil,&black,nil);
HideMenuBar(); HideMenuBar();
//Get Main device info///////////////////////////////////////////////////
deviceHdl = GetMainDevice();
deviceRect = (*deviceHdl)->gdRect;
device_width = deviceRect.right;
device_height = deviceRect.bottom;
//save old window size //save old window size
GetWindowPortBounds(theWindow, &oldRect); GetWindowPortBounds(theWindow, &oldRect);
@ -906,16 +907,8 @@ void window_fullscreen()
} }
else //go back to windowed mode else //go back to windowed mode
{ {
//EndFullScreen( restoreState,0);
ShowMenuBar(); ShowMenuBar();
//Get Main device info///////////////////////////////////////////////////
deviceHdl = GetMainDevice();
deviceRect = (*deviceHdl)->gdRect;
device_width = deviceRect.right;
device_height = deviceRect.bottom;
//show mouse cursor //show mouse cursor
ShowCursor(); ShowCursor();
@ -926,7 +919,5 @@ void window_fullscreen()
RepositionWindow(theWindow, NULL, kWindowCascadeOnMainScreen); RepositionWindow(theWindow, NULL, kWindowCascadeOnMainScreen);
} }
vo_fs = (!(vo_fs));
window_resized(); window_resized();
} }