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