diff options
Diffstat (limited to 'src/porting.cpp')
-rw-r--r-- | src/porting.cpp | 129 |
1 files changed, 122 insertions, 7 deletions
diff --git a/src/porting.cpp b/src/porting.cpp index 98b85b7d0..023f0cca7 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -75,11 +75,16 @@ bool * signal_handler_killstatus(void) #if !defined(_WIN32) // POSIX #include <signal.h> -void sigint_handler(int sig) +void signal_handler(int sig) { if (!g_killed) { - dstream << "INFO: sigint_handler(): " - << "Ctrl-C pressed, shutting down." << std::endl; + if (sig == SIGINT) { + dstream << "INFO: signal_handler(): " + << "Ctrl-C pressed, shutting down." << std::endl; + } else if (sig == SIGTERM) { + dstream << "INFO: signal_handler(): " + << "got SIGTERM, shutting down." << std::endl; + } // Comment out for less clutter when testing scripts /*dstream << "INFO: sigint_handler(): " @@ -88,13 +93,14 @@ void sigint_handler(int sig) g_killed = true; } else { - (void)signal(SIGINT, SIG_DFL); + (void)signal(sig, SIG_DFL); } } void signal_handler_init(void) { - (void)signal(SIGINT, sigint_handler); + (void)signal(SIGINT, signal_handler); + (void)signal(SIGTERM, signal_handler); } #else // _WIN32 @@ -252,7 +258,7 @@ bool getCurrentExecPath(char *buf, size_t len) //// Linux -#elif defined(linux) || defined(__linux) || defined(__linux__) +#elif defined(__linux__) bool getCurrentExecPath(char *buf, size_t len) { @@ -368,7 +374,7 @@ bool setSystemPaths() //// Linux -#elif defined(linux) || defined(__linux) +#elif defined(__linux__) bool setSystemPaths() { @@ -605,6 +611,115 @@ void setXorgClassHint(const video::SExposedVideoData &video_data, #endif } +bool setXorgWindowIcon(IrrlichtDevice *device) +{ +#ifdef XORG_USED +# if RUN_IN_PLACE + return setXorgWindowIconFromPath(device, + path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png"); +# else + // We have semi-support for reading in-place data if we are + // compiled with RUN_IN_PLACE. Don't break with this and + // also try the path_share location. + return + setXorgWindowIconFromPath(device, + ICON_DIR "/hicolor/128x128/apps/" PROJECT_NAME ".png") || + setXorgWindowIconFromPath(device, + path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png"); +# endif +#else + return false; +#endif +} + +bool setXorgWindowIconFromPath(IrrlichtDevice *device, + const std::string &icon_file) +{ +#ifdef XORG_USED + + video::IVideoDriver *v_driver = device->getVideoDriver(); + + video::IImageLoader *image_loader = NULL; + u32 cnt = v_driver->getImageLoaderCount(); + for (u32 i = 0; i < cnt; i++) { + if (v_driver->getImageLoader(i)->isALoadableFileExtension(icon_file.c_str())) { + image_loader = v_driver->getImageLoader(i); + break; + } + } + + if (!image_loader) { + warningstream << "Could not find image loader for file '" + << icon_file << "'" << std::endl; + return false; + } + + io::IReadFile *icon_f = device->getFileSystem()->createAndOpenFile(icon_file.c_str()); + + if (!icon_f) { + warningstream << "Could not load icon file '" + << icon_file << "'" << std::endl; + return false; + } + + video::IImage *img = image_loader->loadImage(icon_f); + + if (!img) { + warningstream << "Could not load icon file '" + << icon_file << "'" << std::endl; + icon_f->drop(); + return false; + } + + u32 height = img->getDimension().Height; + u32 width = img->getDimension().Width; + + size_t icon_buffer_len = 2 + height * width; + long *icon_buffer = new long[icon_buffer_len]; + + icon_buffer[0] = width; + icon_buffer[1] = height; + + for (u32 x = 0; x < width; x++) { + for (u32 y = 0; y < height; y++) { + video::SColor col = img->getPixel(x, y); + long pixel_val = 0; + pixel_val |= (u8)col.getAlpha() << 24; + pixel_val |= (u8)col.getRed() << 16; + pixel_val |= (u8)col.getGreen() << 8; + pixel_val |= (u8)col.getBlue(); + icon_buffer[2 + x + y * width] = pixel_val; + } + } + + img->drop(); + icon_f->drop(); + + const video::SExposedVideoData &video_data = v_driver->getExposedVideoData(); + + Display *x11_dpl = (Display *)video_data.OpenGLLinux.X11Display; + + if (x11_dpl == NULL) { + warningstream << "Could not find x11 display for setting its icon." + << std::endl; + delete [] icon_buffer; + return false; + } + + Window x11_win = (Window)video_data.OpenGLLinux.X11Window; + + Atom net_wm_icon = XInternAtom(x11_dpl, "_NET_WM_ICON", False); + Atom cardinal = XInternAtom(x11_dpl, "CARDINAL", False); + XChangeProperty(x11_dpl, x11_win, + net_wm_icon, cardinal, 32, + PropModeReplace, (const unsigned char *)icon_buffer, + icon_buffer_len); + + delete [] icon_buffer; + +#endif + return true; +} //// //// Video/Display Information (Client-only) |