fix #735,support shortcut to open Latte settngs

--the default shortcut is Meta+A but the user can
change it to whatever wants to from plasma systemsettings.
--the settings windows are show bases on priority.
Primary screen docks have higher priority and for the
edges the priority is: Bottom,Left,Top,Right
pull/2/head
Michail Vourlakos 7 years ago
parent 26a9f2ce61
commit 5b1d35d25b

@ -458,6 +458,16 @@ QString DockView::currentScreen() const
return m_screenToFollowId;
}
bool DockView::settingsWindowIsShown() const
{
return (m_configView != nullptr);
}
void DockView::showSettingsWindow()
{
showConfigurationInterface(containment());
}
void DockView::showConfigurationInterface(Plasma::Applet *applet)
{
if (!applet || !applet->containment())

@ -160,6 +160,9 @@ public:
QRect localGeometry() const;
void setLocalGeometry(const QRect &geometry);
bool settingsWindowIsShown() const;
void showSettingsWindow();
VisibilityManager *visibility() const;
QQmlListProperty<QScreen> screens();

@ -165,6 +165,14 @@ GlobalShortcuts::~GlobalShortcuts()
void GlobalShortcuts::init()
{
KActionCollection *generalActions = new KActionCollection(m_corona);
QAction *settingsAction = generalActions->addAction(QStringLiteral("show settings window"));
settingsAction->setText(i18n("Show Settings Window"));
KGlobalAccel::setGlobalShortcut(settingsAction, QKeySequence(Qt::META + Qt::Key_A));
connect(settingsAction, &QAction::triggered, this, [this] {
showSettings();
});
KActionCollection *taskbarActions = new KActionCollection(m_corona);
//activate actions
@ -436,6 +444,137 @@ void GlobalShortcuts::showDock()
}
}
bool GlobalShortcuts::dockAtLowerScreenPriority(DockView *test, DockView *base)
{
if (!base || ! test) {
return true;
}
if (base->screen() == test->screen()) {
return false;
} else if (base->screen() != qGuiApp->primaryScreen() && test->screen() == qGuiApp->primaryScreen()) {
return false;
} else if (base->screen() == qGuiApp->primaryScreen() && test->screen() != qGuiApp->primaryScreen()) {
return true;
} else {
int basePriority = -1;
int testPriority = -1;
for (int i = 0; i < qGuiApp->screens().count(); ++i) {
if (base->screen() == qGuiApp->screens()[i]) {
basePriority = i;
}
if (test->screen() == qGuiApp->screens()[i]) {
testPriority = i;
}
}
if (testPriority <= basePriority) {
return true;
} else {
return false;
}
}
qDebug() << "dockAtLowerScreenPriority : shouldnt had reached here...";
return false;
}
bool GlobalShortcuts::dockAtLowerEdgePriority(DockView *test, DockView *base)
{
if (!base || ! test) {
return true;
}
QList<Plasma::Types::Location> edges{Plasma::Types::RightEdge, Plasma::Types::TopEdge,
Plasma::Types::LeftEdge, Plasma::Types::BottomEdge};
int testPriority = -1;
int basePriority = -1;
for (int i = 0; i < edges.count(); ++i) {
if (edges[i] == base->location()) {
basePriority = i;
}
if (edges[i] == test->location()) {
testPriority = i;
}
}
if (testPriority < basePriority)
return true;
else
return false;
}
void GlobalShortcuts::showSettings()
{
QList<DockView *> docks;
//! create a docks list to sorted out
for (auto it = m_corona->m_dockViews.constBegin(), end = m_corona->m_dockViews.constEnd(); it != end; ++it) {
docks.append(it.value());
}
qDebug() << " -------- ";
for (int i = 0; i < docks.count(); ++i) {
qDebug() << i << ". " << docks[i]->screen()->name() << " - " << docks[i]->location();
}
//! sort the docks based on screens and edges priorities
//! docks on primary screen have higher priority and
//! for docks in the same screen the priority goes to
//! Bottom,Left,Top,Right
for (int i = 0; i < docks.size(); ++i) {
for (int j = 0; j < docks.size() - i - 1; ++j) {
if (dockAtLowerScreenPriority(docks[j], docks[j + 1])
|| (docks[j]->screen() == docks[j + 1]->screen()
&& dockAtLowerEdgePriority(docks[j], docks[j + 1]))) {
DockView *temp = docks[j + 1];
docks[j + 1] = docks[j];
docks[j] = temp;
}
}
}
qDebug() << " -------- sorted -----";
for (int i = 0; i < docks.count(); ++i) {
qDebug() << i << ". " << docks[i]->screen()->name() << " - " << docks[i]->location();
}
//! find which is the next dock to show its settings
if (docks.count() > 0) {
int openSettings = -1;
//! check if there is a dock with opened settings window
for (int i = 0; i < docks.size(); ++i) {
if (docks[i]->settingsWindowIsShown()) {
openSettings = i;
break;
}
}
if (openSettings >= 0 && docks.count() > 1) {
openSettings = openSettings + 1;
if (openSettings >= docks.size()) {
openSettings = 0;
}
docks[openSettings]->showSettingsWindow();
} else {
docks[0]->showSettingsWindow();
}
}
}
void GlobalShortcuts::hideDockTimerSlot()
{
if (!m_lastInvokedAction || !m_hideDock) {

@ -51,6 +51,10 @@ private:
void activateTaskManagerEntry(int index, Qt::Key modifier);
void showDock();
void hideDock();
void showSettings();
bool dockAtLowerEdgePriority(DockView *test, DockView *base);
bool dockAtLowerScreenPriority(DockView *test, DockView *base);
QAction *m_lastInvokedAction;
QTimer m_hideDockTimer;

Loading…
Cancel
Save