From 6145c2082d3d116962dc96602c9ad2d22d62c675 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Feb 2017 11:26:31 +0100 Subject: logic/shortcuts: remove shared_ptr usage --- logic/shortcuts.cpp | 35 +++++++++++++++++++++-------------- logic/shortcuts.h | 3 ++- 2 files changed, 23 insertions(+), 15 deletions(-) (limited to 'logic') diff --git a/logic/shortcuts.cpp b/logic/shortcuts.cpp index 494af30e..27d47c8b 100644 --- a/logic/shortcuts.cpp +++ b/logic/shortcuts.cpp @@ -11,15 +11,17 @@ #include +#include + void Shortcuts::free_binding(K& key) { #ifndef _WIN32 if (key) { - key->setEnabled(false); - key->setShortcut(QKeySequence::UnknownKey); - std::shared_ptr tmp(nullptr); - key.swap(tmp); + //key->setEnabled(false); + //key->setShortcut(QKeySequence()); + delete key; + key = nullptr; } #else key.keycode = 0; @@ -36,7 +38,7 @@ void Shortcuts::bind_shortcut(K &key, const key_opts& k, unused_on_unix(bool, he free_binding(key); } - key = std::make_shared(); + key = new sh; if (k.keycode != "") { @@ -107,6 +109,14 @@ void Shortcuts::receiver(const Key& k) void Shortcuts::reload(const t_keys& keys_) { const unsigned sz = keys_.size(); +#ifndef _WIN32 + for (tt& tuple : keys) + { + K k; + std::tie(k, std::ignore, std::ignore) = tuple; + delete k; + } +#endif keys = std::vector(); for (unsigned i = 0; i < sz; i++) @@ -115,22 +125,19 @@ void Shortcuts::reload(const t_keys& keys_) const key_opts& opts = std::get<0>(kk); const bool held = std::get<2>(kk); auto fun = std::get<1>(kk); - K k; - bind_shortcut(k, opts, held); - keys.push_back(tt(k, [=](unused_on_unix(bool, flag)) -> void - { #ifdef _WIN32 - fun(flag); + K k; #else - fun(true); + K k(nullptr); #endif - }, - held)); + bind_shortcut(k, opts, held); + keys.push_back(tt(k, [=](bool flag) { fun(flag); }, held)); + #ifndef _WIN32 const int idx = keys.size() - 1; tt& kk_ = keys[idx]; auto& fn = std::get<1>(kk_); - connect(k.get(), &QxtGlobalShortcut::activated, [=]() -> void { fn(true); }); + connect(k, &QxtGlobalShortcut::activated, [=]() { fn(true); }); #endif } } diff --git a/logic/shortcuts.h b/logic/shortcuts.h index 1f57a8fb..4ddc5b34 100644 --- a/logic/shortcuts.h +++ b/logic/shortcuts.h @@ -11,6 +11,7 @@ #include "options/options.hpp" #include "main-settings.hpp" +#include "compat/util.hpp" #ifdef _WIN32 # include "dinput/keybinding-worker.hpp" @@ -33,7 +34,7 @@ struct OPENTRACK_LOGIC_EXPORT Shortcuts final : public QObject public: using K = #ifndef _WIN32 - mem + QxtGlobalShortcut* #else Key #endif -- cgit v1.2.3