Skip to content

Commit 3fcfb9d

Browse files
committed
fix(launcher): Attempt to open new window by default
1 parent de8cbf3 commit 3fcfb9d

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

src/launcher.ts

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ export class Launcher extends search.Search {
7878

7979
if (selected) {
8080
this.service?.activate(selected.result.id)
81-
global.log(`service exists? ${this.service !== null}`)
82-
} else {
83-
global.log(`option does not exist`)
8481
}
8582
}
8683

@@ -197,30 +194,60 @@ export class Launcher extends search.Search {
197194
const app = Shell.AppSystem.get_default().lookup_desktop_wmclass(wmclass)
198195

199196
if (app) {
200-
if (app.state === Shell.AppState.RUNNING) {
197+
const info = app.get_app_info()
198+
const is_gnome_settings = info ? info.get_executable() === "gnome-control-center" : false;
199+
200+
if (is_gnome_settings && app.state === Shell.AppState.RUNNING) {
201201
app.activate()
202202
const window = app.get_windows()[0]
203203
if (window) shell_window.activate(true, DefaultPointerPosition.TopLeft, window)
204204
return;
205205
}
206206

207+
const existing_windows = app.get_windows().length
208+
207209
app.launch(0, -1, gpuPref)
208210

211+
let attempts = 0
212+
209213
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, () => {
210214
if (app.state === Shell.AppState.STOPPED) {
211-
const info = app.get_app_info()
212215
if (info) {
213-
this.locate_by_app_info(info)?.activate(false)
216+
const window = this.locate_by_app_info(info);
217+
if (window) {
218+
window.activate(false)
219+
return false;
220+
}
221+
}
222+
} else if (app.state === Shell.AppState.RUNNING) {
223+
const windows: Array<Meta.Window> = app.get_windows();
224+
225+
if (windows.length > existing_windows) {
226+
let newest_window = null
227+
let newest_time = -1
228+
for (const window of windows) {
229+
const this_time = window.get_user_time()
230+
if (newest_time < this_time) {
231+
newest_window = window
232+
newest_time = this_time
233+
}
234+
235+
if (this_time === 0) {
236+
newest_window = window
237+
break
238+
}
239+
}
240+
241+
if (newest_window) {
242+
shell_window.activate(true, DefaultPointerPosition.TopLeft, newest_window)
243+
}
244+
245+
return false
214246
}
215-
216-
return false;
217247
}
218248

219-
const window = app.get_windows()[0]
220-
if (window) {
221-
shell_window.activate(true, DefaultPointerPosition.TopLeft, window)
222-
return false
223-
}
249+
attempts += 1
250+
if (attempts === 20) return false
224251

225252
return true;
226253
})

src/launcher_service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class LauncherService {
2626
const [bytes,] = stdout.read_line_finish(res)
2727
if (bytes) {
2828
const string = byteArray.toString(bytes)
29-
log.debug(`received response from launcher service: ${string}`)
29+
// log.debug(`received response from launcher service: ${string}`)
3030
callback(JSON.parse(string))
3131
this.service.stdout.read_line_async(0, this.cancellable, generator)
3232
}
@@ -94,7 +94,7 @@ export class LauncherService {
9494
send(object: Object) {
9595
const message = JSON.stringify(object)
9696
try {
97-
this.service.stdin.write_bytes(new GLib.Bytes(message + "\n"), null)
97+
this.service.stdin.write_all(message + "\n", null)
9898
} catch (why) {
9999
log.error(`failed to send request to pop-launcher: ${why}`)
100100
}

src/mod.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ declare namespace Meta {
196196
get_stable_sequence(): number;
197197
get_title(): string;
198198
get_transient_for(): Window | null;
199+
get_user_time(): number;
199200
get_wm_class(): string | null;
200201
get_wm_class_instance(): string | null;
201202
get_work_area_for_monitor(monitor: number): null | Rectangular;

0 commit comments

Comments
 (0)