Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pkamb committed Aug 23, 2013
1 parent b269841 commit bc27d7d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
2 changes: 0 additions & 2 deletions PowerKey/OpenAtLogin.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*/

//https://github.com/pkamb/OpenAtLogin

#import <Cocoa/Cocoa.h>

@interface OpenAtLogin : NSObject {
Expand Down
2 changes: 0 additions & 2 deletions PowerKey/OpenAtLogin.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ of this software and associated documentation files (the "Software"), to deal
*/

//https://github.com/pkamb/OpenAtLogin

#import "OpenAtLogin.h"

@implementation OpenAtLogin (PrivateMethods)
Expand Down
14 changes: 6 additions & 8 deletions PowerKey/PKPowerKeyEventListener.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ - (id)init

- (void)monitorPowerKey
{
CFRunLoopSourceRef runLoopSource;
CGEventMask eventTypeMask = NSSystemDefined;

/*
The power key sends two events of type NSSystemDefined.
We'd idealy monitor *only* NSSystemDefined events.
But there are various bugs with certain other applications if we do.
Therefore, we need to grab other events as well.
*/

CGEventMask eventTypeMask = 0;
for (NSEventType type = NSLeftMouseDown; type < NSEventTypeGesture; ++type) {
switch (type) {
case NSKeyDown:
Expand All @@ -68,7 +67,7 @@ - (void)monitorPowerKey
exit(YES);
}

runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);

CGEventTapEnable(eventTap, true);
Expand All @@ -80,7 +79,6 @@ CGEventRef copyEventTapCallBack(CGEventTapProxy proxy, CGEventType type, CGEvent
{
switch (type) {
case kCGEventTapDisabledByTimeout:
// Re-enable the event tap if it times out.
CGEventTapEnable(eventTap, true);
break;
case NSSystemDefined:
Expand All @@ -99,7 +97,7 @@ - (CGEventRef)newPowerKeyEventOrUnmodifiedSystemDefinedEvent:(CGEventRef)systemE
NSInteger eventData1 = [event data1];
NSUInteger modifierKeys = [event modifierFlags] & NSDeviceIndependentModifierFlagsMask;

//http://weblog.rogueamoeba.com/2007/09/29/
// http://weblog.rogueamoeba.com/2007/09/29/
int keyCode = (([event data1] & 0xFFFF0000) >> 16);
int keyFlags = ([event data1] & 0x0000FFFF);
int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
Expand All @@ -115,7 +113,7 @@ The second power event (keyCode == NX_POWER_KEY), by itself, does not seem to pr
IMPORTANT: Even if these events are prevented, the system WILL still turn off when the power key is held down for a few seconds!
*/

//First Power key event
// First Power key event
if (type == NSSystemDefined &&
subtype == 1 &&
eventData1 == 0 &&
Expand All @@ -129,7 +127,7 @@ The second power event (keyCode == NX_POWER_KEY), by itself, does not seem to pr
systemEvent = [self newPowerKeyReplacementEvent];
}

//Second Power key event
// Second Power key event
if (type == NSSystemDefined &&
subtype == 8 &&
eventData1 == 395776 &&
Expand Down
4 changes: 2 additions & 2 deletions PowerKey/PKPreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ - (IBAction)selectPowerKeyReplacement:(id)sender
}

/*
User can select one of the following power key replacements
Save the keycode of the replacement key as the NSMenuItem's tag
User can select one of the following power key replacements.
Set the keycode of the replacement key as the NSMenuItem's tag.
Keycodes come from 'Events.h'
*/
- (NSMenu *)powerKeyReplacementsMenu
Expand Down

0 comments on commit bc27d7d

Please sign in to comment.