From f9eb3f370a4e600a62e2da6805bd8712ce94cf82 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 24 Jun 2016 20:54:31 +0000 Subject: [PATCH] kwin: fix out of bounds in screen edges KCM Signed-off-by: Ivailo Monev --- kwin/kcmkwin/kwinscreenedges/main.cpp | 134 +++++++++++++++---------------- kwin/kcmkwin/kwinscreenedges/main.h | 10 +-- kwin/kcmkwin/kwinscreenedges/monitor.cpp | 4 +- kwin/kcmkwin/kwinscreenedges/monitor.h | 16 ++-- kwin/libkwineffects/kwinglobals.h | 12 +-- 5 files changed, 88 insertions(+), 88 deletions(-) diff --git a/kwin/kcmkwin/kwinscreenedges/main.cpp b/kwin/kcmkwin/kwinscreenedges/main.cpp index 38631531..89159e60 100644 --- a/kwin/kcmkwin/kwinscreenedges/main.cpp +++ b/kwin/kcmkwin/kwinscreenedges/main.cpp @@ -190,10 +190,10 @@ void KWinScreenEdgesConfig::monitorInit() monitorAddItem(i18n("Lock Screen")); monitorAddItem(i18n("Prevent Screen Locking")); //Prevent Screen Locking is not supported on some edges - m_ui->monitor->setEdgeItemEnabled(int(Monitor::Top), 4, false); - m_ui->monitor->setEdgeItemEnabled(int(Monitor::Left), 4, false); - m_ui->monitor->setEdgeItemEnabled(int(Monitor::Right), 4, false); - m_ui->monitor->setEdgeItemEnabled(int(Monitor::Bottom), 4, false); + m_ui->monitor->setEdgeItemEnabled(Monitor::Top, 4, false); + m_ui->monitor->setEdgeItemEnabled(Monitor::Left, 4, false); + m_ui->monitor->setEdgeItemEnabled(Monitor::Right, 4, false); + m_ui->monitor->setEdgeItemEnabled(Monitor::Bottom, 4, false); // Search the effect names KServiceTypeTrader* trader = KServiceTypeTrader::self(); @@ -214,10 +214,10 @@ void KWinScreenEdgesConfig::monitorLoadAction(ElectricBorder edge, const QString { KConfigGroup config(m_config, "ElectricBorders"); QString lowerName = config.readEntry(configName, "None").toLower(); - if (lowerName == "dashboard") monitorChangeEdge(edge, int(ElectricActionDashboard)); - else if (lowerName == "showdesktop") monitorChangeEdge(edge, int(ElectricActionShowDesktop)); - else if (lowerName == "lockscreen") monitorChangeEdge(edge, int(ElectricActionLockScreen)); - else if (lowerName == "preventscreenlocking") monitorChangeEdge(edge, int(ElectricActionPreventScreenLocking)); + if (lowerName == "dashboard") monitorChangeEdge(edge, ElectricActionDashboard); + else if (lowerName == "showdesktop") monitorChangeEdge(edge, ElectricActionShowDesktop); + else if (lowerName == "lockscreen") monitorChangeEdge(edge, ElectricActionLockScreen); + else if (lowerName == "preventscreenlocking") monitorChangeEdge(edge, ElectricActionPreventScreenLocking); } void KWinScreenEdgesConfig::monitorLoad() @@ -238,41 +238,41 @@ void KWinScreenEdgesConfig::monitorLoad() KConfigGroup presentWindowsConfig(m_config, "Effect-PresentWindows"); QList list = QList(); // PresentWindows BorderActivateAll - list.append(int(ElectricTopLeft)); + list.append(ElectricTopLeft); list = presentWindowsConfig.readEntry("BorderActivateAll", list); foreach (int i, list) { - monitorChangeEdge(ElectricBorder(i), int(PresentWindowsAll)); + monitorChangeEdge(ElectricBorder(i), PresentWindowsAll); } // PresentWindows BorderActivate list.clear(); - list.append(int(ElectricNone)); + list.append(ElectricNone); list = presentWindowsConfig.readEntry("BorderActivate", list); foreach (int i, list) { - monitorChangeEdge(ElectricBorder(i), int(PresentWindowsCurrent)); + monitorChangeEdge(ElectricBorder(i), PresentWindowsCurrent); } // PresentWindows BorderActivateClass list.clear(); - list.append(int(ElectricNone)); + list.append(ElectricNone); list = presentWindowsConfig.readEntry("BorderActivateClass", list); foreach (int i, list) { - monitorChangeEdge(ElectricBorder(i), int(PresentWindowsClass)); + monitorChangeEdge(ElectricBorder(i), PresentWindowsClass); } // TabBox KConfigGroup tabBoxConfig(m_config, "TabBox"); list.clear(); // TabBox - list.append(int(ElectricNone)); + list.append(ElectricNone); list = tabBoxConfig.readEntry("BorderActivate", list); foreach (int i, list) { - monitorChangeEdge(ElectricBorder(i), int(TabBox)); + monitorChangeEdge(ElectricBorder(i), TabBox); } // Alternative TabBox list.clear(); - list.append(int(ElectricNone)); + list.append(ElectricNone); list = tabBoxConfig.readEntry("BorderAlternativeActivate", list); foreach (int i, list) { - monitorChangeEdge(ElectricBorder(i), int(TabBoxAlternative)); + monitorChangeEdge(ElectricBorder(i), TabBoxAlternative); } } @@ -291,10 +291,10 @@ void KWinScreenEdgesConfig::monitorSaveAction(int edge, const QString& configNam else // Anything else config.writeEntry(configName, "None"); - if ((edge == int(Monitor::TopRight)) || - (edge == int(Monitor::BottomRight)) || - (edge == int(Monitor::BottomLeft)) || - (edge == int(Monitor::TopLeft))) { + if ((edge == Monitor::TopRight) || + (edge == Monitor::BottomRight) || + (edge == Monitor::BottomLeft) || + (edge == Monitor::TopLeft)) { KConfig scrnConfig("kscreensaverrc"); KConfigGroup scrnGroup = scrnConfig.group("ScreenSaver"); scrnGroup.writeEntry("Action" + configName, (item == 4) ? 2 /* Prevent Screen Locking */ : 0 /* None */); @@ -305,42 +305,42 @@ void KWinScreenEdgesConfig::monitorSaveAction(int edge, const QString& configNam void KWinScreenEdgesConfig::monitorSave() { // Save ElectricBorderActions - monitorSaveAction(int(Monitor::Top), "Top"); - monitorSaveAction(int(Monitor::TopRight), "TopRight"); - monitorSaveAction(int(Monitor::Right), "Right"); - monitorSaveAction(int(Monitor::BottomRight), "BottomRight"); - monitorSaveAction(int(Monitor::Bottom), "Bottom"); - monitorSaveAction(int(Monitor::BottomLeft), "BottomLeft"); - monitorSaveAction(int(Monitor::Left), "Left"); - monitorSaveAction(int(Monitor::TopLeft), "TopLeft"); + monitorSaveAction(Monitor::Top, "Top"); + monitorSaveAction(Monitor::TopRight, "TopRight"); + monitorSaveAction(Monitor::Right, "Right"); + monitorSaveAction(Monitor::BottomRight, "BottomRight"); + monitorSaveAction(Monitor::Bottom, "Bottom"); + monitorSaveAction(Monitor::BottomLeft, "BottomLeft"); + monitorSaveAction(Monitor::Left, "Left"); + monitorSaveAction(Monitor::TopLeft, "TopLeft"); // Save effect-specific actions: // Present Windows KConfigGroup presentWindowsConfig(m_config, "Effect-PresentWindows"); presentWindowsConfig.writeEntry("BorderActivateAll", - monitorCheckEffectHasEdge(int(PresentWindowsAll))); + monitorCheckEffectHasEdge(PresentWindowsAll)); presentWindowsConfig.writeEntry("BorderActivate", - monitorCheckEffectHasEdge(int(PresentWindowsCurrent))); + monitorCheckEffectHasEdge(PresentWindowsCurrent)); presentWindowsConfig.writeEntry("BorderActivateClass", - monitorCheckEffectHasEdge(int(PresentWindowsClass))); + monitorCheckEffectHasEdge(PresentWindowsClass)); // TabBox KConfigGroup tabBoxConfig(m_config, "TabBox"); tabBoxConfig.writeEntry("BorderActivate", - monitorCheckEffectHasEdge(int(TabBox))); + monitorCheckEffectHasEdge(TabBox)); tabBoxConfig.writeEntry("BorderAlternativeActivate", - monitorCheckEffectHasEdge(int(TabBoxAlternative))); + monitorCheckEffectHasEdge(TabBoxAlternative)); } void KWinScreenEdgesConfig::monitorDefaults() { // Clear all edges for (int i = 0; i < 8; i++) - m_ui->monitor->selectEdgeItem(i, 0); + m_ui->monitor->selectEdgeItem(i, 1); // the index will be deduced to 0 // Present windows = Top-left - m_ui->monitor->selectEdgeItem(int(Monitor::TopLeft), int(PresentWindowsAll)); + m_ui->monitor->selectEdgeItem(Monitor::TopLeft, PresentWindowsAll); } void KWinScreenEdgesConfig::monitorShowEvent() @@ -353,46 +353,46 @@ void KWinScreenEdgesConfig::monitorShowEvent() // Present Windows bool enabled = effectEnabled("presentwindows", config); - monitorItemSetEnabled(int(PresentWindowsCurrent), enabled); - monitorItemSetEnabled(int(PresentWindowsAll), enabled); + monitorItemSetEnabled(PresentWindowsCurrent, enabled); + monitorItemSetEnabled(PresentWindowsAll, enabled); } else { // Compositing disabled - monitorItemSetEnabled(int(PresentWindowsCurrent), false); - monitorItemSetEnabled(int(PresentWindowsAll), false); + monitorItemSetEnabled(PresentWindowsCurrent, false); + monitorItemSetEnabled(PresentWindowsAll, false); } // tabbox, depends on reasonable focus policy. KConfigGroup config2(m_config, "Windows"); QString focusPolicy = config2.readEntry("FocusPolicy", QString()); bool reasonable = focusPolicy != "FocusStrictlyUnderMouse" && focusPolicy != "FocusUnderMouse"; - monitorItemSetEnabled(int(TabBox), reasonable); - monitorItemSetEnabled(int(TabBoxAlternative), reasonable); + monitorItemSetEnabled(TabBox, reasonable); + monitorItemSetEnabled(TabBoxAlternative, reasonable); } void KWinScreenEdgesConfig::monitorChangeEdge(ElectricBorder border, int index) { switch(border) { case ElectricTop: - m_ui->monitor->selectEdgeItem(int(Monitor::Top), index); + m_ui->monitor->selectEdgeItem(Monitor::Top, index); break; case ElectricTopRight: - m_ui->monitor->selectEdgeItem(int(Monitor::TopRight), index); + m_ui->monitor->selectEdgeItem(Monitor::TopRight, index); break; case ElectricRight: - m_ui->monitor->selectEdgeItem(int(Monitor::Right), index); + m_ui->monitor->selectEdgeItem(Monitor::Right, index); break; case ElectricBottomRight: - m_ui->monitor->selectEdgeItem(int(Monitor::BottomRight), index); + m_ui->monitor->selectEdgeItem(Monitor::BottomRight, index); break; case ElectricBottom: - m_ui->monitor->selectEdgeItem(int(Monitor::Bottom), index); + m_ui->monitor->selectEdgeItem(Monitor::Bottom, index); break; case ElectricBottomLeft: - m_ui->monitor->selectEdgeItem(int(Monitor::BottomLeft), index); + m_ui->monitor->selectEdgeItem(Monitor::BottomLeft, index); break; case ElectricLeft: - m_ui->monitor->selectEdgeItem(int(Monitor::Left), index); + m_ui->monitor->selectEdgeItem(Monitor::Left, index); break; case ElectricTopLeft: - m_ui->monitor->selectEdgeItem(int(Monitor::TopLeft), index); + m_ui->monitor->selectEdgeItem(Monitor::TopLeft, index); break; default: // Nothing break; @@ -403,28 +403,28 @@ void KWinScreenEdgesConfig::monitorHideEdge(ElectricBorder border, bool hidden) { switch(border) { case ElectricTop: - m_ui->monitor->setEdgeHidden(int(Monitor::Top), hidden); + m_ui->monitor->setEdgeHidden(Monitor::Top, hidden); break; case ElectricTopRight: - m_ui->monitor->setEdgeHidden(int(Monitor::TopRight), hidden); + m_ui->monitor->setEdgeHidden(Monitor::TopRight, hidden); break; case ElectricRight: - m_ui->monitor->setEdgeHidden(int(Monitor::Right), hidden); + m_ui->monitor->setEdgeHidden(Monitor::Right, hidden); break; case ElectricBottomRight: - m_ui->monitor->setEdgeHidden(int(Monitor::BottomRight), hidden); + m_ui->monitor->setEdgeHidden(Monitor::BottomRight, hidden); break; case ElectricBottom: - m_ui->monitor->setEdgeHidden(int(Monitor::Bottom), hidden); + m_ui->monitor->setEdgeHidden(Monitor::Bottom, hidden); break; case ElectricBottomLeft: - m_ui->monitor->setEdgeHidden(int(Monitor::BottomLeft), hidden); + m_ui->monitor->setEdgeHidden(Monitor::BottomLeft, hidden); break; case ElectricLeft: - m_ui->monitor->setEdgeHidden(int(Monitor::Left), hidden); + m_ui->monitor->setEdgeHidden(Monitor::Left, hidden); break; case ElectricTopLeft: - m_ui->monitor->setEdgeHidden(int(Monitor::TopLeft), hidden); + m_ui->monitor->setEdgeHidden(Monitor::TopLeft, hidden); break; default: // Nothing break; @@ -434,21 +434,21 @@ void KWinScreenEdgesConfig::monitorHideEdge(ElectricBorder border, bool hidden) QList KWinScreenEdgesConfig::monitorCheckEffectHasEdge(int index) const { QList list = QList(); - if (m_ui->monitor->selectedEdgeItem(int(Monitor::Top)) == index) + if (m_ui->monitor->selectedEdgeItem(Monitor::Top) == index) list.append(int(ElectricTop)); - if (m_ui->monitor->selectedEdgeItem(int(Monitor::TopRight)) == index) + if (m_ui->monitor->selectedEdgeItem(Monitor::TopRight) == index) list.append(int(ElectricTopRight)); - if (m_ui->monitor->selectedEdgeItem(int(Monitor::Right)) == index) + if (m_ui->monitor->selectedEdgeItem(Monitor::Right) == index) list.append(int(ElectricRight)); - if (m_ui->monitor->selectedEdgeItem(int(Monitor::BottomRight)) == index) + if (m_ui->monitor->selectedEdgeItem(Monitor::BottomRight) == index) list.append(int(ElectricBottomRight)); - if (m_ui->monitor->selectedEdgeItem(int(Monitor::Bottom)) == index) + if (m_ui->monitor->selectedEdgeItem(Monitor::Bottom) == index) list.append(int(ElectricBottom)); - if (m_ui->monitor->selectedEdgeItem(int(Monitor::BottomLeft)) == index) + if (m_ui->monitor->selectedEdgeItem(Monitor::BottomLeft) == index) list.append(int(ElectricBottomLeft)); - if (m_ui->monitor->selectedEdgeItem(int(Monitor::Left)) == index) + if (m_ui->monitor->selectedEdgeItem(Monitor::Left) == index) list.append(int(ElectricLeft)); - if (m_ui->monitor->selectedEdgeItem(int(Monitor::TopLeft)) == index) + if (m_ui->monitor->selectedEdgeItem(Monitor::TopLeft) == index) list.append(int(ElectricTopLeft)); if (list.isEmpty()) diff --git a/kwin/kcmkwin/kwinscreenedges/main.h b/kwin/kcmkwin/kwinscreenedges/main.h index a4c753e2..2ded43c1 100644 --- a/kwin/kcmkwin/kwinscreenedges/main.h +++ b/kwin/kcmkwin/kwinscreenedges/main.h @@ -64,11 +64,11 @@ private: enum EffectActions { PresentWindowsAll = ELECTRIC_ACTION_COUNT, // Start at the end of built in actions - PresentWindowsCurrent, - PresentWindowsClass, - DesktopGrid, - TabBox, - TabBoxAlternative + PresentWindowsCurrent = 6, + PresentWindowsClass = 7, + DesktopGrid = 8, + TabBox = 9, + TabBoxAlternative = 10 }; bool effectEnabled(const QString& effect, const KConfigGroup& cfg) const; diff --git a/kwin/kcmkwin/kwinscreenedges/monitor.cpp b/kwin/kcmkwin/kwinscreenedges/monitor.cpp index 74bcbfd7..f567a129 100644 --- a/kwin/kcmkwin/kwinscreenedges/monitor.cpp +++ b/kwin/kcmkwin/kwinscreenedges/monitor.cpp @@ -143,12 +143,12 @@ void Monitor::addEdgeItem(int edge, const QString& item) void Monitor::setEdgeItemEnabled(int edge, int index, bool enabled) { - popup_actions[ edge ][ index ]->setEnabled(enabled); + popup_actions[ edge ][ index - 1 ]->setEnabled(enabled); } bool Monitor::edgeItemEnabled(int edge, int index) const { - return popup_actions[ edge ][ index ]->isEnabled(); + return popup_actions[ edge ][ index - 1 ]->isEnabled(); } void Monitor::selectEdgeItem(int edge, int index) diff --git a/kwin/kcmkwin/kwinscreenedges/monitor.h b/kwin/kcmkwin/kwinscreenedges/monitor.h index 68aa87fa..d174453e 100644 --- a/kwin/kcmkwin/kwinscreenedges/monitor.h +++ b/kwin/kcmkwin/kwinscreenedges/monitor.h @@ -59,14 +59,14 @@ public: int selectedEdgeItem(int edge) const; enum Edges { - Left, - Right, - Top, - Bottom, - TopLeft, - TopRight, - BottomLeft, - BottomRight + Left = 0, + Right = 1, + Top = 2, + Bottom = 3, + TopLeft = 4, + TopRight = 5, + BottomLeft = 6, + BottomRight = 7 }; signals: void changed(); diff --git a/kwin/libkwineffects/kwinglobals.h b/kwin/libkwineffects/kwinglobals.h index e229b0d6..6c7f6766 100644 --- a/kwin/libkwineffects/kwinglobals.h +++ b/kwin/libkwineffects/kwinglobals.h @@ -89,12 +89,12 @@ enum ElectricBorder { // such as "only when moving windows" desktop switching that the current global action // system doesn't support. enum ElectricBorderAction { - ElectricActionNone, // No special action, not set, desktop switch or an effect - ElectricActionDashboard, // Launch the Plasma dashboard - ElectricActionShowDesktop, // Show desktop or restore - ElectricActionLockScreen, // Lock screen - ElectricActionPreventScreenLocking, - ELECTRIC_ACTION_COUNT + ElectricActionNone = 0, // No special action, not set, desktop switch or an effect + ElectricActionDashboard = 1, // Launch the Plasma dashboard + ElectricActionShowDesktop = 2, // Show desktop or restore + ElectricActionLockScreen = 3, // Lock screen + ElectricActionPreventScreenLocking = 4, + ELECTRIC_ACTION_COUNT = 5 }; // DesktopMode and WindowsMode are based on the order in which the desktop -- 2.11.0