mac: use visible frame rectangle for window geometry calculation

currently we use the whole screen rectangle to calculate the window
geometry. this doesn't take the menu bar or the Dock into account.

by default use the visible screen rectangle instead. this is also a
change in behaviour, since the window can't be placed outside of this
rectangle anymore. also add an option to change to the old behaviour,
because it can still be useful in certain cases, like placing the window
directly underneath the menu bar when used a desktop background.

Fixes #8272
This commit is contained in:
der richter 2020-12-13 17:13:18 +01:00 committed by Jan Ekström
parent 93d071dbd8
commit af26402948
5 changed files with 41 additions and 12 deletions

View File

@ -27,8 +27,13 @@ Interface changes
::
--- mpv 0.34.0 ---
- add `--screen-name` and `--fs-screen-name` flags to allow selecting the
- add `--screen-name` and `--fs-screen-name` flags to allow selecting the
screen by its name instead of the index
- add `--macos-geometry-calculation` to change the rectangle used for screen
position and size calculation. the old behavior used the whole screen,
which didn't take the menu bar and Dock into account. The new default
behaviour includes both. To revert to the old behavior set this to
`whole`.
--- mpv 0.33.0 ---
- add `--d3d11-exclusive-fs` flag to enable D3D11 exclusive fullscreen mode
when the player enters fullscreen.

View File

@ -5914,6 +5914,16 @@ The following video options are currently all specific to ``--vo=gpu`` and
macOS only.
``--macos-geometry-calculation=<visible|whole>``
This changes the rectangle which is used to calculate the screen position
and size of the window (default: visible). ``visible`` takes the the menu
bar and Dock into account and the window is only positioned/sized within the
visible screen frame rectangle, ``whole`` takes the whole screen frame
rectangle and ignores the menu bar and Dock. Other previous restrictions
still apply, like the window can't be placed on top of the menu bar etc.
macOS only.
``--android-surface-size=<WxH>``
Set dimensions of the rendering surface used by the Android gpu context.
Needs to be set by the embedding application if the dimensions change during

View File

@ -21,6 +21,11 @@
#include "osdep/macosx_menubar.h"
#include "options/m_option.h"
enum {
FRAME_VISIBLE = 0,
FRAME_WHOLE,
};
struct macos_opts {
int macos_title_bar_style;
int macos_title_bar_appearance;
@ -29,6 +34,7 @@ struct macos_opts {
int macos_fs_animation_duration;
int macos_force_dedicated_gpu;
int macos_app_activation_policy;
int macos_geometry_calculation;
int cocoa_cb_sw_renderer;
int cocoa_cb_10bit_context;
};

View File

@ -65,6 +65,8 @@ const struct m_sub_options macos_conf = {
{"macos-force-dedicated-gpu", OPT_FLAG(macos_force_dedicated_gpu)},
{"macos-app-activation-policy", OPT_CHOICE(macos_app_activation_policy,
{"regular", 0}, {"accessory", 1}, {"prohibited", 2})},
{"macos-geometry-calculation", OPT_CHOICE(macos_geometry_calculation,
{"visible", FRAME_VISIBLE}, {"whole", FRAME_WHOLE})},
{"cocoa-cb-sw-renderer", OPT_CHOICE(cocoa_cb_sw_renderer,
{"auto", -1}, {"no", 0}, {"yes", 1})},
{"cocoa-cb-10bit-context", OPT_FLAG(cocoa_cb_10bit_context)},

View File

@ -440,21 +440,27 @@ class Common: NSObject {
func getWindowGeometry(forScreen targetScreen: NSScreen,
videoOut vo: UnsafeMutablePointer<vo>) -> NSRect {
let r = targetScreen.convertRectToBacking(targetScreen.frame)
var screenRC: mp_rect = mp_rect(x0: Int32(0),
y0: Int32(0),
x1: Int32(r.size.width),
y1: Int32(r.size.height))
let targetFrame =
(mpv?.macOpts.macos_geometry_calculation ?? FRAME_VISIBLE) == FRAME_VISIBLE ?
targetScreen.visibleFrame : targetScreen.frame
let rv = targetScreen.convertRectToBacking(targetFrame)
// flip the y origin, mp_rect expects the origin at the top-left
// macOS' windowing system operates from the bottom-left
var originY = r.size.height - rv.origin.y - rv.size.height
var screenRC: mp_rect = mp_rect(x0: Int32(rv.origin.x),
y0: Int32(originY),
x1: Int32(rv.origin.x + rv.size.width),
y1: Int32(originY + rv.size.height))
var geo: vo_win_geometry = vo_win_geometry()
vo_calc_window_geometry2(vo, &screenRC, Double(targetScreen.backingScaleFactor), &geo)
vo_apply_window_geometry(vo, &geo)
// flip y coordinates
geo.win.y1 = Int32(r.size.height) - geo.win.y1
geo.win.y0 = Int32(r.size.height) - geo.win.y0
let wr = NSMakeRect(CGFloat(geo.win.x0), CGFloat(geo.win.y1),
CGFloat(geo.win.x1 - geo.win.x0),
CGFloat(geo.win.y0 - geo.win.y1))
// flip the y origin again
let height = CGFloat(geo.win.y1 - geo.win.y0)
originY = r.size.height - CGFloat(geo.win.y0) - height
let wr = NSMakeRect(CGFloat(geo.win.x0), originY,
CGFloat(geo.win.x1 - geo.win.x0), height)
return targetScreen.convertRectFromBacking(wr)
}