Skip to content

Commit 5583343

Browse files
committed
feat: Enhance overlay functionality with window focus tracking and hotkey support
1 parent b031357 commit 5583343

File tree

5 files changed

+217
-29
lines changed

5 files changed

+217
-29
lines changed

wox.core/plugin/system/explorer/explorer.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ func (c *ExplorerPlugin) queryFileExplorer(ctx context.Context, query plugin.Que
162162
if isDir {
163163
actions = []plugin.QueryResultAction{
164164
{
165-
Name: "i18n:plugin_explorer_open",
165+
Name: "i18n:plugin_explorer_open",
166+
Hotkey: "ctrl+enter",
166167
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
167168
if activePid <= 0 {
168169
c.api.Log(ctx, plugin.LogLevelError, fmt.Sprintf("Navigate explorer by pid failed: invalid pid=%d path=%s", activePid, fullPath))
@@ -176,27 +177,28 @@ func (c *ExplorerPlugin) queryFileExplorer(ctx context.Context, query plugin.Que
176177
},
177178
},
178179
{
179-
Name: "i18n:plugin_explorer_open_containing_folder",
180+
Name: "i18n:plugin_explorer_open_containing_folder",
181+
IsDefault: true,
180182
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
181183
shell.OpenFileInFolder(fullPath)
182184
},
183-
Hotkey: "ctrl+enter",
184185
},
185186
}
186187
} else {
187188
actions = []plugin.QueryResultAction{
188189
{
189-
Name: "i18n:plugin_explorer_open",
190+
Name: "i18n:plugin_explorer_open",
191+
Hotkey: "ctrl+enter",
190192
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
191193
shell.Open(fullPath)
192194
},
193195
},
194196
{
195-
Name: "i18n:plugin_explorer_open_containing_folder",
197+
Name: "i18n:plugin_explorer_open_containing_folder",
198+
IsDefault: true,
196199
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
197200
shell.OpenFileInFolder(fullPath)
198201
},
199-
Hotkey: "ctrl+enter",
200202
},
201203
}
202204
}
@@ -410,10 +412,12 @@ func (c *ExplorerPlugin) loadOpenSaveHistory(ctx context.Context) *util.HashMap[
410412
}
411413

412414
func (c *ExplorerPlugin) startOverlayListener(ctx context.Context) {
415+
woxIcon, _ := common.WoxIcon.ToImage()
413416
StartMonitor(func(pid int) {
414417
message := i18n.GetI18nManager().TranslateWox(ctx, "plugin_explorer_hint_message")
415418
overlay.Show(overlay.OverlayOptions{
416419
Name: "explorer_hint",
420+
Icon: woxIcon,
417421
Message: message,
418422
StickyWindowPid: pid,
419423
Anchor: overlay.AnchorBottomRight,

wox.core/plugin/system/explorer/monitor_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package explorer
22

33
/*
44
#cgo CFLAGS: -x objective-c
5-
#cgo LDFLAGS: -framework Cocoa
5+
#cgo LDFLAGS: -framework Cocoa -framework ApplicationServices
66
extern void finderActivatedCallbackCGO(int pid);
77
void startFinderMonitor();
88
void stopFinderMonitor();

wox.core/plugin/system/explorer/monitor_darwin.m

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,58 @@
44
extern void finderActivatedCallbackCGO(int pid);
55

66
static id gAppActivationObserver = nil;
7+
static AXObserverRef gFinderWindowObserver = nil;
8+
static pid_t gFinderPid = 0;
9+
10+
// AXObserver callback - called when Finder's focused window changes
11+
static void finderWindowFocusCallback(AXObserverRef observer, AXUIElementRef element, CFStringRef notification, void *refcon) {
12+
if (gFinderPid > 0) {
13+
finderActivatedCallbackCGO(gFinderPid);
14+
}
15+
}
16+
17+
static void startFinderWindowObserver(pid_t pid) {
18+
// Stop existing observer if any
19+
if (gFinderWindowObserver) {
20+
CFRunLoopRemoveSource(CFRunLoopGetMain(),
21+
AXObserverGetRunLoopSource(gFinderWindowObserver),
22+
kCFRunLoopDefaultMode);
23+
CFRelease(gFinderWindowObserver);
24+
gFinderWindowObserver = nil;
25+
}
26+
27+
gFinderPid = pid;
28+
29+
// Create AXObserver for window focus changes
30+
AXObserverRef observer = NULL;
31+
AXError err = AXObserverCreate(pid, finderWindowFocusCallback, &observer);
32+
if (err != kAXErrorSuccess || !observer) {
33+
return;
34+
}
35+
36+
gFinderWindowObserver = observer;
37+
38+
// Get the application element and add notification
39+
AXUIElementRef app = AXUIElementCreateApplication(pid);
40+
if (app) {
41+
AXObserverAddNotification(observer, app, kAXFocusedWindowChangedNotification, NULL);
42+
CFRelease(app);
43+
}
44+
45+
// Add observer to run loop
46+
CFRunLoopAddSource(CFRunLoopGetMain(), AXObserverGetRunLoopSource(observer), kCFRunLoopDefaultMode);
47+
}
48+
49+
static void stopFinderWindowObserver() {
50+
if (gFinderWindowObserver) {
51+
CFRunLoopRemoveSource(CFRunLoopGetMain(),
52+
AXObserverGetRunLoopSource(gFinderWindowObserver),
53+
kCFRunLoopDefaultMode);
54+
CFRelease(gFinderWindowObserver);
55+
gFinderWindowObserver = nil;
56+
}
57+
gFinderPid = 0;
58+
}
759

860
void startFinderMonitor() {
961
@autoreleasepool {
@@ -16,14 +68,29 @@ void startFinderMonitor() {
1668
usingBlock:^(NSNotification *notification) {
1769
NSRunningApplication *app = [[notification userInfo] objectForKey:NSWorkspaceApplicationKey];
1870
if (app && [[app bundleIdentifier] isEqualToString:@"com.apple.finder"]) {
19-
finderActivatedCallbackCGO([app processIdentifier]);
71+
pid_t pid = [app processIdentifier];
72+
finderActivatedCallbackCGO(pid);
73+
// Start observing window focus changes within Finder
74+
startFinderWindowObserver(pid);
75+
} else {
76+
// Stop observing when switching away from Finder
77+
stopFinderWindowObserver();
2078
}
2179
}];
80+
81+
// Check if Finder is already active
82+
NSRunningApplication *activeApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
83+
if (activeApp && [[activeApp bundleIdentifier] isEqualToString:@"com.apple.finder"]) {
84+
pid_t pid = [activeApp processIdentifier];
85+
finderActivatedCallbackCGO(pid);
86+
startFinderWindowObserver(pid);
87+
}
2288
}
2389
}
2490

2591
void stopFinderMonitor() {
2692
@autoreleasepool {
93+
stopFinderWindowObserver();
2794
if (gAppActivationObserver) {
2895
[[NSWorkspace sharedWorkspace].notificationCenter removeObserver:gAppActivationObserver];
2996
gAppActivationObserver = nil;

wox.core/util/overlay/overlay_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package overlay
22

33
/*
44
#cgo CFLAGS: -x objective-c
5-
#cgo LDFLAGS: -framework Cocoa -framework ApplicationServices
5+
#cgo LDFLAGS: -framework Cocoa -framework ApplicationServices -framework CoreVideo
66
#include <stdlib.h>
77
#include <stdbool.h>
88

0 commit comments

Comments
 (0)