DEV Community

Nikkhiel Seath
Nikkhiel Seath

Posted on

optimus-manager on arch linux

In this post I am sharing how to use optimus-manager to shift between Integrated and NVIDIA GPU on Arch Linux with i3 as the tiling windows manager and no display manager.
(That is you start your Xserver using the startx command).

startx in my .bash_profile

The official documentation just mentions that prime-offload and prime-switch need to be run at start and end of the Xserver (respectively) but, it fails to mention to how to do this setup.

Without wasting any further time, lets get started.

Steps

  1. Open up your .xinitrc located under $HOME or ~. If it doesn't exist then, create one.

  2. Look at the following code-block:

    # MENTION HERE COMMAND THAT IS RUN AT THE START OF XServer
    # and before starting up `i3` (#a)
    
    nitrogen --restore &
    picom &
    i3
    
    # MENTION HERE COMMAND THAT IS RUN AT THE END OF XServer
    # and after exiting `i3` (#b)
    
  3. Place the command to run prime-offload at #a:

    if [[ -f /usr/bin/prime-offload ]]; then
        /usr/bin/prime-offload
    fi
    
    nitrogen --restore &
    picom &
    i3
    
  4. Place the command to run prime-switch at #b:

    nitrogen --restore &
    picom &
    i3
    
    if [[ -f /usr/bin/prime-switch ]]; then
        sudo /usr/bin/prime-switch
    fi
    

Verify

Your final .xinitrc should be like this:

if [[ -f /usr/bin/prime-offload ]]; then
    /usr/bin/prime-offload
fi

nitrogen --restore &
picom &
i3

if [[ -f /usr/bin/prime-switch ]]; then
    sudo /usr/bin/prime-switch
fi
Enter fullscreen mode Exit fullscreen mode

Basically, we are checking if prime-offload exists then, run it at the start of XServer. Technically, not exactly at start but, before we run our compositor and i3 instance.
And then, we are checking if prime-switch exists then, run it after the i3 instance has ended.

You can read more about .xinitrc here

Top comments (0)