]> git.sesse.net Git - vlc/blob - plugins/macosx/intf_macosx_qt.c
49f652ad9a2a54a823c4cabfe6472b38e26fbb50
[vlc] / plugins / macosx / intf_macosx_qt.c
1 /*****************************************************************************
2  * intf_macosx.c: MacOS X interface plugin
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  *
6  * Authors: Colin Delacroix <colin@zoy.org>
7  *
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.
12  * 
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.
17  *
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  *****************************************************************************/
22
23 #include "modules_inner.h"
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29
30 #include <stdlib.h>                                      /* malloc(), free() */
31 #include <sys/param.h>                                    /* for MAXPATHLEN */
32
33 #include "config.h"
34 #include "common.h"
35 #include "threads.h"
36 #include "mtime.h"
37 #include "tests.h"
38
39 #include "interface.h"
40 #include "intf_msg.h"
41 #include "intf_playlist.h"
42
43 #include "main.h"
44
45 #include "modules.h"
46 #include "modules_export.h"
47
48 #include "macosx_qt_common.h"
49
50
51 /*****************************************************************************
52  * Local prototypes.
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 );
58
59 /* OS specific */
60 #define kMainLoopFrequency  (kEventDurationSecond)              //45 for good measure
61
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) ;
64
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 )
70 {
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;
75 }
76
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 )
84 {
85     if( TestMethod( INTF_METHOD_VAR, "macosx_qt" ) )
86     {
87         return( 999 );
88     }
89
90     /* Under MacOS X, this plugin always works */
91     return( 90 );
92 }
93
94 /*****************************************************************************
95  * intf_Open: initialize interface
96  *****************************************************************************/
97 static int intf_Open( intf_thread_t *p_intf )
98 {
99     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
100     if( p_intf->p_sys == NULL )
101     {
102         return( 1 );
103     };
104
105     return( 0 );
106 }
107
108 /*****************************************************************************
109  * intf_Close: destroy interface
110  *****************************************************************************/
111 static void intf_Close( intf_thread_t *p_intf )
112 {
113     /* Destroy structure */
114     free( p_intf->p_sys );
115 }
116
117 /*****************************************************************************
118  * intf_Run: main loop
119  *****************************************************************************/
120 static void intf_Run( intf_thread_t *p_intf )
121 {
122     static EventTypeSpec suspendResumeEvent[2] = {{kEventClassApplication,kEventAppActivated}, {kEventClassApplication,kEventAppDeactivated}} ;
123
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 ;
130
131     RunApplicationEventLoop() ;
132
133     p_intf->p_sys->b_active = 0 ;
134     EndFullScreen(p_intf->p_sys->before_fullscreen, nil) ;
135 }
136
137 static pascal void APP_timer_handler(EventLoopTimerRef timer, void *dummy)
138 {
139         p_main->p_intf->pf_manage(p_main->p_intf) ;
140         
141         if (p_main->p_intf->b_die) QuitApplicationEventLoop() ;
142 }
143
144 static pascal OSStatus FS_suspend_resume_handler(EventHandlerCallRef ref, EventRef event, void *dummy)
145 {
146         switch (GetEventKind(event))
147         {
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") ;
151                                                 break ;
152                 case kEventAppDeactivated:      HideWindow(p_main->p_intf->p_sys->p_window) ;
153                                                 intf_WarnMsg(1, "Application sent to background") ;
154                                                 break ;
155         }
156
157         return noErr ;
158 }
159