]> git.sesse.net Git - vlc/blob - modules/gui/macosx/AppleRemote.h
macosx: store counting mode of the time field (default is to count up)
[vlc] / modules / gui / macosx / AppleRemote.h
1 /*****************************************************************************
2  * AppleRemote.h
3  * AppleRemote
4  * $Id$
5  *
6  * Created by Martin Kahr on 11.03.06 under a MIT-style license.
7  * Copyright (c) 2006 martinkahr.com. All rights reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  *
27  *****************************************************************************
28  *
29  * Note that changes made by any members or contributors of the VideoLAN team
30  * (i.e. changes that were checked in exclusively into one of VideoLAN's source code
31  * repositories) are licensed under the GNU General Public License version 2,
32  * or (at your option) any later version.
33  * Thus, the following statements apply to our changes:
34  *
35  * Copyright (C) 2006-2007 the VideoLAN team
36  * Authors: Eric Petit <titer@m0k.org>
37  *          Felix Kühne <fkuehne at videolan dot org>
38  *
39  * This program is free software; you can redistribute it and/or modify
40  * it under the terms of the GNU General Public License as published by
41  * the Free Software Foundation; either version 2 of the License, or
42  * (at your option) any later version.
43  *
44  * This program is distributed in the hope that it will be useful,
45  * but WITHOUT ANY WARRANTY; without even the implied warranty of
46  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47  * GNU General Public License for more details.
48  *
49  * You should have received a copy of the GNU General Public License
50  * along with this program; if not, write to the Free Software
51  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
52  *****************************************************************************/
53
54 #import <Cocoa/Cocoa.h>
55 #import <mach/mach.h>
56 #import <mach/mach_error.h>
57 #import <IOKit/IOKitLib.h>
58 #import <IOKit/IOCFPlugIn.h>
59 #import <IOKit/hid/IOHIDLib.h>
60 #import <IOKit/hid/IOHIDKeys.h>
61
62 enum AppleRemoteEventIdentifier
63 {
64     kRemoteButtonVolume_Plus        =1<<1,
65     kRemoteButtonVolume_Minus       =1<<2,
66     kRemoteButtonMenu               =1<<3,
67     kRemoteButtonPlay               =1<<4,
68     kRemoteButtonRight              =1<<5,
69     kRemoteButtonLeft               =1<<6,
70     kRemoteButtonRight_Hold         =1<<7,
71     kRemoteButtonLeft_Hold          =1<<8,
72     kRemoteButtonMenu_Hold          =1<<9,
73     kRemoteButtonPlay_Sleep         =1<<10,
74     kRemoteControl_Switched         =1<<11,
75     kRemoteButtonVolume_Plus_Hold   =1<<12,
76     kRemoteButtonVolume_Minus_Hold  =1<<13,
77     k2009RemoteButtonPlay                       =1<<14,
78     k2009RemoteButtonFullscreen         =1<<15
79 };
80 typedef enum AppleRemoteEventIdentifier AppleRemoteEventIdentifier;
81
82 /*  Encapsulates usage of the apple remote control
83 This class is implemented as a singleton as there is exactly one remote per machine (until now)
84 The class is not thread safe
85 */
86 @interface AppleRemote : NSObject {
87     IOHIDDeviceInterface** hidDeviceInterface;
88     IOHIDQueueInterface**  queue;
89     NSMutableArray*        allCookies;
90     NSMutableDictionary*   cookieToButtonMapping;
91     CFRunLoopSourceRef     eventSource;
92
93     BOOL openInExclusiveMode;
94     BOOL simulatePlusMinusHold;
95     BOOL processesBacklog;
96
97     /* state for simulating plus/minus hold */
98     BOOL lastEventSimulatedHold;
99     AppleRemoteEventIdentifier lastPlusMinusEvent;
100     NSTimeInterval lastPlusMinusEventTime;
101
102     int remoteId;
103     unsigned int clickCountEnabledButtons;
104     NSTimeInterval maxClickTimeDifference;
105     NSTimeInterval lastClickCountEventTime;
106     AppleRemoteEventIdentifier lastClickCountEvent;
107     unsigned int eventClickCount;
108
109     IBOutlet id delegate;
110 }
111 + (AppleRemote *)sharedInstance;
112
113 - (int) remoteId;
114
115 - (BOOL) isRemoteAvailable;
116
117 - (BOOL) isListeningToRemote;
118 - (void) setListeningToRemote: (BOOL) value;
119
120 - (BOOL) isOpenInExclusiveMode;
121 - (void) setOpenInExclusiveMode: (BOOL) value;
122
123 /* click counting makes it possible to recognize if the user has pressed a button repeatedly
124  * click counting does delay each event as it has to wait if there is another event (second click)
125  * therefore there is a slight time difference (maximumClickCountTimeDifference) between a single click
126  * of the user and the call of your delegate method
127  * click counting can be enabled individually for specific buttons. Use the property clickCountEnableButtons
128  * to set the buttons for which click counting shall be enabled */
129 - (BOOL) clickCountingEnabled;
130 - (void) setClickCountingEnabled: (BOOL) value;
131
132 - (unsigned int) clickCountEnabledButtons;
133 - (void) setClickCountEnabledButtons: (unsigned int)value;
134
135 /* the maximum time difference till which clicks are recognized as multi clicks */
136 - (NSTimeInterval) maximumClickCountTimeDifference;
137 - (void) setMaximumClickCountTimeDifference: (NSTimeInterval) timeDiff;
138
139 /* When your application needs to much time on the main thread when processing an event other events
140  * may already be received which are put on a backlog. As soon as your main thread
141  * has some spare time this backlog is processed and may flood your delegate with calls.
142  * Backlog processing is turned off by default. */
143 - (BOOL) processesBacklog;
144 - (void) setProcessesBacklog: (BOOL) value;
145
146 /* Sets an NSApplication delegate which starts listening when application is becoming active
147  * and stops listening when application resigns being active.
148  * If an NSApplication delegate has been already set all method calls will be forwarded to this delegate, too. */
149 - (BOOL) listeningOnAppActivate;
150 - (void) setListeningOnAppActivate: (BOOL) value;
151
152 /* Simulating plus/minus hold does deactivate sending of individual requests for plus/minus pressed down/released.
153  * Instead special hold events are being triggered when the user is pressing and holding plus/minus for a small period.
154  * With simulating enabled the plus/minus buttons do behave as the left/right buttons */
155 - (BOOL) simulatesPlusMinusHold;
156 - (void) setSimulatesPlusMinusHold: (BOOL) value;
157
158 /* Delegates are not retained */
159 - (void) setDelegate: (id) delegate;
160 - (id) delegate;
161
162 - (IBAction) startListening: (id) sender;
163 - (IBAction) stopListening: (id) sender;
164 @end
165
166 @interface AppleRemote (Singleton)
167
168 + (AppleRemote*) sharedRemote;
169
170 @end
171
172 /*  Method definitions for the delegate of the AppleRemote class */
173 @interface NSObject(NSAppleRemoteDelegate)
174
175 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier pressedDown: (BOOL) pressedDown clickCount: (unsigned int) count;
176
177 @end
178
179 @interface AppleRemote (PrivateMethods)
180 - (void) setRemoteId: (int) aValue;
181 - (NSDictionary*) cookieToButtonMapping;
182 - (IOHIDQueueInterface**) queue;
183 - (IOHIDDeviceInterface**) hidDeviceInterface;
184 - (void) handleEventWithCookieString: (NSString*) cookieString sumOfValues: (SInt32) sumOfValues;
185 @end
186
187 @interface AppleRemote (IOKitMethods)
188 - (io_object_t) findAppleRemoteDevice;
189 - (IOHIDDeviceInterface**) createInterfaceForDevice: (io_object_t) hidDevice;
190 - (BOOL) initializeCookies;
191 - (BOOL) openDevice;
192 @end
193
194 /* A NSApplication delegate which is used to activate and deactivate listening to the remote control
195  * dependent on the activation state of your application.
196  * All events are delegated to the original NSApplication delegate if necessary */
197 @interface AppleRemoteApplicationDelegate : NSObject {
198     id applicationDelegate;
199 }
200
201 - (id) initWithApplicationDelegate: (id) delegate;
202 - (id) applicationDelegate;
203 @end