Use phone/tablets/other laptops as external monitor with your laptop

This method is for wayland based systems. There are better ways to do this on GNOME or KDE desktops, but the method we are going to use is independent of DE/WM that you are using.

I am doing this on sway window manager, but you can try this on any other Wayland based WM or DE. I have not tried this on Xorg based systems, there are several other guides for Xorg based systems online.

When we connect a physical monitor to our laptops, it creates a second display output in our display settings that we can then re-arrange in layout, set resolution, set scale etc. Since we are not connecting via a physical interface like HDMI, DP, VGA etc. We need to create a virtual display within our system and set the display properties manually.

Get a list of current display outputs. You can also just check it in display settings of your DE/WM with wdisplays
rajudev@sanganak ~> swaymsg -t get_outputs
Output LVDS-1 'Seiko Epson Corporation 0x3047 Unknown' (focused)
  Current mode: 1366x768 @ 60.002 Hz
  Power: on
  Position: 0,0
  Scale factor: 1.000000
  Scale filter: nearest
  Subpixel hinting: rgb
  Transform: normal
  Workspace: 2
  Max render time: off
  Adaptive sync: disabled
  Allow tearing: no
  Available modes:
    1366x768 @ 60.002 Hz
Single physical display of the laptop

Currently we are seeing only one display output. Our goal is to create a second virtual display that we will then share on the tablet/phone.

To do this there are various tools available. We are using sway-vdctl . It is currently not available within Debian packages, so we need to install it manually.

$ git clone https://github.com/odincat/sway-vdctl.git
$ cd sway-vdctl
$ cargo build --release

This will generate the binary with the name main under target/release . We can then copy this binary to our bin folder.

$ sudo cp target/release/main /usr/local/bin/vdctl

Now we have the vdctl command available.

$ vdctl --help
Usage: vdctl [OPTIONS] <ACTION> [VALUE]

Arguments:
  <ACTION>
          Possible values:
          - create:      Create new output based on a preset
          - kill:        Terminate / unplug an active preset
          - list:        List out active presets
          - next-number: Manually set the next output number, in case something breaks
          - sync-number: Sync the next output number using 'swaymsg -t get_outputs'

  [VALUE]
          Preset name to apply, alternatively a value
          
          [default: ]

Options:
      --novnc
          do not launch a vnc server, just create the output

  -h, --help
          Print help (see a summary with '-h')

Before creating the virtual display, we need to set it's properties at .config/vdctl/config.json . I am using Xiaomi Pad 6 tablet as my external display. You can adjust the properties according to the device you want to use as a second display.

$ (text-editor) .config/vdctl/config.json

{
    "host": "0.0.0.0",
    "presets": [
        {
            "name": "pad6",
            "scale_factor": 2,
            "port": 9901,
            "resolution": {
                "width": 2800,
                "height": 1800
            }
      }
    ]
}

In the JSON, you can set the display resolution according to your external device and other configurations. If you want to configure multiple displays, you can add another entry into the presets in the json file. You can refer to example json file into the git repository.

Now we need to actually create the virtual monitor.

$ vdctl create pad6
Created output, presumably 'HEADLESS-1'
Set resolution of 'HEADLESS-1' to 2800x1800
Set scale factor of 'HEADLESS-1' to 2
Preset 'pad6' ('HEADLESS-1': 2800x1800) is now active on port 9901

Now if you will check the display outputs in your display settings or from command line, you will see two different displays.

$ swaymsg -t get_outputs
Output LVDS-1 'Seiko Epson Corporation 0x3047 Unknown'
  Current mode: 1366x768 @ 60.002 Hz
  Power: on
  Position: 0,0
  Scale factor: 1.000000
  Scale filter: nearest
  Subpixel hinting: rgb
  Transform: normal
  Workspace: 2
  Max render time: off
  Adaptive sync: disabled
  Allow tearing: no
  Available modes:
    1366x768 @ 60.002 Hz

Output HEADLESS-1 'Unknown Unknown Unknown' (focused)
  Current mode: 2800x1800 @ 0.000 Hz
  Power: on
  Position: 1366,0
  Scale factor: 2.000000
  Scale filter: nearest
  Subpixel hinting: unknown
  Transform: normal
  Workspace: 3
  Max render time: off
  Adaptive sync: disabled
  Allow tearing: no

Also in the display settings.

Display settings on Wayland with physical and virtual monitor output

Now we need to make this virtual display available over VNC which we will access with a VNC client on the tablet. To accomplish this I am using wayvnc but you can use any VNC server package.

Install wayvnc

$ sudo apt install wayvnc

Now we will serve our virtual display HEADLESS-1 with wayvnc.

$ wayvnc -o HEADLESS-1 0.0.0.0 5900

You can adjust the port number as per your need.

The process from laptop side is done.

Now install any VNC software on your tablet. I am using AVNC, which is available on F-Droid.

In the VNC software interface, add a new connection with the IP address of your laptop and the port started by wayvnc. Remember, both your laptop and phone need to be on the same Wi-Fi network.

AVNC interface with the connection details to connect to the virtual monitor.

Save and connect. Now you will be able to see a extended display on your tablet.

Enjoy working with multiple screens in a portable setup.

Till next time.. Have a great time.