Skip to content

Commit

Permalink
feat: globalshortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
justforlxz committed Dec 9, 2022
1 parent 0e95bc4 commit 48d562d
Show file tree
Hide file tree
Showing 12 changed files with 482 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ project(xdg-desktop-portal-dde
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX /usr)
endif ()
include(GNUInstallDirs)

find_package(KF5GlobalAccel REQUIRED)

add_subdirectory(src)

Expand Down
4 changes: 2 additions & 2 deletions archlinux/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pkgdesc='xdg-desktop-portal backend for deepin'
arch=('x86_64' 'aarch64')
url='https://github.com/linuxdeepin/xdg-desktop-portal-dde'
license=('LGPL3')
depends=('deepin-qt-dbus-factory-git' 'qt5-base')
makedepends=('git' 'ninja' 'cmake' 'qt5-tools')
depends=('deepin-qt-dbus-factory-git' 'qt5-base' 'kglobalaccel')
makedepends=('git' 'ninja' 'cmake' 'qt5-tools' 'kglobalaccel')
provides=('xdg-desktop-portal-impl')
groups=('deepin-git')
source=('source.tar.gz')
Expand Down
5 changes: 4 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Priority: optional
Maintainer: Deepin Packages Builder <[email protected]>
Build-Depends:
debhelper (>= 9),
cmake, qtbase5-dev, qttools5-dev-tools
cmake,
qtbase5-dev,
qttools5-dev-tools,
libkf5globalaccel-dev
Standards-Version: 4.5.0

Package: xdg-desktop-portal-dde
Expand Down
28 changes: 25 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core)
find_package(
Qt${QT_VERSION_MAJOR} CONFIG REQUIRED COMPONENTS
Core
Expand All @@ -8,6 +8,23 @@ find_package(
#find_package(DtkCore)
#find_package(DtkGui)
#find_package(DtkWidget)

set(kglobalaccel_xml ${KGLOBALACCEL_DBUS_INTERFACES_DIR}/kf5_org.kde.KGlobalAccel.xml)
set_source_files_properties(${kglobalaccel_xml} PROPERTIES
INCLUDE "kglobalaccel.h"
NO_NAMESPACE TRUE
CLASSNAME "KGlobalAccelInterface"
)
qt_add_dbus_interface(xdg_desktop_portal_kde_SRCS ${kglobalaccel_xml} kglobalaccel_interface)

set(kglobalaccel_component_xml ${KGLOBALACCEL_DBUS_INTERFACES_DIR}/kf5_org.kde.kglobalaccel.Component.xml)
set_source_files_properties(${kglobalaccel_component_xml} PROPERTIES
INCLUDE "kglobalshortcutinfo.h"
NO_NAMESPACE TRUE
CLASSNAME "KGlobalAccelComponentInterface"
)
qt_add_dbus_interface(xdg_desktop_portal_kde_SRCS ${kglobalaccel_component_xml} kglobalaccel_component_interface)

set(SRC
xdg-desktop-portal-dde.cpp
ddesktopportal.h
Expand Down Expand Up @@ -49,13 +66,18 @@ set(SRC
)

add_executable(${PROJECT_NAME}
${SRC})
${SRC}
)

target_sources(${PROJECT_NAME} PRIVATE ${xdg_desktop_portal_kde_SRCS})

target_link_libraries(${PROJECT_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Concurrent)
Qt${QT_VERSION_MAJOR}::Concurrent
KF5::GlobalAccel
)

install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR})
15 changes: 9 additions & 6 deletions src/appchooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
#include <QDBusMessage>
#include <QDBusServiceWatcher>
#include <QLoggingCategory>
#include <QTimer>

Q_LOGGING_CATEGORY(appChooserCategory, "xdg-dde-appchooser")
AppChooserPortal::AppChooserPortal(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
#ifdef QT_DEBUG
QVariantMap results;
QVariantMap options;
options.insert("modal", true);
options.insert("content_type", "title");
ChooseApplication(QDBusObjectPath(), "", "", QStringList(), options, results);
qDebug() << results;
QTimer::singleShot(0, this, [=] {
QVariantMap results;
QVariantMap options;
options.insert("modal", true);
options.insert("content_type", "title");
ChooseApplication(QDBusObjectPath(), "", "", QStringList(), options, results);
qDebug() << results;
});
#endif
}

Expand Down
1 change: 0 additions & 1 deletion src/ddesktopportal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ DDesktopPortal::DDesktopPortal(QObject *parent)
m_settings = new SettingsPortal(this);
m_inhibit = new InhibitPortal(this);
m_account = new AccountPortal(this);
m_session = new SessionPortal(this);
m_shortcut = new GlobalShortcutPortal(this);
m_lockdown = new LockdownPortal(this);
m_secret = new SecretPortal(this);
Expand Down
2 changes: 0 additions & 2 deletions src/ddesktopportal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class BackgroundPortal;
class InhibitPortal;
class SettingsPortal;
class AccountPortal;
class SessionPortal;
class GlobalShortcutPortal;
class LockdownPortal;
class SecretPortal;
Expand All @@ -39,7 +38,6 @@ class DDesktopPortal : public QObject, public QDBusContext
InhibitPortal *m_inhibit = nullptr;
SettingsPortal *m_settings = nullptr;
AccountPortal *m_account = nullptr;
SessionPortal *m_session = nullptr;
GlobalShortcutPortal *m_shortcut = nullptr;
LockdownPortal *m_lockdown = nullptr;
SecretPortal *m_secret = nullptr;
Expand Down
103 changes: 88 additions & 15 deletions src/globalshortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,111 @@

#include "globalshortcut.h"

#include "session.h"

#include <QLoggingCategory>
#include <QDBusMetaType>

Q_LOGGING_CATEGORY(XdgDesktopDDEGlobalShortCut, "xdg-dde-global-shortcut")

GlobalShortcutPortal::GlobalShortcutPortal(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
qCDebug(XdgDesktopDDEGlobalShortCut) << "init global shortcut";
qDBusRegisterMetaType<Shortcut>();
qDBusRegisterMetaType<Shortcuts>();

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Q_ASSERT(QLatin1String(QDBusMetaType::typeToSignature(qMetaTypeId<Shortcuts>())) == QLatin1String("a(sa{sv})"));
#else
Q_ASSERT(QLatin1String(QDBusMetaType::typeToSignature(QMetaType(qMetaTypeId<Shortcuts>()))) == QLatin1String("a(sa{sv})"));
#endif
}

uint GlobalShortcutPortal::CreateSession(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QString &app_id,
const QVariantMap &options,
QVariantMap &results)
const QDBusObjectPath &session_handle,
const QString &app_id,
const QVariantMap &options,
QVariantMap &results)
{
qCDebug(XdgDesktopDDEGlobalShortCut) << "create session";
return 1;
qCDebug(XdgDesktopDDEGlobalShortCut) << "CreateSession called with parameters:";
qCDebug(XdgDesktopDDEGlobalShortCut) << " handle: " << handle.path();
qCDebug(XdgDesktopDDEGlobalShortCut) << " session_handle: " << session_handle.path();
qCDebug(XdgDesktopDDEGlobalShortCut) << " app_id: " << app_id;
qCDebug(XdgDesktopDDEGlobalShortCut) << " options: " << options;

if (auto session = qobject_cast<GlobalShortcutsSession *>(
Session::createSession(this, Session::GlobalShortcuts, app_id, session_handle.path()))) {
session->restoreActions(options["shortcuts"]);
connect(session, &GlobalShortcutsSession::shortcutsChanged, this, [this, session, session_handle] {
Q_EMIT ShortcutsChanged(session_handle, session->shortcutDescriptions());
});

connect(session,
&GlobalShortcutsSession::shortcutActivated,
this,
[this, session](const QString &shortcutName, qlonglong timestamp) {
Q_EMIT Activated(QDBusObjectPath(session->handle()), shortcutName, timestamp);
});
connect(session,
&GlobalShortcutsSession::shortcutDeactivated,
this,
[this, session](const QString &shortcutName, qlonglong timestamp) {
Q_EMIT Deactivated(QDBusObjectPath(session->handle()), shortcutName, timestamp);
});

results = {
{"shortcuts", session->shortcutDescriptionsVariant()},
};
return 0;
}

return 2;
}

QVariantMap GlobalShortcutPortal::BindShortCuts(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QVariantMap &shortcuts,
const QString &parent_window,
const QVariantMap &options)
uint GlobalShortcutPortal::BindShortCuts(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QVariantMap &shortcuts,
const QString &parent_window,
const QVariantMap &options,
QVariantMap &results)
{
qCDebug(XdgDesktopDDEGlobalShortCut) << "BindShortCuts";
return QVariantMap();
qCDebug(XdgDesktopDDEGlobalShortCut) << "BindShortcuts called with parameters:";
qCDebug(XdgDesktopDDEGlobalShortCut) << " handle: " << handle.path();
qCDebug(XdgDesktopDDEGlobalShortCut) << " session_handle: " << session_handle.path();
qCDebug(XdgDesktopDDEGlobalShortCut) << " shortcuts: " << shortcuts;
qCDebug(XdgDesktopDDEGlobalShortCut) << " parent_window: " << parent_window;
qCDebug(XdgDesktopDDEGlobalShortCut) << " options: " << options;

if (auto session = qobject_cast<GlobalShortcutsSession *>(Session::getSession(session_handle.path()))) {
// TODO: show dialog to bind a shortcut

results = {
{"shortcuts", session->shortcutDescriptionsVariant()},
};

return 0;
}

return 2;
}

QVariantMap GlobalShortcutPortal::ListShortCuts(const QDBusObjectPath &handle, const QDBusObjectPath &session_handle)
uint GlobalShortcutPortal::ListShortCuts(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
QVariantMap &results)
{
qCDebug(XdgDesktopDDEGlobalShortCut) << "get ShortCuts";
return QVariantMap();
qCDebug(XdgDesktopDDEGlobalShortCut) << "ListShortcuts called with parameters:";
qCDebug(XdgDesktopDDEGlobalShortCut) << " handle: " << handle.path();
qCDebug(XdgDesktopDDEGlobalShortCut) << " session_handle: " << session_handle.path();

if (auto session = qobject_cast<GlobalShortcutsSession *>(Session::getSession(session_handle.path()))) {
results = {
{"shortcuts", session->shortcutDescriptionsVariant()},
};

return 0;
}

return 2;
}
26 changes: 20 additions & 6 deletions src/globalshortcut.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#pragma once

#include "utils.h"

#include <QDBusAbstractAdaptor>
#include <QDBusObjectPath>

Expand All @@ -24,10 +26,22 @@ public slots:
const QString &app_id,
const QVariantMap &options,
QVariantMap &results);
QVariantMap BindShortCuts(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QVariantMap &shortcuts,
const QString &parent_window,
const QVariantMap &options);
QVariantMap ListShortCuts(const QDBusObjectPath &handle, const QDBusObjectPath &session_handle);
uint BindShortCuts(const QDBusObjectPath &handle,
const QDBusObjectPath &session_handle,
const QVariantMap &shortcuts,
const QString &parent_window,
const QVariantMap &options,
QVariantMap &results);
uint ListShortCuts(const QDBusObjectPath &handle, const QDBusObjectPath &session_handle, QVariantMap &results);

Q_SIGNALS:
void Activated(const QDBusObjectPath &session_handle,
const QString &shortcutId,
quint64 timestamp,
const QVariantMap &unused = {});
void Deactivated(const QDBusObjectPath &session_handle,
const QString &shortcutId,
quint64 timestamp,
const QVariantMap &unused = {});
void ShortcutsChanged(const QDBusObjectPath &session_handle, const Shortcuts &shortcuts);
};
Loading

0 comments on commit 48d562d

Please sign in to comment.