Blurred screenshot

Achieving Window Transparency and Overlay for Linux Users

In today's fast-paced world, both productivity and entertainment can benefit from the art of multitasking. By overlaying video content or other content on top of applications, you can enhance your workflow or recreational experiences. Linux offers powerful tools like mpv, streamlink and your window manager that make this possible. 

Imagine you are working diligently on an important project and need a video tutorial to guide you through specific tasks. With the techniques outlined in this blog post, you can watch the tutorial while simultaneously interacting with your work software – increasing efficiency and reducing context switching. Similarly, if you enjoy gaming but also want to stay connected with teammates during multiplayer sessions or follow a live stream for inspiration, overlaying applications allows you to do so without leaving your game. Multitasking has become as much a skill as a convenient way to improve both productivity and entertainment comfort in our digital world.

This functionality is like having Firefox's picture-in-picture feature but for all your windows – providing unparalleled flexibility and convenience.

Tools You'll Need:

  1. mpv: A powerful media player that supports a wide range of video formats and can be controlled via the command line.
  2. streamlink: A command-line utility that pipes video streams from various services into a video player.
  3. Window Manager: Any Linux window manager that supports the "always on top" function. Popular choices include i3, Openbox, or even GNOME with extensions like "Always on Top". I'm using Budgie desktop environment.
  4. xprop: A utility for retrieving and setting X window system properties.

Step 1: Install Required Software

If you haven't already installed mpv and streamlink, you can do so using your package manager. For example, on Debian-based systems:

sudo apt update && sudo apt install mpv streamlink xprop

Step 2: Launch the video content using Mpv or Streamlink

Open a new terminal window to avoid interfering with the overlay, preferably in tmux if you want to close the window but keep your terminal running headless. The launch a video file or the stream you want to watch:

  • For a local video file: mpv --no-border <path_to_video_file>

  • For an online video or live stream: streamlink https://www.twitch.tv/<streamer_id> 480p

Side note : you can configure mpv and Streamlink. By default Streamlink use vlc you can add player=mpv to .config/streamlink/config to use mpv or any other video player.

Other side note: Streamlink can play more than just twitch stream.

Step 3: Set the Window to "Always on Top" 

This step depends on your window manager. You need to find the option to set the window to always stay on top of other windows. In most window managers, you can right-click on the window title bar or use a keyboard shortcut to access this option.

If your WM doesn't show any option for it you can use wmctrland xwininfo:

xwin=$(xwininfo | grep -oP 'Window id: \K0x[0-9a-f]+'); wmctrl -i -r "$xwin" -b add,above

"Ask ubuntu" source.

Step 4: Adjust Window Opacity

If you want to see through the any window and view the content beneath it, use the following command in your terminal or bind it to a keyboard shortcut to control the opacity of the mpv window (or any window):

xprop -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * 60 / 100)))

Your cursor should have change for a cross, just click the window you want to make transparent.

This command sets the window's opacity to 60%, allowing you to see through it while maintaining visibility of the underlying content. You can adjust the percentage value to your desired level.

Conclusion

With the right tools and a bit of know-how, overlaying a video on top of your applications in Linux is entirely achievable. By leveraging utilities like mpv, streamlink, and xprop, along with the "always on top" function of your window manager, you can create a seamless multitasking experience tailored to your needs. So go ahead, give it a try, and enhance your productivity on Linux!