Switch monitor display source from your phone
Published November 29, 2022
Chris Hayes
Archived due to substantial ai writing.
As part of an effort to raise the quality of my blog, I'm distancing myself from posts that were partially written by AI. Besides devaluing the rest of the site, I want my site to show my best work and these posts read like a 300-word essay.
This post started as Slack thread about my setup and converted to a blog post with GPT-3. I'm pretty opinionated about writing style, so this article didn't end up how I would write it.
I really did use this ddcutil script quite a bit for a couple years. Today my setup doesn't require frequent input switching. But, this script was also just a good lesson on how I could write a C++ script that ran with elevated permissions that could still be executed by a less privileged KDE Connect application.
This post was archived on May 27, 2026.
If you're like me and you have multiple external monitors connected to two different computers, you know what a pain it can be to manually switch the display source every time you want to switch between them. But, with some clever use of ddcutil, a utility that allows you to interact with monitors via the I2C protocol, you can programmatically switch the display source with just a few button pushes on your phone.
Prerequisite: This post assumes KDE Connect is installed on your phone and your computer. If you don't have KDE Connect installed, you can install it from the KDE Connect website (opens in a new window) .
First, you need to install ddcutil to be able to communicate with the monitor. To do this on Ubuntu, simply run the following command:
sudo add-apt-repository ppa:rockowitz/ddcutil
sudo apt-get update
sudo apt install ddcutil
For other distros, check out the ddcutil docs (opens in a new window) .
Once installed, you can use ddcutil to figure out which monitor is on which bus, and what hex code corresponds to the display source you want. To do this, run the following command:
ddcutil detect
You should now be able to change your display source with the right ddcutil args from the CLI. However, KDE Connect won't be able to run the script because sudo is required to run it.
To solve that, use the following C code to run the ddcutil command as a bash script inside a compiled executable:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
setuid(0);
// Monitor 1 on bus 6 -> DisplayPort
system("ddcutil -b 6 setvcp 0x60 0x0f");
// Monitor 2 on bus 7 -> DisplayPort
// Comment out the line below if you only have one monitor
system("ddcutil -b 7 setvcp 0x60 0x0f");
return 0;
}
The 0x60 hex code corresponds to the display source config, and the 0x0f hex code corresponds to the DisplayPort value.
Some common display sources are:
DisplayPort 1: 0x0f DisplayPort 2: 0x10 HDMI 1: 0x11 HDMI 2: 0x12 VGA: 0x01 USB-C: 0x1e
gcc -o show_displayport show_displayport.c
Then you need to set the executable to be in the "root" group with the correct permissions for it to be executable as an administrator. To do this, run the following command:
sudo chown root:root show_displayport
sudo chmod 4755 show_displayport
Finally, add the c executable as a command in KDE Connect so you can control it from your phone.
🎉 Now you can switch the source on one or multiple external monitors with ease!
To switch the display back, make another c file, update the 0x0f to another display source, and compile it.
For example, if you want to switch the display source back to HDMI 1, you can use the following c code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
setuid(0);
// Monitor 1 on bus 6 -> HDMI 1
system("ddcutil -b 6 setvcp 0x60 0x11");
// Monitor 2 on bus 7 -> HDMI 1
// Comment out the line below if you only have one monitor
system("ddcutil -b 7 setvcp 0x60 0x11");
return 0;
}
Then compile it with:
gcc -o show_hdmi1 show_hdmi1.c
And set the permissions with:
sudo chown root:root show_hdmi1
sudo chmod 4755 show_hdmi1
💯 Add that executable as a command in KDE Connect, and now you can switch between the two display sources with just a few button pushes on your phone!