From ab7a5c4ff138c39a2491592731d677c9f392caa0 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 24 Jun 2016 20:43:29 +0200 Subject: Also shut down when SIGTERM was received Fixes #4251 --- src/porting.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/porting.cpp') diff --git a/src/porting.cpp b/src/porting.cpp index 98b85b7d0..7ded58b3f 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -75,11 +75,16 @@ bool * signal_handler_killstatus(void) #if !defined(_WIN32) // POSIX #include -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 -- cgit v1.2.3 From 1dfd977ec43370da6931b11a8d0469792c8ebc36 Mon Sep 17 00:00:00 2001 From: Rogier-5 Date: Mon, 4 Jul 2016 21:00:57 +0200 Subject: Fix & make linux conditionals uniform (#4278) The source used a hodge-podge of different combinations of different macros to check for linux: 'linux', '__linux', '__linux__'. As '__linux__' is standard (Posix), and the others are not, the source now uniformly uses __linux__. If either linux or __linux are defined, it is made sure that __linux__ is defined as well. --- src/guiChatConsole.cpp | 2 +- src/intlGUIEditBox.cpp | 2 +- src/porting.cpp | 4 ++-- src/porting.h | 8 ++++++-- src/threading/thread.cpp | 8 ++++---- 5 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src/porting.cpp') diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index bb58d1305..8dd5ab032 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -630,7 +630,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) } else if(event.KeyInput.Char != 0 && !event.KeyInput.Control) { - #if (defined(linux) || defined(__linux)) + #if (defined(__linux__)) wchar_t wc = L'_'; mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) ); prompt.input(wc); diff --git a/src/intlGUIEditBox.cpp b/src/intlGUIEditBox.cpp index 33bf8a13c..29f828076 100644 --- a/src/intlGUIEditBox.cpp +++ b/src/intlGUIEditBox.cpp @@ -271,7 +271,7 @@ bool intlGUIEditBox::OnEvent(const SEvent& event) break; case EET_KEY_INPUT_EVENT: { -#if (defined(linux) || defined(__linux) || defined(__FreeBSD__)) +#if (defined(__linux__) || defined(__FreeBSD__)) // ################################################################ // ValkaTR: // This part is the difference from the original intlGUIEditBox diff --git a/src/porting.cpp b/src/porting.cpp index 7ded58b3f..02ce6174b 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -258,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) { @@ -374,7 +374,7 @@ bool setSystemPaths() //// Linux -#elif defined(linux) || defined(__linux) +#elif defined(__linux__) bool setSystemPaths() { diff --git a/src/porting.h b/src/porting.h index 4d51c5058..d101a7324 100644 --- a/src/porting.h +++ b/src/porting.h @@ -60,7 +60,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include //for uintptr_t - #if (defined(linux) || defined(__linux) || defined(__GNU__)) && !defined(_GNU_SOURCE) + // Use standard Posix macro for Linux + #if (defined(linux) || defined(__linux)) && !defined(__linux__) + #define __linux__ + #endif + #if (defined(__linux__) || defined(__GNU__)) && !defined(_GNU_SOURCE) #define _GNU_SOURCE #endif @@ -321,7 +325,7 @@ inline const char *getPlatformName() return #if defined(ANDROID) "Android" -#elif defined(linux) || defined(__linux) || defined(__linux__) +#elif defined(__linux__) "Linux" #elif defined(_WIN32) || defined(_WIN64) "Windows" diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp index 5161a6c01..0cd536795 100644 --- a/src/threading/thread.cpp +++ b/src/threading/thread.cpp @@ -54,7 +54,7 @@ DEALINGS IN THE SOFTWARE. // for setName -#if defined(linux) || defined(__linux) +#if defined(__linux__) #include #elif defined(__FreeBSD__) || defined(__OpenBSD__) #include @@ -70,7 +70,7 @@ DEALINGS IN THE SOFTWARE. // for bindToProcessor #if __FreeBSD_version >= 702106 typedef cpuset_t cpu_set_t; -#elif defined(__linux) || defined(linux) +#elif defined(__linux__) #include #elif defined(__sun) || defined(sun) #include @@ -261,7 +261,7 @@ DWORD WINAPI Thread::threadProc(LPVOID param) void Thread::setName(const std::string &name) { -#if defined(linux) || defined(__linux) +#if defined(__linux__) // It would be cleaner to do this with pthread_setname_np, // which was added to glibc in version 2.12, but some major @@ -363,7 +363,7 @@ bool Thread::bindToProcessor(unsigned int proc_number) return SetThreadAffinityMask(getThreadHandle(), 1 << proc_number); -#elif __FreeBSD_version >= 702106 || defined(__linux) || defined(linux) +#elif __FreeBSD_version >= 702106 || defined(__linux__) cpu_set_t cpuset; -- cgit v1.2.3 From 5d4d3f8366b74d9c3da892d94188defc49407ebf Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 4 Jul 2016 01:33:46 +0200 Subject: Finally set a window icon on X11 Since the creation of minetest, it had no window icon on X11. Now we have one. The misc/minetest-xorg-icon-128.png file is a rendering of the misc/minetest.svg file with inkscape, created with something like: inkscape -z -e misc/minetest-xorg-icon-128.png -w 128 -h 128 misc/minetest.svg --- misc/minetest-xorg-icon-128.png | Bin 0 -> 11241 bytes src/client/clientlauncher.cpp | 3 ++ src/porting.cpp | 87 ++++++++++++++++++++++++++++++++++++++++ src/porting.h | 3 ++ 4 files changed, 93 insertions(+) create mode 100644 misc/minetest-xorg-icon-128.png (limited to 'src/porting.cpp') diff --git a/misc/minetest-xorg-icon-128.png b/misc/minetest-xorg-icon-128.png new file mode 100644 index 000000000..0241a911c Binary files /dev/null and b/misc/minetest-xorg-icon-128.png differ diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index a0781ef37..aa3c2d548 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -114,6 +114,9 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C); + porting::setXorgWindowIcon(device, + porting::path_share + "/misc/minetest-xorg-icon-128.png"); + /* This changes the minimum allowed number of vertices in a VBO. Default is 500. diff --git a/src/porting.cpp b/src/porting.cpp index 02ce6174b..ddf8139ea 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -611,6 +611,93 @@ void setXorgClassHint(const video::SExposedVideoData &video_data, #endif } +bool setXorgWindowIcon(IrrlichtDevice *device, + const std::string &icon_file) +{ +#ifdef XORG_USED + + video::IVideoDriver *v_driver = device->getVideoDriver(); + + video::IImageLoader *image_loader = NULL; + for (u32 i = v_driver->getImageLoaderCount() - 1; i >= 0; 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; + + return true; +#endif +} //// //// Video/Display Information (Client-only) diff --git a/src/porting.h b/src/porting.h index d101a7324..40f6b4dc3 100644 --- a/src/porting.h +++ b/src/porting.h @@ -367,6 +367,9 @@ inline const char *getPlatformName() void setXorgClassHint(const video::SExposedVideoData &video_data, const std::string &name); +bool setXorgWindowIcon(IrrlichtDevice *device, + const std::string &icon_file); + // This only needs to be called at the start of execution, since all future // threads in the process inherit this exception handler void setWin32ExceptionHandler(); -- cgit v1.2.3 From 795f1c75cb6e337984cccd042371cb8b9a3ef6c1 Mon Sep 17 00:00:00 2001 From: Jay Arndt Date: Wed, 6 Jul 2016 20:15:36 -0500 Subject: Fix warning in porting::setXorgWindowIcon when building without X11 (#4288) --- src/porting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/porting.cpp') diff --git a/src/porting.cpp b/src/porting.cpp index ddf8139ea..15a18bdfb 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -695,8 +695,8 @@ bool setXorgWindowIcon(IrrlichtDevice *device, delete [] icon_buffer; - return true; #endif + return true; } //// -- cgit v1.2.3 From 9edc984b090ca585c0850fa05e0cecac86679638 Mon Sep 17 00:00:00 2001 From: est31 Date: Wed, 3 Aug 2016 23:20:36 +0200 Subject: Porting: Fix endless loop if image format is not recognized --- src/porting.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/porting.cpp') diff --git a/src/porting.cpp b/src/porting.cpp index 15a18bdfb..acd047232 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -619,7 +619,8 @@ bool setXorgWindowIcon(IrrlichtDevice *device, video::IVideoDriver *v_driver = device->getVideoDriver(); video::IImageLoader *image_loader = NULL; - for (u32 i = v_driver->getImageLoaderCount() - 1; i >= 0; i--) { + 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; -- cgit v1.2.3 From f092dac9793b80c29a669b0d676ee3e4f55f682e Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 20 Aug 2016 21:26:44 +0200 Subject: Also support X11 icon for minetest copies installed via make install (#4407) Fixes #4323. --- CMakeLists.txt | 3 +++ src/client/clientlauncher.cpp | 3 +-- src/cmake_config.h.in | 1 + src/porting.cpp | 19 ++++++++++++++++++- src/porting.h | 4 +++- 5 files changed, 26 insertions(+), 4 deletions(-) (limited to 'src/porting.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 592feb997..fbf6bb7fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,6 +175,9 @@ if(UNIX AND NOT APPLE) install(FILES "misc/minetest.desktop" DESTINATION "${XDG_APPS_DIR}") install(FILES "misc/minetest.appdata.xml" DESTINATION "${APPDATADIR}") install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps") + install(FILES "misc/minetest-xorg-icon-128.png" + DESTINATION "${ICONDIR}/hicolor/128x128/apps" + RENAME "minetest.png") endif() if(APPLE) diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index aa3c2d548..6145e3dde 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -114,8 +114,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C); - porting::setXorgWindowIcon(device, - porting::path_share + "/misc/minetest-xorg-icon-128.png"); + porting::setXorgWindowIcon(device); /* This changes the minimum allowed number of vertices in a VBO. diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index 50f34a0b8..4b731020a 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -14,6 +14,7 @@ #define STATIC_SHAREDIR "@SHAREDIR@" #define STATIC_LOCALEDIR "@LOCALEDIR@" #define BUILD_TYPE "@CMAKE_BUILD_TYPE@" +#define ICON_DIR "@ICONDIR@" #cmakedefine01 RUN_IN_PLACE #cmakedefine01 USE_GETTEXT #cmakedefine01 USE_CURL diff --git a/src/porting.cpp b/src/porting.cpp index acd047232..ae9114ac8 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -611,7 +611,24 @@ void setXorgClassHint(const video::SExposedVideoData &video_data, #endif } -bool setXorgWindowIcon(IrrlichtDevice *device, +bool setXorgWindowIcon(IrrlichtDevice *device) +{ +#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 +} + +bool setXorgWindowIconFromPath(IrrlichtDevice *device, const std::string &icon_file) { #ifdef XORG_USED diff --git a/src/porting.h b/src/porting.h index 40f6b4dc3..f5c7efcb2 100644 --- a/src/porting.h +++ b/src/porting.h @@ -367,7 +367,9 @@ inline const char *getPlatformName() void setXorgClassHint(const video::SExposedVideoData &video_data, const std::string &name); -bool setXorgWindowIcon(IrrlichtDevice *device, +bool setXorgWindowIcon(IrrlichtDevice *device); + +bool setXorgWindowIconFromPath(IrrlichtDevice *device, const std::string &icon_file); // This only needs to be called at the start of execution, since all future -- cgit v1.2.3 From 33a606c034a6dfea4a011b6d69077455bbb56746 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 30 Sep 2016 14:30:37 +0200 Subject: Fix android build Fixes #4493. --- src/porting.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/porting.cpp') diff --git a/src/porting.cpp b/src/porting.cpp index ae9114ac8..f0337b610 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -613,10 +613,11 @@ void setXorgClassHint(const video::SExposedVideoData &video_data, bool setXorgWindowIcon(IrrlichtDevice *device) { -#if RUN_IN_PLACE +#ifdef XORG_USED +# if RUN_IN_PLACE return setXorgWindowIconFromPath(device, path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png"); -#else +# 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. @@ -625,6 +626,8 @@ bool setXorgWindowIcon(IrrlichtDevice *device) ICON_DIR "/hicolor/128x128/apps/" PROJECT_NAME ".png") || setXorgWindowIconFromPath(device, path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png"); +# endif + return false; #endif } -- cgit v1.2.3 From fcfa418c4cb5c3490413dd345e5e4b998cb7a4c3 Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 3 Oct 2016 15:55:15 +0200 Subject: Fix build/warning on non X11 platforms --- src/porting.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/porting.cpp') diff --git a/src/porting.cpp b/src/porting.cpp index f0337b610..023f0cca7 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -627,6 +627,7 @@ bool setXorgWindowIcon(IrrlichtDevice *device) setXorgWindowIconFromPath(device, path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png"); # endif +#else return false; #endif } -- cgit v1.2.3