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