diff --git a/CMakeLists.txt b/CMakeLists.txt
index dc6315d65a0e9719167f280fcdf8727ece0ad588..417c13ff0e8ff982421823f24635159acfad2bed 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -64,64 +64,63 @@ endif()
 
 if (PEDANTIC)
     if (CMAKE_COMPILER_IS_GNUCXX)
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wall \
-            -Wsuggest-override \
-            -Wlogical-op \
-            -Wnoexcept \
-            -Wstrict-null-sentinel \
-            ")
+        list(APPEND copyq_pedantic_flags
+            -Wextra -Wall
+            -Wsuggest-override
+            -Wlogical-op
+            -Wnoexcept
+            -Wstrict-null-sentinel
+            )
     else()
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything \
-            -Winconsistent-missing-override \
-            ")
-
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-            -Wno-c++98-compat \
-            -Wno-c++98-compat-pedantic \
-            -Wno-shadow-field-in-constructor \
-            -Wno-weak-vtables \
-            -Wno-disabled-macro-expansion \
-            -fcomment-block-commands=retval \
-            ")
-
-        # Disable errors from moc-generated files.
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-            -Wno-undefined-reinterpret-cast \
-            -Wno-missing-prototypes \
-            ")
-
-        # Disable errors from qrc-generated files.
-        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-            -Wno-exit-time-destructors \
-            -Wno-global-constructors \
-            ")
+        list(APPEND copyq_pedantic_flags
+            -Weverything
+            -Winconsistent-missing-override
+            )
+
+        list(APPEND copyq_pedantic_flags
+            -Wno-c++98-compat
+            -Wno-c++98-compat-pedantic
+            -Wno-disabled-macro-expansion
+            -Wno-exit-time-destructors
+            -Wno-extra-semi-stmt
+            -Wno-redundant-parens
+            -Wno-shadow-field
+            -Wno-shadow-field-in-constructor
+            -Wno-shorten-64-to-32
+            -Wno-sign-conversion
+            -Wno-suggest-destructor-override
+            -Wno-unknown-warning-option
+            -Wno-used-but-marked-unused
+            -Wno-weak-vtables
+            -fcomment-block-commands=retval
+            )
     endif()
 
-    set(CMAKE_CXX_FLAGS
-        "${CMAKE_CXX_FLAGS} -pedantic -Werror \
-        -Wcast-align \
-        -Wctor-dtor-privacy \
-        -Wdisabled-optimization \
-        -Wformat=2 \
-        -Winit-self \
-        -Wmissing-declarations \
-        -Wmissing-include-dirs \
-        -Wold-style-cast \
-        -Woverloaded-virtual \
-        -Wredundant-decls \
-        -Wstrict-overflow=4 \
-        -Wundef \
-        ")
-
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-        -Wno-padded \
-        -Wno-switch-enum \
-        ")
+    list(APPEND copyq_pedantic_flags
+        -pedantic
+        -Wcast-align
+        -Wctor-dtor-privacy
+        -Wdisabled-optimization
+        -Wformat=2
+        -Winit-self
+        -Wmissing-declarations
+        -Wmissing-include-dirs
+        -Wold-style-cast
+        -Woverloaded-virtual
+        -Wredundant-decls
+        -Wstrict-overflow=4
+        -Wundef
+        )
+
+    list(APPEND copyq_pedantic_flags
+        -Wno-padded
+        -Wno-switch-enum
+        )
 
     # Disable Q_OBJECT macro warnings.
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-        -Wno-unused-member-function \
-        ")
+    list(APPEND copyq_pedantic_flags
+        -Wno-unused-member-function
+        )
 endif()
 
 if(WITH_TESTS)
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
index 9a20f45955ba78514e64641fd902f8e799e211e2..d6209844ee2ae73b7566d5d66557a3dcf81b9b96 100644
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -1,7 +1,7 @@
 macro (copyq_add_plugin copyq_pkg)
-
     file(GLOB copyq_plugin_SOURCES
         ${copyq_plugin_${copyq_pkg}_SOURCES}
+        ${copyq_plugin_${copyq_pkg}_external_SOURCES}
         *.cpp
         ../../src/item/itemwidget.cpp
         )
@@ -10,6 +10,10 @@ macro (copyq_add_plugin copyq_pkg)
         *.ui
         )
 
+    set_source_files_properties(
+        ${copyq_plugin_${copyq_pkg}_SOURCES} PROPERTIES
+        COMPILE_OPTIONS "${copyq_pedantic_flags}")
+
     if (WITH_TESTS)
         file(GLOB copyq_plugin_SOURCES ${copyq_plugin_SOURCES} tests/*.cpp)
     endif (WITH_TESTS)
diff --git a/plugins/itemencrypted/itemencrypted.cpp b/plugins/itemencrypted/itemencrypted.cpp
index edefaca6e3b66a036f8f0226db35a8e152efec60..6be260dced26c48b63764ee5ad5176fe67ae3571 100644
--- a/plugins/itemencrypted/itemencrypted.cpp
+++ b/plugins/itemencrypted/itemencrypted.cpp
@@ -756,7 +756,7 @@ QObject *ItemEncryptedLoader::tests(const TestInterfacePtr &test) const
     QObject *tests = new ItemEncryptedTests(test);
     return tests;
 #else
-    Q_UNUSED(test);
+    Q_UNUSED(test)
     return nullptr;
 #endif
 }
diff --git a/plugins/itemfakevim/CMakeLists.txt b/plugins/itemfakevim/CMakeLists.txt
index 5480d20c122dee43f315f1c4ae77e81a4ab51f3c..bf80f6e9f9d07cee3ef60a0e98ad9bf521db6f62 100644
--- a/plugins/itemfakevim/CMakeLists.txt
+++ b/plugins/itemfakevim/CMakeLists.txt
@@ -1,6 +1,7 @@
 file(GLOB copyq_plugin_itemfakevim_SOURCES
-    ${copyq_plugin_itemfakevim_SOURCES}
     ../../src/item/itemwidgetwrapper.cpp
+    )
+file(GLOB copyq_plugin_itemfakevim_external_SOURCES
     fakevim/*.cpp
     fakevim/utils/*.cpp
     )
@@ -15,30 +16,3 @@ set(copyq_plugin_itemfakevim_DEFINITIONS
 set(copyq_plugin_itemfakevim_RESOURCES itemfakevim.qrc)
 
 copyq_add_plugin(itemfakevim)
-
-# Disable warnings for 3rd-party source code.
-if (PEDANTIC)
-    if (CMAKE_COMPILER_IS_GNUCXX)
-        set(IGNORE_PEDANTIC_FLAGS "-Wno-suggest-override")
-    else()
-        set(IGNORE_PEDANTIC_FLAGS "-Wno-unused-macros")
-    endif()
-
-    set_source_files_properties(
-        fakevim/fakevimhandler.cpp
-        fakevim/fakevimactions.cpp
-        PROPERTIES COMPILE_FLAGS
-        "\
-        -Wno-shorten-64-to-32 \
-        -Wno-sign-conversion \
-        -Wno-conversion \
-        -Wno-unreachable-code \
-        -Wno-documentation-unknown-command \
-        -Wno-shadow \
-        -Wno-missing-declarations \
-        -Wno-strict-overflow \
-        -Wno-zero-as-null-pointer-constant \
-        ${IGNORE_PEDANTIC_FLAGS} \
-        ")
-endif()
-
diff --git a/plugins/itemfakevim/itemfakevim.cpp b/plugins/itemfakevim/itemfakevim.cpp
index 3e53aa24ff3d917585701006b00995eb33d3dbbc..9d9a69cedc71aff3440a4302f22c79005a45a6f9 100644
--- a/plugins/itemfakevim/itemfakevim.cpp
+++ b/plugins/itemfakevim/itemfakevim.cpp
@@ -808,7 +808,7 @@ QObject *ItemFakeVimLoader::tests(const TestInterfacePtr &test) const
     tests->setProperty("CopyQ_test_settings", settings);
     return tests;
 #else
-    Q_UNUSED(test);
+    Q_UNUSED(test)
     return nullptr;
 #endif
 }
diff --git a/plugins/itempinned/itempinned.cpp b/plugins/itempinned/itempinned.cpp
index 831ab369e897eb2664f48ab25abe7bcf4c7a612b..738d37c78d8c27ccb135b004de2587e8f6155d0d 100644
--- a/plugins/itempinned/itempinned.cpp
+++ b/plugins/itempinned/itempinned.cpp
@@ -369,7 +369,7 @@ QObject *ItemPinnedLoader::tests(const TestInterfacePtr &test) const
     QObject *tests = new ItemPinnedTests(test);
     return tests;
 #else
-    Q_UNUSED(test);
+    Q_UNUSED(test)
     return nullptr;
 #endif
 }
diff --git a/plugins/itemsync/itemsync.cpp b/plugins/itemsync/itemsync.cpp
index 27a309cca15d0d98cb0c33756483e863bc4a59c0..a617a146679ce2db67fb66dacf399f6459de9a52 100644
--- a/plugins/itemsync/itemsync.cpp
+++ b/plugins/itemsync/itemsync.cpp
@@ -783,7 +783,7 @@ QObject *ItemSyncLoader::tests(const TestInterfacePtr &test) const
     tests->setProperty("CopyQ_test_settings", settings);
     return tests;
 #else
-    Q_UNUSED(test);
+    Q_UNUSED(test)
     return nullptr;
 #endif
 }
diff --git a/plugins/itemtags/itemtags.cpp b/plugins/itemtags/itemtags.cpp
index 4e6f41e5672d59af2cbed42871a6f81f5b268116..e9860191d89e90c961c7b9666a6aa68bdabfbc0d 100644
--- a/plugins/itemtags/itemtags.cpp
+++ b/plugins/itemtags/itemtags.cpp
@@ -679,7 +679,7 @@ QObject *ItemTagsLoader::tests(const TestInterfacePtr &test) const
     tests->setProperty("CopyQ_test_settings", settings);
     return tests;
 #else
-    Q_UNUSED(test);
+    Q_UNUSED(test)
     return nullptr;
 #endif
 }
diff --git a/qxt/qxtglobalshortcut_mac.cpp b/qxt/qxtglobalshortcut_mac.cpp
index 16be4d6f82b48ff2434ac3b9eaf5498c92b9d019..bac7fd8c81660d7d5cac14b304768fe8fd20ceaf 100644
--- a/qxt/qxtglobalshortcut_mac.cpp
+++ b/qxt/qxtglobalshortcut_mac.cpp
@@ -43,8 +43,8 @@ static bool qxt_mac_handler_installed = false;
 
 OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data)
 {
-    Q_UNUSED(nextHandler);
-    Q_UNUSED(data);
+    Q_UNUSED(nextHandler)
+    Q_UNUSED(data)
     if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed)
     {
         EventHotKeyID keyID;
@@ -76,9 +76,9 @@ quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifier
 bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
     void * message, long * result)
 {
-    Q_UNUSED(result);
-    Q_UNUSED(message);
-    Q_UNUSED(eventType);
+    Q_UNUSED(result)
+    Q_UNUSED(message)
+    Q_UNUSED(eventType)
 
     return false;
 }
diff --git a/qxt/qxtglobalshortcut_win.cpp b/qxt/qxtglobalshortcut_win.cpp
index 4876b72e5cc55c5e42654d3e6739a49850cfcd4e..0acf55c99ae5a615016a49702dca53e347e28821 100644
--- a/qxt/qxtglobalshortcut_win.cpp
+++ b/qxt/qxtglobalshortcut_win.cpp
@@ -39,8 +39,8 @@ bool QxtGlobalShortcutPrivate::eventFilter(void* message)
 bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
     void * message, long * result)
 {
-    Q_UNUSED(eventType);
-    Q_UNUSED(result);
+    Q_UNUSED(eventType)
+    Q_UNUSED(result)
 #endif
     MSG* msg = static_cast<MSG*>(message);
     if (msg->message == WM_HOTKEY)
diff --git a/qxt/qxtglobalshortcut_x11.cpp b/qxt/qxtglobalshortcut_x11.cpp
index b654fd85d19b2ae9d4b45098ec839cd8f9500b22..0f22c9f21fa0e3f9ada149e5d21a88b8c277215c 100644
--- a/qxt/qxtglobalshortcut_x11.cpp
+++ b/qxt/qxtglobalshortcut_x11.cpp
@@ -79,7 +79,7 @@ public:
 
     static int qxtX11ErrorHandler(Display* display, XErrorEvent *event)
     {
-        Q_UNUSED(display);
+        Q_UNUSED(display)
         switch (event->error_code)
         {
             case BadAccess:
@@ -227,7 +227,7 @@ bool QxtGlobalShortcutPrivate::eventFilter(void* message)
 bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
     void * message, long * result)
 {
-    Q_UNUSED(result);
+    Q_UNUSED(result)
 
     xcb_key_press_event_t *kev = nullptr;
     if (eventType == "xcb_generic_event_t") {
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7e8a832ea15faf29f9209c4ca28576d8ad13f893..91636794116a7637b4a27e468e13fe1dfcb4c89c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -22,6 +22,15 @@ add_definitions(${Qt5Widgets_DEFINITIONS})
 
 include(platform/platform.cmake)
 
+# Compile with tests?
+if (WITH_TESTS)
+    file(GLOB copyq_SOURCES ${copyq_SOURCES} tests/*.cpp)
+endif()
+
+set_source_files_properties(
+    ${copyq_SOURCES} PROPERTIES
+    COMPILE_OPTIONS "${copyq_pedantic_flags}")
+
 # Qxt - global shortcuts
 if (USE_QXT)
     set(copyq_SOURCES ${copyq_SOURCES}
@@ -30,11 +39,6 @@ if (USE_QXT)
     add_definitions( -DQXT_STATIC )
 endif()
 
-# Compile with tests?
-if (WITH_TESTS)
-    file(GLOB copyq_SOURCES ${copyq_SOURCES} tests/*.cpp)
-endif()
-
 # translations
 file(GLOB copyq_TRANSLATIONS ../translations/*.ts)
 
diff --git a/src/app/clipboardserver.cpp b/src/app/clipboardserver.cpp
index 3f76cde1eaefdc14b00a3ae1b2f1271bb399442f..c3a3b95b86f5a02fe185da9760694302ba0fdc5b 100644
--- a/src/app/clipboardserver.cpp
+++ b/src/app/clipboardserver.cpp
@@ -591,8 +591,8 @@ void ClipboardServer::onNotificationButtonClicked(const NotificationButton &butt
 void ClipboardServer::createGlobalShortcut(const QKeySequence &shortcut, const Command &command)
 {
 #ifdef NO_GLOBAL_SHORTCUTS
-    Q_UNUSED(shortcut);
-    Q_UNUSED(command);
+    Q_UNUSED(shortcut)
+    Q_UNUSED(command)
 #else
     auto s = new QxtGlobalShortcut(shortcut, this);
     if (!s->isValid()) {
@@ -721,7 +721,7 @@ void ClipboardServer::loadSettings()
 void ClipboardServer::shortcutActivated(QxtGlobalShortcut *shortcut)
 {
 #ifdef NO_GLOBAL_SHORTCUTS
-    Q_UNUSED(shortcut);
+    Q_UNUSED(shortcut)
 #else
     m_ignoreKeysTimer.start();
 
diff --git a/src/common/actionhandlerenums.h b/src/common/actionhandlerenums.h
index b8d0e0ae86c0627637d725f16b2fbbd641232436..ca09ccd1d3ec3d3d940cc7b98d90fff422dbcb65 100644
--- a/src/common/actionhandlerenums.h
+++ b/src/common/actionhandlerenums.h
@@ -1,6 +1,8 @@
 #ifndef ACTIONHANDLERENUMS_H
 #define ACTIONHANDLERENUMS_H
 
+#include <QtGlobal>
+
 enum class ActionState {
     Starting,
     Running,
@@ -22,7 +24,7 @@ enum {
 
 namespace ActionHandlerRole {
 enum {
-    sort,
+    sort = Qt::UserRole,
     status,
     id
 };
diff --git a/src/common/actiontablemodel.cpp b/src/common/actiontablemodel.cpp
index f27e4f47afe139557f969fa45a76a9202994c701..5d462c2f1e32e866be8d3e1e2a9c88d83bf23120 100644
--- a/src/common/actiontablemodel.cpp
+++ b/src/common/actiontablemodel.cpp
@@ -206,7 +206,6 @@ QVariant ActionTableModel::data(const QModelIndex &index, int role) const
                 }
             }
     } else if (role >= Qt::UserRole) {
-        role -= Qt::UserRole;
         if (role == ActionHandlerRole::sort) {
             const int row = index.row();
             const int column = index.column();
diff --git a/src/common/config.cpp b/src/common/config.cpp
index a841332b8827b9668e133df31fc2f3b65b17acd2..0f7a287e8d8d86f877d4bfe1fffdaae52af1cf76 100644
--- a/src/common/config.cpp
+++ b/src/common/config.cpp
@@ -272,7 +272,7 @@ void moveToCurrentWorkspace(QWidget *w)
         w->show();
     }
 #else
-    Q_UNUSED(w);
+    Q_UNUSED(w)
 #endif
 }
 
diff --git a/src/gui/actiondialog.cpp b/src/gui/actiondialog.cpp
index 02a77362be5d9015667ec96dbc6bc900e9976b99..65ca834d4eb0c63723c5dec33e8d4c22b75c73cc 100644
--- a/src/gui/actiondialog.cpp
+++ b/src/gui/actiondialog.cpp
@@ -73,9 +73,9 @@ ActionDialog::ActionDialog(QWidget *parent)
     ui->setupUi(this);
     ui->comboBoxCommands->setFont( ui->commandEdit->commandFont() );
 
-    auto shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_P), this);
+    auto shortcut = new QShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_P), this);
     connect(shortcut, &QShortcut::activated, this, &ActionDialog::previousCommand);
-    shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_N), this);
+    shortcut = new QShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_N), this);
     connect(shortcut, &QShortcut::activated, this, &ActionDialog::nextCommand);
 
     connect(ui->buttonBox, &QDialogButtonBox::clicked,
diff --git a/src/gui/actionhandlerdialog.cpp b/src/gui/actionhandlerdialog.cpp
index 98051e1154e29581259b35c2263fb3a84a453a6a..8bac9c04a9dddad77f785b4cc96eea234b91fc5c 100644
--- a/src/gui/actionhandlerdialog.cpp
+++ b/src/gui/actionhandlerdialog.cpp
@@ -32,7 +32,7 @@ void terminateSelectedActions(QItemSelectionModel *selectionModel, ActionHandler
 {
      QSet<int> ids;
      for ( const auto &index : selectionModel->selectedIndexes() ) {
-         const int actionId = index.data(Qt::UserRole + ActionHandlerRole::id).toInt();
+         const int actionId = index.data(ActionHandlerRole::id).toInt();
          ids.insert(actionId);
      }
      for (const int id : ids)
@@ -44,7 +44,7 @@ void updateTerminateButton(QItemSelectionModel *selectionModel, QAbstractItemMod
      for ( const auto &index : selectionModel->selectedIndexes() ) {
          const int row = index.row();
          const auto statusIndex = model->index(row, 0);
-         const auto state = static_cast<ActionState>(statusIndex.data(Qt::UserRole + ActionHandlerRole::status).toInt());
+         const auto state = static_cast<ActionState>(statusIndex.data(ActionHandlerRole::status).toInt());
          if (state == ActionState::Running || state == ActionState::Starting) {
              button->setEnabled(true);
              return;
@@ -65,7 +65,7 @@ ActionHandlerDialog::ActionHandlerDialog(ActionHandler *actionHandler, QAbstract
     auto proxyModel = new QSortFilterProxyModel(this);
     proxyModel->setSourceModel(model);
     proxyModel->setDynamicSortFilter(true);
-    proxyModel->setSortRole(Qt::UserRole + ActionHandlerRole::sort);
+    proxyModel->setSortRole(ActionHandlerRole::sort);
     proxyModel->setFilterKeyColumn(ActionHandlerColumn::name);
     ui->tableView->setModel(proxyModel);
 
diff --git a/src/gui/clipboardbrowser.cpp b/src/gui/clipboardbrowser.cpp
index cb924011eebf9b03928fa519730de9635ec2e25a..94947580d0fcef522cffbbc398e35f5078e9d343 100644
--- a/src/gui/clipboardbrowser.cpp
+++ b/src/gui/clipboardbrowser.cpp
@@ -715,10 +715,10 @@ void ClipboardBrowser::dragDropScroll()
 
     const auto y = mapFromGlobal(QCursor::pos()).y();
     const auto h = viewport()->contentsRect().height();
-    const auto d = h / 4;
+    const auto diff = h / 4;
     const auto scrollAmount =
-            (h < y + d) ? (y + d - h) / 4
-          : (y < d) ? -(d - y) / 4
+            (h < y + diff) ? (y + diff - h) / 4
+          : (y < diff) ? -(diff - y) / 4
           : 0;
 
     if (scrollAmount != 0) {
@@ -824,7 +824,7 @@ QPixmap ClipboardBrowser::renderItemPreview(const QModelIndexList &indexes, int
         return QPixmap();
 
     const auto ratio = pixelRatio(this);
-    const int frameLineWidth = std::ceil(2 * ratio);
+    const int frameLineWidth = static_cast<int>( std::ceil(2 * ratio) );
 
     const auto height = qMin(maxHeight, h + s + 2 * frameLineWidth);
     const auto width = qMin(maxWidth, viewport()->contentsRect().width() + 2 * frameLineWidth);
diff --git a/src/gui/icon_list.h b/src/gui/icon_list.h
index 3c0035327413f51753106c60783b0fe200c50746..c709c2d5472cf0586ca4a08980cf427ddc6d3ba5 100644
--- a/src/gui/icon_list.h
+++ b/src/gui/icon_list.h
@@ -1,7 +1,7 @@
 // This file is generated with "update_icon_font.py" from FontAwesome's metadata.
 
 struct Icon {
-    unsigned int unicode;
+    unsigned short unicode;
     bool isBrand;
     const char *searchTerms;
 };
diff --git a/src/gui/iconfactory.cpp b/src/gui/iconfactory.cpp
index ed21585489223a66702bde2a27aca1494c8cd013..836a78937508855f96dec6e5ddcd0391070ed00b 100644
--- a/src/gui/iconfactory.cpp
+++ b/src/gui/iconfactory.cpp
@@ -56,7 +56,10 @@ const int lightThreshold = 100;
 
 bool sessionIconTagEnabledFlag = true;
 
-QPointer<QObject> activePaintDevice;
+QPointer<QObject> &activePaintDevice() {
+    static QPointer<QObject> activePaintDevice;
+    return activePaintDevice;
+}
 
 QIcon fromTheme(const QString &name)
 {
@@ -355,7 +358,7 @@ QColor colorForMode(QPainter *painter, QIcon::Mode mode)
 {
     auto parent = painter
             ? dynamic_cast<QWidget*>(painter->device())
-            : qobject_cast<QWidget*>(activePaintDevice.data());
+            : qobject_cast<QWidget*>(activePaintDevice().data());
 
     const bool selected = (mode == QIcon::Active || mode == QIcon::Selected);
     QColor color = parent ? getDefaultIconColor(*parent, selected) : Qt::darkGray;
@@ -661,7 +664,7 @@ QIcon appIcon()
 
 void setActivePaintDevice(QObject *device)
 {
-    activePaintDevice = device;
+    activePaintDevice() = device;
 }
 
 QColor getDefaultIconColor(const QWidget &widget, bool selected)
diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp
index 914e2f8f695083f47832e5bf37623ad8b974398d..7d7de288f2f69991ec134792bac76d0b41490a8e 100644
--- a/src/gui/mainwindow.cpp
+++ b/src/gui/mainwindow.cpp
@@ -760,10 +760,10 @@ void MainWindow::createMenu()
     // Open Item Menu
     createAction( Actions::ItemMenu, &MainWindow::showContextMenu, nullptr );
 
-    for (auto menu : menuBar()->findChildren<QMenu*>()) {
-        connect( menu, &QMenu::aboutToShow,
+    for (auto subMenu : menuBar()->findChildren<QMenu*>()) {
+        connect( subMenu, &QMenu::aboutToShow,
                  this, &MainWindow::disableHideWindowOnUnfocus );
-        connect( menu, &QMenu::aboutToHide,
+        connect( subMenu, &QMenu::aboutToHide,
                  this, &MainWindow::enableHideWindowOnUnfocus );
     }
 }
diff --git a/src/gui/menuitems.cpp b/src/gui/menuitems.cpp
index 16dfdfd2bf622f102e95048be64016947c357c53..c90437f1090324cdd3070e1dbfe8932215d616c7 100644
--- a/src/gui/menuitems.cpp
+++ b/src/gui/menuitems.cpp
@@ -32,7 +32,7 @@ void addMenuItem(
         const QKeySequence &shortcut, const QString &iconName, ushort iconId = 0)
 {
     Q_ASSERT(items.size() == id && "Menu item index must be same as its ID.");
-    Q_UNUSED(id);
+    Q_UNUSED(id)
 
     MenuItem item;
     item.text = text;
diff --git a/src/gui/notification.cpp b/src/gui/notification.cpp
index 0eb2d5a628e5909700994007d45b2422056a2210..7aaf2d74b2c521e6bd49453d816e040c33cc9d00 100644
--- a/src/gui/notification.cpp
+++ b/src/gui/notification.cpp
@@ -189,7 +189,7 @@ void Notification::updateIcon()
 
     auto pixmap = iconId == 0
             ? QPixmap(m_icon)
-            : createPixmap(iconId, color, height * ratio);
+            : createPixmap(iconId, color, static_cast<int>(height * ratio));
 
     pixmap.setDevicePixelRatio(ratio);
 
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 4fc3e715ff020ac92c404531e51c280a3ccc68bb..dd72ebfd48a9226fe43424a63e44c7f08e2ec9c5 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -42,17 +42,19 @@ double normalizeFactor(double value)
     return qBound( 0.0, value, 1.0 );
 }
 
-int normalizeColorValue(float value)
+int normalizeColorValue(int value)
 {
-    return qBound( 0, static_cast<int>(value), 255 );
+    return qBound(0, value, 255);
 }
 
 /// Add RGB components properly.
 int addColor(int c1, float multiply, int c2)
 {
+    const float f1 = static_cast<float>(c1);
+    const float f2 = static_cast<float>(c2);
     return multiply > 0.0f
-            ? static_cast<int>( std::sqrt(c1*c1 + multiply * c2*c2) )
-            : c1 + static_cast<int>(multiply * c2);
+            ? static_cast<int>( std::sqrt(f1*f1 + multiply * f2*f2) )
+            : c1 + static_cast<int>(multiply * f2);
 }
 
 void addColor(
@@ -84,8 +86,11 @@ void addColor(
     *r = normalizeColorValue( addColor(*r, x, toAdd.red()) );
     *g = normalizeColorValue( addColor(*g, x, toAdd.green()) );
     *b = normalizeColorValue( addColor(*b, x, toAdd.blue()) );
-    if (multiply > 0.0f)
-        *a = normalizeColorValue(*a + x * toAdd.alpha());
+    if (multiply > 0.0f) {
+        const float fa = static_cast<float>(*a);
+        const float fad = static_cast<float>(toAdd.alpha());
+        *a = normalizeColorValue( static_cast<int>(fa + x * fad) );
+    }
 }
 
 int fitFontWeight(int weight, int low, int high, int highCss)
diff --git a/src/platform/win/winplatform.cpp b/src/platform/win/winplatform.cpp
index c29e173f12cab454548358e4b2e68bbf0e123eb1..f2cddcf13a6769628bd75994e821673609ef3704 100644
--- a/src/platform/win/winplatform.cpp
+++ b/src/platform/win/winplatform.cpp
@@ -191,7 +191,7 @@ QApplication *createGuiApplication(int &argc, char **argv)
     //             WM_QUERYENDSESSION (from installer) and similar events.
     auto w = new QWidget();
     auto winId = w->winId();
-    Q_UNUSED(winId);
+    Q_UNUSED(winId)
 
     return app;
 }
diff --git a/src/platform/x11/systemclipboard/waylandclipboard.cpp b/src/platform/x11/systemclipboard/waylandclipboard.cpp
index 123fc2e38b6d585c585dc0020d6fdcd93fe4ee34..3d942db9a91346e8a475259154a93412ec388d43 100644
--- a/src/platform/x11/systemclipboard/waylandclipboard.cpp
+++ b/src/platform/x11/systemclipboard/waylandclipboard.cpp
@@ -90,7 +90,7 @@ QVariant DataControlOffer::retrieveData(const QString &mimeType, QVariant::Type
     if (!hasFormat(mimeType)) {
         return QVariant();
     }
-    Q_UNUSED(type);
+    Q_UNUSED(type)
 
     int pipeFds[2];
     if (pipe(pipeFds) != 0){
diff --git a/src/platform/x11/x11platform.cpp b/src/platform/x11/x11platform.cpp
index dbe7e406c924f64d2bbacba16ceb5fba82a51745..5f80889b5829b8b63e966393d428462fd8c37cca 100644
--- a/src/platform/x11/x11platform.cpp
+++ b/src/platform/x11/x11platform.cpp
@@ -232,7 +232,7 @@ void X11Platform::setAutostartEnabled(bool enable)
 
     maybePrintFileError(desktopFile2, "Failed to write desktop file");
 #else
-    Q_UNUSED(enable);
+    Q_UNUSED(enable)
 #endif
 }
 
diff --git a/src/scriptable/scriptable.cpp b/src/scriptable/scriptable.cpp
index c2aeae62dfda833f36bcd55be1959aba9a875d91..7c7d551733861bfe9e399cb62db5534598edcf94 100644
--- a/src/scriptable/scriptable.cpp
+++ b/src/scriptable/scriptable.cpp
@@ -2107,8 +2107,8 @@ QJSValue Scriptable::dialog()
 
 QJSValue Scriptable::menuItems()
 {
-    const auto arg = argument(0);
-    if ( arg.isString() ) {
+    const auto text = argument(0);
+    if ( text.isString() ) {
         m_skipArguments = -1;
         QVector<QVariantMap> items;
         for (const auto &arg : arguments())
@@ -2120,7 +2120,7 @@ QJSValue Scriptable::menuItems()
     }
 
     m_skipArguments = 1;
-    const auto items = fromScriptValue<QVector<QVariantMap>>( arg, this );
+    const auto items = fromScriptValue<QVector<QVariantMap>>(text, this);
     if ( items.isEmpty() )
         return -1;
     return m_proxy->menuItems(items);
@@ -2752,8 +2752,8 @@ void Scriptable::onSynchronizeSelection(ClipboardMode sourceMode, const QString
         : "copyq --clipboard-access synchronizeFromSelection";
     m_proxy->runInternalAction(data, command);
 #else
-    Q_UNUSED(text);
-    Q_UNUSED(sourceMode);
+    Q_UNUSED(text)
+    Q_UNUSED(sourceMode)
 #endif
 }
 
@@ -3410,7 +3410,7 @@ void Scriptable::synchronizeSelection(ClipboardMode targetMode)
 #ifdef HAS_MOUSE_SELECTIONS
 #   define COPYQ_SYNC_LOG(MESSAGE) \
         COPYQ_LOG( QString("Synchronizing to %1: " MESSAGE) \
-                   .arg(targetMode == ClipboardMode::Clipboard ? "clipboard" : "selection") );
+                   .arg(targetMode == ClipboardMode::Clipboard ? "clipboard" : "selection") )
 
     if (!verifyClipboardAccess())
         return;
@@ -3470,7 +3470,7 @@ void Scriptable::synchronizeSelection(ClipboardMode targetMode)
         provideSelection();
 #   undef COPYQ_SYNC_LOG
 #else
-    Q_UNUSED(targetMode);
+    Q_UNUSED(targetMode)
 #endif
 }
 
diff --git a/src/scriptable/scriptableproxy.cpp b/src/scriptable/scriptableproxy.cpp
index ddcccf81526fd75c688fe2da4db560cf1700075c..4ceec39763790fd93c262b77fa30b4254583542e 100644
--- a/src/scriptable/scriptableproxy.cpp
+++ b/src/scriptable/scriptableproxy.cpp
@@ -121,27 +121,30 @@ void registerMetaTypes() {
 
 #define STR(str) str
 
-#define INVOKE_(function, arguments, functionCallId) \
+#define INVOKE_(function, arguments, functionCallId) do { \
     static const auto f = FunctionCallSerializer(STR(#function)).withSlotArguments arguments; \
     const auto args = f.argumentList arguments; \
-    emit sendMessage(f.serialize(functionCallId, args), CommandFunctionCall)
+    emit sendMessage(f.serialize(functionCallId, args), CommandFunctionCall); \
+} while(false)
 
-#define INVOKE(FUNCTION, ARGUMENTS) \
+#define INVOKE(FUNCTION, ARGUMENTS) do { \
     if (!m_wnd) { \
         using Result = decltype(FUNCTION ARGUMENTS); \
         const auto functionCallId = ++m_lastFunctionCallId; \
         INVOKE_(FUNCTION, ARGUMENTS, functionCallId); \
         const auto result = waitForFunctionCallFinished(functionCallId); \
         return result.value<Result>(); \
-    }
+    } \
+} while(false)
 
-#define INVOKE2(FUNCTION, ARGUMENTS) \
+#define INVOKE2(FUNCTION, ARGUMENTS) do { \
     if (!m_wnd) { \
         const auto functionCallId = ++m_lastFunctionCallId; \
         INVOKE_(FUNCTION, ARGUMENTS, functionCallId); \
         waitForFunctionCallFinished(functionCallId); \
         return; \
-    }
+    } \
+} while(false)
 
 Q_DECLARE_METATYPE(QFile*)
 
@@ -1340,7 +1343,7 @@ void ScriptableProxy::browserMoveSelected(int targetRow)
         return;
 
     QModelIndexList indexes;
-    for (const auto index : selected)
+    for (const auto &index : selected)
         indexes.append(index);
     c->move(indexes, targetRow);
 }
@@ -1794,8 +1797,8 @@ int ScriptableProxy::inputDialog(const NamedValueList &values)
     QObject::connect( buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject );
     layout.addWidget(buttons);
 
-    installShortcutToCloseDialog(&dialog, &dialog, Qt::CTRL | Qt::Key_Enter);
-    installShortcutToCloseDialog(&dialog, &dialog, Qt::CTRL | Qt::Key_Return);
+    installShortcutToCloseDialog(&dialog, &dialog, Qt::ControlModifier | Qt::Key_Enter);
+    installShortcutToCloseDialog(&dialog, &dialog, Qt::ControlModifier | Qt::Key_Return);
 
     if (icon.isNull())
         icon = appIcon();
diff --git a/src/tests/test_utils.h b/src/tests/test_utils.h
index 728fdef60cb0ae848e4cd15baac26a2e3af7ee14..b4c51efc3aba626f06161aa166476fdd9964d5d0 100644
--- a/src/tests/test_utils.h
+++ b/src/tests/test_utils.h
@@ -35,19 +35,19 @@
  * didn't fail or print error.
  */
 #define TEST(ERRORS_OR_EMPTY) \
-    QVERIFY2( NO_ERRORS(ERRORS_OR_EMPTY), "Failed with errors above." );
+    QVERIFY2( NO_ERRORS(ERRORS_OR_EMPTY), "Failed with errors above." )
 
 #define RUN(ARGUMENTS, STDOUT_EXPECTED) \
-    TEST( m_test->runClient((Args() << ARGUMENTS), toByteArray(STDOUT_EXPECTED)) );
+    TEST( m_test->runClient((Args() << ARGUMENTS), toByteArray(STDOUT_EXPECTED)) )
 
 #define RUN_WITH_INPUT(ARGUMENTS, INPUT, STDOUT_EXPECTED) \
-    TEST( m_test->runClient((Args() << ARGUMENTS), toByteArray(STDOUT_EXPECTED), toByteArray(INPUT)) );
+    TEST( m_test->runClient((Args() << ARGUMENTS), toByteArray(STDOUT_EXPECTED), toByteArray(INPUT)) )
 
 #define RUN_EXPECT_ERROR(ARGUMENTS, EXIT_CODE) \
-    TEST( m_test->runClientWithError((Args() << ARGUMENTS), (EXIT_CODE)) );
+    TEST( m_test->runClientWithError((Args() << ARGUMENTS), (EXIT_CODE)) )
 
 #define RUN_EXPECT_ERROR_WITH_STDERR(ARGUMENTS, EXIT_CODE, STDERR_CONTAINS) \
-    TEST( m_test->runClientWithError((Args() << ARGUMENTS), (EXIT_CODE), toByteArray(STDERR_CONTAINS)) );
+    TEST( m_test->runClientWithError((Args() << ARGUMENTS), (EXIT_CODE), toByteArray(STDERR_CONTAINS)) )
 
 #define WAIT_FOR_CLIPBOARD(DATA) \
     TEST( m_test->verifyClipboard(DATA, "text/plain") )
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp
index 3b03c80e4c7b1f241becaafdce3268e548077f85..035764fd839fbc59e18932126c4d1fe127c1ff58 100644
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -877,7 +877,7 @@ void Tests::badSessionName()
 
 void Tests::commandExit()
 {
-    RUN("exit", "Terminating server.\n")
+    RUN("exit", "Terminating server.\n");
 
     TEST( m_test->waitForServerToStop() );
 
@@ -983,8 +983,8 @@ void Tests::commandSource()
     scriptFile.close();
     const auto scriptFileName = scriptFile.fileName();
 
-    RUN("source" << scriptFileName, "SOURCED")
-    RUN("source" << scriptFileName << "test()", "SOURCED TEST\n")
+    RUN("source" << scriptFileName, "SOURCED");
+    RUN("source" << scriptFileName << "test()", "SOURCED TEST\n");
 }
 
 void Tests::commandVisible()
@@ -1608,7 +1608,7 @@ void Tests::commandsImportExportCommandsFixIndentation()
 
 void Tests::commandScreenshot()
 {
-    RUN("screenshot().size() > 0", "true\n")
+    RUN("screenshot().size() > 0", "true\n");
 }
 
 void Tests::commandNotification()
@@ -2272,7 +2272,7 @@ void Tests::copyPasteCommands()
     WAIT_FOR_CLIPBOARD(commands);
 
     RUN("keys" << commandDialogListId << "Enter" << clipboardBrowserId, "");
-    RUN("commands().length", "2\n")
+    RUN("commands().length", "2\n");
 }
 
 void Tests::editItems()
@@ -2715,14 +2715,14 @@ void Tests::itemPreview()
     RUN("keys" << clipboardBrowserId << "F7", "");
     RUN("preview", "true\n");
 
-    RUN("keys" << clipboardBrowserId << "TAB" << itemPreviewId, "")
-    RUN("keys" << itemPreviewId << "HOME", "")
-    RUN("keys" << itemPreviewId << "RIGHT", "")
-    RUN("keys" << itemPreviewId << "SHIFT+RIGHT", "")
-    RUN("keys" << itemPreviewId << keyNameFor(QKeySequence::Copy), "")
+    RUN("keys" << clipboardBrowserId << "TAB" << itemPreviewId, "");
+    RUN("keys" << itemPreviewId << "HOME", "");
+    RUN("keys" << itemPreviewId << "RIGHT", "");
+    RUN("keys" << itemPreviewId << "SHIFT+RIGHT", "");
+    RUN("keys" << itemPreviewId << keyNameFor(QKeySequence::Copy), "");
     WAIT_FOR_CLIPBOARD("b");
 
-    RUN("keys" << itemPreviewId << "F7" << clipboardBrowserId, "")
+    RUN("keys" << itemPreviewId << "F7" << clipboardBrowserId, "");
 
     RUN("preview" << "true", "false\n");
     RUN("preview" << "false", "true\n");
@@ -3527,7 +3527,7 @@ void Tests::showHideClipboardDialog()
 
 void Tests::showHideItemDialog()
 {
-    RUN("write" << "test-format" << "TEST", "")
+    RUN("write" << "test-format" << "TEST", "");
     RUN("selectItems" << "0", "true\n");
 
     RUN("keys" << clipboardBrowserId << "F4" << clipboardDialogId, "");
@@ -3573,7 +3573,7 @@ void Tests::shortcutDialogAddShortcut()
 #endif
 
     RUN("setCommands([{name: 'test', inMenu: true, cmd: 'copyq add OK'}])", "");
-    RUN("commands()[0].shortcuts", "")
+    RUN("commands()[0].shortcuts", "");
 
     RUN("keys" << clipboardBrowserId << "F6" << commandDialogId, "");
     RUN("keys" << commandDialogId << "ALT+S" << shortcutButtonId, "");
@@ -3582,7 +3582,7 @@ void Tests::shortcutDialogAddShortcut()
 
     RUN("keys" << commandDialogId << "ESCAPE" << commandDialogSaveButtonId, "");
     RUN("keys" << commandDialogSaveButtonId << "Enter" << clipboardBrowserId, "");
-    RUN("commands()[0].shortcuts", "ctrl+f1\n")
+    RUN("commands()[0].shortcuts", "ctrl+f1\n");
 }
 
 void Tests::shortcutDialogAddTwoShortcuts()
@@ -3592,7 +3592,7 @@ void Tests::shortcutDialogAddTwoShortcuts()
 #endif
 
     RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['ctrl+f1'], cmd: 'copyq add OK'}])", "");
-    RUN("commands()[0].shortcuts", "ctrl+f1\n")
+    RUN("commands()[0].shortcuts", "ctrl+f1\n");
 
     RUN("keys" << clipboardBrowserId << "F6" << commandDialogId, "");
     RUN("keys" << commandDialogId << "ALT+S" << shortcutButtonId, "");
@@ -3606,7 +3606,7 @@ void Tests::shortcutDialogAddTwoShortcuts()
 
     RUN("keys" << commandDialogId << "ESCAPE" << commandDialogSaveButtonId, "");
     RUN("keys" << commandDialogSaveButtonId << "Enter" << clipboardBrowserId, "");
-    RUN("commands()[0].shortcuts", "ctrl+f1\nf1\nf2\n")
+    RUN("commands()[0].shortcuts", "ctrl+f1\nf1\nf2\n");
 }
 
 void Tests::shortcutDialogChangeShortcut()
@@ -3616,7 +3616,7 @@ void Tests::shortcutDialogChangeShortcut()
 #endif
 
     RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['f1','f2','f3'], cmd: 'copyq add OK'}])", "");
-    RUN("commands()[0].shortcuts", "f1\nf2\nf3\n")
+    RUN("commands()[0].shortcuts", "f1\nf2\nf3\n");
 
     RUN("keys" << clipboardBrowserId << "F6" << commandDialogId, "");
     RUN("keys" << commandDialogId << "ALT+S" << shortcutButtonId, "");
@@ -3626,7 +3626,7 @@ void Tests::shortcutDialogChangeShortcut()
 
     RUN("keys" << commandDialogId << "ESCAPE" << commandDialogSaveButtonId, "");
     RUN("keys" << commandDialogSaveButtonId << "Enter" << clipboardBrowserId, "");
-    RUN("commands()[0].shortcuts", "f1\nf4\nf3\n")
+    RUN("commands()[0].shortcuts", "f1\nf4\nf3\n");
 }
 
 void Tests::shortcutDialogSameShortcut()
@@ -3636,7 +3636,7 @@ void Tests::shortcutDialogSameShortcut()
 #endif
 
     RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['ctrl+f1'], cmd: 'copyq add OK'}])", "");
-    RUN("commands()[0].shortcuts", "ctrl+f1\n")
+    RUN("commands()[0].shortcuts", "ctrl+f1\n");
 
     RUN("keys" << clipboardBrowserId << "F6" << commandDialogId, "");
     RUN("keys" << commandDialogId << "ALT+S" << shortcutButtonId, "");
@@ -3645,7 +3645,7 @@ void Tests::shortcutDialogSameShortcut()
     RUN("keys" << shortcutDialogId << "CTRL+F1" << shortcutButtonId, "");
 
     RUN("keys" << commandDialogId << "ESCAPE" << clipboardBrowserId, "");
-    RUN("commands()[0].shortcuts", "ctrl+f1\n")
+    RUN("commands()[0].shortcuts", "ctrl+f1\n");
 }
 
 void Tests::shortcutDialogCancel()
@@ -3655,7 +3655,7 @@ void Tests::shortcutDialogCancel()
 #endif
 
     RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['ctrl+f1'], cmd: 'copyq add OK'}])", "");
-    RUN("commands()[0].shortcuts", "ctrl+f1\n")
+    RUN("commands()[0].shortcuts", "ctrl+f1\n");
 
     RUN("keys" << clipboardBrowserId << "F6" << commandDialogId, "");
     RUN("keys" << commandDialogId << "ALT+S" << shortcutButtonId, "");
@@ -3664,7 +3664,7 @@ void Tests::shortcutDialogCancel()
     RUN("keys" << shortcutDialogId << "ESCAPE" << shortcutButtonId, "");
 
     RUN("keys" << commandDialogId << "ESCAPE" << clipboardBrowserId, "");
-    RUN("commands()[0].shortcuts", "ctrl+f1\n")
+    RUN("commands()[0].shortcuts", "ctrl+f1\n");
 }
 
 void Tests::actionDialogCancel()
@@ -3777,7 +3777,7 @@ void Tests::exitConfirm()
 
 void Tests::exitNoConfirm()
 {
-    RUN("config" << "confirm_exit" << "false", "false\n")
+    RUN("config" << "confirm_exit" << "false", "false\n");
     RUN("keys" << clipboardBrowserId << "CTRL+Q", "");
     TEST( m_test->waitForServerToStop() );
 }
@@ -3871,7 +3871,7 @@ int runTests(int argc, char *argv[])
 
     const auto platform = platformNativeInterface();
     std::unique_ptr<QGuiApplication> app( platform->createTestApplication(argc, argv) );
-    Q_UNUSED(app);
+    Q_UNUSED(app)
 
     const QString session = "copyq.test";
     QCoreApplication::setOrganizationName(session);
diff --git a/utils/update_icon_font.py b/utils/update_icon_font.py
index 98be9096f53378d370b5a565a26e9bc5ab5d25f7..a6ac57936012eace287a7d67fb99b34844f31bbe 100755
--- a/utils/update_icon_font.py
+++ b/utils/update_icon_font.py
@@ -54,7 +54,7 @@ def write_icon_list_header_file(header_icon_list, icons):
         item_list_content = ',\n'.join(items)
         content = dedent('''\
             struct Icon {
-                unsigned int unicode;
+                unsigned short unicode;
                 bool isBrand;
                 const char *searchTerms;
             };