├── LICENSE ├── Makefile ├── README.md ├── sway-start.service └── sway_setup.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 ewagner12 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | BINDIR := /usr/bin 2 | SYSDIR := /etc/systemd/system 3 | 4 | all: 5 | 6 | install: 7 | mkdir -p ${DESTDIR}${BINDIR} 8 | cp sway_setup.sh ${DESTDIR}${BINDIR} 9 | chmod +x ${DESTDIR}${BINDIR}/sway_setup.sh 10 | mkdir -p ${DESTDIR}${SYSDIR} 11 | cp sway-start.service ${DESTDIR}${SYSDIR} 12 | mkdir -p ${DESTDIR}/usr/share/sway-eGPU-setup 13 | 14 | uninstall: 15 | systemctl disable sway-start.service 16 | rm -f ${DESTDIR}${BINDIR}/sway_setup.sh 17 | rm -f ${DESTDIR}${SYSDIR}/sway-start.service 18 | rm -rf ${DESTDIR}/usr/share/sway-eGPU-setup 19 | rm -f /etc/environment.d/10sway.conf 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > Note: This repository is provided as-is for those who find it useful. However, for my personal use case, I have moved on to my newer, desktop-agnostic [all-ways-egpu](https://github.com/ewagner12/all-ways-egpu) script (Yes, it works with Sway too!). Thus, this project may not get updated to address future changes in wlroots such as [this](https://github.com/swaywm/wlroots/pull/2752). 2 | 3 | # sway-eGPU-setup 4 | Manages setting of the WLR_DRM_DEVICES environment variable based on cards found by udevadm. 5 | 6 | ## Installation 7 | I finally added a Makefile! To install the most recent version, just download the repo and from the downloaded directory: 8 | 9 | ``` 10 | sudo make install 11 | ``` 12 | 13 | Configuration and enabling the service to start on bootup has also been automated. After installing, just run: 14 | 15 | ``` 16 | sudo sway_setup.sh setup 17 | ``` 18 | 19 | This stores the BusIDs in the file */usr/share/sway-eGPU-setup/user-pci-ids* by default in the format: 20 | `aa:aa.a,bb:bb.b` 21 | where "aa:aa.a" is the eGPU's BusID in hex and "bb:bb.b" is the (optional) iGPU BusID in hex. 22 | Manual configuration could be done by simply adding this file by hand if you prefer. 23 | 24 | Uninstallation is simply: 25 | ``` 26 | sudo make uninstall 27 | ``` 28 | from the repo directory. 29 | -------------------------------------------------------------------------------- /sway-start.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Configure Sway for eGPU 3 | 4 | [Service] 5 | Type=oneshot 6 | ExecStart=/usr/bin/sway_setup.sh 7 | 8 | [Install] 9 | WantedBy=graphical.target 10 | -------------------------------------------------------------------------------- /sway_setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | USER_IDS_DIR=/usr/share/sway-eGPU-setup 4 | 5 | function setup() { 6 | if [[ ! -d /etc/environment.d ]]; then 7 | mkdir /etc/environment.d 8 | fi 9 | 10 | echo "Warning: This will overwrite /etc/environment.d/10sway.conf if it already exists." 11 | echo "Which of these cards is your eGPU?" 12 | lspci -d ::0300 && lspci -d ::0302 13 | echo "Please type in the eGPU BusID (in hex!), e.g: 0a:00.0" 14 | read -r EGPU_PCIE 15 | echo "If you want the internal display on, enter your iGPU BusID now. If not, just press [ENTER]" 16 | read -r IGPU_PCIE 17 | 18 | if [[ ! -d $USER_IDS_DIR ]]; then 19 | mkdir $USER_IDS_DIR 20 | fi 21 | echo "$EGPU_PCIE","$IGPU_PCIE" > $USER_IDS_DIR/user-pcie-ids 22 | 23 | echo "Enabling automatic start-up service (disable sway-start.service if you don't want this)" 24 | systemctl enable sway-start 25 | } 26 | 27 | # check if the script is run as root 28 | if [[ $EUID -ne 0 ]]; then 29 | echo "You need to run the script with root privileges" 30 | exit 31 | fi 32 | 33 | if [[ $1 = "setup" ]]; then 34 | setup 35 | 36 | else 37 | if [[ ! -e $USER_IDS_DIR/user-pcie-ids ]]; then 38 | echo "Please run sway_setup.sh setup" 39 | exit 40 | fi 41 | 42 | EGPU_PCIE=$(cut -d "," -f 1 < $USER_IDS_DIR/user-pcie-ids) 43 | IGPU_PCIE=$(cut -d "," -f 2 < $USER_IDS_DIR/user-pcie-ids) 44 | 45 | for C_NAME in /dev/dri/card*; do 46 | CARD_P=$(udevadm info -n "$C_NAME" -q path) 47 | EGPU_P=$(echo "$CARD_P" | grep "$EGPU_PCIE"/drm) 48 | IGPU_P=$(echo "$CARD_P" | grep "$IGPU_PCIE"/drm) 49 | if [[ -n $EGPU_P ]]; then 50 | EGPU_VAL=$(echo "$EGPU_P" | rev | cut -c 1) 51 | fi 52 | if [[ -n $IGPU_P ]] && [[ -n $IGPU_PCIE ]]; then 53 | IGPU_VAL=$(echo "$IGPU_P" | rev | cut -c 1) 54 | fi 55 | done 56 | 57 | if [[ -n $EGPU_VAL ]]; then 58 | if [[ -n $IGPU_VAL ]]; then 59 | echo WLR_DRM_DEVICES=/dev/dri/card"$EGPU_VAL":/dev/dri/card"$IGPU_VAL" > /etc/environment.d/10sway.conf 60 | else 61 | echo WLR_DRM_DEVICES=/dev/dri/card"$EGPU_VAL" > /etc/environment.d/10sway.conf 62 | fi 63 | else 64 | if [[ -e /etc/environment.d/10sway.conf ]]; then 65 | rm /etc/environment.d/10sway.conf 66 | fi 67 | fi 68 | fi 69 | --------------------------------------------------------------------------------