mirror of https://github.com/cutefishos/core
Add hotkeys module
parent
5e16a0b416
commit
9b4ba7c140
@ -0,0 +1,20 @@
|
|||||||
|
find_package(Qt5 COMPONENTS Core DBus REQUIRED)
|
||||||
|
find_package(KF5GlobalAccel REQUIRED)
|
||||||
|
|
||||||
|
set(PROJECT_SOURCES
|
||||||
|
main.cpp
|
||||||
|
application.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(chotkeys
|
||||||
|
${PROJECT_SOURCES}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(chotkeys
|
||||||
|
PRIVATE
|
||||||
|
Qt5::Core
|
||||||
|
Qt5::DBus
|
||||||
|
KF5::GlobalAccel
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS chotkeys RUNTIME DESTINATION /usr/bin)
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 CutefishOS Team.
|
||||||
|
*
|
||||||
|
* Author: Reion Wong <aj@cutefishos.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "application.h"
|
||||||
|
#include <KGlobalAccel>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
|
Application::Application(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
setupShortcuts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setupShortcuts()
|
||||||
|
{
|
||||||
|
QAction *a = addAction("Log Out");
|
||||||
|
KGlobalAccel::self()->setGlobalShortcut(a, QList<QKeySequence>() << Qt::ALT + Qt::CTRL + Qt::Key_Delete);
|
||||||
|
connect(a, &QAction::triggered, this, [=] { QProcess::startDetached("cutefish-shutdown", QStringList()); });
|
||||||
|
|
||||||
|
a = addAction("Lock Screen");
|
||||||
|
a->setProperty("isConfigurationAction", true);
|
||||||
|
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_L);
|
||||||
|
KGlobalAccel::self()->setGlobalShortcut(a, QList<QKeySequence>() << Qt::META + Qt::Key_L);
|
||||||
|
connect(a, &QAction::triggered, this, [=] { QProcess::startDetached("cutefish-screenlocker", QStringList()); });
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction *Application::addAction(const QString &name)
|
||||||
|
{
|
||||||
|
QAction *a = new QAction(this);
|
||||||
|
a->setProperty("componentDisplayName", QStringLiteral("kwin"));
|
||||||
|
a->setObjectName(name);
|
||||||
|
a->setText(name);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 CutefishOS Team.
|
||||||
|
*
|
||||||
|
* Author: Reion Wong <aj@cutefishos.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef APPLICATION_H
|
||||||
|
#define APPLICATION_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAction>
|
||||||
|
|
||||||
|
class Application : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Application(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupShortcuts();
|
||||||
|
QAction *addAction(const QString &name);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // APPLICATION_H
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 CutefishOS Team.
|
||||||
|
*
|
||||||
|
* Author: Reion Wong <aj@cutefishos.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDBusConnection>
|
||||||
|
#include "application.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
if (!QDBusConnection::sessionBus().registerService("org.cutefish.Chotkeys")) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!QDBusConnection::sessionBus().registerObject("/Chotkeys", &a)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Application app;
|
||||||
|
return a.exec();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue