SkillAgentSearch skills...

TransparentWindows

Example of how to create non-rectangular semi-transparent windows (cross-platform)

Install / Use

/learn @texus/TransparentWindows
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Transparent Windows

This repository contains an example of how to create non-rectangular semi-transparent windows on multiple operating systems with SFML (which is only used to load the image and display the result). It loads an image with transparent parts, uses this image to set the shape of the window and draws the image on the window. The code also contains an opacity variable to set the opacity of the window.

The code works for Windows, Linux and macOS.

Feel free to send pull requests to improve the code.

Compiling

Linux:

g++ Transparent.cpp -lsfml-graphics -lsfml-window -lsfml-system -lX11 -lXext

macOS:

If you installed SFML manually (Frameworks):

clang++ Transparent.cpp Transparent.mm -framework sfml-graphics -framework sfml-window -framework sfml-system -framework Cocoa

If you installed SFML via Homebrew:

clang++ Transparent.cpp Transparent.mm \
  -I$(brew --prefix sfml@2)/include \
  -L$(brew --prefix sfml@2)/lib \
  -lsfml-graphics -lsfml-window -lsfml-system \
  -framework Cocoa \
  -std=c++17

Windows:

No special libraries are needed for the transparency. You should just compile Transparent.cpp and link to sfml the way you do it for your own programs.

Translucent windows

This code in this project works by using a fully opaque image and then applying an alpha value over all the visible pixels, it does not support per-pixel alpha. If you want to use a transparent image and set the alpha values of the window like in the image then check the following resources:

  • Windows: I wrote an implementation for Windows using the UpdateLayeredWindow function.

  • Linux: I found this gist which can be changed to use per-pixel alpha. Adapting it to use SFML only worked when creating the sf::RenderWindow from the created Xlib Window, but not the other way around. If you manage to get it working on linux with a window created by SFML then please let me know.

  • macOS: The code in this repository already supports translucent windows for macOS! You can just replace the image with a transparent one and it will work.

View on GitHub
GitHub Stars50
CategoryDevelopment
Updated1mo ago
Forks5

Languages

C++

Security Score

95/100

Audited on Feb 24, 2026

No findings