]> git.sesse.net Git - vlc/blob - modules/video_output/msw/common.c
Converted direct3d to vout display.
[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 <GL/gl.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 && !vd->cfg->is_fullscreen) {
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  * UpdateRects: update clipping rectangles
212  *****************************************************************************
213  * This function is called when the window position or size are changed, and
214  * its job is to update the source and destination RECTs used to display the
215  * picture.
216  *****************************************************************************/
217 void UpdateRects(vout_display_t *vd,
218                   const vout_display_cfg_t *cfg,
219                   const video_format_t *source,
220                   bool is_forced)
221 {
222     vout_display_sys_t *sys = vd->sys;
223 #define rect_src sys->rect_src
224 #define rect_src_clipped sys->rect_src_clipped
225 #define rect_dest sys->rect_dest
226 #define rect_dest_clipped sys->rect_dest_clipped
227
228     RECT  rect;
229     POINT point;
230
231     /* Retrieve the window size */
232     GetClientRect(sys->hwnd, &rect);
233
234     /* Retrieve the window position */
235     point.x = point.y = 0;
236     ClientToScreen(sys->hwnd, &point);
237
238     /* If nothing changed, we can return */
239     bool has_changed;
240     EventThreadUpdateWindowPosition(sys->event, &has_changed,
241                                     point.x, point.y,
242                                     rect.right, rect.bottom);
243     if (!is_forced && !has_changed)
244         return;
245
246     /* */
247     if (!cfg)
248         cfg = vd->cfg;
249     if (!source)
250         source = &vd->source;
251
252     /* Update the window position and size */
253     vout_display_cfg_t place_cfg = *cfg;
254     place_cfg.display.width  = rect.right;
255     place_cfg.display.height = rect.bottom;
256
257     vout_display_place_t place;
258     vout_display_PlacePicture(&place, source, &place_cfg, true);
259
260     EventThreadUpdateSourceAndPlace(sys->event, source, &place);
261
262     if (sys->hvideownd)
263         SetWindowPos(sys->hvideownd, 0,
264                      place.x, place.y, place.width, place.height,
265                      SWP_NOCOPYBITS|SWP_NOZORDER|SWP_ASYNCWINDOWPOS);
266
267     /* Destination image position and dimensions */
268 #if defined(MODULE_NAME_IS_direct3d)
269     rect_dest.left   = 0;
270     rect_dest.right  = place.width;
271     rect_dest.top    = 0;
272     rect_dest.bottom = place.height;
273 #else
274     rect_dest.left = point.x + place.x;
275     rect_dest.right = rect_dest.left + place.width;
276     rect_dest.top = point.y + place.y;
277     rect_dest.bottom = rect_dest.top + place.height;
278
279 #ifdef MODULE_NAME_IS_directx
280     /* Apply overlay hardware constraints */
281     if (sys->b_using_overlay) {
282         if (sys->i_align_dest_boundary)
283             rect_dest.left = (rect_dest.left +
284                               sys->i_align_dest_boundary / 2) &
285                                         ~sys->i_align_dest_boundary;
286
287         if (sys->i_align_dest_size)
288             rect_dest.right = ((rect_dest.right -
289                                 rect_dest.left +
290                                 sys->i_align_dest_size / 2) &
291                                     ~sys->i_align_dest_size) + rect_dest.left;
292     }
293 #endif
294
295 #endif
296
297 #if defined(MODULE_NAME_IS_directx) || defined(MODULE_NAME_IS_direct3d)
298     /* UpdateOverlay directdraw function doesn't automatically clip to the
299      * display size so we need to do it otherwise it will fail
300      * It is also needed for d3d to avoid exceding our surface size */
301
302     /* Clip the destination window */
303     if (!IntersectRect(&rect_dest_clipped, &rect_dest,
304                        &sys->rect_display)) {
305         SetRectEmpty(&rect_src_clipped);
306         return;
307     }
308
309 #ifndef NDEBUG
310     msg_Dbg(vd, "DirectXUpdateRects image_dst_clipped coords:"
311                 " %li,%li,%li,%li",
312                 rect_dest_clipped.left, rect_dest_clipped.top,
313                 rect_dest_clipped.right, rect_dest_clipped.bottom);
314 #endif
315
316 #else
317
318     /* AFAIK, there are no clipping constraints in Direct3D, OpenGL and GDI */
319     rect_dest_clipped = rect_dest;
320
321 #endif
322
323     /* the 2 following lines are to fix a bug when clicking on the desktop */
324     if ((rect_dest_clipped.right - rect_dest_clipped.left) == 0 ||
325         (rect_dest_clipped.bottom - rect_dest_clipped.top) == 0) {
326         SetRectEmpty(&rect_src_clipped);
327         return;
328     }
329
330     /* src image dimensions */
331     rect_src.left   = 0;
332     rect_src.top    = 0;
333     rect_src.right  = source->i_width;
334     rect_src.bottom = source->i_height;
335
336     /* Clip the source image */
337     rect_src_clipped.left = source->i_x_offset +
338       (rect_dest_clipped.left - rect_dest.left) *
339       source->i_visible_width / (rect_dest.right - rect_dest.left);
340     rect_src_clipped.right = source->i_x_offset +
341       source->i_visible_width -
342       (rect_dest.right - rect_dest_clipped.right) *
343       source->i_visible_width / (rect_dest.right - rect_dest.left);
344     rect_src_clipped.top = source->i_y_offset +
345       (rect_dest_clipped.top - rect_dest.top) *
346       source->i_visible_height / (rect_dest.bottom - rect_dest.top);
347     rect_src_clipped.bottom = source->i_y_offset +
348       source->i_visible_height -
349       (rect_dest.bottom - rect_dest_clipped.bottom) *
350       source->i_visible_height / (rect_dest.bottom - rect_dest.top);
351
352 #ifdef MODULE_NAME_IS_directx
353     /* Apply overlay hardware constraints */
354     if (sys->b_using_overlay) {
355         if (sys->i_align_src_boundary)
356             rect_src_clipped.left =
357                 (rect_src_clipped.left +
358                  sys->i_align_src_boundary / 2) &
359                             ~sys->i_align_src_boundary;
360
361         if (sys->i_align_src_size)
362             rect_src_clipped.right =
363                 ((rect_src_clipped.right - rect_src_clipped.left +
364                   sys->i_align_src_size / 2) &
365                             ~sys->i_align_src_size) + rect_src_clipped.left;
366     }
367 #elif defined(MODULE_NAME_IS_direct3d)
368     /* Needed at least with YUV content */
369     rect_src_clipped.left &= ~1;
370     rect_src_clipped.right &= ~1;
371     rect_src_clipped.top &= ~1;
372     rect_src_clipped.bottom &= ~1;
373 #endif
374
375 #ifndef NDEBUG
376     msg_Dbg(vd, "DirectXUpdateRects image_src_clipped"
377                 " coords: %li,%li,%li,%li",
378                 rect_src_clipped.left, rect_src_clipped.top,
379                 rect_src_clipped.right, rect_src_clipped.bottom);
380 #endif
381
382 #ifdef MODULE_NAME_IS_directx
383     /* The destination coordinates need to be relative to the current
384      * directdraw primary surface (display) */
385     rect_dest_clipped.left -= sys->rect_display.left;
386     rect_dest_clipped.right -= sys->rect_display.left;
387     rect_dest_clipped.top -= sys->rect_display.top;
388     rect_dest_clipped.bottom -= sys->rect_display.top;
389
390     if (sys->b_using_overlay)
391         DirectDrawUpdateOverlay(vd);
392 #endif
393
394 #ifndef UNDER_CE
395     /* Windows 7 taskbar thumbnail code */
396     LPTASKBARLIST3 taskbl;
397     OSVERSIONINFO winVer;
398     winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
399     if (GetVersionEx(&winVer) && winVer.dwMajorVersion > 5) {
400         CoInitialize(0);
401
402         if (S_OK == CoCreateInstance(&clsid_ITaskbarList,
403                                      NULL, CLSCTX_INPROC_SERVER,
404                                      &IID_ITaskbarList3,
405                                      &taskbl)) {
406             RECT rect_video, rect_parent, rect_relative;
407             HWND hroot = GetAncestor(sys->hwnd,GA_ROOT);
408
409             taskbl->vt->HrInit(taskbl);
410             GetWindowRect(sys->hvideownd, &rect_video);
411             GetWindowRect(hroot, &rect_parent);
412             rect_relative.left = rect_video.left - rect_parent.left - 8;
413             rect_relative.right = rect_video.right - rect_video.left + rect_relative.left;
414             rect_relative.top = rect_video.top - rect_parent.top - 10;
415             rect_relative.bottom = rect_video.bottom - rect_video.top + rect_relative.top - 25;
416
417             if (S_OK != taskbl->vt->SetThumbnailClip(taskbl, hroot, &rect_relative))
418                 msg_Err(vd, "SetThumbNailClip failed");
419
420             taskbl->vt->Release(taskbl);
421         }
422         CoUninitialize();
423     }
424 #endif
425     /* Signal the change in size/position */
426     sys->changes |= DX_POSITION_CHANGE;
427
428 #undef rect_src
429 #undef rect_src_clipped
430 #undef rect_dest
431 #undef rect_dest_clipped
432 }
433
434 static int CommonControlSetFullscreen(vout_display_t *vd, bool is_fullscreen)
435 {
436     vout_display_sys_t *sys = vd->sys;
437
438 #ifdef MODULE_NAME_IS_direct3d
439     if (sys->use_desktop && is_fullscreen)
440         return VLC_EGENERIC;
441 #endif
442
443     /* */
444     if (sys->parent_window)
445         return vout_window_SetFullScreen(sys->parent_window, is_fullscreen);
446
447     /* */
448     HWND hwnd = sys->hparent && sys->hfswnd ? sys->hfswnd : sys->hwnd;
449
450     /* Save the current windows placement/placement to restore
451        when fullscreen is over */
452     WINDOWPLACEMENT window_placement;
453     window_placement.length = sizeof(WINDOWPLACEMENT);
454     GetWindowPlacement(hwnd, &window_placement);
455
456     if (is_fullscreen) {
457         msg_Dbg(vd, "entering fullscreen mode");
458
459         /* Change window style, no borders and no title bar */
460         SetWindowLong(hwnd, GWL_STYLE, WS_CLIPCHILDREN | WS_VISIBLE);
461
462         if (sys->hparent) {
463 #ifdef UNDER_CE
464             POINT point = {0,0};
465             RECT rect;
466             ClientToScreen(sys->hwnd, &point);
467             GetClientRect(sys->hwnd, &rect);
468             SetWindowPos(hwnd, 0, point.x, point.y,
469                          rect.right, rect.bottom,
470                          SWP_NOZORDER|SWP_FRAMECHANGED);
471 #else
472             /* Retrieve current window position so fullscreen will happen
473             *on the right screen */
474             HMONITOR hmon = MonitorFromWindow(sys->hparent,
475                                               MONITOR_DEFAULTTONEAREST);
476             MONITORINFO mi;
477             mi.cbSize = sizeof(MONITORINFO);
478             if (GetMonitorInfo(hmon, &mi))
479                 SetWindowPos(hwnd, 0,
480                              mi.rcMonitor.left,
481                              mi.rcMonitor.top,
482                              mi.rcMonitor.right - mi.rcMonitor.left,
483                              mi.rcMonitor.bottom - mi.rcMonitor.top,
484                              SWP_NOZORDER|SWP_FRAMECHANGED);
485 #endif
486         } else {
487             /* Maximize non embedded window */
488             ShowWindow(hwnd, SW_SHOWMAXIMIZED);
489         }
490
491         if (sys->hparent) {
492             /* Hide the previous window */
493             RECT rect;
494             GetClientRect(hwnd, &rect);
495             SetParent(sys->hwnd, hwnd);
496             SetWindowPos(sys->hwnd, 0, 0, 0,
497                          rect.right, rect.bottom,
498                          SWP_NOZORDER|SWP_FRAMECHANGED);
499
500 #ifdef UNDER_CE
501             HWND topLevelParent = GetParent(sys->hparent);
502 #else
503             HWND topLevelParent = GetAncestor(sys->hparent, GA_ROOT);
504 #endif
505             ShowWindow(topLevelParent, SW_HIDE);
506         }
507         SetForegroundWindow(hwnd);
508     } else {
509         msg_Dbg(vd, "leaving fullscreen mode");
510
511         /* Change window style, no borders and no title bar */
512         SetWindowLong(hwnd, GWL_STYLE, EventThreadGetWindowStyle(sys->event));
513
514         if (sys->hparent) {
515             RECT rect;
516             GetClientRect(sys->hparent, &rect);
517             SetParent(sys->hwnd, sys->hparent);
518             SetWindowPos(sys->hwnd, 0, 0, 0,
519                          rect.right, rect.bottom,
520                          SWP_NOZORDER|SWP_FRAMECHANGED);
521
522 #ifdef UNDER_CE
523             HWND topLevelParent = GetParent(sys->hparent);
524 #else
525             HWND topLevelParent = GetAncestor(sys->hparent, GA_ROOT);
526 #endif
527             ShowWindow(topLevelParent, SW_SHOW);
528             SetForegroundWindow(sys->hparent);
529             ShowWindow(hwnd, SW_HIDE);
530         } else {
531             /* return to normal window for non embedded vout */
532             SetWindowPlacement(hwnd, &window_placement);
533             ShowWindow(hwnd, SW_SHOWNORMAL);
534         }
535
536         /* Make sure the mouse cursor is displayed */
537         EventThreadMouseShow(sys->event);
538     }
539     return VLC_SUCCESS;
540 }
541
542 int CommonControl(vout_display_t *vd, int query, va_list args)
543 {
544     vout_display_sys_t *sys = vd->sys;
545
546     switch (query) {
547     case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:   /* const vout_display_cfg_t *p_cfg, int is_forced */
548     case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED: /* const vout_display_cfg_t *p_cfg */
549     case VOUT_DISPLAY_CHANGE_ZOOM:           /* const vout_display_cfg_t *p_cfg */
550     case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:  /* const video_format_t *p_source */
551     case VOUT_DISPLAY_CHANGE_SOURCE_CROP: {  /* const video_format_t *p_source */
552         const vout_display_cfg_t *cfg;
553         const video_format_t *source;
554         bool  is_forced = true;
555         if (query == VOUT_DISPLAY_CHANGE_SOURCE_CROP ||
556             query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT) {
557             cfg    = vd->cfg;
558             source = va_arg(args, const video_format_t *);
559         } else {
560             cfg    = va_arg(args, const vout_display_cfg_t *);
561             source = &vd->source;
562             if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
563                 is_forced = va_arg(args, int);
564         }
565         if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE && is_forced) {
566             /* Update dimensions */
567             if (sys->parent_window) {
568                 vout_window_SetSize(sys->parent_window, cfg->display.width, cfg->display.height);
569             } else {
570                 RECT rect_window;
571                 rect_window.top    = 0;
572                 rect_window.left   = 0;
573                 rect_window.right  = cfg->display.width;
574                 rect_window.bottom = cfg->display.height;
575                 AdjustWindowRect(&rect_window, EventThreadGetWindowStyle(sys->event), 0);
576
577                 SetWindowPos(sys->hwnd, 0, 0, 0,
578                              rect_window.right - rect_window.left,
579                              rect_window.bottom - rect_window.top, SWP_NOMOVE);
580             }
581         }
582         UpdateRects(vd, cfg, source, is_forced);
583         return VLC_SUCCESS;
584     }
585     case VOUT_DISPLAY_CHANGE_ON_TOP: {       /* int b_on_top */
586         const bool is_on_top = va_arg(args, int);
587 #ifdef MODULE_NAME_IS_direct3d
588         if (sys->use_desktop && is_on_top)
589             return VLC_EGENERIC;
590 #endif
591         if (sys->parent_window) {
592             if (vout_window_SetOnTop(sys->parent_window, is_on_top))
593                 return VLC_EGENERIC;
594         } else {
595             HMENU hMenu = GetSystemMenu(sys->hwnd, FALSE);
596
597             if (is_on_top && !(GetWindowLong(sys->hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
598                 CheckMenuItem(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_CHECKED);
599                 SetWindowPos(sys->hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
600             } else if (!is_on_top && (GetWindowLong(sys->hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
601                 CheckMenuItem(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_UNCHECKED);
602                 SetWindowPos(sys->hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
603             }
604         }
605         sys->is_on_top = is_on_top;
606         return VLC_SUCCESS;
607     }
608     case VOUT_DISPLAY_CHANGE_FULLSCREEN: {   /* const vout_display_cfg_t *p_cfg */
609         const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
610         return CommonControlSetFullscreen(vd, cfg->is_fullscreen);
611     }
612
613     case VOUT_DISPLAY_RESET_PICTURES:
614     case VOUT_DISPLAY_HIDE_MOUSE:
615         assert(0);
616     default:
617         return VLC_EGENERIC;
618     }
619 }
620
621 #ifndef UNDER_CE
622 static void DisableScreensaver(vout_display_t *vd)
623 {
624     vout_display_sys_t *sys = vd->sys;
625
626     /* disable screensaver by temporarily changing system settings */
627     sys->i_spi_lowpowertimeout = 0;
628     sys->i_spi_powerofftimeout = 0;
629     sys->i_spi_screensavetimeout = 0;
630     if (var_GetBool(vd, "disable-screensaver")) {
631         msg_Dbg(vd, "disabling screen saver");
632         SystemParametersInfo(SPI_GETLOWPOWERTIMEOUT, 0,
633                              &sys->i_spi_lowpowertimeout, 0);
634         if (0 != sys->i_spi_lowpowertimeout) {
635             SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, 0, NULL, 0);
636         }
637         SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT, 0,
638                              &sys->i_spi_powerofftimeout, 0);
639         if (0 != sys->i_spi_powerofftimeout) {
640             SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);
641         }
642         SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0,
643                              &sys->i_spi_screensavetimeout, 0);
644         if (0 != sys->i_spi_screensavetimeout) {
645             SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0);
646         }
647     }
648 }
649
650 static void RestoreScreensaver(vout_display_t *vd)
651 {
652     vout_display_sys_t *sys = vd->sys;
653
654     /* restore screensaver system settings */
655     if (0 != sys->i_spi_lowpowertimeout) {
656         SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT,
657                              sys->i_spi_lowpowertimeout, NULL, 0);
658     }
659     if (0 != sys->i_spi_powerofftimeout) {
660         SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT,
661                              sys->i_spi_powerofftimeout, NULL, 0);
662     }
663     if (0 != sys->i_spi_screensavetimeout) {
664         SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT,
665                              sys->i_spi_screensavetimeout, NULL, 0);
666     }
667 }
668 #endif
669