]> git.sesse.net Git - vlc/blob - modules/video_output/msw/common.c
msw : support for vout_window_SetFullscreen
[vlc] / modules / video_output / msw / common.c
1 /*****************************************************************************
2  * common.c:
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 #include <assert.h>
33
34 #include <vlc_common.h>
35 #include <vlc_vout_display.h>
36 #include <vlc_vout_window.h>
37
38 #include <windows.h>
39 #include <windowsx.h>
40 #include <shellapi.h>
41
42 #ifdef MODULE_NAME_IS_directx
43 #include <ddraw.h>
44 #endif
45 #ifdef MODULE_NAME_IS_direct3d
46 #include <d3d9.h>
47 #endif
48 #ifdef MODULE_NAME_IS_glwin32
49 #include "../opengl.h"
50 #endif
51
52 #include "common.h"
53
54 #ifndef UNDER_CE
55 #include <vlc_windows_interfaces.h>
56 #endif
57
58 #ifdef UNDER_CE
59 #include <aygshell.h>
60     //WINSHELLAPI BOOL WINAPI SHFullScreen(HWND hwndRequester, DWORD dwState);
61 #endif
62
63 static int CommonControlSetFullscreen(vout_display_t *, bool is_fullscreen);
64
65 static void DisableScreensaver(vout_display_t *);
66 static void RestoreScreensaver(vout_display_t *);
67
68 /* */
69 int CommonInit(vout_display_t *vd)
70 {
71     vout_display_sys_t *sys = vd->sys;
72
73     sys->hwnd      = NULL;
74     sys->hvideownd = NULL;
75     sys->hparent   = NULL;
76     sys->hfswnd    = NULL;
77     sys->changes   = 0;
78     SetRectEmpty(&sys->rect_display);
79     SetRectEmpty(&sys->rect_parent);
80     sys->is_first_display = true;
81     sys->is_on_top = false;
82
83     var_Create(vd, "video-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
84     var_Create(vd, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
85
86     /* FIXME remove mouse hide from msw */
87     var_Create(vd, "mouse-hide-timeout", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
88
89     /* */
90     sys->event = EventThreadCreate(vd);
91     if (!sys->event)
92         return VLC_EGENERIC;
93
94     event_cfg_t cfg;
95     memset(&cfg, 0, sizeof(cfg));
96 #ifdef MODULE_NAME_IS_direct3d
97     cfg.use_desktop = sys->use_desktop;
98 #endif
99 #ifdef MODULE_NAME_IS_directx
100     cfg.use_overlay = sys->b_using_overlay;
101 #endif
102     cfg.win.type   = VOUT_WINDOW_TYPE_HWND;
103     cfg.win.x      = 0;
104     cfg.win.y      = 0;
105     cfg.win.width  = vd->cfg->display.width;
106     cfg.win.height = vd->cfg->display.height;
107
108     event_hwnd_t hwnd;
109     if (EventThreadStart(sys->event, &hwnd, &cfg))
110         return VLC_EGENERIC;
111
112     sys->parent_window = hwnd.parent_window;
113     sys->hparent       = hwnd.hparent;
114     sys->hwnd          = hwnd.hwnd;
115     sys->hvideownd     = hwnd.hvideownd;
116     sys->hfswnd        = hwnd.hfswnd;
117
118     if (vd->cfg->is_fullscreen) {
119         if (CommonControlSetFullscreen(vd, true))
120             vout_display_SendEventFullscreen(vd, false);
121     }
122
123     /* Why not with glwin32 */
124 #if !defined(UNDER_CE) && !defined(MODULE_NAME_IS_glwin32)
125     var_Create(vd, "disable-screensaver", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
126     DisableScreensaver (vd);
127 #endif
128
129     return VLC_SUCCESS;
130 }
131
132 /* */
133 void CommonClean(vout_display_t *vd)
134 {
135     vout_display_sys_t *sys = vd->sys;
136
137     if (sys->event) {
138         EventThreadStop(sys->event);
139         EventThreadDestroy(sys->event);
140     }
141
142 #if !defined(UNDER_CE) && !defined(MODULE_NAME_IS_glwin32)
143     RestoreScreensaver(vd);
144 #endif
145 }
146
147 void CommonManage(vout_display_t *vd)
148 {
149     vout_display_sys_t *sys = vd->sys;
150
151     /* We used to call the Win32 PeekMessage function here to read the window
152      * messages. But since window can stay blocked into this function for a
153      * long time (for example when you move your window on the screen), I
154      * decided to isolate PeekMessage in another thread. */
155
156     /* If we do not control our window, we check for geometry changes
157      * ourselves because the parent might not send us its events. */
158     if (sys->hparent) {
159         RECT rect_parent;
160         POINT point;
161
162         GetClientRect(sys->hparent, &rect_parent);
163         point.x = point.y = 0;
164         ClientToScreen(sys->hparent, &point);
165         OffsetRect(&rect_parent, point.x, point.y);
166
167         if (!EqualRect(&rect_parent, &sys->rect_parent)) {
168             sys->rect_parent = rect_parent;
169
170             /* FIXME I find such #ifdef quite weirds. Are they really needed ? */
171
172 #if defined(MODULE_NAME_IS_direct3d)
173             SetWindowPos(sys->hwnd, 0, 0, 0,
174                          rect_parent.right - rect_parent.left,
175                          rect_parent.bottom - rect_parent.top,
176                          SWP_NOZORDER);
177             UpdateRects(vd, NULL, NULL, true);
178 #else
179             /* This one is to force the update even if only
180              * the position has changed */
181             SetWindowPos(sys->hwnd, 0, 1, 1,
182                          rect_parent.right - rect_parent.left,
183                          rect_parent.bottom - rect_parent.top, 0);
184
185             SetWindowPos(sys->hwnd, 0, 0, 0,
186                          rect_parent.right - rect_parent.left,
187                          rect_parent.bottom - rect_parent.top, 0);
188
189 #if defined(MODULE_NAME_IS_wingdi) || defined(MODULE_NAME_IS_wingapi)
190             unsigned int i_x, i_y, i_width, i_height;
191             vout_PlacePicture(vd, rect_parent.right - rect_parent.left,
192                               rect_parent.bottom - rect_parent.top,
193                               &i_x, &i_y, &i_width, &i_height);
194
195             SetWindowPos(sys->hvideownd, HWND_TOP,
196                          i_x, i_y, i_width, i_height, 0);
197 #endif
198 #endif
199         }
200     }
201
202     /* */
203     if (EventThreadGetAndResetHasMoved(sys->event))
204         UpdateRects(vd, NULL, NULL, false);
205
206     /* Pointer change */
207     EventThreadMouseAutoHide(sys->event);
208 }
209
210 /**
211  * It ensures that the video window is shown after the first picture
212  * is displayed.
213  */
214 void CommonDisplay(vout_display_t *vd)
215 {
216     vout_display_sys_t *sys = vd->sys;
217
218     if (!sys->is_first_display)
219         return;
220
221     /* Video window is initially hidden, show it now since we got a
222      * picture to show.
223      */
224     SetWindowPos(sys->hvideownd, 0, 0, 0, 0, 0,
225                  SWP_ASYNCWINDOWPOS|
226                  SWP_FRAMECHANGED|
227                  SWP_SHOWWINDOW|
228                  SWP_NOMOVE|
229                  SWP_NOSIZE|
230                  SWP_NOZORDER);
231     sys->is_first_display = false;
232 }
233
234 /*****************************************************************************
235  * UpdateRects: update clipping rectangles
236  *****************************************************************************
237  * This function is called when the window position or size are changed, and
238  * its job is to update the source and destination RECTs used to display the
239  * picture.
240  *****************************************************************************/
241 void UpdateRects(vout_display_t *vd,
242                   const vout_display_cfg_t *cfg,
243                   const video_format_t *source,
244                   bool is_forced)
245 {
246     vout_display_sys_t *sys = vd->sys;
247 #define rect_src sys->rect_src
248 #define rect_src_clipped sys->rect_src_clipped
249 #define rect_dest sys->rect_dest
250 #define rect_dest_clipped sys->rect_dest_clipped
251
252     RECT  rect;
253     POINT point;
254
255     /* Retrieve the window size */
256     GetClientRect(sys->hwnd, &rect);
257
258     /* Retrieve the window position */
259     point.x = point.y = 0;
260     ClientToScreen(sys->hwnd, &point);
261
262     /* If nothing changed, we can return */
263     bool has_changed;
264     EventThreadUpdateWindowPosition(sys->event, &has_changed,
265                                     point.x, point.y,
266                                     rect.right, rect.bottom);
267     if (!is_forced && !has_changed)
268         return;
269
270     /* */
271     if (!cfg)
272         cfg = vd->cfg;
273     if (!source)
274         source = &vd->source;
275
276     /* Update the window position and size */
277     vout_display_cfg_t place_cfg = *cfg;
278     place_cfg.display.width  = rect.right;
279     place_cfg.display.height = rect.bottom;
280
281     vout_display_place_t place;
282     vout_display_PlacePicture(&place, source, &place_cfg, true);
283
284     EventThreadUpdateSourceAndPlace(sys->event, source, &place);
285
286     if (sys->hvideownd)
287         SetWindowPos(sys->hvideownd, 0,
288                      place.x, place.y, place.width, place.height,
289                      SWP_NOCOPYBITS|SWP_NOZORDER|SWP_ASYNCWINDOWPOS);
290
291     /* Destination image position and dimensions */
292 #if defined(MODULE_NAME_IS_direct3d)
293     rect_dest.left   = 0;
294     rect_dest.right  = place.width;
295     rect_dest.top    = 0;
296     rect_dest.bottom = place.height;
297 #else
298     rect_dest.left = point.x + place.x;
299     rect_dest.right = rect_dest.left + place.width;
300     rect_dest.top = point.y + place.y;
301     rect_dest.bottom = rect_dest.top + place.height;
302
303 #ifdef MODULE_NAME_IS_directx
304     /* Apply overlay hardware constraints */
305     if (sys->b_using_overlay) {
306         if (sys->i_align_dest_boundary)
307             rect_dest.left = (rect_dest.left +
308                               sys->i_align_dest_boundary / 2) &
309                                         ~sys->i_align_dest_boundary;
310
311         if (sys->i_align_dest_size)
312             rect_dest.right = ((rect_dest.right -
313                                 rect_dest.left +
314                                 sys->i_align_dest_size / 2) &
315                                     ~sys->i_align_dest_size) + rect_dest.left;
316     }
317 #endif
318
319 #endif
320
321 #if defined(MODULE_NAME_IS_directx) || defined(MODULE_NAME_IS_direct3d)
322     /* UpdateOverlay directdraw function doesn't automatically clip to the
323      * display size so we need to do it otherwise it will fail
324      * It is also needed for d3d to avoid exceding our surface size */
325
326     /* Clip the destination window */
327     if (!IntersectRect(&rect_dest_clipped, &rect_dest,
328                        &sys->rect_display)) {
329         SetRectEmpty(&rect_src_clipped);
330         return;
331     }
332
333 #ifndef NDEBUG
334     msg_Dbg(vd, "DirectXUpdateRects image_dst_clipped coords:"
335                 " %li,%li,%li,%li",
336                 rect_dest_clipped.left, rect_dest_clipped.top,
337                 rect_dest_clipped.right, rect_dest_clipped.bottom);
338 #endif
339
340 #else
341
342     /* AFAIK, there are no clipping constraints in Direct3D, OpenGL and GDI */
343     rect_dest_clipped = rect_dest;
344
345 #endif
346
347     /* the 2 following lines are to fix a bug when clicking on the desktop */
348     if ((rect_dest_clipped.right - rect_dest_clipped.left) == 0 ||
349         (rect_dest_clipped.bottom - rect_dest_clipped.top) == 0) {
350         SetRectEmpty(&rect_src_clipped);
351         return;
352     }
353
354     /* src image dimensions */
355     rect_src.left   = 0;
356     rect_src.top    = 0;
357     rect_src.right  = source->i_width;
358     rect_src.bottom = source->i_height;
359
360     /* Clip the source image */
361     rect_src_clipped.left = source->i_x_offset +
362       (rect_dest_clipped.left - rect_dest.left) *
363       source->i_visible_width / (rect_dest.right - rect_dest.left);
364     rect_src_clipped.right = source->i_x_offset +
365       source->i_visible_width -
366       (rect_dest.right - rect_dest_clipped.right) *
367       source->i_visible_width / (rect_dest.right - rect_dest.left);
368     rect_src_clipped.top = source->i_y_offset +
369       (rect_dest_clipped.top - rect_dest.top) *
370       source->i_visible_height / (rect_dest.bottom - rect_dest.top);
371     rect_src_clipped.bottom = source->i_y_offset +
372       source->i_visible_height -
373       (rect_dest.bottom - rect_dest_clipped.bottom) *
374       source->i_visible_height / (rect_dest.bottom - rect_dest.top);
375
376 #ifdef MODULE_NAME_IS_directx
377     /* Apply overlay hardware constraints */
378     if (sys->b_using_overlay) {
379         if (sys->i_align_src_boundary)
380             rect_src_clipped.left =
381                 (rect_src_clipped.left +
382                  sys->i_align_src_boundary / 2) &
383                             ~sys->i_align_src_boundary;
384
385         if (sys->i_align_src_size)
386             rect_src_clipped.right =
387                 ((rect_src_clipped.right - rect_src_clipped.left +
388                   sys->i_align_src_size / 2) &
389                             ~sys->i_align_src_size) + rect_src_clipped.left;
390     }
391 #elif defined(MODULE_NAME_IS_direct3d)
392     /* Needed at least with YUV content */
393     rect_src_clipped.left &= ~1;
394     rect_src_clipped.right &= ~1;
395     rect_src_clipped.top &= ~1;
396     rect_src_clipped.bottom &= ~1;
397 #endif
398
399 #ifndef NDEBUG
400     msg_Dbg(vd, "DirectXUpdateRects image_src_clipped"
401                 " coords: %li,%li,%li,%li",
402                 rect_src_clipped.left, rect_src_clipped.top,
403                 rect_src_clipped.right, rect_src_clipped.bottom);
404 #endif
405
406 #ifdef MODULE_NAME_IS_directx
407     /* The destination coordinates need to be relative to the current
408      * directdraw primary surface (display) */
409     rect_dest_clipped.left -= sys->rect_display.left;
410     rect_dest_clipped.right -= sys->rect_display.left;
411     rect_dest_clipped.top -= sys->rect_display.top;
412     rect_dest_clipped.bottom -= sys->rect_display.top;
413
414     if (sys->b_using_overlay)
415         DirectDrawUpdateOverlay(vd);
416 #endif
417
418 #ifndef UNDER_CE
419     /* Windows 7 taskbar thumbnail code */
420     LPTASKBARLIST3 taskbl;
421     OSVERSIONINFO winVer;
422     winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
423     if (GetVersionEx(&winVer) && winVer.dwMajorVersion > 5) {
424         CoInitialize(0);
425
426         if (S_OK == CoCreateInstance(&clsid_ITaskbarList,
427                                      NULL, CLSCTX_INPROC_SERVER,
428                                      &IID_ITaskbarList3,
429                                      &taskbl)) {
430             RECT rect_video, rect_parent, rect_relative;
431             HWND hroot = GetAncestor(sys->hwnd,GA_ROOT);
432
433             taskbl->vt->HrInit(taskbl);
434             GetWindowRect(sys->hvideownd, &rect_video);
435             GetWindowRect(hroot, &rect_parent);
436             rect_relative.left = rect_video.left - rect_parent.left - 8;
437             rect_relative.right = rect_video.right - rect_video.left + rect_relative.left;
438             rect_relative.top = rect_video.top - rect_parent.top - 10;
439             rect_relative.bottom = rect_video.bottom - rect_video.top + rect_relative.top - 25;
440
441             if (S_OK != taskbl->vt->SetThumbnailClip(taskbl, hroot, &rect_relative))
442                 msg_Err(vd, "SetThumbNailClip failed");
443
444             taskbl->vt->Release(taskbl);
445         }
446         CoUninitialize();
447     }
448 #endif
449     /* Signal the change in size/position */
450     sys->changes |= DX_POSITION_CHANGE;
451
452 #undef rect_src
453 #undef rect_src_clipped
454 #undef rect_dest
455 #undef rect_dest_clipped
456 }
457
458 static int CommonControlSetFullscreen(vout_display_t *vd, bool is_fullscreen)
459 {
460     vout_display_sys_t *sys = vd->sys;
461
462 #ifdef MODULE_NAME_IS_direct3d
463     if (sys->use_desktop && is_fullscreen)
464         return VLC_EGENERIC;
465 #endif
466
467     /* */
468     if (sys->parent_window)
469         return vout_window_SetFullScreen(sys->parent_window, is_fullscreen);
470
471     /* */
472     HWND hwnd = sys->hparent && sys->hfswnd ? sys->hfswnd : sys->hwnd;
473
474     /* Save the current windows placement/placement to restore
475        when fullscreen is over */
476     WINDOWPLACEMENT window_placement;
477     window_placement.length = sizeof(WINDOWPLACEMENT);
478     GetWindowPlacement(hwnd, &window_placement);
479
480     if (is_fullscreen) {
481         msg_Dbg(vd, "entering fullscreen mode");
482
483         /* Change window style, no borders and no title bar */
484         SetWindowLong(hwnd, GWL_STYLE, WS_CLIPCHILDREN | WS_VISIBLE);
485
486         if (sys->hparent) {
487 #ifdef UNDER_CE
488             POINT point = {0,0};
489             RECT rect;
490             ClientToScreen(sys->hwnd, &point);
491             GetClientRect(sys->hwnd, &rect);
492             SetWindowPos(hwnd, 0, point.x, point.y,
493                          rect.right, rect.bottom,
494                          SWP_NOZORDER|SWP_FRAMECHANGED);
495 #else
496             /* Retrieve current window position so fullscreen will happen
497             *on the right screen */
498             HMONITOR hmon = MonitorFromWindow(sys->hparent,
499                                               MONITOR_DEFAULTTONEAREST);
500             MONITORINFO mi;
501             mi.cbSize = sizeof(MONITORINFO);
502             if (GetMonitorInfo(hmon, &mi))
503                 SetWindowPos(hwnd, 0,
504                              mi.rcMonitor.left,
505                              mi.rcMonitor.top,
506                              mi.rcMonitor.right - mi.rcMonitor.left,
507                              mi.rcMonitor.bottom - mi.rcMonitor.top,
508                              SWP_NOZORDER|SWP_FRAMECHANGED);
509 #endif
510         } else {
511             /* Maximize non embedded window */
512             ShowWindow(hwnd, SW_SHOWMAXIMIZED);
513         }
514
515         if (sys->hparent) {
516             /* Hide the previous window */
517             RECT rect;
518             GetClientRect(hwnd, &rect);
519             SetParent(sys->hwnd, hwnd);
520             SetWindowPos(sys->hwnd, 0, 0, 0,
521                          rect.right, rect.bottom,
522                          SWP_NOZORDER|SWP_FRAMECHANGED);
523
524 #ifdef UNDER_CE
525             HWND topLevelParent = GetParent(sys->hparent);
526 #else
527             HWND topLevelParent = GetAncestor(sys->hparent, GA_ROOT);
528 #endif
529             ShowWindow(topLevelParent, SW_HIDE);
530         }
531         SetForegroundWindow(hwnd);
532     } else {
533         msg_Dbg(vd, "leaving fullscreen mode");
534
535         /* Change window style, no borders and no title bar */
536         SetWindowLong(hwnd, GWL_STYLE, EventThreadGetWindowStyle(sys->event));
537
538         if (sys->hparent) {
539             RECT rect;
540             GetClientRect(sys->hparent, &rect);
541             SetParent(sys->hwnd, sys->hparent);
542             SetWindowPos(sys->hwnd, 0, 0, 0,
543                          rect.right, rect.bottom,
544                          SWP_NOZORDER|SWP_FRAMECHANGED);
545
546 #ifdef UNDER_CE
547             HWND topLevelParent = GetParent(sys->hparent);
548 #else
549             HWND topLevelParent = GetAncestor(sys->hparent, GA_ROOT);
550 #endif
551             ShowWindow(topLevelParent, SW_SHOW);
552             SetForegroundWindow(sys->hparent);
553             ShowWindow(hwnd, SW_HIDE);
554         } else {
555             /* return to normal window for non embedded vout */
556             SetWindowPlacement(hwnd, &window_placement);
557             ShowWindow(hwnd, SW_SHOWNORMAL);
558         }
559
560         /* Make sure the mouse cursor is displayed */
561         EventThreadMouseShow(sys->event);
562     }
563     return VLC_SUCCESS;
564 }
565
566 int CommonControl(vout_display_t *vd, int query, va_list args)
567 {
568     vout_display_sys_t *sys = vd->sys;
569
570     switch (query) {
571     case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:   /* const vout_display_cfg_t *p_cfg, int is_forced */
572     case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED: /* const vout_display_cfg_t *p_cfg */
573     case VOUT_DISPLAY_CHANGE_ZOOM:           /* const vout_display_cfg_t *p_cfg */
574     case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:  /* const video_format_t *p_source */
575     case VOUT_DISPLAY_CHANGE_SOURCE_CROP: {  /* const video_format_t *p_source */
576         const vout_display_cfg_t *cfg;
577         const video_format_t *source;
578         bool  is_forced = true;
579         if (query == VOUT_DISPLAY_CHANGE_SOURCE_CROP ||
580             query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT) {
581             cfg    = vd->cfg;
582             source = va_arg(args, const video_format_t *);
583         } else {
584             cfg    = va_arg(args, const vout_display_cfg_t *);
585             source = &vd->source;
586             if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
587                 is_forced = va_arg(args, int);
588         }
589         if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE && is_forced) {
590             /* Update dimensions */
591             if (sys->parent_window) {
592                 vout_window_SetSize(sys->parent_window, cfg->display.width, cfg->display.height);
593             } else {
594                 RECT rect_window;
595                 rect_window.top    = 0;
596                 rect_window.left   = 0;
597                 rect_window.right  = cfg->display.width;
598                 rect_window.bottom = cfg->display.height;
599                 AdjustWindowRect(&rect_window, EventThreadGetWindowStyle(sys->event), 0);
600
601                 SetWindowPos(sys->hwnd, 0, 0, 0,
602                              rect_window.right - rect_window.left,
603                              rect_window.bottom - rect_window.top, SWP_NOMOVE);
604             }
605         }
606         UpdateRects(vd, cfg, source, is_forced);
607         return VLC_SUCCESS;
608     }
609     case VOUT_DISPLAY_CHANGE_WINDOW_STATE: {       /* unsigned state */
610         const unsigned state = va_arg(args, unsigned);
611         const bool is_on_top = (state & VOUT_WINDOW_STATE_ABOVE) != 0;
612 #ifdef MODULE_NAME_IS_direct3d
613         if (sys->use_desktop && is_on_top)
614             return VLC_EGENERIC;
615 #endif
616         if (sys->parent_window) {
617             if (vout_window_SetState(sys->parent_window, state))
618                 return VLC_EGENERIC;
619         } else {
620             HMENU hMenu = GetSystemMenu(sys->hwnd, FALSE);
621
622             if (is_on_top && !(GetWindowLong(sys->hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
623                 CheckMenuItem(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_CHECKED);
624                 SetWindowPos(sys->hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
625             } else if (!is_on_top && (GetWindowLong(sys->hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
626                 CheckMenuItem(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_UNCHECKED);
627                 SetWindowPos(sys->hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
628             }
629         }
630         sys->is_on_top = is_on_top;
631         return VLC_SUCCESS;
632     }
633     case VOUT_DISPLAY_CHANGE_FULLSCREEN: {   /* const vout_display_cfg_t *p_cfg */
634         const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
635         return CommonControlSetFullscreen(vd, cfg->is_fullscreen);
636     }
637
638     case VOUT_DISPLAY_RESET_PICTURES:
639     case VOUT_DISPLAY_HIDE_MOUSE:
640         assert(0);
641     default:
642         return VLC_EGENERIC;
643     }
644 }
645
646 #ifndef UNDER_CE
647 static void DisableScreensaver(vout_display_t *vd)
648 {
649     vout_display_sys_t *sys = vd->sys;
650
651     /* disable screensaver by temporarily changing system settings */
652     sys->i_spi_lowpowertimeout = 0;
653     sys->i_spi_powerofftimeout = 0;
654     sys->i_spi_screensavetimeout = 0;
655     if (var_GetBool(vd, "disable-screensaver")) {
656         msg_Dbg(vd, "disabling screen saver");
657         SystemParametersInfo(SPI_GETLOWPOWERTIMEOUT, 0,
658                              &sys->i_spi_lowpowertimeout, 0);
659         if (0 != sys->i_spi_lowpowertimeout) {
660             SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, 0, NULL, 0);
661         }
662         SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT, 0,
663                              &sys->i_spi_powerofftimeout, 0);
664         if (0 != sys->i_spi_powerofftimeout) {
665             SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);
666         }
667         SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0,
668                              &sys->i_spi_screensavetimeout, 0);
669         if (0 != sys->i_spi_screensavetimeout) {
670             SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0);
671         }
672     }
673 }
674
675 static void RestoreScreensaver(vout_display_t *vd)
676 {
677     vout_display_sys_t *sys = vd->sys;
678
679     /* restore screensaver system settings */
680     if (0 != sys->i_spi_lowpowertimeout) {
681         SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT,
682                              sys->i_spi_lowpowertimeout, NULL, 0);
683     }
684     if (0 != sys->i_spi_powerofftimeout) {
685         SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT,
686                              sys->i_spi_powerofftimeout, NULL, 0);
687     }
688     if (0 != sys->i_spi_screensavetimeout) {
689         SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT,
690                              sys->i_spi_screensavetimeout, NULL, 0);
691     }
692 }
693 #endif
694