Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build flag to disable X11 support #2534

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ if (USE_QXT)
../qxt/qxtglobalshortcut.cpp
)
add_definitions( -DQXT_STATIC )
add_definitions( -DCOPYQ_GLOBAL_SHORTCUTS )
endif()

# translations
Expand Down
12 changes: 6 additions & 6 deletions src/app/clipboardserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
#include <QStyleFactory>
#include <QTextEdit>

#ifdef NO_GLOBAL_SHORTCUTS
class QxtGlobalShortcut final {};
#else
#ifdef COPYQ_GLOBAL_SHORTCUTS
#include "../qxt/qxtglobalshortcut.h"
#else
class QxtGlobalShortcut final {};
#endif

#include <memory>
Expand Down Expand Up @@ -247,7 +247,7 @@ void ClipboardServer::removeGlobalShortcuts()

void ClipboardServer::onCommandsSaved(const QVector<Command> &commands)
{
#ifndef NO_GLOBAL_SHORTCUTS
#ifdef COPYQ_GLOBAL_SHORTCUTS
removeGlobalShortcuts();

QList<QKeySequence> usedShortcuts;
Expand Down Expand Up @@ -556,7 +556,7 @@ void ClipboardServer::onNotificationButtonClicked(const NotificationButton &butt

void ClipboardServer::createGlobalShortcut(const QKeySequence &shortcut, const Command &command)
{
#ifdef NO_GLOBAL_SHORTCUTS
#ifndef COPYQ_GLOBAL_SHORTCUTS
Q_UNUSED(shortcut)
Q_UNUSED(command)
#else
Expand Down Expand Up @@ -731,7 +731,7 @@ void ClipboardServer::loadSettings(AppConfig *appConfig)

void ClipboardServer::shortcutActivated(QxtGlobalShortcut *shortcut)
{
#ifdef NO_GLOBAL_SHORTCUTS
#ifndef COPYQ_GLOBAL_SHORTCUTS
Q_UNUSED(shortcut)
#else
m_ignoreKeysTimer.start();
Expand Down
9 changes: 0 additions & 9 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ class QMimeData;
class QProcess;
class QString;

#if !defined(COPYQ_WS_X11) && !defined(Q_OS_WIN) && !defined(Q_OS_MAC)
# define NO_GLOBAL_SHORTCUTS
#endif

#ifdef COPYQ_WS_X11
// QClipboard::supportsSelection() must return true.
# define HAS_MOUSE_SELECTIONS
#endif

bool isMainThread();

QByteArray makeClipboardOwnerData();
Expand Down
2 changes: 1 addition & 1 deletion src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void saveMainWindowState(const QString &mainWindowObjectName, const QByteArray &

void moveToCurrentWorkspace(QWidget *w)
{
#ifdef COPYQ_WS_X11
#ifdef COPYQ_MOVE_TO_WORKSPACE
/* Re-initialize window in window manager so it can popup on current workspace. */
if (w->isVisible()) {
GEOMETRY_LOG( w, QLatin1String("Move to current workspace") );
Expand Down
6 changes: 3 additions & 3 deletions src/common/globalshortcutcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#include "globalshortcutcommands.h"

#include "common/command.h"
#include "common/shortcuts.h"
#include "gui/icons.h"

#include <QCoreApplication>
#include <QLocale>
#include <QVector>

#ifndef NO_GLOBAL_SHORTCUTS
#ifdef COPYQ_GLOBAL_SHORTCUTS
# include "common/shortcuts.h"
# include "gui/icons.h"

namespace {

Expand Down
10 changes: 6 additions & 4 deletions src/gui/commandwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ namespace {

const QIcon iconClipboard() { return getIcon("", IconClipboard); }
const QIcon iconMenu() { return getIcon("", IconBars); }
const QIcon iconShortcut() { return getIcon("", IconKeyboard); }
const QIcon iconScript() { return getIcon("", IconGear); }
const QIcon iconDisplay() { return getIcon("", IconEye); }
#ifdef COPYQ_GLOBAL_SHORTCUTS
const QIcon iconShortcut() { return getIcon("", IconKeyboard); }
#endif

QStringList serializeShortcuts(const QList<QKeySequence> &shortcuts)
{
Expand Down Expand Up @@ -91,11 +93,11 @@ CommandWidget::CommandWidget(QWidget *parent)

updateWidgets();

#ifdef NO_GLOBAL_SHORTCUTS
#ifdef COPYQ_GLOBAL_SHORTCUTS
ui->toolButtonGlobalShortcut->setIcon(iconShortcut());
#else
ui->toolButtonGlobalShortcut->hide();
ui->shortcutButtonGlobalShortcut->hide();
#else
ui->toolButtonGlobalShortcut->setIcon(iconShortcut());
#endif

ui->toolButtonAutomatic->setIcon(iconClipboard());
Expand Down
4 changes: 0 additions & 4 deletions src/gui/menuitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ MenuItems menuItems()
addMenuItem( items, Actions::File_Preferences, QObject::tr("&Preferences..."), "preferences", QObject::tr("Ctrl+P"),
"preferences-other", IconWrench );
addMenuItem( items, Actions::File_Commands,
#ifndef NO_GLOBAL_SHORTCUTS
QObject::tr("C&ommands/Global Shortcuts..."),
#else
QObject::tr("C&ommands..."),
#endif
"commands", QObject::tr("F6"), "system-run", IconGear );

addMenuItem( items, Actions::File_ShowClipboardContent, QObject::tr("Show &Clipboard Content"),
Expand Down
1 change: 0 additions & 1 deletion src/platform/platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ else()
)
set(USE_QXT FALSE)
endif()

17 changes: 12 additions & 5 deletions src/platform/x11/x11info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@

#include <QGuiApplication>

#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
# include <QX11Info>
#ifdef COPYQ_WITH_X11
# if QT_VERSION < QT_VERSION_CHECK(6,0,0)
# include <QX11Info>
# else
# include <QtGui/private/qtx11extras_p.h>
# endif
# include <X11/Xlib.h>
#else
# include <QtGui/private/qtx11extras_p.h>
struct _XDisplay {};
#endif

#include <X11/Xlib.h>

bool X11Info::isPlatformX11()
{
return QGuiApplication::platformName() == QStringLiteral("xcb");
}

Display *X11Info::display()
{
#ifdef COPYQ_WITH_X11
return QX11Info::display();
#else
return nullptr;
#endif
}
63 changes: 37 additions & 26 deletions src/platform/x11/x11platform.cmake
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
# X11 requires 'fixes' extension for clipboard to work correctly.
message(STATUS "Building for X11 window system.")
if(NOT X11_Xfixes_FOUND)
message(FATAL_ERROR "X11 'fixes' extension library is required")
endif(NOT X11_Xfixes_FOUND)

if(X11_XTest_FOUND)
add_definitions( -DHAS_X11TEST )
list(APPEND copyq_DEFINITIONS HAS_X11TEST)
list(APPEND copyq_LIBRARIES ${X11_XTest_LIB})
else(X11_XTest_FOUND)
message(WARNING "X11 'TEST' extension library is needed to be able to"
" automatically paste to some windows!")
endif(X11_XTest_FOUND)

add_definitions( -DCOPYQ_WS_X11 )
list(APPEND copyq_DEFINITIONS COPYQ_WS_X11)

file(GLOB copyq_SOURCES ${copyq_SOURCES}
platform/x11/*.cpp
platform/x11/x11info.cpp
platform/x11/x11platform.cpp
platform/x11/x11platformclipboard.cpp
platform/dummy/dummyclipboard.cpp
platform/platformcommon.cpp
../qxt/qxtglobalshortcut_x11.cpp
)

set(USE_QXT TRUE)
add_definitions( -DHAS_MOUSE_SELECTIONS )
add_definitions( -DCOPYQ_MOVE_TO_WORKSPACE )

OPTION(WITH_X11 "Enable X11 support (global shortcuts, getting window titles)" ON)
if (WITH_X11)
add_definitions( -DCOPYQ_WITH_X11 )

# X11 requires 'fixes' extension for clipboard to work correctly.
message(STATUS "Building for X11 window system.")
if(NOT X11_Xfixes_FOUND)
message(FATAL_ERROR "X11 'fixes' extension library is required")
endif(NOT X11_Xfixes_FOUND)

if(X11_XTest_FOUND)
add_definitions( -DHAS_X11TEST )
list(APPEND copyq_DEFINITIONS HAS_X11TEST)
list(APPEND copyq_LIBRARIES ${X11_XTest_LIB})
else(X11_XTest_FOUND)
message(WARNING "X11 'TEST' extension library is needed to be able to"
" automatically paste to some windows!")
endif(X11_XTest_FOUND)

file(GLOB copyq_SOURCES ${copyq_SOURCES}
platform/x11/x11platformwindow.cpp
../qxt/qxtglobalshortcut_x11.cpp
)

set(USE_QXT TRUE)

set(copyq_LIBRARIES ${copyq_LIBRARIES} ${X11_LIBRARIES} ${X11_Xfixes_LIB})
set(copyq_LIBRARIES ${copyq_LIBRARIES} ${X11_LIBRARIES} ${X11_Xfixes_LIB})

if(WITH_QT6)
list(APPEND copyq_LIBRARIES Qt::GuiPrivate)
else()
list(APPEND copyq_qt_modules X11Extras)
if(WITH_QT6)
list(APPEND copyq_LIBRARIES Qt::GuiPrivate)
else()
list(APPEND copyq_qt_modules X11Extras)
endif()
endif()

# Wayland clipboard
Expand Down
30 changes: 25 additions & 5 deletions src/platform/x11/x11platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
#include <QVariant>
#include <QWidget>

#include "x11platformwindow.h"
#include "x11platformclipboard.h"

#include <X11/Xatom.h>
#include <X11/Xlib.h>
#ifdef COPYQ_WITH_X11
# include "x11platformwindow.h"
# include <X11/Xatom.h>
# include <X11/Xlib.h>
#endif

#include <memory>

namespace {

int (*old_xio_errhandler)(Display *) = nullptr;

const char *defaultDesktopFileContent =
R"([Desktop Entry]
Name=CopyQ
Expand All @@ -40,6 +40,9 @@ X-KDE-StartupNotify=false
X-KDE-UniqueApplet=true
)";

#ifdef COPYQ_WITH_X11
int (*old_xio_errhandler)(Display *) = nullptr;

// Try to handle X11 fatal error gracefully.
int copyq_xio_errhandler(Display *display)
{
Expand All @@ -60,6 +63,7 @@ int copyq_xio_errhandler(Display *display)
// As documentation for XSetIOErrorHandler states, this function should not return.
exit(1);
}
#endif

#ifdef COPYQ_DESKTOP_FILE
QString getDesktopFilename()
Expand Down Expand Up @@ -96,20 +100,29 @@ X11Platform::~X11Platform() = default;

PlatformWindowPtr X11Platform::getWindow(WId winId)
{
#ifdef COPYQ_WITH_X11
if (!X11Info::isPlatformX11())
return PlatformWindowPtr();

std::unique_ptr<X11PlatformWindow> window(new X11PlatformWindow(winId));
return PlatformWindowPtr(window->isValid() ? window.release() : nullptr);
#else
Q_UNUSED(winId)
return PlatformWindowPtr();
#endif
}

PlatformWindowPtr X11Platform::getCurrentWindow()
{
#ifdef COPYQ_WITH_X11
if (!X11Info::isPlatformX11())
return PlatformWindowPtr();

std::unique_ptr<X11PlatformWindow> window(new X11PlatformWindow());
return PlatformWindowPtr(window->isValid() ? window.release() : nullptr);
#else
return PlatformWindowPtr();
#endif
}

bool X11Platform::canAutostart()
Expand Down Expand Up @@ -227,8 +240,10 @@ QCoreApplication *X11Platform::createConsoleApplication(int &argc, char **argv)

QApplication *X11Platform::createServerApplication(int &argc, char **argv)
{
#ifdef COPYQ_WITH_X11
if (X11Info::isPlatformX11())
old_xio_errhandler = XSetIOErrorHandler(copyq_xio_errhandler);
#endif
return new ApplicationExceptionHandler<QApplication>(argc, argv);
}

Expand Down Expand Up @@ -305,15 +320,20 @@ QString X11Platform::translationPrefix()
return QString();
}

#ifdef COPYQ_WITH_X11
void sendDummyX11Event()
{
if (!X11Info::isPlatformX11())
return;

auto display = X11Info::display();
if (!display)
return;

auto black = BlackPixel(display, 0);
Window window = XCreateSimpleWindow(
display, RootWindow(display, 0), -100000, -100000, 1, 1, 0, black, black);
XDestroyWindow(display, window);
XFlush(display);
}
#endif
2 changes: 2 additions & 0 deletions src/platform/x11/x11platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class X11Platform final : public PlatformNativeInterface
QString themePrefix() override { return QString(); }
};

#ifdef COPYQ_WITH_X11
void sendDummyX11Event();
#endif

#endif // X11PLATFORM_H
12 changes: 10 additions & 2 deletions src/platform/x11/x11platformclipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

#include "systemclipboard/waylandclipboard.h"

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#ifdef COPYQ_WITH_X11
# include <X11/Xlib.h>
# include <X11/Xatom.h>
#endif

#include <QClipboard>
#include <QMimeData>
Expand All @@ -28,10 +30,13 @@ constexpr auto maxRetryCount = 3;
/// Return true only if selection is incomplete, i.e. mouse button or shift key is pressed.
bool isSelectionIncomplete()
{
#ifdef COPYQ_WITH_X11
if (!X11Info::isPlatformX11())
return false;

auto display = X11Info::display();
if (!display)
return false;

// If mouse button or shift is pressed then assume that user is selecting text.
XEvent event{};
Expand All @@ -42,6 +47,9 @@ bool isSelectionIncomplete()
&event.xbutton.state);

return event.xbutton.state & (Button1Mask | ShiftMask);
#else
return true;
#endif
}

} // namespace
Expand Down
Loading