From aefc897d8538a7172adf1361b1c61a63a2ac5df6 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 22 Feb 2023 13:39:47 +0100 Subject: [PATCH] macosx: Add VLCFullVideoViewWindow class Signed-off-by: Claudio Cambra --- .../macosx/VLC.xcodeproj/project.pbxproj | 6 + modules/gui/macosx/Makefile.am | 2 + .../windows/video/VLCFullVideoViewWindow.h | 39 +++++++ .../windows/video/VLCFullVideoViewWindow.m | 106 ++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 modules/gui/macosx/windows/video/VLCFullVideoViewWindow.h create mode 100644 modules/gui/macosx/windows/video/VLCFullVideoViewWindow.m diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj index 342273912c..52cce93557 100644 --- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj +++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj @@ -94,6 +94,7 @@ 53628403291147C500640C15 /* VLCSubScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 53628400291147C500640C15 /* VLCSubScrollView.m */; }; 536EFBF5295BCB8300F4CB13 /* VLCLibraryUIUnits.m in Sources */ = {isa = PBXBuildFile; fileRef = 536EFBF4295BCB8300F4CB13 /* VLCLibraryUIUnits.m */; }; 536EFC39295E521600F4CB13 /* VLCLibraryVideoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 536EFC38295E521600F4CB13 /* VLCLibraryVideoViewController.m */; }; + 538A7EDA29A63EE40068AD4F /* VLCFullVideoViewWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 538A7ED929A63EE40068AD4F /* VLCFullVideoViewWindow.m */; }; 53903D3A29576ED500D0B308 /* VLCLibraryAudioGroupDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 53903D3929576ED500D0B308 /* VLCLibraryAudioGroupDataSource.m */; }; 539BA79F298C726200918C36 /* VLCAspectRatioRetainingVideoWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 539BA79E298C726200918C36 /* VLCAspectRatioRetainingVideoWindow.m */; }; 53B447CA2939823E00857588 /* VLCLibrarySongsTableViewSongPlayingTableCellView.m in Sources */ = {isa = PBXBuildFile; fileRef = 53B447C92939823E00857588 /* VLCLibrarySongsTableViewSongPlayingTableCellView.m */; }; @@ -285,6 +286,8 @@ 536EFC37295E521600F4CB13 /* VLCLibraryVideoViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryVideoViewController.h; sourceTree = ""; }; 536EFC38295E521600F4CB13 /* VLCLibraryVideoViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryVideoViewController.m; sourceTree = ""; }; 536EFC3A295F828000F4CB13 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 538A7ED829A63EE40068AD4F /* VLCFullVideoViewWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCFullVideoViewWindow.h; sourceTree = ""; }; + 538A7ED929A63EE40068AD4F /* VLCFullVideoViewWindow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCFullVideoViewWindow.m; sourceTree = ""; }; 53903D3829576ED500D0B308 /* VLCLibraryAudioGroupDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryAudioGroupDataSource.h; sourceTree = ""; }; 53903D3929576ED500D0B308 /* VLCLibraryAudioGroupDataSource.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryAudioGroupDataSource.m; sourceTree = ""; }; 539BA79D298C726200918C36 /* VLCAspectRatioRetainingVideoWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCAspectRatioRetainingVideoWindow.h; sourceTree = ""; }; @@ -920,6 +923,8 @@ 7D2E0ED920CD204D0033A221 /* VLCWindow.m */, 539BA79D298C726200918C36 /* VLCAspectRatioRetainingVideoWindow.h */, 539BA79E298C726200918C36 /* VLCAspectRatioRetainingVideoWindow.m */, + 538A7ED829A63EE40068AD4F /* VLCFullVideoViewWindow.h */, + 538A7ED929A63EE40068AD4F /* VLCFullVideoViewWindow.m */, ); path = video; sourceTree = ""; @@ -1988,6 +1993,7 @@ 7DFBDCC4226E445500B700A5 /* VLCMediaSourceBaseDataSource.m in Sources */, 6B2EFC601F2819F700F3C0EA /* VLCVolumeSlider.m in Sources */, 7DE2F0472282D5D10040DD0A /* VLCLibraryTableCellView.m in Sources */, + 538A7EDA29A63EE40068AD4F /* VLCFullVideoViewWindow.m in Sources */, 7D2E0EDB20CD204D0033A221 /* VLCWindow.m in Sources */, 6B4D50A71E7AB52C004479B5 /* NSScreen+VLCAdditions.m in Sources */, 1C3113DD1E508C6900D4DD76 /* VLCTrackSynchronizationWindowController.m in Sources */, diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am index 09787a6d7b..668d8595a9 100644 --- a/modules/gui/macosx/Makefile.am +++ b/modules/gui/macosx/Makefile.am @@ -339,6 +339,8 @@ libmacosx_plugin_la_SOURCES = \ gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m \ gui/macosx/windows/video/VLCAspectRatioRetainingVideoWindow.h \ gui/macosx/windows/video/VLCAspectRatioRetainingVideoWindow.m \ + gui/macosx/windows/video/VLCFullVideoViewWindow.h \ + gui/macosx/windows/video/VLCFullVideoViewWindow.m \ gui/macosx/windows/video/VLCMainVideoViewController.h \ gui/macosx/windows/video/VLCMainVideoViewController.m \ gui/macosx/windows/video/VLCVideoOutputProvider.h \ diff --git a/modules/gui/macosx/windows/video/VLCFullVideoViewWindow.h b/modules/gui/macosx/windows/video/VLCFullVideoViewWindow.h new file mode 100644 index 0000000000..2dd3f7971b --- /dev/null +++ b/modules/gui/macosx/windows/video/VLCFullVideoViewWindow.h @@ -0,0 +1,39 @@ +/***************************************************************************** + * VLCFullVideoViewWindow: MacOS X interface module + ***************************************************************************** + * Copyright (C) 2023 VLC authors and VideoLAN + * + * Authors: Claudio Cambra + * + * 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 "VLCVideoWindowCommon.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface VLCFullVideoViewWindow : VLCVideoWindowCommon + +- (void)stopTitlebarAutohideTimer; +- (void)startTitlebarAutohideTimer; +- (void)showTitleBar; + +- (void)hideTitleBar:(id)sender; +- (void)enableVideoTitleBarMode; +- (void)disableVideoTitleBarMode; + +@end + +NS_ASSUME_NONNULL_END diff --git a/modules/gui/macosx/windows/video/VLCFullVideoViewWindow.m b/modules/gui/macosx/windows/video/VLCFullVideoViewWindow.m new file mode 100644 index 0000000000..8bbe24a99a --- /dev/null +++ b/modules/gui/macosx/windows/video/VLCFullVideoViewWindow.m @@ -0,0 +1,106 @@ +/***************************************************************************** + * VLCFullVideoViewWindow.m: MacOS X interface module + ***************************************************************************** + * Copyright (C) 2023 VLC authors and VideoLAN + * + * Authors: Claudio Cambra + * + * 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 "VLCFullVideoViewWindow.h" + +#import "main/VLCMain.h" + +@interface VLCFullVideoViewWindow () +{ + BOOL _autohideTitlebar; + NSTimer *_hideTitlebarTimer; +} +@end + +@implementation VLCFullVideoViewWindow + +- (void)awakeFromNib +{ + [super awakeFromNib]; + _autohideTitlebar = NO; +} + +- (void)stopTitlebarAutohideTimer +{ + [_hideTitlebarTimer invalidate]; +} + +- (void)startTitlebarAutohideTimer +{ + /* Do nothing if timer is already in place */ + if (_hideTitlebarTimer.valid) { + return; + } + + /* Get timeout and make sure it is not lower than 1 second */ + long long timeToKeepVisibleInSec = MAX(var_CreateGetInteger(getIntf(), "mouse-hide-timeout") / 1000, 1); + + _hideTitlebarTimer = [NSTimer scheduledTimerWithTimeInterval:timeToKeepVisibleInSec + target:self + selector:@selector(hideTitleBar:) + userInfo:nil + repeats:NO]; +} + +- (void)showTitleBar +{ + [self stopTitlebarAutohideTimer]; + + NSView *titlebarView = [self standardWindowButton:NSWindowCloseButton].superview; + if (!titlebarView.hidden && !_autohideTitlebar) { + return; + } + + titlebarView.hidden = NO; + + if (_autohideTitlebar) { + [self startTitlebarAutohideTimer]; + } +} + +- (void)hideTitleBar:(id)sender +{ + [self stopTitlebarAutohideTimer]; + [self standardWindowButton:NSWindowCloseButton].superview.hidden = YES; +} + +- (void)enableVideoTitleBarMode +{ + self.toolbar.visible = NO; + self.styleMask |= NSWindowStyleMaskFullSizeContentView; + self.titlebarAppearsTransparent = YES; + + _autohideTitlebar = YES; + [self showTitleBar]; +} + +- (void)disableVideoTitleBarMode +{ + self.toolbar.visible = YES; + self.styleMask &= ~NSWindowStyleMaskFullSizeContentView; + self.titlebarAppearsTransparent = NO; + + _autohideTitlebar = NO; + [self showTitleBar]; +} + +@end