1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-30 03:32:50 +00:00

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.
This commit is contained in:
Stefano Pigozzi 2014-10-12 00:14:21 +02:00
parent b9077214cf
commit 8b6b84f36b
5 changed files with 37 additions and 89 deletions

View File

@ -1,27 +0,0 @@
/*
* This file is part of mpv.
*
* mpv is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* mpv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#import <Cocoa/Cocoa.h>
@interface NSScreen (mpvadditions)
- (BOOL)hasDock;
- (BOOL)hasMenubar;
@end
@interface NSEvent (mpvadditions)
- (int)mpvButtonNumber;
@end

View File

@ -1,54 +0,0 @@
/*
* This file is part of mpv.
*
* mpv is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* mpv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#import "additions.h"
#include "osdep/macosx_compat.h"
@implementation NSScreen (mpvadditions)
- (BOOL)hasDock
{
NSRect vF = [self visibleFrame];
NSRect f = [self frame];
return
// The visible frame's width is smaller: dock is on left or right end
// of this method's receiver.
vF.size.width < f.size.width ||
// The visible frame's veritical origin is bigger: dock is
// on the bottom of this method's receiver.
vF.origin.y > f.origin.y;
}
- (BOOL)hasMenubar
{
NSRect vF = [self visibleFrame];
NSRect f = [self frame];
return f.size.height + f.origin.y > vF.size.height + vF.origin.y;
}
@end
@implementation NSEvent (mpvadditions)
- (int)mpvButtonNumber
{
int buttonNumber = [self buttonNumber];
switch (buttonNumber) {
case 1: return 2;
case 2: return 1;
default: return buttonNumber;
}
}
@end

View File

@ -22,14 +22,15 @@
#include "osdep/macosx_compat.h"
#include "video/out/cocoa_common.h"
#import "video/out/cocoa/additions.h"
#include "events_view.h"
@interface MpvEventsView()
@property(nonatomic, assign) BOOL hasMouseDown;
@property(nonatomic, retain) NSTrackingArea *tracker;
- (void)signalMousePosition;
- (BOOL)hasDock:(NSScreen*)screen;
- (BOOL)hasMenubar:(NSScreen*)screen;
- (int)mpvButtonNumber:(NSEvent*)event;
@end
@implementation MpvEventsView
@ -52,14 +53,14 @@
NSApplicationPresentationOptions popts =
NSApplicationPresentationDefault;
if ([[self.adapter fsScreen] hasMenubar])
if ([self hasMenubar:[self.adapter fsScreen]])
// Cocoa raises an exception when autohiding the menubar but
// not the dock. They probably got bored while programming the
// multi screen support and took some shortcuts (tested on 10.8).
popts |= NSApplicationPresentationAutoHideMenuBar |
NSApplicationPresentationAutoHideDock;
if ([[self.adapter fsScreen] hasDock])
if ([self hasDock:[self.adapter fsScreen]])
popts |= NSApplicationPresentationAutoHideDock;
NSDictionary *fsopts = @{
@ -233,7 +234,7 @@
- (void)putMouseEvent:(NSEvent *)event withState:(int)state
{
self.hasMouseDown = (state == MP_KEY_STATE_DOWN);
int mpkey = (MP_MOUSE_BTN0 + [event mpvButtonNumber]);
int mpkey = (MP_MOUSE_BTN0 + [self mpvButtonNumber:event]);
[self.adapter putKey:(mpkey | state) withModifiers:[event modifierFlags]];
}
@ -262,4 +263,35 @@
}
return NO;
}
- (BOOL)hasDock:(NSScreen*)screen
{
NSRect vF = [screen visibleFrame];
NSRect f = [screen frame];
return
// The visible frame's width is smaller: dock is on left or right end
// of this method's receiver.
vF.size.width < f.size.width ||
// The visible frame's veritical origin is bigger: dock is
// on the bottom of this method's receiver.
vF.origin.y > f.origin.y;
}
- (BOOL)hasMenubar:(NSScreen*)screen
{
NSRect vF = [screen visibleFrame];
NSRect f = [screen frame];
return f.size.height + f.origin.y > vF.size.height + vF.origin.y;
}
- (int)mpvButtonNumber:(NSEvent*)event
{
int buttonNumber = [event buttonNumber];
switch (buttonNumber) {
case 1: return 2;
case 2: return 1;
default: return buttonNumber;
}
}
@end

View File

@ -21,8 +21,6 @@
#include "osdep/macosx_events.h"
#include "osdep/macosx_compat.h"
#include "video/out/cocoa/additions.h"
#include "video/out/cocoa_common.h"
#include "window.h"

View File

@ -335,7 +335,6 @@ def build(ctx):
( "video/filter/vf_yadif.c" ),
( "video/out/aspect.c" ),
( "video/out/bitmap_packer.c" ),
( "video/out/cocoa/additions.m", "cocoa" ),
( "video/out/cocoa/video_view.m", "cocoa" ),
( "video/out/cocoa/events_view.m", "cocoa" ),
( "video/out/cocoa/window.m", "cocoa" ),