Skip to content

Commit 73ac105

Browse files
committed
fix(launcher): Find app window to activate even if it doesn't register with Shell.App
1 parent bea8c35 commit 73ac105

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

src/launcher.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { ShellWindow } from 'window'
1515
import type { JsonIPC } from 'launcher_service'
1616

1717
const { DefaultPointerPosition } = config
18-
const { Clutter, GLib, Meta, Shell } = imports.gi
18+
const { Clutter, Gio, GLib, Meta, Shell } = imports.gi
1919

2020
interface SearchOption {
2121
result: JsonIPC.SearchResult
@@ -192,7 +192,6 @@ export class Launcher extends search.Search {
192192

193193
if (app) {
194194
if (app.state === Shell.AppState.RUNNING) {
195-
global.log(`activating window`)
196195
app.activate()
197196
const window = app.get_windows()[0]
198197
if (window) shell_window.activate(true, DefaultPointerPosition.TopLeft, window)
@@ -202,6 +201,15 @@ export class Launcher extends search.Search {
202201
app.launch(0, -1, gpuPref)
203202

204203
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, () => {
204+
if (app.state === Shell.AppState.STOPPED) {
205+
const info = app.get_app_info()
206+
if (info) {
207+
this.locate_by_app_info(info)?.activate(false)
208+
}
209+
210+
return false;
211+
}
212+
205213
const window = app.get_windows()[0]
206214
if (window) {
207215
shell_window.activate(true, DefaultPointerPosition.TopLeft, window)
@@ -223,6 +231,30 @@ export class Launcher extends search.Search {
223231
log.warn("pop-shell: deprecated function called (dialog_launcher::load_desktop_files)")
224232
}
225233

234+
locate_by_app_info(info: any): null | ShellWindow {
235+
const exec_info: null | string = info.get_string("Exec")
236+
const exec = exec_info?.split(' ').shift()?.split('/').pop()
237+
if (exec) {
238+
for (const window of this.ext.tab_list(Meta.TabList.NORMAL, null)) {
239+
const pid = window.meta.get_pid()
240+
if (pid !== -1) {
241+
try {
242+
let f = Gio.File.new_for_path(`/proc/${pid}/cmdline`)
243+
const [,bytes] = f.load_contents(null)
244+
const output: string = imports.byteArray.toString(bytes)
245+
const cmd = output.split(' ').shift()?.split('/').pop()
246+
global.log(`is ${cmd} equal to ${exec}`)
247+
if (cmd === exec) return window
248+
} catch (_) {
249+
250+
}
251+
}
252+
}
253+
}
254+
255+
return null
256+
}
257+
226258
open(ext: Ext) {
227259
const mon = ext.monitor_work_area(ext.active_monitor())
228260

src/search.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,14 @@ export class Search {
250250

251251
highlight_selected() {
252252
const widget = this.widgets[this.active_id]
253-
widget.add_style_pseudo_class("select")
253+
if (widget) {
254+
widget.add_style_pseudo_class("select")
254255

255-
try {
256-
imports.misc.util.ensureActorVisibleInScrollView(this.scroller, widget)
257-
} catch (_error) {
256+
try {
257+
imports.misc.util.ensureActorVisibleInScrollView(this.scroller, widget)
258+
} catch (_error) {
258259

260+
}
259261
}
260262
}
261263

@@ -266,9 +268,7 @@ export class Search {
266268
}
267269

268270
unselect() {
269-
this.widgets[this.active_id].remove_style_pseudo_class(
270-
"select"
271-
);
271+
this.widgets[this.active_id]?.remove_style_pseudo_class("select");
272272
}
273273

274274
append_search_option(option: SearchOption) {

src/window.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ export function activate(move_mouse: boolean, default_pointer_position: Config.D
610610

611611
win.raise();
612612
win.unminimize();
613-
win.get_workspace().activate_with_focus(win, global.get_current_time())
613+
614+
workspace.activate_with_focus(win, global.get_current_time())
614615

615616
if (move_mouse && !pointer_already_on_window(win)) {
616617
place_pointer_on(default_pointer_position, win)

0 commit comments

Comments
 (0)