Support nvidia on-demand app launching.
Requires linuxmint/xapps@dcb600595d to function correctly.
This commit is contained in:
parent
b4f6cadcf0
commit
a819d570eb
@ -12,7 +12,7 @@ import urllib.request, urllib.parse, urllib.error
|
|||||||
import gi
|
import gi
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
gi.require_version("MateMenu", "2.0")
|
gi.require_version("MateMenu", "2.0")
|
||||||
from gi.repository import Gtk, Gdk, GdkPixbuf, Gio, GLib, MateMenu
|
from gi.repository import Gtk, Gdk, GdkPixbuf, Gio, GLib, MateMenu, XApp
|
||||||
|
|
||||||
import plugins.recentHelper as RecentHelper
|
import plugins.recentHelper as RecentHelper
|
||||||
from plugins.easybuttons import (ApplicationLauncher, CategoryButton,
|
from plugins.easybuttons import (ApplicationLauncher, CategoryButton,
|
||||||
@ -188,6 +188,13 @@ class pluginclass(object):
|
|||||||
self.menuFiles = []
|
self.menuFiles = []
|
||||||
self.de = de
|
self.de = de
|
||||||
|
|
||||||
|
self.canOffload = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.canOffload = XApp.util_gpu_offload_supported()
|
||||||
|
except AttributeError:
|
||||||
|
print("Could not check for gpu offload support - maybe xapps isn't up to date.");
|
||||||
|
|
||||||
# Detect the locale (this is used for the Wikipedia search)
|
# Detect the locale (this is used for the Wikipedia search)
|
||||||
self.lang = "en"
|
self.lang = "en"
|
||||||
lang = os.getenv('LANG')
|
lang = os.getenv('LANG')
|
||||||
@ -835,6 +842,7 @@ class pluginclass(object):
|
|||||||
startupMenuItem = Gtk.CheckMenuItem(_("Launch when I log in"))
|
startupMenuItem = Gtk.CheckMenuItem(_("Launch when I log in"))
|
||||||
separator3 = Gtk.SeparatorMenuItem()
|
separator3 = Gtk.SeparatorMenuItem()
|
||||||
launchMenuItem = Gtk.MenuItem(_("Launch"))
|
launchMenuItem = Gtk.MenuItem(_("Launch"))
|
||||||
|
launchOffloadedMenuItem = Gtk.MenuItem(_("Run with NVIDIA GPU"))
|
||||||
removeFromFavMenuItem = Gtk.MenuItem(_("Remove from favorites"))
|
removeFromFavMenuItem = Gtk.MenuItem(_("Remove from favorites"))
|
||||||
separator4 = Gtk.SeparatorMenuItem()
|
separator4 = Gtk.SeparatorMenuItem()
|
||||||
propsMenuItem = Gtk.MenuItem(_("Edit properties"))
|
propsMenuItem = Gtk.MenuItem(_("Edit properties"))
|
||||||
@ -850,6 +858,7 @@ class pluginclass(object):
|
|||||||
startupMenuItem.set_active(False)
|
startupMenuItem.set_active(False)
|
||||||
startupMenuItem.connect("toggled", self.onAddToStartup, widget)
|
startupMenuItem.connect("toggled", self.onAddToStartup, widget)
|
||||||
launchMenuItem.connect("activate", self.onLaunchApp, widget)
|
launchMenuItem.connect("activate", self.onLaunchApp, widget)
|
||||||
|
launchOffloadedMenuItem.connect("activate", self.onLaunchOffloadedApp, widget)
|
||||||
removeFromFavMenuItem.connect("activate", self.onFavoritesRemove, widget)
|
removeFromFavMenuItem.connect("activate", self.onFavoritesRemove, widget)
|
||||||
propsMenuItem.connect("activate", self.onPropsApp, widget)
|
propsMenuItem.connect("activate", self.onPropsApp, widget)
|
||||||
|
|
||||||
@ -863,6 +872,8 @@ class pluginclass(object):
|
|||||||
mTree.append(startupMenuItem)
|
mTree.append(startupMenuItem)
|
||||||
mTree.append(separator3)
|
mTree.append(separator3)
|
||||||
mTree.append(launchMenuItem)
|
mTree.append(launchMenuItem)
|
||||||
|
if self.canOffload:
|
||||||
|
mTree.append(launchOffloadedMenuItem)
|
||||||
mTree.append(removeFromFavMenuItem)
|
mTree.append(removeFromFavMenuItem)
|
||||||
mTree.append(separator4)
|
mTree.append(separator4)
|
||||||
mTree.append(propsMenuItem)
|
mTree.append(propsMenuItem)
|
||||||
@ -904,6 +915,7 @@ class pluginclass(object):
|
|||||||
startupMenuItem = Gtk.CheckMenuItem(_("Launch when I log in"))
|
startupMenuItem = Gtk.CheckMenuItem(_("Launch when I log in"))
|
||||||
separator2 = Gtk.SeparatorMenuItem()
|
separator2 = Gtk.SeparatorMenuItem()
|
||||||
launchMenuItem = Gtk.MenuItem(_("Launch"))
|
launchMenuItem = Gtk.MenuItem(_("Launch"))
|
||||||
|
launchOffloadedMenuItem = Gtk.MenuItem(_("Run with NVIDIA GPU"))
|
||||||
uninstallMenuItem = Gtk.MenuItem(_("Uninstall"))
|
uninstallMenuItem = Gtk.MenuItem(_("Uninstall"))
|
||||||
deleteMenuItem = Gtk.MenuItem(_("Delete from menu"))
|
deleteMenuItem = Gtk.MenuItem(_("Delete from menu"))
|
||||||
separator3 = Gtk.SeparatorMenuItem()
|
separator3 = Gtk.SeparatorMenuItem()
|
||||||
@ -918,6 +930,8 @@ class pluginclass(object):
|
|||||||
mTree.append(startupMenuItem)
|
mTree.append(startupMenuItem)
|
||||||
mTree.append(separator2)
|
mTree.append(separator2)
|
||||||
mTree.append(launchMenuItem)
|
mTree.append(launchMenuItem)
|
||||||
|
if self.canOffload:
|
||||||
|
mTree.append(launchOffloadedMenuItem)
|
||||||
mTree.append(uninstallMenuItem)
|
mTree.append(uninstallMenuItem)
|
||||||
if home in widget.desktopFile:
|
if home in widget.desktopFile:
|
||||||
mTree.append(deleteMenuItem)
|
mTree.append(deleteMenuItem)
|
||||||
@ -929,6 +943,7 @@ class pluginclass(object):
|
|||||||
desktopMenuItem.connect("activate", self.add_to_desktop, widget)
|
desktopMenuItem.connect("activate", self.add_to_desktop, widget)
|
||||||
panelMenuItem.connect("activate", self.add_to_panel, widget)
|
panelMenuItem.connect("activate", self.add_to_panel, widget)
|
||||||
launchMenuItem.connect("activate", self.onLaunchApp, widget)
|
launchMenuItem.connect("activate", self.onLaunchApp, widget)
|
||||||
|
launchOffloadedMenuItem.connect("activate", self.onLaunchOffloadedApp, widget)
|
||||||
propsMenuItem.connect("activate", self.onPropsApp, widget)
|
propsMenuItem.connect("activate", self.onPropsApp, widget)
|
||||||
uninstallMenuItem.connect("activate", self.onUninstallApp, widget)
|
uninstallMenuItem.connect("activate", self.onUninstallApp, widget)
|
||||||
|
|
||||||
@ -1070,6 +1085,10 @@ class pluginclass(object):
|
|||||||
widget.execute()
|
widget.execute()
|
||||||
self.mintMenuWin.hide()
|
self.mintMenuWin.hide()
|
||||||
|
|
||||||
|
def onLaunchOffloadedApp(self, menu, widget):
|
||||||
|
widget.execute(offload=True)
|
||||||
|
self.mintMenuWin.hide()
|
||||||
|
|
||||||
def onPropsApp(self, menu, widget):
|
def onPropsApp(self, menu, widget):
|
||||||
newFileFlag = False
|
newFileFlag = False
|
||||||
sysPaths = get_system_item_paths()
|
sysPaths = get_system_item_paths()
|
||||||
|
@ -344,7 +344,7 @@ class ApplicationLauncher(easyButton):
|
|||||||
else:
|
else:
|
||||||
selection.set_uris(["file://" + self.desktopFile])
|
selection.set_uris(["file://" + self.desktopFile])
|
||||||
|
|
||||||
def execute(self, *args):
|
def execute(self, *args, **kwargs):
|
||||||
if self.appExec:
|
if self.appExec:
|
||||||
if self.useTerminal:
|
if self.useTerminal:
|
||||||
cmd = "x-terminal-emulator -e \"" + self.appExec + "\""
|
cmd = "x-terminal-emulator -e \"" + self.appExec + "\""
|
||||||
@ -352,7 +352,14 @@ class ApplicationLauncher(easyButton):
|
|||||||
cmd = "mate-terminal -e \"" + self.appExec + "\""
|
cmd = "mate-terminal -e \"" + self.appExec + "\""
|
||||||
Execute(cmd, self.appPath)
|
Execute(cmd, self.appPath)
|
||||||
else:
|
else:
|
||||||
Execute(None, desktopFile=self.desktopFile)
|
offload = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
offload = kwargs["offload"]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
Execute(None, desktopFile=self.desktopFile, offload=offload)
|
||||||
|
|
||||||
def uninstall(self, *args):
|
def uninstall(self, *args):
|
||||||
Execute("mint-remove-application " + self.desktopFile)
|
Execute("mint-remove-application " + self.desktopFile)
|
||||||
@ -464,12 +471,12 @@ class MenuApplicationLauncher(ApplicationLauncher):
|
|||||||
else:
|
else:
|
||||||
self.addLabel(appName)
|
self.addLabel(appName)
|
||||||
|
|
||||||
def execute(self, *args):
|
def execute(self, *args, **kwargs):
|
||||||
self.highlight = False
|
self.highlight = False
|
||||||
for child in self.labelBox:
|
for child in self.labelBox:
|
||||||
child.destroy()
|
child.destroy()
|
||||||
self.setupLabels()
|
self.setupLabels()
|
||||||
return super(MenuApplicationLauncher, self).execute(*args)
|
return super(MenuApplicationLauncher, self).execute(*args, **kwargs)
|
||||||
|
|
||||||
def setShowComment(self, showComment):
|
def setShowComment(self, showComment):
|
||||||
self.showComment = showComment
|
self.showComment = showComment
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from gi.repository import Gio, GLib
|
from gi.repository import Gio, GLib, Gdk
|
||||||
|
|
||||||
|
|
||||||
def RemoveArgs(Execline):
|
def RemoveArgs(Execline):
|
||||||
@ -25,12 +25,26 @@ def gather_pid_callback(appinfo, pid, data):
|
|||||||
GLib.child_watch_add(pid, dummy_child_watch, None)
|
GLib.child_watch_add(pid, dummy_child_watch, None)
|
||||||
|
|
||||||
# Actually execute the command
|
# Actually execute the command
|
||||||
def Execute(cmd , commandCwd=None, desktopFile=None):
|
def Execute(cmd , commandCwd=None, desktopFile=None, offload=False):
|
||||||
if desktopFile:
|
if desktopFile:
|
||||||
launcher = Gio.DesktopAppInfo.new_from_filename(desktopFile)
|
launcher = Gio.DesktopAppInfo.new_from_filename(desktopFile)
|
||||||
retval = launcher.launch_uris_as_manager(uris=[], launch_context=None, spawn_flags=GLib.SpawnFlags.SEARCH_PATH|GLib.SpawnFlags.DO_NOT_REAP_CHILD, \
|
context = Gdk.Display.get_default().get_app_launch_context()
|
||||||
user_setup=None, user_setup_data=None, pid_callback=gather_pid_callback, pid_callback_data=None)
|
if offload:
|
||||||
|
print("Offloading '%s' to discrete gpu." % launcher.get_name());
|
||||||
|
|
||||||
|
context.setenv("__NV_PRIME_RENDER_OFFLOAD", "1")
|
||||||
|
context.setenv("__GLX_VENDOR_LIBRARY_NAME", "nvidia");
|
||||||
|
|
||||||
|
try:
|
||||||
|
retval = launcher.launch_uris_as_manager(uris=[],
|
||||||
|
launch_context=context,
|
||||||
|
spawn_flags=GLib.SpawnFlags.SEARCH_PATH|GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
||||||
|
user_setup=None, user_setup_data=None,
|
||||||
|
pid_callback=gather_pid_callback, pid_callback_data=None)
|
||||||
return retval
|
return retval
|
||||||
|
except GLib.Error as e:
|
||||||
|
print("Error launching %s: %s" % (launcher.get_name(), e.message))
|
||||||
|
return False
|
||||||
|
|
||||||
cwd = os.path.expanduser("~")
|
cwd = os.path.expanduser("~")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user