Skip to content

Commit

Permalink
Feat[controls]: add option to hide from screen recording
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Jun 7, 2024
1 parent 879f852 commit 299b03d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Natives/LauncherPreferencesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions Natives/PLPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion Natives/SurfaceViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ @interface SurfaceViewController ()<UITextFieldDelegate, UIPointerInteractionDel
@property(nonatomic) CGFloat screenScale;
@property(nonatomic) CGFloat mouseSpeed;
@property(nonatomic) CGRect clickRange;
@property(nonatomic) BOOL isMacCatalystApp, shouldTriggerClick, shouldTriggerHaptic, slideableHotbar, toggleHidden;
@property(nonatomic) BOOL isMacCatalystApp, shouldHideControlsFromRecording,
shouldTriggerClick, shouldTriggerHaptic, slideableHotbar, toggleHidden;

@property(nonatomic) BOOL enableMouseGestures, enableHotbarGestures;

Expand Down Expand Up @@ -338,6 +339,8 @@ - (void)updatePreferenceChanges {
virtualMouseFrame = CGRectMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2, 18.0 * mouseScale, 27 * mouseScale);
self.mousePointerView.frame = virtualMouseFrame;

self.shouldHideControlsFromRecording = getPrefFloat(@"control.recording_hide");
[self.ctrlView hideViewFromCapture:self.shouldHideControlsFromRecording];
self.ctrlView.frame = getSafeArea();

// Update gestures state
Expand Down
5 changes: 5 additions & 0 deletions Natives/customcontrols/ControlLayout.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#import <UIKit/UIKit.h>

@interface CALayer(private)
@property(atomic, assign) NSUInteger disableUpdateMask;
@end

@interface ControlLayout : UIView

@property(nonatomic) NSMutableDictionary *layoutDictionary;

- (void)loadControlLayout:(NSMutableDictionary *)layoutDictionary;
- (void)loadControlFile:(NSString *)path;
- (void)removeAllButtons;
- (void)hideViewFromCapture:(BOOL)hide;

@end
6 changes: 6 additions & 0 deletions Natives/customcontrols/ControlLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions Natives/resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 299b03d

Please sign in to comment.