Add new global shortcut system backend for X11 and Windows
- Remove qxt - Also create an option for enabled/disabling shortcuts through X11.
This commit is contained in:
@@ -133,7 +133,10 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent)
|
||||
QTreeWidgetItem *iface = AddCategory(tr("User interface"));
|
||||
AddPage(Page_Appearance, new AppearanceSettingsPage(this), iface);
|
||||
AddPage(Page_Notifications, new NotificationsSettingsPage(this), iface);
|
||||
|
||||
#ifdef HAVE_GLOBALSHORTCUTS
|
||||
AddPage(Page_GlobalShortcuts, new GlobalShortcutsSettingsPage(this), iface);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STREAM_TIDAL) || defined(HAVE_STREAM_DEEZER)
|
||||
QTreeWidgetItem *streaming = AddCategory(tr("Streaming"));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -53,6 +54,7 @@ GlobalShortcutsSettingsPage::GlobalShortcutsSettingsPage(SettingsDialog *dialog)
|
||||
ui_(new Ui_GlobalShortcutsSettingsPage),
|
||||
initialised_(false),
|
||||
grabber_(new GlobalShortcutGrabber) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
ui_->shortcut_options->setEnabled(false);
|
||||
ui_->list->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
@@ -64,8 +66,17 @@ GlobalShortcutsSettingsPage::GlobalShortcutsSettingsPage(SettingsDialog *dialog)
|
||||
connect(ui_->radio_none, SIGNAL(clicked()), SLOT(NoneClicked()));
|
||||
connect(ui_->radio_default, SIGNAL(clicked()), SLOT(DefaultClicked()));
|
||||
connect(ui_->radio_custom, SIGNAL(clicked()), SLOT(ChangeClicked()));
|
||||
connect(ui_->change, SIGNAL(clicked()), SLOT(ChangeClicked()));
|
||||
connect(ui_->gnome_open, SIGNAL(clicked()), SLOT(OpenGnomeKeybindingProperties()));
|
||||
connect(ui_->button_change, SIGNAL(clicked()), SLOT(ChangeClicked()));
|
||||
|
||||
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
||||
#ifdef HAVE_DBUS
|
||||
connect(ui_->checkbox_dbus, SIGNAL(clicked(bool)), SLOT(DBusChanged(bool)));
|
||||
connect(ui_->button_dbus_open, SIGNAL(clicked()), SLOT(OpenGnomeKeybindingProperties()));
|
||||
#endif
|
||||
#ifdef HAVE_X11
|
||||
connect(ui_->checkbox_x11, SIGNAL(clicked(bool)), SLOT(X11Changed(bool)));
|
||||
#endif
|
||||
#endif // !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
||||
|
||||
}
|
||||
|
||||
@@ -91,10 +102,16 @@ void GlobalShortcutsSettingsPage::Load() {
|
||||
if (!initialised_) {
|
||||
initialised_ = true;
|
||||
|
||||
connect(ui_->mac_open, SIGNAL(clicked()), manager, SLOT(ShowMacAccessibilityDialog()));
|
||||
connect(ui_->button_macos_open, SIGNAL(clicked()), manager, SLOT(ShowMacAccessibilityDialog()));
|
||||
|
||||
if (!manager->IsGsdAvailable()) {
|
||||
ui_->gnome_container->hide();
|
||||
ui_->widget_dbus->hide();
|
||||
settings_.setValue("use_dbus", false);
|
||||
}
|
||||
|
||||
if (!manager->IsX11Available()) {
|
||||
ui_->widget_x11->hide();
|
||||
settings_.setValue("use_x11", false);
|
||||
}
|
||||
|
||||
for (const GlobalShortcuts::Shortcut &s : manager->shortcuts().values()) {
|
||||
@@ -114,29 +131,25 @@ void GlobalShortcutsSettingsPage::Load() {
|
||||
SetShortcut(s.s.id, s.s.action->shortcut());
|
||||
}
|
||||
|
||||
bool use_gnome = settings_.value("use_gnome", true).toBool();
|
||||
if (ui_->gnome_container->isVisibleTo(this)) {
|
||||
ui_->gnome_checkbox->setChecked(use_gnome);
|
||||
bool use_dbus = settings_.value("use_dbus", true).toBool();
|
||||
if (ui_->widget_dbus->isVisibleTo(this)) {
|
||||
ui_->checkbox_dbus->setChecked(use_dbus);
|
||||
}
|
||||
|
||||
ui_->mac_container->setVisible(!manager->IsMacAccessibilityEnabled());
|
||||
bool use_x11 = settings_.value("use_x11", false).toBool();
|
||||
if (ui_->widget_x11->isVisibleTo(this)) {
|
||||
ui_->checkbox_x11->setChecked(use_x11);
|
||||
}
|
||||
|
||||
ui_->widget_macos->setVisible(!manager->IsMacAccessibilityEnabled());
|
||||
#ifdef Q_OS_MACOS
|
||||
qint32 mac_version = Utilities::GetMacVersion();
|
||||
ui_->mac_label->setVisible(mac_version < 9);
|
||||
ui_->mac_label_mavericks->setVisible(mac_version >= 9);
|
||||
qint32 macos_version = Utilities::GetMacOsVersion();
|
||||
ui_->label_macos->setVisible(macos_version < 9);
|
||||
ui_->label_macos_mavericks->setVisible(macos_version >= 9);
|
||||
#endif // Q_OS_MACOS
|
||||
|
||||
}
|
||||
|
||||
void GlobalShortcutsSettingsPage::SetShortcut(const QString &id, const QKeySequence &key) {
|
||||
|
||||
Shortcut &shortcut = shortcuts_[id];
|
||||
|
||||
shortcut.key = key;
|
||||
shortcut.item->setText(1, key.toString(QKeySequence::NativeText));
|
||||
|
||||
}
|
||||
|
||||
void GlobalShortcutsSettingsPage::Save() {
|
||||
|
||||
for (const Shortcut &s : shortcuts_.values()) {
|
||||
@@ -145,12 +158,74 @@ void GlobalShortcutsSettingsPage::Save() {
|
||||
settings_.setValue(s.s.id, s.key.toString());
|
||||
}
|
||||
|
||||
settings_.setValue("use_gnome", ui_->gnome_checkbox->isChecked());
|
||||
settings_.setValue("use_dbus", ui_->checkbox_dbus->isChecked());
|
||||
settings_.setValue("use_x11", ui_->checkbox_x11->isChecked());
|
||||
|
||||
dialog()->global_shortcuts_manager()->ReloadSettings();
|
||||
|
||||
}
|
||||
|
||||
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
||||
#ifdef HAVE_X11
|
||||
void GlobalShortcutsSettingsPage::X11Changed(bool) {
|
||||
|
||||
if (!ui_->widget_x11->isVisible()) return;
|
||||
|
||||
if (ui_->checkbox_x11->isChecked()) {
|
||||
ui_->list->setEnabled(true);
|
||||
}
|
||||
else {
|
||||
ui_->list->setEnabled(false);
|
||||
}
|
||||
|
||||
}
|
||||
#endif // HAVE_X11
|
||||
#ifdef HAVE_DBUS
|
||||
void GlobalShortcutsSettingsPage::DBusChanged(bool) {
|
||||
|
||||
if (!ui_->widget_dbus->isVisible()) return;
|
||||
|
||||
if (ui_->checkbox_dbus->isChecked()) {
|
||||
if (ui_->checkbox_x11->isEnabled()) {
|
||||
ui_->checkbox_x11->setEnabled(false);
|
||||
ui_->list->setEnabled(false);
|
||||
}
|
||||
|
||||
if (ui_->checkbox_x11->isChecked()) {
|
||||
ui_->checkbox_x11->setChecked(false);
|
||||
ui_->list->setEnabled(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!ui_->checkbox_x11->isEnabled()) {
|
||||
ui_->checkbox_x11->setEnabled(true);
|
||||
if (ui_->checkbox_x11->isChecked()) ui_->list->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void GlobalShortcutsSettingsPage::OpenGnomeKeybindingProperties() {
|
||||
|
||||
if (!QProcess::startDetached("gnome-keybinding-properties")) {
|
||||
if (!QProcess::startDetached("gnome-control-center", QStringList() << "keyboard")) {
|
||||
QMessageBox::warning(this, "Error", QString("The \"%1\" command could not be started.").arg("gnome-keybinding-properties"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif // HAVE_DBUS
|
||||
|
||||
#endif // !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
||||
|
||||
void GlobalShortcutsSettingsPage::SetShortcut(const QString &id, const QKeySequence &key) {
|
||||
|
||||
Shortcut &shortcut = shortcuts_[id];
|
||||
|
||||
shortcut.key = key;
|
||||
shortcut.item->setText(1, key.toString(QKeySequence::NativeText));
|
||||
|
||||
}
|
||||
|
||||
void GlobalShortcutsSettingsPage::ItemClicked(QTreeWidgetItem *item) {
|
||||
|
||||
current_id_ = item->data(0, Qt::UserRole).toString();
|
||||
@@ -196,14 +271,3 @@ void GlobalShortcutsSettingsPage::ChangeClicked() {
|
||||
|
||||
}
|
||||
|
||||
void GlobalShortcutsSettingsPage::OpenGnomeKeybindingProperties() {
|
||||
|
||||
if (!QProcess::startDetached("gnome-keybinding-properties")) {
|
||||
if (!QProcess::startDetached("gnome-control-center", QStringList() << "keyboard")) {
|
||||
QMessageBox::warning(this, "Error",
|
||||
tr("The \"%1\" command could not be started.")
|
||||
.arg("gnome-keybinding-properties"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -26,6 +27,7 @@
|
||||
#include <memory>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QMap>
|
||||
@@ -43,7 +45,7 @@ class Ui_GlobalShortcutsSettingsPage;
|
||||
class GlobalShortcutsSettingsPage : public SettingsPage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
GlobalShortcutsSettingsPage(SettingsDialog *dialog);
|
||||
~GlobalShortcutsSettingsPage();
|
||||
static const char *kSettingsGroup;
|
||||
@@ -53,15 +55,24 @@ public:
|
||||
void Load();
|
||||
void Save();
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
|
||||
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
||||
#ifdef HAVE_X11
|
||||
void X11Changed(bool);
|
||||
#endif
|
||||
#ifdef HAVE_DBUS
|
||||
void DBusChanged(bool);
|
||||
void OpenGnomeKeybindingProperties();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void ItemClicked(QTreeWidgetItem *);
|
||||
void NoneClicked();
|
||||
void DefaultClicked();
|
||||
void ChangeClicked();
|
||||
|
||||
void OpenGnomeKeybindingProperties();
|
||||
|
||||
private:
|
||||
private:
|
||||
struct Shortcut {
|
||||
GlobalShortcuts::Shortcut s;
|
||||
QKeySequence key;
|
||||
@@ -70,7 +81,7 @@ private:
|
||||
|
||||
void SetShortcut(const QString &id, const QKeySequence &key);
|
||||
|
||||
private:
|
||||
private:
|
||||
Ui_GlobalShortcutsSettingsPage *ui_;
|
||||
|
||||
bool initialised_;
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="gnome_container" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<widget class="QWidget" name="widget_dbus" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_gnome">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@@ -34,7 +34,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="gnome_checkbox">
|
||||
<widget class="QCheckBox" name="checkbox_dbus">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -42,12 +42,12 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use Gnome's shortcut keys</string>
|
||||
<string>Use Gnome D-Bus shortcut keys</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="gnome_open">
|
||||
<widget class="QPushButton" name="button_dbus_open">
|
||||
<property name="text">
|
||||
<string>Open...</string>
|
||||
</property>
|
||||
@@ -57,7 +57,41 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="mac_container" native="true">
|
||||
<widget class="QWidget" name="widget_x11" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_x11">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkbox_x11">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use X11's shortcut keys</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_macos" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
@@ -75,7 +109,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="mac_label">
|
||||
<widget class="QLabel" name="label_macos">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -91,7 +125,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="mac_label_mavericks">
|
||||
<widget class="QLabel" name="label_macos_mavericks">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -107,7 +141,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mac_open">
|
||||
<widget class="QPushButton" name="button_macos_open">
|
||||
<property name="text">
|
||||
<string>Open...</string>
|
||||
</property>
|
||||
@@ -167,7 +201,7 @@
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radio_default">
|
||||
<property name="text">
|
||||
<string>De&fault</string>
|
||||
<string>&Default</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -179,7 +213,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<spacer name="spacer_bottom">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
@@ -192,7 +226,7 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="change">
|
||||
<widget class="QPushButton" name="button_change">
|
||||
<property name="text">
|
||||
<string>Change shortcut...</string>
|
||||
</property>
|
||||
@@ -208,44 +242,11 @@
|
||||
<tabstop>radio_none</tabstop>
|
||||
<tabstop>radio_default</tabstop>
|
||||
<tabstop>radio_custom</tabstop>
|
||||
<tabstop>change</tabstop>
|
||||
<tabstop>button_change</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../data/data.qrc"/>
|
||||
<include location="../../data/icons.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>gnome_checkbox</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>list</receiver>
|
||||
<slot>setDisabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>63</x>
|
||||
<y>25</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>82</x>
|
||||
<y>63</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>gnome_checkbox</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>shortcut_options</receiver>
|
||||
<slot>setDisabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>244</x>
|
||||
<y>26</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>122</x>
|
||||
<y>298</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user