<div dir="ltr">I would normally agree, but monitors can be unplugged and plugged in at any time (especially wireless displays). Consider this scenario:<br><div><br></div><div>1. A chosen monitor is selected and VLC closed.</div><div>2. The chosen monitor is disconnected.</div><div>3. The next time VLC is run, and video played, the enumeration (without the chosen monitor) is saved, and video plays on the primary monitor.</div><div>4. You realize your forgot to plug in your chosen monitor, and do so.</div><div><br></div><div>In that case, VLC will not play video on the chosen monitor until the enumeration is forced to happen again (restarting VLC or opening preferences, for example).</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 25, 2019 at 12:18 PM Rémi Denis-Courmont <<a href="mailto:remi@remlab.net">remi@remlab.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Le sunnuntaina 13. lokakuuta 2019, 6.58.31 EEST Gabriel Luci a écrit :<br>
> This reads the id parameter as the name of the monitor that should be<br>
> used. If anything goes wrong, it will fall back to the monitor the<br>
> window is already on (which is what it always did before).<br>
> <br>
> ---<br>
> modules/video_output/win32/window.c | 72<br>
> +++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 7<br>
> deletions(-)<br>
> <br>
> diff --git a/modules/video_output/win32/window.c<br>
> b/modules/video_output/win32/window.c index 50e172b9b4..eefaed256e 100644<br>
> --- a/modules/video_output/win32/window.c<br>
> +++ b/modules/video_output/win32/window.c<br>
> @@ -37,6 +37,7 @@<br>
> #include <vlc_actions.h><br>
> <br>
> #include <shellapi.h> /*<br>
> ExtractIcon */ +#include <vlc_charset.h> <br>
> /* FromWide */<br>
> <br>
> #define RECTWidth(r) (LONG)((r).right - (r).left)<br>
> #define RECTHeight(r) (LONG)((r).bottom - (r).top)<br>
> @@ -153,9 +154,37 @@ static void SetTitle(vout_window_t *wnd, const char<br>
> *title) PostMessage( sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );<br>
> }<br>
> <br>
> +typedef struct enum_monitors_callback_params_t {<br>
> + bool is_monitor_found;<br>
> + const char *psz_name_to_find;<br>
> + MONITORINFOEX *found_monitor_info;<br>
> +} enum_monitors_callback_params_t;<br>
> +<br>
> +static BOOL CALLBACK EnumDisplayMonitorsCallback(HMONITOR hMonitor, HDC<br>
> hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) +{<br>
> + /* this is called for each active monitor */<br>
> +<br>
> + VLC_UNUSED(hdcMonitor);<br>
> + VLC_UNUSED(lprcMonitor);<br>
> +<br>
> + MONITORINFOEX mi;<br>
> + mi.cbSize = sizeof(MONITORINFOEX);<br>
> + if (!GetMonitorInfo(hMonitor, (LPMONITORINFO) &mi)) return true;<br>
> +<br>
> + enum_monitors_callback_params_t *params =<br>
> (enum_monitors_callback_params_t*) dwData;<br>
> + char *psz_monitor_name =<br>
> FromWide(mi.szDevice);<br>
<br>
Enumeration is supposed to be done when either the window provider is <br>
initialized with the respective callback, or when the setting choices are <br>
requested by the CLI or GUI.<br>
<br>
So then it would seem saner to keep the list of monitors internally, than to <br>
enumerate them again.<br>
<br>
> + if (!strcmp(psz_monitor_name, params->psz_name_to_find))<br>
> + {<br>
> + /* the monitor name matches what we're looking for */<br>
> + params->is_monitor_found = true;<br>
> + params->found_monitor_info = &mi;<br>
> + }<br>
> + free(psz_monitor_name);<br>
> + return !params->is_monitor_found;<br>
> +}<br>
> +<br>
> static void SetFullscreen(vout_window_t *wnd, const char *id)<br>
> {<br>
> - VLC_UNUSED(id);<br>
> msg_Dbg(wnd, "entering fullscreen mode");<br>
> vout_window_sys_t *sys = wnd->sys;<br>
> <br>
> @@ -167,12 +196,41 @@ static void SetFullscreen(vout_window_t *wnd, const<br>
> char *id) /* Change window style, no borders and no title bar */<br>
> SetWindowLong(sys->hwnd, GWL_STYLE, WS_CLIPCHILDREN | WS_VISIBLE);<br>
> <br>
> - /* Retrieve current window position so fullscreen will happen<br>
> - * on the right screen */<br>
> - HMONITOR hmon = MonitorFromWindow(sys->hwnd, MONITOR_DEFAULTTONEAREST);<br>
> - MONITORINFO mi;<br>
> - mi.cbSize = sizeof(MONITORINFO);<br>
> - if (GetMonitorInfo(hmon, &mi))<br>
> + /* Figure out which monitor we should be using */<br>
> + MONITORINFOEX mi;<br>
> + bool is_monitor_found = false;<br>
> +<br>
> + if (id)<br>
> + {<br>
> + /* We're being told to use a specific monitor, so see if we can<br>
> find an + * active monitor with the same name */<br>
> + enum_monitors_callback_params_t params = {<br>
> + .is_monitor_found = false,<br>
> + .psz_name_to_find = id<br>
> + };<br>
> + EnumDisplayMonitors(NULL, NULL, &EnumDisplayMonitorsCallback,<br>
> (LPARAM) ¶ms); +<br>
> + if (params.is_monitor_found)<br>
> + {<br>
> + is_monitor_found = true;<br>
> + mi = *(params.found_monitor_info);<br>
> + }<br>
> + else<br>
> + {<br>
> + msg_Dbg(wnd, "display device with name \"%s\" was requested,<br>
> but no such device exists. Falling back to primary", id); + }<br>
> + }<br>
> +<br>
> + if (!is_monitor_found)<br>
> + {<br>
> + /* fall back to using the screen the window is currently mostly on<br>
> */ + HMONITOR hmon;<br>
> + hmon = MonitorFromWindow(sys->hwnd, MONITOR_DEFAULTTONEAREST);<br>
> + mi.cbSize = sizeof(MONITORINFOEX);<br>
> + is_monitor_found = GetMonitorInfo(hmon, (LPMONITORINFO) &mi);<br>
> + }<br>
> +<br>
> + if (is_monitor_found)<br>
> SetWindowPos(sys->hwnd, 0,<br>
> mi.rcMonitor.left,<br>
> mi.rcMonitor.top,<br>
<br>
<br>
-- <br>
レミ・デニ-クールモン<br>
<a href="http://www.remlab.net/" rel="noreferrer" target="_blank">http://www.remlab.net/</a><br>
<br>
<br>
<br>
_______________________________________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a></blockquote></div>