Skip to content

Instantly share code, notes, and snippets.

@torma616
Last active December 25, 2024 03:48
Show Gist options
  • Save torma616/cb51d236dd6e0abd5edbd63b2e831558 to your computer and use it in GitHub Desktop.
Save torma616/cb51d236dd6e0abd5edbd63b2e831558 to your computer and use it in GitHub Desktop.
KDE Plasma 6 24-hr Clock on Lockscreen
--- /usr/share/plasma/look-and-feel/org.kde.breeze.desktop/contents/lockscreen/LockScreenUi.qml.original 2024-08-27 03:48:33.088548792 -0400
+++ /usr/share/plasma/look-and-feel/org.kde.breeze.desktop/contents/lockscreen/LockScreenUi.qml 2024-08-27 10:50:45.599963229 -0400
@@ -224,6 +224,13 @@
anchors.horizontalCenter: parent.horizontalCenter
y: (mainBlock.userList.y + mainStack.y)/2 - height/2
Layout.alignment: Qt.AlignBaseline
+ Component.onCompleted: {
+ function updateClockString() {
+ clock.children[0].text = Qt.formatTime(clock.data[0].data["Local"]["DateTime"], 'hh:mm:ss');
+ }
+ updateClockString();
+ clock.data[0].onDataChanged.connect(updateClockString);
+ }
}
ListModel {
@alexwh
Copy link

alexwh commented Sep 19, 2024

For me the file was under /usr/share/plasma/shells/org.kde.plasma.desktop/contents/lockscreen/LockScreenUi.qml

@hlmtre
Copy link

hlmtre commented Oct 17, 2024

If you want to change the date format (or add whatever nonsense appeals to you), you can further update the child objects after it's loaded by making the Clock entry around line 220 look like so:

        Clock {                                                                                                                                                                                                       
            id: clock                                                                                                                                                                                                 
            property Item shadow: clockShadow                                                                                                                                                                         
            visible: y > 0 && config.alwaysShowClock                                                                                                                                                                  
            anchors.horizontalCenter: parent.horizontalCenter                                                                                                                                                         
            y: (mainBlock.userList.y + mainStack.y)/2 - height/2                                                                                                                                                      
            Layout.alignment: Qt.AlignBaseline                                                                                                                                                                        
            Component.onCompleted: {                                                                                                                                                                                  
                function updateClockString() {                                                                                                                                                                        
                    // there are two childitems you can play with here                                                                                                                                                
                    clock.children[0].text = Qt.formatTime(clock.data[0].data["Local"]["DateTime"], 'hh:mm');                                                                                                         
                    clock.children[1].text = Qt.formatDate(clock.data[0].data["Local"]["DateTime"], 'ddd yyyy-MM-dd');                                                                                                
                    //clock.children[1].text = "LOL HI GITHUB";                                                                                                                                                       
                }                                                                                                                                                                                                     
                updateClockString();                                                                                                                                                                                  
                clock.data[0].onDataChanged.connect(updateClockString);                                                                                                                                               
            }                                                                                                                                                                                                         
        }                                                                                                                                                                                         

@barraIhsan
Copy link

If you want to change the date format (or add whatever nonsense appeals to you), you can further update the child objects after it's loaded by making the Clock entry around line 220 look like so:

        Clock {                                                                                                                                                                                                       
            id: clock                                                                                                                                                                                                 
            property Item shadow: clockShadow                                                                                                                                                                         
            visible: y > 0 && config.alwaysShowClock                                                                                                                                                                  
            anchors.horizontalCenter: parent.horizontalCenter                                                                                                                                                         
            y: (mainBlock.userList.y + mainStack.y)/2 - height/2                                                                                                                                                      
            Layout.alignment: Qt.AlignBaseline                                                                                                                                                                        
            Component.onCompleted: {                                                                                                                                                                                  
                function updateClockString() {                                                                                                                                                                        
                    // there are two childitems you can play with here                                                                                                                                                
                    clock.children[0].text = Qt.formatTime(clock.data[0].data["Local"]["DateTime"], 'hh:mm');                                                                                                         
                    clock.children[1].text = Qt.formatDate(clock.data[0].data["Local"]["DateTime"], 'ddd yyyy-MM-dd');                                                                                                
                    //clock.children[1].text = "LOL HI GITHUB";                                                                                                                                                       
                }                                                                                                                                                                                                     
                updateClockString();                                                                                                                                                                                  
                clock.data[0].onDataChanged.connect(updateClockString);                                                                                                                                               
            }                                                                                                                                                                                                         
        }                                                                                                                                                                                         

hey! Can I also adjust the font size and the font weight? I've been wanting to do this cuz I don't like the default lockscreen style

@hlmtre
Copy link

hlmtre commented Dec 24, 2024

You almost certainly can but I don't think it'll be here - the child item style is set elsewhere. I don't have my KDE Plasma machine handy to find it :(

@barraIhsan
Copy link

I don't get the reason on why kde decided to not let us customize the lockscreen tho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment