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