Linux – Full screen applications on dual monitor setup

arch linuxnvidiaoptimusxorgxrandr

Optimus on Linux is far from perfect however using the native nVidia drivers most issues I had in the past are mainly resolved except one.

Whenever I run a full screen application, like Kodi or some Steam games the position is off, either the screen is centered right in the middle of the 2 screens on exactly 1080p or is rendered showing only the left half on any display.

I think this is due on how I made the multi monitor setup working using xrandr.
When sddm initializes it runs the following command:

xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --output HDMI-1-1 --mode 1920x1080 --pos 1920x0 --output HDMI-0 --primary --mode 1920x1080 --panning 3840x1080+0+0/0x0+0+0/0/0/-1920/0

It works perfectly however as you might notice the container is 3x1080p as this is due to having 3 screens (all being 1080p), disabling my internal display and using panning I am able to shift the output for 2 monitors right next to each other.

It appears I cannot control full screen behavior, noor in KDE or by using put. Playing around in the applications settings I can select which monitor to render it on, but it renders in the center anyways.

To clarify:

xs on monitor left at 1920/2
ys on monitor left at 1080
xe on monitor right at (1920/2)+1920
ye on monitor right at 1080

Here is a link for visual reference

To be honest, I've tried many things and I'm at a loss here. I'm not a Linux expert, I've been using it for about 4 years as my only operating system.

Since KDE supports Wayland I am willing to give this a try however due to the amount of issues I had with Optimus in the past I am reluctant to try it out because everything is running so smoothly and there is little information about Optimus / Nvidia / Wayland compatibility.

Is there anything I might perhaps I've missed before doing anything as radical as changing a stable display manager for a new one? Or perhaps one simplistic command from the terminal for running applications I missed out completely.

Any help is appreciated.

Additional information:

xorg.conf, xorg.conf.d is empty.

Section "Module"
    Load "modesetting"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1:0:0"
    Option "AllowEmptyInitialConfiguration"
EndSection

Request more information if needed in comments.

Best Answer

I've used some scripts on top of xrandr for some years now to set up side-by-side and (currently) tee-shaped desktops on Arch Linux. It should be a simple job to adapt side-by-side.sh to your needs:

#!/bin/sh
eval `\`dirname -- "$0"\`/monitor_resolutions.sh`
expected_monitors=2
if [ "${monitor_count:-0}" -ne "$expected_monitors" ]
then
    echo "$0: Expected ${expected_monitors} monitors; found ${monitor_count:-0}." >&2
    exit 1
fi

xrandr \
    --output "$monitor1_name" \
        --mode ${monitor1_width}x${monitor1_height} \
        --rotate normal \
    --output "$monitor2_name" \
        --mode ${monitor2_width}x${monitor2_height} \
        --right-of "$monitor1_name" \
        --rotate normal

monitor_resolutions.sh helper script:

#!/bin/sh
#
# NAME
#        monitor_resolutions.sh - Variables for monitor resolutions
#
# SYNOPSIS
#        eval `./monitor_resolutions.sh`
#
# DESCRIPTION
#        Prints a set of `eval`-able variable assignments with monitor name,
#        width and height for each monitor plus a monitor count.
#
# EXAMPLES
#        eval `./monitor_resolutions.sh`
#               Assign monitor1_name, monitor1_width, monitor1_height,
#               monitor2_name, etc. and monitor_count variables.
#
# BUGS
#        https://github.com/l0b0/tilde/issues
#
# COPYRIGHT
#        Copyright (C) 2013-2014 Victor Engmark
#
#        This program is free software: you can redistribute it and/or modify
#        it under the terms of the GNU General Public License as published by
#        the Free Software Foundation, either version 3 of the License, or
#        (at your option) any later version.
#
#        This program is distributed in the hope that it will be useful,
#        but WITHOUT ANY WARRANTY; without even the implied warranty of
#        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#        GNU General Public License for more details.
#
#        You should have received a copy of the GNU General Public License
#        along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

monitor_info() {
    xrandr --query | tee ~/.xsession-xrandr-query
}

monitor_resolutions() {
    # Input: XRandR monitor info
    # Output: Lines with monitor name, width and height separated by spaces
    while read -r word1 word2 _
    do
        if [ "${word2:-}" = 'connected' ]
        then
            IFS='xi ' read -r width height _
            printf '%s %d %d\n' "$word1" "$width" "$height"
        fi
    done
}

monitor_assignments() {
    # Input: Lines with monitor name, width and height separated by spaces
    # Output: eval-able variable assignments for each input value, including a final count
    count=0
    while read monitor width height
    do
        count=$(($count + 1))
        printf "monitor%d_name='%s'\n" "$count" "$monitor"
        printf "monitor%d_width='%s'\n" "$count" "$width"
        printf "monitor%d_height='%s'\n" "$count" "$height"
    done
    printf "monitor_count='%s'\n" "$count"
}

monitor_info | monitor_resolutions | monitor_assignments

Run side-by-side.sh in your local .xprofile or otherwise just after starting X, and you should be good to go.

This setup has worked with both AMD and nVidia video cards, using both proprietary and open source drivers. I don't think I've ever tried with Wayland instead of X, but I suspect that should work iff xrandr works with Wayland.

Related Question