Sway: no wl output

  • I’m using a script to detect changes in a region of the screen and produce a sound when the change happens.
    link to original script

  • Sometimes I need to switch to a Windows PC connected to my only monitor. I do that via a USB switch. I need the script to continue running even when the monitor is no longer connected to the Linux machine.

  • The above code works in i3wm but not in Sway (error: “no wl output”).

How do I make it work on Sway, i.e. is this related to output commands in Sway, and how?

Do you have slurp and grim installed?

Never mind. I just glanced through the script. It will output a “not installed” error message if you don’t have those commands installed.

yeah I have. The script works fine in Sway, provided I don’t switch PC.

I read through the code. The script probably failed due to the fact that it relies on grim to capture pixels from your outputs. Here’s what I think happened: when you used the USB switch to connect the monitor to your windows laptop, the Sway compositor no longer detects the output connected to your system. However, the script works by storing the pixel coordinates that you initially selected and then repeatedly passing those coordinates to grim to take screenshots. The problem is that those pixel coordinates are no longer valid after you disconnected the output. That’s why grim exits with a “no wl output” error.

Here’s what you can do to test out the theory:

  1. Connected the monitor to your linux laptop (the one that’s running sway)
  2. Open up a terminal and run
$ slurp
  1. Select a rectangle on the external monitor
  2. After step 3, slurp will return a pixel coordinate and a set of dimensions (these parameters describe the rectangle you just selected). For example: 800, 100 300x200.
  3. Remember the numbers obtained in step 4.
  4. Now, disconnect the output from your system.
  5. Open another terminal and run grim with the -g flag and pass those numbers you obtained from step 4 into the command. (Refer to man grim if you aren’t sure how to use the -g flag)

If my theory is correct, you should see a similar no wl ouput error after step 7.

You can probably tweak the script to account for output disconnections. Just store the initial number of outputs inside a shell variable (you can obtain this information simply by parsing the output of the swaymsg -t get_outputs command), and then add a simple check inside the while loop to make sure that the number of connected outputs are the same before attempting to take a screenshot with grim.

Not sure what you mean at step 3: I only have one monitor shared via a hardware switch and the second PC run Windows.

I’ll try editing the script as you suggest to account for output disconnections.