Skip to content

Commit

Permalink
Support for Qt 6
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Sep 22, 2021
1 parent eefcb19 commit 23dd6f7
Show file tree
Hide file tree
Showing 78 changed files with 612 additions and 389 deletions.
36 changes: 32 additions & 4 deletions CMakeLists.txt
Expand Up @@ -45,8 +45,35 @@ endif()

set(CMAKE_AUTOMOC ON)

find_package(Qt5Widgets 5.8.0 REQUIRED)
list(APPEND copyq_LIBRARIES Qt5::Widgets)
OPTION(WITH_QT6 "Enable Qt 6" OFF)
if (WITH_QT6)
set(QT_DEFAULT_MAJOR_VERSION 6)
find_package(Qt6Widgets 6.1.0 REQUIRED)
set(copyq_qt Qt6)
find_package(Qt6Core5Compat REQUIRED)
list(APPEND copyq_LIBRARIES Qt::Core5Compat)
add_definitions( -DQT_DEPRECATED_WARNINGS_SINCE=0x051500 )
else()
set(QT_DEFAULT_MAJOR_VERSION 5)
find_package(Qt5Widgets 5.8.0 REQUIRED)
set(copyq_qt Qt5)
if (Qt5Widgets_VERSION VERSION_LESS 5.15.0)
function(qt_wrap_ui outfiles)
qt5_wrap_ui("${outfiles}" ${ARGN})
set("${outfiles}" "${${outfiles}}" PARENT_SCOPE)
endfunction()
function(qt_add_resources outfiles)
qt5_add_resources("${outfiles}" ${ARGN})
set("${outfiles}" "${${outfiles}}" PARENT_SCOPE)
endfunction()
function(qt_add_translation _qm_files)
qt5_add_translation("${_qm_files}" ${ARGN})
set("${_qm_files}" "${${_qm_files}}" PARENT_SCOPE)
endfunction()
endif()
endif()

list(APPEND copyq_LIBRARIES ${copyq_qt}::Widgets)

set(copyq_APP_ID com.github.hluk.copyq)
set(copyq_ICON_PREFIX src/images/icon)
Expand Down Expand Up @@ -83,6 +110,7 @@ if (PEDANTIC)
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-disabled-macro-expansion
-Wno-double-promotion
-Wno-exit-time-destructors
-Wno-extra-semi-stmt
-Wno-redundant-parens
Expand Down Expand Up @@ -130,8 +158,8 @@ if(WITH_TESTS)

add_definitions( -DHAS_TESTS )

find_package(Qt5Test REQUIRED)
list(APPEND copyq_LIBRARIES Qt5::Test)
find_package(${copyq_qt}Test REQUIRED)
list(APPEND copyq_LIBRARIES ${copyq_qt}::Test)
endif()

include(version.cmake)
Expand Down
2 changes: 0 additions & 2 deletions README.md
Expand Up @@ -240,7 +240,6 @@ sudo apt install \
libqt5svg5 \
libqt5svg5-dev \
libqt5waylandclient5-dev \
libqt5x11extras5-dev \
libwayland-dev \
libxfixes-dev \
libxtst-dev \
Expand All @@ -266,7 +265,6 @@ sudo yum install \
qt5-qtsvg-devel \
qt5-qttools-devel \
qt5-qtwayland-devel \
qt5-qtx11extras-devel \
wayland-devel \
kf5-knotifications-devel
```
Expand Down
1 change: 0 additions & 1 deletion debian/control
Expand Up @@ -11,7 +11,6 @@ Build-Depends:
libxfixes-dev,
libxtst-dev,
libqt5waylandclient5-dev,
libqt5x11extras5-dev,
qtbase5-private-dev,
qtdeclarative5-dev,
qttools5-dev,
Expand Down
2 changes: 0 additions & 2 deletions docs/build-source-code.rst
Expand Up @@ -41,7 +41,6 @@ On **Ubuntu** you can install all build dependencies with:
libqt5svg5 \
libqt5svg5-dev \
libqt5waylandclient5-dev \
libqt5x11extras5-dev \
libwayland-dev \
libxfixes-dev \
libxtst-dev \
Expand Down Expand Up @@ -70,7 +69,6 @@ On **Fedora** and derivatives you can install all build dependencies with:
qt5-qtsvg-devel \
qt5-qttools-devel \
qt5-qtwayland-devel \
qt5-qtx11extras-devel \
wayland-devel

Build and Install
Expand Down
8 changes: 4 additions & 4 deletions plugins/CMakeLists.txt
Expand Up @@ -20,10 +20,10 @@ macro (copyq_add_plugin copyq_pkg)

include_directories(${CMAKE_CURRENT_BINARY_DIR} ../../src)

include_directories(${Qt5Widgets_INCLUDES})
add_definitions(${Qt5Widgets_DEFINITIONS})
qt5_wrap_ui(copyq_plugin_FORMS_HEADERS ${copyq_plugin_FORMS})
qt5_add_resources(copyq_plugin_RCC ${copyq_plugin_${copyq_pkg}_RESOURCES})
include_directories(${${copyq_qt}Widgets_INCLUDES})
add_definitions(${${copyq_qt}Widgets_DEFINITIONS})
qt_wrap_ui(copyq_plugin_FORMS_HEADERS ${copyq_plugin_FORMS})
qt_add_resources(copyq_plugin_RCC ${copyq_plugin_${copyq_pkg}_RESOURCES})

add_library(${copyq_pkg} MODULE
${copyq_plugin_SOURCES}
Expand Down
3 changes: 1 addition & 2 deletions plugins/itemnotes/itemnotes.cpp
Expand Up @@ -112,7 +112,6 @@ ItemNotes::ItemNotes(ItemWidget *childItem, const QString &text, const QByteArra
layout = new QVBoxLayout(this);

auto labelLayout = new QHBoxLayout;
labelLayout->setMargin(0);
labelLayout->setContentsMargins(notesIndent, 0, 0, 0);

if (m_icon)
Expand All @@ -137,7 +136,7 @@ ItemNotes::ItemNotes(ItemWidget *childItem, const QString &text, const QByteArra
m_toolTipText = text;
}

layout->setMargin(0);
layout->setContentsMargins({});
layout->setSpacing(0);
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/itempinned/itempinned.cpp
Expand Up @@ -88,7 +88,7 @@ void ItemPinned::paintEvent(QPaintEvent *paintEvent)
);

QPainter painter(this);
const int border = pointsToPixels(6);
const int border = pointsToPixels(6, this);
const QRect rect(width() - border, 0, width(), height());
painter.setOpacity(0.15);
painter.fillRect(rect, color);
Expand All @@ -100,7 +100,7 @@ void ItemPinned::updateSize(QSize maximumSize, int idealWidth)
{
setMinimumWidth(idealWidth);
setMaximumWidth(maximumSize.width());
const int border = pointsToPixels(12);
const int border = pointsToPixels(12, this);
const int childItemWidth = idealWidth - border;
const auto childItemMaximumSize = QSize(maximumSize.width() - border, maximumSize.height());
ItemWidgetWrapper::updateSize(childItemMaximumSize, childItemWidth);
Expand Down
4 changes: 2 additions & 2 deletions plugins/itemtags/itemtags.cpp
Expand Up @@ -364,14 +364,14 @@ ItemTags::ItemTags(ItemWidget *childItem, const Tags &tags)
, m_tagWidget(new QWidget(childItem->widget()->parentWidget()))
{
QBoxLayout *tagLayout = new QHBoxLayout(m_tagWidget);
tagLayout->setMargin(0);
tagLayout->setContentsMargins({});
addTagButtons(tagLayout, tags);

childItem->widget()->setObjectName("item_child");
childItem->widget()->setParent(this);

QBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setContentsMargins({});
layout->setSpacing(0);

layout->addWidget(m_tagWidget, 0);
Expand Down
5 changes: 1 addition & 4 deletions qxt/qxtglobalshortcut_mac.cpp
Expand Up @@ -71,19 +71,16 @@ quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifier
return native;
}

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
// This is only here to get it to compile on OSX
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
void * message, long * result)
void * message, NativeEventResult * result)
{
Q_UNUSED(result)
Q_UNUSED(message)
Q_UNUSED(eventType)

return false;
}
#endif


quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key, Qt::KeyboardModifiers)
{
Expand Down
18 changes: 7 additions & 11 deletions qxt/qxtglobalshortcut_p.h
Expand Up @@ -37,14 +37,16 @@
class QKeySequence;
class QxtGlobalShortcut;

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
#include <QAbstractNativeEventFilter>

#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
using NativeEventResult = qintptr;
#else
using NativeEventResult = long;
#endif

class QxtGlobalShortcutPrivate
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
: public QAbstractNativeEventFilter
#endif
{
public:
explicit QxtGlobalShortcutPrivate(QxtGlobalShortcut *q);
Expand All @@ -64,14 +66,8 @@ class QxtGlobalShortcutPrivate
static int ref;
# endif // Q_OS_MAC

# if QT_VERSION < QT_VERSION_CHECK(5,0,0)
# ifndef Q_OS_MAC
static QAbstractEventDispatcher::EventFilter prevEventFilter;
static bool eventFilter(void* message);
# endif // Q_OS_MAC
# else
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
# endif // QT_VERSION < QT_VERSION_CHECK(5,0,0)
bool nativeEventFilter(
const QByteArray &eventType, void *message, NativeEventResult *result) override;

static void activateShortcut(quint32 nativeKey, quint32 nativeMods);

Expand Down
7 changes: 1 addition & 6 deletions qxt/qxtglobalshortcut_win.cpp
Expand Up @@ -32,16 +32,11 @@
#include <qt_windows.h>


#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
bool QxtGlobalShortcutPrivate::eventFilter(void* message)
{
#else
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
void * message, long * result)
void * message, NativeEventResult * result)
{
Q_UNUSED(eventType)
Q_UNUSED(result)
#endif
MSG* msg = static_cast<MSG*>(message);
if (msg->message == WM_HOTKEY)
{
Expand Down
24 changes: 7 additions & 17 deletions qxt/qxtglobalshortcut_x11.cpp
Expand Up @@ -29,9 +29,10 @@
** <http://libqxt.org> <foundation@libqxt.org>
*****************************************************************************/

#include "platform/x11/x11info.h"

#include <QVector>
#include <QWidget>
#include <QX11Info>
#include <X11/keysym.h>
#include <X11/Xlib.h>

Expand Down Expand Up @@ -121,13 +122,13 @@ class QxtX11Data final {
: m_display(nullptr)
{
createFirstWindow();
if ( QX11Info::isPlatformX11() )
m_display = QX11Info::display();
if ( X11Info::isPlatformX11() )
m_display = X11Info::display();
}

bool isValid()
{
return QX11Info::isPlatformX11() && m_display != nullptr;
return X11Info::isPlatformX11() && m_display != nullptr;
}

Display *display()
Expand Down Expand Up @@ -214,18 +215,8 @@ KeySym qtKeyToXKeySym(Qt::Key key, Qt::KeyboardModifiers mods)

} // namespace

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
bool QxtGlobalShortcutPrivate::eventFilter(void* message)
{
XEvent *event = static_cast<XEvent *>(message);
if (event->type == KeyPress)
{
XKeyEvent* key = reinterpret_cast<XKeyEvent *>(event);
unsigned int keycode = key->keycode;
unsigned int keystate = key->state;
#else
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
void * message, long * result)
bool QxtGlobalShortcutPrivate::nativeEventFilter(
const QByteArray &eventType, void *message, NativeEventResult *result)
{
Q_UNUSED(result)

Expand All @@ -247,7 +238,6 @@ bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
keystate |= Mod4Mask;
if(kev->state & XCB_MOD_MASK_SHIFT)
keystate |= ShiftMask;
#endif
activateShortcut(keycode,
// Mod1Mask == Alt, Mod4Mask == Meta
keystate & (ShiftMask | ControlMask | Mod1Mask | Mod4Mask));
Expand Down
26 changes: 13 additions & 13 deletions src/CMakeLists.txt
Expand Up @@ -18,8 +18,8 @@ set(copyq_RESOURCES copyq.qrc)

# Qt include paths and definitions
include_directories(${CMAKE_CURRENT_BINARY_DIR} .)
include_directories(${Qt5Widgets_INCLUDES})
add_definitions(${Qt5Widgets_DEFINITIONS})
include_directories(${${copyq_qt}Widgets_INCLUDES})
add_definitions(${${copyq_qt}Widgets_DEFINITIONS})

include(notifications.cmake)
include(platform/platform.cmake)
Expand All @@ -44,13 +44,13 @@ endif()
# translations
file(GLOB copyq_TRANSLATIONS ../translations/*.ts)

find_package(Qt5LinguistTools)
if (Qt5LinguistTools_FOUND)
qt5_add_translation(copyq_QM ${copyq_TRANSLATIONS})
find_package(${copyq_qt}LinguistTools)
if (${copyq_qt}LinguistTools_FOUND)
qt_add_translation(copyq_QM ${copyq_TRANSLATIONS})
endif()

qt5_wrap_ui(copyq_FORMS_HEADERS ${copyq_FORMS})
qt5_add_resources(copyq_RESOURCES_RCC ${copyq_RESOURCES})
qt_wrap_ui(copyq_FORMS_HEADERS ${copyq_FORMS})
qt_add_resources(copyq_RESOURCES_RCC ${copyq_RESOURCES})

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})

Expand Down Expand Up @@ -109,8 +109,8 @@ add_dependencies(${COPYQ_EXECUTABLE_NAME} generate_version_header)
# Qt modules
list(APPEND copyq_qt_modules Network Svg Xml Qml)
foreach (copyq_qt_module ${copyq_qt_modules})
find_package(Qt5${copyq_qt_module} REQUIRED)
list(APPEND copyq_LIBRARIES Qt5::${copyq_qt_module})
find_package(${copyq_qt}${copyq_qt_module} REQUIRED)
list(APPEND copyq_LIBRARIES ${copyq_qt}::${copyq_qt_module})
endforeach()

# macros definitions for preprocessor and moc
Expand Down Expand Up @@ -145,7 +145,7 @@ else()
set(plugin_dest_dir "${COPYQ_EXECUTABLE_NAME}.app/Contents/PlugIns")
set(qtconf_dest_dir "${COPYQ_EXECUTABLE_NAME}.app/Contents/Resources")

macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var)
macro(install_qt_plugin _qt_plugin_name _qt_plugins_var)
get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
if(EXISTS "${_qt_plugin_path}")
get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
Expand All @@ -162,9 +162,9 @@ else()

# Install needed Qt plugins
foreach(_copyq_qt_module ${copyq_qt_modules} "Gui" "Widgets")
set(_module_plugins "${Qt5${_copyq_qt_module}_PLUGINS}")
set(_module_plugins "${${copyq_qt}${_copyq_qt_module}_PLUGINS}")
foreach(_plugin ${_module_plugins})
install_qt5_plugin("${_plugin}" FIXUP_BUNDLE_QT_PLUGINS)
install_qt_plugin("${_plugin}" FIXUP_BUNDLE_QT_PLUGINS)
endforeach()
endforeach()

Expand All @@ -181,7 +181,7 @@ else()
get_property(_copyq_installed_plugins GLOBAL PROPERTY COPYQ_INSTALLED_PLUGINS)

# Directories to look for dependencies
set(FIXUP_BUNDLE_DEP_DIRS "${CMAKE_BINARY_DIR};${QT_LIBRARY_DIRS};${Qt5Widgets_DIR}/../..")
set(FIXUP_BUNDLE_DEP_DIRS "${CMAKE_BINARY_DIR};${QT_LIBRARY_DIRS};${${copyq_qt}Widgets_DIR}/../..")

message(STATUS "Fixup app: ${FIXUP_BUNDLE_APPS}")
message(STATUS "Fixup app plugins: ${_copyq_installed_plugins}")
Expand Down
2 changes: 1 addition & 1 deletion src/app/clipboardownermonitor.cpp
Expand Up @@ -48,7 +48,7 @@ ClipboardOwnerMonitor::~ClipboardOwnerMonitor()
qApp->removeNativeEventFilter(this);
}

bool ClipboardOwnerMonitor::nativeEventFilter(const QByteArray &, void *, long *)
bool ClipboardOwnerMonitor::nativeEventFilter(const QByteArray &, void *, NativeEventResult *)
{
if ( !m_timer.isActive() )
m_timer.start();
Expand Down

0 comments on commit 23dd6f7

Please sign in to comment.