From 7c489e43d9bfcdba6b4d6f4f710ef34323968850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 15 Apr 2013 13:03:13 +0200 Subject: [PATCH] Plasma Package support for desktop switcher layouts The existing desktop switcher becomes the first available layout called "informative". For both variants of desktop switchers a new config key is introduced to define the desktop switcher layout. Desktop layouts are installed into a different directory than window switcher layout and use a different service type. For the moment it's basically a hidden config option as there are no further layouts yet. BUG: 296068 FIXED-IN: 4.11 REVIEW: 110021 --- tabbox/CMakeLists.txt | 1 + tabbox/declarative.cpp | 65 ++++++++++++++----- tabbox/declarative.h | 5 ++ tabbox/kwindesktopswitcher.desktop | 14 ++++ tabbox/qml/CMakeLists.txt | 7 +- .../informative/contents/ui/main.qml} | 0 .../qml/desktops/informative/metadata.desktop | 17 +++++ tabbox/tabbox.cpp | 3 + 8 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 tabbox/kwindesktopswitcher.desktop rename tabbox/qml/{desktop.qml => desktops/informative/contents/ui/main.qml} (100%) create mode 100644 tabbox/qml/desktops/informative/metadata.desktop diff --git a/tabbox/CMakeLists.txt b/tabbox/CMakeLists.txt index 2ef58101fa..01cb74d361 100644 --- a/tabbox/CMakeLists.txt +++ b/tabbox/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory( tests ) # Install the KWin/WindowSwitcher service type install( FILES kwinwindowswitcher.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) +install( FILES kwindesktopswitcher.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) diff --git a/tabbox/declarative.cpp b/tabbox/declarative.cpp index b6ae22fea9..fb734347f9 100644 --- a/tabbox/declarative.cpp +++ b/tabbox/declarative.cpp @@ -351,12 +351,26 @@ void DeclarativeView::updateQmlSource(bool force) if (!force && tabBox->config().layoutName() == m_currentLayout) { return; } - if (m_mode == TabBoxConfig::DesktopTabBox) { - m_currentLayout = tabBox->config().layoutName(); - const QString file = KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + QLatin1String("/tabbox/desktop.qml")); - rootObject()->setProperty("source", QUrl(file)); + const bool desktopMode = (m_mode == TabBoxConfig::DesktopTabBox); + m_currentLayout = tabBox->config().layoutName(); + KService::Ptr service = desktopMode ? findDesktopSwitcher() : findWindowSwitcher(); + if (service.isNull()) { return; } + if (service->property("X-Plasma-API").toString() != "declarativeappletscript") { + kDebug(1212) << "Window Switcher Layout is no declarativeappletscript"; + return; + } + const QString file = desktopMode ? findDesktopSwitcherScriptFile(service) : findWindowSwitcherScriptFile(service); + if (file.isNull()) { + kDebug(1212) << "Could not find QML file for window switcher"; + return; + } + rootObject()->setProperty("source", QUrl(file)); +} + +KService::Ptr DeclarativeView::findWindowSwitcher() +{ QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(tabBox->config().layoutName()); KService::List offers = KServiceTypeTrader::self()->query("KWin/WindowSwitcher", constraint); if (offers.isEmpty()) { @@ -365,23 +379,40 @@ void DeclarativeView::updateQmlSource(bool force) offers = KServiceTypeTrader::self()->query("KWin/WindowSwitcher", constraint); if (offers.isEmpty()) { kDebug(1212) << "could not find default window switcher layout"; - return; + return KService::Ptr(); } } - m_currentLayout = tabBox->config().layoutName(); - KService::Ptr service = offers.first(); + return offers.first(); +} + +KService::Ptr DeclarativeView::findDesktopSwitcher() +{ + QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(tabBox->config().layoutName()); + KService::List offers = KServiceTypeTrader::self()->query("KWin/DesktopSwitcher", constraint); + if (offers.isEmpty()) { + // load default + constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg("informative"); + offers = KServiceTypeTrader::self()->query("KWin/DesktopSwitcher", constraint); + if (offers.isEmpty()) { + kDebug(1212) << "could not find default desktop switcher layout"; + return KService::Ptr(); + } + } + return offers.first(); +} + +QString DeclarativeView::findWindowSwitcherScriptFile(KService::Ptr service) +{ const QString pluginName = service->property("X-KDE-PluginInfo-Name").toString(); - if (service->property("X-Plasma-API").toString() != "declarativeappletscript") { - kDebug(1212) << "Window Switcher Layout is no declarativeappletscript"; - return; - } const QString scriptName = service->property("X-Plasma-MainScript").toString(); - const QString file = KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + "/tabbox/" + pluginName + "/contents/" + scriptName); - if (file.isNull()) { - kDebug(1212) << "Could not find QML file for window switcher"; - return; - } - rootObject()->setProperty("source", QUrl(file)); + return KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + "/tabbox/" + pluginName + "/contents/" + scriptName); +} + +QString DeclarativeView::findDesktopSwitcherScriptFile(KService::Ptr service) +{ + const QString pluginName = service->property("X-KDE-PluginInfo-Name").toString(); + const QString scriptName = service->property("X-Plasma-MainScript").toString(); + return KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + "/desktoptabbox/" + pluginName + "/contents/" + scriptName); } void DeclarativeView::slotEmbeddedChanged(bool enabled) diff --git a/tabbox/declarative.h b/tabbox/declarative.h index e36e67bf72..3ebb5284b2 100644 --- a/tabbox/declarative.h +++ b/tabbox/declarative.h @@ -22,6 +22,7 @@ along with this program. If not, see . // includes #include #include +#include #include "tabboxconfig.h" // forward declaration @@ -71,6 +72,10 @@ private Q_SLOTS: void currentIndexChanged(int row); void slotWindowChanged(WId wId, unsigned int properties); private: + KService::Ptr findWindowSwitcher(); + KService::Ptr findDesktopSwitcher(); + QString findWindowSwitcherScriptFile(KService::Ptr service); + QString findDesktopSwitcherScriptFile(KService::Ptr service); QAbstractItemModel *m_model; TabBoxConfig::TabBoxMode m_mode; QRect m_currentScreenGeometry; diff --git a/tabbox/kwindesktopswitcher.desktop b/tabbox/kwindesktopswitcher.desktop new file mode 100644 index 0000000000..0da7de640f --- /dev/null +++ b/tabbox/kwindesktopswitcher.desktop @@ -0,0 +1,14 @@ +[Desktop Entry] +Type=ServiceType +X-KDE-ServiceType=KWin/DesktopSwitcher + +Comment=KWin Desktop Switcher Layout + +[PropertyDef::X-Plasma-API] +Type=QString + +[PropertyDef::X-Plasma-MainScript] +Type=QString + +[PropertyDef::X-KWin-Exclude-Listing] +Type=bool diff --git a/tabbox/qml/CMakeLists.txt b/tabbox/qml/CMakeLists.txt index 7a5a5e0807..816ce6a588 100644 --- a/tabbox/qml/CMakeLists.txt +++ b/tabbox/qml/CMakeLists.txt @@ -1,5 +1,4 @@ install( FILES tabbox.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) -install( FILES desktop.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) # packages install( DIRECTORY clients/big_icons DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) @@ -11,6 +10,8 @@ install( DIRECTORY clients/text DESTINATION ${DATA_INSTALL_DIR}/${KWIN_N install( DIRECTORY clients/thumbnails DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) install( DIRECTORY clients/window_strip DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox ) +install( DIRECTORY desktops/informative DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/desktoptabbox ) + # service files install( FILES clients/big_icons/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_big_icons.desktop ) install( FILES clients/compact/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_compact.desktop ) @@ -21,6 +22,8 @@ install( FILES clients/text/metadata.desktop DESTINATION ${SERVICES_INST install( FILES clients/thumbnails/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_thumbnails.desktop ) install( FILES clients/window_strip/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_window_switcher_window_strip.desktop ) +install( FILES desktops/informative/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME} RENAME kwin4_desktop_switcher_informative.desktop ) + install (FILES IconTabBox.qml ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/big_icons/contents/ui) install (FILES IconTabBox.qml ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/small_icons/contents/ui) install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/) @@ -29,3 +32,5 @@ install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/ install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/present_windows/contents/ui) install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/thumbnails/contents/ui) install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/text/contents/ui) + +install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/desktoptabbox/informative/contents/ui) diff --git a/tabbox/qml/desktop.qml b/tabbox/qml/desktops/informative/contents/ui/main.qml similarity index 100% rename from tabbox/qml/desktop.qml rename to tabbox/qml/desktops/informative/contents/ui/main.qml diff --git a/tabbox/qml/desktops/informative/metadata.desktop b/tabbox/qml/desktops/informative/metadata.desktop new file mode 100644 index 0000000000..1851d31615 --- /dev/null +++ b/tabbox/qml/desktops/informative/metadata.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Name=Informative +Comment=An informative desktop switcher layout +Icon=preferences-system-desktop-switcher-informative + +X-Plasma-API=declarativeappletscript +X-Plasma-MainScript=ui/main.qml + +X-KDE-PluginInfo-Author=Martin Gräßlin +X-KDE-PluginInfo-Email=mgraesslin@kde.org +X-KDE-PluginInfo-Name=informative +X-KDE-PluginInfo-Version=1.0 + +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-ServiceTypes=KWin/DesktopSwitcher +Type=Service diff --git a/tabbox/tabbox.cpp b/tabbox/tabbox.cpp index ee44fb8af0..be61185ae7 100644 --- a/tabbox/tabbox.cpp +++ b/tabbox/tabbox.cpp @@ -729,6 +729,9 @@ void TabBox::reconfigure() m_delayShow = config.readEntry("ShowDelay", true); m_delayShowTime = config.readEntry("DelayTime", 90); + m_desktopConfig.setLayoutName(config.readEntry("DesktopLayout", "informative")); + m_desktopListConfig.setLayoutName(config.readEntry("DesktopListLayout", "informative")); + QList *borders = &m_borderActivate; QString borderConfig = "BorderActivate"; for (int i = 0; i < 2; ++i) {