protonfixes icon indicating copy to clipboard operation
protonfixes copied to clipboard

POC: Launcher/Configurator

Open pchome opened this issue 4 years ago • 3 comments

The idea is simple: hold Left Ctrl key during game launch to spawn an program where one can add/modify PF options.

I hacked this as two parts: a simple keypress detector, to avoid additional dependencies (except it depends on X11), and a patch.

is_ctrl_key.c

#include <X11/Xlib.h>
#include <X11/keysym.h>

int main() {
  char keys_return[32];

  Display *dpy    = XOpenDisplay(NULL);
  KeyCode keycode = XKeysymToKeycode(dpy, XK_Control_L);

  XQueryKeymap(dpy, keys_return);
  XCloseDisplay(dpy);

  return !!(keys_return[keycode >> 3] & (1 << (keycode & 7))) ? 0 : -1;
}

patch

diff --git a/protonfixes/fix.py b/protonfixes/fix.py
index b026a31..16bacec 100755
--- a/protonfixes/fix.py
+++ b/protonfixes/fix.py
@@ -5,6 +5,7 @@ from __future__ import print_function
 import io
 import os
 import re
+import subprocess
 import sys
 from importlib import import_module
 from protonfixes.splash import splash
@@ -133,6 +134,28 @@ def main():

     log.info('Running protonfixes')

+    try:
+        # Check if Left Ctrl key pressed
+        subprocess.run(os.path.expanduser('~/.local/bin/is_ctrl_key'), shell=True, check=True)
+
+        lpf_file = os.path.expanduser('~/.config/protonfixes/localfixes/' + game_id() + '.py')
+
+        # Create local gamefix file
+        if not os.path.isfile(lpf_file):
+            lpf_template = ''
+            lpf_template += 'from protonfixes import util' + "\n\n"
+            lpf_template += 'def main():' + "\n"
+            lpf_template += '    """ game: ' + game_name() + "\n"
+            lpf_template += '    """' + "\n"
+            lpf_template += '    #util.set_environment("PROTON_USE_WINED3D11", "1")' + "\n"
+            lpf_template += '    '
+            subprocess.run('echo \''+ lpf_template +'\' >> ' + lpf_file, shell=True, check=True)
+
+        #subprocess.run('xdg-open ' + lpf_file, shell=True, check=True)
+        subprocess.run('kate ' + lpf_file, shell=True, check=True)
+    except subprocess.CalledProcessError:
+        pass
+
     if config.enable_splash:
         with splash():
             run_fix(game_id())

When LCtrl pressed, PF will check for existing local gamefix or will create a new one from template. Then (in this example) will open it with the text editor (kate). After closing editor session PF will continue it's work and should load modified gamefix as usual.

Could be changed to an GUI program with most common proton switches to select, if any do/will exist.

pchome avatar Dec 05 '19 17:12 pchome

I like this idea, and would love a pull request. The only thing I would say is that i think it would make the most sense to use xdg-open like you have commented out in the example, since there's no way of knowing what text editor would be available.

simons-public avatar Dec 18 '19 23:12 simons-public

The problem with xdg-open is that it do not wait for process to exit, so the text editor running in parallel with the game. I should figure out is there other XDG utility to determine available program.

Also I'm not sure how binaries should be distributed or built in python packages. Maybe template should be the file too, then it could be more complex and contain some examples.

So, before I eventually will figure this out, any hints are welcomed. I'll do the PR then.

pchome avatar Dec 19 '19 10:12 pchome

While I thought about custom launcher for protonfixes, and maybe some kind of gamefix parser, I remembered the winetricks GUI which I almost never used before, but which can be a good start.

Here is my attempt to combine everything together: pf-launcher-draft-v3.patch.gz

It's very basic, and I'm still unsure about some things, but if this patch is acceptable, you can use git apply /path/to/pf-launcher-draft-v3.patch and close this issue for now.

pchome avatar Feb 05 '20 15:02 pchome