]> git.sesse.net Git - vlc/blob - modules/video_output/msw/common.c
fddbd3dc02e5df36b302236f9de74d693068cfc7
[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 #ifdef MODULE_NAME_IS_direct2d
52 #include <d2d1.h>
53 #endif
54
55 #include "common.h"
56
57 #ifndef UNDER_CE
58 #include <vlc_windows_interfaces.h>
59 #endif
60
61 #ifdef UNDER_CE
62 #include <aygshell.h>
63     //WINSHELLAPI BOOL WINAPI SHFullScreen(HWND hwndRequester, DWORD dwState);
64 #endif
65
66 static void CommonChangeThumbnailClip(vout_display_t *, bool show);
67 static int CommonControlSetFullscreen(vout_display_t *, bool is_fullscreen);
68
69 static void DisableScreensaver(vout_display_t *);
70 static void RestoreScreensaver(vout_display_t *);
71
72 /* */
73 int CommonInit(vout_display_t *vd)
74 {
75     vout_display_sys_t *sys = vd->sys;
76
77     sys->hwnd      = NULL;
78     sys->hvideownd = NULL;
79     sys->hparent   = NULL;
80     sys->hfswnd    = NULL;
81     sys->changes   = 0;
82     SetRectEmpty(&sys->rect_display);
83     SetRectEmpty(&sys->rect_parent);
84     sys->is_first_display = true;
85     sys->is_on_top = false;
86
87     var_Create(vd, "video-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
88     var_Create(vd, "video-deco", VLC_VAR_BOOL | 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         /* Check if the parent window has resized or moved */
165         GetClientRect(sys->hparent, &rect_parent);
166         point.x = point.y = 0;
167         ClientToScreen(sys->hparent, &point);
168         OffsetRect(&rect_parent, point.x, point.y);
169
170         if (!EqualRect(&rect_parent, &sys->rect_parent)) {
171             sys->rect_parent = rect_parent;
172
173             /* This code deals with both resize and move
174              *
175              * For most drivers(direct3d, gdi, opengl), move is never
176              * an issue. The surface automatically gets moved together
177              * with the associated window (hvideownd)
178              *
179              * For directx, it is still important to call UpdateRects
180              * on a move of the parent window, even if no resize occured
181              */
182             SetWindowPos(sys->hwnd, 0, 0, 0,
183                          rect_parent.right - rect_parent.left,
184                          rect_parent.bottom - rect_parent.top,
185                          SWP_NOZORDER);
186
187             UpdateRects(vd, NULL, NULL, true);
188         }
189     }
190
191     /* HasMoved means here resize or move */
192     if (EventThreadGetAndResetHasMoved(sys->event))
193         UpdateRects(vd, NULL, NULL, false);
194 }
195
196 /**
197  * It ensures that the video window is shown after the first picture
198  * is displayed.
199  */
200 void CommonDisplay(vout_display_t *vd)
201 {
202     vout_display_sys_t *sys = vd->sys;
203
204     if (!sys->is_first_display)
205         return;
206
207     /* Video window is initially hidden, show it now since we got a
208      * picture to show.
209      */
210     SetWindowPos(sys->hvideownd, 0, 0, 0, 0, 0,
211                  SWP_ASYNCWINDOWPOS|
212                  SWP_FRAMECHANGED|
213                  SWP_SHOWWINDOW|
214                  SWP_NOMOVE|
215                  SWP_NOSIZE|
216                  SWP_NOZORDER);
217     sys->is_first_display = false;
218 }
219
220 /**
221  * It updates a picture data/pitches.
222  */
223 int CommonUpdatePicture(picture_t *picture, picture_t **fallback,
224                         uint8_t *data, unsigned pitch)
225 {
226     if (fallback) {
227         if (*fallback == NULL) {
228             *fallback = picture_NewFromFormat(&picture->format);
229             if (*fallback == NULL)
230                 return VLC_EGENERIC;
231         }
232         for (int n = 0; n < picture->i_planes; n++) {
233             const plane_t *src = &(*fallback)->p[n];
234             plane_t       *dst = &picture->p[n];
235             dst->p_pixels = src->p_pixels;
236             dst->i_pitch  = src->i_pitch;
237             dst->i_lines  = src->i_lines;
238         }
239         return VLC_SUCCESS;
240     }
241     /* fill in buffer info in first plane */
242     picture->p->p_pixels = data;
243     picture->p->i_pitch  = pitch;
244     picture->p->i_lines  = picture->format.i_height;
245
246     /*  Fill chroma planes for planar YUV */
247     if (picture->format.i_chroma == VLC_CODEC_I420 ||
248         picture->format.i_chroma == VLC_CODEC_J420 ||
249         picture->format.i_chroma == VLC_CODEC_YV12) {
250
251         for (int n = 1; n < picture->i_planes; n++) {
252             const plane_t *o = &picture->p[n-1];
253             plane_t *p = &picture->p[n];
254
255             p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
256             p->i_pitch  = pitch / 2;
257             p->i_lines  = picture->format.i_height / 2;
258         }
259         /* The dx/d3d buffer is always allocated as YV12 */
260         if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12)) {
261             uint8_t *p_tmp = picture->p[1].p_pixels;
262             picture->p[1].p_pixels = picture->p[2].p_pixels;
263             picture->p[2].p_pixels = p_tmp;
264         }
265     }
266     return VLC_SUCCESS;
267 }
268
269 void AlignRect(RECT *r, int align_boundary, int align_size)
270 {
271     if (align_boundary)
272         r->left = (r->left + align_boundary/2) & ~align_boundary;
273     if (align_size)
274         r->right = ((r->right - r->left + align_size/2) & ~align_size) + r->left;
275 }
276
277 /* */
278 static void CommonChangeThumbnailClip(vout_display_t *vd, bool show)
279 {
280 #ifndef UNDER_CE
281     vout_display_sys_t *sys = vd->sys;
282
283     /* Windows 7 taskbar thumbnail code */
284     OSVERSIONINFO winVer;
285     winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
286     if (!GetVersionEx(&winVer) || winVer.dwMajorVersion <= 5)
287         return;
288
289     CoInitialize(0);
290
291     LPTASKBARLIST3 taskbl;
292     if (S_OK == CoCreateInstance(&clsid_ITaskbarList,
293                                  NULL, CLSCTX_INPROC_SERVER,
294                                  &IID_ITaskbarList3,
295                                  &taskbl)) {
296         taskbl->vt->HrInit(taskbl);
297
298         HWND hroot = GetAncestor(sys->hwnd,GA_ROOT);
299         RECT relative;
300         if (show) {
301             RECT video, parent;
302             GetWindowRect(sys->hvideownd, &video);
303             GetWindowRect(hroot, &parent);
304             relative.left   = video.left   - parent.left - 8;
305             relative.top    = video.top    - parent.top - 10;
306
307             relative.right  = video.right  - video.left + relative.left;
308             relative.bottom = video.bottom - video.top  + relative.top - 25;
309         }
310         if (S_OK != taskbl->vt->SetThumbnailClip(taskbl, hroot,
311                                                  show ? &relative : NULL))
312             msg_Err(vd, "SetThumbNailClip failed");
313
314         taskbl->vt->Release(taskbl);
315     }
316     CoUninitialize();
317 #endif
318 }
319
320 /*****************************************************************************
321  * UpdateRects: update clipping rectangles
322  *****************************************************************************
323  * This function is called when the window position or size are changed, and
324  * its job is to update the source and destination RECTs used to display the
325  * picture.
326  *****************************************************************************/
327 void UpdateRects(vout_display_t *vd,
328                   const vout_display_cfg_t *cfg,
329                   const video_format_t *source,
330                   bool is_forced)
331 {
332     vout_display_sys_t *sys = vd->sys;
333 #define rect_src sys->rect_src
334 #define rect_src_clipped sys->rect_src_clipped
335 #define rect_dest sys->rect_dest
336 #define rect_dest_clipped sys->rect_dest_clipped
337
338     RECT  rect;
339     POINT point;
340
341     /* */
342     if (!cfg)
343         cfg = vd->cfg;
344     if (!source)
345         source = &vd->source;
346
347     /* Retrieve the window size */
348     GetClientRect(sys->hwnd, &rect);
349
350     /* Retrieve the window position */
351     point.x = point.y = 0;
352     ClientToScreen(sys->hwnd, &point);
353
354     /* If nothing changed, we can return */
355     bool has_moved;
356     bool is_resized;
357     EventThreadUpdateWindowPosition(sys->event, &has_moved, &is_resized,
358                                     point.x, point.y,
359                                     rect.right, rect.bottom);
360     if (is_resized)
361         vout_display_SendEventDisplaySize(vd, rect.right, rect.bottom, cfg->is_fullscreen);
362     if (!is_forced && !has_moved && !is_resized )
363         return;
364
365     /* Update the window position and size */
366     vout_display_cfg_t place_cfg = *cfg;
367     place_cfg.display.width  = rect.right;
368     place_cfg.display.height = rect.bottom;
369
370     vout_display_place_t place;
371     vout_display_PlacePicture(&place, source, &place_cfg, false);
372
373     EventThreadUpdateSourceAndPlace(sys->event, source, &place);
374 #if defined(MODULE_NAME_IS_wingapi)
375     if (place.width != vd->fmt.i_width || place.height != vd->fmt.i_height)
376         vout_display_SendEventPicturesInvalid(vd);
377 #endif
378
379     if (sys->hvideownd)
380         SetWindowPos(sys->hvideownd, 0,
381                      place.x, place.y, place.width, place.height,
382                      SWP_NOCOPYBITS|SWP_NOZORDER|SWP_ASYNCWINDOWPOS);
383
384     /* Destination image position and dimensions */
385 #if defined(MODULE_NAME_IS_direct3d) || defined(MODULE_NAME_IS_direct2d)
386     rect_dest.left   = 0;
387     rect_dest.right  = place.width;
388     rect_dest.top    = 0;
389     rect_dest.bottom = place.height;
390 #else
391     rect_dest.left = point.x + place.x;
392     rect_dest.right = rect_dest.left + place.width;
393     rect_dest.top = point.y + place.y;
394     rect_dest.bottom = rect_dest.top + place.height;
395
396 #ifdef MODULE_NAME_IS_directx
397     /* Apply overlay hardware constraints */
398     if (sys->use_overlay)
399         AlignRect(&rect_dest, sys->i_align_dest_boundary, sys->i_align_dest_size);
400 #endif
401
402 #endif
403
404 #if defined(MODULE_NAME_IS_directx) || defined(MODULE_NAME_IS_direct3d) || defined(MODULE_NAME_IS_direct2d)
405     /* UpdateOverlay directdraw function doesn't automatically clip to the
406      * display size so we need to do it otherwise it will fail
407      * It is also needed for d3d to avoid exceding our surface size */
408
409     /* Clip the destination window */
410     if (!IntersectRect(&rect_dest_clipped, &rect_dest,
411                        &sys->rect_display)) {
412         SetRectEmpty(&rect_src_clipped);
413         goto exit;
414     }
415
416 #ifndef NDEBUG
417     msg_Dbg(vd, "DirectXUpdateRects image_dst_clipped coords:"
418                 " %li,%li,%li,%li",
419                 rect_dest_clipped.left, rect_dest_clipped.top,
420                 rect_dest_clipped.right, rect_dest_clipped.bottom);
421 #endif
422
423 #else
424
425     /* AFAIK, there are no clipping constraints in Direct3D, OpenGL and GDI */
426     rect_dest_clipped = rect_dest;
427
428 #endif
429
430     /* the 2 following lines are to fix a bug when clicking on the desktop */
431     if ((rect_dest_clipped.right - rect_dest_clipped.left) == 0 ||
432         (rect_dest_clipped.bottom - rect_dest_clipped.top) == 0) {
433         SetRectEmpty(&rect_src_clipped);
434         goto exit;
435     }
436
437     /* src image dimensions */
438     rect_src.left   = 0;
439     rect_src.top    = 0;
440     rect_src.right  = source->i_width;
441     rect_src.bottom = source->i_height;
442
443     /* Clip the source image */
444     rect_src_clipped.left = source->i_x_offset +
445       (rect_dest_clipped.left - rect_dest.left) *
446       source->i_visible_width / (rect_dest.right - rect_dest.left);
447     rect_src_clipped.right = source->i_x_offset +
448       source->i_visible_width -
449       (rect_dest.right - rect_dest_clipped.right) *
450       source->i_visible_width / (rect_dest.right - rect_dest.left);
451     rect_src_clipped.top = source->i_y_offset +
452       (rect_dest_clipped.top - rect_dest.top) *
453       source->i_visible_height / (rect_dest.bottom - rect_dest.top);
454     rect_src_clipped.bottom = source->i_y_offset +
455       source->i_visible_height -
456       (rect_dest.bottom - rect_dest_clipped.bottom) *
457       source->i_visible_height / (rect_dest.bottom - rect_dest.top);
458
459 #ifdef MODULE_NAME_IS_directx
460     /* Apply overlay hardware constraints */
461     if (sys->use_overlay)
462         AlignRect(&rect_src_clipped, sys->i_align_src_boundary, sys->i_align_src_size);
463 #elif defined(MODULE_NAME_IS_direct3d) || defined(MODULE_NAME_IS_direct2d)
464     /* Needed at least with YUV content */
465     rect_src_clipped.left &= ~1;
466     rect_src_clipped.right &= ~1;
467     rect_src_clipped.top &= ~1;
468     rect_src_clipped.bottom &= ~1;
469 #endif
470
471 #ifndef NDEBUG
472     msg_Dbg(vd, "DirectXUpdateRects image_src_clipped"
473                 " coords: %li,%li,%li,%li",
474                 rect_src_clipped.left, rect_src_clipped.top,
475                 rect_src_clipped.right, rect_src_clipped.bottom);
476 #endif
477
478 #ifdef MODULE_NAME_IS_directx
479     /* The destination coordinates need to be relative to the current
480      * directdraw primary surface (display) */
481     rect_dest_clipped.left -= sys->rect_display.left;
482     rect_dest_clipped.right -= sys->rect_display.left;
483     rect_dest_clipped.top -= sys->rect_display.top;
484     rect_dest_clipped.bottom -= sys->rect_display.top;
485 #endif
486
487     CommonChangeThumbnailClip(vd, true);
488
489 exit:
490     /* Signal the change in size/position */
491     sys->changes |= DX_POSITION_CHANGE;
492
493 #undef rect_src
494 #undef rect_src_clipped
495 #undef rect_dest
496 #undef rect_dest_clipped
497 }
498
499 static int CommonControlSetFullscreen(vout_display_t *vd, bool is_fullscreen)
500 {
501     vout_display_sys_t *sys = vd->sys;
502
503 #ifdef MODULE_NAME_IS_direct3d
504     if (sys->use_desktop && is_fullscreen)
505         return VLC_EGENERIC;
506 #endif
507
508     /* */
509     if (sys->parent_window)
510         return vout_window_SetFullScreen(sys->parent_window, is_fullscreen);
511
512     /* */
513     HWND hwnd = sys->hparent && sys->hfswnd ? sys->hfswnd : sys->hwnd;
514
515     /* Save the current windows placement/placement to restore
516        when fullscreen is over */
517     WINDOWPLACEMENT window_placement;
518     window_placement.length = sizeof(WINDOWPLACEMENT);
519     GetWindowPlacement(hwnd, &window_placement);
520
521     if (is_fullscreen) {
522         msg_Dbg(vd, "entering fullscreen mode");
523
524         /* Change window style, no borders and no title bar */
525         SetWindowLong(hwnd, GWL_STYLE, WS_CLIPCHILDREN | WS_VISIBLE);
526
527         if (sys->hparent) {
528 #ifdef UNDER_CE
529             POINT point = {0,0};
530             RECT rect;
531             ClientToScreen(sys->hwnd, &point);
532             GetClientRect(sys->hwnd, &rect);
533             SetWindowPos(hwnd, 0, point.x, point.y,
534                          rect.right, rect.bottom,
535                          SWP_NOZORDER|SWP_FRAMECHANGED);
536 #else
537             /* Retrieve current window position so fullscreen will happen
538             *on the right screen */
539             HMONITOR hmon = MonitorFromWindow(sys->hparent,
540                                               MONITOR_DEFAULTTONEAREST);
541             MONITORINFO mi;
542             mi.cbSize = sizeof(MONITORINFO);
543             if (GetMonitorInfo(hmon, &mi))
544                 SetWindowPos(hwnd, 0,
545                              mi.rcMonitor.left,
546                              mi.rcMonitor.top,
547                              mi.rcMonitor.right - mi.rcMonitor.left,
548                              mi.rcMonitor.bottom - mi.rcMonitor.top,
549                              SWP_NOZORDER|SWP_FRAMECHANGED);
550 #endif
551         } else {
552             /* Maximize non embedded window */
553             ShowWindow(hwnd, SW_SHOWMAXIMIZED);
554         }
555
556         if (sys->hparent) {
557             /* Hide the previous window */
558             RECT rect;
559             GetClientRect(hwnd, &rect);
560             SetParent(sys->hwnd, hwnd);
561             SetWindowPos(sys->hwnd, 0, 0, 0,
562                          rect.right, rect.bottom,
563                          SWP_NOZORDER|SWP_FRAMECHANGED);
564
565 #ifdef UNDER_CE
566             HWND topLevelParent = GetParent(sys->hparent);
567 #else
568             HWND topLevelParent = GetAncestor(sys->hparent, GA_ROOT);
569 #endif
570             ShowWindow(topLevelParent, SW_HIDE);
571         }
572         SetForegroundWindow(hwnd);
573     } else {
574         msg_Dbg(vd, "leaving fullscreen mode");
575
576         /* Change window style, no borders and no title bar */
577         SetWindowLong(hwnd, GWL_STYLE, EventThreadGetWindowStyle(sys->event));
578
579         if (sys->hparent) {
580             RECT rect;
581             GetClientRect(sys->hparent, &rect);
582             SetParent(sys->hwnd, sys->hparent);
583             SetWindowPos(sys->hwnd, 0, 0, 0,
584                          rect.right, rect.bottom,
585                          SWP_NOZORDER|SWP_FRAMECHANGED);
586
587 #ifdef UNDER_CE
588             HWND topLevelParent = GetParent(sys->hparent);
589 #else
590             HWND topLevelParent = GetAncestor(sys->hparent, GA_ROOT);
591 #endif
592             ShowWindow(topLevelParent, SW_SHOW);
593             SetForegroundWindow(sys->hparent);
594             ShowWindow(hwnd, SW_HIDE);
595         } else {
596             /* return to normal window for non embedded vout */
597             SetWindowPlacement(hwnd, &window_placement);
598             ShowWindow(hwnd, SW_SHOWNORMAL);
599         }
600     }
601     return VLC_SUCCESS;
602 }
603
604 int CommonControl(vout_display_t *vd, int query, va_list args)
605 {
606     vout_display_sys_t *sys = vd->sys;
607
608     switch (query) {
609     case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:   /* const vout_display_cfg_t *p_cfg, int is_forced */
610     case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED: /* const vout_display_cfg_t *p_cfg */
611     case VOUT_DISPLAY_CHANGE_ZOOM:           /* const vout_display_cfg_t *p_cfg */
612     case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:  /* const video_format_t *p_source */
613     case VOUT_DISPLAY_CHANGE_SOURCE_CROP: {  /* const video_format_t *p_source */
614         const vout_display_cfg_t *cfg;
615         const video_format_t *source;
616         bool  is_forced = true;
617         if (query == VOUT_DISPLAY_CHANGE_SOURCE_CROP ||
618             query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT) {
619             cfg    = vd->cfg;
620             source = va_arg(args, const video_format_t *);
621         } else {
622             cfg    = va_arg(args, const vout_display_cfg_t *);
623             source = &vd->source;
624             if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
625                 is_forced = va_arg(args, int);
626         }
627         if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE && is_forced) {
628             /* Update dimensions */
629             if (sys->parent_window) {
630                 vout_window_SetSize(sys->parent_window, cfg->display.width, cfg->display.height);
631             } else {
632                 RECT rect_window;
633                 rect_window.top    = 0;
634                 rect_window.left   = 0;
635                 rect_window.right  = cfg->display.width;
636                 rect_window.bottom = cfg->display.height;
637                 AdjustWindowRect(&rect_window, EventThreadGetWindowStyle(sys->event), 0);
638
639                 SetWindowPos(sys->hwnd, 0, 0, 0,
640                              rect_window.right - rect_window.left,
641                              rect_window.bottom - rect_window.top, SWP_NOMOVE);
642             }
643         }
644         UpdateRects(vd, cfg, source, is_forced);
645         return VLC_SUCCESS;
646     }
647     case VOUT_DISPLAY_CHANGE_WINDOW_STATE: {       /* unsigned state */
648         const unsigned state = va_arg(args, unsigned);
649         const bool is_on_top = (state & VOUT_WINDOW_STATE_ABOVE) != 0;
650 #ifdef MODULE_NAME_IS_direct3d
651         if (sys->use_desktop && is_on_top)
652             return VLC_EGENERIC;
653 #endif
654         if (sys->parent_window) {
655             if (vout_window_SetState(sys->parent_window, state))
656                 return VLC_EGENERIC;
657         } else {
658             HMENU hMenu = GetSystemMenu(sys->hwnd, FALSE);
659
660             if (is_on_top && !(GetWindowLong(sys->hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
661                 CheckMenuItem(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_CHECKED);
662                 SetWindowPos(sys->hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
663             } else if (!is_on_top && (GetWindowLong(sys->hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
664                 CheckMenuItem(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_UNCHECKED);
665                 SetWindowPos(sys->hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
666             }
667         }
668         sys->is_on_top = is_on_top;
669         return VLC_SUCCESS;
670     }
671     case VOUT_DISPLAY_CHANGE_FULLSCREEN: {   /* const vout_display_cfg_t *p_cfg */
672         const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
673         if (CommonControlSetFullscreen(vd, cfg->is_fullscreen))
674             return VLC_EGENERIC;
675         UpdateRects(vd, NULL, NULL, false);
676         return VLC_SUCCESS;
677     }
678
679     case VOUT_DISPLAY_HIDE_MOUSE:
680         EventThreadMouseHide(sys->event);
681         return VLC_SUCCESS;
682     case VOUT_DISPLAY_RESET_PICTURES:
683         assert(0);
684     default:
685         return VLC_EGENERIC;
686     }
687 }
688
689 #ifndef UNDER_CE
690 static void DisableScreensaver(vout_display_t *vd)
691 {
692     vout_display_sys_t *sys = vd->sys;
693
694     /* disable screensaver by temporarily changing system settings */
695     sys->i_spi_lowpowertimeout = 0;
696     sys->i_spi_powerofftimeout = 0;
697     sys->i_spi_screensavetimeout = 0;
698     if (var_GetBool(vd, "disable-screensaver")) {
699         msg_Dbg(vd, "disabling screen saver");
700         SystemParametersInfo(SPI_GETLOWPOWERTIMEOUT, 0,
701                              &sys->i_spi_lowpowertimeout, 0);
702         if (0 != sys->i_spi_lowpowertimeout) {
703             SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, 0, NULL, 0);
704         }
705         SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT, 0,
706                              &sys->i_spi_powerofftimeout, 0);
707         if (0 != sys->i_spi_powerofftimeout) {
708             SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);
709         }
710         SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0,
711                              &sys->i_spi_screensavetimeout, 0);
712         if (0 != sys->i_spi_screensavetimeout) {
713             SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0);
714         }
715     }
716 }
717
718 static void RestoreScreensaver(vout_display_t *vd)
719 {
720     vout_display_sys_t *sys = vd->sys;
721
722     /* restore screensaver system settings */
723     if (0 != sys->i_spi_lowpowertimeout) {
724         SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT,
725                              sys->i_spi_lowpowertimeout, NULL, 0);
726     }
727     if (0 != sys->i_spi_powerofftimeout) {
728         SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT,
729                              sys->i_spi_powerofftimeout, NULL, 0);
730     }
731     if (0 != sys->i_spi_screensavetimeout) {
732         SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT,
733                              sys->i_spi_screensavetimeout, NULL, 0);
734     }
735 }
736 #endif
737