diff --git a/Natives/LauncherPreferencesViewController.m b/Natives/LauncherPreferencesViewController.m index d47f22bed6..311d122d7d 100644 --- a/Natives/LauncherPreferencesViewController.m +++ b/Natives/LauncherPreferencesViewController.m @@ -222,6 +222,11 @@ - (void)viewDidLoad @"hasDetail": @YES, @"type": self.typeSwitch, }, + @{@"key": @"recording_hide", + @"icon": @"eye.slash", + @"hasDetail": @YES, + @"type": self.typeSwitch, + }, @{@"key": @"gesture_mouse", @"icon": @"cursorarrow.click", @"hasDetail": @YES, diff --git a/Natives/PLPreferences.m b/Natives/PLPreferences.m index bb4f2a1b39..f2e715d80a 100644 --- a/Natives/PLPreferences.m +++ b/Natives/PLPreferences.m @@ -31,6 +31,7 @@ + (id)defaultPrefForGlobal:(BOOL)global { @"default_gamepad_ctrl": @"default.json", @"controller_type": @"xbox", @"hardware_hide": @YES, + @"recording_hide": @YES, @"gesture_mouse": @YES, @"gesture_hotbar": @YES, @"disable_haptics": @NO, diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index 1fc2405c43..37f204f323 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -50,7 +50,8 @@ @interface SurfaceViewController () +@interface CALayer(private) +@property(atomic, assign) NSUInteger disableUpdateMask; +@end + @interface ControlLayout : UIView @property(nonatomic) NSMutableDictionary *layoutDictionary; @@ -7,5 +11,6 @@ - (void)loadControlLayout:(NSMutableDictionary *)layoutDictionary; - (void)loadControlFile:(NSString *)path; - (void)removeAllButtons; +- (void)hideViewFromCapture:(BOOL)hide; @end diff --git a/Natives/customcontrols/ControlLayout.m b/Natives/customcontrols/ControlLayout.m index 661545b50d..0559fb7f9a 100644 --- a/Natives/customcontrols/ControlLayout.m +++ b/Natives/customcontrols/ControlLayout.m @@ -80,4 +80,10 @@ - (void)setFrame:(CGRect)frame { self.layoutDictionary[@"scaledAt"] = @(savedScale); } +// https://nsantoine.dev/posts/CALayerCaptureHiding +- (void)hideViewFromCapture:(BOOL)hide { + NSUInteger hideFlag = (1 << 1) | (1 << 4); + self.layer.disableUpdateMask = hide ? hideFlag : 0; +} + @end diff --git a/Natives/resources/en.lproj/Localizable.strings b/Natives/resources/en.lproj/Localizable.strings index c7f45b35cd..e1c54ba135 100644 --- a/Natives/resources/en.lproj/Localizable.strings +++ b/Natives/resources/en.lproj/Localizable.strings @@ -198,6 +198,8 @@ "preference.title.default_gamepad_ctrl" = "Controller configuration"; "preference.title.hardware_hide" = "Hide controls when hardware is connected"; "preference.detail.hardware_hide" = "Enable the behaviour of automatically disabling the on-screen control overlay when a mouse or game controller is connected."; +"preference.title.recording_hide" = "Hide controls from screen recording"; +"preference.detail.recording_hide" = "Hides controls from screenshot and screen recording while they remain visible on the screen."; "preference.title.gesture_mouse" = "Mouse gestures"; "preference.detail.gesture_mouse" = "Enables gestures, such as tap to place block, hold to break block, scrolling with 2 fingers"; "preference.title.gesture_hotbar" = "Hotbar gestures";