Skip to content

Commit

Permalink
support bluetooth HID pointing devices through BTC Mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
zydeco committed Dec 4, 2016
1 parent 81d985f commit 9f2e3f8
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Mini vMac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
283423EC1CFA329C0088B634 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
283423ED1CFA329C0088B634 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
283423EE1CFA329C0088B634 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
283CA9821DF47AF300B33D5E /* BTCMouse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BTCMouse.h; sourceTree = "<group>"; };
285A8C901D05AFD3002993DE /* PlugIn-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "PlugIn-Info.plist"; sourceTree = "<group>"; };
28848B601CDE97D600B86C45 /* InsertDiskViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InsertDiskViewController.h; sourceTree = "<group>"; };
28848B611CDE97D600B86C45 /* InsertDiskViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InsertDiskViewController.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -628,6 +629,7 @@
28F6B4511CF07C48002D76D0 /* UIImage+DiskImageIcon.m */,
28F6B4C91CF1FA7A002D76D0 /* about.plist */,
28F6B4CE1CF77099002D76D0 /* compat.m */,
283CA9821DF47AF300B33D5E /* BTCMouse.h */,
283422EF1CF8F33A0088B634 /* Emulator Bundles */,
);
path = "Mini vMac";
Expand Down
1 change: 1 addition & 0 deletions Mini vMac/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <UIKit/UIKit.h>
#import "EmulatorProtocol.h"
#import "BTCMouse.h"

extern NSString *DocumentsChangedNotification;

Expand Down
12 changes: 11 additions & 1 deletion Mini vMac/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
static NSObject<Emulator> *sharedEmulator = nil;
NSString *DocumentsChangedNotification = @"documentsChanged";

@interface AppDelegate () <UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning>
@interface AppDelegate () <UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning, BTCMouseDelegate>

@end

Expand All @@ -40,6 +40,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self initDefaults];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:NULL];
[sharedEmulator performSelector:@selector(run) withObject:nil afterDelay:0.1];

if ([application respondsToSelector:@selector(btcMouseSetRawMode:)]) {
[application btcMouseSetRawMode:YES];
[application btcMouseSetDelegate:self];
}
return YES;
}

Expand Down Expand Up @@ -109,6 +114,11 @@ - (void)applicationDidEnterBackground:(UIApplication *)application {
}
}

- (void)handleEventWithMove:(CGPoint)move andWheel:(float)wheel andPan:(float)pan andButtons:(int)buttons {
[sharedEmulator moveMouseX:move.x/2.0 Y:move.y/2.0];
[sharedEmulator setMouseButton:buttons == 1];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (sharedEmulator.running) {
Expand Down
20 changes: 20 additions & 0 deletions Mini vMac/BTCMouse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// BTCMouse.h
// Mini vMac
//
// Created by Jesús A. Álvarez on 04/12/2016.
// Copyright © 2016 namedfork. All rights reserved.
//


@protocol BTCMouseDelegate
- (void)handleEventWithMove:(CGPoint)move andWheel:(float)wheel andPan:(float)pan andButtons:(int)buttons;
@end

@interface UIApplication (BTCMouse)
- (void)btcMouseSetPanning:(BOOL)panning;
- (void)btcMouseSetZooming:(BOOL)zooming;
- (void)btcMouseSetDelegate:(id<BTCMouseDelegate>)delegate;
- (void)btcMouseSetRawMode:(BOOL)rawMode;
@end

3 changes: 3 additions & 0 deletions Mini vMac/InsertDiskViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ - (void)viewDidAppear:(BOOL)animated {
[nc addObserver:self selector:@selector(reloadData:) name:[AppDelegate sharedEmulator].insertDiskNotification object:nil];
[nc addObserver:self selector:@selector(reloadData:) name:[AppDelegate sharedEmulator].ejectDiskNotification object:nil];
[nc addObserver:self selector:@selector(reloadData:) name:DocumentsChangedNotification object:nil];
if ([UIApplication instancesRespondToSelector:@selector(btcMouseSetRawMode:)]) {
[[UIApplication sharedApplication] btcMouseSetRawMode:NO];
}
}

- (void)viewDidDisappear:(BOOL)animated {
Expand Down
3 changes: 3 additions & 0 deletions Mini vMac/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ - (void)loadCredits {
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[AppDelegate sharedEmulator].running = NO;
if ([UIApplication instancesRespondToSelector:@selector(btcMouseSetRawMode:)]) {
[[UIApplication sharedApplication] btcMouseSetRawMode:NO];
}
}

- (void)viewWillDisappear:(BOOL)animated {
Expand Down
3 changes: 3 additions & 0 deletions Mini vMac/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ - (void)setUpPointingDevice {
pointingDeviceView = [[pointingDeviceClass alloc] initWithFrame:self.view.bounds];
pointingDeviceView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:pointingDeviceView aboveSubview:self.screenView];
if ([UIApplication instancesRespondToSelector:@selector(btcMouseSetRawMode:)]) {
[[UIApplication sharedApplication] btcMouseSetRawMode:YES];
}
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
Expand Down

0 comments on commit 9f2e3f8

Please sign in to comment.