Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* Copyright 2016 Eike Hein <hein@kde.org>
*
* 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 <http: //www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.taskmanager 0.1 as TaskManager
// import org.kde.kwindowsystem 1.0 as KWindowSystem
Item {
id: root
Layout.preferredHeight: 600 * units.devicePixelRatio
Layout.minimumWidth: units.gridUnit * 12
Layout.minimumHeight: units.gridUnit * 12
Plasmoid.switchWidth: units.gridUnit * 11
Plasmoid.switchHeight: units.gridUnit * 11
property int itemHeight: Math.ceil((Math.max(theme.mSize(theme.defaultFont).height, units.iconSizes.small)
+ Math.max(highlightItemSvg.margins.top + highlightItemSvg.margins.bottom,
listItemSvg.margins.top + listItemSvg.margins.bottom)) / 2) * 2
TaskManager.TasksModel {
id: tasksModel
virtualDesktop: virtualDesktopInfo.currentDesktop
screenGeometry: plasmoid.screenGeometry
activity: activityInfo.currentActivity
filterByVirtualDesktop: true
filterByScreen: true
filterByActivity: true
filterNotMinimized: true
sortMode: TaskManager.TasksModel.SortVirtualDesktop
groupMode: TaskManager.TasksModel.GroupDisabled
}
TaskManager.VirtualDesktopInfo {
id: virtualDesktopInfo
}
TaskManager.ActivityInfo {
id: activityInfo
}
// KWindowSystem.KWindowSystem {
// id: windowSystem
// }
PlasmaCore.FrameSvgItem {
id : highlightItemSvg
visible: false
imagePath: "widgets/viewitem"
prefix: "hover"
}
PlasmaCore.FrameSvgItem {
id : listItemSvg
visible: false
imagePath: "widgets/viewitem"
prefix: "normal"
}
Connections {
target: plasmoid
onExpandedChanged: {
if (!expanded) {
windowListView.currentIndex = 0;
}
}
}
PlasmaExtras.ScrollArea {
anchors.fill: parent
focus: true
onFocusChanged: {
if (!focus) {
windowListView.currentIndex = -1;
}
}
ListView {
id: windowListView
property bool overflowing: (visibleArea.heightRatio < 1.0)
property var pinTopItem: null
property var pinBottomItem: null
focus: true
model: tasksModel
boundsBehavior: Flickable.StopAtBounds
snapMode: ListView.SnapToItem
spacing: 0
keyNavigationWraps: true
highlight: PlasmaComponents.Highlight {}
highlightMoveDuration: 0
onOverflowingChanged: {
if (!overflowing) {
pinTopItem = null;
pinBottomItem = null;
}
}
onContentYChanged: {
pinTopItem = contentItem.childAt(0, contentY);
pinBottomItem = contentItem.childAt(0, contentY + windowPin.height);
}
section.property: virtualDesktopInfo.numberOfDesktops ? "VirtualDesktop" : undefined
section.criteria: ViewSection.FullString
section.delegate: PlasmaComponents.Label {
height: root.itemHeight
width: root.width
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
textFormat: Text.PlainText
wrapMode: Text.NoWrap
elide: Text.ElideRight
text: {
if (section > 0) {
return virtualDesktopInfo.desktopNames[section - 1];
}
return i18n("On all desktops");
}
}
delegate: MouseArea {
id: item
// visible: model.IsMinimized
// implicitHeight: visible ? layout.implicitHeight : 0
property rect geometry: model.Geometry
property int windowId: model.LegacyWinIdList[0]
property string visibleName: model.display
property bool minimized: (model.IsMinimized === true)
property bool isWindowMinimized: {
console.log('caption', item.visibleName)
console.log('\t isMinimized', model.IsMinimized)
console.log('\t item.minimized', item.minimized)
return item.minimized
}
width: windowListView.overflowing ? ListView.view.width - units.smallSpacing : ListView.view.width
implicitHeight: layout.implicitHeight
property bool underPin: (item == windowListView.pinTopItem || item == windowListView.pinBottomItem)
Accessible.role: Accessible.MenuItem
Accessible.name: label.text
hoverEnabled: true
onClicked: tasksModel.requestActivate(tasksModel.makeModelIndex(index))
onContainsMouseChanged: {
if (containsMouse) {
windowListView.focus = true;
windowListView.currentIndex = index;
}
}
ColumnLayout {
id: layout
anchors.left: parent.left
anchors.leftMargin: highlightItemSvg.margins.left
anchors.right: parent.right
anchors.rightMargin: highlightItemSvg.margins.right
RowLayout {
spacing: units.smallSpacing * 2
LayoutMirroring.enabled: (Qt.application.layoutDirection == Qt.RightToLeft)
PlasmaCore.IconItem {
id: icon
Layout.preferredWidth: label.implicitHeight
Layout.preferredHeight: label.implicitHeight
Layout.alignment: Qt.AlignVCenter
usesPlasmaTheme: false
source: model.decoration
}
PlasmaComponents.Label {
id: label
Layout.fillWidth: true
Layout.fillHeight: true
verticalAlignment: Text.AlignVCenter
textFormat: Text.PlainText
wrapMode: Text.NoWrap
elide: Text.ElideRight
text: model.display
}
}
PlasmaCore.WindowThumbnail {
Layout.fillWidth: true
Layout.preferredHeight: Math.ceil(200 * units.devicePixelRatio)
readonly property var windows: model.LegacyWinIdList
readonly property int flatIndex: 0
winId: windows && windows[flatIndex] != undefined ? windows[flatIndex] : 0
// Component.onCompleted: logThumb()
onWinIdChanged: logThumb()
function logThumb() {
console.log('caption', model.display)
console.log('\t windows', windows)
console.log('\t winId', winId)
console.log('\t IsMinimized', model.IsMinimized)
}
}
}
Keys.onTabPressed: windowPin.focus = true
Keys.onBacktabPressed: windowPin.focus = true
Keys.onPressed: {
if (event.key == Qt.Key_Enter || event.key == Qt.Key_Return) {
event.accepted = true;
tasksModel.requestActivate(tasksModel.makeModelIndex(index))
if (!windowPin.checked) {
plasmoid.expanded = false;
}
}
}
}
}
}
PlasmaComponents.ToolButton {
id: windowPin
anchors.top: parent.top
anchors.right: parent.right
anchors.rightMargin: windowListView.overflowing ? units.gridUnit : 0
width: Math.round(units.gridUnit * 1.25)
height: width
iconSource: "window-pin"
visible: plasmoid.compactRepresentationItem && plasmoid.compactRepresentationItem.visible
checkable: true
onCheckedChanged: plasmoid.hideOnWindowDeactivate = !checked
Keys.onTabPressed: {
if (windowListView.count) {
windowListView.currentIndex = 0;
windowListView.forceActiveFocus();
}
}
Keys.onBacktabPressed: cascadeButton.focus = true
Keys.onUpPressed: {
if (windowListView.count) {
windowListView.currentIndex = (windowListView.count - 1);
windowListView.forceActiveFocus();
}
}
Keys.onDownPressed: {
if (windowListView.count) {
windowListView.currentIndex = 0;
windowListView.forceActiveFocus();
}
}
Keys.onLeftPressed: {
if (windowListView.count) {
windowListView.currentIndex = 0;
windowListView.forceActiveFocus();
}
}
Keys.onRightPressed: {
if (windowListView.count) {
windowListView.currentIndex = 0;
windowListView.forceActiveFocus();
}
}
}
}
diff --git a/contents/ui/main.qml b/contents/ui/main.qml
index 0c01369..c91e935 100644
--- a/contents/ui/main.qml
+++ b/contents/ui/main.qml
@@ -23,20 +23,20 @@ import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.taskmanager 0.1 as TaskManager
-import org.kde.kwindowsystem 1.0 as KWindowSystem
+// import org.kde.kwindowsystem 1.0 as KWindowSystem
Item {
id: root
+ Layout.preferredHeight: 600 * units.devicePixelRatio
+
Layout.minimumWidth: units.gridUnit * 12
Layout.minimumHeight: units.gridUnit * 12
Plasmoid.switchWidth: units.gridUnit * 11
Plasmoid.switchHeight: units.gridUnit * 11
- Plasmoid.toolTipSubText: i18n("Show list of opened windows")
-
property int itemHeight: Math.ceil((Math.max(theme.mSize(theme.defaultFont).height, units.iconSizes.small)
+ Math.max(highlightItemSvg.margins.top + highlightItemSvg.margins.bottom,
listItemSvg.margins.top + listItemSvg.margins.bottom)) / 2) * 2
@@ -44,6 +44,15 @@ Item {
TaskManager.TasksModel {
id: tasksModel
+ virtualDesktop: virtualDesktopInfo.currentDesktop
+ screenGeometry: plasmoid.screenGeometry
+ activity: activityInfo.currentActivity
+
+ filterByVirtualDesktop: true
+ filterByScreen: true
+ filterByActivity: true
+ filterNotMinimized: true
+
sortMode: TaskManager.TasksModel.SortVirtualDesktop
groupMode: TaskManager.TasksModel.GroupDisabled
}
@@ -52,10 +61,14 @@ Item {
id: virtualDesktopInfo
}
- KWindowSystem.KWindowSystem {
- id: windowSystem
+ TaskManager.ActivityInfo {
+ id: activityInfo
}
+ // KWindowSystem.KWindowSystem {
+ // id: windowSystem
+ // }
+
PlasmaCore.FrameSvgItem {
id : highlightItemSvg
@@ -151,8 +164,23 @@ Item {
delegate: MouseArea {
id: item
- height: root.itemHeight
+ // visible: model.IsMinimized
+ // implicitHeight: visible ? layout.implicitHeight : 0
+
+ property rect geometry: model.Geometry
+ property int windowId: model.LegacyWinIdList[0]
+ property string visibleName: model.display
+ property bool minimized: (model.IsMinimized === true)
+
+ property bool isWindowMinimized: {
+ console.log('caption', item.visibleName)
+ console.log('\t isMinimized', model.IsMinimized)
+ console.log('\t item.minimized', item.minimized)
+ return item.minimized
+ }
+
width: windowListView.overflowing ? ListView.view.width - units.smallSpacing : ListView.view.width
+ implicitHeight: layout.implicitHeight
property bool underPin: (item == windowListView.pinTopItem || item == windowListView.pinBottomItem)
@@ -170,44 +198,62 @@ Item {
}
}
- Row {
+ ColumnLayout {
+ id: layout
anchors.left: parent.left
anchors.leftMargin: highlightItemSvg.margins.left
anchors.right: parent.right
anchors.rightMargin: highlightItemSvg.margins.right
- height: parent.height
+ RowLayout {
- spacing: units.smallSpacing * 2
+ spacing: units.smallSpacing * 2
- LayoutMirroring.enabled: (Qt.application.layoutDirection == Qt.RightToLeft)
+ LayoutMirroring.enabled: (Qt.application.layoutDirection == Qt.RightToLeft)
- PlasmaCore.IconItem {
- id: icon
+ PlasmaCore.IconItem {
+ id: icon
- anchors.verticalCenter: parent.verticalCenter
+ Layout.preferredWidth: label.implicitHeight
+ Layout.preferredHeight: label.implicitHeight
+ Layout.alignment: Qt.AlignVCenter
- width: visible ? units.iconSizes.small : 0
- height: width
+ usesPlasmaTheme: false
- usesPlasmaTheme: false
-
- source: model.decoration
- }
+ source: model.decoration
+ }
- PlasmaComponents.Label {
- id: label
+ PlasmaComponents.Label {
+ id: label
- width: (parent.width - icon.width - parent.spacing - (underPin ? root.width - windowPin.x : 0))
- height: parent.height
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ verticalAlignment: Text.AlignVCenter
- verticalAlignment: Text.AlignVCenter
+ textFormat: Text.PlainText
+ wrapMode: Text.NoWrap
+ elide: Text.ElideRight
- textFormat: Text.PlainText
- wrapMode: Text.NoWrap
- elide: Text.ElideRight
+ text: model.display
+ }
+ }
- text: model.display
+ PlasmaCore.WindowThumbnail {
+ Layout.fillWidth: true
+ Layout.preferredHeight: Math.ceil(200 * units.devicePixelRatio)
+
+ readonly property var windows: model.LegacyWinIdList
+ readonly property int flatIndex: 0
+ winId: windows && windows[flatIndex] != undefined ? windows[flatIndex] : 0
+ // Component.onCompleted: logThumb()
+ onWinIdChanged: logThumb()
+
+ function logThumb() {
+ console.log('caption', model.display)
+ console.log('\t windows', windows)
+ console.log('\t winId', winId)
+ console.log('\t IsMinimized', model.IsMinimized)
+ }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.