Kanshi

kanshi allows you to define output profiles that are automatically enabled and disabled on hotplug. For instance, this can be used to turn a laptop's internal screen off when docked.

This is a Wayland equivalent for tools like autorandr. kanshi can be used on Wayland compositors supporting the wlr-output-management protocol.

Installation

Install kanshi or kanshi-gitAUR.

Configuration

Create kanshi configuration file:

~/.config/kanshi/config
profile {
	output LVDS-1 disable
	output "Some Company ASDF 4242" mode 1600x900 position 0,0
}

profile {
	output LVDS-1 enable scale 2
}

Each output profile is delimited by brackets. It contains several output directives (whose syntax is similar to sway-output(5)). A profile will be enabled if all of the listed outputs are connected.

Tip: You can get a list of output names and additional information using the command swaymsg -t get_outputs.

Usage

Run the command:

$ kanshi

See #Manage kanshi with systemd for an automated usage.

Tips and tricks

Manage kanshi with systemd

Create and start ~/.config/systemd/user/sway-session.target (if you don't have created yet) by following Sway#Manage Sway-specific daemons with systemd.

Create the kanshi.service file:

~/.config/systemd/user/kanshi.service
[Unit]
Description=Dynamic output configuration for Wayland compositors
Documentation=https://sr.ht/~emersion/kanshi
BindsTo=sway-session.target

[Service]
Type=simple
ExecStart=/usr/bin/kanshi

[Install]
WantedBy=sway-session.target

Enable this user unit. It is only activated when Sway is running and deactivated when Sway stops.

Troubleshooting

Workspace number starts from 2 in external monitor after wake up

If you have a configuration like above, when you connected a second display to your computer, the workspace in the second display should start from 1 since the first display is disabled. This should be the case when you plugged your monitor in the first time or after starting the system. But after sleep, this number might be 2. In this case just move the first workspace to this monitor by adding a directive to the kanshi configuration file:

~/.config/kanshi/config
profile {
	output LVDS-1 disable
	output "Some Company ASDF 4242" mode 1600x900 position 0,0
	# We've added this directive here (do not forget to update the output name):
	exec swaymsg workspace 1, move workspace to HDMI-A-1
}

profile {
	output LVDS-1 enable scale 2
}

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.