Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JonMagon committed May 20, 2023
0 parents commit 8970627
Show file tree
Hide file tree
Showing 10 changed files with 1,024 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Create Release

on:
push:
tags:
- '*'

env:
file_name: ${{ github.event.repository.name }}-${{ github.ref_name }}.plasmoid

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build
run: |
zip -r ${{ env.file_name }} LICENSE.md README.md
cd package
zip -r ../${{ env.file_name }} *
- name: Release
uses: softprops/action-gh-release@v1
with:
files: ${{ env.file_name }}
674 changes: 674 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# KDE Plasma Applet for display brightness adjustment

<p align="center">
<img src="https://raw.githubusercontent.com/JonMagon/plasma-screendimmer/main/screenshot.png"/>
</p>

## Setup
```bash
git clone https://github.com/JonMagon/plasma-screendimmer.git
cd package
kpackagetool5 --install package
```

Right-click the task bar, then click Add widgets, search for Display Brightness and add to the panel. You can move it if necessary.

Alternatively, right click on the system tray, open settings, in entries list search for Display Brightness and enable it.

## Copyright
* BrightnessItem.qml owned by KDE Team
17 changes: 17 additions & 0 deletions package/contents/config/config.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
SPDX-FileCopyrightText: 2023 Dmitry Ilyich Sidorov <[email protected]>
SPDX-License-Identifier: LGPL-3.0-or-later
*/

import QtQuick 2.0

import org.kde.plasma.configuration 2.0

ConfigModel {
ConfigCategory {
name: i18nd("plasma_applet_org.kde.plasma.notifications", "Configure")
icon: "configure"
source: "ConfigGeneral.qml"
}
}
12 changes: 12 additions & 0 deletions package/contents/config/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name=""/>
<group name="General">
<entry name="minimumBrightness" type="Int">
<default>10</default>
</entry>
</group>
</kcfg>
85 changes: 85 additions & 0 deletions package/contents/ui/BrightnessItem.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
SPDX-FileCopyrightText: 2012-2013 Daniel Nicoletti <[email protected]>
SPDX-FileCopyrightText: 2013, 2015 Kai Uwe Broulik <[email protected]>
SPDX-License-Identifier: LGPL-2.0-or-later
*/

import QtQuick 2.15
import QtQuick.Layouts 1.15

import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.core 2.1 as PlasmaCore

PlasmaComponents3.ItemDelegate {
id: root

property alias slider: control
property alias value: control.value
property alias maximumValue: control.to
property alias stepSize: control.stepSize
property alias showPercentage: percent.visible

readonly property real percentage: Math.round(100 * value / maximumValue)

signal moved()

background.visible: highlighted
highlighted: activeFocus
hoverEnabled: false

Accessible.description: percent.text
Accessible.role: Accessible.Slider
Keys.forwardTo: [slider]

contentItem: RowLayout {
spacing: PlasmaCore.Units.gridUnit

PlasmaCore.IconItem {
id: image
Layout.alignment: Qt.AlignTop
Layout.preferredWidth: PlasmaCore.Units.iconSizes.medium
Layout.preferredHeight: PlasmaCore.Units.iconSizes.medium
source: root.icon.name
}

ColumnLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
spacing: 0

RowLayout {
Layout.fillWidth: true
spacing: PlasmaCore.Units.smallSpacing

PlasmaComponents3.Label {
id: title
Layout.fillWidth: true
text: root.text
}

PlasmaComponents3.Label {
id: percent
Layout.alignment: Qt.AlignRight
text: i18nc("Placeholder is brightness percentage", "%1%", root.percentage)
}
}

PlasmaComponents3.Slider {
id: control
Layout.fillWidth: true

activeFocusOnTab: false
// Don't allow the slider to turn off the screen
// Please see https://git.reviewboard.kde.org/r/122505/ for more information
from: to > 100 ? 1 : 0
stepSize: 1

Accessible.name: root.text
Accessible.description: percent.text

onMoved: root.moved()
}
}
}
}
35 changes: 35 additions & 0 deletions package/contents/ui/ConfigGeneral.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
SPDX-FileCopyrightText: 2023 Dmitry Ilyich Sidorov <[email protected]>
SPDX-License-Identifier: LGPL-3.0-or-later
*/

import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
import org.kde.kirigami 2.4 as Kirigami

Item {
id: page
width: childrenRect.width
height: childrenRect.height

signal configurationChanged

function saveConfig() {
plasmoid.configuration.minimumBrightness = minimumBrightness.value
}

Kirigami.FormLayout {
anchors.left: parent.left
anchors.right: parent.right

SpinBox {
id: minimumBrightness
Kirigami.FormData.label: i18n("Minimal safe brightness:")
from: 1
value: plasmoid.configuration.minimumBrightness
}
}
}

130 changes: 130 additions & 0 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
SPDX-FileCopyrightText: 2023 Dmitry Ilyich Sidorov <[email protected]>
SPDX-License-Identifier: LGPL-3.0-or-later
*/

import QtQuick 2.0
import QtQuick.Layouts 1.0

import org.kde.plasma.core 2.1 as PlasmaCore
import org.kde.plasma.components 3.0 as PC3
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.plasmoid 2.0
import QtQuick.Dialogs 1.2

Item {
id: main

property string displayName: i18n("plasma_applet_org.kde.plasma.battery", "Brightness")

property int minimumScreenBrightness: plasmoid.configuration.minimumBrightness
property int maximumScreenBrightness: 100
property int screenBrightness: 100
property string screenOutput

MessageDialog {
id: errorDialog
title: "An error occuried"
text: "Failed to get the current brightness and output values with xrandr."
icon: StandardIcon.Critical
}

Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation

Plasmoid.fullRepresentation: PlasmaExtras.Representation {
id: dialogItem

Layout.minimumWidth: PlasmaCore.Units.gridUnit * 10
Layout.maximumWidth: PlasmaCore.Units.gridUnit * 80
Layout.preferredWidth: PlasmaCore.Units.gridUnit * 20

Layout.preferredHeight: implicitHeight

contentItem: BrightnessItem {
id: brightnessSlider

icon.name: "video-display-brightness"
text: i18nd("plasma_applet_org.kde.plasma.battery", "Display Brightness")
value: screenBrightness
maximumValue: maximumScreenBrightness

stepSize: maximumScreenBrightness / 100

enabled: screenOutput

onMoved: {
screenBrightness = value
if (value < minimumScreenBrightness) {
screenBrightness = minimumScreenBrightness
return
}

executable.exec(`xrandr --output ${screenOutput} --brightness ${screenBrightness / 100}`)
}

}
}

Plasmoid.compactRepresentation: PlasmaCore.IconItem {
source: Plasmoid.icon
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onClicked: {
if (mouse.button === Qt.LeftButton) {
if (plasmoid.expanded) {
plasmoid.expanded = false
} else {
executable.exec("xrandr --verbose | grep -m 2 -i \" connected\\|brightness\"")
}
}
}
}
}

Connections {
target: executable
onExited: {
if (exitCode == 0 && exitStatus == 0) {
if (stdout != null && stdout.length > 5) {
var lines = stdout.trim().split('\n')
if (lines.length < 2) return

for (var i = 1; i < lines.length; i++) {
if (lines[i].split(' ')[0].includes('Brightness')) {
screenOutput = lines[i - 1].split(' ')[0]
screenBrightness = lines[i].split(' ')[1] * 100
break
}
}

if (!plasmoid.expanded) {
plasmoid.expanded = true
}
}
}
else {
errorDialog.visible = true
}
}
}

PlasmaCore.DataSource {
id: executable
engine: "executable"
connectedSources: []
onNewData: {
var exitCode = data["exit code"]
var exitStatus = data["exit status"]
var stdout = data["stdout"]
var stderr = data["stderr"]
exited(exitCode, exitStatus, stdout, stderr)
disconnectSource(sourceName)
}
function exec(cmd) {
connectSource(cmd)
}
signal exited(int exitCode, int exitStatus, string stdout, string stderr)
}
}
27 changes: 27 additions & 0 deletions package/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"KPlugin": {
"Authors": [
{
"Email": "[email protected]",
"Name": "Dmitry Sidorov"
}
],
"Category": "Hardware",
"Description": "The simplest KDE brightness applet (X11, XRandR)",
"Icon": "brightness-high",
"Id": "com.github.jonmagon.plasma-screendimmer",
"License": "GPL-3.0+",
"Name": "Display Brightness",
"Name[de]": "Monitor-Helligkeit",
"Name[ru]": "Яркость экрана",
"ServiceTypes": [
"Plasma/Applet"
],
"Version": "0.9",
"Website": "https://github.com/JonMagon/plasma-screendimmer"
},
"X-Plasma-API": "declarativeappletscript",
"X-Plasma-MainScript": "ui/main.qml",
"X-Plasma-NotificationArea": true,
"X-Plasma-NotificationAreaCategory": "Hardware"
}
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8970627

Please sign in to comment.