diff --git a/lutris/game.py b/lutris/game.py index 5f18ea844..331a6823f 100644 --- a/lutris/game.py +++ b/lutris/game.py @@ -398,7 +398,7 @@ class Game(GObject.Object): if gamemode: env['LD_PRELOAD'] = ':'.join([ path for path in - [env.get('LD_PRELOAD'), system.GAMEMODE_PATH] + [env.get('LD_PRELOAD'), "/usr/$LIB/libgamemodeauto.so.0"] if path ]) diff --git a/lutris/sysoptions.py b/lutris/sysoptions.py index 9544ba735..8a1cdf38f 100644 --- a/lutris/sysoptions.py +++ b/lutris/sysoptions.py @@ -105,8 +105,8 @@ system_options = [ # pylint: disable=invalid-name { 'option': 'gamemode', 'type': 'bool', - 'default': bool(system.GAMEMODE_PATH), - 'condition': bool(system.GAMEMODE_PATH), + 'default': bool(system.find_lib("libgamemodeauto.so.0")), + 'condition': bool(system.find_lib("libgamemodeauto.so.0")), 'label': 'Enable Feral gamemode', 'help': 'Request a set of optimisations be temporarily applied to the host OS' }, diff --git a/lutris/util/system.py b/lutris/util/system.py index 8a852ae50..a3337a769 100644 --- a/lutris/util/system.py +++ b/lutris/util/system.py @@ -46,17 +46,6 @@ INSTALLED_TERMINALS = [] # Detect if system is 64bit capable IS_64BIT = sys.maxsize > 2**32 -# Path to Feral gamemode library -GAMEMODE_PATH = next( - ( - path for path in map( - lambda x: os.path.join(x, 'libgamemodeauto.so'), - ['/usr/lib/x86_64-linux-gnu', '/usr/lib'] - ) if os.path.exists(path) - ), - None -) - def execute(command, env=None, cwd=None, log_errors=False, quiet=False, shell=False): """ @@ -455,3 +444,18 @@ def is_running(process): if re.search(process, x): return True return False + + +def find_lib(libname): + """Returns a list of absoulte paths found in the system of a given library""" + lib_paths = [] + ldconfig_cmd = find_executable("ldconfig") + if ldconfig_cmd: + ldconfig_out = subprocess.check_output( + [ldconfig_cmd, "-p"]).decode("UTF-8") + for out in ldconfig_out.splitlines(): + if libname in out: + lib_paths.append(out.split("=> ")[1]) + else: + logger.error("ldconfig not found, can't search for lib %s", libname) + return lib_paths