0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00
Commit Graph

222 Commits

Author SHA1 Message Date
sunpenghao
1dd71a6093 win32: improve window snapping behavior
Several window resizing operations (i.e., --auto-window-resize,
border dragging with --keep-aspect-window, Alt+0/1/2) cause the
window to detach from the snapped borders. This patch resolves
this by recording to which borders the window is snapped, and
using this info to determine how the window should be placed after
resizing.

Closes https://github.com/mpv-player/mpv/issues/6588
2023-10-10 19:41:08 +00:00
Kacper Michajłow
d17db1367a win32: clear client area to black early
This fixes white background appearing for short period of time before
first frame is drawn. Clear to black as this is way less distracting
than bright white flash.

Borderless window and fullscreen seems to be initially not
drawn/transparent, so no need to clear it to black. Only when
decorations are enabled (--border) the issue happens.

Fixes: #12549
2023-10-05 17:10:23 +02:00
Kacper Michajłow
01c5346d1a win32: adjust WM_NCACTIVATE for better compatibility with window state
We have to support all changing states, not only borderless.
2023-10-02 21:51:47 +00:00
Kacper Michajłow
a98641cf45 win32: add WS_THICKFRAME style in borderless mode
Fixes window resizing in borderless mode after adding WS_SYSMENU.

Fixes: 172d9be300
2023-10-01 15:57:31 +00:00
Kacper Michajłow
172d9be300 win32: set WS_SYSMENU style always
Fixes missing icon when initial window is created without caption.

Fixes: #12472
2023-10-01 14:05:10 +00:00
DeadSix
f19ada7b58 win32: add option to change backdrop style 2023-09-27 14:02:08 +00:00
DeadSix27
3665b8d1d8 win32: pass window handle to the window-id property
uses the same mechanic as for x11
2023-09-25 15:35:25 +00:00
Kacper Michajłow
6eb35f6f64 win32: don't remove WS_CAPTION from style
Apparently removing WS_CAPTION disables some window animations. Instead
adjust non-client area to not draw title bar.

Note that we do not account for difference in real border size and
invisible one, but seems to work correctly.
2023-09-21 23:13:19 +00:00
Kacper Michajłow
18deac3e81 win32: enable custom WM_NCHITTEST also when title bar is hidden 2023-09-21 23:13:19 +00:00
Kacper Michajłow
4defeddbfc win32: set window_corners to default for fullscreen
I don't think in fullscreen mode it makes sense to enable rounded corners.
We can add another option if someone needs it, but for now `window_corners`
affects only the window as one would expect.
2023-09-21 23:13:19 +00:00
Kacper Michajłow
804eb80e78 win32: add --window-corners
Allows to set preference for window corners rounding for DWM.
2023-09-21 23:13:19 +00:00
Kacper Michajłow
0d457ffc40 win32: fix fit_window_on_screen to account for invisible borders
Fixes too small initial window size.
2023-09-21 23:13:19 +00:00
Kacper Michajłow
fac2b31df7 win32: reduce top border thickness to imitate DWM invisible borders
DWM makes part of left, right and bottom border invisible.
2023-09-21 23:13:19 +00:00
Kacper Michajłow
ee24dd0419 win32: add an option to control window title bar state
Fixes: #11432
2023-09-21 23:13:19 +00:00
DeadSix
2c738ca54b win32: add an option to change window affinity 2023-09-21 22:14:28 +00:00
Kacper Michajłow
7f6785f363 win32: explicitly guard dark mode calls by Windows version
Fixes: #11610
Fixes: 9feeb324ed
2023-09-21 19:40:40 +00:00
Kacper Michajłow
63ca12d7bc win32: remove noisy debug log
It is quite unnecessary to log every window move.
2023-09-17 17:14:34 +02:00
Kacper Michajłow
ce79976498 win32: don't ignore --screen and --fs-screen
Fixes: 57ba77fc73
Fixes: #12220
2023-08-23 15:37:41 +02:00
Zenos
57ba77fc73 w32_common: try to get the monitor from the window bounds 2023-08-20 20:39:05 +02:00
Zenos
da965906ef w32_common: don't fit to screen when VO_WIN_FORCE_POS is set 2023-08-20 20:39:05 +02:00
mwalmer
f88ed14168 win32_common: fixes minimized window being focused on launch
mpv was taking focus when being started with "--window-minimized=yes". This change stops mpv from taking focus when this option is used.

Resolves: #9641
2023-08-20 20:21:14 +02:00
Dudemanguy
455487bdc9 win32: fix display resolution calculation on mulitple monitors
It was actually always wrong, and no one ever noticed. This currently
returns the size of the entire display area and not one actual monitor.
Fix this by calling get_monitor_info and then doing the appropriate
subtractions. Checked by @CrendKing and fixes #12172.
2023-08-15 21:01:13 +00:00
Dudemanguy
8417804224 win32: signal VO_EVENT_DPI on dpi changes
The win32 code already updates itself on dpi changes. However, it never
signalled mpv's core when this happened which meant that the
display-hidpi-scale property never changed. Simply send the
VO_EVENT_DPI event when appropriate. Fixes #12081.
2023-08-06 19:09:44 +00:00
Dudemanguy
f76c441ba2 win32: add support for drag-and-drop option 2023-07-01 02:06:02 +00:00
Kacper Michajłow
9feeb324ed win32: follow Windows settings and update dark mode state
Microsoft documented how to enable dark mode for title bar:

https://learn.microsoft.com/windows/apps/desktop/modernize/apply-windows-themes
https://learn.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute

Documentation says to set the DWMWA_USE_IMMERSIVE_DARK_MODE attribute to
TRUE to honor dark mode for the window, FALSE to always use light mode.
While in fact setting it to TRUE causes dark mode to be always enabled,
regardless of the settings. Since it is quite unlikely that it will be
fixed, just use UxTheme API to check if dark mode should be applied and
while at it enable it fully. Ideally this function should only call the
DwmSetWindowAttribute(), but it just doesn't work as documented.

Fixes: #6901
2023-04-04 20:04:57 +02:00
Dudemanguy
c993d5c0ce player: add --auto-window-resize option
mpv's window resizing logic always automatically resized the window
whenever the video resolution changed (i.e. advancing forward in a
playlist). This simply introduces the option to make this behavior
configurable. Every windowing backend would need to implement this
behavior in their code since a reconfigure event must always be a
resize. The params of the frame changed so you either have to resize the
window to the new size of the params or make the params the same size as
the window. This commit implements it for wayland, win32, and x11.
2023-03-02 02:55:36 +00:00
Dudemanguy
e4e0e7dfcf vo: change vo_platform_init to bool
There's several functions that are used for initializing mpv on a
certain platform (x11, wayland, etc.). These currently are all int, but
they actually return 1 and 0 like a boolean. This gets a bit confusing
because actual vo preinit functions return 0 and -1 instead. Just make
these all bool instead and return true/false to make it clearer.
2023-01-08 20:42:42 +00:00
Guido Cella
fe9e074752 various: remove trailing whitespace 2022-05-14 14:51:34 +00:00
Cœur
bb5b4b1ba6 various: fix typos 2022-04-25 09:07:18 -04:00
Avi Halachmi (:avih)
555c15efba win32: apply geometry position to content instead of window
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.
2022-02-02 13:05:55 +02:00
Avi Halachmi (:avih)
8fb4fd9a18 win32: initial position: center with borders
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.
2021-09-06 10:16:10 +03:00
Avi Halachmi (:avih)
73f16b5431 win32: fix incorrect application of --monitoraspect
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.
2021-09-06 10:16:10 +03:00
Avi Halachmi (:avih)
6193f723b0 win32: support the property display-hidpi-scale
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.
2021-08-18 02:21:33 +03:00
Avi Halachmi (:avih)
052220d1c7 win32: apply dpi-scale with [current]-window-scale
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.
2021-08-18 02:21:33 +03:00
Avi Halachmi (:avih)
19e24bbe86 win32: ensure initial dpi-scale value
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.
2021-08-18 02:21:33 +03:00
Avi Halachmi (:avih)
89684976ac win32: support the property 'focused'
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
2021-05-27 13:49:07 +03:00
Dudemanguy
a88fdfde0c command: add display-width/display-height property
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.
2021-05-06 17:36:55 +00:00
Avi Halachmi (:avih)
f60e327e49 win32: fit_window_on_screen: simplify, add comments
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.
2021-04-23 10:45:51 +03:00
Avi Halachmi (:avih)
954f6ac7bf win32: fit_window_on_screen: centralize logic (no-op)
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.
2021-04-23 10:45:51 +03:00
Avi Halachmi (:avih)
e00ae12bbb win32: fit_window_on_screen: ensure top edge is inside
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
2021-04-23 10:45:51 +03:00
Avi Halachmi (:avih)
ef1d0b2cdb options: win32: ignore and deprecate --fit-border
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.
2021-04-23 10:45:51 +03:00
Piotr Gasior
5676e5ba39 w32_common: Scale window when moving to display with different DPI
For applications that are DPI aware WM_DPICHANGED message contains
suggested size and position of window
2020-05-08 21:47:32 +10:00
RealDolos
8bce6d0b89 w32_common: Support HiDPI on Windows 2020-05-08 21:46:45 +10:00
James Ross-Gowan
80423e5b55 w32_common: support minimized and maximized properties
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
2020-01-26 15:36:12 +02:00
James Ross-Gowan
c4600394d4 w32_common: remove implicit fallthrough
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.
2019-12-29 02:30:31 +11:00
Jan Ekström
df7d5a1689 video/w32_common: follow updates to the border option instead of VOCTRL_BORDER 2019-12-18 00:02:49 +02:00
Jan Ekström
6554db47ab video/w32_common: follow updates to the ontop option instead of VOCTRL_ONTOP 2019-12-18 00:02:49 +02:00
Jan Ekström
ee75908134 video/w32_common: move minimized state signaling to where it happens
WM_SIZE is the message we receive from which we can infer if we got
minimized or not.
2019-12-18 00:02:49 +02:00
Jan Ekström
8200304768 video/w32_common: switch full screening to options cache
* 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.
2019-12-18 00:02:49 +02:00
James Ross-Gowan
c754c31d6f w32_common: avoid unnecessary sprintfs
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.)
2019-05-10 20:47:05 +10:00