Browse Source

macosx/main menu: refactor the shortcuts handling

pull/89/head
Felix Paul Kühne 7 years ago
parent
commit
175f55a6f9
  1. 6
      modules/gui/macosx/coreinteraction/VLCCoreInteraction.m
  2. 4
      modules/gui/macosx/extensions/NSString+Helpers.h
  3. 18
      modules/gui/macosx/extensions/NSString+Helpers.m
  4. 315
      modules/gui/macosx/menus/VLCMainMenu.m
  5. 50
      modules/gui/macosx/windows/mainwindow/VLCMainWindow.m

6
modules/gui/macosx/coreinteraction/VLCCoreInteraction.m

@ -491,10 +491,10 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
BOOL b_found_key = NO;
NSUInteger numberOfUsedHotkeys = [_usedHotkeys count];
for (NSUInteger i = 0; i < numberOfUsedHotkeys; i++) {
NSString *str = [_usedHotkeys objectAtIndex:i];
unsigned int i_keyModifiers = VLCModifiersToCocoa(str);
const char *str = [[_usedHotkeys objectAtIndex:i] UTF8String];
unsigned int i_keyModifiers = VLCModifiersToCocoa((char *)str);
if ([[characters lowercaseString] isEqualToString: VLCKeyToString(str)] &&
if ([[characters lowercaseString] isEqualToString:VLCKeyToString((char *)str)] &&
(i_keyModifiers & NSShiftKeyMask) == (i_pressed_modifiers & NSShiftKeyMask) &&
(i_keyModifiers & NSControlKeyMask) == (i_pressed_modifiers & NSControlKeyMask) &&
(i_keyModifiers & NSAlternateKeyMask) == (i_pressed_modifiers & NSAlternateKeyMask) &&

4
modules/gui/macosx/extensions/NSString+Helpers.h

@ -189,9 +189,9 @@ NSString * OSXStringKeyToString(NSString *theString);
/**
* Converts VLC key string to cocoa modifiers which can be used as setKeyEquivalent for menu items
*/
NSString * VLCKeyToString(NSString *theString);
NSString * VLCKeyToString(char *theChar);
/**
* Converts VLC key to cocoa string which can be used as setKeyEquivalentModifierMask for menu items
*/
unsigned int VLCModifiersToCocoa(NSString *theString);
unsigned int VLCModifiersToCocoa(char *theChar);

18
modules/gui/macosx/extensions/NSString+Helpers.m

@ -409,8 +409,13 @@ NSString * OSXStringKeyToString(NSString *theString)
return theString;
}
NSString * VLCKeyToString(NSString *theString)
NSString * VLCKeyToString(char *theChar)
{
if (theChar == NULL) {
return @"";
}
NSString *theString = toNSStr(theChar);
if (![theString isEqualToString:@""]) {
if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
@ -497,17 +502,18 @@ NSString * VLCKeyToString(NSString *theString)
return theString;
}
unsigned int VLCModifiersToCocoa(NSString *theString)
unsigned int VLCModifiersToCocoa(char *theChar)
{
unsigned int new = 0;
if ([theString rangeOfString:@"Command"].location != NSNotFound)
if (strstr(theChar, "Command") != NULL)
new |= NSCommandKeyMask;
if ([theString rangeOfString:@"Alt"].location != NSNotFound)
if (strstr(theChar, "Alt") != NULL)
new |= NSAlternateKeyMask;
if ([theString rangeOfString:@"Shift"].location != NSNotFound)
if (strstr(theChar, "Shift") != NULL)
new |= NSShiftKeyMask;
if ([theString rangeOfString:@"Ctrl"].location != NSNotFound)
if (strstr(theChar, "Ctrl") != NULL)
new |= NSControlKeyMask;
return new;
}

315
modules/gui/macosx/menus/VLCMainMenu.m

@ -115,105 +115,8 @@
[_checkForUpdate setEnabled:NO];
#endif
NSString* keyString;
char *key;
/* Get ExtensionsManager */
intf_thread_t *p_intf = getIntf();
[self initStrings];
key = config_GetPsz("key-quit");
keyString = [NSString stringWithFormat:@"%s", key];
[_quit setKeyEquivalent: VLCKeyToString(keyString)];
[_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
// do not assign play/pause key
key = config_GetPsz("key-stop");
keyString = [NSString stringWithFormat:@"%s", key];
[_stop setKeyEquivalent: VLCKeyToString(keyString)];
[_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-prev");
keyString = [NSString stringWithFormat:@"%s", key];
[_previous setKeyEquivalent: VLCKeyToString(keyString)];
[_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-next");
keyString = [NSString stringWithFormat:@"%s", key];
[_next setKeyEquivalent: VLCKeyToString(keyString)];
[_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-jump+short");
keyString = [NSString stringWithFormat:@"%s", key];
[_fwd setKeyEquivalent: VLCKeyToString(keyString)];
[_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-jump-short");
keyString = [NSString stringWithFormat:@"%s", key];
[_bwd setKeyEquivalent: VLCKeyToString(keyString)];
[_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-vol-up");
keyString = [NSString stringWithFormat:@"%s", key];
[_vol_up setKeyEquivalent: VLCKeyToString(keyString)];
[_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-vol-down");
keyString = [NSString stringWithFormat:@"%s", key];
[_vol_down setKeyEquivalent: VLCKeyToString(keyString)];
[_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-vol-mute");
keyString = [NSString stringWithFormat:@"%s", key];
[_mute setKeyEquivalent: VLCKeyToString(keyString)];
[_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-toggle-fullscreen");
keyString = [NSString stringWithFormat:@"%s", key];
[_fullscreenItem setKeyEquivalent: VLCKeyToString(keyString)];
[_fullscreenItem setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-snapshot");
keyString = [NSString stringWithFormat:@"%s", key];
[_snapshot setKeyEquivalent: VLCKeyToString(keyString)];
[_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-random");
keyString = [NSString stringWithFormat:@"%s", key];
[_random setKeyEquivalent: VLCKeyToString(keyString)];
[_random setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-zoom-half");
keyString = [NSString stringWithFormat:@"%s", key];
[_half_window setKeyEquivalent: VLCKeyToString(keyString)];
[_half_window setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-zoom-original");
keyString = [NSString stringWithFormat:@"%s", key];
[_normal_window setKeyEquivalent: VLCKeyToString(keyString)];
[_normal_window setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
key = config_GetPsz("key-zoom-double");
keyString = [NSString stringWithFormat:@"%s", key];
[_double_window setKeyEquivalent: VLCKeyToString(keyString)];
[_double_window setKeyEquivalentModifierMask: VLCModifiersToCocoa(keyString)];
FREENULL(key);
[self setupKeyboardShortcuts];
[self setSubmenusEnabled: YES];
@ -250,8 +153,10 @@
name:VLCPlaybackOrderChanged
object:self];
[self setupVarMenuItem:_add_intf target: (vlc_object_t *)p_intf
var:"intf-add" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_add_intf
target:VLC_OBJECT(getIntf())
var:"intf-add"
selector:@selector(toggleVar:)];
/* setup extensions menu */
/* Let the ExtensionsManager itself build the menu */
@ -260,26 +165,22 @@
[_extensions setEnabled: ([_extensionsMenu numberOfItems] > 0)];
// FIXME: Implement preference for autoloading extensions on mac
// FIXME: this is definitely the wrong place to do this.
if (![extMgr isLoaded] && ![extMgr cannotLoad])
[extMgr loadExtensions];
/* setup post-proc menu */
NSUInteger count = (NSUInteger) [_postprocessingMenu numberOfItems];
if (count > 0)
[_postprocessingMenu removeAllItems];
// FIXME: re-write the following using VLCPlayerController
NSMenuItem *mitem;
[_postprocessingMenu removeAllItems];
[_postprocessingMenu setAutoenablesItems: YES];
[_postprocessingMenu addItemWithTitle: _NS("Disable") action:@selector(togglePostProcessing:) keyEquivalent:@""];
mitem = [_postprocessingMenu itemAtIndex: 0];
NSMenuItem *mitem = [_postprocessingMenu itemAtIndex: 0];
[mitem setTag: -1];
[mitem setEnabled: YES];
[mitem setTarget: self];
for (NSUInteger x = 1; x < 7; x++) {
[_postprocessingMenu addItemWithTitle:[NSString stringWithFormat:_NS("Level %i"), x]
action:@selector(togglePostProcessing:)
keyEquivalent:@""];
action:@selector(togglePostProcessing:)
keyEquivalent:@""];
mitem = [_postprocessingMenu itemAtIndex:x];
[mitem setEnabled:YES];
[mitem setTag:x];
@ -327,14 +228,14 @@
{ NULL, 0 }
};
for(int i = 0; scaleValues[i].name; i++) {
for (int i = 0; scaleValues[i].name; i++) {
NSMenuItem *menuItem = [_subtitle_sizeMenu addItemWithTitle: _NS(scaleValues[i].name) action:@selector(switchSubtitleSize:) keyEquivalent:@""];
[menuItem setTag:scaleValues[i].scaleValue];
[menuItem setTarget: self];
}
}
- (void)setupMenu: (NSMenu*)menu withIntList: (char *)psz_name andSelector:(SEL)selector
- (void)setupMenu:(NSMenu *)menu withIntList:(char *)psz_name andSelector:(SEL)selector
{
module_config_t *p_item;
@ -548,6 +449,88 @@
[_voutMenusnapshot setTitle: _NS("Snapshot")];
}
- (void)setupKeyboardShortcuts
{
char *key;
key = config_GetPsz("key-quit");
[_quit setKeyEquivalent: VLCKeyToString(key)];
[_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
// do not assign play/pause key
key = config_GetPsz("key-stop");
[_stop setKeyEquivalent: VLCKeyToString(key)];
[_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-prev");
[_previous setKeyEquivalent: VLCKeyToString(key)];
[_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-next");
[_next setKeyEquivalent: VLCKeyToString(key)];
[_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-jump+short");
[_fwd setKeyEquivalent: VLCKeyToString(key)];
[_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-jump-short");
[_bwd setKeyEquivalent: VLCKeyToString(key)];
[_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-vol-up");
[_vol_up setKeyEquivalent: VLCKeyToString(key)];
[_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-vol-down");
[_vol_down setKeyEquivalent: VLCKeyToString(key)];
[_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-vol-mute");
[_mute setKeyEquivalent: VLCKeyToString(key)];
[_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-toggle-fullscreen");
[_fullscreenItem setKeyEquivalent: VLCKeyToString(key)];
[_fullscreenItem setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-snapshot");
[_snapshot setKeyEquivalent: VLCKeyToString(key)];
[_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-random");
[_random setKeyEquivalent: VLCKeyToString(key)];
[_random setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-zoom-half");
[_half_window setKeyEquivalent: VLCKeyToString(key)];
[_half_window setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-zoom-original");
[_normal_window setKeyEquivalent: VLCKeyToString(key)];
[_normal_window setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
key = config_GetPsz("key-zoom-double");
[_double_window setKeyEquivalent: VLCKeyToString(key)];
[_double_window setKeyEquivalentModifierMask: VLCModifiersToCocoa(key)];
FREENULL(key);
}
#pragma mark - Termination
- (void)releaseRepresentedObjects:(NSMenu *)the_menu
@ -567,10 +550,10 @@
- (void)setupMenus
{
playlist_t *p_playlist = pl_Get(getIntf());
input_thread_t *p_input = playlist_CurrentInput(p_playlist);
if (p_input != NULL) {
[self setupVarMenuItem:_program target: (vlc_object_t *)p_input
input_item_t *p_mediaItem = _playerController.currentMedia;
if (p_mediaItem != NULL) {
/* [self setupVarMenuItem:_program target: (vlc_object_t *)p_input
var:"program" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_title target: (vlc_object_t *)p_input
@ -586,39 +569,38 @@
var:"video-es" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_subtitle_track target: (vlc_object_t *)p_input
var:"spu-es" selector: @selector(toggleVar:)];
var:"spu-es" selector: @selector(toggleVar:)];*/
audio_output_t *p_aout = [_playerController mainAudioOutput];
if (p_aout != NULL) {
[self setupVarMenuItem:_channels target: (vlc_object_t *)p_aout
var:"stereo-mode" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_channels target:VLC_OBJECT(p_aout)
var:"stereo-mode" selector:@selector(toggleVar:)];
[self setupVarMenuItem:_visual target: (vlc_object_t *)p_aout
var:"visual" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_visual target:VLC_OBJECT(p_aout)
var:"visual" selector:@selector(toggleVar:)];
aout_Release(p_aout);
}
vout_thread_t *p_vout = [_playerController videoOutputThreadForKeyWindow];
if (p_vout != NULL) {
[self setupVarMenuItem:_aspect_ratio target: (vlc_object_t *)p_vout
var:"aspect-ratio" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_aspect_ratio target:VLC_OBJECT(p_vout)
var:"aspect-ratio" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_crop target: (vlc_object_t *) p_vout
var:"crop" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_crop target:VLC_OBJECT(p_vout)
var:"crop" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_deinterlace target: (vlc_object_t *)p_vout
var:"deinterlace" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_deinterlace target:VLC_OBJECT(p_vout)
var:"deinterlace" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_deinterlace_mode target: (vlc_object_t *)p_vout
var:"deinterlace-mode" selector: @selector(toggleVar:)];
[self setupVarMenuItem:_deinterlace_mode target:VLC_OBJECT(p_vout)
var:"deinterlace-mode" selector: @selector(toggleVar:)];
vout_Release(p_vout);
[self refreshVoutDeviceMenu:nil];
}
[_postprocessing setEnabled:YES];
input_Release(p_input);
input_item_Release(p_mediaItem);
} else {
[_postprocessing setEnabled:NO];
}
@ -626,29 +608,28 @@
- (void)refreshVoutDeviceMenu:(NSNotification *)notification
{
NSUInteger count = (NSUInteger) [_screenMenu numberOfItems];
NSMenu *submenu = _screenMenu;
if (count > 0)
[submenu removeAllItems];
[submenu removeAllItems];
NSArray *screens = [NSScreen screens];
NSMenuItem *mitem;
count = [screens count];
NSMenuItem *menuItem;
NSUInteger numberOfScreens = [screens count];
[_screen setEnabled: YES];
[submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
mitem = [submenu itemAtIndex: 0];
[mitem setTag: 0];
[mitem setEnabled: YES];
[mitem setTarget: self];
menuItem = [submenu itemAtIndex: 0];
[menuItem setTag: 0];
[menuItem setEnabled: YES];
[menuItem setTarget: self];
NSRect s_rect;
for (NSUInteger i = 0; i < count; i++) {
for (NSUInteger i = 0; i < numberOfScreens; i++) {
s_rect = [[screens objectAtIndex:i] frame];
[submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
(int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
mitem = [submenu itemAtIndex:i+1];
[mitem setTag: (int)[[screens objectAtIndex:i] displayID]];
[mitem setEnabled: YES];
[mitem setTarget: self];
[submenu addItemWithTitle:[NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1, (int)s_rect.size.width, (int)s_rect.size.height]
action:@selector(toggleFullscreenDevice:)
keyEquivalent:@""];
menuItem = [submenu itemAtIndex:i+1];
[menuItem setTag: (int)[[screens objectAtIndex:i] displayID]];
[menuItem setEnabled: YES];
[menuItem setTarget: self];
}
[[submenu itemWithTag: var_InheritInteger(getIntf(), "macosx-vdev")] setState: NSOnState];
}
@ -744,27 +725,31 @@
- (IBAction)play:(id)sender
{
[[VLCCoreInteraction sharedInstance] playOrPause];
[_playerController togglePlayPause];
}
- (IBAction)stop:(id)sender
{
[[VLCCoreInteraction sharedInstance] stop];
[_playerController stop];
}
- (IBAction)prev:(id)sender
{
[[VLCCoreInteraction sharedInstance] previous];
[_playlistController playPreviousItem];
}
- (IBAction)next:(id)sender
{
[[VLCCoreInteraction sharedInstance] next];
[_playlistController playNextItem];
}
- (IBAction)random:(id)sender
{
[[VLCCoreInteraction sharedInstance] shuffle];
if (_playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM) {
_playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL;
} else {
_playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM;
}
}
- (IBAction)repeat:(id)sender
@ -819,7 +804,11 @@
- (IBAction)quitAfterPlayback:(id)sender
{
_playerController.actionAfterStop = VLC_PLAYER_MEDIA_STOPPED_EXIT;
if (_playerController.actionAfterStop != VLC_PLAYER_MEDIA_STOPPED_EXIT) {
_playerController.actionAfterStop = VLC_PLAYER_MEDIA_STOPPED_EXIT;
} else {
_playerController.actionAfterStop = VLC_PLAYER_MEDIA_STOPPED_CONTINUE;
}
}
- (IBAction)toggleRecord:(id)sender
@ -891,8 +880,8 @@
if (!p_aout)
return;
int n = aout_DevicesList(p_aout, &ids, &names);
if (n == -1) {
int numberOfAudioDevices = aout_DevicesList(p_aout, &ids, &names);
if (numberOfAudioDevices == -1) {
aout_Release(p_aout);
return;
}
@ -900,7 +889,7 @@
currentDevice = aout_DeviceGet(p_aout);
NSMenuItem *_tmp;
for (NSUInteger x = 0; x < n; x++) {
for (NSUInteger x = 0; x < numberOfAudioDevices; x++) {
_tmp = [_audioDeviceMenu addItemWithTitle:toNSStr(names[x]) action:@selector(toggleAudioDevice:) keyEquivalent:@""];
[_tmp setTarget:self];
[_tmp setTag:[[NSString stringWithFormat:@"%s", ids[x]] intValue]];
@ -911,7 +900,7 @@
free(currentDevice);
for (NSUInteger x = 0; x < n; x++) {
for (NSUInteger x = 0; x < numberOfAudioDevices; x++) {
free(ids[x]);
free(names[x]);
}
@ -1356,7 +1345,7 @@
#pragma mark - Dynamic menu creation and validation
- (void)setupVarMenuItem:(NSMenuItem *)mi
- (void)setupVarMenuItem:(NSMenuItem *)menuItem
target:(vlc_object_t *)p_object
var:(const char *)psz_variable
selector:(SEL)pf_callback
@ -1379,12 +1368,12 @@
/* Get the descriptive name of the variable */
var_Change(p_object, psz_variable, VLC_VAR_GETTEXT, &text);
[mi setTitle: _NS(text ? text : psz_variable)];
[menuItem setTitle: _NS(text ? text : psz_variable)];
if (i_type & VLC_VAR_HASCHOICE) {
NSMenu *menu = [mi submenu];
NSMenu *menu = [menuItem submenu];
[self setupVarMenu:menu forMenuItem:mi target:p_object
[self setupVarMenu:menu forMenuItem:menuItem target:p_object
var:psz_variable selector:pf_callback];
free(text);
@ -1399,15 +1388,15 @@
case VLC_VAR_VOID:
data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
andValue: val ofType: i_type];
[mi setRepresentedObject:data];
[menuItem setRepresentedObject:data];
break;
case VLC_VAR_BOOL:
data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
andValue: val ofType: i_type];
[mi setRepresentedObject:data];
[menuItem setRepresentedObject:data];
if (!(i_type & VLC_VAR_ISCOMMAND))
[mi setState: val.b_bool ? TRUE : FALSE ];
[menuItem setState: val.b_bool ? TRUE : FALSE ];
break;
default:

50
modules/gui/macosx/windows/mainwindow/VLCMainWindow.m

@ -86,50 +86,46 @@ static const float f_min_window_height = 307.;
#pragma mark -
#pragma mark Initialization
- (BOOL)isEvent:(NSEvent *)o_event forKey:(const char *)keyString
- (BOOL)isEvent:(NSEvent *)anEvent forKey:(const char *)keyString
{
char *key;
NSString *o_key;
key = config_GetPsz(keyString);
o_key = [NSString stringWithFormat:@"%s", key];
char *key = config_GetPsz(keyString);
unsigned int keyModifiers = VLCModifiersToCocoa(key);
NSString *vlcKeyString = VLCKeyToString(key);
FREENULL(key);
unsigned int i_keyModifiers = VLCModifiersToCocoa(o_key);
NSString * characters = [o_event charactersIgnoringModifiers];
NSString *characters = [anEvent charactersIgnoringModifiers];
if ([characters length] > 0) {
return [[characters lowercaseString] isEqualToString: VLCKeyToString(o_key)] &&
(i_keyModifiers & NSShiftKeyMask) == ([o_event modifierFlags] & NSShiftKeyMask) &&
(i_keyModifiers & NSControlKeyMask) == ([o_event modifierFlags] & NSControlKeyMask) &&
(i_keyModifiers & NSAlternateKeyMask) == ([o_event modifierFlags] & NSAlternateKeyMask) &&
(i_keyModifiers & NSCommandKeyMask) == ([o_event modifierFlags] & NSCommandKeyMask);
return [[characters lowercaseString] isEqualToString: vlcKeyString] &&
(keyModifiers & NSShiftKeyMask) == ([anEvent modifierFlags] & NSShiftKeyMask) &&
(keyModifiers & NSControlKeyMask) == ([anEvent modifierFlags] & NSControlKeyMask) &&
(keyModifiers & NSAlternateKeyMask) == ([anEvent modifierFlags] & NSAlternateKeyMask) &&
(keyModifiers & NSCommandKeyMask) == ([anEvent modifierFlags] & NSCommandKeyMask);
}
return NO;
}
- (BOOL)performKeyEquivalent:(NSEvent *)o_event
- (BOOL)performKeyEquivalent:(NSEvent *)anEvent
{
BOOL b_force = NO;
// these are key events which should be handled by vlc core, but are attached to a main menu item
if (![self isEvent: o_event forKey: "key-vol-up"] &&
![self isEvent: o_event forKey: "key-vol-down"] &&
![self isEvent: o_event forKey: "key-vol-mute"] &&
![self isEvent: o_event forKey: "key-prev"] &&
![self isEvent: o_event forKey: "key-next"] &&
![self isEvent: o_event forKey: "key-jump+short"] &&
![self isEvent: o_event forKey: "key-jump-short"]) {
if (![self isEvent: anEvent forKey: "key-vol-up"] &&
![self isEvent: anEvent forKey: "key-vol-down"] &&
![self isEvent: anEvent forKey: "key-vol-mute"] &&
![self isEvent: anEvent forKey: "key-prev"] &&
![self isEvent: anEvent forKey: "key-next"] &&
![self isEvent: anEvent forKey: "key-jump+short"] &&
![self isEvent: anEvent forKey: "key-jump-short"]) {
/* We indeed want to prioritize some Cocoa key equivalent against libvlc,
so we perform the menu equivalent now. */
if ([[NSApp mainMenu] performKeyEquivalent:o_event])
if ([[NSApp mainMenu] performKeyEquivalent:anEvent])
return TRUE;
}
else
} else {
b_force = YES;
}
VLCCoreInteraction *coreInteraction = [VLCCoreInteraction sharedInstance];
return [coreInteraction hasDefinedShortcutKey:o_event force:b_force] ||
[coreInteraction keyEvent:o_event];
return [coreInteraction hasDefinedShortcutKey:anEvent force:b_force] ||
[coreInteraction keyEvent:anEvent];
}
- (void)dealloc

Loading…
Cancel
Save