Window Switcher layouts follow Plasma Package structure

A new service type is introduced which is used by the KCM to find
all available window switcher layouts. This makes it finally possible
to have 3rd party window switchers.

Also the tabbox finds the packaged QML file through the service
definitions.

Desktop switcher is not yet in packaged version (UI to configure
is missing).

REVIEW: 103951
This commit is contained in:
Martin Gräßlin 2012-02-12 15:15:54 +01:00
parent 8983a373f1
commit 9297a8a9b2
20 changed files with 204 additions and 37 deletions

View file

@ -72,6 +72,7 @@ endif( KWIN_BUILD_DECORATIONS )
add_subdirectory( data )
add_subdirectory( effects )
add_subdirectory( tabbox )
########### next target ###############
@ -231,17 +232,5 @@ install(TARGETS kwinnvidiahack ${INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_
install( FILES kwin.kcfg DESTINATION ${KCFG_INSTALL_DIR} )
install( FILES kwin.notifyrc DESTINATION ${DATA_INSTALL_DIR}/kwin )
install( FILES org.kde.KWin.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} )
install( FILES
tabbox/qml/informative.qml
tabbox/qml/big_icons.qml
tabbox/qml/compact.qml
tabbox/qml/desktop.qml
tabbox/qml/small_icons.qml
tabbox/qml/tabbox.qml
tabbox/qml/text.qml
tabbox/qml/thumbnails.qml
tabbox/qml/IconTabBox.qml
tabbox/qml/window_strip.qml
DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox )
kde4_install_icons( ${ICON_INSTALL_DIR} )

View file

@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QtDeclarative/QDeclarativeEngine>
#include <QtGui/QGraphicsObject>
#include <kdeclarative.h>
#include <KDE/KConfigGroup>
#include <KDE/KDesktopFile>
#include <KDE/KGlobal>
#include <KDE/KIcon>
@ -32,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KDE/KIconLoader>
#include <KDE/KLocalizedString>
#include <KDE/KService>
#include <KDE/KServiceTypeTrader>
#include <KDE/KStandardDirs>
namespace KWin
@ -208,23 +210,20 @@ LayoutModel::~LayoutModel()
void LayoutModel::init()
{
QStringList layouts;
layouts << "thumbnails" << "informative" << "compact" << "text" << "big_icons" << "small_icons";
QStringList descriptions;
descriptions << i18nc("Name for a window switcher layout showing live window thumbnails", "Thumbnails");
descriptions << i18nc("Name for a window switcher layout showing icon, name and desktop", "Informative");
descriptions << i18nc("Name for a window switcher layout showing only icon and name", "Compact");
descriptions << i18nc("Name for a window switcher layout showing only the name", "Text");
descriptions << i18nc("Name for a window switcher layout showing large icons", "Large Icons");
descriptions << i18nc("Name for a window switcher layout showing small icons", "Small Icons");
for (int i=0; i<layouts.size(); ++i) {
const QString path = KStandardDirs::locate("data", "kwin/tabbox/" + layouts.at(i) + ".qml");
if (!path.isNull()) {
m_nameList << descriptions.at(i);
m_pathList << path;
m_layoutList << layouts.at(i);
KService::List offers = KServiceTypeTrader::self()->query("KWin/WindowSwitcher");
foreach (KService::Ptr service, offers) {
const QString pluginName = service->property("X-KDE-PluginInfo-Name").toString();
if (service->property("X-Plasma-API").toString() != "declarativeappletscript") {
continue;
}
const QString scriptName = service->property("X-Plasma-MainScript").toString();
const QString scriptFile = KStandardDirs::locate("data", "kwin/tabbox/" + pluginName + "/contents/" + scriptName);
if (scriptFile.isNull()) {
continue;
}
m_nameList << service->name();
m_pathList << scriptFile;
m_layoutList << pluginName;
}
}
@ -254,11 +253,12 @@ int LayoutModel::rowCount (const QModelIndex& parent) const
QModelIndex LayoutModel::indexForLayoutName(const QString &name) const
{
// fallback for default
QString normalizedName = name.toLower().replace(' ', '_');
if (name == "Default" || name.isEmpty()) {
return index(0);
normalizedName = "informative";
}
for (int i=0; i<m_layoutList.size(); ++i) {
if (name.toLower().replace(' ', '_') == m_layoutList.at(i)) {
if (normalizedName == m_layoutList.at(i)) {
return index(i);
}
}

4
tabbox/CMakeLists.txt Normal file
View file

@ -0,0 +1,4 @@
add_subdirectory( qml )
# Install the KWin/WindowSwitcher service type
install( FILES kwinwindowswitcher.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} )

View file

@ -33,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KDE/KDebug>
#include <KDE/KIconEffect>
#include <KDE/KIconLoader>
#include <KDE/KServiceTypeTrader>
#include <KDE/KStandardDirs>
#include <KDE/Plasma/FrameSvg>
#include <KDE/Plasma/Theme>
@ -284,16 +285,35 @@ void DeclarativeView::updateQmlSource(bool force)
if (!force && tabBox->config().layoutName() == m_currentLayout) {
return;
}
m_currentLayout = tabBox->config().layoutName();
QString file = KStandardDirs::locate("data", "kwin/tabbox/" + m_currentLayout.toLower().replace(' ', '_') + ".qml");
if (m_mode == TabBoxConfig::DesktopTabBox) {
file = KStandardDirs::locate("data", "kwin/tabbox/desktop.qml");
m_currentLayout = tabBox->config().layoutName();
const QString file = KStandardDirs::locate("data", "kwin/tabbox/desktop.qml");
rootObject()->setProperty("source", QUrl(file));
return;
}
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(tabBox->config().layoutName());
KService::List offers = KServiceTypeTrader::self()->query("KWin/WindowSwitcher", constraint);
if (offers.isEmpty()) {
// load default
constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg("informative");
offers = KServiceTypeTrader::self()->query("KWin/WindowSwitcher", constraint);
if (offers.isEmpty()) {
kDebug(1212) << "could not find default window switcher layout";
return;
}
}
m_currentLayout = tabBox->config().layoutName();
KService::Ptr service = offers.first();
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", "kwin/tabbox/" + pluginName + "/contents/" + scriptName);
if (file.isNull()) {
// fallback to default
if (m_mode == TabBoxConfig::ClientTabBox) {
file = KStandardDirs::locate("data", "kwin/tabbox/informative.qml");
}
kDebug(1212) << "Could not find QML file for window switcher";
return;
}
rootObject()->setProperty("source", QUrl(file));
}

View file

@ -0,0 +1,11 @@
[Desktop Entry]
Type=ServiceType
X-KDE-ServiceType=KWin/WindowSwitcher
Comment=KWin Window Switcher Layout
[PropertyDef::X-Plasma-API]
Type=QString
[PropertyDef::X-Plasma-MainScript]
Type=QString

24
tabbox/qml/CMakeLists.txt Normal file
View file

@ -0,0 +1,24 @@
install( FILES tabbox.qml DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox )
install( FILES desktop.qml DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox )
# packages
install( DIRECTORY clients/big_icons DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox )
install( DIRECTORY clients/compact DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox )
install( DIRECTORY clients/informative DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox )
install( DIRECTORY clients/small_icons DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox )
install( DIRECTORY clients/text DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox )
install( DIRECTORY clients/thumbnails DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox )
install( DIRECTORY clients/window_strip DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox )
# service files
install( FILES clients/big_icons/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin RENAME kwin4_window_switcher_big_icons.desktop )
install( FILES clients/compact/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin RENAME kwin4_window_switcher_compact.desktop )
install( FILES clients/informative/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin RENAME kwin4_window_switcher_informative.desktop )
install( FILES clients/small_icons/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin RENAME kwin4_window_switcher_small_icons.desktop )
install( FILES clients/text/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin RENAME kwin4_window_switcher_text.desktop )
install( FILES clients/thumbnails/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin RENAME kwin4_window_switcher_thumbnails.desktop )
install( FILES clients/window_strip/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin RENAME kwin4_window_switcher_window_strip.desktop )
# install additional icon tabbox into those that need it
install (FILES IconTabBox.qml DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox/big_icons/contents/ui)
install (FILES IconTabBox.qml DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox/small_icons/contents/ui)

View file

@ -0,0 +1,17 @@
[Desktop Entry]
Name=Large Icons
Comment=A window switcher layout using large icons to represent the window
Icon=preferences-system-windows-switcher-big-icons
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=big_icons
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-ServiceTypes=KWin/WindowSwitcher
Type=Service

View file

@ -0,0 +1,17 @@
[Desktop Entry]
Name=Compact
Comment=A compact window switcher layout
Icon=preferences-system-windows-switcher-compact
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=compact
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-ServiceTypes=KWin/WindowSwitcher
Type=Service

View file

@ -0,0 +1,17 @@
[Desktop Entry]
Name=Informative
Comment=An informative window switcher layout including desktop name
Icon=preferences-system-windows-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/WindowSwitcher
Type=Service

View file

@ -0,0 +1,17 @@
[Desktop Entry]
Name=Small Icons
Comment=A window switcher layout using small icons to represent the window
Icon=preferences-system-windows-switcher-small-icons
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=small_icons
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-ServiceTypes=KWin/WindowSwitcher
Type=Service

View file

@ -0,0 +1,17 @@
[Desktop Entry]
Name=Text Icons
Comment=A window switcher layout only showing window captions
Icon=preferences-system-windows-switcher-text
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=text
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-ServiceTypes=KWin/WindowSwitcher
Type=Service

View file

@ -0,0 +1,17 @@
[Desktop Entry]
Name=Thumbnails
Comment=A window switcher layout using live thumbnails
Icon=preferences-system-windows-switcher-thumbnails
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=thumbnails
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-ServiceTypes=KWin/WindowSwitcher
Type=Service

View file

@ -0,0 +1,17 @@
[Desktop Entry]
Name=Window Strip
Comment=Window switcher layout for Plasma Active
Icon=preferences-system-windows-switcher-window-strip
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=window_strip
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-ServiceTypes=KWin/WindowSwitcher
Type=Service