Skip to content

Commit c917419

Browse files
committed
feat: video decoding configuration
Allows to set the following using Plasma's Session Environment Variables QT_FFMPEG_DECODING_HW_DEVICE_TYPES QT_MEDIA_BACKEND LIBVA_DRIVER_NAME unclear if it does anything VDPAU_DRIVER unclear if it does anything https://wiki.archlinux.org/title/Hardware_video_acceleration https://doc.qt.io/qt-6/advanced-ffmpeg-configuration.html https://doc.qt.io/qt-6/qtmultimedia-index.html https://userbase.kde.org/Session_Environment_Variables https://wiki.archlinux.org/title/Environment_variables
1 parent cf101b5 commit c917419

2 files changed

Lines changed: 368 additions & 9 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import QtQuick
2+
3+
// import "code/utils.js" as Utils
4+
5+
Item {
6+
id: root
7+
property ListModel model: ListModel {}
8+
property bool isLoading: true
9+
readonly property string plasmaEnvFile: "$HOME/.config/plasma-workspace/env/luisbocanegra.smart.video.wallpaper.reborn.sh"
10+
11+
signal updated
12+
signal loaded
13+
14+
function initModel(envVars) {
15+
model.clear();
16+
let varList = envVars.split("\n");
17+
for (let envVar of varList) {
18+
let [name, value] = envVar.split("=");
19+
const existsIndex = getIndex(name);
20+
if (existsIndex !== -1) {
21+
model.set(existsIndex, {
22+
name,
23+
value
24+
});
25+
continue;
26+
}
27+
model.append({
28+
name,
29+
value
30+
});
31+
}
32+
root.isLoading = false;
33+
loaded();
34+
}
35+
36+
function getValue(name) {
37+
for (let i = 0; i < model.count; i++) {
38+
const item = model.get(i);
39+
if (item.name === name) {
40+
return item.value;
41+
}
42+
}
43+
return "";
44+
}
45+
46+
function getIndex(name) {
47+
for (let i = 0; i < model.count; i++) {
48+
const item = model.get(i);
49+
if (item.name === name) {
50+
return i;
51+
}
52+
}
53+
return -1;
54+
}
55+
56+
function getPlasmaEnvVar(name, c) {
57+
// check if it exists
58+
// if it does sed
59+
// if it does not, append
60+
runCommand.exec(`grep 'export ${name}' "${plasmaEnvFile}" | sed 's/export ${name}=//'`, output => {
61+
if (c) {
62+
if (output.exitCode === 0 && output.stdout.length > 0) {
63+
return c(output.stdout.trim());
64+
}
65+
return c(null);
66+
}
67+
});
68+
}
69+
70+
function setPlasmaEnvVar(name, value) {
71+
// check if it exists
72+
// if it does sed
73+
// if it does not, append
74+
runCommand.exec(`grep 'export ${name}' "${plasmaEnvFile}"`, output => {
75+
if (output.exitCode === 0 && output.stdout.length > 0) {
76+
console.log(`${name}`, output.stdout);
77+
console.log(`sed -i 's/export ${name}=.*/export ${name}=${value}/g' "${plasmaEnvFile}"`);
78+
runCommand.exec(`sed -i 's/export ${name}=.*/export ${name}=${value}/g' "${plasmaEnvFile}"`);
79+
} else {
80+
runCommand.exec(`touch "${plasmaEnvFile}" && echo "export ${name}=${value}" >> "${plasmaEnvFile}"`);
81+
}
82+
});
83+
}
84+
85+
function removePlasmaEnvVar(name) {
86+
console.log(`sed -i '/export ${name}=.*/d' "${plasmaEnvFile}"`);
87+
runCommand.exec(`sed -i '/export ${name}=.*/d' "${plasmaEnvFile}"`);
88+
}
89+
90+
function varExists(name) {
91+
return getValue(name) !== "";
92+
}
93+
94+
RunCommand {
95+
id: runCommand
96+
}
97+
98+
function getVars() {
99+
let vars;
100+
runCommand.exec(`printenv`, output => {
101+
if (output.exitCode === 0 && output.stdout.length > 0) {
102+
initModel(output.stdout.trim());
103+
}
104+
});
105+
}
106+
107+
Component.onCompleted: {
108+
getVars();
109+
}
110+
}

0 commit comments

Comments
 (0)