The python script wl-togglescreens will help you to quickly switch monitor modes on Wayland. You can execute it directly or via keybindings to turn the internal or external screen on and off.

The script will detect any external monitor and switches between 3 states: Only main screen enabled, only external screen enabled or both enabled whereas the secondary screen has its on workspace. I’m not sure if it is possible to mirror screens on Wayland or how to achieve this.

If you want to install this on NixOS, you could add the script as a Flakes package to your system configuration. One dependency is the program wlr-randr, which will be also installed by Flakes.

{
  inputs = {
    [...]
    wl-togglescreens.url = "git+https://git.project-insanity.org/onny/wl-togglescreens.git?ref=main";
  };

  outputs = {self, nixpkgs, ...}@inputs: {
    nixosConfigurations.myhost = inputs.nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs.inputs = inputs;
      [...]

Configuring keybindings of window managers like sway is possible in NixOS using home-manager. The execution of the script can be mapped to one of the usual FN-keys, for example XF86Display

{ config, pkgs, lib, inputs, ... }:{
  home-manager.users.onny = {
    programs = {
      [...]
      wayland.windowManager.sway = {
        enable = true;
        config = {
          [...]
          keybindings = lib.mkOptionDefault{
            [...]
            "XF86Display" = "exec ${inputs.wl-togglescreens.packages.x86_64-linux.wl-togglescreens}/bin/wl-togglescreens";
          };
        };
      };
    };
X86Display keybinding

For further reference, my complete system configuration is available here.

💬 Are you interested in our work or have some questions? Join us in our public Signal chat pi crew 👋
🪙 If you like our work or want to supprot us, you can donate MobileCoins to our address.