summaryrefslogtreecommitdiffstats
path: root/video/out/w32_common.c
Commit message (Collapse)AuthorAgeFilesLines
* win32: apply geometry position to content instead of windowAvi Halachmi (:avih)2022-02-021-1/+6
| | | | | | | | | | | | | | The docs specify that the +-X+-Y geometry values position the content. This used to work correctly but got broken at 8fb4fd9a . Geometry size is unaffected - this only concerns position. Commit 8fb4fd9a made it center the window rather than the content by taking the borders into account during positioning, but forgot to make an exception when a position is specified explicitly. This commit adds this exception, and now if a specific position is requested then the borders are ignored, and the content is positioned correctly.
* win32: initial position: center with bordersAvi Halachmi (:avih)2021-09-061-0/+2
| | | | | | | | | | | | | | | | | | | | | | | Previously, the initial positioning and fit ignored the borders, and centered the content (the video itself) at the working area. Now, the initial positioning centers the window, by subtracting the borders (if needed) from the target area for the initial fit/position. While this does mean that the initial maximum content area is now smaller than before, ultimately this has no impact on the window size, because fit_on_screen is called later and, if needed, further shrinks the window to fit the borders too - but without centering the window. So the net impact of this commit is only the initial positioning (same size as before), which now centers the window instead of the content. Note that on Windows 10 the borders include invisible areas at the sides and bottom of the window (for mouse edge-drag), so visibly the window is nearer to the top than to the bottom, but these are the metrics we have (fit_on_screen uses the same border size values). On Windows 7 it looks perfectly centered.
* win32: fix incorrect application of --monitoraspectAvi Halachmi (:avih)2021-09-061-1/+4
| | | | | | | | | | | | | The --monitoraspect value is calculated at vo_calc_window_geometry2 (VCWG2) or VCWG3, and applied via vo_apply_window_geometry. Before this commit, the screen size which the win32 VO used with VCWG2 was the working area (screen minus taskbar). This allows better fitting, but breaks the pixelaspect calculation which is derived from the --monitoraspect value and this rectangle. VCWG3 allows an independent size for the aspect calculations, and now we use it independently of the fit size.
* win32: support the property display-hidpi-scaleAvi Halachmi (:avih)2021-08-181-0/+4
| | | | | | | | This read-only property reflects the VO's dpi-scale value, and wasn't supported on win32 until now (it is supported on wayland/x11/osx). Currently in mpv it's only used by the builtin script console.lua, and assumed 1 if unavailable.
* win32: apply dpi-scale with [current]-window-scaleAvi Halachmi (:avih)2021-08-181-2/+5
| | | | | | | | | | | | | | When --window-scale=NUM is set from CLI, the dpi_scale value was/is taken into account when the win32 VO calls vo_calc_window_geometry2. However, when [current]-window-scale is read or set at runtime, it uses the VOCTRL_{GET,SET}_UNFS_WINDOW_SIZE interface, where other VOs apply the dpi_scale value internally (wayland, x11, osx), but the win32 VO didn't before this commit. Fixes two issues when --hidpi-window-scale=yes and dpi_scale != 1 : - Incorrect window-size when setting [current-]window-scale at runtime. - Incorrect current-window-scale value when reading it.
* win32: ensure initial dpi-scale valueAvi Halachmi (:avih)2021-08-181-14/+19
| | | | | | | | | | | | | | | | | | | | vo_calc_window_geometry2(...) is called to initialize the window size with the dpi_scale value as one of the arguments. dpi_scale is 0 initially, and set to a valid value at update_dpi(), which is called from [force_]update_display_info(). However, no measures were taken to ensure that dpi_scale is set correctly before vo_calc_window_geometry2() is called, which could result in incorrect window size if it's not initialized. It did happen to get initialized on time, by luck, because VOCTRL_GET_DISPLAY_FPS is used early, which happens to call update_display_info to read the fps value (other update_display_info() calls are after the first vo_calc_window_geometry2() call). This commit ensures that dpi_scale is initialized on time if needed. Also, update_dpi() now ensures that dpi_scale is never 0.
* win32: support the property 'focused'Avi Halachmi (:avih)2021-05-271-1/+12
| | | | | | | | | | | | | And also change the existing WM_KILLFOCUS handler to return 0 instead of 'break' (which later calls DefWindowProcW), as MSDN says we should do for WM_{KILL,SET}FOCUS. It seems that the 'focused' property is now supported by all main VOs: x11, macOS, wayland, Windows. TCT/sixel/caca probably don't support it, and unknown with SDL. Fixes #8868
* command: add display-width/display-height propertyDudemanguy2021-05-061-0/+5
| | | | | | | | | For some reason, this never existed before. Add VOCTRL_GET_DISPLAY_RES and use it to obtain the current display's resolution from each vo/windowing backend if applicable. Users can then access the current display resolution as display-width and display-height as per the client api. Note that macOS/cocoa was not attempted in this commit since the author has no clue how to write swift.
* win32: fit_window_on_screen: simplify, add commentsAvi Halachmi (:avih)2021-04-231-16/+17
| | | | | | | | | | The fit_on_screen logic was a bit twisted. Simplify it a bit and update few comments to explain better what it's used for. Note that the new logic is not identical to before, but its intent should now be clearer. This means there might be regressions or improvements at edge cases. If followup fixes are needed, then we should keep the intent clear. Most likely though that it's fine.
* win32: fit_window_on_screen: centralize logic (no-op)Avi Halachmi (:avih)2021-04-231-4/+3
| | | | | | | | fit_on_screen is called only from reinit_window_state. Move the yes/no logic unmodified from fit_on_screen to reinit_window_state, and remove the w32->parent condition because it's already checked earlier at reinit_window_state.
* win32: fit_window_on_screen: ensure top edge is insideAvi Halachmi (:avih)2021-04-231-6/+18
| | | | | | | | | | | | | | | | | | | | | Previously, because the video (client area) was centered but the top and bottom borders are uneven (title is taller), then if the window is shrunk vertically to just-fit the desktop - the top edge of the title bar ended above the top edge of the display. This is a state which Windows prevents during manual move, but apparently it's not rejected at the Windows API. Now we ensure it doesn't happen, and nudge the window down to align the top edges if necessary. This is a commulative regression of commits 981048e0 and 364af7c6. To clarify functionality, this includes a no-op change: fit_rect was renamed to fit_rect_size and it now takes explicit width and height, because it only used the width/height of rc2 anyway. Fixes #6695
* options: win32: ignore and deprecate --fit-borderAvi Halachmi (:avih)2021-04-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The accurate description of this option was: - fit-border is enabled by default. When disabled, it adds a bug where if the window has borders and mpv shrinks it to fit the desktop, then the calculation ignores the borders and adds incorrect video crop. The option was added at commits 70f64f3c and 949247d6, in order to solve an issue (#2935) where if mpv wanted to display a video with size WxH, then w32_common.c incorrectly set the window to WxH, while down-scaling the video slightly to fit (even with small sizes). It was addressed with a new option which is enabled by default, but does the right thing (sets the client area to WxH) only when disabled, so that everyone who prefers their video slightly downscaled could keep their default behavior. (#2935 also addressed an off-by-one issue, fixed before fit-border) While disabling the option did avoid unnecessary downscaling, it also added a bug when disabled: the borders are no longer taken into account when the size is too big for the desktop. Most users don't notice and are unaffected as it's enabled by default. Shortly later (981048e0) the core issue is fixed, and now the client area is correctly set to WxH instead of the window (and together with the three following commits which center the video, adds a new bug where the window title can be outside the display - addressed next). However, fit-border remained, now without any effect, except that it still has the same bug when disabled and the window is too big. Later code changes and refactoring preserved this issue with great attention to details, and it remained in identical form until now. Simply rip out fit-border.
* w32_common: Scale window when moving to display with different DPIPiotr Gasior2020-05-081-0/+5
| | | | | For applications that are DPI aware WM_DPICHANGED message contains suggested size and position of window
* w32_common: Support HiDPI on WindowsRealDolos2020-05-081-8/+24
|
* w32_common: support minimized and maximized propertiesJames Ross-Gowan2020-01-261-5/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for setting window-minimized and window-maximized in Windows. The minimized and maximized state can be set independently. When the window is minimized, the value of window-maximized will determine whether the window is restored to the maximized state or not. Changing state is done with ShowWindow(), which has commands that change the window state and activate it (eg. SW_RESTORE) and commands that change the window state without activating it (eg. SW_SHOWNOACTIVATE.) It would be nice if we could use commands that don't activate the window, so scripts could change the window state in the backrgound without bringing it to the foreground, but there are some problems with that. There is no command to maximize a window without activating it, so SW_MAXIMIZE is used instead. Also, restoring a window from minimize without activating it seems buggy. On my Windows 10 1909 PC, it always moves the window to the back of the z-order. SW_RESTORE is used instead of SW_SHOWNOACTIVATE because of this. This also changes the way the window is initially shown. Previously, the window was made visible as a consequence of the SWP_SHOWWINDOW flag in the first call to SetWindowPos. In order to set the initial minimized or maximized state of the window, the window is shown with the ShowWindow function instead, where the ShowWindow command is determined by whether the window should be initially maximized or minimized. Even when showing the window normally, we should still call ShowWindow with the SW_SHOW command instead of using SetWindowPos, since the first call a process makes to ShowWindow(SW_SHOW) has special behaviour where it uses the show command in the process' STARTUPINFO instead of the command passed to the function, which should fix #5724. Note: While changes to window-minimized while in fullscreen mode should work as expected, changing window-maximized while in fullscreen does not work and won't result in the window changing state, even after leaving fullscreen. For this to work correctly, the fullscreen logic needs to be changed to apply the new maximized state on leaving fullscreen. Fixes: #5724 Fixes: #7351
* w32_common: remove implicit fallthroughJames Ross-Gowan2019-12-291-2/+3
| | | | | | GCC 9.2 warns about this. It was always a bit sketchy, so get rid of it. VK_F10 generates WM_SYSKEYDOWN, so it only needs to be handled in the WM_SYSKEYDOWN case.
* video/w32_common: follow updates to the border option instead of VOCTRL_BORDERJan Ekström2019-12-181-4/+3
|
* video/w32_common: follow updates to the ontop option instead of VOCTRL_ONTOPJan Ekström2019-12-181-3/+2
|
* video/w32_common: move minimized state signaling to where it happensJan Ekström2019-12-181-3/+3
| | | | | WM_SIZE is the message we receive from which we can infer if we got minimized or not.
* video/w32_common: switch full screening to options cacheJan Ekström2019-12-181-9/+22
| | | | | | | | | | | | * Instead of following VOCTRL_FULLSCREEN, check for option changes. * Instead of signaling VO_EVENT_FULLSCREEN_STATE, update the cached option structure and have it propagated to the origin. Additionally, gets rid of all the straight usage of the VO options structure. Done in a similar style to the Wayland common file, where in case of reading the value, the "payload" from cache is utilized.
* w32_common: avoid unnecessary sprintfsJames Ross-Gowan2019-05-101-8/+5
| | | | | | | | | | These were unnecessary for a couple of reasons, but it seems like the old code went through a lot of effort to avoid duplicating the code to print a RECT, even though the windowrc gets printed anyway at the end of the function. Avoid printing the same windowrc twice by only printing it when it gets changed (in the w32->current_fs branch.)
* w32_common: use the screen working area when resizing the windowpavelxdd2018-11-181-74/+81
| | | | | | | | | | | | | | | | | | | | | | This makes the default fit on screen, autofit and window-scale changing behavior to use the screen working area, instead of the whole screen area. As a result mpv window doesn't cover the taskbar now when opening videos with size larger than the screen size. The actual behavior now is the same as expected behavior for usecases 1-4 from #4363. This commit also removes the screenrc from w32 struct. The screen rect can now be retrieved via `get_screen_area` function, which was renamed from `update_screen_rect`. On a multi-monitor system, if the user moved the window between monitors, this function will return the current screen area under the window, and not the screen area from monitor specified by `--screen` option. The `--screen` option sets the initial monitor the mpv window is displayed on.
* w32_common: avoid recursive dispatch queue callswm42018-04-181-1/+6
| | | | | | | | I suppose this doesn't matter in practice, i.e. even if calls relayed over the dispatch queue will cause WndProc to be invoked, WndProc will never run for a longer time. Preparation for removing recursion support from the dispatch queue code.
* w32_common: refactor and improve window state handlingpavelxdd2017-12-191-131/+151
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Refactored and split the `reinit_window_state` code into four separate functions: - `update_window_style` used to update window styles without modifying the window rect. - `fit_window_on_screen` used to adjust the window size when it is larger than the screen size. Added a helper function `fit_rect` to fit one rect on another without using any data from w32 struct. - `update_fullscreen_state` used to calculate the new fullscreen state and adjust the window rect accordingly. - `update_window_state` used to display the window on screen with new size, position and ontop state. This commit fixes three issues: - fixed #4753 by skipping `fit_window_on_screen` for a maximized window, since maximized window should already fit on the screen. It should be noted that this bug was only reproducible with `--fit-border` option which is enabled by default. The cause of the bug is that after calling the `add_window_borders` for a maximized window, the rect in result is slightly larger than the screen rect, which is okay, `SetWindowPos` will interpret it as a maximized state later, so no auto-fitting to screen size is needed here. - fixed #5215 by skipping `fit_window_on_screen` when leaving fullscreen. On a multi-monitor system if the mpv window was stretched to cover multiple monitors, its size was reset after switching back from fullscreen to fit the size of the active monitor. Also, when changing `--ontop` and `--border` options, now only the `update_window_style` and `update_window_state` functions are used, so `fit_window_on_screen` is not used for them too. - fixed #2451 by moving the `ITaskbarList2_MarkFullscreenWindow` below the `SetWindowPos`. If the taskbar is notified about fullscreen state before the window is shown on screen, the taskbar button could be missing until Alt-TAB is pressed, usually it was reproducible on Windows 8. Other changes: - In `update_fullscreen_state` the `reset window bounds` debug message now reports client area size and position, instead of window area size and position. This is done for consistency with debug messages in handling fullscreen state above in this function, since they also print window bounds of the client area. - Refactored `gui_thread_reconfig`. Added a new window flag `fit_on_screen` to fit the window on screen even when leaving fullscreen. This is needed for the case when the new video opened while the window is still in the fullscreen state. - Moved parent and fullscreen state checks out from the WM_MOVING to `snap_to_screen_edges` function for consistency with other functions. There's no point in keeping these checks out of the function body.
* w32_common: use RECT for storing screen and window size & positionpavelxdd2017-12-191-100/+71
| | | | | | When window and screen size and position are stored in RECT, it's much easier to modify them using WinAPI functions. Added two macros to get width and height of the rect.
* w32_common: update outdated comment about wakeup eventspavelxdd2017-12-111-2/+1
| | | | | mpv doesn't use WM_USER for wakeup events since 91079c0 Updated the comment.
* w32_common: improve the window message state machinepavelxdd2017-12-071-1/+13
| | | | | | | | * Distinguish between the window being moved or not. * Skip trying to snap if currently in full screen or an embedded window. * Exit snapped state if the size changed when the window was being moved.
* w32_common: skip window snapping if Windows handled itpavelxdd2017-12-071-2/+12
| | | | | | Check the expected width and height against up-to-date window placement. If they do not match, we will consider snapping to have happened on Windows' side.
* w32_common: move imm32.dll function to w32->api structpavelxdd2017-11-151-15/+12
| | | | | | | | | For consistency with already implemented shcore.dll function loading in w32->api: Moved loading of imm32.dll to w32_api_load, and declare pImmDisableIME function pointer in the w32->api struct. Removed unloading of imm32.dll.
* input: merge mouse wheel and axis keycodesJames Ross-Gowan2017-09-031-3/+3
| | | | | | | | | | | | | | | | | | | | | | Mouse wheel bindings have always been a cause of user confusion. Previously, on Wayland and macOS, precise touchpads would generate AXIS keycodes and notched mouse wheels would generate mouse button keycodes. On Windows, both types of device would generate AXIS keycodes and on X11, both types of device would generate mouse button keycodes. This made it pretty difficult for users to modify their mouse-wheel bindings, since it differed between platforms and in some cases, between devices. To make it more confusing, the keycodes used on Windows were changed in 18a45a42d524 without a deprecation period or adequate communication to users. This change aims to make mouse wheel binds less confusing. Both the mouse button and AXIS keycodes are now deprecated aliases of the new WHEEL keycodes. This will technically break input configs on Wayland and macOS that assign different commands to precise and non-precise scroll events, but this is probably uncommon (if anyone does it at all) and I think it's a fair tradeoff for finally fixing mouse wheel-related confusion on other platforms.
* input: use mnemonic names for mouse buttonsJames Ross-Gowan2017-09-031-13/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | mpv's mouse button numbering is based on X11 button numbering, which allows for an arbitrary number of buttons and includes mouse wheel input as buttons 3-6. This button numbering was used throughout the codebase and exposed in input.conf, and it was difficult to remember which physical button each number actually referred to and which referred to the scroll wheel. In practice, PC mice only have between two and five buttons and one or two scroll wheel axes, which are more or less in the same location and have more or less the same function. This allows us to use names to refer to the buttons instead of numbers, which makes input.conf syntax a lot easier to remember. It also makes the syntax robust to changes in mpv's underlying numbering. The old MOUSE_BTNx names are still understood as deprecated aliases of the named buttons. This changes both the input.conf syntax and the MP_MOUSE_BTNx symbols in the codebase, since I think both would benefit from using names over numbers, especially since some platforms don't use X11 button numbering and handle different mouse buttons in different windowing system events. This also makes the names shorter, since otherwise they would be pretty long, and it removes the high-numbered MOUSE_BTNx_DBL names, since they weren't used. Names are the same as used in Qt: https://doc.qt.io/qt-5/qt.html#MouseButton-enum
* w32_common: handle media keysJames Ross-Gowan2017-08-051-0/+15
| | | | | | | | | | | | | | | | | This was attempted before in fc9695e63b5b, but it was reverted in 1b7ce759b1f4 because it caused conflicts with other software watching the same keys (See #2041.) It seems like some PCs ship with OEM software that watches the volume keys without consuming key events and this causes them to be handled twice, once by mpv and once by the other software. In order to prevent conflicts like this, use the WM_APPCOMMAND message to handle media keys. Returning TRUE from the WM_APPCOMMAND handler should indicate to the operating system that we consumed the key event and it should not be propogated to the shell. Also, we now only listen for keys that are directly related to multimedia playback (eg. the APPCOMMAND_MEDIA_* keys.) Keys like APPCOMMAND_VOLUME_* are ignored, so they can be handled by the shell, or by other mixer software.
* w32_common: use sent messages to wake up the Win32 threadJames Ross-Gowan2017-07-041-5/+12
| | | | | | | | | | | | | | | | | Instead of PostMessage, use SendNotifyMessage from the SendMessage family of functions to wake up the Win32 thread from the VO thread. When a message is sent rather than posted between threads, it ends up in a different queue which is processed before posted messages and can be processed in more places. This prevents a playback glitch when clicking on the titlebar, but not moving the window. With PostMessage-based wakeups, VOCTRLs could be delayed for up to 500ms after the user clicks on the titlebar, but with SendNotifyMessage, they still complete in under a millisecond. Also, instead of handling WM_USER, process the dispatch queue before every message. This ensures the dispatch queue is processed as soon as possible. WM_NULL is used to wake up the window procedure in case there are no other messages being processed.
* w32_common: use SWP_NOSENDCHANGING when resizing childJames Ross-Gowan2017-07-031-1/+1
| | | | | | This seems to reduce glitches when resizing a --wid program (or it could be a placebo.) Since we don't need the WM_WINDOWPOSCHANGING handler in --wid mode, it should be fine.
* w32_common, w32_keyboard: change license to LGPLwm42017-06-241-7/+7
| | | | All authors agreed.
* w32_common: drop TLS usageJames Ross-Gowan2017-05-161-20/+21
| | | | | | | | | | | This was added in 3f268cc4f2a4 because it wasn't clear whether WM_NCCREATE could be used to send a context pointer from CreateWindowEx to the window procedure. WM_NCCREATE isn't always the first message sent to a window, but this seems to be because of an undocumented but well-known bug where, for top-level overlapped windows, a spurious WM_GETMINMAXINFO arrives first instead. The WM_GETMINMAXINFO can be safely ignored, so it is still okay to pass the context struct in WM_NCCREATE.
* w32_common: use the proper keycodes for XBUTTON1/2James Ross-Gowan2017-05-121-2/+2
| | | | | | | mpv's mouse button numbering is based on X11, which means XBUTTON1 and 2 on Windows (the "back" and "forward" buttons) should map to MOUSE_BTN7 and 8 in mpv. MOUSE_BTN5 and 6 refer to the horizontal scroll buttons on mouses that have them.
* w32_common: generate MP_AXIS_* keycodes for scrollingJames Ross-Gowan2017-05-121-8/+18
| | | | | | | | | | | Windows doesn't have a way to distinguish "precise" mouse wheel events and events from regular notched mouse wheels. A notched wheel should always send events with a delta of 120, but a precise wheel could also happen to send 120 if multiple scroll events are coalesced (and to make things even harder, some buggy Microsoft drivers send deltas less than 120, even for notched wheels.) Since there is no distinction, but MP_AXIS_* keycodes can hold more information (the delta value,) send MP_AXIS_* events for both kinds of mouse wheel scrolling.
* w32_common: refactor mouse button handlingJames Ross-Gowan2017-04-041-39/+47
| | | | | | | Previously, the shared behaviour for each mouse-button message lived at the bottom of the WndProc. Move it into handle_mouse_down/up functions (similar to the handle_key_down/up functions.) This makes the WndProc slightly less complicated. There should be no change in behaviour.
* w32_common: fix undefined behaviour when toggling fullscreenJames Ross-Gowan2017-04-021-222/+214
| | | | | | | The old code called reinit_window_state() from the VO thread, which is not safe. Instead of calling reinit_window_state() when VO_EVENT_FULLSCREEN_STATE is captured, it should be called when sending the event from the Win32 thread instead.
* w32_common: move the IDropTarget impl to a separate fileJames Ross-Gowan2017-03-261-201/+3
| | | | | | This was mostly self-contained, so its removal makes w32_common.c a bit easier to read. Also, because it was self contained and its author has agreed to LGPL relicencing, the new file has the LGPL licence header.
* win32: update the fullscreen state on restoringpavelxdd2017-02-121-1/+22
| | | | | If a maximized window restored from fullscreen, the fullscreen state needs to be updated manually.