dsh-gufa-code 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,10 +12,15 @@
|
|
|
12
12
|
#import <AppKit/AppKit.h>
|
|
13
13
|
#import <WebKit/WebKit.h>
|
|
14
14
|
#import <CoreGraphics/CoreGraphics.h>
|
|
15
|
+
#import <Carbon/Carbon.h>
|
|
16
|
+
|
|
17
|
+
static const EventHotKeyID GufaToggleHotKey = {'gufa', 1};
|
|
18
|
+
|
|
19
|
+
@class GufaAppDelegate;
|
|
20
|
+
|
|
21
|
+
static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
|
|
15
22
|
|
|
16
23
|
@interface GufaDragStrip : NSView
|
|
17
|
-
@property (nonatomic, weak) id doubleClickTarget;
|
|
18
|
-
@property (nonatomic, assign) SEL doubleClickAction;
|
|
19
24
|
@end
|
|
20
25
|
|
|
21
26
|
@implementation GufaDragStrip
|
|
@@ -29,7 +34,7 @@
|
|
|
29
34
|
NSFontAttributeName: [NSFont systemFontOfSize:10 weight:NSFontWeightMedium],
|
|
30
35
|
NSForegroundColorAttributeName: [NSColor colorWithCalibratedWhite:1.0 alpha:0.6],
|
|
31
36
|
};
|
|
32
|
-
NSString *label = @"古法编程 · 悬浮层(拖动移动 ·
|
|
37
|
+
NSString *label = @"古法编程 · 悬浮层(拖动移动 · 右键菜单 · ⌥⌘G 切穿透)";
|
|
33
38
|
NSSize size = [label sizeWithAttributes:attrs];
|
|
34
39
|
NSPoint origin = NSMakePoint(floor((self.bounds.size.width - size.width) / 2.0), floor((self.bounds.size.height - size.height) / 2.0));
|
|
35
40
|
[label drawAtPoint:origin withAttributes:attrs];
|
|
@@ -49,10 +54,6 @@
|
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
- (void)mouseDown:(NSEvent *)event {
|
|
52
|
-
if (event.clickCount == 2 && self.doubleClickTarget != nil && self.doubleClickAction != NULL) {
|
|
53
|
-
[NSApp sendAction:self.doubleClickAction to:self.doubleClickTarget from:self];
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
57
|
[self.window performWindowDragWithEvent:event];
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -77,12 +78,14 @@
|
|
|
77
78
|
@property (nonatomic, strong) NSString *frameKey;
|
|
78
79
|
@property (nonatomic, strong) GufaNavigationDelegate *navigation;
|
|
79
80
|
@property (nonatomic, strong) NSDictionary *options;
|
|
81
|
+
@property (nonatomic, assign) EventHotKeyRef hotKeyRef;
|
|
80
82
|
@property (nonatomic, assign) BOOL following;
|
|
81
83
|
@property (nonatomic, assign) int followWindowNumber;
|
|
82
84
|
@property (nonatomic, assign) pid_t followOwnerPID;
|
|
83
85
|
@property (nonatomic, strong) NSTimer *followTimer;
|
|
84
86
|
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *windowCandidates;
|
|
85
87
|
- (void)loadWebContent;
|
|
88
|
+
- (void)registerToggleHotKey;
|
|
86
89
|
- (void)toggleClickThrough:(id)sender;
|
|
87
90
|
- (void)resetFrame:(id)sender;
|
|
88
91
|
- (void)quitApp:(id)sender;
|
|
@@ -110,6 +113,7 @@
|
|
|
110
113
|
[self parseOptions];
|
|
111
114
|
[self buildWindow];
|
|
112
115
|
[self buildStatusItem];
|
|
116
|
+
[self registerToggleHotKey];
|
|
113
117
|
[self loadWebContent];
|
|
114
118
|
}
|
|
115
119
|
|
|
@@ -177,8 +181,6 @@
|
|
|
177
181
|
GufaDragStrip *strip = [[GufaDragStrip alloc] initWithFrame:NSMakeRect(0, frame.size.height - stripHeight, frame.size.width, stripHeight)];
|
|
178
182
|
strip.autoresizingMask = NSViewWidthSizable | NSViewMinYMargin;
|
|
179
183
|
strip.menu = self.mainMenu;
|
|
180
|
-
strip.doubleClickTarget = self;
|
|
181
|
-
strip.doubleClickAction = @selector(toggleClickThrough:);
|
|
182
184
|
[container addSubview:strip];
|
|
183
185
|
self.dragStrip = strip;
|
|
184
186
|
|
|
@@ -197,7 +199,7 @@
|
|
|
197
199
|
[menu addItemWithTitle:@"跟随 App 窗口…(需屏幕录制权限)" action:@selector(chooseFollowWindow:) keyEquivalent:@""].target = self;
|
|
198
200
|
[menu addItemWithTitle:@"停止跟随" action:@selector(stopFollow:) keyEquivalent:@""].target = self;
|
|
199
201
|
[menu addItem:[NSMenuItem separatorItem]];
|
|
200
|
-
[menu addItemWithTitle:@"
|
|
202
|
+
[menu addItemWithTitle:@"切换点击穿透(⌥⌘G)" action:@selector(toggleClickThrough:) keyEquivalent:@""].target = self;
|
|
201
203
|
[menu addItemWithTitle:@"重置窗口位置和大小" action:@selector(resetFrame:) keyEquivalent:@""].target = self;
|
|
202
204
|
[menu addItem:[NSMenuItem separatorItem]];
|
|
203
205
|
[menu addItemWithTitle:@"关闭悬浮层" action:@selector(quitApp:) keyEquivalent:@""].target = self;
|
|
@@ -379,6 +381,13 @@
|
|
|
379
381
|
[self saveFrame];
|
|
380
382
|
}
|
|
381
383
|
|
|
384
|
+
/* 全局快捷键 ⌥⌘G:穿透后窗口收不到鼠标事件,靠它切回来(Carbon 热键不需要辅助功能权限) */
|
|
385
|
+
- (void)registerToggleHotKey {
|
|
386
|
+
EventTypeSpec spec = {kEventClassKeyboard, kEventHotKeyPressed};
|
|
387
|
+
InstallApplicationEventHandler(NewEventHandlerUPP(GufaHotKeyHandler), 1, &spec, (__bridge void *)self, NULL);
|
|
388
|
+
RegisterEventHotKey(kVK_ANSI_G, cmdKey | optionKey, GufaToggleHotKey, GetApplicationEventTarget(), 0, &_hotKeyRef);
|
|
389
|
+
}
|
|
390
|
+
|
|
382
391
|
- (void)toggleClickThrough:(id)sender {
|
|
383
392
|
self.clickThrough = !self.clickThrough;
|
|
384
393
|
self.window.ignoresMouseEvents = self.clickThrough;
|
|
@@ -406,6 +415,14 @@
|
|
|
406
415
|
|
|
407
416
|
@end
|
|
408
417
|
|
|
418
|
+
static OSStatus GufaHotKeyHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) {
|
|
419
|
+
(void)nextHandler;
|
|
420
|
+
(void)event;
|
|
421
|
+
GufaAppDelegate *self = (__bridge GufaAppDelegate *)userData;
|
|
422
|
+
[self toggleClickThrough:nil];
|
|
423
|
+
return noErr;
|
|
424
|
+
}
|
|
425
|
+
|
|
409
426
|
int main(int argc, const char *argv[]) {
|
|
410
427
|
@autoreleasepool {
|
|
411
428
|
[NSApplication sharedApplication];
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ cd "$(dirname "$0")/.."
|
|
|
5
5
|
mkdir -p desktop/float/bin
|
|
6
6
|
ARCH="$(uname -m)"
|
|
7
7
|
OUT="desktop/float/bin/gufa-float-macos-${ARCH}"
|
|
8
|
-
clang -fobjc-arc -O2 -framework AppKit -framework WebKit -o "$OUT" desktop/float/GufaFloat.m
|
|
8
|
+
clang -fobjc-arc -O2 -framework AppKit -framework WebKit -framework Carbon -o "$OUT" desktop/float/GufaFloat.m
|
|
9
9
|
chmod +x "$OUT"
|
|
10
10
|
codesign --force --sign - "$OUT" >/dev/null 2>&1 || true
|
|
11
11
|
echo "built: $OUT"
|