I was setting up Bumblee with primus to switch between my discrete/integrated GPUs using the Arch Wiki as a guide when I saw this:

Note: Since compositing hurts performance, invoking primus when a compositing WM is active is not recommended. See #Primus issues under compositing window managers.

I use the Compton compositor with i3, so I want to disable Compton whenever primusrun or optirun is invoked and re-enable it when primusrun/optirun are not used.

How could I do this with a bash script or systemd?

I started by writing writing a user level systemd service file for Compton with the idea that I could write a service file for primusrun/optirun that Conflicts= with Compton and starts it again after exiting. But the problem is that primusrun/optirun take an application as an argument and run that using the discrete GPU. So their use doesn't seem compatible with starting a service that invokes them.

Any solutions to this? To re-state the core issue: I want to automatically stop the Compton process when primusrun/optirun are started and restart Compton when they are killed.

  • How about make primus/optirun a service and add compton shutdown & startup lines? – Xen2050 Mar 10 '18 at 10:08
  • I don't think that works because they require an argument that I supply at the command line, e.g optirun glxgears or optirun wine app.exe -- so if I made them a service and started it with systemctl start primusrun then how could I supply an arbitrary argument? – Elfen Dew Mar 10 '18 at 10:12
  • 1
    I don't know anything about Compton, but how about just aliasing primusrun to kill Compton first (if that is possible). Then restore it after it quits (pgrep to check if any other primusrun instances are running). – Sparhawk Mar 10 '18 at 14:03
  • 1
    I know how to do the first part -- something like `alias primusrun='pkill compton; primusrun' , but I want some set up where I don't have to manually restart it when primusrun quits. Any ideas? Maybe primusrun could be an alias for a wrapper bash script that kills compton, starts primusrun, ... periodically checks if primusrun is still running?? .., and runs compton if no primusrun is found before exiting. – Elfen Dew Mar 12 '18 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.