forked from Shinonome/dots-hyprland
background widgets
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
import "root:/"
|
||||
import "root:/modules/common"
|
||||
import "root:/modules/common/widgets"
|
||||
import "root:/services"
|
||||
import "root:/modules/common/functions/color_utils.js" as ColorUtils
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Wayland
|
||||
import Quickshell.Hyprland
|
||||
import Quickshell.Services.UPower
|
||||
|
||||
Scope {
|
||||
id: root
|
||||
property string filePath: `${Directories.state}/user/generated/wallpaper/least_busy_region.json`
|
||||
property real centerX: 0
|
||||
property real centerY: 0
|
||||
property color dominantColor: Appearance.m3colors.m3primary
|
||||
property bool dominantColorIsDark: dominantColor.hslLightness < 0.5
|
||||
property color colBackground: ColorUtils.transparentize(ColorUtils.mix(Appearance.m3colors.m3primary, Appearance.m3colors.m3secondaryContainer), 1)
|
||||
property color colText: ColorUtils.colorWithLightness(Appearance.m3colors.m3primary, (root.dominantColorIsDark ? 0.8 : 0.12))
|
||||
|
||||
function updateWidgetPosition(fileContent) {
|
||||
console.log("[BackgroundWidgets] Updating widget position with content:", fileContent)
|
||||
const parsedContent = JSON.parse(fileContent)
|
||||
root.centerX = parsedContent.center_x
|
||||
root.centerY = parsedContent.center_y
|
||||
root.dominantColor = parsedContent.dominant_color || Appearance.m3colors.m3primary
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: delayedFileRead
|
||||
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
|
||||
running: false
|
||||
onTriggered: {
|
||||
root.updateWidgetPosition(leastBusyRegionFileView.text())
|
||||
}
|
||||
}
|
||||
|
||||
FileView {
|
||||
id: leastBusyRegionFileView
|
||||
path: Qt.resolvedUrl(root.filePath)
|
||||
watchChanges: true
|
||||
onFileChanged: {
|
||||
this.reload()
|
||||
delayedFileRead.start()
|
||||
}
|
||||
onLoadedChanged: {
|
||||
const fileContent = leastBusyRegionFileView.text()
|
||||
root.updateWidgetPosition(fileContent)
|
||||
}
|
||||
}
|
||||
|
||||
Variants { // For each monitor
|
||||
model: Quickshell.screens
|
||||
|
||||
Loader {
|
||||
required property var modelData
|
||||
active: !ToplevelManager.activeToplevel?.activated
|
||||
sourceComponent: PanelWindow { // Window
|
||||
id: windowRoot
|
||||
screen: modelData
|
||||
property var textHorizontalAlignment: root.centerX < windowRoot.width / 3 ? Text.AlignLeft :
|
||||
(root.centerX > windowRoot.width * 2 / 3 ? Text.AlignRight : Text.AlignHCenter)
|
||||
|
||||
WlrLayershell.layer: WlrLayer.Bottom
|
||||
WlrLayershell.namespace: "quickshell:backgroundWidgets"
|
||||
|
||||
anchors {
|
||||
top: true
|
||||
bottom:true
|
||||
left: true
|
||||
right: true
|
||||
}
|
||||
color: "transparent"
|
||||
HyprlandWindow.visibleMask: Region {
|
||||
item: widgetBackground
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: widgetBackground
|
||||
property real verticalPadding: 20
|
||||
property real horizontalPadding: 30
|
||||
radius: 40
|
||||
color: root.colBackground
|
||||
implicitHeight: columnLayout.implicitHeight + verticalPadding * 2
|
||||
implicitWidth: columnLayout.implicitWidth + horizontalPadding * 2
|
||||
anchors {
|
||||
left: parent.left
|
||||
top: parent.top
|
||||
leftMargin: root.centerX - implicitWidth / 2
|
||||
topMargin: root.centerY - implicitHeight / 2
|
||||
Behavior on leftMargin {
|
||||
animation: Appearance.animation.elementMove.numberAnimation.createObject(this)
|
||||
}
|
||||
Behavior on topMargin {
|
||||
animation: Appearance.animation.elementMove.numberAnimation.createObject(this)
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: columnLayout
|
||||
anchors.centerIn: parent
|
||||
spacing: -5
|
||||
|
||||
StyledText {
|
||||
Layout.fillWidth: true
|
||||
horizontalAlignment: windowRoot.textHorizontalAlignment
|
||||
font.pixelSize: 95
|
||||
color: root.colText
|
||||
style: Text.Raised
|
||||
styleColor: Appearance.colors.colShadow
|
||||
text: DateTime.time
|
||||
}
|
||||
StyledText {
|
||||
Layout.fillWidth: true
|
||||
horizontalAlignment: windowRoot.textHorizontalAlignment
|
||||
font.pixelSize: 25
|
||||
color: root.colText
|
||||
style: Text.Raised
|
||||
styleColor: Appearance.colors.colShadow
|
||||
text: DateTime.date
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,6 +39,30 @@ function colorWithSaturationOf(color1, color2) {
|
||||
return Qt.hsva(hue, sat, val, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a color with the given lightness and the hue, saturation, and alpha of the input color (using HSL).
|
||||
*
|
||||
* @param {string} color - The base color (any Qt.color-compatible string).
|
||||
* @param {number} lightness - The lightness value to use (0-1).
|
||||
* @returns {Qt.rgba} The resulting color.
|
||||
*/
|
||||
function colorWithLightness(color, lightness) {
|
||||
var c = Qt.color(color);
|
||||
return Qt.hsla(c.hslHue, c.hslSaturation, lightness, c.a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a color with the lightness of color2 and the hue, saturation, and alpha of color1 (using HSL).
|
||||
*
|
||||
* @param {string} color1 - The base color (any Qt.color-compatible string).
|
||||
* @param {string} color2 - The color to take lightness from.
|
||||
* @returns {Qt.rgba} The resulting color.
|
||||
*/
|
||||
function colorWithLightnessOf(color1, color2) {
|
||||
var c2 = Qt.color(color2);
|
||||
return colorWithLightness(color1, c2.hslLightness);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts color1 to the accent (hue and saturation) of color2 using HSL, keeping lightness and alpha from color1.
|
||||
*
|
||||
@@ -66,7 +90,7 @@ function adaptToAccent(color1, color2) {
|
||||
* @param {number} percentage - The mix ratio (0-1). 1 = all color1, 0 = all color2.
|
||||
* @returns {Qt.rgba} The resulting mixed color.
|
||||
*/
|
||||
function mix(color1, color2, percentage) {
|
||||
function mix(color1, color2, percentage = 0.5) {
|
||||
var c1 = Qt.color(color1);
|
||||
var c2 = Qt.color(color2);
|
||||
return Qt.rgba(percentage * c1.r + (1 - percentage) * c2.r, percentage * c1.g + (1 - percentage) * c2.g, percentage * c1.b + (1 - percentage) * c2.b, percentage * c1.a + (1 - percentage) * c2.a);
|
||||
|
||||
Reference in New Issue
Block a user