Skip to content

Commit b4cc82d

Browse files
Only paste when the cursor is an ibeam
Don't paste unless the cursor is an ibeam, aka is hovering over a text field. Should let the middle button work for eg browser links in new tab hopefully
1 parent a3a1ff5 commit b4cc82d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ help:
88
clean:
99
-rm -f macpaste
1010

11-
macpaste: macpaste.c
12-
gcc -O2 -framework ApplicationServices -o macpaste macpaste.c
11+
macpaste: macpaste.m
12+
gcc -O2 -framework AppKit -framework ApplicationServices -o macpaste macpaste.m
1313

1414
run:
1515
./macpaste

macpaste.c renamed to macpaste.m

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <ApplicationServices/ApplicationServices.h>
1818
#include <Carbon/Carbon.h> // kVK_ANSI_*
1919
#include <sys/time.h> // gettimeofday
20+
#include <AppKit/NSCursor.h>
2021

2122
char isDragging = 0;
2223
long long prevClickTime = 0;
@@ -25,7 +26,7 @@ long long curClickTime = 0;
2526
CGEventTapLocation tapA = kCGAnnotatedSessionEventTap;
2627
CGEventTapLocation tapH = kCGHIDEventTap;
2728

28-
#define DOUBLE_CLICK_MILLIS 500
29+
#define DOUBLE_CLICK_MILLIS 200
2930

3031
long long now() {
3132
struct timeval te;
@@ -99,7 +100,9 @@ static void paste(CGEventRef event) {
99100
{
100101
case kCGEventOtherMouseDown:
101102
button = CGEventGetIntegerValueField(event, kCGMouseEventButtonNumber);
102-
if (*dontpaste == 0 && button == 2)
103+
NSCursor* cursor = [NSCursor currentSystemCursor];
104+
NSCursor* ibeam = [NSCursor IBeamCursor];
105+
if (*dontpaste == 0 && button == 2 && NSEqualPoints([cursor hotSpot] , [ibeam hotSpot] ))
103106
paste( event );
104107
break;
105108

@@ -134,6 +137,7 @@ static void paste(CGEventRef event) {
134137
CFMachPortRef myEventTap;
135138
CFRunLoopSourceRef eventTapRLSrc;
136139

140+
137141
// parse args for -n flag
138142
int c;
139143
int dontpaste = 0;
@@ -152,6 +156,7 @@ static void paste(CGEventRef event) {
152156
CGEventMaskBit( kCGEventLeftMouseDown ) |
153157
CGEventMaskBit( kCGEventLeftMouseUp ) |
154158
CGEventMaskBit( kCGEventLeftMouseDragged );
159+
NSApplicationLoad();
155160

156161
// Create the Tap
157162
myEventTap = CGEventTapCreate (

0 commit comments

Comments
 (0)