examples: Add quick script example

This commit is contained in:
Vlad Zahorodnii 2024-02-23 21:10:52 +02:00
parent 181ce590a9
commit f0b3964c1a
5 changed files with 131 additions and 0 deletions

1
examples/quick-script/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build

View file

@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: None
# SPDX-License-Identifier: CC0-1.0
cmake_minimum_required(VERSION 3.20)
project(quick-script)
set(KF6_MIN_VERSION "6.0.0")
find_package(ECM ${KF6_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS
Package
)
kpackage_install_package(package quick-script scripts kwin)

View file

@ -0,0 +1,94 @@
/*
SPDX-FileCopyrightText: 2024 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: MIT
*/
import QtQuick
import QtQuick.Window
import org.kde.kirigami as Kirigami
import org.kde.kwin as KWinComponents
Window {
id: root
readonly property int thumbnailWidth: Kirigami.Units.gridUnit * 10
readonly property int thumbnailHeight: Kirigami.Units.gridUnit * 10
readonly property bool _q_showWithoutActivating: true
color: "transparent"
flags: Qt.BypassWindowManagerHint | Qt.FramelessWindowHint
visible: listModel.count > 0
width: thumbnailWidth
height: Math.min(listModel.count * thumbnailHeight, Screen.height)
x: (Screen.virtualX + Screen.width) - width
y: Screen.virtualY + 0.5 * (Screen.height - height)
ListView {
id: listView
anchors.fill: parent
model: listModel
opacity: 0.5
delegate: KWinComponents.WindowThumbnail {
client: model.window
width: thumbnailWidth
height: thumbnailHeight
TapHandler {
onTapped: KWinComponents.Workspace.activeWindow = client;
}
}
transform: Rotation {
axis {
x: 0
y: 1
z: 0
}
origin {
x: width
y: height / 2
}
angle: -30
}
}
ListModel {
id: listModel
}
function toggle() {
const window = KWinComponents.Workspace.activeWindow;
if (!window) {
return;
}
for (let i = 0; i < listModel.count; ++i) {
if (listModel.get(i)["window"] == window) {
listModel.remove(i);
return;
}
}
listModel.append({"window": window});
}
function remove(window) {
for (let i = 0; i < listModel.count; ++i) {
const item = listModel.get(i);
if (item["window"] == window) {
listModel.remove(i);
}
}
}
KWinComponents.ShortcutHandler {
name: "Toggle Current Thumbnail"
text: "Toggle Current Thumbnail"
sequence: "Meta+Ctrl+T"
onActivated: toggle()
}
Component.onCompleted: {
KWinComponents.Workspace.windowRemoved.connect(remove);
}
}

View file

@ -0,0 +1,18 @@
{
"KPackageStructure": "KWin/Script",
"KPlugin": {
"Authors": [
{
"Email": "user@example.com",
"Name": "Your Name"
}
],
"Description": "An example QtQuick script",
"EnabledByDefault": false,
"Icon": "preferences-system-windows-script-test",
"Id": "quick-script",
"License": "GPL",
"Name": "Quick Script"
},
"X-Plasma-API": "declarativescript"
}

View file

@ -0,0 +1,2 @@
SPDX-FileCopyrightText: None
SPDX-License-Identifier: CC0-1.0