Skip to content

Commit d46d92c

Browse files
committed
feat(launcher): Launch using discrete graphics
1 parent 4c9b6df commit d46d92c

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

src/app_info.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export class AppInfo {
4747
return this.app_info.filename;
4848
}
4949

50+
id(): string {
51+
let name = this.filename
52+
name = name.substr(0, name.lastIndexOf('.'))
53+
return name.substr(name.lastIndexOf('/') + 1)
54+
}
55+
5056
categories(): string {
5157
return this.categories_.get_or_init(() => this.app_info.get_categories());
5258
}

src/dedicated_gpu.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { AppInfo } from './app_info'
2+
3+
const { Shell, St } = imports.gi;
4+
const AppDisplay = imports.ui.appDisplay;
5+
6+
const PopupMenu = imports.ui.popupMenu
7+
const Main = imports.ui.main
8+
9+
const appSys = Shell.AppSystem.get_default()
10+
11+
export function addPopup(info: AppInfo, widget: any) {
12+
// GNOME Shell already tracks if a discrete GPU is available.
13+
// We will only add a popup if one is available.
14+
if (!AppDisplay.discreteGpuAvailable) return
15+
16+
const menu = new PopupMenu.PopupMenu(widget, 0.0, St.Side.TOP, 0)
17+
Main.uiGroup.add_actor(menu.actor)
18+
menu.actor.hide()
19+
menu.actor.add_style_class_name('panel-menu');
20+
21+
const appPrefersNonDefaultGPU = info.app_info.get_boolean('PrefersNonDefaultGPU');
22+
const gpuPref = appPrefersNonDefaultGPU
23+
? Shell.AppLaunchGpu.DEFAULT
24+
: Shell.AppLaunchGpu.DISCRETE;
25+
26+
const menu_item = appendMenuItem(menu, appPrefersNonDefaultGPU
27+
? _('Launch using Integrated Graphics Card')
28+
: _('Launch using Discrete Graphics Card'));
29+
30+
menu_item.connect('activate', () => {
31+
appSys.lookup_desktop_wmclass(info.id())?.launch(0, -1, gpuPref)
32+
});
33+
34+
// Intercept right click events on the launcher app's button
35+
widget.connect('button-press-event', (_: any, event: any) => {
36+
if (event.get_button() === 3) {
37+
menu.toggle()
38+
}
39+
})
40+
}
41+
42+
function appendMenuItem(menu: any, label: string) {
43+
let item = new PopupMenu.PopupMenuItem(label);
44+
menu.addMenuItem(item);
45+
return item
46+
}

src/dialog_launcher.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();
33

44
import * as app_info from 'app_info';
55
import * as error from 'error';
6+
import * as DedicatedGPU from 'dedicated_gpu';
67
import * as launch from 'launcher_service';
78
import * as levenshtein from 'levenshtein';
89
import * as lib from 'lib';
@@ -123,6 +124,8 @@ export class Launcher extends search.Search {
123124
{ app }
124125
)
125126

127+
DedicatedGPU.addPopup(app, button.widget)
128+
126129
this.options.push(button)
127130
}
128131
}

src/launcher_service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class LauncherService {
130130
yield plugin
131131
}
132132
}
133-
133+
134134
for (const plugin of this.plugins.values()) {
135135
if (!plugin.pattern || plugin.pattern.test(query)) {
136136
yield plugin

0 commit comments

Comments
 (0)