a35bdee45c66803412be17bb1d508e6cd4e17f31
[vlc.git] / modules / video_output / msw / events.c
1 /*****************************************************************************
2  * events.c: Windows DirectX video output events handler
3  *****************************************************************************
4  * Copyright (C) 2001-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24
25 /*****************************************************************************
26  * Preamble: This file contains the functions related to the creation of
27  *             a window and the handling of its messages (events).
28  *****************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <errno.h>                                                 /* ENOMEM */
34 #include <ctype.h>                                              /* tolower() */
35
36 #ifndef _WIN32_WINNT
37 #   define _WIN32_WINNT 0x0500
38 #endif
39
40 #include <vlc_common.h>
41 #include <vlc_interface.h>
42 #include <vlc_playlist.h>
43 #include <vlc_vout.h>
44 #include <vlc_window.h>
45
46 #include <windows.h>
47 #include <tchar.h>
48 #include <windowsx.h>
49 #include <shellapi.h>
50
51 #ifdef MODULE_NAME_IS_vout_directx
52 #include <ddraw.h>
53 #endif
54 #ifdef MODULE_NAME_IS_direct3d
55 #include <d3d9.h>
56 #endif
57 #ifdef MODULE_NAME_IS_glwin32
58 #include <GL/gl.h>
59 #endif
60
61 #include "vlc_keys.h"
62 #include "vout.h"
63
64 #ifdef UNDER_CE
65 #include <aygshell.h>
66     //WINSHELLAPI BOOL WINAPI SHFullScreen(HWND hwndRequester, DWORD dwState);
67 #endif
68
69 /*#if defined(UNDER_CE) && !defined(__PLUGIN__) --FIXME*/
70 /*#   define SHFS_SHOWSIPBUTTON 0x0004
71 #   define SHFS_HIDESIPBUTTON 0x0008
72 #   define MENU_HEIGHT 26
73     BOOL SHFullScreen(HWND hwndRequester, DWORD dwState);
74 #endif*/
75
76
77 /*****************************************************************************
78  * Local prototypes.
79  *****************************************************************************/
80 static int  DirectXCreateWindow( vout_thread_t *p_vout );
81 static void DirectXCloseWindow ( vout_thread_t *p_vout );
82 static long FAR PASCAL DirectXEventProc( HWND, UINT, WPARAM, LPARAM );
83
84 static int Control( vout_thread_t *p_vout, int i_query, va_list args );
85 static int vaControlParentWindow( vout_thread_t *, int, va_list );
86
87 static void DirectXPopupMenu( event_thread_t *p_event, bool b_open )
88 {
89     vlc_value_t val;
90     val.b_bool = b_open;
91     var_Set( p_event->p_libvlc, "intf-popupmenu", val );
92 }
93
94 static int DirectXConvertKey( int i_key );
95
96 /*****************************************************************************
97  * EventThread: Create video window & handle its messages
98  *****************************************************************************
99  * This function creates a video window and then enters an infinite loop
100  * that handles the messages sent to that window.
101  * The main goal of this thread is to isolate the Win32 PeekMessage function
102  * because this one can block for a long time.
103  *****************************************************************************/
104 void* EventThread( vlc_object_t *p_this )
105 {
106     event_thread_t *p_event = (event_thread_t *)p_this;
107     MSG msg;
108     POINT old_mouse_pos = {0,0}, mouse_pos;
109     vlc_value_t val;
110     unsigned int i_width, i_height, i_x, i_y;
111     HMODULE hkernel32;
112     int canc = vlc_savecancel ();
113
114     /* Initialisation */
115     p_event->p_vout->pf_control = Control;
116
117     /* Create a window for the video */
118     /* Creating a window under Windows also initializes the thread's event
119      * message queue */
120     if( DirectXCreateWindow( p_event->p_vout ) )
121     {
122         vlc_restorecancel (canc);
123         return NULL;
124     }
125
126     /* Signal the creation of the window */
127     SetEvent( p_event->window_ready );
128
129 #ifndef UNDER_CE
130     /* Set power management stuff */
131     if( (hkernel32 = GetModuleHandle( _T("KERNEL32") ) ) )
132     {
133         ULONG (WINAPI* OurSetThreadExecutionState)( ULONG );
134
135         OurSetThreadExecutionState = (ULONG (WINAPI*)( ULONG ))
136             GetProcAddress( hkernel32, _T("SetThreadExecutionState") );
137
138         if( OurSetThreadExecutionState )
139             /* Prevent monitor from powering off */
140             OurSetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS );
141         else
142             msg_Dbg( p_event, "no support for SetThreadExecutionState()" );
143     }
144 #endif
145
146     /* Main loop */
147     /* GetMessage will sleep if there's no message in the queue */
148     while( vlc_object_alive (p_event) && GetMessage( &msg, 0, 0, 0 ) )
149     {
150         /* Check if we are asked to exit */
151         if( !vlc_object_alive (p_event) )
152             break;
153
154         switch( msg.message )
155         {
156
157         case WM_MOUSEMOVE:
158             vout_PlacePicture( p_event->p_vout,
159                                p_event->p_vout->p_sys->i_window_width,
160                                p_event->p_vout->p_sys->i_window_height,
161                                &i_x, &i_y, &i_width, &i_height );
162
163             if( msg.hwnd == p_event->p_vout->p_sys->hvideownd )
164             {
165                 /* Child window */
166                 i_x = i_y = 0;
167             }
168
169             if( i_width && i_height )
170             {
171                 val.i_int = ( GET_X_LPARAM(msg.lParam) - i_x ) *
172                     p_event->p_vout->fmt_in.i_visible_width / i_width +
173                     p_event->p_vout->fmt_in.i_x_offset;
174                 var_Set( p_event->p_vout, "mouse-x", val );
175                 val.i_int = ( GET_Y_LPARAM(msg.lParam) - i_y ) *
176                     p_event->p_vout->fmt_in.i_visible_height / i_height +
177                     p_event->p_vout->fmt_in.i_y_offset;
178                 var_Set( p_event->p_vout, "mouse-y", val );
179
180                 var_SetBool( p_event->p_vout, "mouse-moved", true );
181             }
182
183         case WM_NCMOUSEMOVE:
184             GetCursorPos( &mouse_pos );
185             if( (abs(mouse_pos.x - old_mouse_pos.x) > 2 ||
186                 (abs(mouse_pos.y - old_mouse_pos.y)) > 2 ) )
187             {
188                 GetCursorPos( &old_mouse_pos );
189                 p_event->p_vout->p_sys->i_lastmoved = mdate();
190
191                 if( p_event->p_vout->p_sys->b_cursor_hidden )
192                 {
193                     p_event->p_vout->p_sys->b_cursor_hidden = 0;
194                     ShowCursor( TRUE );
195                 }
196             }
197             break;
198
199         case WM_VLC_HIDE_MOUSE:
200             if( p_event->p_vout->p_sys->b_cursor_hidden ) break;
201             p_event->p_vout->p_sys->b_cursor_hidden = true;
202             GetCursorPos( &old_mouse_pos );
203             ShowCursor( FALSE );
204             break;
205
206         case WM_VLC_SHOW_MOUSE:
207             if( !p_event->p_vout->p_sys->b_cursor_hidden ) break;
208             p_event->p_vout->p_sys->b_cursor_hidden = false;
209             GetCursorPos( &old_mouse_pos );
210             ShowCursor( TRUE );
211             break;
212
213         case WM_LBUTTONDOWN:
214             var_Get( p_event->p_vout, "mouse-button-down", &val );
215             val.i_int |= 1;
216             var_Set( p_event->p_vout, "mouse-button-down", val );
217             DirectXPopupMenu( p_event, false );
218             break;
219
220         case WM_LBUTTONUP:
221             var_Get( p_event->p_vout, "mouse-button-down", &val );
222             val.i_int &= ~1;
223             var_Set( p_event->p_vout, "mouse-button-down", val );
224
225             var_SetBool( p_event->p_vout, "mouse-clicked", true );
226             break;
227
228         case WM_LBUTTONDBLCLK:
229             p_event->p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE;
230             break;
231
232         case WM_MBUTTONDOWN:
233             var_Get( p_event->p_vout, "mouse-button-down", &val );
234             val.i_int |= 2;
235             var_Set( p_event->p_vout, "mouse-button-down", val );
236             DirectXPopupMenu( p_event, false );
237             break;
238
239         case WM_MBUTTONUP:
240             var_Get( p_event->p_vout, "mouse-button-down", &val );
241             val.i_int &= ~2;
242             var_Set( p_event->p_vout, "mouse-button-down", val );
243             break;
244
245         case WM_RBUTTONDOWN:
246             var_Get( p_event->p_vout, "mouse-button-down", &val );
247             val.i_int |= 4;
248             var_Set( p_event->p_vout, "mouse-button-down", val );
249             DirectXPopupMenu( p_event, false );
250             break;
251
252         case WM_RBUTTONUP:
253             var_Get( p_event->p_vout, "mouse-button-down", &val );
254             val.i_int &= ~4;
255             var_Set( p_event->p_vout, "mouse-button-down", val );
256             DirectXPopupMenu( p_event, true );
257             break;
258
259         case WM_KEYDOWN:
260         case WM_SYSKEYDOWN:
261             /* The key events are first processed here and not translated
262              * into WM_CHAR events because we need to know the status of the
263              * modifier keys. */
264             val.i_int = DirectXConvertKey( msg.wParam );
265             if( !val.i_int )
266             {
267                 /* This appears to be a "normal" (ascii) key */
268                 val.i_int = tolower( MapVirtualKey( msg.wParam, 2 ) );
269             }
270
271             if( val.i_int )
272             {
273                 if( GetKeyState(VK_CONTROL) & 0x8000 )
274                 {
275                     val.i_int |= KEY_MODIFIER_CTRL;
276                 }
277                 if( GetKeyState(VK_SHIFT) & 0x8000 )
278                 {
279                     val.i_int |= KEY_MODIFIER_SHIFT;
280                 }
281                 if( GetKeyState(VK_MENU) & 0x8000 )
282                 {
283                     val.i_int |= KEY_MODIFIER_ALT;
284                 }
285
286                 var_Set( p_event->p_libvlc, "key-pressed", val );
287             }
288             break;
289
290         case WM_MOUSEWHEEL:
291             if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )
292             {
293                 val.i_int = KEY_MOUSEWHEELUP;
294             }
295             else
296             {
297                 val.i_int = KEY_MOUSEWHEELDOWN;
298             }
299             if( val.i_int )
300             {
301                 if( GetKeyState(VK_CONTROL) & 0x8000 )
302                 {
303                     val.i_int |= KEY_MODIFIER_CTRL;
304                 }
305                 if( GetKeyState(VK_SHIFT) & 0x8000 )
306                 {
307                     val.i_int |= KEY_MODIFIER_SHIFT;
308                 }
309                 if( GetKeyState(VK_MENU) & 0x8000 )
310                 {
311                     val.i_int |= KEY_MODIFIER_ALT;
312                 }
313
314                 var_Set( p_event->p_libvlc, "key-pressed", val );
315             }
316             break;
317
318         case WM_VLC_CHANGE_TEXT:
319             var_Get( p_event->p_vout, "video-title", &val );
320             if( !val.psz_string || !*val.psz_string ) /* Default video title */
321             {
322                 free( val.psz_string );
323
324 #ifdef MODULE_NAME_IS_wingdi
325                 val.psz_string = strdup( VOUT_TITLE " (WinGDI output)" );
326 #endif
327 #ifdef MODULE_NAME_IS_wingapi
328                 val.psz_string = strdup( VOUT_TITLE " (WinGAPI output)" );
329 #endif
330 #ifdef MODULE_NAME_IS_glwin32
331                 val.psz_string = strdup( VOUT_TITLE " (OpenGL output)" );
332 #endif
333 #ifdef MODULE_NAME_IS_direct3d
334                 val.psz_string = strdup( VOUT_TITLE " (Direct3D output)" );
335 #endif
336 #ifdef MODULE_NAME_IS_vout_directx
337                 if( p_event->p_vout->p_sys->b_using_overlay ) val.psz_string =
338                     strdup( VOUT_TITLE " (hardware YUV overlay DirectX output)" );
339                 else if( p_event->p_vout->p_sys->b_hw_yuv ) val.psz_string =
340                     strdup( VOUT_TITLE " (hardware YUV DirectX output)" );
341                 else val.psz_string =
342                     strdup( VOUT_TITLE " (software RGB DirectX output)" );
343 #endif
344             }
345
346 #ifdef UNICODE
347             {
348                 wchar_t *psz_title = malloc( strlen(val.psz_string) * 2 + 2 );
349                 if( psz_title )
350                 {
351                     mbstowcs( psz_title, val.psz_string, strlen(val.psz_string)*2);
352                     psz_title[strlen(val.psz_string)] = 0;
353                     free( val.psz_string ); val.psz_string = (char *)psz_title;
354                 }
355             }
356 #endif
357
358             SetWindowText( p_event->p_vout->p_sys->hwnd,
359                            (LPCTSTR)val.psz_string );
360             if( p_event->p_vout->p_sys->hfswnd )
361                 SetWindowText( p_event->p_vout->p_sys->hfswnd,
362                                (LPCTSTR)val.psz_string );
363             free( val.psz_string );
364             break;
365
366         default:
367             /* Messages we don't handle directly are dispatched to the
368              * window procedure */
369             TranslateMessage(&msg);
370             DispatchMessage(&msg);
371             break;
372
373         } /* End Switch */
374
375     } /* End Main loop */
376
377     /* Check for WM_QUIT if we created the window */
378     if( !p_event->p_vout->p_sys->hparent && msg.message == WM_QUIT )
379     {
380         msg_Warn( p_event, "WM_QUIT... should not happen!!" );
381         p_event->p_vout->p_sys->hwnd = NULL; /* Window already destroyed */
382     }
383
384     msg_Dbg( p_event, "DirectXEventThread terminating" );
385
386     /* clear the changes formerly signaled */
387     p_event->p_vout->p_sys->i_changes = 0;
388
389     DirectXCloseWindow( p_event->p_vout );
390     vlc_restorecancel (canc);
391     return NULL;
392 }
393
394
395 /* following functions are local */
396
397 /*****************************************************************************
398  * DirectXCreateWindow: create a window for the video.
399  *****************************************************************************
400  * Before creating a direct draw surface, we need to create a window in which
401  * the video will be displayed. This window will also allow us to capture the
402  * events.
403  *****************************************************************************/
404 static int DirectXCreateWindow( vout_thread_t *p_vout )
405 {
406     HINSTANCE  hInstance;
407     HMENU      hMenu;
408     RECT       rect_window;
409     WNDCLASS   wc;                            /* window class components */
410     HICON      vlc_icon = NULL;
411     char       vlc_path[MAX_PATH+1];
412     int        i_style, i_stylex;
413
414     msg_Dbg( p_vout, "DirectXCreateWindow" );
415
416     /* Get this module's instance */
417     hInstance = GetModuleHandle(NULL);
418
419     /* If an external window was specified, we'll draw in it. */
420     p_vout->p_sys->parent_window =
421         vout_RequestHWND( p_vout, &p_vout->p_sys->i_window_x,
422                             &p_vout->p_sys->i_window_y,
423                             &p_vout->p_sys->i_window_width,
424                             &p_vout->p_sys->i_window_height );
425     if( p_vout->p_sys->parent_window )
426         p_vout->p_sys->hparent = p_vout->p_sys->parent_window->handle.hwnd;
427
428     /* We create the window ourself, there is no previous window proc. */
429     p_vout->p_sys->pf_wndproc = NULL;
430
431     /* Get the Icon from the main app */
432     vlc_icon = NULL;
433 #ifndef UNDER_CE
434     if( GetModuleFileName( NULL, vlc_path, MAX_PATH ) )
435     {
436         vlc_icon = ExtractIcon( hInstance, vlc_path, 0 );
437     }
438 #endif
439
440     /* Fill in the window class structure */
441     wc.style         = CS_OWNDC|CS_DBLCLKS;          /* style: dbl click */
442     wc.lpfnWndProc   = (WNDPROC)DirectXEventProc;       /* event handler */
443     wc.cbClsExtra    = 0;                         /* no extra class data */
444     wc.cbWndExtra    = 0;                        /* no extra window data */
445     wc.hInstance     = hInstance;                            /* instance */
446     wc.hIcon         = vlc_icon;                /* load the vlc big icon */
447     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);    /* default cursor */
448     wc.hbrBackground = GetStockObject(BLACK_BRUSH);  /* background color */
449     wc.lpszMenuName  = NULL;                                  /* no menu */
450     wc.lpszClassName = _T("VLC DirectX");         /* use a special class */
451
452     /* Register the window class */
453     if( !RegisterClass(&wc) )
454     {
455         WNDCLASS wndclass;
456
457         if( vlc_icon ) DestroyIcon( vlc_icon );
458
459         /* Check why it failed. If it's because one already exists
460          * then fine, otherwise return with an error. */
461         if( !GetClassInfo( hInstance, _T("VLC DirectX"), &wndclass ) )
462         {
463             msg_Err( p_vout, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
464             return VLC_EGENERIC;
465         }
466     }
467
468     /* Register the video sub-window class */
469     wc.lpszClassName = _T("VLC DirectX video"); wc.hIcon = 0;
470     wc.hbrBackground = NULL; /* no background color */
471     if( !RegisterClass(&wc) )
472     {
473         WNDCLASS wndclass;
474
475         /* Check why it failed. If it's because one already exists
476          * then fine, otherwise return with an error. */
477         if( !GetClassInfo( hInstance, _T("VLC DirectX video"), &wndclass ) )
478         {
479             msg_Err( p_vout, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
480             return VLC_EGENERIC;
481         }
482     }
483
484     /* When you create a window you give the dimensions you wish it to
485      * have. Unfortunatly these dimensions will include the borders and
486      * titlebar. We use the following function to find out the size of
487      * the window corresponding to the useable surface we want */
488     rect_window.top    = 10;
489     rect_window.left   = 10;
490     rect_window.right  = rect_window.left + p_vout->p_sys->i_window_width;
491     rect_window.bottom = rect_window.top + p_vout->p_sys->i_window_height;
492
493     if( var_GetBool( p_vout, "video-deco" ) )
494     {
495         /* Open with window decoration */
496         AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );
497         i_style = WS_OVERLAPPEDWINDOW|WS_SIZEBOX|WS_VISIBLE|WS_CLIPCHILDREN;
498         i_stylex = 0;
499     }
500     else
501     {
502         /* No window decoration */
503         AdjustWindowRect( &rect_window, WS_POPUP, 0 );
504         i_style = WS_POPUP|WS_VISIBLE|WS_CLIPCHILDREN;
505         i_stylex = 0; // WS_EX_TOOLWINDOW; Is TOOLWINDOW really needed ?
506                       // It messes up the fullscreen window.
507     }
508
509     if( p_vout->p_sys->hparent )
510     {
511         i_style = WS_VISIBLE|WS_CLIPCHILDREN|WS_CHILD;
512         i_stylex = 0;
513     }
514
515     p_vout->p_sys->i_window_style = i_style;
516
517     /* Create the window */
518     p_vout->p_sys->hwnd =
519         CreateWindowEx( WS_EX_NOPARENTNOTIFY | i_stylex,
520                     _T("VLC DirectX"),               /* name of window class */
521                     _T(VOUT_TITLE) _T(" (DirectX Output)"),  /* window title */
522                     i_style,                                 /* window style */
523                     (p_vout->p_sys->i_window_x < 0) ? CW_USEDEFAULT :
524                         (UINT)p_vout->p_sys->i_window_x,   /* default X coordinate */
525                     (p_vout->p_sys->i_window_y < 0) ? CW_USEDEFAULT :
526                         (UINT)p_vout->p_sys->i_window_y,   /* default Y coordinate */
527                     rect_window.right - rect_window.left,    /* window width */
528                     rect_window.bottom - rect_window.top,   /* window height */
529                     p_vout->p_sys->hparent,                 /* parent window */
530                     NULL,                          /* no menu in this window */
531                     hInstance,            /* handle of this program instance */
532                     (LPVOID)p_vout );            /* send p_vout to WM_CREATE */
533
534     if( !p_vout->p_sys->hwnd )
535     {
536         msg_Warn( p_vout, "DirectXCreateWindow create window FAILED (err=%lu)", GetLastError() );
537         return VLC_EGENERIC;
538     }
539
540     if( p_vout->p_sys->hparent )
541     {
542         LONG i_style;
543
544         /* We don't want the window owner to overwrite our client area */
545         i_style = GetWindowLong( p_vout->p_sys->hparent, GWL_STYLE );
546
547         if( !(i_style & WS_CLIPCHILDREN) )
548             /* Hmmm, apparently this is a blocking call... */
549             SetWindowLong( p_vout->p_sys->hparent, GWL_STYLE,
550                            i_style | WS_CLIPCHILDREN );
551
552         /* Create our fullscreen window */
553         p_vout->p_sys->hfswnd =
554             CreateWindowEx( WS_EX_APPWINDOW, _T("VLC DirectX"),
555                             _T(VOUT_TITLE) _T(" (DirectX Output)"),
556                             WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_SIZEBOX,
557                             CW_USEDEFAULT, CW_USEDEFAULT,
558                             CW_USEDEFAULT, CW_USEDEFAULT,
559                             NULL, NULL, hInstance, NULL );
560     }
561
562     /* Append a "Always On Top" entry in the system menu */
563     hMenu = GetSystemMenu( p_vout->p_sys->hwnd, FALSE );
564     AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
565     AppendMenu( hMenu, MF_STRING | MF_UNCHECKED,
566                        IDM_TOGGLE_ON_TOP, _T("Always on &Top") );
567
568     /* Create video sub-window. This sub window will always exactly match
569      * the size of the video, which allows us to use crazy overlay colorkeys
570      * without having them shown outside of the video area. */
571     p_vout->p_sys->hvideownd =
572     CreateWindow( _T("VLC DirectX video"), _T(""),   /* window class */
573         WS_CHILD,                   /* window style, not visible initially */
574         0, 0,
575         p_vout->render.i_width,         /* default width */
576         p_vout->render.i_height,        /* default height */
577         p_vout->p_sys->hwnd,                    /* parent window */
578         NULL, hInstance,
579         (LPVOID)p_vout );            /* send p_vout to WM_CREATE */
580
581     if( !p_vout->p_sys->hvideownd )
582         msg_Warn( p_vout, "can't create video sub-window" );
583     else
584         msg_Dbg( p_vout, "created video sub-window" );
585
586     /* Now display the window */
587     ShowWindow( p_vout->p_sys->hwnd, SW_SHOW );
588
589     return VLC_SUCCESS;
590 }
591
592 /*****************************************************************************
593  * DirectXCloseWindow: close the window created by DirectXCreateWindow
594  *****************************************************************************
595  * This function returns all resources allocated by DirectXCreateWindow.
596  *****************************************************************************/
597 static void DirectXCloseWindow( vout_thread_t *p_vout )
598 {
599     msg_Dbg( p_vout, "DirectXCloseWindow" );
600
601     DestroyWindow( p_vout->p_sys->hwnd );
602     if( p_vout->p_sys->hfswnd ) DestroyWindow( p_vout->p_sys->hfswnd );
603
604     vout_ReleaseWindow( p_vout->p_sys->parent_window );
605     p_vout->p_sys->hwnd = NULL;
606
607     /* We don't unregister the Window Class because it could lead to race
608      * conditions and it will be done anyway by the system when the app will
609      * exit */
610 }
611
612 /*****************************************************************************
613  * UpdateRects: update clipping rectangles
614  *****************************************************************************
615  * This function is called when the window position or size are changed, and
616  * its job is to update the source and destination RECTs used to display the
617  * picture.
618  *****************************************************************************/
619 void UpdateRects( vout_thread_t *p_vout, bool b_force )
620 {
621 #define rect_src p_vout->p_sys->rect_src
622 #define rect_src_clipped p_vout->p_sys->rect_src_clipped
623 #define rect_dest p_vout->p_sys->rect_dest
624 #define rect_dest_clipped p_vout->p_sys->rect_dest_clipped
625
626     int i_width, i_height, i_x, i_y;
627
628     RECT  rect;
629     POINT point;
630
631     /* Retrieve the window size */
632     GetClientRect( p_vout->p_sys->hwnd, &rect );
633
634     /* Retrieve the window position */
635     point.x = point.y = 0;
636     ClientToScreen( p_vout->p_sys->hwnd, &point );
637
638     /* If nothing changed, we can return */
639     if( !b_force
640          && p_vout->p_sys->i_window_width == rect.right
641          && p_vout->p_sys->i_window_height == rect.bottom
642          && p_vout->p_sys->i_window_x == point.x
643          && p_vout->p_sys->i_window_y == point.y )
644     {
645         return;
646     }
647
648     /* Update the window position and size */
649     p_vout->p_sys->i_window_x = point.x;
650     p_vout->p_sys->i_window_y = point.y;
651     p_vout->p_sys->i_window_width = rect.right;
652     p_vout->p_sys->i_window_height = rect.bottom;
653
654     vout_PlacePicture( p_vout, rect.right, rect.bottom,
655                        &i_x, &i_y, &i_width, &i_height );
656
657     if( p_vout->p_sys->hvideownd )
658         SetWindowPos( p_vout->p_sys->hvideownd, 0,
659                       i_x, i_y, i_width, i_height,
660                       SWP_NOCOPYBITS|SWP_NOZORDER|SWP_ASYNCWINDOWPOS );
661
662     /* Destination image position and dimensions */
663     rect_dest.left = point.x + i_x;
664     rect_dest.right = rect_dest.left + i_width;
665     rect_dest.top = point.y + i_y;
666     rect_dest.bottom = rect_dest.top + i_height;
667
668 #ifdef MODULE_NAME_IS_vout_directx
669     /* Apply overlay hardware constraints */
670     if( p_vout->p_sys->b_using_overlay )
671     {
672         if( p_vout->p_sys->i_align_dest_boundary )
673             rect_dest.left = ( rect_dest.left +
674                 p_vout->p_sys->i_align_dest_boundary / 2 ) &
675                 ~p_vout->p_sys->i_align_dest_boundary;
676
677         if( p_vout->p_sys->i_align_dest_size )
678             rect_dest.right = (( rect_dest.right - rect_dest.left +
679                 p_vout->p_sys->i_align_dest_size / 2 ) &
680                 ~p_vout->p_sys->i_align_dest_size) + rect_dest.left;
681     }
682
683     /* UpdateOverlay directdraw function doesn't automatically clip to the
684      * display size so we need to do it otherwise it will fail */
685
686     /* Clip the destination window */
687     if( !IntersectRect( &rect_dest_clipped, &rect_dest,
688                         &p_vout->p_sys->rect_display ) )
689     {
690         SetRectEmpty( &rect_src_clipped );
691         return;
692     }
693
694 #if 0
695     msg_Dbg( p_vout, "DirectXUpdateRects image_dst_clipped coords:"
696                      " %i,%i,%i,%i",
697                      rect_dest_clipped.left, rect_dest_clipped.top,
698                      rect_dest_clipped.right, rect_dest_clipped.bottom );
699 #endif
700
701 #else /* MODULE_NAME_IS_vout_directx */
702
703     /* AFAIK, there are no clipping constraints in Direct3D, OpenGL and GDI */
704     rect_dest_clipped = rect_dest;
705
706 #endif
707
708     /* the 2 following lines are to fix a bug when clicking on the desktop */
709     if( (rect_dest_clipped.right - rect_dest_clipped.left)==0 ||
710         (rect_dest_clipped.bottom - rect_dest_clipped.top)==0 )
711     {
712         SetRectEmpty( &rect_src_clipped );
713         return;
714     }
715
716     /* src image dimensions */
717     rect_src.left = 0;
718     rect_src.top = 0;
719     rect_src.right = p_vout->render.i_width;
720     rect_src.bottom = p_vout->render.i_height;
721
722     /* Clip the source image */
723     rect_src_clipped.left = p_vout->fmt_out.i_x_offset +
724       (rect_dest_clipped.left - rect_dest.left) *
725       p_vout->fmt_out.i_visible_width / (rect_dest.right - rect_dest.left);
726     rect_src_clipped.right = p_vout->fmt_out.i_x_offset +
727       p_vout->fmt_out.i_visible_width -
728       (rect_dest.right - rect_dest_clipped.right) *
729       p_vout->fmt_out.i_visible_width / (rect_dest.right - rect_dest.left);
730     rect_src_clipped.top = p_vout->fmt_out.i_y_offset +
731       (rect_dest_clipped.top - rect_dest.top) *
732       p_vout->fmt_out.i_visible_height / (rect_dest.bottom - rect_dest.top);
733     rect_src_clipped.bottom = p_vout->fmt_out.i_y_offset +
734       p_vout->fmt_out.i_visible_height -
735       (rect_dest.bottom - rect_dest_clipped.bottom) *
736       p_vout->fmt_out.i_visible_height / (rect_dest.bottom - rect_dest.top);
737
738 #ifdef MODULE_NAME_IS_vout_directx
739     /* Apply overlay hardware constraints */
740     if( p_vout->p_sys->b_using_overlay )
741     {
742         if( p_vout->p_sys->i_align_src_boundary )
743             rect_src_clipped.left = ( rect_src_clipped.left +
744                 p_vout->p_sys->i_align_src_boundary / 2 ) &
745                 ~p_vout->p_sys->i_align_src_boundary;
746
747         if( p_vout->p_sys->i_align_src_size )
748             rect_src_clipped.right = (( rect_src_clipped.right -
749                 rect_src_clipped.left +
750                 p_vout->p_sys->i_align_src_size / 2 ) &
751                 ~p_vout->p_sys->i_align_src_size) + rect_src_clipped.left;
752     }
753 #endif
754
755 #if 0
756     msg_Dbg( p_vout, "DirectXUpdateRects image_src_clipped"
757                      " coords: %i,%i,%i,%i",
758                      rect_src_clipped.left, rect_src_clipped.top,
759                      rect_src_clipped.right, rect_src_clipped.bottom );
760 #endif
761
762 #ifdef MODULE_NAME_IS_vout_directx
763     /* The destination coordinates need to be relative to the current
764      * directdraw primary surface (display) */
765     rect_dest_clipped.left -= p_vout->p_sys->rect_display.left;
766     rect_dest_clipped.right -= p_vout->p_sys->rect_display.left;
767     rect_dest_clipped.top -= p_vout->p_sys->rect_display.top;
768     rect_dest_clipped.bottom -= p_vout->p_sys->rect_display.top;
769
770     if( p_vout->p_sys->b_using_overlay )
771         DirectDrawUpdateOverlay( p_vout );
772 #endif
773
774     /* Signal the change in size/position */
775     p_vout->p_sys->i_changes |= DX_POSITION_CHANGE;
776
777 #undef rect_src
778 #undef rect_src_clipped
779 #undef rect_dest
780 #undef rect_dest_clipped
781 }
782
783 /*****************************************************************************
784  * DirectXEventProc: This is the window event processing function.
785  *****************************************************************************
786  * On Windows, when you create a window you have to attach an event processing
787  * function to it. The aim of this function is to manage "Queued Messages" and
788  * "Nonqueued Messages".
789  * Queued Messages are those picked up and retransmitted by vout_Manage
790  * (using the GetMessage and DispatchMessage functions).
791  * Nonqueued Messages are those that Windows will send directly to this
792  * procedure (like WM_DESTROY, WM_WINDOWPOSCHANGED...)
793  *****************************************************************************/
794 static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
795                                          WPARAM wParam, LPARAM lParam )
796 {
797     vout_thread_t *p_vout;
798
799     if( message == WM_CREATE )
800     {
801         /* Store p_vout for future use */
802         p_vout = (vout_thread_t *)((CREATESTRUCT *)lParam)->lpCreateParams;
803         SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_vout );
804         return TRUE;
805     }
806     else
807     {
808         p_vout = (vout_thread_t *)GetWindowLongPtr( hwnd, GWLP_USERDATA );
809         if( !p_vout )
810         {
811             /* Hmmm mozilla does manage somehow to save the pointer to our
812              * windowproc and still calls it after the vout has been closed. */
813             return DefWindowProc(hwnd, message, wParam, lParam);
814         }
815     }
816
817 #ifndef UNDER_CE
818     /* Catch the screensaver and the monitor turn-off */
819     if( message == WM_SYSCOMMAND &&
820         ( (wParam & 0xFFF0) == SC_SCREENSAVE || (wParam & 0xFFF0) == SC_MONITORPOWER ) )
821     {
822         //if( p_vout ) msg_Dbg( p_vout, "WinProc WM_SYSCOMMAND screensaver" );
823         return 0; /* this stops them from happening */
824     }
825 #endif
826
827     if( hwnd == p_vout->p_sys->hvideownd )
828     {
829         switch( message )
830         {
831 #ifdef MODULE_NAME_IS_vout_directx
832         case WM_ERASEBKGND:
833         /* For overlay, we need to erase background */
834             return !p_vout->p_sys->b_using_overlay ?
835                 1 : DefWindowProc(hwnd, message, wParam, lParam);
836         case WM_PAINT:
837         /*
838         ** For overlay, DefWindowProc() will erase dirty regions
839         ** with colorkey.
840         ** For non-overlay, vout will paint the whole window at
841         ** regular interval, therefore dirty regions can be ignored
842         ** to minimize repaint.
843         */
844             if( !p_vout->p_sys->b_using_overlay )
845             {
846                 ValidateRect(hwnd, NULL);
847             }
848             // fall through to default
849 #else
850         /*
851         ** For OpenGL and Direct3D, vout will update the whole
852         ** window at regular interval, therefore dirty region
853         ** can be ignored to minimize repaint.
854         */
855         case WM_ERASEBKGND:
856             /* nothing to erase */
857             return 1;
858         case WM_PAINT:
859             /* nothing to repaint */
860             ValidateRect(hwnd, NULL);
861             // fall through
862 #endif
863         default:
864             return DefWindowProc(hwnd, message, wParam, lParam);
865         }
866     }
867
868     switch( message )
869     {
870
871     case WM_WINDOWPOSCHANGED:
872         UpdateRects( p_vout, true );
873         return 0;
874
875     /* the user wants to close the window */
876     case WM_CLOSE:
877     {
878         playlist_t * p_playlist = pl_Hold( p_vout );
879         if( p_playlist )
880         {
881             playlist_Stop( p_playlist );
882             pl_Release( p_vout );
883         }
884         return 0;
885     }
886
887     /* the window has been closed so shut down everything now */
888     case WM_DESTROY:
889         msg_Dbg( p_vout, "WinProc WM_DESTROY" );
890         /* just destroy the window */
891         PostQuitMessage( 0 );
892         return 0;
893
894     case WM_SYSCOMMAND:
895         switch (wParam)
896         {
897             case IDM_TOGGLE_ON_TOP:            /* toggle the "on top" status */
898             {
899                 vlc_value_t val;
900                 msg_Dbg( p_vout, "WinProc WM_SYSCOMMAND: IDM_TOGGLE_ON_TOP");
901
902                 /* Change the current value */
903                 var_Get( p_vout, "video-on-top", &val );
904                 val.b_bool = !val.b_bool;
905                 var_Set( p_vout, "video-on-top", val );
906                 return 0;
907             }
908         }
909         break;
910
911     case WM_PAINT:
912     case WM_NCPAINT:
913     case WM_ERASEBKGND:
914         return DefWindowProc(hwnd, message, wParam, lParam);
915
916     case WM_KILLFOCUS:
917 #ifdef MODULE_NAME_IS_wingapi
918         p_vout->p_sys->b_focus = false;
919         if( !p_vout->p_sys->b_parent_focus ) GXSuspend();
920 #endif
921 #ifdef UNDER_CE
922         if( hwnd == p_vout->p_sys->hfswnd )
923         {
924             HWND htbar = FindWindow( _T("HHTaskbar"), NULL );
925             ShowWindow( htbar, SW_SHOW );
926         }
927
928         if( !p_vout->p_sys->hparent ||
929             hwnd == p_vout->p_sys->hfswnd )
930         {
931             SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
932         }
933 #endif
934         return 0;
935
936     case WM_SETFOCUS:
937 #ifdef MODULE_NAME_IS_wingapi
938         p_vout->p_sys->b_focus = true;
939         GXResume();
940 #endif
941 #ifdef UNDER_CE
942         if( p_vout->p_sys->hparent &&
943             hwnd != p_vout->p_sys->hfswnd && p_vout->b_fullscreen )
944             p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE;
945
946         if( hwnd == p_vout->p_sys->hfswnd )
947         {
948             HWND htbar = FindWindow( _T("HHTaskbar"), NULL );
949             ShowWindow( htbar, SW_HIDE );
950         }
951
952         if( !p_vout->p_sys->hparent ||
953             hwnd == p_vout->p_sys->hfswnd )
954         {
955             SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
956         }
957 #endif
958         return 0;
959
960     default:
961         //msg_Dbg( p_vout, "WinProc WM Default %i", message );
962         break;
963     }
964
965     /* Let windows handle the message */
966     return DefWindowProc(hwnd, message, wParam, lParam);
967 }
968
969 static struct
970 {
971     int i_dxkey;
972     int i_vlckey;
973
974 } dxkeys_to_vlckeys[] =
975 {
976     { VK_F1, KEY_F1 }, { VK_F2, KEY_F2 }, { VK_F3, KEY_F3 }, { VK_F4, KEY_F4 },
977     { VK_F5, KEY_F5 }, { VK_F6, KEY_F6 }, { VK_F7, KEY_F7 }, { VK_F8, KEY_F8 },
978     { VK_F9, KEY_F9 }, { VK_F10, KEY_F10 }, { VK_F11, KEY_F11 },
979     { VK_F12, KEY_F12 },
980
981     { VK_RETURN, KEY_ENTER },
982     { VK_SPACE, KEY_SPACE },
983     { VK_ESCAPE, KEY_ESC },
984
985     { VK_LEFT, KEY_LEFT },
986     { VK_RIGHT, KEY_RIGHT },
987     { VK_UP, KEY_UP },
988     { VK_DOWN, KEY_DOWN },
989
990     { VK_HOME, KEY_HOME },
991     { VK_END, KEY_END },
992     { VK_PRIOR, KEY_PAGEUP },
993     { VK_NEXT, KEY_PAGEDOWN },
994
995     { VK_INSERT, KEY_INSERT },
996     { VK_DELETE, KEY_DELETE },
997
998     { VK_CONTROL, 0 },
999     { VK_SHIFT, 0 },
1000     { VK_MENU, 0 },
1001
1002     { VK_BROWSER_BACK, KEY_BROWSER_BACK },
1003     { VK_BROWSER_FORWARD, KEY_BROWSER_FORWARD },
1004     { VK_BROWSER_REFRESH, KEY_BROWSER_REFRESH },
1005     { VK_BROWSER_STOP, KEY_BROWSER_STOP },
1006     { VK_BROWSER_SEARCH, KEY_BROWSER_SEARCH },
1007     { VK_BROWSER_FAVORITES, KEY_BROWSER_FAVORITES },
1008     { VK_BROWSER_HOME, KEY_BROWSER_HOME },
1009     { VK_VOLUME_MUTE, KEY_VOLUME_MUTE },
1010     { VK_VOLUME_DOWN, KEY_VOLUME_DOWN },
1011     { VK_VOLUME_UP, KEY_VOLUME_UP },
1012     { VK_MEDIA_NEXT_TRACK, KEY_MEDIA_NEXT_TRACK },
1013     { VK_MEDIA_PREV_TRACK, KEY_MEDIA_PREV_TRACK },
1014     { VK_MEDIA_STOP, KEY_MEDIA_STOP },
1015     { VK_MEDIA_PLAY_PAUSE, KEY_MEDIA_PLAY_PAUSE },
1016
1017     { 0, 0 }
1018 };
1019
1020 static int DirectXConvertKey( int i_key )
1021 {
1022     int i;
1023
1024     for( i = 0; dxkeys_to_vlckeys[i].i_dxkey != 0; i++ )
1025     {
1026         if( dxkeys_to_vlckeys[i].i_dxkey == i_key )
1027         {
1028             return dxkeys_to_vlckeys[i].i_vlckey;
1029         }
1030     }
1031
1032     return 0;
1033 }
1034
1035 /*****************************************************************************
1036  * Control: control facility for the vout
1037  *****************************************************************************/
1038 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
1039 {
1040     unsigned int *pi_width, *pi_height;
1041         bool b_bool;
1042     RECT rect_window;
1043     POINT point;
1044
1045     switch( i_query )
1046     {
1047     case VOUT_SET_SIZE:
1048         if( p_vout->p_sys->parent_window )
1049             return vaControlParentWindow( p_vout, i_query, args );
1050
1051         /* Update dimensions */
1052         rect_window.top = rect_window.left = 0;
1053         rect_window.right  = va_arg( args, unsigned int );
1054         rect_window.bottom = va_arg( args, unsigned int );
1055         if( !rect_window.right ) rect_window.right = p_vout->i_window_width;
1056         if( !rect_window.bottom ) rect_window.bottom = p_vout->i_window_height;
1057         AdjustWindowRect( &rect_window, p_vout->p_sys->i_window_style, 0 );
1058
1059         SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
1060                       rect_window.right - rect_window.left,
1061                       rect_window.bottom - rect_window.top, SWP_NOMOVE );
1062
1063         return VLC_SUCCESS;
1064
1065     case VOUT_SET_STAY_ON_TOP:
1066         if( p_vout->p_sys->hparent && !var_GetBool( p_vout, "fullscreen" ) )
1067             return vaControlParentWindow( p_vout, i_query, args );
1068
1069         p_vout->p_sys->b_on_top_change = true;
1070         return VLC_SUCCESS;
1071
1072     default:
1073         return VLC_EGENERIC;
1074     }
1075 }
1076
1077
1078 /* Internal wrapper over GetWindowPlacement */
1079 static WINDOWPLACEMENT getWindowState(HWND hwnd)
1080 {
1081     WINDOWPLACEMENT window_placement;
1082     window_placement.length = sizeof(WINDOWPLACEMENT);
1083     GetWindowPlacement( hwnd, &window_placement );
1084     return window_placement;
1085 }
1086
1087 /* Internal wrapper to call vout_ControlWindow for hparent */
1088 static int vaControlParentWindow( vout_thread_t *p_vout, int i_query,
1089                                    va_list args )
1090 {
1091     return vout_ControlWindow( p_vout->p_sys->parent_window, i_query, args );
1092 }
1093
1094 static int ControlParentWindow( vout_thread_t *p_vout, int i_query, ... )
1095 {
1096     va_list args;
1097     int ret;
1098
1099     va_start( args, i_query );
1100     ret = vaControlParentWindow( p_vout, i_query, args );
1101     va_end( args );
1102     return ret;
1103 }
1104
1105 void Win32ToggleFullscreen( vout_thread_t *p_vout )
1106 {
1107     HWND hwnd = (p_vout->p_sys->hparent && p_vout->p_sys->hfswnd) ?
1108         p_vout->p_sys->hfswnd : p_vout->p_sys->hwnd;
1109
1110     /* Save the current windows placement/placement to restore
1111        when fullscreen is over */
1112     WINDOWPLACEMENT window_placement = getWindowState( hwnd );
1113
1114     p_vout->b_fullscreen = ! p_vout->b_fullscreen;
1115
1116     /* We want to go to Fullscreen */
1117     if( p_vout->b_fullscreen )
1118     {
1119         msg_Dbg( p_vout, "entering fullscreen mode" );
1120
1121         /* Change window style, no borders and no title bar */
1122         int i_style = WS_CLIPCHILDREN | WS_VISIBLE;
1123         SetWindowLong( hwnd, GWL_STYLE, i_style );
1124
1125         if( p_vout->p_sys->hparent )
1126         {
1127 #ifdef UNDER_CE
1128             POINT point = {0,0};
1129             RECT rect;
1130             ClientToScreen( p_vout->p_sys->hwnd, &point );
1131             GetClientRect( p_vout->p_sys->hwnd, &rect );
1132             SetWindowPos( hwnd, 0, point.x, point.y,
1133                           rect.right, rect.bottom,
1134                           SWP_NOZORDER|SWP_FRAMECHANGED );
1135 #else
1136             /* Retrieve current window position so fullscreen will happen
1137             *on the right screen */
1138             HMONITOR hmon = MonitorFromWindow(p_vout->p_sys->hparent,
1139                                             MONITOR_DEFAULTTONEAREST);
1140             MONITORINFO mi = {sizeof(mi)};
1141             if (GetMonitorInfo(hmon, &mi))
1142             SetWindowPos( hwnd, 0,
1143                             mi.rcMonitor.left,
1144                             mi.rcMonitor.top,
1145                             mi.rcMonitor.right - mi.rcMonitor.left,
1146                             mi.rcMonitor.bottom - mi.rcMonitor.top,
1147                             SWP_NOZORDER|SWP_FRAMECHANGED );
1148 #endif
1149         }
1150         else
1151         {
1152             /* Maximize non embedded window */
1153             ShowWindow( hwnd, SW_SHOWMAXIMIZED );
1154         }
1155
1156         if( p_vout->p_sys->hparent )
1157         {
1158             /* Hide the previous window */
1159             RECT rect;
1160             GetClientRect( hwnd, &rect );
1161             SetParent( p_vout->p_sys->hwnd, hwnd );
1162             SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
1163                           rect.right, rect.bottom,
1164                           SWP_NOZORDER|SWP_FRAMECHANGED );
1165
1166 #ifdef UNDER_CE
1167             HWND topLevelParent = GetParent( p_vout->p_sys->hparent );
1168 #else
1169             HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT );
1170 #endif
1171             ShowWindow( topLevelParent, SW_HIDE );
1172         }
1173
1174         SetForegroundWindow( hwnd );
1175     }
1176     else
1177     {
1178         msg_Dbg( p_vout, "leaving fullscreen mode" );
1179         /* Change window style, no borders and no title bar */
1180         SetWindowLong( hwnd, GWL_STYLE, p_vout->p_sys->i_window_style );
1181
1182         if( p_vout->p_sys->hparent )
1183         {
1184             RECT rect;
1185             GetClientRect( p_vout->p_sys->hparent, &rect );
1186             SetParent( p_vout->p_sys->hwnd, p_vout->p_sys->hparent );
1187             SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
1188                           rect.right, rect.bottom,
1189                           SWP_NOZORDER|SWP_FRAMECHANGED );
1190
1191 #ifdef UNDER_CE
1192             HWND topLevelParent = GetParent( p_vout->p_sys->hparent );
1193 #else
1194             HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT );
1195 #endif
1196             ShowWindow( topLevelParent, SW_SHOW );
1197             SetForegroundWindow( p_vout->p_sys->hparent );
1198             ShowWindow( hwnd, SW_HIDE );
1199         }
1200         else
1201         {
1202             /* return to normal window for non embedded vout */
1203             SetWindowPlacement( hwnd, &window_placement );
1204             ShowWindow( hwnd, SW_SHOWNORMAL );
1205         }
1206
1207         /* Make sure the mouse cursor is displayed */
1208         PostMessage( p_vout->p_sys->hwnd, WM_VLC_SHOW_MOUSE, 0, 0 );
1209     }
1210
1211     /* Update the object variable and trigger callback */
1212     var_SetBool( p_vout, "fullscreen", p_vout->b_fullscreen );
1213 }