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