https://github.com/haimgel/display-switch Skip to content Sign up * Why GitHub? + Features + Mobile + Actions + Codespaces + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Learning Lab + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} haimgel / display-switch Public * Notifications * Fork 57 * Star 1.8k * Turn a $30 USB switch into a full-featured multi-monitor KVM switch MIT License 1.8k stars 57 forks Star Notifications * Code * Issues 17 * Pull requests 0 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 2 branches 4 tags Code Latest commit @haimgel haimgel Better explanation of on_xxx_execute quirks. ... 6858139 Dec 2, 2021 Better explanation of `on_xxx_execute` quirks. closes #72 6858139 Git stats * 115 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows Fixing non-Windows compile Oct 18, 2021 src Fixing non-Windows compile Oct 18, 2021 .gitignore Make Clippy happy: minor style improvements Sep 22, 2020 Cargo.lock Bumping a version # Oct 17, 2021 Cargo.toml Bumping a version # Oct 17, 2021 LICENSE Readme updates Jul 28, 2020 README.md Better explanation of on_xxx_execute quirks. Dec 2, 2021 dev.haim.display-switch.daemon.plist Removed MacOS code that is integrated into Rust code now. Sep 7, 2020 rust-toolchain Using latest Rust Oct 17, 2021 rustfmt.toml Pin Rust to a specific version, relax dependency version requirements. Sep 10, 2020 View code [ ] Turn a $30 USB switch into a full-featured KVM Platforms supported Configuration Different inputs on different monitors Running external commands USB Device IDs Windows MacOS Linux Logging Building from source Windows MacOS Linux Running on startup Windows MacOS Linux README.md build GitHub license Turn a $30 USB switch into a full-featured KVM This utility watches for USB device connect/disconnect events and switches monitor inputs via DDC/CI. This turns a simple USB switch into a full-fledged KVM solution: press one button on your USB switch and all your monitors connect to a different input. It is supposed to be installed on all computers that could be connected to these monitors, since the app only switches monitors "one way" and relies on itself running on the other computers to switch it "the other way" as needed. Platforms supported The app should function on MacOS, Windows, and Linux. Most of the code is in Rust, with the exception of DDC support on MacOS, which is done via statically-linked Swift library. Configuration The configuration is pretty similar on all platforms: On MacOS: the configuration file is expected in ~/Library/Preferences /display-switch.ini On Windows: the configuration file is expected in %APPDATA%\display-switch\display-switch.ini On Linux: the configuration file is expected in $XDG_CONFIG_HOME/display-switch/ display-switch.ini or ~/.config/display-switch/display-switch.ini Configuration file settings: usb_device = "1050:0407" on_usb_connect = "Hdmi1" on_usb_disconnect = "Hdmi2" usb_device is which USB device to watch (vendor id / device id in hex), and on_usb_connect is which monitor input to switch to, when this device is connected. Supported values are Hdmi1, Hdmi2, DisplayPort1, DisplayPort2, Dvi1. If your monitor has an USB-C port, it's usually reported as DisplayPort2. Input can also be specified as a "raw" decimal or hexadecimal value: on_usb_connect = 0x10 The optional on_usb_disconnect settings allows to switch in the other direction when the USB device is disconnected. Note that the preferred way is to have this app installed on both computers. Switching "away" is problematic: if the other computer has put the monitors to sleep, they will switch immediately back to the original input. Different inputs on different monitors display-switch supports per-monitor configuration: add one or more monitor-specific configuration sections to set monitor-specific inputs. For example: on_usb_connect = "DisplayPort2" on_usb_disconnect = "Hdmi1" [monitor1] monitor_id = "len" on_usb_connect = "DisplayPort1" [monitor2] monitor_id = "dell" on_usb_connect = "hdmi2" monitor_id specifies a case-insensitive substring to match against the monitor ID. For example, 'len' would match LEN P27u-10 S/N 1144206897 monitor ID. If more than one section has a match, a first one will be used. on_usb_connect and on_usb_disconnect, if defined, take precedence over global defaults. Running external commands display-switch supports running external commands upon connection or disconnection of USB devices. This configuration can be global (runs every time a configured USB device is connected or disconnected) or per-monitor (runs only when a given monitor is being switched): usb_device = "1050:0407" on_usb_connect = "Hdmi1" on_usb_disconnect = "DisplayPort2" on_usb_connect_execute = "echo connected" on_usb_disconnect_execute = "echo disconnected" [monitor1] monitor_id="foobar" on_usb_connect_execute = "echo usb connected, monitor 'foobar' being switched" on_usb_disconnect_execute = "'c:\\program files\\my app.exe' --parameter" Notes: 1. External applications are executed as the same user that started display-switch. 2. This program supports splitting supplied configuration into application name and parameters, but no other shell features are supported. 3. If the application path contains spaces, surround the full file path with single quotes. 4. On Windows, escape the backslashes (replace \ with \, see the example above). USB Device IDs Windows To locate the ID of your USB device ID on Windows: 1. Open Device Manager 2. Locate the USB device, view the properties 3. Switch to the Details tab and select Hardware IDs in the Property dropdown 4. You should see a value similar to HID\VID_046D&PID_C52B&MI_00 (the exact values will differ) - the USB device ID is a combination of the Vendor ID and the Product ID - for example, in this case it would be 046D:C52B MacOS To locate the ID of your USB device ID on MacOS, open a terminal and run the following: brew install lsusb $ lsusb > a $ lsusb > b $ opendiff a b In the command output, the highlighted lines show you which USB IDs are most relevant. Linux To locate the ID of your USB device on Linux, first install lsusb, which your Linux distro should have a package for. (On Debian, Ubuntu and RedHat, the package name is usbutils.) Then, in a terminal, run the following: $ lsusb > a $ lsusb > b $ diff -u a b The diff output will show which USB IDs are most relevant. Logging * On MacOS: the log file is written to /Users/USERNAME/Library/Logs /display-switch/display-switch.log * On Windows: the log file is written to %LOCALAPPDATA%\ display-switch\display-switch.log * On Linux: The log file is written to $XDG_DATA_HOME/ display-switch/display-switch.log or ~/.local/share/ display-switch/display-switch.log Building from source Windows Install Rust, then do cargo build --release MacOS Install Xcode, install Rust, then do cargo build --release Linux Install Rust, then do cargo build --release Running on startup Windows Copy display_switch.exe from target\release (where it was built in the previous step) to %APPDATA%\Microsoft\Windows\Start Menu\Programs \Startup (replace Username with your Windows user name). MacOS # Get your INI file in order! (see above) cp target/release/display_switch /usr/local/bin cp dev.haim.display-switch.daemon.plist ~/Library/LaunchAgents/ launchctl load ~/Library/LaunchAgents/dev.haim.display-switch.daemon.plist Linux Copy built executable: cp target/release/display_switch /usr/local/bin Enable read/write access to i2c devices for users in i2c group. Run as root : groupadd i2c echo 'KERNEL=="i2c-[0-9]*", GROUP="i2c"' >> /etc/udev/rules.d/10-local_i2c_group.rules udevadm control --reload-rules && udevadm trigger Then add your user to the i2c group : sudo usermod -aG i2c $(whoami) Create a systemd unit file in your user directory (/home/$USER /.config/systemd/user/display-switch.service) with contents [Unit] Description=Display switch via USB switch [Service] ExecStart=/usr/local/bin/display_switch Type=simple StandardOutput=journal Restart=always [Install] WantedBy=default.target Create the config file at /home/$USER/.config/display-switch/ display-switch.ini. Then enable the service with systemctl --user daemon-reload systemctl --user enable display-switch.service systemctl --user start display-switch.service About Turn a $30 USB switch into a full-featured multi-monitor KVM switch Topics windows macos rust-lang ddc monitor-configuration switches-monitors Resources Readme License MIT License Stars 1.8k stars Watchers 23 watching Forks 57 forks Releases 4 1.1.0 Latest Oct 18, 2021 + 3 releases Packages 0 No packages published Contributors 13 * @haimgel * @svend * @andornaut * @jrr * @pm215 * @universal * @olivierlemoal * @max-wittig * @jabl * @GeorgeHahn * @kcorey + 2 contributors Languages * Rust 100.0% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.