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

[WIP] Use KGlobalAccel for shorcut handling #56

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ find_package(Qt5Widgets REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5LinguistTools REQUIRED QUIET)
find_package(lxqt REQUIRED)
find_package(lxqt-globalkeys REQUIRED)
find_package(lxqt-globalkeys-ui REQUIRED)
find_package(KF5GlobalAccel REQUIRED)
message(STATUS "Building with Qt${Qt5Core_VERSION_STRING}")

include(LXQtCompilerSettings NO_POLICY_SCOPE)
Expand Down Expand Up @@ -78,8 +77,7 @@ set(QRC_FILES

set(lxqt-runner_LIBRARIES
lxqt
lxqt-globalkeys
lxqt-globalkeys-ui
KF5::GlobalAccel
${MENUCACHE_LIBRARIES}
${QTX_LIBRARIES}
${MUPARSER_LDFLAGS}
Expand Down
43 changes: 33 additions & 10 deletions configuredialog/configuredialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@



const QKeySequence ConfigureDialog::DEFAULT_SHORTCUT{Qt::ALT + Qt::Key_F2};
/************************************************

************************************************/
ConfigureDialog::ConfigureDialog(QSettings *settings, const QString &defaultShortcut, QWidget *parent) :
ConfigureDialog::ConfigureDialog(QSettings *settings, QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfigureDialog),
mSettings(settings),
mOldSettings(new LXQt::SettingsCache(settings)),
mDefaultShortcut(defaultShortcut)
mOldSettings(new LXQt::SettingsCache(settings))
{
ui->setupUi(this);

Expand All @@ -75,9 +75,10 @@ ConfigureDialog::ConfigureDialog(QSettings *settings, const QString &defaultShor


// Shortcut .................................
connect(ui->shortcutEd, SIGNAL(shortcutGrabbed(QString)), this, SLOT(shortcutChanged(QString)));
connect(ui->shortcutEd, &QKeySequenceEdit::editingFinished, this, &ConfigureDialog::shortcutChanged);

connect(ui->shortcutEd->addMenuAction(tr("Reset")), SIGNAL(triggered()), this, SLOT(shortcutReset()));
//TODO:?
//connect(ui->shortcutEd->addMenuAction(tr("Reset")), SIGNAL(triggered()), this, SLOT(shortcutReset()));

settingsChanged();

Expand All @@ -96,7 +97,7 @@ void ConfigureDialog::settingsChanged()
ui->positionCbx->setCurrentIndex(1);

ui->monitorCbx->setCurrentIndex(mSettings->value("dialog/monitor", -1).toInt() + 1);
ui->shortcutEd->setText(mSettings->value("dialog/shortcut", "Alt+F2").toString());
ui->shortcutEd->setKeySequence(mSettings->value("dialog/shortcut", DEFAULT_SHORTCUT).toString());
ui->historyCb->setChecked(mSettings->value("dialog/history_first", true).toBool());
}

Expand All @@ -114,10 +115,31 @@ ConfigureDialog::~ConfigureDialog()
/************************************************

************************************************/
void ConfigureDialog::shortcutChanged(const QString &text)
void ConfigureDialog::shortcutChanged()
{
ui->shortcutEd->setText(text);
mSettings->setValue("dialog/shortcut", text);
QKeySequence shortcut = ui->shortcutEd->keySequence();
if (shortcut.isEmpty())
shortcut = mSettings->value("dialog/shortcut", DEFAULT_SHORTCUT).toString();
else
{
// use only the first key (+modifiers)
if (shortcut.count() > 1)
shortcut = shortcut[0];

const int modifiers = shortcut[0] & Qt::MODIFIER_MASK;
const int key = shortcut[0] & ~Qt::MODIFIER_MASK;
// do not allow plain printable keys
if (modifiers
&& !(modifiers == Qt::SHIFT && key > Qt::Key_Space && key <= Qt::Key_AsciiTilde))
{
mSettings->setValue("dialog/shortcut", shortcut);
} else
{
shortcut = mSettings->value("dialog/shortcut", DEFAULT_SHORTCUT).toString();
}
}
ui->shortcutEd->setKeySequence(shortcut);
ui->shortcutEd->clearFocus();
}


Expand All @@ -126,7 +148,8 @@ void ConfigureDialog::shortcutChanged(const QString &text)
************************************************/
void ConfigureDialog::shortcutReset()
{
shortcutChanged(mDefaultShortcut);
ui->shortcutEd->setKeySequence(DEFAULT_SHORTCUT);
shortcutChanged();
}


Expand Down
6 changes: 3 additions & 3 deletions configuredialog/configuredialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class ConfigureDialog : public QDialog
PositionCenter
};

static const QKeySequence DEFAULT_SHORTCUT;

explicit ConfigureDialog(QSettings *settings, const QString &defaultShortcut, QWidget *parent = 0);
explicit ConfigureDialog(QSettings *settings, QWidget *parent = 0);
~ConfigureDialog();

protected:
Expand All @@ -62,10 +63,9 @@ class ConfigureDialog : public QDialog
Ui::ConfigureDialog *ui;
QSettings *mSettings;
LXQt::SettingsCache *mOldSettings;
QString mDefaultShortcut;

private slots:
void shortcutChanged(const QString &text);
void shortcutChanged();
void shortcutReset();
void settingsChanged();
void positionCbxChanged(int index);
Expand Down
19 changes: 1 addition & 18 deletions configuredialog/configuredialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="ShortcutSelector" name="shortcutEd">
<property name="minimumSize">
<size>
<width>81</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QKeySequenceEdit" name="shortcutEd"/>
</item>
</layout>
</item>
Expand Down Expand Up @@ -119,13 +109,6 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ShortcutSelector</class>
<extends>QToolButton</extends>
<header location="global">LXQtGlobalKeysUi/ShortcutSelector</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
Expand Down
31 changes: 13 additions & 18 deletions dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
#include <XdgIcon>
#include <LXQt/PowerManager>
#include <LXQt/ScreenSaver>
#include <LXQtGlobalKeys/Action>
#include <LXQtGlobalKeys/Client>
#include <KGlobalAccel>
#include <QDebug>
#include <QCloseEvent>
#include <QDesktopWidget>
Expand All @@ -53,7 +52,6 @@

#include <KWindowSystem/KWindowSystem>

#define DEFAULT_SHORTCUT "Alt+F2"

/************************************************

Expand All @@ -62,7 +60,7 @@ Dialog::Dialog(QWidget *parent) :
QDialog(parent, Qt::Dialog | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint),
ui(new Ui::Dialog),
mSettings(new LXQt::Settings("lxqt-runner", this)),
mGlobalShortcut(0),
mGlobalShortcut(new QAction("lxqt-runner action", this)),
mLockCascadeChanges(false),
mDesktopChanged(false),
mConfigureDialog(0)
Expand Down Expand Up @@ -111,12 +109,15 @@ Dialog::Dialog(QWidget *parent) :
ui->actionButton->setMenu(menu);
// End of popup menu ........................

mGlobalShortcut->setObjectName("show_hide_dialog");
mGlobalShortcut->setProperty("componentName", "org.lxqt.runner");
mGlobalShortcut->setProperty("componentDisplayName", tr("Show/hide runner dialog"));
applySettings();

connect(QApplication::desktop(), SIGNAL(screenCountChanged(int)), SLOT(realign()));
connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(realign()));
connect(mGlobalShortcut, SIGNAL(activated()), this, SLOT(showHide()));
connect(mGlobalShortcut, SIGNAL(shortcutChanged(QString,QString)), this, SLOT(shortcutChanged(QString,QString)));
connect(mGlobalShortcut, &QAction::triggered, this, &Dialog::showHide);
connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutChanged, this, &Dialog::shortcutChanged);
connect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)), this, SLOT(onActiveWindowChanged(WId)));
connect(KWindowSystem::self(), &KWindowSystem::currentDesktopChanged, this, &Dialog::onCurrentDesktopChanged);

Expand Down Expand Up @@ -343,14 +344,10 @@ void Dialog::applySettings()
return;

// Shortcut .................................
QString shortcut = mSettings->value("dialog/shortcut", DEFAULT_SHORTCUT).toString();
QKeySequence shortcut = mSettings->value("dialog/shortcut", ConfigureDialog::DEFAULT_SHORTCUT).toString();
if (shortcut.isEmpty())
shortcut = DEFAULT_SHORTCUT;

if (!mGlobalShortcut)
mGlobalShortcut = GlobalKeyShortcut::Client::instance()->addAction(shortcut, "/runner/show_hide_dialog", tr("Show/hide runner dialog"), this);
else if (mGlobalShortcut->shortcut() != shortcut)
mGlobalShortcut->changeShortcut(shortcut);
shortcut = ConfigureDialog::DEFAULT_SHORTCUT;
KGlobalAccel::self()->setShortcut(mGlobalShortcut, {shortcut}, KGlobalAccel::NoAutoloading);

mShowOnTop = mSettings->value("dialog/show_on_top", true).toBool();

Expand All @@ -366,9 +363,9 @@ void Dialog::applySettings()
/************************************************

************************************************/
void Dialog::shortcutChanged(const QString &/*oldShortcut*/, const QString &newShortcut)
void Dialog::shortcutChanged(QAction * action, const QKeySequence & newShortcut)
{
if (!newShortcut.isEmpty())
if (mGlobalShortcut == action && !newShortcut.isEmpty())
{
mLockCascadeChanges = true;

Expand Down Expand Up @@ -483,8 +480,6 @@ void Dialog::runCommand()
void Dialog::showConfigDialog()
{
if (!mConfigureDialog)
mConfigureDialog = new ConfigureDialog(mSettings, DEFAULT_SHORTCUT, this);
mConfigureDialog = new ConfigureDialog(mSettings, this);
mConfigureDialog->exec();
}

#undef DEFAULT_SHORTCUT
10 changes: 3 additions & 7 deletions dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ namespace LXQt {
class CommandListView;
class CommandItemModel;
class ConfigureDialog;

namespace GlobalKeyShortcut
{
class Action;
}
class QAction;


class Dialog : public QDialog
Expand All @@ -70,7 +66,7 @@ class Dialog : public QDialog
private:
Ui::Dialog *ui;
LXQt::Settings *mSettings;
GlobalKeyShortcut::Action *mGlobalShortcut;
QAction *mGlobalShortcut;
CommandItemModel *mCommandItemModel;
bool mShowOnTop;
int mMonitor;
Expand All @@ -90,7 +86,7 @@ private slots:
void dataChanged();
void runCommand();
void showConfigDialog();
void shortcutChanged(const QString &oldShortcut, const QString &newShortcut);
void shortcutChanged(QAction * action, const QKeySequence & newShortcut);
void onActiveWindowChanged(WId id);
void onCurrentDesktopChanged(int desktop);
};
Expand Down
2 changes: 0 additions & 2 deletions providers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@
#include <QSettings>
#include <QDir>
#include <QApplication>
#include <QAction>
#include <LXQt/PowerManager>
#include <LXQt/ScreenSaver>
#include "providers.h"
#include <LXQtGlobalKeys/Action>
#include <wordexp.h>
#include <QStandardPaths>

Expand Down