optimus-manager: GPU setup was initiated but Xorg post-start hook did not run

Hello! I’ve been optimus-manager for a couple of months now with no issues, but lately I can’t seem to be able to switch modes.

If I run optimus-manager --switch [whatever], my display turns off for a couple of seconds, I get logged out and once I log back in and run optimus-manager --print-mode, I get the following error:

ERROR: a GPU setup was initiated but Xorg post-start hook did not run.  
Log at /var/log/optimus-manager/switch/switch-20201220T121244.log  
[...]  
Cannot execute command because of previous errors.  

The log:

[29] INFO: # Xorg pre-start hook
[29] INFO: Previous state was: {'type': 'pending_pre_xorg_start', 'requested_mode': 'hybrid', current_mode': 'nvidia'}
[29] INFO: Requested mode is: hybrid
[54] INFO: Loaded extra integrated-gpu Xorg options (0 lines)
[54] INFO: Loaded extra nvidia-gpu Xorg options (0 lines)
[54] INFO: Writing to /etc/X11/xorg.conf.d/10-optimus-manager.conf
[54] INFO: Writing state {'type': 'pending_post_xorg_start', 'switch_id': '20201220T121244', 'requested_mode': 'hybrid'}
[55] INFO: Xorg pre-start hook completed successfully.

I am using KDE Plasma with SDDM and I’m on a Dell G5 5587 with a GTX1060Max-Q running Arch. I would appreciate any help you guys can give me!

About this issue

Most upvoted comments

I had a similar issue, and a workaround for me was first running

prime-offload

and then switching works. I have to do this every time I switch though.

I found some other people with similiar issues and more info : https://github.com/Askannz/optimus-manager/issues/281 and https://bbs.archlinux.org/viewtopic.php?id=255752

My issue was that I’ve not commented out the two lines in /etc/sddm.conf that the wiki says to comment out:

Manjaro ships with a default configuration for SDDM (the default login manager for KDE) which overrides some keys needed by optimus-manager. To use optimus-manager, you need to edit the file /etc/sddm.conf and simply put a # before the line starting with DisplayCommandand the one starting with DisplayStopCommand.

Once I’ve done that, everything works seamlessly.

$ optimus-manager --status
Optimus Manager (Client) version 1.4

Current GPU mode : integrated
GPU mode requested for next login : no change
GPU at startup : auto
Temporary config path: no

Another workaround.

  1. Create a script to launch prime-offload on login. Don’t forget to make it executable.
#!/bin/bash

# not sure why but needs to sleep before launching, otherwise, it doesn't work.
sleep 2
prime-offload &> /dev/null
  1. Under ~/.config/autostart. Create a file called prime-offload.desktop with the following contents.
[Desktop Entry]
Type=Application
Exec=<insert-path-to-script-here>/prime-offload.sh
Name=Prime Offload
Comment=Required for Optimus Prime Graphics switching

In this way you don’t have to create any aliases or execute prime-offload every time you want to switch graphics, which should be the case in the first place.