1 /*****************************************************************************
2 * intf_macosx.c: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
6 * Authors: Colin Delacroix <colin@zoy.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 #include "modules_inner.h"
25 /*****************************************************************************
27 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
31 #include <sys/param.h> /* for MAXPATHLEN */
39 #include "interface.h"
41 #include "intf_playlist.h"
46 #include "modules_export.h"
48 #include "macosx_qt_common.h"
51 /*****************************************************************************
53 *****************************************************************************/
54 static int intf_Probe ( probedata_t *p_data );
55 static int intf_Open ( intf_thread_t *p_intf );
56 static void intf_Close ( intf_thread_t *p_intf );
57 static void intf_Run ( intf_thread_t *p_intf );
60 #define kMainLoopFrequency (kEventDurationSecond) //45 for good measure
62 static pascal OSStatus FS_suspend_resume_handler(EventHandlerCallRef ref, EventRef event, void *dummy) ;
63 static pascal void APP_timer_handler(EventLoopTimerRef timer, void *dummy) ;
65 /*****************************************************************************
66 * Functions exported as capabilities. They are declared as static so that
67 * we don't pollute the namespace too much.
68 *****************************************************************************/
69 void _M( intf_getfunctions )( function_list_t * p_function_list )
71 p_function_list->pf_probe = intf_Probe;
72 p_function_list->functions.intf.pf_open = intf_Open;
73 p_function_list->functions.intf.pf_close = intf_Close;
74 p_function_list->functions.intf.pf_run = intf_Run;
77 /*****************************************************************************
78 * intf_Probe: probe the interface and return a score
79 *****************************************************************************
80 * This function checks the interface can be run and returns a score to the
81 * plugin manager so that it can select the best plugin.
82 *****************************************************************************/
83 static int intf_Probe( probedata_t *p_data )
85 if( TestMethod( INTF_METHOD_VAR, "macosx_qt" ) )
90 /* Under MacOS X, this plugin always works */
94 /*****************************************************************************
95 * intf_Open: initialize interface
96 *****************************************************************************/
97 static int intf_Open( intf_thread_t *p_intf )
99 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
100 if( p_intf->p_sys == NULL )
108 /*****************************************************************************
109 * intf_Close: destroy interface
110 *****************************************************************************/
111 static void intf_Close( intf_thread_t *p_intf )
113 /* Destroy structure */
114 free( p_intf->p_sys );
117 /*****************************************************************************
118 * intf_Run: main loop
119 *****************************************************************************/
120 static void intf_Run( intf_thread_t *p_intf )
122 static EventTypeSpec suspendResumeEvent[2] = {{kEventClassApplication,kEventAppActivated}, {kEventClassApplication,kEventAppDeactivated}} ;
124 BeginFullScreen(&p_intf->p_sys->before_fullscreen, nil, 0, 0, &p_intf->p_sys->p_window, 0, fullScreenAllowEvents) ;
125 InstallStandardEventHandler(GetApplicationEventTarget()) ;
126 InstallApplicationEventHandler(NewEventHandlerUPP(FS_suspend_resume_handler), 2, suspendResumeEvent, &p_intf->p_sys->p_window, NULL) ;
127 InstallEventLoopTimer(GetMainEventLoop(), 0, kMainLoopFrequency, NewEventLoopTimerUPP(APP_timer_handler), NULL, &p_intf->p_sys->r_timer) ;
128 ShowWindow(p_intf->p_sys->p_window );
129 p_intf->p_sys->b_active = 1 ;
131 RunApplicationEventLoop() ;
133 p_intf->p_sys->b_active = 0 ;
134 EndFullScreen(p_intf->p_sys->before_fullscreen, nil) ;
137 static pascal void APP_timer_handler(EventLoopTimerRef timer, void *dummy)
139 p_main->p_intf->pf_manage(p_main->p_intf) ;
141 if (p_main->p_intf->b_die) QuitApplicationEventLoop() ;
144 static pascal OSStatus FS_suspend_resume_handler(EventHandlerCallRef ref, EventRef event, void *dummy)
146 switch (GetEventKind(event))
148 case kEventAppActivated: ShowWindow(p_main->p_intf->p_sys->p_window) ;
149 SetPortWindowPort(p_main->p_intf->p_sys->p_window) ;
150 intf_WarnMsg(1, "Application is on foreground") ;
152 case kEventAppDeactivated: HideWindow(p_main->p_intf->p_sys->p_window) ;
153 intf_WarnMsg(1, "Application sent to background") ;