{"id":13493267,"url":"https://github.com/haimgel/display-switch","last_synced_at":"2025-10-04T07:39:42.378Z","repository":{"id":37020971,"uuid":"283323929","full_name":"haimgel/display-switch","owner":"haimgel","description":"Turn a $30 USB switch into a full-featured multi-monitor KVM switch","archived":false,"fork":false,"pushed_at":"2024-12-01T15:39:15.000Z","size":292,"stargazers_count":3023,"open_issues_count":17,"forks_count":114,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-04-10T13:11:12.733Z","etag":null,"topics":["ddc","macos","monitor-configuration","rust-lang","switches-monitors","windows"],"latest_commit_sha":null,"homepage":"https://haim.dev/posts/2020-07-28-dual-monitor-kvm/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haimgel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-28T20:46:02.000Z","updated_at":"2025-04-09T16:36:27.000Z","dependencies_parsed_at":"2024-11-27T12:11:16.700Z","dependency_job_id":"34b60968-1af4-4332-ae3c-1334a88bff7d","html_url":"https://github.com/haimgel/display-switch","commit_stats":{"total_commits":134,"total_committers":28,"mean_commits":4.785714285714286,"dds":0.6865671641791045,"last_synced_commit":"a5b76e0d04a84051b7fc6dac212143bce5760b41"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haimgel%2Fdisplay-switch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haimgel%2Fdisplay-switch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haimgel%2Fdisplay-switch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haimgel%2Fdisplay-switch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haimgel","download_url":"https://codeload.github.com/haimgel/display-switch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254044226,"owners_count":22005105,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ddc","macos","monitor-configuration","rust-lang","switches-monitors","windows"],"created_at":"2024-07-31T19:01:13.702Z","updated_at":"2025-10-04T07:39:37.341Z","avatar_url":"https://github.com/haimgel.png","language":"Rust","readme":"[![build](https://github.com/haimgel/display-switch/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/haimgel/display-switch/actions)\n[![GitHub license](https://img.shields.io/github/license/haimgel/display-switch)](https://github.com/haimgel/display-switch/blob/main/LICENSE)\n\n# Turn a $30 USB switch into a full-featured KVM\n\nThis utility watches for USB device connect/disconnect events and switches monitor inputs via DDC/CI. This turns\na simple USB switch into a full-fledged KVM solution: press one button on your USB switch and all your monitors\nconnect to a different input.\n\nIt is supposed to be installed on all computers that could be connected to these monitors, since the app only switches\nmonitors \"one way\" and relies on itself running on the other computers to switch it \"the other way\" as needed.\n \n## Platforms supported\n\nThe app should function on MacOS, Windows, and Linux.\n\n## Installation\n * Linux and Windows: download and extract the files from the releases page and place them where\n   you see fit.\n * MacOS: `display_switch` can be installed with Homebrew:\n   ```bash\n   brew install haimgel/tools/display_switch\n   ```\n\n## Configuration\n\nThe configuration is pretty similar on all platforms:\n\nOn MacOS: the configuration file is expected in `~/Library/Preferences/display-switch.ini`\nOn Windows: the configuration file is expected in `%APPDATA%\\display-switch\\display-switch.ini`\nOn Linux: the configuration file is expected in `$XDG_CONFIG_HOME/display-switch/display-switch.ini` or `~/.config/display-switch/display-switch.ini`\n\nConfiguration file settings:\n\n```ini\n  usb_device = \"1050:0407\"\n  on_usb_connect = \"Hdmi1\"\n  on_usb_disconnect = \"Hdmi2\"\n```\n\n`usb_device` is which USB device to watch (vendor id / device id in hex), and `on_usb_connect` is which monitor input\nto switch to, when this device is connected. Supported values are `Hdmi1`, `Hdmi2`, `DisplayPort1`, `DisplayPort2`, `Dvi1`, `Dvi2`, `Vga1`.\nIf your monitor has an USB-C port, it's usually reported as `DisplayPort2`. Input can also be specified as a \"raw\"\ndecimal or hexadecimal value: `on_usb_connect = 0x10`\n\nThe optional `on_usb_disconnect` settings allows to switch in the other direction when the USB device is disconnected.\nNote that the preferred way is to have this app installed on both computers. Switching \"away\" is problematic: if the\nother computer has put the monitors to sleep, they will switch immediately back to the original input.\n\n### Different inputs on different monitors\n`display-switch` supports per-monitor configuration: add one or more monitor-specific configuration sections to set\nmonitor-specific inputs. For example:\n\n```ini\non_usb_connect = \"DisplayPort2\"\non_usb_disconnect = \"Hdmi1\"\n\n[monitor1]\nmonitor_id = \"len\"\non_usb_connect = \"DisplayPort1\"\n\n[monitor2]\nmonitor_id = \"dell\"\non_usb_connect = \"hdmi2\"\n```\n\n`monitor_id` specifies a case-insensitive substring to match against the monitor ID. For example, 'len' would match\n`LEN P27u-10 S/N 1144206897` monitor ID. If more than one section has a match, a first one will be used.\n`on_usb_connect` and `on_usb_disconnect`, if defined, take precedence over global defaults.\n\n_Tips for Windows_: monitors can be renamed in the Registry at\n`\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\{MODEL_ID}\\{CONNECTION_ID}`. Edit the `DeviceDesc` value and change the name after the last semicolon. This is especially helpful in case they are all just \"Generic PnP Monitor\".\n\n### Running external commands\n`display-switch` supports running external commands upon connection or disconnection of USB devices. This configuration\ncan be global (runs every time a configured USB device is connected or disconnected) or per-monitor (runs only when\na given monitor is being switched):\n\n```ini\nusb_device = \"1050:0407\"\non_usb_connect = \"Hdmi1\"\non_usb_disconnect = \"DisplayPort2\"\non_usb_connect_execute = \"echo connected\"\non_usb_disconnect_execute = \"echo disconnected\"\n\n[monitor1]\nmonitor_id=\"foobar\"\non_usb_connect_execute = \"echo usb connected, monitor 'foobar' being switched\"\non_usb_disconnect_execute = \"'c:\\\\program files\\\\my app.exe' --parameter\"\n```\n\nNotes: \n1. External applications are executed as the same user that started `display-switch`. \n2. This program supports splitting supplied configuration into application name and parameters, but no other shell features are supported.\n3. If the application path contains spaces, surround the full file path with single quotes.\n4. On Windows, escape the backslashes (replace \\ with \\\\, see the example above).\n\n### USB Device IDs\n\n#### Windows\nTo locate the ID of your USB device ID on Windows:\n1. Open Device Manager\n2. Locate the USB device, view the properties\n3. Switch to the *Details* tab and select *Hardware IDs* in the Property dropdown\n4. You should see a value similar to `HID\\VID_046D\u0026PID_C52B\u0026MI_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`\n\n#### MacOS\nTo locate the ID of your USB device ID on MacOS, open a terminal and run the following:\n```bash\nbrew install lsusb\n\n$ lsusb \u003e a\n\u003cswitch the usb dock here\u003e\n$ lsusb \u003e b\n$ opendiff a b\n```\nIn the command output, the highlighted lines show you which USB IDs are most relevant.\n\n\nFor a full list of USB devices:\n```\nsystem_profiler SPUSBDataType\n```\n**Important**: The format for your display-switch.ini is VendorID:ProductID. VendorID is displyed *second* in the `system_profiler` output\n\n#### Linux\nRequires additional packages, install via: `sudo apt install libxi-dev xorg-dev`\n\nTo locate the ID of your USB device on Linux, first install `lsusb`, which your Linux\ndistro should have a package for. (On Debian, Ubuntu and RedHat, the package name is `usbutils`.)\nThen, in a terminal, run the following:\n```\n$ lsusb \u003e a\n\u003cswitch the usb dock here\u003e\n$ lsusb \u003e b\n$ diff -u a b\n```\nThe diff output will show which USB IDs are most relevant.\n\n## Logging\n\n* On MacOS: the log file is written to `/Users/USERNAME/Library/Logs/display-switch/display-switch.log`\n* On Windows: the log file is written to `%LOCALAPPDATA%\\display-switch\\display-switch.log`\n* On Linux: The log file is written to `$XDG_DATA_HOME/display-switch/display-switch.log`\n or `~/.local/share/display-switch/display-switch.log`\n\n## Building from source\n\n### Windows\n\n[Install Rust](https://www.rust-lang.org/tools/install), then do `cargo build --release`\n\n### MacOS\n\n[Install Xcode](https://developer.apple.com/xcode/), [install Rust](https://www.rust-lang.org/tools/install), then do\n`cargo build --release` \n\n### Linux\n\n[Install Rust](https://www.rust-lang.org/tools/install), then do `cargo build --release`\n\n## Running on startup\n\n### Windows\n\nCopy `display_switch.exe` from `target\\release` (where it was built in the previous step) to \n`%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup`.\n\n### MacOS\n\n```bash\n  # Get your INI file in order! (see above)\n  cp target/release/display_switch /usr/local/bin/\n  cp dev.haim.display-switch.daemon.plist ~/Library/LaunchAgents/\n  launchctl load ~/Library/LaunchAgents/dev.haim.display-switch.daemon.plist\n```\n### Linux\nCopy built executable:\n\n```bash\n  cp target/release/display_switch /usr/local/bin/\n```\nEnable read/write access to i2c devices for users in `i2c` group. Run as root :\n\n```bash\ngroupadd i2c\necho 'KERNEL==\"i2c-[0-9]*\", GROUP=\"i2c\"' \u003e\u003e /etc/udev/rules.d/10-local_i2c_group.rules\nudevadm control --reload-rules \u0026\u0026 udevadm trigger\n```\n\nThen add your user to the i2c group :\n\n```\nsudo usermod -aG i2c $(whoami)\n```\n\nCreate a systemd unit file in your user directory (`/home/$USER/.config/systemd/user/display-switch.service`) with contents\n\n```\n[Unit]\nDescription=Display switch via USB switch\n\n[Service]\nExecStart=/usr/local/bin/display_switch\nType=simple\nStandardOutput=journal\nRestart=always\n\n[Install]\nWantedBy=default.target\n```\n\nCreate the config file at `/home/$USER/.config/display-switch/display-switch.ini`.\nThen enable the service with\n\n```bash\nsystemctl --user daemon-reload\nsystemctl --user enable display-switch.service\nsystemctl --user start display-switch.service\n```\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaimgel%2Fdisplay-switch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaimgel%2Fdisplay-switch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaimgel%2Fdisplay-switch/lists"}