diff --git a/include/modules/fs.hpp b/include/modules/fs.hpp index 728614a5..b43d4ea4 100644 --- a/include/modules/fs.hpp +++ b/include/modules/fs.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "components/config.hpp" #include "modules/meta/timer_module.hpp" #include "settings.hpp" @@ -25,7 +27,7 @@ namespace modules { int percentage_free{0}; int percentage_used{0}; - explicit fs_mount(const string& mountpoint, bool mounted = false) : mountpoint(mountpoint), mounted(mounted) {} + explicit fs_mount(string mountpoint, bool mounted = false) : mountpoint(move(mountpoint)), mounted(mounted) {} }; using fs_mount_t = unique_ptr; diff --git a/include/x11/xresources.hpp b/include/x11/xresources.hpp index 763e6b72..65fda3d0 100644 --- a/include/x11/xresources.hpp +++ b/include/x11/xresources.hpp @@ -48,7 +48,7 @@ class xresource_manager { T get(const char* name, const T& fallback) const { try { return convert(require(name)); - } catch (const xresource_error) { + } catch (const xresource_error&) { return fallback; } } diff --git a/src/adapters/mpd.cpp b/src/adapters/mpd.cpp index 4a5438ad..425af042 100644 --- a/src/adapters/mpd.cpp +++ b/src/adapters/mpd.cpp @@ -168,7 +168,7 @@ namespace mpd { } bool mpdconnection::connected() { - return m_connection && m_connection != nullptr; + return static_cast(m_connection); } bool mpdconnection::retry_connection(int interval) { diff --git a/src/modules/alsa.cpp b/src/modules/alsa.cpp index 429835c1..da432494 100644 --- a/src/modules/alsa.cpp +++ b/src/modules/alsa.cpp @@ -265,15 +265,15 @@ namespace modules { bool headphones{m_headphones}; if (m_mixer[mixer::MASTER] && !m_mixer[mixer::MASTER]->get_name().empty()) { - mixers.emplace_back(new mixer_t::element_type( + mixers.emplace_back(std::make_shared( string{m_mixer[mixer::MASTER]->get_name()}, string{m_mixer[mixer::MASTER]->get_sound_card()})); } if (m_mixer[mixer::HEADPHONE] && !m_mixer[mixer::HEADPHONE]->get_name().empty() && headphones) { - mixers.emplace_back(new mixer_t::element_type( + mixers.emplace_back(std::make_shared( string{m_mixer[mixer::HEADPHONE]->get_name()}, string{m_mixer[mixer::HEADPHONE]->get_sound_card()})); } if (m_mixer[mixer::SPEAKER] && !m_mixer[mixer::SPEAKER]->get_name().empty() && !headphones) { - mixers.emplace_back(new mixer_t::element_type( + mixers.emplace_back(std::make_shared( string{m_mixer[mixer::SPEAKER]->get_name()}, string{m_mixer[mixer::SPEAKER]->get_sound_card()})); } diff --git a/src/modules/fs.cpp b/src/modules/fs.cpp index b8193fd2..368d327e 100644 --- a/src/modules/fs.cpp +++ b/src/modules/fs.cpp @@ -87,7 +87,7 @@ namespace modules { for (auto&& mountpoint : m_mountpoints) { auto details = std::find_if(mountinfo.begin(), mountinfo.end(), [&](const vector& m) { return m.size() > 4 && m[MOUNTINFO_DIR] == mountpoint; }); - m_mounts.emplace_back(new fs_mount{mountpoint, details != mountinfo.end()}); + m_mounts.emplace_back(std::make_unique(mountpoint, details != mountinfo.end())); struct statvfs buffer {}; if (!m_mounts.back()->mounted) { @@ -106,20 +106,24 @@ namespace modules { mount->bytes_used = mount->bytes_total - mount->bytes_free; mount->bytes_avail = static_cast(buffer.f_frsize) * static_cast(buffer.f_bavail); - mount->percentage_free = math_util::percentage(mount->bytes_avail, mount->bytes_used + mount->bytes_avail); - mount->percentage_used = math_util::percentage(mount->bytes_used, mount->bytes_used + mount->bytes_avail); + mount->percentage_free = + math_util::percentage(mount->bytes_avail, mount->bytes_used + mount->bytes_avail); + mount->percentage_used = + math_util::percentage(mount->bytes_used, mount->bytes_used + mount->bytes_avail); } } if (m_remove_unmounted) { - for (auto&& mount : m_mounts) { - if (!mount->mounted) { - m_log.info("%s: Removing mountpoint \"%s\" (reason: `remove-unmounted = true`)", name(), mount->mountpoint); - m_mountpoints.erase( - std::remove(m_mountpoints.begin(), m_mountpoints.end(), mount->mountpoint), m_mountpoints.end()); - m_mounts.erase(std::remove(m_mounts.begin(), m_mounts.end(), mount), m_mounts.end()); - } + auto new_end = + std::stable_partition(m_mounts.begin(), m_mounts.end(), [](const auto& mount) { return mount->mounted; }); + + for (auto it = new_end; it < m_mounts.end(); ++it) { + m_log.info("%s: Removing mountpoint \"%s\" (reason: `remove-unmounted = true`)", name(), (*it)->mountpoint); + m_mountpoints.erase( + std::remove(m_mountpoints.begin(), m_mountpoints.end(), (*it)->mountpoint), m_mountpoints.end()); } + + m_mounts.erase(new_end, m_mounts.end()); } return true; @@ -197,6 +201,6 @@ namespace modules { return true; } -} +} // namespace modules POLYBAR_NS_END diff --git a/src/modules/ipc.cpp b/src/modules/ipc.cpp index c8082769..2e6b9948 100644 --- a/src/modules/ipc.cpp +++ b/src/modules/ipc.cpp @@ -16,7 +16,7 @@ namespace modules { size_t index = 0; for (auto&& command : m_conf.get_list(name(), "hook")) { - m_hooks.emplace_back(new hook{name() + to_string(++index), command}); + m_hooks.emplace_back(std::make_unique(hook{name() + to_string(++index), command})); } if (m_hooks.empty()) { diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index 837f68d2..4670565b 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -254,7 +254,7 @@ namespace modules { if (m_mpd) { auto song = m_mpd->get_song(); - if (song && song.get()) { + if (song) { artist = song->get_artist(); album_artist = song->get_album_artist(); album = song->get_album(); diff --git a/src/modules/xwindow.cpp b/src/modules/xwindow.cpp index fbc23af6..4afde7d8 100644 --- a/src/modules/xwindow.cpp +++ b/src/modules/xwindow.cpp @@ -132,7 +132,7 @@ namespace modules { * Output content as defined in the config */ bool xwindow_module::build(builder* builder, const string& tag) const { - if (tag == TAG_LABEL && m_label && m_label.get()) { + if (tag == TAG_LABEL && m_label) { builder->node(m_label); return true; } diff --git a/src/x11/background_manager.cpp b/src/x11/background_manager.cpp index e8e10642..8dc2b132 100644 --- a/src/x11/background_manager.cpp +++ b/src/x11/background_manager.cpp @@ -189,7 +189,7 @@ void bg_slice::allocate_resources(const logger& log, xcb_visualtype_t* visual) { } void bg_slice::free_resources() { - m_surface.release(); + m_surface.reset(); if(m_pixmap != XCB_NONE) { m_connection.free_pixmap(m_pixmap); diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp index 5cf503d1..66bca404 100644 --- a/src/x11/tray_manager.cpp +++ b/src/x11/tray_manager.cpp @@ -253,8 +253,8 @@ void tray_manager::deactivate(bool clear_selection) { m_log.trace("tray: Destroy window"); m_connection.destroy_window(m_tray); } - m_context.release(); - m_surface.release(); + m_context.reset(); + m_surface.reset(); if (m_pixmap) { m_connection.free_pixmap(m_pixmap); } @@ -519,11 +519,11 @@ void tray_manager::create_bg(bool realloc) { m_gc = 0; } - if (realloc && m_surface) { - m_surface.release(); + if(realloc && m_surface) { + m_surface.reset(); } - if (realloc && m_context) { - m_context.release(); + if(realloc && m_context) { + m_context.reset(); } auto w = m_opts.width_max;