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