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