From c7434afed8227e4a53b2b9e57030cefc841e4d24 Mon Sep 17 00:00:00 2001 From: unitrunker Date: Sun, 21 Jan 2018 23:41:52 -0600 Subject: [PATCH 01/13] NANA_POSIX for bits common to Linux, MacOS and BSD. OSS sound as fall-back for POSIX. Cheat for detecting default browser on POSIX. --- include/nana/audio/detail/audio_device.hpp | 13 +- include/nana/audio/detail/audio_stream.hpp | 4 +- .../nana/audio/detail/buffer_preparation.hpp | 4 +- include/nana/c++defines.hpp | 28 ++- include/nana/filesystem/filesystem_ext.hpp | 14 +- include/nana/gui/detail/basic_window.hpp | 12 +- include/nana/gui/detail/bedrock.hpp | 12 +- include/nana/gui/detail/window_manager.hpp | 2 +- include/nana/system/platform.hpp | 2 +- source/audio/detail/audio_device.cpp | 212 +++++++++++++++++- source/audio/detail/buffer_preparation.cpp | 5 +- source/charset.cpp | 26 +-- source/deploy.cpp | 7 +- source/detail/platform_spec_posix.cpp | 12 +- source/detail/platform_spec_selector.hpp | 4 +- source/detail/posix/msg_dispatcher.hpp | 24 +- source/detail/posix/platform_spec.hpp | 3 +- source/filesystem/filesystem.cpp | 44 ++-- source/gui/detail/bedrock_pi.cpp | 14 +- source/gui/detail/bedrock_posix.cpp | 46 ++-- source/gui/detail/window_manager.cpp | 20 +- source/gui/notifier.cpp | 2 +- source/gui/timer.cpp | 2 +- source/paint/graphics.cpp | 12 +- source/system/platform.cpp | 43 +++- source/system/shared_wrapper.cpp | 14 +- source/system/timepiece.cpp | 8 +- source/threads/pool.cpp | 2 +- 28 files changed, 415 insertions(+), 176 deletions(-) diff --git a/include/nana/audio/detail/audio_device.hpp b/include/nana/audio/detail/audio_device.hpp index ef3b9934..915d6780 100644 --- a/include/nana/audio/detail/audio_device.hpp +++ b/include/nana/audio/detail/audio_device.hpp @@ -9,8 +9,10 @@ #include #if defined(NANA_WINDOWS) #include +#elif defined(NANA_POSIX) + #include #elif defined(NANA_LINUX) - #include + #include #endif namespace nana{ namespace audio @@ -34,7 +36,6 @@ namespace nana{ namespace audio static void __stdcall _m_dev_callback(HWAVEOUT handle, UINT msg, audio_device * self, DWORD_PTR, DWORD_PTR); #endif - #if defined(NANA_WINDOWS) HWAVEOUT handle_; std::recursive_mutex queue_lock_; @@ -45,6 +46,12 @@ namespace nana{ namespace audio std::size_t channels_; std::size_t bytes_per_sample_; std::size_t bytes_per_frame_; +#elif defined(NANA_POSIX) + int handle_; + int rate_; + int channels_; + int bytes_per_sample_; + int bytes_per_frame_; #endif buffer_preparation * buf_prep_; }; @@ -54,4 +61,4 @@ namespace nana{ namespace audio }//end namespace nana #endif //NANA_ENABLE_AUDIO -#endif \ No newline at end of file +#endif diff --git a/include/nana/audio/detail/audio_stream.hpp b/include/nana/audio/detail/audio_stream.hpp index 72734ec9..6b0a56af 100644 --- a/include/nana/audio/detail/audio_stream.hpp +++ b/include/nana/audio/detail/audio_stream.hpp @@ -33,7 +33,7 @@ namespace nana{ namespace audio{ unsigned short wBitsPerSample; }; #pragma pack() - #elif defined(NANA_LINUX) + #elif defined(NANA_POSIX) struct master_riff_chunk { unsigned ckID; //"RIFF" @@ -83,4 +83,4 @@ namespace nana{ namespace audio{ }//end namespace audio }//end namespace nana #endif //NANA_ENABLE_AUDIO -#endif \ No newline at end of file +#endif diff --git a/include/nana/audio/detail/buffer_preparation.hpp b/include/nana/audio/detail/buffer_preparation.hpp index 501b8736..57e6f32e 100644 --- a/include/nana/audio/detail/buffer_preparation.hpp +++ b/include/nana/audio/detail/buffer_preparation.hpp @@ -32,7 +32,7 @@ namespace nana{ namespace audio public: #if defined(NANA_WINDOWS) typedef WAVEHDR meta; -#elif defined(NANA_LINUX) +#elif defined(NANA_POSIX) struct meta { char * buf; @@ -66,4 +66,4 @@ namespace nana{ namespace audio }//end namespace audio }//end namespace nana #endif //NANA_ENABLE_AUDIO -#endif \ No newline at end of file +#endif diff --git a/include/nana/c++defines.hpp b/include/nana/c++defines.hpp index 04b5113f..f4aa89f6 100644 --- a/include/nana/c++defines.hpp +++ b/include/nana/c++defines.hpp @@ -68,9 +68,16 @@ # endif #endif +// Set this to "UTF-32" at the command-line for big endian. +#ifndef NANA_UNICODE + // much of the world runs intel compatible processors so default to LE. + #define NANA_UNICODE "UTF-32LE" +#endif + // Select platform ...... #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) //Microsoft Windows #define NANA_WINDOWS + typedef DWORD_PTR thread_t; // MINGW ... #if defined(__MINGW32__) || defined(__MINGW64__) || defined(MINGW) @@ -79,24 +86,23 @@ #elif defined(APPLE) //Mac OS X //Symbols for MACOS - #define NANA_MACOS + #define NANA_POSIX #define NANA_X11 - + typedef long long thread_t; +#elif defined(__FreeBSD__) + #define NANA_POSIX + #define NANA_X11 + typedef long long thread_t; #elif (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC) //Linux #define NANA_LINUX - #define NANA_X11 -#else - static_assert(false, "Only Windows and Unix are supported now (Mac OS is experimental)"); -#endif - -//Define a symbol for POSIX operating system. -#if defined(NANA_LINUX) || defined(NANA_MACOS) #define NANA_POSIX + #define NANA_X11 + typedef long long thread_t; +#else + static_assert(false, "Only Windows and Linux are supported now (Mac OS and BSD are experimental)"); #endif - - // Select compiler ... #if defined(_MSC_VER) //Microsoft Visual C++ #define _SCL_SECURE_NO_WARNNGS diff --git a/include/nana/filesystem/filesystem_ext.hpp b/include/nana/filesystem/filesystem_ext.hpp index 2c28acad..114ea013 100644 --- a/include/nana/filesystem/filesystem_ext.hpp +++ b/include/nana/filesystem/filesystem_ext.hpp @@ -17,21 +17,21 @@ #include -namespace nana +namespace nana { -namespace filesystem_ext +namespace filesystem_ext { #if defined(NANA_WINDOWS) constexpr auto const def_root = "C:"; constexpr auto const def_rootstr = "C:\\"; constexpr auto const def_rootname = "Local Drive(C:)"; -#elif defined(NANA_LINUX) +#elif defined(NANA_POSIX) constexpr auto const def_root = "/"; constexpr auto const def_rootstr = "/"; constexpr auto const def_rootname = "Root/"; #endif - + std::experimental::filesystem::path path_user(); ///< extention ? inline bool is_directory(const std::experimental::filesystem::directory_entry& dir) noexcept @@ -41,7 +41,7 @@ inline bool is_directory(const std::experimental::filesystem::directory_entry& d //template // DI = directory_iterator from std, boost, or nana : return directory_entry class directory_only_iterator : public std::experimental::filesystem::directory_iterator -{ +{ using directory_iterator = std::experimental::filesystem::directory_iterator; directory_only_iterator& find_first() @@ -49,7 +49,7 @@ class directory_only_iterator : public std::experimental::filesystem::directory_ auto end = directory_only_iterator{}; while (*this != end) { - if (is_directory((**this).status())) + if (is_directory((**this).status())) return *this; this->directory_iterator::operator++(); } @@ -99,7 +99,7 @@ public: { find_first(); } - + regular_file_only_iterator& operator++() { this->directory_iterator::operator++(); diff --git a/include/nana/gui/detail/basic_window.hpp b/include/nana/gui/detail/basic_window.hpp index 3f90c300..6c5bc202 100644 --- a/include/nana/gui/detail/basic_window.hpp +++ b/include/nana/gui/detail/basic_window.hpp @@ -3,8 +3,8 @@ * Nana C++ Library(http://www.nanapro.org) * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE_1_0.txt or copy at + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * @file nana/gui/detail/basic_window.hpp @@ -79,7 +79,7 @@ namespace detail }; - /// a window data structure descriptor + /// a window data structure descriptor struct basic_window : public events_holder { @@ -139,7 +139,7 @@ namespace detail void _m_init_pos_and_size(basic_window* parent, const rectangle&); void _m_initialize(basic_window* parent); public: -#if defined(NANA_LINUX) || defined(NANA_MACOS) +#if defined(NANA_POSIX) point pos_native; #endif point pos_root; ///< coordinates of the root window @@ -202,7 +202,7 @@ namespace detail effects::bground_interface * bground; double bground_fade_rate; }effect; - + struct other_tag { #ifndef WIDGET_FRAME_DEPRECATED @@ -248,7 +248,7 @@ namespace detail }other; native_window_type root; ///< root Window handle - unsigned thread_id; ///< the identifier of the thread that created the window. + thread_t thread_id; ///< the identifier of the thread that created the window. unsigned index; container children; }; diff --git a/include/nana/gui/detail/bedrock.hpp b/include/nana/gui/detail/bedrock.hpp index 0db691b3..cee36fc6 100644 --- a/include/nana/gui/detail/bedrock.hpp +++ b/include/nana/gui/detail/bedrock.hpp @@ -27,7 +27,7 @@ namespace detail struct basic_window; class window_manager; - + /// @brief fundamental core component, it provides an abstraction to the OS platform and some basic functions. class bedrock { @@ -45,10 +45,10 @@ namespace detail ~bedrock(); void pump_event(window, bool is_modal); void flush_surface(core_window_t*, bool forced, const rectangle* update_area = nullptr); - static int inc_window(unsigned tid = 0); - thread_context* open_thread_context(unsigned tid = 0); - thread_context* get_thread_context(unsigned tid = 0); - void remove_thread_context(unsigned tid = 0); + static int inc_window(thread_t tid = 0); + thread_context* open_thread_context(thread_t tid = 0); + thread_context* get_thread_context(thread_t tid = 0); + void remove_thread_context(thread_t tid = 0); static bedrock& instance(); core_window_t* focus(); @@ -72,7 +72,7 @@ namespace detail void map_through_widgets(core_window_t*, native_drawable_type); //Closes the windows which are associated with the specified thread. If the given thread_id is 0, it closes all windows - void close_thread_window(unsigned thread_id); + void close_thread_window(thread_t thread_id); public: void event_expose(core_window_t *, bool exposed); void event_move(core_window_t*, int x, int y); diff --git a/include/nana/gui/detail/window_manager.hpp b/include/nana/gui/detail/window_manager.hpp index 8fa5cd53..bc5c9b03 100644 --- a/include/nana/gui/detail/window_manager.hpp +++ b/include/nana/gui/detail/window_manager.hpp @@ -154,7 +154,7 @@ namespace detail core_window_t* find_shortkey(native_window_type, unsigned long key); void set_safe_place(core_window_t* wd, std::function&& fn); - void call_safe_place(unsigned thread_id); + void call_safe_place(thread_t thread_id); private: void _m_disengage(core_window_t*, core_window_t* for_new); void _m_destroy(core_window_t*); diff --git a/include/nana/system/platform.hpp b/include/nana/system/platform.hpp index 6a5f4ffd..399e149a 100644 --- a/include/nana/system/platform.hpp +++ b/include/nana/system/platform.hpp @@ -26,7 +26,7 @@ namespace system //this_thread_id //@brief: get the identifier of calling thread. - unsigned long this_thread_id(); + thread_t this_thread_id(); //timestamp //@brief: it retrieves the timestamp at the time the function is called. diff --git a/source/audio/detail/audio_device.cpp b/source/audio/detail/audio_device.cpp index 32e1e1d0..f191a302 100644 --- a/source/audio/detail/audio_device.cpp +++ b/source/audio/detail/audio_device.cpp @@ -5,11 +5,14 @@ #include -#if defined(NANA_LINUX) +#if defined(NANA_POSIX) #include #include #include #include + #include + + static bool get_default_audio(std::string &, bool); #endif namespace nana{namespace audio @@ -47,6 +50,8 @@ namespace nana{namespace audio audio_device::audio_device() #if defined(NANA_WINDOWS) : handle_(nullptr), buf_prep_(nullptr) +#elif defined(NANA_POSIX) + : handle_(-1), buf_prep_(nullptr) #elif defined(NANA_LINUX) : handle_(nullptr), buf_prep_(nullptr) #endif @@ -59,7 +64,11 @@ namespace nana{namespace audio bool audio_device::empty() const { + #ifdef NANA_POSIX + return (-1 == handle_); + #else return (nullptr == handle_); + #endif } bool audio_device::open(std::size_t channels, std::size_t rate, std::size_t bits_per_sample) @@ -80,6 +89,7 @@ namespace nana{namespace audio MMRESULT mmr = wave_native_if.out_open(&handle_, WAVE_MAPPER, &wfx, reinterpret_cast(&audio_device::_m_dev_callback), reinterpret_cast(this), CALLBACK_FUNCTION); return (mmr == MMSYSERR_NOERROR); #elif defined(NANA_LINUX) + // assumes ALSA sub-system if(nullptr == handle_) { if(::snd_pcm_open(&handle_, "plughw:0,0", SND_PCM_STREAM_PLAYBACK, 0) < 0) @@ -158,7 +168,52 @@ namespace nana{namespace audio ::snd_pcm_prepare(handle_); return true; } - return false; + return false; +#elif defined(NANA_POSIX) + std::string dsp; + if ( !get_default_audio(dsp, true) ) + return false; + handle_ = ::open(dsp.c_str(), O_WRONLY); + if (handle_ == -1) + return false; + + int zero = 0; + int caps = 0; + int fragment = 0x200008L; + int ok; + ok = ioctl(handle_, SNDCTL_DSP_COOKEDMODE, &zero); + if (ok >= 0) + { + ok = ioctl(handle_, SNDCTL_DSP_SETFRAGMENT, &fragment); + if (ok >= 0) + { + ok = ioctl(handle_, SNDCTL_DSP_GETCAPS, &caps); + if (ok >= 0) + { + ok = ioctl(handle_, SNDCTL_DSP_SETFMT, &bits_per_sample); + if (ok >= 0) + { + ok = ioctl(handle_, SNDCTL_DSP_CHANNELS, &channels); + if (ok >= 0) + { + ok = ioctl(handle_, SNDCTL_DSP_SPEED, &rate); + if (ok >= 0) + { + channels_ = channels; + rate_ = rate; + bytes_per_sample_ = ( (bits_per_sample + 7) >> 3 ); + bytes_per_frame_ = bytes_per_sample_ * channels; + return true; + } + } + } + } + } + } + // failure so close handle. + ::close(handle_); + handle_ = -1; + return false; #endif } @@ -168,10 +223,14 @@ namespace nana{namespace audio { #if defined(NANA_WINDOWS) wave_native_if.out_close(handle_); + handle_ = nullptr; +#elif defined(__FreeBSD__) + ::close(handle_); + handle_ = 0; #elif defined(NANA_LINUX) ::snd_pcm_close(handle_); -#endif handle_ = nullptr; +#endif } } @@ -190,6 +249,11 @@ namespace nana{namespace audio wave_native_if.out_prepare(handle_, m, sizeof(WAVEHDR)); wave_native_if.out_write(handle_, m, sizeof(WAVEHDR)); +#elif defined(NANA_POSIX) + // consider moving this to a background thread. + // currently this blocks calling thread. + ::write(handle_, m->buf, m->bufsize); + buf_prep_->revert(m); #elif defined(NANA_LINUX) std::size_t frames = m->bufsize / bytes_per_frame_; std::size_t buffered = 0; //in bytes @@ -240,4 +304,144 @@ namespace nana{namespace audio }//end namespace audio }//end namespace nana -#endif //NANA_ENABLE_AUDIO \ No newline at end of file +#ifdef NANA_POSIX +// parse input securely, no-overruns or overflows. +static bool match(char *&cursor, const char *pattern, const char *tail) +{ + char *skim = cursor; + while (*skim != '\n' && *pattern != 0 && cursor != tail) + { + if (*pattern != *skim) + return false; + pattern++; + skim++; + } + if (*pattern == 0) + { + cursor = skim; + return true; + } + return false; +} + +// parse input securely, no-overruns or overflows. +static bool skip(char *&cursor, const char stop, const char *tail) +{ + char *skim = cursor; + while (*skim != '\n' && cursor != tail) + { + if (stop == *skim) + { + cursor = skim; + return true; + } + skim++; + } + return false; +} + +struct audio_device +{ + // pcm name + std::string device; + // /dev/dsp + std::string path; + // terse description + std::string description; + // can record eg. microphone or line-in. + bool rec; + // can play - speaker, headphone or line-out. + bool play; + // is the default device. + bool chosen; +}; + +static bool get_audio_devices(std::vector &list) +{ + // read the sndstat device to get a list of audio devices. + // mostly OSS but some ALSA installs mimic this. + FILE *cat = fopen("/dev/sndstat", "r"); + if (cat != 0) + { + char line[128] = {0}; + const char *last = line + sizeof line; + while ( fgets(line, sizeof line, cat) != 0 ) + { + // extract five things about a device: name, description, play, rec, and default. + audio_device next; + char *cursor = line; + // ignore these lines + if ( match(cursor, "Installed", last) || match(cursor, "No devices", last) ) + continue; + + const char *device = cursor; + if ( !skip(cursor, ':', last) ) + continue; + // nul terminate device name. + *cursor++ = 0; + next.device = device; + + if ( !skip(cursor, '<', last) ) + continue; + + const char *description = ++cursor; + if ( !skip(cursor, '>', last) ) + continue; + // nul terminate description. + *cursor++ = 0; + next.description = description; + + if ( !skip(cursor, '(', last) ) + continue; + + cursor++; + // supports play? + next.play = match(cursor, "play", last); + if (next.play) + match(cursor, "/", last); + + // supports record? + next.rec = match(cursor, "rec", last); + if ( !skip(cursor, ')', last) ) + continue; + + cursor++; + // default ? + if ( match(cursor, " ", last) ) + next.chosen = match(cursor, "default", last); + + if (next.device.compare(0, 3, "pcm") == 0) + { + // proper dev path with number appended. + next.path = "/dev/dsp"; + next.path += next.device.c_str() + 3; + } + + list.push_back(next); + } + fclose(cat); + } + return list.size() > 0; +} + +static bool get_default_audio(std::string &dsp, bool play) +{ + std::vector list; + if ( !get_audio_devices(list) ) + return false; + for (auto it = list.begin(); it != list.end(); it++) + { + if ( (it->play && play) || (it->rec && !play) ) + { + if (it->chosen) + { + dsp = it->path; + return true; + } + } + } + return false; +} +#endif //NANA_POSIX + +#endif //NANA_ENABLE_AUDIO diff --git a/source/audio/detail/buffer_preparation.cpp b/source/audio/detail/buffer_preparation.cpp index febe3a77..f9497576 100644 --- a/source/audio/detail/buffer_preparation.cpp +++ b/source/audio/detail/buffer_preparation.cpp @@ -26,6 +26,7 @@ namespace nana{ namespace audio memset(m, 0, sizeof(meta)); m->dwBufferLength = static_cast(block_size_); m->lpData = rawbuf + sizeof(meta); +#elif defined(__FreeBSD__) #elif defined(NANA_LINUX) m->bufsize = ck.nAvgBytesPerSec; m->buf = rawbuf + sizeof(meta); @@ -124,6 +125,7 @@ namespace nana{ namespace audio { #if defined(NANA_WINDOWS) memcpy(m->lpData + buffered, buf, read_bytes); +#elif defined(__FreeBSD__) #elif defined(NANA_LINUX) memcpy(m->buf + buffered, buf, read_bytes); #endif @@ -144,6 +146,7 @@ namespace nana{ namespace audio } #if defined(NANA_WINDOWS) m->dwBufferLength = static_cast(buffered); +#elif defined(__FreeBSD__) #elif defined(NANA_LINUX) m->bufsize = buffered; #endif @@ -163,4 +166,4 @@ namespace nana{ namespace audio }//end namespace audio }//end namespace nana -#endif //NANA_ENABLE_AUDIO \ No newline at end of file +#endif //NANA_ENABLE_AUDIO diff --git a/source/charset.cpp b/source/charset.cpp index 454b5ea3..1b258fc7 100644 --- a/source/charset.cpp +++ b/source/charset.cpp @@ -42,7 +42,7 @@ namespace nana { auto ustr = reinterpret_cast(text); auto const end = ustr + std::strlen(text); - + for (unsigned i = 0; i != pos; ++i) { const auto uch = *ustr; @@ -55,7 +55,7 @@ namespace nana if (uch < 0xC0) // use police ? return nullptr; - if ((uch < 0xE0) && (ustr + 1 < end)) //? *(ustr + 1) < 0xE0 + if ((uch < 0xE0) && (ustr + 1 < end)) //? *(ustr + 1) < 0xE0 ustr += 2; else if (uch < 0xF0 && (ustr + 2 <= end)) ustr += 3; @@ -217,7 +217,7 @@ namespace nana } namespace detail - { + { /// candidate to be more general?? class locale_initializer { @@ -226,7 +226,7 @@ namespace nana { static bool initialized = false; if (initialized) return; - + initialized = true; //Only set the C library locale std::setlocale(LC_CTYPE, ""); @@ -288,7 +288,7 @@ namespace nana std::size_t len = std::mbsrtowcs(nullptr, &s, 0, &mbstate); if(len == static_cast(-1)) return false; - + if(len) { wcstr.resize(len); @@ -322,7 +322,7 @@ namespace nana std::size_t len = std::mbsrtowcs(nullptr, &s, 0, &mbstate); if(len == static_cast(-1)) return false; - + if(len) { wcstr.resize(sizeof(wchar_t) * len); @@ -367,7 +367,7 @@ namespace nana }; - /// + /// struct utf8_error_police_def_char : public encoding_error_police { static unsigned long def_error_mark ; @@ -386,13 +386,13 @@ namespace nana unsigned long utf8_error_police_def_char::def_error_mark{ '*' }; - /// + /// struct utf8_error_police_throw : public encoding_error_police { unsigned long next_code_point(const unsigned char*& current_code_unit, const unsigned char* end) override { //utf8_Error::use_throw = true; - utf8_Error(std::string("The text is not encoded in UTF8: ") + + utf8_Error(std::string("The text is not encoded in UTF8: ") + reinterpret_cast( current_code_unit) ).emit();; current_code_unit = end; return 0; @@ -561,7 +561,7 @@ namespace nana std::u32string utf32str = std::wstring_convert, char32_t>().from_bytes(bytes, bytes + sizeof(wchar_t) * wcstr.size()); return std::string(reinterpret_cast(utf32str.c_str()), sizeof(char32_t) * utf32str.size()); } - #elif defined(NANA_LINUX) || defined(NANA_MACOS) + #elif defined(NANA_POSIX) return std::string(reinterpret_cast(wcstr.c_str()), sizeof(wchar_t) * wcstr.size()); #else throw std::runtime_error("Bad charset"); @@ -653,7 +653,7 @@ namespace nana std::u32string utf32str = std::wstring_convert, char32_t>().from_bytes(bytes, bytes + sizeof(wchar_t) * data_.size()); return std::string(reinterpret_cast(utf32str.c_str()), sizeof(char32_t) * utf32str.size()); } - #elif defined(NANA_LINUX) || defined(NANA_MACOS) + #elif defined(NANA_POSIX) return std::string(reinterpret_cast(data_.c_str()), data_.size() * sizeof(wchar_t)); #else throw std::runtime_error("Bad charset"); @@ -689,7 +689,7 @@ namespace nana } unsigned ch = *p; unsigned long code; - if(ch < 0xC0) // error? - move to end. Posible ANSI or ISO code-page + if(ch < 0xC0) // error? - move to end. Posible ANSI or ISO code-page { //return *(p++); // temp: assume equal //p = end; @@ -809,7 +809,7 @@ namespace nana s += static_cast(0x80 | ((code >> 12) & 0x3F)); s += static_cast(0x80 | ((code >> 6) & 0x3F)); s += static_cast(0x80 | (code & 0x3F)); - } + } } //le_or_be, true = le, false = be diff --git a/source/deploy.cpp b/source/deploy.cpp index 0c68a2ae..bdc6c829 100644 --- a/source/deploy.cpp +++ b/source/deploy.cpp @@ -19,12 +19,11 @@ #if defined(NANA_WINDOWS) #include -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) #include #include "detail/platform_spec_selector.hpp" #endif - #include namespace nana @@ -76,7 +75,7 @@ namespace nana std::cerr << what(); } - //bool utf8_Error::use_throw{true}; + //bool utf8_Error::use_throw{true}; bool utf8_Error::use_throw{ false }; //end class utf8_Error @@ -240,4 +239,4 @@ namespace nana #if defined(VERBOSE_PREPROCESSOR) # include -#endif \ No newline at end of file +#endif diff --git a/source/detail/platform_spec_posix.cpp b/source/detail/platform_spec_posix.cpp index 7f825395..914bc529 100644 --- a/source/detail/platform_spec_posix.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -206,7 +206,7 @@ namespace detail } } }; - + class timer_runner { typedef void (*timer_proc_t)(std::size_t id); @@ -250,7 +250,7 @@ namespace detail i->second.proc = proc; return; } - unsigned tid = nana::system::this_thread_id(); + auto tid = nana::system::this_thread_id(); threadmap_[tid].timers.insert(id); timer_tag & tag = holder_[id]; @@ -272,7 +272,7 @@ namespace detail if(i != holder_.end()) { auto tid = i->second.tid; - + auto ig = threadmap_.find(tid); if(ig != threadmap_.end()) //Generally, the ig should not be the end of threadmap_ { @@ -723,7 +723,7 @@ namespace detail ::XFree(attr); } else - addr->input_context = ::XCreateIC(addr->input_method, + addr->input_context = ::XCreateIC(addr->input_method, XNInputStyle, (XIMPreeditNothing | XIMStatusNothing), XNClientWindow, reinterpret_cast(wd), XNFocusWindow, reinterpret_cast(wd), nullptr); @@ -794,7 +794,7 @@ namespace detail XSetWindowAttributes new_attr; //Don't remove the KeyPress and KeyRelease mask(0x3), otherwise the window will not receive - //Keyboard events after destroying caret + //Keyboard events after destroying caret new_attr.event_mask = (attr.your_event_mask & ~(addr->input_context_event_mask & (~0x3))); ::XChangeWindowAttributes(display_, reinterpret_cast(wd), CWEventMask, &new_attr); } @@ -1066,7 +1066,7 @@ namespace detail // 2 = msg_dispatcher should ignore the msg, because the XEvent is processed by _m_msg_filter int platform_spec::_m_msg_filter(XEvent& evt, msg_packet_tag& msg) { - auto & bedrock = detail::bedrock::instance(); + auto & bedrock = detail::bedrock::instance(); platform_spec & self = instance(); if(KeyPress == evt.type || KeyRelease == evt.type) diff --git a/source/detail/platform_spec_selector.hpp b/source/detail/platform_spec_selector.hpp index f37edf21..5c65a86f 100644 --- a/source/detail/platform_spec_selector.hpp +++ b/source/detail/platform_spec_selector.hpp @@ -16,6 +16,6 @@ #if defined(NANA_WINDOWS) #include "mswin/platform_spec.hpp" -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) #include "posix/platform_spec.hpp" -#endif \ No newline at end of file +#endif diff --git a/source/detail/posix/msg_dispatcher.hpp b/source/detail/posix/msg_dispatcher.hpp index 632f604c..58adf7b0 100644 --- a/source/detail/posix/msg_dispatcher.hpp +++ b/source/detail/posix/msg_dispatcher.hpp @@ -2,8 +2,8 @@ * Message Dispatcher Implementation * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE_1_0.txt or copy at + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * @file: nana/detail/msg_dispatcher.hpp @@ -76,7 +76,7 @@ namespace detail void insert(Window wd) { - unsigned tid = nana::system::this_thread_id(); + auto tid = nana::system::this_thread_id(); bool start_driver; @@ -100,7 +100,7 @@ namespace detail thr->mutex.lock(); thr->window.insert(wd); thr->mutex.unlock(); - + table_.wnd_table[wd] = thr; } @@ -120,7 +120,7 @@ namespace detail void erase(Window wd) { std::lock_guard lock(table_.mutex); - + auto i = table_.wnd_table.find(wd); if(i != table_.wnd_table.end()) { @@ -136,7 +136,7 @@ namespace detail table_.wnd_table.erase(i); thr->window.erase(wd); - + //There still is at least one window alive. if(thr->window.size()) { @@ -151,10 +151,10 @@ namespace detail void dispatch(Window modal) { - unsigned tid = nana::system::this_thread_id(); + auto tid = nana::system::this_thread_id(); msg_packet_tag msg; int qstate; - + //Test whether the thread is registered for window, and retrieve the queue state for event while((qstate = _m_read_queue(tid, msg, modal))) { @@ -186,7 +186,7 @@ namespace detail if(pending) { ::XNextEvent(display_, &event); - + if(KeyRelease == event.type) { //Check whether the key is pressed, because X will send KeyRelease when pressing and @@ -260,7 +260,7 @@ namespace detail if(i != table_.wnd_table.end()) { thread_binder * const thr = i->second; - + std::lock_guardmutex)> lock(thr->mutex); thr->msg_queue.push_back(msg); thr->cond.notify_one(); @@ -330,12 +330,12 @@ namespace detail thr = i->second; } } - + //Waits for notifying the condition variable, it indicates a new msg is pushing into the queue. std::unique_lockmutex)> lock(thr->mutex); return (thr->cond.wait_for(lock, std::chrono::milliseconds(10)) != std::cv_status::timeout); } - + private: Display * display_; volatile bool is_work_{ false }; diff --git a/source/detail/posix/platform_spec.hpp b/source/detail/posix/platform_spec.hpp index 2ada1eac..fc8cc644 100644 --- a/source/detail/posix/platform_spec.hpp +++ b/source/detail/posix/platform_spec.hpp @@ -13,7 +13,7 @@ * This file should not be included by any header files. */ -#if defined(NANA_LINUX) || defined(NANA_MACOS) +#if defined(NANA_POSIX) #ifndef NANA_DETAIL_PLATFORM_SPEC_HPP #define NANA_DETAIL_PLATFORM_SPEC_HPP @@ -319,6 +319,5 @@ namespace detail // .h ward #endif -//#if defined(NANA_LINUX) || defined(NANA_MACOS) #endif diff --git a/source/filesystem/filesystem.cpp b/source/filesystem/filesystem.cpp index fa5a8cb8..830187bb 100644 --- a/source/filesystem/filesystem.cpp +++ b/source/filesystem/filesystem.cpp @@ -58,7 +58,7 @@ namespace nana wchar_t pstr[MAX_PATH]; if (SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, pstr))) return pstr; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) const char * pstr = ::getenv("HOME"); if (pstr) return pstr; @@ -66,7 +66,7 @@ namespace nana return fs::path(); } - std::string pretty_file_size(const fs::path& path) + std::string pretty_file_size(const fs::path& path) { try { auto bytes = fs::file_size(path); @@ -118,7 +118,7 @@ namespace nana if (ftime == ((fs::file_time_type::min)())) return{}; //std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); - + //A workaround for VC2013 using time_point = decltype(ftime); @@ -169,7 +169,7 @@ namespace nana } } -#if NANA_USING_NANA_FILESYSTEM +#if NANA_USING_NANA_FILESYSTEM namespace nana_fs = nana::experimental::filesystem; @@ -208,7 +208,7 @@ namespace nana { namespace experimental { namespace filesystem //Because of No wide character version of POSIX -#if defined(NANA_LINUX) || defined(NANA_MACOS) +#if defined(NANA_POSIX) const char* splstr = "/"; #else const wchar_t* splstr = L"/\\"; @@ -251,7 +251,7 @@ namespace nana { namespace experimental { namespace filesystem { #if defined(NANA_WINDOWS) return (::GetFileAttributes(pathstr_.c_str()) == INVALID_FILE_ATTRIBUTES); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) struct stat sta; return (::stat(pathstr_.c_str(), &sta) == -1); #endif @@ -293,7 +293,7 @@ namespace nana { namespace experimental { namespace filesystem return file_type::directory; return file_type::regular; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) struct stat sta; if (-1 == ::stat(pathstr_.c_str(), &sta)) return file_type::not_found; //?? @@ -372,7 +372,7 @@ namespace nana { namespace experimental { namespace filesystem { return pathstr_; } - + path::operator string_type() const { return native(); @@ -392,7 +392,7 @@ namespace nana { namespace experimental { namespace filesystem { return to_utf8(pathstr_); } - std::string path::generic_string() const + std::string path::generic_string() const { auto str = string(); std::replace(str.begin(), str.end(), '\\', '/'); @@ -404,7 +404,7 @@ namespace nana { namespace experimental { namespace filesystem std::replace(str.begin(), str.end(), L'\\', L'/'); return str; } - std::string path::generic_u8string() const // uppss ... + std::string path::generic_u8string() const // uppss ... { auto str = pathstr_; std::replace(str.begin(), str.end(), '\\', '/'); // uppss ... revise this !!!!! @@ -447,7 +447,7 @@ namespace nana { namespace experimental { namespace filesystem void path::_m_assign(const std::wstring& source) { - pathstr_ = to_nstring(source); + pathstr_ = to_nstring(source); } //end class path @@ -517,9 +517,9 @@ namespace nana { namespace experimental { namespace filesystem void operator()(void** handle) { #if defined(NANA_WINDOWS) - ::FindClose(*handle); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - ::closedir(*reinterpret_cast(handle)); + ::FindClose(*handle); +#elif defined(NANA_POSIX) + ::closedir(*reinterpret_cast(handle)); #endif } }; @@ -554,7 +554,7 @@ namespace nana { namespace experimental { namespace filesystem bool directory_iterator::equal(const directory_iterator& x) const { if (end_ && (end_ == x.end_)) return true; - return (value_.path().filename() == x.value_.path().filename()); + return (value_.path().filename() == x.value_.path().filename()); } @@ -695,11 +695,11 @@ namespace nana { namespace experimental { namespace filesystem { if (p.empty()) return false; -#if defined(NANA_WINDOWS) +#if defined(NANA_WINDOWS) return (FALSE != ::DeleteFileW(p.c_str())); #elif defined(NANA_POSIX) return (!std::remove(p.c_str())); -#endif +#endif } bool rm_dir(const path& p) @@ -708,7 +708,7 @@ namespace nana { namespace experimental { namespace filesystem return (FALSE != ::RemoveDirectoryW(p.c_str())) || not_found_error(static_cast(::GetLastError())); #elif defined(NANA_POSIX) return (!::rmdir(p.c_str())) || not_found_error(errno); -#endif +#endif } bool rm_dir(const path& p, bool fails_if_not_empty); @@ -841,7 +841,7 @@ namespace nana { namespace experimental { namespace filesystem return file_status{ file_type::socket, prms }; return file_status{ file_type::unknown }; -#endif +#endif } bool is_directory(const path& p) @@ -877,7 +877,7 @@ namespace nana { namespace experimental { namespace filesystem # if defined(NANA_LINUX) fseeko64(stream, 0, SEEK_END); size = ftello64(stream); -# elif defined(NANA_MACOS) +# elif defined(NANA_POSIX) fseeko(stream, 0, SEEK_END); size = ftello(stream); # endif @@ -891,7 +891,7 @@ namespace nana { namespace experimental { namespace filesystem file_time_type last_write_time(const path& p) { struct tm t; - nana::filesystem_ext::modified_file_time(p, t); + nana::filesystem_ext::modified_file_time(p, t); std::chrono::system_clock::time_point dateTime =std::chrono::system_clock::from_time_t( mktime(&t) ); return dateTime; } @@ -946,7 +946,7 @@ namespace nana { namespace experimental { namespace filesystem auto pstr = ::getcwd(buf, 260); if (pstr) return pstr; - + int bytes = 260 + 260; while (ERANGE == errno) { diff --git a/source/gui/detail/bedrock_pi.cpp b/source/gui/detail/bedrock_pi.cpp index 3422beaa..90363acc 100644 --- a/source/gui/detail/bedrock_pi.cpp +++ b/source/gui/detail/bedrock_pi.cpp @@ -37,7 +37,7 @@ namespace nana detail::bedrock::instance().wd_manager().internal_lock().unlock(); } //end class internal_scope_guard - + //class internal_revert_guard internal_revert_guard::internal_revert_guard() { @@ -55,7 +55,7 @@ namespace nana { stop_propagation_ = true; } - + bool event_arg::propagation_stopped() const { return stop_propagation_; @@ -111,7 +111,7 @@ namespace nana pi_data_->auto_form_set.insert(wd); return; } - + if (pi_data_->auto_form_set.erase(wd)) { auto p = wd->widget_notifier->widget_ptr(); @@ -119,7 +119,7 @@ namespace nana } } - void bedrock::close_thread_window(unsigned thread_id) + void bedrock::close_thread_window(thread_t thread_id) { std::vector v; wd_manager().all_handles(v); @@ -321,7 +321,7 @@ namespace nana } return false; } - + void bedrock::set_menu(native_window_type menu_wd, bool has_keyboard) { if(menu_wd && pi_data_->menu.window != menu_wd) @@ -453,7 +453,7 @@ namespace nana flag_guard fguard(this, wd); (wd->drawer.*drawer_event_fn)(*arg, bForce__EmitInternal); } - + if (bProcess__External_event) evt_addr->emit(*arg, reinterpret_cast(wd)); break; @@ -610,4 +610,4 @@ namespace nana } } }//end namespace detail -}//end namespace nana \ No newline at end of file +}//end namespace nana diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index 5f4fa1fa..16273989 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -80,13 +80,13 @@ namespace detail cursor.handle = 0; } }; - + struct bedrock::private_impl { typedef std::map thr_context_container; std::recursive_mutex mutex; thr_context_container thr_contexts; - + element_store estore; struct cache_type @@ -139,7 +139,7 @@ namespace detail //inc_window //@biref: increament the number of windows - int bedrock::inc_window(unsigned tid) + int bedrock::inc_window(thread_t tid) { private_impl * impl = instance().impl_; std::lock_guardmutex)> lock(impl->mutex); @@ -148,7 +148,7 @@ namespace detail return (cnt < 0 ? cnt = 1 : ++cnt); } - bedrock::thread_context* bedrock::open_thread_context(unsigned tid) + bedrock::thread_context* bedrock::open_thread_context(thread_t tid) { if(0 == tid) tid = nana::system::this_thread_id(); @@ -169,7 +169,7 @@ namespace detail return context; } - bedrock::thread_context* bedrock::get_thread_context(unsigned tid) + bedrock::thread_context* bedrock::get_thread_context(thread_t tid) { if(0 == tid) tid = nana::system::this_thread_id(); @@ -188,7 +188,7 @@ namespace detail return 0; } - void bedrock::remove_thread_context(unsigned tid) + void bedrock::remove_thread_context(thread_t tid) { if(0 == tid) tid = nana::system::this_thread_id(); @@ -266,7 +266,7 @@ namespace detail good_wd = true; } - + if(thrd) thrd->event_window = prev_wd; return good_wd; @@ -349,7 +349,7 @@ namespace detail arg.distance = 120; arg.which = arg_wheel::wheel::vertical; } - + } void timer_proc(unsigned tid) @@ -534,7 +534,7 @@ namespace detail arg.evt_code = event_code::mouse_move; brock.emit(event_code::mouse_move, msgwnd, arg, true, &context); - + if (!wd_manager.available(hovered_wd)) hovered_wd = nullptr; } @@ -561,7 +561,7 @@ namespace detail auto & cf = xevent.xconfigure; wd_manager.size(msgwnd, nana::size{static_cast(cf.width), static_cast(cf.height)}, true, true); } - + if(msgwnd->pos_native.x != xevent.xconfigure.x || msgwnd->pos_native.y != xevent.xconfigure.y) { msgwnd->pos_native.x = xevent.xconfigure.x; @@ -582,7 +582,7 @@ namespace detail pressed_wd = nullptr; if(nullptr == msgwnd) break; - + if ((msgwnd == msgwnd->root_widget->other.attribute.root->menubar) && brock.get_menu(msgwnd->root, true)) brock.erase_menu(true); else @@ -670,7 +670,7 @@ namespace detail arg.which = arg_wheel::wheel::vertical; assign_arg(arg, msgwnd, xevent); draw_invoker(&drawer::mouse_wheel, msgwnd, arg, &context); - wd_manager.do_lazy_refresh(msgwnd, false); + wd_manager.do_lazy_refresh(msgwnd, false); } } else @@ -700,13 +700,13 @@ namespace detail draw_invoker(&drawer::click, msgwnd, click_arg, &context); } } - + //Do mouse_up, this handle may be closed by click handler. if(wd_manager.available(msgwnd) && msgwnd->flags.enabled) { if(hit) msgwnd->set_action(mouse_action::hovered); - + auto retain = msgwnd->annex.events_ptr; auto evt_ptr = retain.get(); @@ -804,7 +804,7 @@ namespace detail { arg_mouse arg; assign_arg(arg, msgwnd, message, xevent); - + if (mouse_action::pressed != msgwnd->flags.action) msgwnd->set_action(mouse_action::hovered); @@ -1039,12 +1039,12 @@ namespace detail context.is_ctrl_pressed = false; if (('\t' == os_code) && root_runtime->condition.ignore_tab) - { + { root_runtime->condition.ignore_tab = false; } else { - + msgwnd = brock.focus(); if(msgwnd) { @@ -1078,7 +1078,7 @@ namespace detail else { arg_keyboard arg; - + arg.evt_code = event_code::key_release; arg.window_handle = reinterpret_cast(msgwnd); arg.ignore = false; @@ -1177,7 +1177,7 @@ namespace detail auto & lock = wd_manager().internal_lock(); lock.revert(); - + native_window_type owner_native{}; core_window_t * owner = 0; if(condition_wd && is_modal) @@ -1190,9 +1190,9 @@ namespace detail owner = wd_manager().root(owner_native); if(owner) owner->flags.enabled = false; - } + } } - + nana::detail::platform_spec::instance().msg_dispatch(condition_wd ? reinterpret_cast(condition_wd)->root : 0); if(owner_native) @@ -1204,7 +1204,7 @@ namespace detail //Before exit of pump_event, it should call the remove_trash_handle. //Under Linux, if the windows are closed in other threads, all the widgets handles - //will be marked as deleted after exit of the event loop and in other threads. So the + //will be marked as deleted after exit of the event loop and in other threads. So the //handle should be deleted from trash before exit the pump_event. auto thread_id = ::nana::system::this_thread_id(); wd_manager().call_safe_place(thread_id); @@ -1289,7 +1289,7 @@ namespace detail { if (!wd_manager().available(wd)) return; - + wd->root_widget->other.attribute.root->state_cursor = nana::cursor::arrow; wd->root_widget->other.attribute.root->state_cursor_window = nullptr; diff --git a/source/gui/detail/window_manager.cpp b/source/gui/detail/window_manager.cpp index 4bfd1900..83eb2ef4 100644 --- a/source/gui/detail/window_manager.cpp +++ b/source/gui/detail/window_manager.cpp @@ -256,7 +256,7 @@ namespace detail std::vector table_; }; - //class window_manager + //class window_manager //struct wdm_private_impl struct window_manager::wdm_private_impl { @@ -835,7 +835,7 @@ namespace detail std::lock_guard lock(mutex_); if (!impl_->wd_register.available(wd)) return false; - + auto & brock = bedrock::instance(); bool moved = false; const bool size_changed = (r.width != wd->dimension.width || r.height != wd->dimension.height); @@ -906,12 +906,12 @@ namespace detail // window again, otherwise, it causes an infinite loop, because when a root_widget is resized, // window_manager will call the function. bool window_manager::size(core_window_t* wd, nana::size sz, bool passive, bool ask_update) - { + { //Thread-Safe Required! std::lock_guard lock(mutex_); if (!impl_->wd_register.available(wd)) return false; - + auto & brock = bedrock::instance(); if (sz != wd->dimension) { @@ -1168,7 +1168,7 @@ namespace detail } bool window_manager::set_parent(core_window_t* wd, core_window_t* newpa) - { + { //Thread-Safe Required! std::lock_guard lock(mutex_); if (!impl_->wd_register.available(wd)) @@ -1248,7 +1248,7 @@ namespace detail //The menubar token window will be redirected to the prev focus window when the new //focus window is a menubar. //The focus window will be restored to the prev focus which losts the focus becuase of - //memberbar. + //memberbar. if (prev_focus && (wd == wd->root_widget->other.attribute.root->menubar)) wd = prev_focus; @@ -1396,7 +1396,7 @@ namespace detail return tabs.front(); } } - else if (tabs.size() > 1) //at least 2 elments in tabs are required when moving backward. + else if (tabs.size() > 1) //at least 2 elments in tabs are required when moving backward. { auto i = std::find(tabs.begin(), end, wd); if (i != end) @@ -1564,7 +1564,7 @@ namespace detail } } - void window_manager::call_safe_place(unsigned thread_id) + void window_manager::call_safe_place(thread_t thread_id) { std::lock_guard lock(mutex_); @@ -1601,7 +1601,7 @@ namespace detail bool established = (for_new && (wdpa != for_new)); decltype(for_new->root_widget->other.attribute.root) pa_root_attr = nullptr; - + if (established) pa_root_attr = for_new->root_widget->other.attribute.root; @@ -1736,7 +1736,7 @@ namespace detail wd->root = for_new->root; wd->root_graph = for_new->root_graph; wd->root_widget = for_new->root_widget; - + wd->pos_owner.x = wd->pos_owner.y = 0; auto delta_pos = wd->pos_root - for_new->pos_root; diff --git a/source/gui/notifier.cpp b/source/gui/notifier.cpp index e3ec1b66..dc7c07f2 100644 --- a/source/gui/notifier.cpp +++ b/source/gui/notifier.cpp @@ -28,7 +28,7 @@ #include "../detail/platform_spec_selector.hpp" -#if defined(NANA_LINUX) || defined(NANA_MACOS) +#if defined(NANA_POSIX) #include #include #endif diff --git a/source/gui/timer.cpp b/source/gui/timer.cpp index e5ea14e3..8e551220 100644 --- a/source/gui/timer.cpp +++ b/source/gui/timer.cpp @@ -27,7 +27,7 @@ #if defined(NANA_WINDOWS) #include -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) #include "../detail/platform_spec_selector.hpp" #include #endif diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 62f74016..67954266 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -437,7 +437,7 @@ namespace paint #endif impl_->handle->string.tab_pixels = detail::raw_text_extent_size(impl_->handle, L"\t", 1).width; impl_->handle->string.whitespace_pixels = detail::raw_text_extent_size(impl_->handle, L" ", 1).width; - + if (impl_->changed == false) impl_->changed = true; } @@ -830,11 +830,11 @@ namespace paint } #elif defined(NANA_X11) auto & spec = nana::detail::platform_spec::instance(); - + Display * display = spec.open_display(); - + nana::detail::platform_scope_guard lock; - + ::XCopyArea(display, impl_->handle->pixmap, reinterpret_cast(dst), impl_->handle->context, sx, sy, width, height, dx, dy); @@ -844,7 +844,7 @@ namespace paint ::XGetWindowAttributes(display, reinterpret_cast(dst), &attr); if(BadWindow != spec.rev_error_handler() && attr.map_state != IsUnmapped) ::XMapWindow(display, reinterpret_cast(dst)); - + ::XFlush(display); #endif } @@ -1060,7 +1060,7 @@ namespace paint { auto const end = str + len; auto i = std::find(str, end, '\t'); -#if defined(NANA_LINUX) || defined(NANA_MACOS) +#if defined(NANA_POSIX) impl_->handle->update_text_color(); #endif if (i != end) diff --git a/source/system/platform.cpp b/source/system/platform.cpp index d6ee1462..dd255f46 100644 --- a/source/system/platform.cpp +++ b/source/system/platform.cpp @@ -17,12 +17,15 @@ #if defined(NANA_WINDOWS) #include #include "../detail/mswin/platform_spec.hpp" -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) #include #include #include #include #include + #include + #include + #include #endif namespace nana @@ -36,7 +39,7 @@ namespace system { #if defined(NANA_WINDOWS) ::Sleep(milliseconds); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) struct timespec timeOut, remains; timeOut.tv_sec = milliseconds / 1000; timeOut.tv_nsec = (milliseconds % 1000) * 1000000; @@ -52,14 +55,16 @@ namespace system //this_thread_id //@brief: get the identifier of calling thread. - unsigned long this_thread_id() + thread_t this_thread_id() { #if defined(NANA_WINDOWS) - return ::GetCurrentThreadId(); + return (thread_t)::GetCurrentThreadId(); #elif defined(NANA_LINUX) - return ::syscall(__NR_gettid); + return (thread_t)::syscall(__NR_gettid); #elif defined(NANA_MACOS) - return ::syscall(SYS_thread_selfid); + return (thread_t)::syscall(SYS_thread_selfid); +#elif defined(NANA_POSIX) + return (thread_t)pthread_self(); #endif } @@ -67,7 +72,7 @@ namespace system { #if defined(NANA_WINDOWS) return ::GetTickCount(); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) struct timeval tv; ::gettimeofday(&tv, 0); return (tv.tv_sec * 1000 + tv.tv_usec / 1000); @@ -92,7 +97,7 @@ namespace system } return (::GetAsyncKeyState(button) != 0); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) static_cast(button); //eliminate unused parameter compiler warning. return false; #endif @@ -105,7 +110,6 @@ namespace system return; #if defined(NANA_WINDOWS) - std::wstring url = to_wstring(url_utf8); if(::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL) < reinterpret_cast(32)) { //Because ShellExecute can delegate execution to Shell extensions (data sources, context menu handlers, @@ -115,8 +119,25 @@ namespace system nana::detail::platform_spec::co_initializer co_init; ::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL); } -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) + const char *home = getenv("HOME"); + std::string cheat(home); + cheat += "/.mozilla"; + struct stat exists{}; + // Look for $HOME/.mozilla directory as + // strong evidence they use firefox. + if ( stat(cheat.c_str(), &exists) == 0 && S_ISDIR(exists.st_mode)) + { + extern char **environ; + pid_t pid = 0; + static const char firefox[] = "firefox"; + char name[sizeof firefox]{}; + // argv does not like const-literals so make a copy. + strcpy(name, firefox); + char *argv[3] = {name, const_cast(url_utf8.c_str()), nullptr}; + posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ); + } #endif - } + } }//end namespace system }//end namespace nana diff --git a/source/system/shared_wrapper.cpp b/source/system/shared_wrapper.cpp index 124f2822..3e93c2d6 100644 --- a/source/system/shared_wrapper.cpp +++ b/source/system/shared_wrapper.cpp @@ -2,8 +2,8 @@ * Operation System Shared Linkage Library Wrapper Implementation * Copyright(C) 2003 Jinhao * - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE_1_0.txt or copy at + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * @file: nana/system/shared_wrapper.cpp @@ -12,7 +12,7 @@ #include #include #include -#if defined(NANA_LINUX) || defined(NANA_MACOS) +#if defined(NANA_POSIX) #include #else #include @@ -30,7 +30,7 @@ namespace system module_t open(const char* filename) { -#if defined(NANA_LINUX) || defined(NANA_MACOS) +#if defined(NANA_POSIX) return ::dlopen(filename, RTLD_LAZY); #else return ::LoadLibraryA(filename); @@ -39,7 +39,7 @@ namespace system void* symbols(module_t handle, const char* symbol) { -#if defined(NANA_LINUX) || defined(NANA_MACOS) +#if defined(NANA_POSIX) return ::dlsym(handle, const_cast(symbol)); #else return (void*)(::GetProcAddress(reinterpret_cast(handle), symbol)); @@ -48,7 +48,7 @@ namespace system void close(module_t handle) { -#if defined(NANA_LINUX) || defined(NANA_MACOS) +#if defined(NANA_POSIX) ::dlclose(handle); #else ::FreeLibrary(reinterpret_cast(handle)); @@ -90,7 +90,7 @@ namespace system std::transform(filename + length - 13, filename + length , std::back_inserter(file), tolower); if(file == ".nana_shared") { -#if defined(NANA_LINUX) || defined(NANA_MACOS) +#if defined(NANA_POSIX) ofn.replace(length - 13, 13, ".so"); #else ofn.replace(length - 13, 13, ".DLL"); diff --git a/source/system/timepiece.cpp b/source/system/timepiece.cpp index daae31dc..fb2f71b9 100644 --- a/source/system/timepiece.cpp +++ b/source/system/timepiece.cpp @@ -2,7 +2,7 @@ #include #ifdef NANA_WINDOWS #include -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) #include #endif @@ -15,7 +15,7 @@ namespace system { #if defined(NANA_WINDOWS) LARGE_INTEGER beg_timestamp; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) struct timeval beg_timestamp; #endif }; @@ -45,7 +45,7 @@ namespace system { #if defined(NANA_WINDOWS) ::QueryPerformanceCounter(&impl_->beg_timestamp); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) struct timezone tz; ::gettimeofday(&impl_->beg_timestamp, &tz); #endif @@ -63,7 +63,7 @@ namespace system ::QueryPerformanceFrequency(&freq); return double(diff)/double(freq.QuadPart) * 1000; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); diff --git a/source/threads/pool.cpp b/source/threads/pool.cpp index 0e2c6c29..d1f356b7 100644 --- a/source/threads/pool.cpp +++ b/source/threads/pool.cpp @@ -29,7 +29,7 @@ #if defined(NANA_WINDOWS) #include #include -#elif defined(NANA_LINUX) || defined(NANA_MACOS) +#elif defined(NANA_POSIX) #include #endif From e9c381e1de321385f07bcec78c5de7a1fab4d01d Mon Sep 17 00:00:00 2001 From: unitrunker Date: Sun, 21 Jan 2018 23:53:09 -0600 Subject: [PATCH 02/13] Unicode fix for using iconv on little-endian machines. --- source/detail/platform_spec_posix.cpp | 4 ++-- source/gui/detail/bedrock_posix.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/detail/platform_spec_posix.cpp b/source/detail/platform_spec_posix.cpp index 914bc529..853f4df1 100644 --- a/source/detail/platform_spec_posix.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -339,8 +339,8 @@ namespace detail string.tab_pixels = 0; string.whitespace_pixels = 0; #if defined(NANA_USE_XFT) - conv_.handle = ::iconv_open("UTF-8", "UTF-32"); - conv_.code = "UTF-32"; + conv_.handle = ::iconv_open("UTF-8", NANA_UNICODE); + conv_.code = NANA_UNICODE; #endif } diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index 16273989..9609fe7f 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -981,7 +981,7 @@ namespace detail { const wchar_t* charbuf; - nana::detail::charset_conv charset("UTF-32", "UTF-8"); + nana::detail::charset_conv charset(NANA_UNICODE, "UTF-8"); const std::string& str = charset.charset(std::string(keybuf, keybuf + len)); charbuf = reinterpret_cast(str.c_str()) + 1; len = str.size() / sizeof(wchar_t) - 1; From f2baba7c778ebef1aa6894e00090e6ca6ab04c68 Mon Sep 17 00:00:00 2001 From: unitrunker Date: Mon, 22 Jan 2018 11:46:29 -0600 Subject: [PATCH 03/13] More thread_t fixes (dont use a 32 bit type to hold a 64 bit handle). --- include/nana/gui/detail/window_manager.hpp | 2 +- source/detail/platform_spec_posix.cpp | 8 ++--- source/detail/posix/msg_dispatcher.hpp | 12 +++---- source/detail/posix/platform_spec.hpp | 4 +-- source/gui/detail/bedrock_posix.cpp | 6 ++-- source/gui/detail/bedrock_windows.cpp | 12 +++---- source/gui/detail/window_manager.cpp | 8 ++--- source/gui/detail/window_register.hpp | 2 +- source/system/platform.cpp | 39 ++++++++++++---------- 9 files changed, 49 insertions(+), 44 deletions(-) diff --git a/include/nana/gui/detail/window_manager.hpp b/include/nana/gui/detail/window_manager.hpp index bc5c9b03..0807978d 100644 --- a/include/nana/gui/detail/window_manager.hpp +++ b/include/nana/gui/detail/window_manager.hpp @@ -139,7 +139,7 @@ namespace detail void enable_tabstop(core_window_t*); core_window_t* tabstop(core_window_t*, bool forward) const; //forward means move to next in logic. - void remove_trash_handle(unsigned tid); + void remove_trash_handle(thread_t tid); bool enable_effects_bground(core_window_t*, bool); diff --git a/source/detail/platform_spec_posix.cpp b/source/detail/platform_spec_posix.cpp index 853f4df1..c6ee7abf 100644 --- a/source/detail/platform_spec_posix.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -214,7 +214,7 @@ namespace detail struct timer_tag { std::size_t id; - unsigned tid; + thread_t tid; std::size_t interval; std::size_t timestamp; timer_proc_t proc; @@ -295,7 +295,7 @@ namespace detail return (holder_.empty()); } - void timer_proc(unsigned tid) + void timer_proc(thread_t tid) { is_proc_handling_ = true; auto i = threadmap_.find(tid); @@ -329,7 +329,7 @@ namespace detail } private: bool is_proc_handling_; - std::map threadmap_; + std::map threadmap_; std::map holder_; }; @@ -966,7 +966,7 @@ namespace detail } } - void platform_spec::timer_proc(unsigned tid) + void platform_spec::timer_proc(thread_t tid) { std::lock_guard lock(timer_.mutex); if(timer_.runner) diff --git a/source/detail/posix/msg_dispatcher.hpp b/source/detail/posix/msg_dispatcher.hpp index 58adf7b0..8aed6ce5 100644 --- a/source/detail/posix/msg_dispatcher.hpp +++ b/source/detail/posix/msg_dispatcher.hpp @@ -35,7 +35,7 @@ namespace detail { struct thread_binder { - unsigned tid; + thread_t tid; std::mutex mutex; std::condition_variable cond; std::list msg_queue; @@ -44,7 +44,7 @@ namespace detail public: typedef msg_packet_tag msg_packet; - typedef void (*timer_proc_type)(unsigned tid); + typedef void (*timer_proc_type)(thread_t tid); typedef void (*event_proc_type)(Display*, msg_packet_tag&); typedef int (*event_filter_type)(XEvent&, msg_packet_tag&); @@ -87,7 +87,7 @@ namespace detail start_driver = (0 == table_.thr_table.size()); thread_binder * thr; - std::map::iterator i = table_.thr_table.find(tid); + std::map::iterator i = table_.thr_table.find(tid); if(i == table_.thr_table.end()) { thr = new thread_binder; @@ -270,7 +270,7 @@ namespace detail //_m_read_queue //@brief:Read the event from a specified thread queue. //@return: 0 = exit the queue, 1 = fetch the msg, -1 = no msg - int _m_read_queue(unsigned tid, msg_packet_tag& msg, Window modal) + int _m_read_queue(thread_t tid, msg_packet_tag& msg, Window modal) { bool stop_driver = false; @@ -317,7 +317,7 @@ namespace detail //_m_wait_for_queue // wait for the insertion of queue. //return@ it returns true if the queue is not empty, otherwise the wait is timeout. - bool _m_wait_for_queue(unsigned tid) + bool _m_wait_for_queue(thread_t tid) { thread_binder * thr = nullptr; { @@ -344,7 +344,7 @@ namespace detail struct table_tag { std::recursive_mutex mutex; - std::map thr_table; + std::map thr_table; std::map wnd_table; }table_; diff --git a/source/detail/posix/platform_spec.hpp b/source/detail/posix/platform_spec.hpp index fc8cc644..e8b2be24 100644 --- a/source/detail/posix/platform_spec.hpp +++ b/source/detail/posix/platform_spec.hpp @@ -186,7 +186,7 @@ namespace detail public: int error_code; public: - typedef void (*timer_proc_type)(unsigned tid); + typedef void (*timer_proc_type)(thread_t tid); typedef void (*event_proc_type)(Display*, msg_packet_tag&); typedef ::nana::event_code event_code; typedef ::nana::native_window_type native_window_type; @@ -235,7 +235,7 @@ namespace detail Window grab(Window); void set_timer(std::size_t id, std::size_t interval, void (*timer_proc)(std::size_t id)); void kill_timer(std::size_t id); - void timer_proc(unsigned tid); + void timer_proc(thread_t tid); //Message dispatcher void msg_insert(native_window_type); diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index 9609fe7f..8412cb04 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -93,13 +93,13 @@ namespace detail { struct thread_context_cache { - unsigned tid{ 0 }; + thread_t tid{ 0 }; thread_context *object{ nullptr }; }tcontext; }cache; }; - void timer_proc(unsigned); + void timer_proc(thread_t); void window_proc_dispatcher(Display*, nana::detail::msg_packet_tag&); void window_proc_for_packet(Display *, nana::detail::msg_packet_tag&); void window_proc_for_xevent(Display*, XEvent&); @@ -352,7 +352,7 @@ namespace detail } - void timer_proc(unsigned tid) + void timer_proc(thread_t tid) { nana::detail::platform_spec::instance().timer_proc(tid); } diff --git a/source/gui/detail/bedrock_windows.cpp b/source/gui/detail/bedrock_windows.cpp index 2d75e7d4..c97618b8 100644 --- a/source/gui/detail/bedrock_windows.cpp +++ b/source/gui/detail/bedrock_windows.cpp @@ -176,7 +176,7 @@ namespace detail { struct thread_context_cache { - unsigned tid{ 0 }; + thread_t tid{ 0 }; thread_context *object{ nullptr }; }tcontext; }cache; @@ -245,7 +245,7 @@ namespace detail /// @brief increament the number of windows in the thread id - int bedrock::inc_window(unsigned tid) + int bedrock::inc_window(thread_t tid) { //impl refers to the object of private_impl, the object is created when bedrock is creating. private_impl * impl = instance().impl_; @@ -255,7 +255,7 @@ namespace detail return (cnt < 0 ? cnt = 1 : ++cnt); } - auto bedrock::open_thread_context(unsigned tid) -> thread_context* + auto bedrock::open_thread_context(thread_t tid) -> thread_context* { if(0 == tid) tid = nana::system::this_thread_id(); std::lock_guardmutex)> lock(impl_->mutex); @@ -269,7 +269,7 @@ namespace detail return context; } - auto bedrock::get_thread_context(unsigned tid) -> thread_context * + auto bedrock::get_thread_context(thread_t tid) -> thread_context * { if(0 == tid) tid = nana::system::this_thread_id(); @@ -289,7 +289,7 @@ namespace detail return nullptr; } - void bedrock::remove_thread_context(unsigned tid) + void bedrock::remove_thread_context(thread_t tid) { if(0 == tid) tid = nana::system::this_thread_id(); @@ -347,7 +347,7 @@ namespace detail void bedrock::pump_event(window condition_wd, bool is_modal) { - const unsigned tid = ::GetCurrentThreadId(); + thread_t tid = ::GetCurrentThreadId(); auto context = this->open_thread_context(tid); if(0 == context->window_count) { diff --git a/source/gui/detail/window_manager.cpp b/source/gui/detail/window_manager.cpp index 83eb2ef4..cd85c260 100644 --- a/source/gui/detail/window_manager.cpp +++ b/source/gui/detail/window_manager.cpp @@ -273,10 +273,10 @@ namespace detail //class revertible_mutex struct thread_refcount { - unsigned tid; //Thread ID + thread_t tid; //Thread ID std::vector callstack_refs; - thread_refcount(unsigned thread_id, unsigned refs) + thread_refcount(thread_t thread_id, unsigned refs) : tid(thread_id) { callstack_refs.push_back(refs); @@ -287,7 +287,7 @@ namespace detail { std::recursive_mutex mutex; - unsigned thread_id; //Thread ID + thread_t thread_id; //Thread ID unsigned refs; //Ref count std::vector records; @@ -1442,7 +1442,7 @@ namespace detail return nullptr; } - void window_manager::remove_trash_handle(unsigned tid) + void window_manager::remove_trash_handle(thread_t tid) { //Thread-Safe Required! std::lock_guard lock(mutex_); diff --git a/source/gui/detail/window_register.hpp b/source/gui/detail/window_register.hpp index 40b2fae6..7a2500e4 100644 --- a/source/gui/detail/window_register.hpp +++ b/source/gui/detail/window_register.hpp @@ -153,7 +153,7 @@ namespace nana } } - void delete_trash(unsigned thread_id) + void delete_trash(thread_t thread_id) { if (0 == thread_id) { diff --git a/source/system/platform.cpp b/source/system/platform.cpp index dd255f46..95221a37 100644 --- a/source/system/platform.cpp +++ b/source/system/platform.cpp @@ -26,6 +26,27 @@ #include #include #include + +static void posix_open_url(const char *url_utf8) +{ + extern char **environ; + const char *home = getenv("HOME"); + std::string cheat(home); + cheat += "/.mozilla"; + struct stat exists{}; + // Look for $HOME/.mozilla directory as + // strong evidence they use firefox. + if ( stat(cheat.c_str(), &exists) == 0 && S_ISDIR(exists.st_mode)) + { + pid_t pid = 0; + static const char firefox[] = "firefox"; + char name[sizeof firefox]{}; + // argv does not like const-literals so make a copy. + strcpy(name, firefox); + char *argv[3] = {name, const_cast(url_utf8), nullptr}; + posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ); + } +} #endif namespace nana @@ -120,23 +141,7 @@ namespace system ::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL); } #elif defined(NANA_POSIX) - const char *home = getenv("HOME"); - std::string cheat(home); - cheat += "/.mozilla"; - struct stat exists{}; - // Look for $HOME/.mozilla directory as - // strong evidence they use firefox. - if ( stat(cheat.c_str(), &exists) == 0 && S_ISDIR(exists.st_mode)) - { - extern char **environ; - pid_t pid = 0; - static const char firefox[] = "firefox"; - char name[sizeof firefox]{}; - // argv does not like const-literals so make a copy. - strcpy(name, firefox); - char *argv[3] = {name, const_cast(url_utf8.c_str()), nullptr}; - posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ); - } + posix_open_url(url_utf8.c_str()); #endif } }//end namespace system From bf0228487b5e1401d48304f34f6d5069bfd15764 Mon Sep 17 00:00:00 2001 From: unitrunker Date: Mon, 22 Jan 2018 14:52:10 -0600 Subject: [PATCH 04/13] Deal with possible BOM (dont assume BOM always there). --- source/gui/detail/bedrock_posix.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index 8412cb04..dcbea76d 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -983,8 +983,8 @@ namespace detail nana::detail::charset_conv charset(NANA_UNICODE, "UTF-8"); const std::string& str = charset.charset(std::string(keybuf, keybuf + len)); - charbuf = reinterpret_cast(str.c_str()) + 1; - len = str.size() / sizeof(wchar_t) - 1; + charbuf = reinterpret_cast(str.c_str()); + len = str.size() / sizeof(wchar_t); for(int i = 0; i < len; ++i) { @@ -992,6 +992,9 @@ namespace detail arg.ignore = false; arg.key = charbuf[i]; + // ignore Unicode BOM (it may or may not appear) + if (arg.key == 0xFEFF) continue; + //Only accept tab when it is not ignored. if ((keyboard::tab == arg.key) && root_runtime->condition.ignore_tab) continue; From aada05d28ddb47bce9ab89a5b4e20d2e63362a07 Mon Sep 17 00:00:00 2001 From: unitrunker Date: Mon, 22 Jan 2018 18:29:15 -0600 Subject: [PATCH 05/13] long long was overkill. --- include/nana/c++defines.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/nana/c++defines.hpp b/include/nana/c++defines.hpp index f4aa89f6..24f2f844 100644 --- a/include/nana/c++defines.hpp +++ b/include/nana/c++defines.hpp @@ -89,16 +89,16 @@ #define NANA_MACOS #define NANA_POSIX #define NANA_X11 - typedef long long thread_t; + typedef unsigned long thread_t; #elif defined(__FreeBSD__) #define NANA_POSIX #define NANA_X11 - typedef long long thread_t; + typedef unsigned long thread_t; #elif (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC) //Linux #define NANA_LINUX #define NANA_POSIX #define NANA_X11 - typedef long long thread_t; + typedef unsigned long thread_t; #else static_assert(false, "Only Windows and Linux are supported now (Mac OS and BSD are experimental)"); #endif From 796e5a492475ef5c30f820d2dc0535e23bdd8f62 Mon Sep 17 00:00:00 2001 From: unitrunker Date: Mon, 22 Jan 2018 20:22:10 -0600 Subject: [PATCH 06/13] static for potentially easier use elsewhere. --- source/charset.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/charset.cpp b/source/charset.cpp index 1b258fc7..ffb82e72 100644 --- a/source/charset.cpp +++ b/source/charset.cpp @@ -234,7 +234,7 @@ namespace nana }; /// convert wchar C string from ? ANSI code page CP_ACP (windows) or LC_CTYPE c locale (-nix) into utf8 std::string - bool wc2mb(std::string& mbstr, const wchar_t * s) + static bool wc2mb(std::string& mbstr, const wchar_t * s) { if(nullptr == s || *s == 0) { @@ -268,7 +268,7 @@ namespace nana } /// convert a char C-string from The system default Windows ANSI code page CP_ACP or from LC_CTYPE c locale (-nix) into utf16 std::wstring - bool mb2wc(std::wstring& wcstr, const char* s) + static bool mb2wc(std::wstring& wcstr, const char* s) { if(nullptr == s || *s == 0) { From 4415ba4ca0e5e88a75f3956bb27baed505732927 Mon Sep 17 00:00:00 2001 From: unitrunker Date: Mon, 22 Jan 2018 20:23:41 -0600 Subject: [PATCH 07/13] nana::system::open_url actually works (with limitations). --- source/system/platform.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/source/system/platform.cpp b/source/system/platform.cpp index 95221a37..a34c5d1e 100644 --- a/source/system/platform.cpp +++ b/source/system/platform.cpp @@ -34,17 +34,29 @@ static void posix_open_url(const char *url_utf8) std::string cheat(home); cheat += "/.mozilla"; struct stat exists{}; - // Look for $HOME/.mozilla directory as - // strong evidence they use firefox. + + // TODO: generalize this for chromium, opera, waterfox, etc. + // Most desktop environments (KDE, Gnome, Lumina etc.) provide a way to set + // your preferred browser - but there are more desktops than browsers. + + // Look for $HOME/.mozilla directory as strong evidence they use firefox. if ( stat(cheat.c_str(), &exists) == 0 && S_ISDIR(exists.st_mode)) { + const char *path = ""; + static const char *likely[2] = { "/usr/local/bin/firefox", "/usr/bin/firefox"}; + if ( stat(likely[0], &exists) == 0 && S_ISREG(exists.st_mode)) + path = likely[0]; + else if ( stat(likely[1], &exists) == 0 && S_ISREG(exists.st_mode) ) + path = likely[1]; + else return; + pid_t pid = 0; static const char firefox[] = "firefox"; char name[sizeof firefox]{}; // argv does not like const-literals so make a copy. strcpy(name, firefox); char *argv[3] = {name, const_cast(url_utf8), nullptr}; - posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ); + posix_spawn(&pid, path, NULL, NULL, argv, environ); } } #endif From 9b85d0a3f0e241753260f4baecd5969e19c7646d Mon Sep 17 00:00:00 2001 From: unitrunker Date: Mon, 22 Jan 2018 21:52:54 -0600 Subject: [PATCH 08/13] POSIX *after* LINUX --- include/nana/audio/detail/audio_device.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nana/audio/detail/audio_device.hpp b/include/nana/audio/detail/audio_device.hpp index 915d6780..768a957a 100644 --- a/include/nana/audio/detail/audio_device.hpp +++ b/include/nana/audio/detail/audio_device.hpp @@ -9,10 +9,10 @@ #include #if defined(NANA_WINDOWS) #include -#elif defined(NANA_POSIX) - #include #elif defined(NANA_LINUX) #include +#elif defined(NANA_POSIX) + #include #endif namespace nana{ namespace audio From 80dcc96da41b59edd7659e925f77209dbd31c3ff Mon Sep 17 00:00:00 2001 From: unitrunker Date: Tue, 23 Jan 2018 18:44:52 -0600 Subject: [PATCH 09/13] missing header file for strcpy. --- source/system/platform.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/system/platform.cpp b/source/system/platform.cpp index a34c5d1e..56239cf6 100644 --- a/source/system/platform.cpp +++ b/source/system/platform.cpp @@ -26,6 +26,7 @@ #include #include #include + #include static void posix_open_url(const char *url_utf8) { From 37882efb1ad419d147d19ed78d8204a22a81794c Mon Sep 17 00:00:00 2001 From: unitrunker Date: Tue, 23 Jan 2018 19:34:16 -0600 Subject: [PATCH 10/13] Attempt fix for gcc 4.9 --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cdeb93d..115e59fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,7 +174,11 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AN # message("Setting NANA_LINKS to -static-libgcc -static-libstdc++ -pthread or ${NANA_LINKS}") endif(NANA_CMAKE_SHARED_LIB) - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) + # GCC 4.9 + list(APPEND NANA_LINKS -lboost_system -lboost_thread) + + elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) # IS_GNUCXX < 5.3 else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) From a716d4837ac68f18dcbcb2696442c3676429d657 Mon Sep 17 00:00:00 2001 From: unitrunker Date: Wed, 24 Jan 2018 19:56:34 -0600 Subject: [PATCH 11/13] Whats up with compiler version? --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 115e59fb..bb53c4b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -395,6 +395,7 @@ message ( "NANA_CMAKE_ENABLE_AUDIO = " ${NANA_CMAKE_ENABLE_AUDIO}) message ( "NANA_CMAKE_SHARED_LIB = " ${NANA_CMAKE_SHARED_LIB}) message ( "NANA_CLION = " ${NANA_CLION}) message ( "CMAKE_MAKE_PROGRAM = " ${CMAKE_MAKE_PROGRAM}) +message ( "CMAKE_CXX_COMPILER_VERSION = " ${CMAKE_CXX_COMPILER_VERSION}) message ( "NANA_CMAKE_FIND_BOOST_FILESYSTEM = " ${NANA_CMAKE_FIND_BOOST_FILESYSTEM}) message ( "NANA_CMAKE_BOOST_FILESYSTEM_FORCE = " ${NANA_CMAKE_BOOST_FILESYSTEM_FORCE}) From 2e360da2173dce86f49a104ac27e80636b60f7dd Mon Sep 17 00:00:00 2001 From: unitrunker Date: Wed, 24 Jan 2018 20:37:55 -0600 Subject: [PATCH 12/13] play with list APPEND --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb53c4b0..811e7784 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,16 +176,16 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AN if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) # GCC 4.9 - list(APPEND NANA_LINKS -lboost_system -lboost_thread) + list(APPEND NANA_LINKS "-lboost_system -lboost_thread") elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) # IS_GNUCXX < 5.3 - else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) + else() # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++fs") # IS_GNUCXX 5.3 or more list(APPEND NANA_LINKS -lstdc++fs) - endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3) + endif() endif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # AND NOT MINGW From 9127942a5ad4db8a71b8397ab2a5a0e88eecc12a Mon Sep 17 00:00:00 2001 From: unitrunker Date: Wed, 24 Jan 2018 20:53:35 -0600 Subject: [PATCH 13/13] if someone wants this, they can put it back - fixed. --- .travis.yml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index d6805b1e..75c0a444 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,24 +22,6 @@ matrix: - libxft-dev sources: - ubuntu-toolchain-r-test - - env: CXX=g++-4.9 CC=gcc-4.9 - addons: - apt: - packages: - - g++-4.9 - - libjpeg8-dev - - libpng-dev - - libasound2-dev - - alsa-utils - - alsa-oss - - libx11-dev - - libxft-dev - - libboost-filesystem-dev - - libboost-system-dev - - libboost-thread-dev - - libboost-chrono-dev - sources: - - ubuntu-toolchain-r-test allow_failures: - env: CXX=clang++-3.8 CC=clang-3.8