Cache calculated launcher entry colors
wow an actual commit message
This commit is contained in:
22
Launcher.qml
22
Launcher.qml
@@ -20,6 +20,7 @@ PanelWindow {
|
|||||||
function open() {
|
function open() {
|
||||||
visible = true
|
visible = true
|
||||||
list.visible = true
|
list.visible = true
|
||||||
|
list.currentIndex = currentApps.findIndex(entry => entry.id === lastLaunched)
|
||||||
}
|
}
|
||||||
|
|
||||||
implicitWidth: 800
|
implicitWidth: 800
|
||||||
@@ -34,8 +35,9 @@ PanelWindow {
|
|||||||
|
|
||||||
readonly property int radius: 20
|
readonly property int radius: 20
|
||||||
readonly property int entry_height: 100
|
readonly property int entry_height: 100
|
||||||
|
property var apps: {Array.from(DesktopEntries.applications.values)}
|
||||||
property var currentApps: {
|
property var currentApps: {
|
||||||
let apps = Array.from(DesktopEntries.applications.values);
|
let apps = this.apps;
|
||||||
if (searchInput.text.length === 0) {
|
if (searchInput.text.length === 0) {
|
||||||
apps.sort((a, b) => a.name.localeCompare(b.name));
|
apps.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
return apps;
|
return apps;
|
||||||
@@ -75,8 +77,10 @@ PanelWindow {
|
|||||||
preferredHighlightBegin: 120
|
preferredHighlightBegin: 120
|
||||||
preferredHighlightEnd: this.height/2
|
preferredHighlightEnd: this.height/2
|
||||||
|
|
||||||
model: ScriptModel { values: currentApps; objectProp: "id" }
|
model: ScriptModel { values: currentApps }
|
||||||
delegate: Button {
|
delegate: Button {
|
||||||
|
id: button
|
||||||
|
z: -index
|
||||||
height: entry_height
|
height: entry_height
|
||||||
width: launcher.width + 10
|
width: launcher.width + 10
|
||||||
property var leftMargin: (Math.pow(Math.abs(this.y - list.contentY - launcher.height/2), 1.8) / 1400)
|
property var leftMargin: (Math.pow(Math.abs(this.y - list.contentY - launcher.height/2), 1.8) / 1400)
|
||||||
@@ -84,7 +88,6 @@ PanelWindow {
|
|||||||
left: parent?.left
|
left: parent?.left
|
||||||
leftMargin: leftMargin + selectedOffset
|
leftMargin: leftMargin + selectedOffset
|
||||||
}
|
}
|
||||||
z: -index
|
|
||||||
property real selectedOffset: ListView.isCurrentItem ? 16 : 64
|
property real selectedOffset: ListView.isCurrentItem ? 16 : 64
|
||||||
function execute() {
|
function execute() {
|
||||||
modelData.execute()
|
modelData.execute()
|
||||||
@@ -94,7 +97,6 @@ PanelWindow {
|
|||||||
Behavior on selectedOffset {
|
Behavior on selectedOffset {
|
||||||
NumberAnimation {duration: 500; easing.type: Easing.OutQuint}
|
NumberAnimation {duration: 500; easing.type: Easing.OutQuint}
|
||||||
}
|
}
|
||||||
id: button
|
|
||||||
onClicked: execute()
|
onClicked: execute()
|
||||||
|
|
||||||
// Calculate background color based on average color of icon
|
// Calculate background color based on average color of icon
|
||||||
@@ -109,9 +111,13 @@ PanelWindow {
|
|||||||
Component.onCompleted: loadImage(button.iconPath)
|
Component.onCompleted: loadImage(button.iconPath)
|
||||||
}
|
}
|
||||||
property var color: {
|
property var color: {
|
||||||
|
if (modelData.color) {
|
||||||
|
return modelData.color
|
||||||
|
}
|
||||||
if (!canvas.available) {
|
if (!canvas.available) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.log("calculating color for " + modelData.id)
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
ctx.drawImage(button.iconPath, 0, 0, canvas.width, canvas.height)
|
ctx.drawImage(button.iconPath, 0, 0, canvas.width, canvas.height)
|
||||||
const pixels = ctx.getImageData(0, 0, 100, 100).data;
|
const pixels = ctx.getImageData(0, 0, 100, 100).data;
|
||||||
@@ -126,7 +132,9 @@ PanelWindow {
|
|||||||
avg[2] += pixels[i+2] * saturation;
|
avg[2] += pixels[i+2] * saturation;
|
||||||
count += pixels[i+3] * saturation;
|
count += pixels[i+3] * saturation;
|
||||||
}
|
}
|
||||||
return Qt.rgba(avg[0]/count, avg[1]/count, avg[2]/count, 1);
|
let res = Qt.rgba(avg[0]/count, avg[1]/count, avg[2]/count, 1);
|
||||||
|
modelData.color = res;
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
property var iconPath: Quickshell.iconPath(modelData.icon)
|
property var iconPath: Quickshell.iconPath(modelData.icon)
|
||||||
|
|
||||||
@@ -167,11 +175,11 @@ PanelWindow {
|
|||||||
y: (y_anim + y_off) % (entry_height + y_size) - y_size
|
y: (y_anim + y_off) % (entry_height + y_size) - y_size
|
||||||
ShapePath {
|
ShapePath {
|
||||||
strokeWidth: 2
|
strokeWidth: 2
|
||||||
strokeColor: Qt.hsla(
|
strokeColor: button.color ? Qt.hsla(
|
||||||
button.color.hslHue,
|
button.color.hslHue,
|
||||||
button.color.hslSaturation,
|
button.color.hslSaturation,
|
||||||
0.3, 1
|
0.3, 1
|
||||||
)
|
) : button.color
|
||||||
fillColor: "transparent"
|
fillColor: "transparent"
|
||||||
|
|
||||||
startX: tri.x_size/2
|
startX: tri.x_size/2
|
||||||
|
|||||||
Reference in New Issue
Block a user