diff --git a/main.cpp b/main.cpp index 0cc523f..2df67c5 100644 --- a/main.cpp +++ b/main.cpp @@ -8,8 +8,12 @@ #include #include #include +#include #include "GLFW/glfw3.h" +#include +#include + #include "WallpaperEngine/Core/CProject.h" #include "WallpaperEngine/Render/CWallpaper.h" #include "WallpaperEngine/Render/CContext.h" @@ -54,6 +58,26 @@ std::string stringPathFixes(const std::string& s) return std::move (str); } +void free_display_wallpaper(int sig) +{ + Display* display = XOpenDisplay (nullptr); + Window root = DefaultRootWindow(display); + // create a blank pm to reset compositors values, compositors will render as a blank X window. + Pixmap pm = XCreatePixmap(display, root, 1, 1, 1); + Atom prop_root = XInternAtom(display, "_XROOTPMAP_ID", False); + Atom prop_esetroot = XInternAtom(display, "ESETROOT_PMAP_ID", False); + XChangeProperty(display, root, prop_root, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pm, 1); + XChangeProperty(display, root, prop_esetroot, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pm, 1); + XFreePixmap(display, pm); + // set background to black. Only needed if no compositors are running + XSetWindowBackground(display, root, 0); + // sync changes before exiting + XClearWindow(display, root); + XFlush(display); + XCloseDisplay(display); + exit(sig); +} + int main (int argc, char* argv[]) { std::vector screens; @@ -145,6 +169,14 @@ int main (int argc, char* argv[]) // ensure the path has a trailing slash + // Attach signals for unexpected killing of program by user. We need to reset the + // screen otherwise the background will remain the last frame on sigterm or sigint. + if (!screens.empty()) + { + std::signal(SIGINT, free_display_wallpaper); + std::signal(SIGTERM, free_display_wallpaper); + } + // first of all, initialize the window if (glfwInit () == GLFW_FALSE) {