Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FRAMEWORKS = -framework Cocoa -framework Carbon -framework CoreServices
FRAMEWORK_PATH = -F/System/Library/PrivateFrameworks
FRAMEWORKS = -framework Cocoa -framework Carbon -framework CoreServices -framework MultitouchSupport -framework CoreFoundation
BUILD_PATH = ./bin
BUILD_FLAGS = -std=c99 -Wall -g -O0
SKHD_SRC = ./src/skhd.c
Expand All @@ -16,4 +17,4 @@ clean:

$(BUILD_PATH)/skhd: $(SKHD_SRC)
mkdir -p $(BUILD_PATH)
clang $^ $(BUILD_FLAGS) $(FRAMEWORKS) -o $@
clang $^ $(BUILD_FLAGS) $(FRAMEWORK_PATH) $(FRAMEWORKS) -o $@
23 changes: 23 additions & 0 deletions src/hotkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@
#define Modifier_Keycode_Ctrl 0x3B
#define Modifier_Keycode_Fn 0x3F

#define Gesture_Keycode_Base 0x10000000
#define Gesture_TwoFingerSwipeLeft (Gesture_Keycode_Base + 1)
#define Gesture_TwoFingerSwipeRight (Gesture_Keycode_Base + 2)
#define Gesture_TwoFingerSwipeUp (Gesture_Keycode_Base + 3)
#define Gesture_TwoFingerSwipeDown (Gesture_Keycode_Base + 4)
#define Gesture_ThreeFingerSwipeLeft (Gesture_Keycode_Base + 5)
#define Gesture_ThreeFingerSwipeRight (Gesture_Keycode_Base + 6)
#define Gesture_ThreeFingerSwipeUp (Gesture_Keycode_Base + 7)
#define Gesture_ThreeFingerSwipeDown (Gesture_Keycode_Base + 8)
#define Gesture_ThreeFingerTap (Gesture_Keycode_Base + 9)
#define Gesture_FourFingerSwipeLeft (Gesture_Keycode_Base + 10)
#define Gesture_FourFingerSwipeRight (Gesture_Keycode_Base + 11)
#define Gesture_FourFingerSwipeUp (Gesture_Keycode_Base + 12)
#define Gesture_FourFingerSwipeDown (Gesture_Keycode_Base + 13)
#define Gesture_FiveFingerSwipeLeft (Gesture_Keycode_Base + 14)
#define Gesture_FiveFingerSwipeRight (Gesture_Keycode_Base + 15)
#define Gesture_FiveFingerSwipeUp (Gesture_Keycode_Base + 16)
#define Gesture_FiveFingerSwipeDown (Gesture_Keycode_Base + 17)
#define Gesture_FourFingerTap (Gesture_Keycode_Base + 18)
#define Gesture_FiveFingerTap (Gesture_Keycode_Base + 19)
#define Gesture_TwoFingerTap (Gesture_Keycode_Base + 20)

enum osx_event_mask
{
Event_Mask_Alt = 0x00080000,
Expand Down Expand Up @@ -105,6 +127,7 @@ unsigned long hash_hotkey(struct hotkey *a);

struct hotkey create_eventkey(CGEventRef event);
bool intercept_systemkey(CGEventRef event, struct hotkey *eventkey);
static uint32_t cgevent_flags_to_hotkey_flags(uint32_t eventflags);

bool find_and_exec_hotkey(struct hotkey *k, struct table *t, struct mode **m, struct carbon_event *carbon);
void free_mode_map(struct table *mode_map);
Expand Down
145 changes: 145 additions & 0 deletions src/multitouch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright (C) 2009 Fajran Iman Rusadi <fajran@gmail.com>

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#ifndef MULTITOUCH_H
#define MULTITOUCH_H

#ifdef __OBJC__
#include <Cocoa/Cocoa.h>
#endif
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
float x;
float y;
} MTPoint;

typedef struct {
MTPoint position;
MTPoint velocity;
} MTVector;

enum {
MTTouchStateNotTracking = 0,
MTTouchStateStartInRange = 1,
MTTouchStateHoverInRange = 2,
MTTouchStateMakeTouch = 3,
MTTouchStateTouching = 4,
MTTouchStateBreakTouch = 5,
MTTouchStateLingerInRange = 6,
MTTouchStateOutOfRange = 7
};
typedef uint32_t MTTouchState;

typedef struct {
int32_t frame;
double timestamp;
int32_t pathIndex; // "P" (~transducerIndex)
MTTouchState state;
int32_t fingerID; // "F" (~identity)
int32_t handID; // "H" (always 1)
MTVector normalizedVector;
float zTotal; // "ZTot" (~quality, multiple of 1/8 between 0 and 1)
int32_t field9; // always 0
float angle;
float majorAxis;
float minorAxis;
MTVector absoluteVector; // "mm"
int32_t field14; // always 0
int32_t field15; // always 0
float zDensity; // "ZDen" (~density)
} MTTouch;

typedef void* MTDeviceRef;

double MTAbsoluteTimeGetCurrent();
bool MTDeviceIsAvailable(); // true if can create default device

CFArrayRef MTDeviceCreateList(); // creates for driver types 0, 1, 4, 2, 3
MTDeviceRef MTDeviceCreateDefault();
MTDeviceRef MTDeviceCreateFromDeviceID(int64_t);
MTDeviceRef MTDeviceCreateFromService(io_service_t);
MTDeviceRef MTDeviceCreateFromGUID(uuid_t); // GUID's compared by pointer, not value!
void MTDeviceRelease(MTDeviceRef);

CFRunLoopSourceRef MTDeviceCreateMultitouchRunLoopSource(MTDeviceRef);
OSStatus MTDeviceScheduleOnRunLoop(MTDeviceRef, CFRunLoopRef, CFStringRef);

OSStatus MTDeviceStart(MTDeviceRef, int);
OSStatus MTDeviceStop(MTDeviceRef);
bool MTDeviceIsRunning(MTDeviceRef);

bool MTDeviceIsValid(MTDeviceRef);
bool MTDeviceIsBuiltIn(MTDeviceRef) __attribute__ ((weak_import)); // no 10.5
bool MTDeviceIsOpaqueSurface(MTDeviceRef);
io_service_t MTDeviceGetService(MTDeviceRef);
OSStatus MTDeviceGetSensorSurfaceDimensions(MTDeviceRef, int*, int*);
OSStatus MTDeviceGetFamilyID(MTDeviceRef, int*);
OSStatus MTDeviceGetDeviceID(MTDeviceRef, uint64_t*) __attribute__ ((weak_import)); // no 10.5
OSStatus MTDeviceGetDriverType(MTDeviceRef, int*);
OSStatus MTDeviceGetActualType(MTDeviceRef, int*);
OSStatus MTDeviceGetGUID(MTDeviceRef, uuid_t*);
void MTDeviceGetTransportMethod(MTDeviceRef, int *);

typedef void (*MTFrameCallbackFunction)(MTDeviceRef device,
MTTouch touches[], size_t numTouches,
double timestamp, size_t frame);
void MTRegisterContactFrameCallback(MTDeviceRef, MTFrameCallbackFunction);
void MTUnregisterContactFrameCallback(MTDeviceRef, MTFrameCallbackFunction);

typedef void (*MTPathCallbackFunction)(MTDeviceRef device, long pathID, long state, MTTouch* touch);
//MTPathCallbackFunction MTPathPrintCallback;
void MTRegisterPathCallback(MTDeviceRef, MTPathCallbackFunction);
void MTUnregisterPathCallback(MTDeviceRef, MTPathCallbackFunction);

/*
// callbacks never called (need different flags?)
typedef void (*MTImageCallbackFunction)(MTDeviceRef, void*, void*);
MTImageCallbackFunction MTImagePrintCallback;
void MTRegisterMultitouchImageCallback(MTDeviceRef, MTImageCallbackFunction);
*/

/*
// these log error
void MTVibratorRunForDuration(MTDeviceRef,long);
void MTVibratorStop(MTDeviceRef);
*/

inline const char*
MTTouchStateName(MTTouchState ps) {
switch (ps) {
case MTTouchStateNotTracking: return "NotTracking" ;
case MTTouchStateStartInRange: return "StartInRange" ;
case MTTouchStateHoverInRange: return "HoverInRange" ;
case MTTouchStateMakeTouch: return "MakeTouch" ;
case MTTouchStateTouching: return "Touching" ;
case MTTouchStateBreakTouch: return "BreakTouch" ;
case MTTouchStateLingerInRange: return "LingerInRange" ;
case MTTouchStateOutOfRange: return "OutOfRange" ;
default: return "Unknown" ;
}
}

#ifdef __cplusplus
}
#endif

#endif
22 changes: 18 additions & 4 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ parse_key(struct parser *parser)
}

#define KEY_HAS_IMPLICIT_FN_MOD 4
#define KEY_HAS_IMPLICIT_NX_MOD 35
#define KEY_NX_START 35
#define KEY_NX_END 47
static uint32_t literal_keycode_value[] =
{
kVK_Return, kVK_Tab, kVK_Space,
Expand All @@ -171,16 +172,29 @@ static uint32_t literal_keycode_value[] =
NX_KEYTYPE_SOUND_UP, NX_KEYTYPE_SOUND_DOWN, NX_KEYTYPE_MUTE,
NX_KEYTYPE_PLAY, NX_KEYTYPE_PREVIOUS, NX_KEYTYPE_NEXT,
NX_KEYTYPE_REWIND, NX_KEYTYPE_FAST, NX_KEYTYPE_BRIGHTNESS_UP,
NX_KEYTYPE_BRIGHTNESS_DOWN, NX_KEYTYPE_ILLUMINATION_UP, NX_KEYTYPE_ILLUMINATION_DOWN
NX_KEYTYPE_BRIGHTNESS_DOWN, NX_KEYTYPE_ILLUMINATION_UP, NX_KEYTYPE_ILLUMINATION_DOWN,

Gesture_TwoFingerSwipeLeft, Gesture_TwoFingerSwipeRight,
Gesture_TwoFingerSwipeUp, Gesture_TwoFingerSwipeDown,
Gesture_TwoFingerTap,
Gesture_ThreeFingerSwipeLeft, Gesture_ThreeFingerSwipeRight,
Gesture_ThreeFingerSwipeUp, Gesture_ThreeFingerSwipeDown,
Gesture_ThreeFingerTap,
Gesture_FourFingerSwipeLeft, Gesture_FourFingerSwipeRight,
Gesture_FourFingerSwipeUp, Gesture_FourFingerSwipeDown,
Gesture_FourFingerTap,
Gesture_FiveFingerSwipeLeft, Gesture_FiveFingerSwipeRight,
Gesture_FiveFingerSwipeUp, Gesture_FiveFingerSwipeDown,
Gesture_FiveFingerTap
};

static inline void
handle_implicit_literal_flags(struct hotkey *hotkey, int literal_index)
{
if ((literal_index > KEY_HAS_IMPLICIT_FN_MOD) &&
(literal_index < KEY_HAS_IMPLICIT_NX_MOD)) {
(literal_index < KEY_NX_START)) {
hotkey->flags |= Hotkey_Flag_Fn;
} else if (literal_index >= KEY_HAS_IMPLICIT_NX_MOD) {
} else if (literal_index >= KEY_NX_START && literal_index < KEY_NX_END) {
hotkey->flags |= Hotkey_Flag_NX;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/skhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "hotkey.h"
#include "synthesize.h"
#include "service.h"
#include "touch.h"

#include "hotload.c"
#include "event_tap.c"
Expand All @@ -38,6 +39,7 @@
#include "hotkey.c"
#include "synthesize.c"
#include "notify.c"
#include "touch.c"

extern void NSApplicationLoad(void);
extern CFDictionaryRef CGSCopyCurrentSessionDictionary(void);
Expand Down Expand Up @@ -514,6 +516,8 @@ int main(int argc, char **argv)
event_tap.mask = (1 << kCGEventKeyDown) | (1 << NX_SYSDEFINED);
event_tap_begin(&event_tap, key_handler);
END_SCOPED_TIMED_BLOCK();

touch_begin(&mode_map, &blacklst, &current_mode, &carbon);
END_SCOPED_TIMED_BLOCK();

NSApplicationLoad();
Expand Down
15 changes: 14 additions & 1 deletion src/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ static const char *literal_keycode_str[] =
"sound_up", "sound_down", "mute",
"play", "previous", "next",
"rewind", "fast", "brightness_up",
"brightness_down", "illumination_up", "illumination_down"
"brightness_down", "illumination_up", "illumination_down",

"two_finger_swipe_left", "two_finger_swipe_right",
"two_finger_swipe_up", "two_finger_swipe_down",
"two_finger_tap",
"three_finger_swipe_left", "three_finger_swipe_right",
"three_finger_swipe_up", "three_finger_swipe_down",
"three_finger_tap",
"four_finger_swipe_left", "four_finger_swipe_right",
"four_finger_swipe_up", "four_finger_swipe_down",
"four_finger_tap",
"five_finger_swipe_left", "five_finger_swipe_right",
"five_finger_swipe_up", "five_finger_swipe_down",
"five_finger_tap"
};

enum token_type
Expand Down
Loading