haimgel / display-switch

Turn a $30 USB switch into a full-featured multi-monitor KVM switch
https://haim.dev/posts/2020-07-28-dual-monitor-kvm/
MIT License
2.85k stars 112 forks source link

Linux support #22

Closed haimgel closed 3 years ago

haimgel commented 3 years ago

Some preliminary Linux support

Things that seem to be working

The app detected USB changes and changed display inputs based on that. I tested this on Raspberry Pi 3, don't have a normal Linux desktop.

Things that do not work / missing

Ref: #22

universal commented 3 years ago

trying this out under ubuntu 20.04/popos, and for now:

switching usb device away and back to this machine:

11:23:26 [INFO] Display '22794' #0 is currently set to 0xf
11:23:35 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0bda:0411"
11:23:35 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "045e:082a"
11:23:35 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:0891"
11:23:36 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "046d:c33c"
11:23:36 [DEBUG] (1) display_switch::app: Detected device change. Removed device: "0bda:5411"
11:23:43 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0bda:5411"
11:23:44 [DEBUG] (1) display_switch::app: Detected device change. Added device: "0bda:0411"
11:23:45 [DEBUG] (1) display_switch::app: Detected device change. Added device: "045e:082a"
11:23:45 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:0891"
11:23:45 [DEBUG] (1) display_switch::app: Detected device change. Added device: "046d:c33c"
11:23:45 [INFO] Detected device we're looking for "046d:c33c"
11:23:45 [DEBUG] (1) display_switch::platform::display_control_ddc_hi: Setting display ''22794' #0' to 0xf
11:23:45 [INFO] Display '22794' #0 set to 0xf

looks good and works for me just fine, as I've only one display directly connected and the other is daisy-chained via displayport :-)

haimgel commented 3 years ago

@universal thanks for testing! Did you happen to notice the permissions / ownership of /dev/i2c-* before you changed it?

We'll need a more permanent solution as this chown is not going to survive a reboot.

universal commented 3 years ago

yep, should be root:root . there are guides for creating udev rules and adding a new usergroup that would provide a more permanent solution. I have been busy with other stuff, but I will crosscheck if it stays across a reboot. I suspect kernel-updates potentially also change the device, but will check that as well.

universal commented 3 years ago

so I just checked:

haimgel commented 3 years ago

@universal thanks for checking, makes sense!

I think going forward, the best approach would be building a deb / rpm package to install the app system-wide, with the config in /etc, logging to system logs normally and running under root with systemd. This would sidestep the whole permissions issue completely.

I created #26, #27, #28, that all together should make Linux support more decent, but this PR seems to work good enough for now, will merge it.

tdryer commented 3 years ago

ubuntu/popos don't appear to have a dedicated i2c group by default

You can get an i2c group on Ubuntu by installing the i2c-tools package, which comes with a udev rule.

Then you just need to add your user to the group, and log out for it to take effect:

sudo usermod $USER -aG i2c