From 6073cd5f6bbd17e9dd8ae5e28de57b1a74d076e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 20 Mar 2012 15:04:50 +0100 Subject: [PATCH] Present Windows like Window Switcher layout This layout is intended to replace the TabBox mode in Present Windows effect. The advantages of a layout over the effect are: * works without compositing * supports multi-screen in a better way (windows don't move) * is an overlay on top of the windows instead of reusing the windows * is not a hack inside the actual effect * visually consistent with other layouts --- tabbox/qml/CMakeLists.txt | 2 + .../present_windows/contents/ui/main.qml | 172 ++++++++++++++++++ .../clients/present_windows/metadata.desktop | 17 ++ 3 files changed, 191 insertions(+) create mode 100644 tabbox/qml/clients/present_windows/contents/ui/main.qml create mode 100644 tabbox/qml/clients/present_windows/metadata.desktop diff --git a/tabbox/qml/CMakeLists.txt b/tabbox/qml/CMakeLists.txt index d6771e068b..c616b863b3 100644 --- a/tabbox/qml/CMakeLists.txt +++ b/tabbox/qml/CMakeLists.txt @@ -5,6 +5,7 @@ install( FILES desktop.qml DESTINATION ${DATA_INSTALL_DIR}/kwin/tabbox ) 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/present_windows 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 ) @@ -14,6 +15,7 @@ install( DIRECTORY clients/window_strip DESTINATION ${DATA_INSTALL_DIR}/kwin/tab 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/present_windows/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin RENAME kwin4_window_switcher_present_windows.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 ) diff --git a/tabbox/qml/clients/present_windows/contents/ui/main.qml b/tabbox/qml/clients/present_windows/contents/ui/main.qml new file mode 100644 index 0000000000..fb38b525f1 --- /dev/null +++ b/tabbox/qml/clients/present_windows/contents/ui/main.qml @@ -0,0 +1,172 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2012 Martin Gräßlin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +import QtQuick 1.1 +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.qtextracomponents 0.1 +import org.kde.kwin 0.1 as KWin + +Item { + id: presentWindowsTabBox + property int screenWidth : 1 + property int screenHeight : 1 + property int optimalWidth: 0.9*screenWidth + property int optimalHeight: 0.9*screenHeight + property int imagePathPrefix: (new Date()).getTime() + property int standardMargin: 2 + width: optimalWidth + height: optimalHeight + + function setModel(model) { + thumbnailListView.model = model; + thumbnailListView.imageId++; + } + + function modelChanged() { + thumbnailListView.imageId++; + } + + PlasmaCore.FrameSvgItem { + id: background + anchors.fill: parent + imagePath: "dialogs/background" + } + // just to get the margin sizes + PlasmaCore.FrameSvgItem { + id: hoverItem + imagePath: "widgets/viewitem" + prefix: "hover" + visible: false + } + + PlasmaCore.Theme { + id: theme + } + + GridView { + signal currentIndexChanged(int index) + // used for image provider URL to trick Qt into reloading icons when the model changes + property int imageId: 0 + property int rows: Math.round(Math.sqrt(count)) + property int columns: (rows*rows < count) ? rows + 1 : rows + id: thumbnailListView + objectName: "listView" + cellWidth: Math.floor(width / columns) + cellHeight: Math.floor(height / rows) + anchors { + fill: parent + leftMargin: background.margins.left + rightMargin: background.margins.right + topMargin: background.margins.top + bottomMargin: background.margins.bottom + } + delegate: Item { + width: thumbnailListView.cellWidth + height: thumbnailListView.cellHeight + KWin.ThumbnailItem { + id: thumbnailItem + wId: windowId + anchors { + top: parent.top + left: parent.left + right: parent.right + bottom: captionItem.top + leftMargin: hoverItem.margins.left + rightMargin: hoverItem.margins.right + topMargin: hoverItem.margins.top + bottomMargin: standardMargin + } + } + Item { + id: captionItem + height: childrenRect.height + anchors { + left: parent.left + right: parent.right + bottom: parent.bottom + leftMargin: hoverItem.margins.left + standardMargin + bottomMargin: hoverItem.margins.bottom + rightMargin: hoverItem.margins.right + } + Image { + id: iconItem + source: "image://client/" + index + "/" + presentWindowsTabBox.imagePathPrefix + "-" + thumbnailListView.imageId + width: 32 + height: 32 + sourceSize { + width: 32 + height: 32 + } + anchors { + bottom: parent.bottom + right: textItem.left + } + } + Item { + id: textItem + property int maxWidth: parent.width - iconItem.width - parent.anchors.leftMargin - parent.anchors.rightMargin - anchors.leftMargin - standardMargin * 2 + width: (textElementSelected.implicitWidth >= maxWidth) ? maxWidth : textElementSelected.implicitWidth + anchors { + top: parent.top + bottom: parent.bottom + horizontalCenter: parent.horizontalCenter + leftMargin: standardMargin + } + Text { + id: textElementSelected + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: caption + font.italic: minimized + font.bold: true + visible: index == thumbnailListView.currentIndex + color: theme.textColor + elide: Text.ElideMiddle + anchors.fill: parent + } + Text { + id: textElementNormal + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: caption + font.italic: minimized + visible: index != thumbnailListView.currentIndex + color: theme.textColor + elide: Text.ElideMiddle + anchors.fill: parent + } + } + } + MouseArea { + anchors.fill: parent + onClicked: { + thumbnailListView.currentIndex = index; + thumbnailListView.currentIndexChanged(thumbnailListView.currentIndex); + } + } + } + highlight: PlasmaCore.FrameSvgItem { + id: highlightItem + imagePath: "widgets/viewitem" + prefix: "hover" + width: thumbnailListView.cellWidth + height: thumbnailListView.cellHeight + } + } +} diff --git a/tabbox/qml/clients/present_windows/metadata.desktop b/tabbox/qml/clients/present_windows/metadata.desktop new file mode 100644 index 0000000000..2742756420 --- /dev/null +++ b/tabbox/qml/clients/present_windows/metadata.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Name=Present Windows +Comment=A Window Switcher layout showing all windows as thumbnails in a grid +Icon=preferences-system-windows-switcher-present-windows + +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=present_windows +X-KDE-PluginInfo-Version=1.0 + +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-ServiceTypes=KWin/WindowSwitcher +Type=Service