Commit Graph

72 Commits

Author SHA1 Message Date
Akemi 80758eda17 cocoa: remove usage of FFABS and the dependency on libavutil/common.h 2017-07-31 20:22:33 +02:00
Akemi b726f1eb90 cocoa: distinguish between horizontal and vertical scroll
we need to switch the x and y deltas when Shift is being held because
macOS switches them around. otherwise we would get a horizontal scroll
on a vertical one and vice versa.

additional we switch from deltaX/Y to scrollingDeltaX/Y since the Apple
docs suggest it's the preferred way now. in my tests both reported the
same values on imprecise scrolls though.
2017-07-31 20:22:33 +02:00
wm4 aa458c1fef osx: change license header on some more cocoa files
Changing the headers was actually forgotten in the previous commit.
2017-06-24 16:50:52 +02:00
Akemi 37f0571973 cocoa: properly unhide Dock when quitting during System fs animation
when quitting mpv during the System fullscreen animation cocoa can't
reset some flags properly and won't reset the Dock hiding behaviour
to it's previous state.

Fixes #4400
2017-05-19 19:19:29 +02:00
Akemi 5e066670d0 cocoa: fix first responder when borderless window is used
this fixes a weird behaviour when a borderless window's style mask is
set to a none-borderless style mask. this can happen when cycling the
border or just toggling fullscreen. what happens is that the first
responder is reset to the NSWindow instead of being kept, the events
view in our case. this happens without the usual resignFirstResponder,
becomeFirstResponder routine.

this is a small workaround that overrides the setStyleMask method. it
keeps the first responder from before the style mask change and resets
this first responder after the new style mask was applied.
2017-03-26 20:38:26 +02:00
Akemi 063ca8f0fe osx: fix key input in certain circumstances
for a reason i can just assume some key events can vanish from the
event chain and mpv seems unresponsive.

after quite some testing i could confirm that the events are present at
the first entry point of the event chain, the sendEvent method of the
Application, and that they vanish at a point afterwards. now we use
that entry point to grab keyDown and keyUp events. we also stop
propagating those key events to prevent the no key input' error sound.
if we ever need the key events somewhere down the event chain we need
to start propagating them again. though this is not necessary currently.
2017-03-26 20:38:26 +02:00
Akemi 076116a0e5 cocoa: set background of the title bar from black to white
due to the see-through nature of the title bar and our standard black
window background, the title bar appears dark grey opposed to the
expected light grey.

we change the window background to white but at the same time set the
background of the enclosed view to black. that way the title bar has a
white background and the background of our video stays black in all
cases. this prevents white flashing in some cases when the video is
resized with too heavy render settings.
2017-03-09 18:02:36 +01:00
Akemi 4fe199c6a0 cocoa: improve calculation of new window position on a different screen
forcibly moving a window from one screen to another is supposed to put
it in a position that looks relative the same as on the old screen, as
in bottom, top, left and right margin look the same, without changing
the window size. in some situations the old code moved the window off
screen or on top of the menu bar so it ended up at a somewhat random
position. the new code fixes some edge cases but is probably not
completely correct since the priority is to make sure that the window
ends up on the right screen.
2017-02-28 00:01:15 +01:00
Akemi 9d549e6837 cocoa: only move window into screen bounds when changing screens
when forcibly moving windows to a different screen with --screen or
--fs-screen we need to move the window into the screen bounds if the
window is out of bounds, otherwise it can end up on the wrong screen.
previously it always recalculated the bounds and moved the window when
toggling fullscreen, now it only does the bound calculation when
changing screens.

Fixes #4178
2017-02-27 23:57:44 +01:00
Akemi 9bd819a0bc cocoa: fix segfault in certain circumstances
i falsely assumed that the windowDidChangeScreen was meant to report
‘physical’ screen changes but was wondering why it triggers on other
events too. it actually is a event that informs us when anything
referenced by our current NSScreen is changed. even when something
referenced in the NSScreen changed the old and new NSScreen are still
equal if the physical screen didn’t change. with that my previous
optimisation broke some cases where the physical screen didn’t change
but things it referenced did, leading to a segfault when theses were
accessed. to keep the optimisation we will always update our internal
NSScreen reference but the rest only when the physical screen was
changed.
2017-02-27 23:57:44 +01:00
Akemi c824a023c4 cocoa: fix dragging out of focus window
fffab30 introduced a small regression where the cursor couldn't be
unhidden after refocusing. the problem is that no mouseUp event was
reported in our events_view. work around this with a separate event
monitor. this also fixes another regression when the window is being
dragged from the title bar.

#4174
2017-02-21 19:26:33 +01:00
Akemi fffab30a3e cocoa: only report mouse movements when window is not being dragged
even though the mouse doesn’t move relative to the window itself, when
the window is being dragged, some outliers are still reported and
trigger the OSC.
2017-02-20 17:26:56 +01:00
Akemi 4f74b93546 cocoa: fix cursor hiding at the top of the screen in fullscreen
even before the recent refactor the cursor was hidden when moving it to
the top of the screen in fullscreen and placing it on top of the now
visible menu bar.

we need to know when the menu bar is hidden so we don’t create a
‘dead zone’ at the top of the screen where the cursor can’t be hidden.
to determine when the menu bar is visible, and with that the title bar,
we get the height of the menu bar. the height is always 0 when hidden.

furthermore there is no way to get the title bar directly and with that
its height. so we calculate the frame rect of a NSWindowStyleMaskTitled
window from a CGRectZero content frame. the resulting height is the
height of a title bar.

with that we can exclude the top area for the cursor hiding and can be
certain when the menu bar is not hidden.
2017-02-19 17:54:06 +01:00
Akemi d45074455a cocoa: fix cursor hiding in the Dock area of the screen
the cursor couldn’t be hidden when the cursor was at the same position
as the Dock, even if the cursor was next to it. this is especially
annoying in fullscreen since the Dock isn’t actually hidden but is still
reported as being visible. this basically made the part of the screen,
where the Dock resides, a ‘dead zone’. so instead of using the
visibleFrame we will just use the normal frame. there is no problem at
the top area of the screen, since a window can’t be placed above the
menu bar and in fullscreen the menu bar is always reported as not being
on screen.

i suspect this was done so the cursor wasn’t hidden when the it was
placed above the Dock when windowed. with the recent refactor this is
not needed any more.
2017-02-19 17:54:06 +01:00
Akemi 3064bbe1dd cocoa: fix scroll wheel input with Shift modifier
holding shift swaps the scroll wheel axes and deltaY returned zero.
summing up deltaX and deltaY will always give us the right button.

Fixes #3506
2017-02-19 17:54:06 +01:00
Akemi 9ac05a575c cocoa: refactor mouse events and cursor visibility
we reported some unnecessary mouse movements and not all mouse enter
and leave events. that lead to wrongly reported activity on hover areas
like on the OSC or comparable lua scripts. sometimes menu items were
shown that shouldn't be shown or they didn't vanish because of the
missing mouse leave event.

this incorporates @torque's fix for mouse leave events that weren't
triggered during a transition, like going to fullscreen. the
tracking area was updated but the mouse never left that area because
it was never over it.

besides some known cursor visibility bugs the aforementioned changes
also revealed some other bugs that weren't reproducible before because
of the missbehavior.
known issues, in some cases the cursor doesn't show or hide properly.
for example when switching spaces, switching Apps via CMD+Tab or a
system notification. former two could be fixed while keeping our current
blank cursor approach. though the notification case couldn't. there is
no event or similar to detect a notification and the cursor visibility
couldn't be recovered in any way.

new issues, i noticed that our event view isn't initialised yet when the
first VOCTRL_SET_CURSOR_VISIBILITY event gets dispatched, which depends
on the event view to be initialised. so the mouse cursor couldn't be
hidden when mpv was opened and the cursor was within the window bounds.
this wasn't noticeable before because of various bugs and unwanted
behavior that have been fixed with this. now, in case the event view
isn't ready yet, we set the visibility at a later point when the event
view is ready and a helper flag is set.

Fixes #1817 #3856 #4147
2017-02-16 22:22:11 +01:00
Akemi 5f10a415d7 cocoa: fix dropping of files and URLs
the problem here is that dropped files can also be treated as
NSURLPboardType instead of just NSFilenamesPboardType. the 'else if'
could never be reached and was dead code.

this basically reverts ed695ce which tried to fix multiple dropped
URLs, or rather files, and moves the filename check infront of the URL
check. the filename path can handle multiple dropped files, whereas the
URL path can only handle one dropped URL. this assumes that only one URL
can be dropped at a time. it also reverts a603543 because it's not
needed any more.

this also fixes a problem where dropped URLs from Chrome don't conform
to the NSURL class and the readObjectsForClasses method always returned
an empty URL.

Fixes #4036
2017-02-02 16:25:44 +01:00
Akemi 6da224b1dd cocoa: optimise screen event handling
this optimises two things and fix a minor bug.

1. we always updated the display refresh rate on any mode change whether
it was the current screen or not. now we only update the refresh rate
when the mode changed happened on the current screen.
2. the windowDidChangeScreen event doesn't exclusively trigger on screen
changes so we updated the display refresh rate in cases where it wasn't
needed at all. since we manually keep track of the current screen, we
can easily test if the screen really changed.
3. weirdly on initWithContentRect accessing the screen of the window
always returned the main screen instead of the screen the window is
created on. since we already use the window init method with the screen
as argument, overwrite that method instead and use the screen argument.
2017-02-02 16:22:27 +01:00
Akemi 717ee3ddba cocoa: don't constrain window frame for fullscreen
our constrainFrameRect prevents our window from positioning itself ontop
of the menubar, which is unwanted for a fullscreen window. this always
positioned our window vertically at -22/-23pt when going into fullscreen
because of the menubar. this bug doesn't show on newer versions of OS X
since the various flags we set force the window position. on OS X 10.9
though the fullscreen window was shifted 22pt downwards. even though
this bug doesn't show on newer OS X versions, it should still be fixed
for a possible behaviour changes in future version.

Fixes #4044
2017-01-19 14:59:51 +01:00
Akemi fe02e5023c cocoa: move updateBorder method to the protocol
we are calling the method on a NSWindow object that may not respond to
that call, since its a method of MpvVideoWindow. add the method to our
protocol and rename that protocol to reflect the change.
2017-01-19 14:54:22 +01:00
Akemi 202f9b218a cocoa: properly recover from toggleFullscreen fail
in some circumstances cocoa isn't able to enter or exit fullscreen but
we still set window sizes and flags accordingly. this leaves us in a
hanging state between fullscreen and window. it also prevents the
toggleFullscreen method and its events to work properly afterwards. in
that state it's impossible to enter or exit this 'semi-fullscreen'.
add a proper fallback to recover from this state.

Fixes #4035
2017-01-19 14:52:51 +01:00
Akemi 4fe45fb3a1 cocoa: fix window size in certain circumstances
a combination of starting from bundle and fullscreen used the standard
window size (960x480) from the pseudo GUI instead of the wanted video
size.
2017-01-19 14:51:11 +01:00
Akemi 46b74a38f1 cocoa: add border cycling
Fixes #2430
2017-01-11 14:17:33 +01:00
Akemi a283b35556 cocoa: fix build on OS X 10.9
fixes #3946
2016-12-26 22:53:04 +01:00
Akemi 2b8b17402e cocoa: cosmetic fixes 2016-12-16 16:32:26 +01:00
Akemi a8347eb9ba cocoa: fullscreen refactoring
this replaces the old fullscreen with the native
macOS fullscreen. additional the
--fs-black-out-screens was removed since the new
API doesn't support it in a way the old one did.
it can possibly be re-added if done manually.

Fixes #2857 #3272 #1352 #2062 #3864
2016-12-15 20:55:16 +01:00
Akemi a6035439a9 cocoa: fix dropping of certain urls on the window
the 'path' of an youtube url (youtube.com/watch?v=x)
would just be '/watch'. obviously this fails to
load.
2016-12-14 00:34:16 +01:00
Akemi 47d9fbd133 cocoa: fix display refresh rate retrieval on multi monitor setups
1. this basically reverts commit de4c74e5a4.
even with CVDisplayLinkCreateWithActiveCGDisplays and
CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext we still have to
explicitly set the current display ID, otherwise it will just always
choose the display with the lowest refresh rate. another weird thing is,
we still have to set the display ID another time with
CVDisplayLinkSetCurrentCGDisplay after the link was started. otherwise
the display period is 0 and the fallback will be used.
if we ever use the callback method for something useful it's probably
better to use CVDisplayLinkCreateWithActiveCGDisplays since we will need
to keep the display link around instead of releasing it at the end.
in that case we have to call CVDisplayLinkSetCurrentCGDisplay two times,
once before and once after LinkStart.
2. add windowDidChangeScreen delegate to update the display refresh rate
when mpv is moved to a different screen.
2016-06-18 19:15:36 +02:00
Nyx0uf ed695ce689 os x: handle multiple dropped files on the window
Should fix #3076 (partially).

Signed-off-by: wm4 <wm4@nowhere>
2016-04-30 18:58:06 +02:00
Jaime Marquínez Ferrándiz d7f04e2085 cocoa: support the "window-minimized" property
Signed-off-by: Stefano Pigozzi <stefano.pigozzi@gmail.com>
2015-03-08 22:00:47 +01:00
Stefano Pigozzi 8ec9bce2d3 cocoa: fix autohide in fullscreen 2015-03-08 15:19:17 +01:00
Stefano Pigozzi ce239f1577 cocoa: fix mouse hiding with launchpad and dock folders
Some UI elements in OS X – like Launchpad and Dock folders – are implemented
using borderless windows in background demonized applications.
When we use these elements, mpv doesn't stop to be the active application, but
the mpv window leaves keyWindow state while we use the OS controls.

This commit just keeps track of window state to update the cursor visibility
accordingly.

Fixes #513
2015-03-08 11:56:56 +01:00
torque 39537f6474 cocoa: clamp mouse position to window.
Prevents out-of-window coordinates being reported for mouse coordinates.
Previously they could be out-of-window coordinates on init or on resize.
2015-03-07 19:32:02 +01:00
torque bce753060e cocoa: update mouse coordinates when window is initialized.
Make MpvEventsView -signalMousePosition a public method so it can be
called without a compiler warning. Previously, the mouse position would
be reported as (0,0) until the cursor was moved.
2015-03-07 19:31:52 +01:00
torque 3b269ac0a0 input: add MOUSE_ENTER keybinding.
Signed-off-by: wm4 <wm4@nowhere>
2015-02-18 00:03:16 +01:00
Stefano Pigozzi 9633790ac6 cocoa: fix build on 10.9
Use -isInFullScreenMode instead of the property introduced with the 10.10 SDK.
2015-01-02 20:54:09 +01:00
Stefano Pigozzi 43faae7a1e cocoa: fix NSMapGet error
regression from 64b6b2ea45
2015-01-02 19:19:23 +01:00
Stefano Pigozzi 64b6b2ea45 cocoa: fix uninitialization while in fullscreen
This is only needed for switching video track with `_`, since Cocoa
automatically handles cleaning up the application's presentation options when
quitting the process.

Fixes #1399
2015-01-01 14:38:08 +01:00
Stefano Pigozzi 586c9e7155 cocoa: allow to black out other display when going fs
fixes #1302
2014-12-01 18:05:30 +01:00
Stefano Pigozzi fa904150bf cocoa: reintroduce async resize
After removing synchronous libdispatch calls, this looks like it doesn't
deadlock anymore. I also experimented with pthread_mutex_trylock liek wm4
suggested, but it leads to some annoying black flickering. I will fallback to
that only if some new deadlocks are discovered.
2014-10-18 18:30:22 +02:00
Stefano Pigozzi eb902efb04 cocoa: allow mouse events to bubble up with no-input-cursor
Previously we didn't report events to the core, but still prevented the events
to travel on the responder chain.
2014-10-17 19:19:45 +02:00
Stefano Pigozzi c2eca2e4b7 libmpv/cocoa: allow clients to use mpv event system
This allows mpv's view to take key and send events to mpv's core.
To set key status correctly, clients must call -[NSWindow selectNextKeyView:]
during reconfig on the main thread. All is 'documented' in the cocoabasic
example.

If someone knows a better way to handle giving key to the embedded view,
let me know!
2014-10-12 00:19:44 +02:00
Stefano Pigozzi 8b6b84f36b cocoa: remove usage of Objective-C categories
Objective-C categories need special linker flags from the user when statically
linking (-ObjC LDFLAG), so make everyone's life simpler and remove them.
2014-10-12 00:19:44 +02:00
Stefano Pigozzi 8a25a4af65 cocoa: post keydown and keyup events without event monitor
Our code worked under the assumption that the event monitor is always active
and we did remove the keydown and keyup overrides from our cocoa view.
2014-10-09 22:14:41 +02:00
Stefano Pigozzi 69fa956f50 cocoa: allow to embed into an arbitrary NSView
Basically add if guards on all the problematic features. I'm still thinking
about a better way to handle this, but for the time being, this will do.
2014-10-08 19:38:35 +02:00
Stefano Pigozzi ba994bc0dd cocoa: fix mouse autohide
broken in 547b62f
2014-10-05 23:49:09 +02:00
Stefano Pigozzi 69508dc507 cocoa: remove a debug commento
fixup previous commit
2014-10-05 23:41:39 +02:00
Stefano Pigozzi 547b62f45e cocoa: separate video view and events view 2014-10-05 23:38:39 +02:00
Stefano Pigozzi c6b68c28f4 cocoa: remove --fs-missioncontrol
This is the first of a series of commits that will change the Cocoa way in a
way that is easily embeddable inside parent views. To reach that point common
code must avoid referencing the parent NSWindow since that could be the host
application's window.
2014-10-05 18:07:27 +02:00
Stefano Pigozzi c8ed4736ef cocoa/libmpv: allow to embed mpv GL view in another window
This is just temporary code but is a good base for future work (and baby
steps are required for these changes). The 'final destination' is embedding
the video view into any NSView but that requires some more work (the mechanism
will be the same: pass the view's pointer casted to int64_t through -wid).

For instance we will need to remove as much usage of the window instance
as possible, and use nil guards where not possible. For this reason I will
remove stuff like the mission control fullscreen feature (it's a cute feature
but annoying to support and quite limited, go make your GUIs), and a way to
lookup the current screen directly from the NSView absolute coordinates
(this is needed for ICC detection mostly, and reporting back the screen to
mpv's core).

Moreover the current view.m will need to be separated into 2 views: the actual
video view that will be embedded, and a parent view that will not be embedded
and will be responsibile for tracking events.
2014-10-05 14:28:33 +02:00