Browse Source

macosx: add custom window close button

This is based on legacy code of the 3.0 branch
pull/100/head
Felix Paul Kühne 7 years ago
parent
commit
72e49c8ea3
  1. 6
      extras/package/macosx/VLC.xcodeproj/project.pbxproj
  2. 16
      modules/gui/macosx/Makefile.am
  3. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close-graphite.png
  4. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close-graphite@2x.png
  5. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close-on-graphite.png
  6. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close-on-graphite@2x.png
  7. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close-on.png
  8. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close-on@2x.png
  9. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close-over-graphite.png
  10. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close-over-graphite@2x.png
  11. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close-over.png
  12. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close-over@2x.png
  13. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close.png
  14. BIN
      modules/gui/macosx/Resources/Button-Icons/window-close@2x.png
  15. 56
      modules/gui/macosx/views/VLCCustomWindowButton.h
  16. 262
      modules/gui/macosx/views/VLCCustomWindowButton.m
  17. 2
      po/POTFILES.in

6
extras/package/macosx/VLC.xcodeproj/project.pbxproj

@ -120,6 +120,7 @@
7D445D8B22032B9200263D34 /* VLCPlaylistTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D445D8A22032B9200263D34 /* VLCPlaylistTableView.m */; };
7D445D8E2203375100263D34 /* VLCPlaylistMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D445D8D2203375100263D34 /* VLCPlaylistMenuController.m */; };
7D460B0C229EB4C700097948 /* VLCDragDropView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D460B0B229EB4C700097948 /* VLCDragDropView.m */; };
7D61DCE4236C1937008133CF /* VLCCustomWindowButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D61DCE3236C1937008133CF /* VLCCustomWindowButton.m */; };
7D66D4362200BC340040D04A /* VLCClickerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D66D4352200BC340040D04A /* VLCClickerManager.m */; };
7D66D4392200C5B80040D04A /* VLCVideoFilterHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D66D4382200C5B80040D04A /* VLCVideoFilterHelper.m */; };
7D66D43C2200D6090040D04A /* VLCDetachedVideoWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D66D43B2200D6090040D04A /* VLCDetachedVideoWindow.m */; };
@ -497,6 +498,8 @@
7D5678EC1D5BA1DC002698F3 /* VLCApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCApplication.m; sourceTree = "<group>"; };
7D5678EE1D5BA397002698F3 /* VLCMainWindowControlsBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCMainWindowControlsBar.h; sourceTree = "<group>"; };
7D5678EF1D5BA397002698F3 /* VLCMainWindowControlsBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCMainWindowControlsBar.m; sourceTree = "<group>"; };
7D61DCE2236C1937008133CF /* VLCCustomWindowButton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCCustomWindowButton.h; sourceTree = "<group>"; };
7D61DCE3236C1937008133CF /* VLCCustomWindowButton.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCCustomWindowButton.m; sourceTree = "<group>"; };
7D66D4342200BC340040D04A /* VLCClickerManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCClickerManager.h; sourceTree = "<group>"; };
7D66D4352200BC340040D04A /* VLCClickerManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCClickerManager.m; sourceTree = "<group>"; };
7D66D4372200C5B80040D04A /* VLCVideoFilterHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCVideoFilterHelper.h; sourceTree = "<group>"; };
@ -825,6 +828,8 @@
1C1ED5062204AB7C00811EC0 /* views */ = {
isa = PBXGroup;
children = (
7D61DCE2236C1937008133CF /* VLCCustomWindowButton.h */,
7D61DCE3236C1937008133CF /* VLCCustomWindowButton.m */,
6B0292E41F43256300A50082 /* VLCBottomBarView.h */,
6B0292E51F43256300A50082 /* VLCBottomBarView.m */,
6B6A499A1DFD9B23009128AC /* VLCDefaultValueSlider.h */,
@ -1658,6 +1663,7 @@
7D2554C522C8E8B500F2D9C2 /* VLCMediaSourceDeviceCollectionViewItem.m in Sources */,
1CCC88F52078A3D500E5626F /* SyncTracks.xib in Sources */,
1CCC88F62078A3D500E5626F /* VLCInformationWindow.xib in Sources */,
7D61DCE4236C1937008133CF /* VLCCustomWindowButton.m in Sources */,
7DFFF90123682D4800C8B0C9 /* VLCDetachedAudioWindow.m in Sources */,
7D66D4392200C5B80040D04A /* VLCVideoFilterHelper.m in Sources */,
7D445D812202524000263D34 /* VLCPlaylistController.m in Sources */,

16
modules/gui/macosx/Makefile.am

@ -173,6 +173,8 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/preferences/prefs_widgets.m \
gui/macosx/views/VLCBottomBarView.h \
gui/macosx/views/VLCBottomBarView.m \
gui/macosx/views/VLCCustomWindowButton.h \
gui/macosx/views/VLCCustomWindowButton.m \
gui/macosx/views/VLCDefaultValueSlider.h \
gui/macosx/views/VLCDefaultValueSlider.m \
gui/macosx/views/VLCDefaultValueSliderCell.h \
@ -456,7 +458,19 @@ libmacosx_plugin_la_RES = \
gui/macosx/Resources/Button-Icons/VLCVolumeOnTemplate.pdf \
gui/macosx/Resources/Button-Icons/VLCVolumeOffTemplate.pdf \
gui/macosx/Resources/Button-Icons/VLCClearLogTemplate.pdf \
gui/macosx/Resources/Button-Icons/VLCSaveTemplate.pdf
gui/macosx/Resources/Button-Icons/VLCSaveTemplate.pdf \
gui/macosx/Resources/Button-Icons/window-close-graphite.png \
gui/macosx/Resources/Button-Icons/window-close-graphite@2x.png \
gui/macosx/Resources/Button-Icons/window-close-on-graphite.png \
gui/macosx/Resources/Button-Icons/window-close-on-graphite@2x.png \
gui/macosx/Resources/Button-Icons/window-close-on.png \
gui/macosx/Resources/Button-Icons/window-close-on@2x.png \
gui/macosx/Resources/Button-Icons/window-close-over-graphite.png \
gui/macosx/Resources/Button-Icons/window-close-over-graphite@2x.png \
gui/macosx/Resources/Button-Icons/window-close-over.png \
gui/macosx/Resources/Button-Icons/window-close-over@2x.png \
gui/macosx/Resources/Button-Icons/window-close.png \
gui/macosx/Resources/Button-Icons/window-close@2x.png
libmacosx_plugin_la_RES += \
gui/macosx/Resources/dsa_pub.pem \

BIN
modules/gui/macosx/Resources/Button-Icons/window-close-graphite.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close-graphite@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close-on-graphite.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close-on-graphite@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close-on.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close-on@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close-over-graphite.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close-over-graphite@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close-over.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close-over@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

BIN
modules/gui/macosx/Resources/Button-Icons/window-close@2x.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

56
modules/gui/macosx/views/VLCCustomWindowButton.h

@ -0,0 +1,56 @@
/*****************************************************************************
* VLCCustomWindowButton.h: MacOS X interface module
*****************************************************************************
* Copyright (C) 2011-2019 VLC authors and VideoLAN
*
* Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
* David Fuhrmann <dfuhrmann at videolan dot org>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
@interface VLCWindowButtonCell : NSButtonCell
@end
@interface VLCCustomWindowButtonPrototype : NSButton
- (void)performDefaultButtonAction:(id)sender;
@end
@interface VLCCustomWindowCloseButton : VLCCustomWindowButtonPrototype
@end
@interface VLCCustomWindowMinimizeButton : VLCCustomWindowButtonPrototype
@end
@interface VLCCustomWindowZoomButton : VLCCustomWindowButtonPrototype
@end
@interface VLCCustomWindowFullscreenButton : VLCCustomWindowButtonPrototype
@end
NS_ASSUME_NONNULL_END

262
modules/gui/macosx/views/VLCCustomWindowButton.m

@ -0,0 +1,262 @@
/*****************************************************************************
* VLCCustomWindowButton.m: MacOS X interface module
*****************************************************************************
* Copyright (C) 2011-2019 VLC authors and VideoLAN
*
* Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
* David Fuhrmann <dfuhrmann at videolan dot org>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "VLCCustomWindowButton.h"
@interface VLCCustomWindowButtonPrototype()
@property (readwrite, retain) NSImage *buttonImage;
@property (readwrite, retain) NSImage *hoverButtonImage;
@property (readwrite, retain) NSImage *onClickButtonImage;
- (void)loadButtonIcons;
- (NSArray *)extendedAccessibilityAttributeNames:(NSArray *)theAttributeNames;
- (id)extendedAccessibilityAttributeValue:(NSString *)theAttributeName;
- (NSNumber *)extendedAccessibilityIsAttributeSettable:(NSString *)theAttributeName;
@end
@implementation VLCWindowButtonCell
- (NSArray *)accessibilityAttributeNames
{
NSArray *theAttributeNames = [super accessibilityAttributeNames];
id theControlView = [self controlView];
return ([theControlView respondsToSelector: @selector(extendedAccessibilityAttributeNames:)] ? [theControlView extendedAccessibilityAttributeNames: theAttributeNames] : theAttributeNames); // ask the cell's control view (i.e., the button) for additional attribute values
}
- (id)accessibilityAttributeValue:(NSString *)theAttributeName
{
id theControlView = [self controlView];
if ([theControlView respondsToSelector: @selector(extendedAccessibilityAttributeValue:)]) {
id theValue = [theControlView extendedAccessibilityAttributeValue: theAttributeName];
if (theValue) {
return theValue; // if this is an extended attribute value we added, return that -- otherwise, fall back to super's implementation
}
}
return [super accessibilityAttributeValue: theAttributeName];
}
- (BOOL)accessibilityIsAttributeSettable:(NSString *)theAttributeName
{
id theControlView = [self controlView];
if ([theControlView respondsToSelector: @selector(extendedAccessibilityIsAttributeSettable:)]) {
NSNumber *theValue = [theControlView extendedAccessibilityIsAttributeSettable: theAttributeName];
if (theValue)
return [theValue boolValue]; // same basic strategy we use in -accessibilityAttributeValue:
}
return [super accessibilityIsAttributeSettable: theAttributeName];
}
@end
@implementation VLCCustomWindowButtonPrototype
+ (Class)cellClass
{
return [VLCWindowButtonCell class];
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
[self commonInitializer];
}
return self;
}
- (instancetype)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self) {
[self commonInitializer];
}
return self;
}
- (void)commonInitializer
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(controlTintChanged:)
name:NSControlTintDidChangeNotification
object:nil];
[self loadButtonIcons];
[self setTarget:self];
[self setAction:@selector(performDefaultButtonAction:)];
}
- (NSImage *)getButtonImage:(NSString *)imageName
{
if ([NSColor currentControlTint] != NSBlueControlTint) {
imageName = [imageName stringByAppendingString:@"-graphite"];
}
return [NSImage imageNamed:imageName];
}
- (void)controlTintChanged:(NSNotification *)notification
{
[self loadButtonIcons];
[self setNeedsDisplay];
}
- (void)loadButtonIcons
{
[self setImage:self.buttonImage];
[self setAlternateImage:self.hoverButtonImage];
}
- (void)mouseEntered:(NSEvent *)event
{
[self setImage:self.hoverButtonImage];
[super mouseEntered:event];
}
- (void)mouseExited:(NSEvent *)event
{
[self setImage:self.buttonImage];
[super mouseExited:event];
}
- (void)performDefaultButtonAction:(id)sender
{
}
- (NSArray *)extendedAccessibilityAttributeNames:(NSArray *)theAttributeNames {
return ([theAttributeNames containsObject: NSAccessibilitySubroleAttribute] ? theAttributeNames : [theAttributeNames arrayByAddingObject: NSAccessibilitySubroleAttribute]); // run-of-the-mill button cells don't usually have a Subrole attribute, so we add that attribute
}
- (id)extendedAccessibilityAttributeValue:(NSString *)theAttributeName {
return nil;
}
- (NSNumber *)extendedAccessibilityIsAttributeSettable:(NSString *)theAttributeName {
return ([theAttributeName isEqualToString: NSAccessibilitySubroleAttribute] ? [NSNumber numberWithBool:NO] : nil); // make the Subrole attribute we added non-settable
}
- (void)accessibilityPerformAction:(NSString *)theActionName {
if ([theActionName isEqualToString: NSAccessibilityPressAction]) {
if ([self isEnabled])
[self performClick: nil];
} else
[super accessibilityPerformAction: theActionName];
}
@end
@implementation VLCCustomWindowCloseButton
- (id)extendedAccessibilityAttributeValue:(NSString *)theAttributeName
{
return ([theAttributeName isEqualToString: NSAccessibilitySubroleAttribute] ? NSAccessibilityCloseButtonAttribute : nil);
}
- (void)loadButtonIcons
{
self.buttonImage = [self getButtonImage:@"window-close"];
self.hoverButtonImage = [self getButtonImage:@"window-close-over"];
self.onClickButtonImage = [self getButtonImage:@"window-close-on"];
[super loadButtonIcons];
}
- (void)performDefaultButtonAction:(id)sender
{
if (self.window.styleMask & NSWindowStyleMaskClosable) {
[[self window] performClose:sender];
} else {
[[self window] close];
}
}
@end
@implementation VLCCustomWindowMinimizeButton
- (id)extendedAccessibilityAttributeValue:(NSString *)theAttributeName
{
return ([theAttributeName isEqualToString: NSAccessibilitySubroleAttribute] ? NSAccessibilityMinimizeButtonAttribute : nil);
}
- (void)loadButtonIcons
{
self.buttonImage = [self getButtonImage:@"window-minimize"];
self.hoverButtonImage = [self getButtonImage:@"window-minimize-over"];
self.onClickButtonImage = [self getButtonImage:@"window-minimize-on"];
[super loadButtonIcons];
}
- (void)performDefaultButtonAction:(id)sender
{
[[self window] miniaturize: sender];
}
@end
@implementation VLCCustomWindowZoomButton
- (id)extendedAccessibilityAttributeValue:(NSString *)theAttributeName
{
return ([theAttributeName isEqualToString: NSAccessibilitySubroleAttribute] ? NSAccessibilityZoomButtonAttribute : nil);
}
- (void)loadButtonIcons
{
self.buttonImage = [self getButtonImage:@"window-zoom"];
self.hoverButtonImage = [self getButtonImage:@"window-zoom-over"];
self.onClickButtonImage = [self getButtonImage:@"window-zoom-on"];
[super loadButtonIcons];
}
- (void)performDefaultButtonAction:(id)sender
{
[[self window] performZoom: sender];
}
@end
@implementation VLCCustomWindowFullscreenButton
- (id)extendedAccessibilityAttributeValue:(NSString *)theAttributeName
{
return ([theAttributeName isEqualToString: NSAccessibilitySubroleAttribute] ? NSAccessibilityFullScreenButtonAttribute : nil);
}
- (void)loadButtonIcons
{
self.buttonImage = [self getButtonImage:@"window-fullscreen"];
self.hoverButtonImage = [self getButtonImage:@"window-fullscreen-over"];
self.onClickButtonImage = [self getButtonImage:@"window-fullscreen-on"];
[super loadButtonIcons];
}
- (void)performDefaultButtonAction:(id)sender
{
[[self window] toggleFullScreen:self];
}
@end

2
po/POTFILES.in

@ -578,6 +578,8 @@ modules/gui/macosx/preferences/prefs_widgets.h
modules/gui/macosx/preferences/prefs_widgets.m
modules/gui/macosx/views/VLCBottomBarView.h
modules/gui/macosx/views/VLCBottomBarView.m
modules/gui/macosx/views/VLCCustomWindowButton.h
modules/gui/macosx/views/VLCCustomWindowButton.m
modules/gui/macosx/views/VLCDefaultValueSlider.h
modules/gui/macosx/views/VLCDefaultValueSlider.m
modules/gui/macosx/views/VLCDefaultValueSliderCell.h

Loading…
Cancel
Save