add monitor config script for presentations

This commit is contained in:
Kopatz
2025-08-24 14:11:04 +02:00
parent c71563b698
commit 19fafe5b61
3 changed files with 83 additions and 0 deletions

74
.config/hypr/monitor-config.js Executable file
View File

@@ -0,0 +1,74 @@
#!/usr/bin/env node
import { exec } from 'child_process';
async function execCommand(command) {
console.log(`Executing command: ${command}`);
return new Promise((resolve, reject) => {
let child = exec(command);
let stdoutData = '';
child.stdout.on('data', (data) => {
stdoutData += data;
process.stdout.write(data.toString());
});
child.stderr.on('data', (data) => {
process.stderr.write(data.toString());
});
child.on('close', (code) => {
if (code !== 0) {
reject(new Error(`Command failed with exit code ${code}`));
} else {
resolve(stdoutData.trim());
}
});
child.on('error', (err) => {
reject(err);
});
});
}
/** @type(String) */
let result = await execCommand('hyprctl monitors all');
let monitors = {};
let currentMonitor = null;
result.split('\n').forEach(line => {
if (line.includes('Monitor')) {
let parts = line.split(' ');
let name = parts[1];
monitors[name] = { name };
currentMonitor = name;
}
if (line.includes('availableModes:')) {
line = line.trim();
let start = line.indexOf(":") + 2;
let modes = line.substring(start).split(' ');
monitors[currentMonitor].availableModes = modes;
}
});
console.log(monitors);
let zenity_monitors = Object.keys(monitors).join(' \\\n');
let selectedMonitor = await execCommand(`zenity --list --title "Choose a monitor" \
--column="Name" \
${zenity_monitors}`);
let zenity_modes = monitors[selectedMonitor].availableModes.join(' \\\n');
let selectedMode = await execCommand(`zenity --list --title "Choose a mode" \
--column="Mode" \
${zenity_modes}`);
console.log(`monitor = ${selectedMonitor}, ${selectedMode}, auto, auto`);
let mirror = false;
try {
await execCommand(`zenity --question --text="Do you want to mirror to this display?"`);
mirror = true;
} catch (e) {
}
if (mirror) {
let otherMonitor = Object.keys(monitors).filter(m => m !== selectedMonitor);
await execCommand(`hyprctl keyword monitor "${selectedMonitor}, ${selectedMode},auto,auto,mirror,${otherMonitor}"`);
} else {
await execCommand(`hyprctl keyword monitor "${selectedMonitor}, ${selectedMode}, auto, auto"`);
}

View File

@@ -17,6 +17,7 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
#programs.swaylock.enable = true; #programs.swaylock.enable = true;
services.hyprpaper.enable = true; services.hyprpaper.enable = true;
home.file.".config/hypr/monitor-config.js".source = ../../.config/hypr/monitor-config.js;
wayland.windowManager.hyprland = { wayland.windowManager.hyprland = {
enable = true; enable = true;
#enableNvidiaPatches = true; #enableNvidiaPatches = true;
@@ -299,6 +300,10 @@ in
"$mainMod, mouse:273, resizewindow" "$mainMod, mouse:273, resizewindow"
]; ];
windowrule = [
"float, class:zenity"
"center, class:zenity"
];
windowrulev2 = [ windowrulev2 = [
#"center, class:jetbrains-idea" #"center, class:jetbrains-idea"
@@ -349,6 +354,8 @@ in
dunstctl = "${pkgs.dunst}/bin/dunstctl"; dunstctl = "${pkgs.dunst}/bin/dunstctl";
pdfgrep = "${pkgs.pdfgrep}/bin/pdfgrep --cache"; pdfgrep = "${pkgs.pdfgrep}/bin/pdfgrep --cache";
path = "/synced/fh/os-hardening/**/slides"; path = "/synced/fh/os-hardening/**/slides";
node = "${pkgs.nodejs}/bin/node";
set-monitor = "~/.config/hypr/monitor-config.js";
in in
'' ''
bind = $mainMod, A, submap, notes bind = $mainMod, A, submap, notes
@@ -356,6 +363,7 @@ in
submap = notes submap = notes
bind = $mainMod, M, exec, hyprctl keyword monitor ",preferred,auto,1,mirror,${monitor1}" && ${dunstify} "Mirroring enabled" bind = $mainMod, M, exec, hyprctl keyword monitor ",preferred,auto,1,mirror,${monitor1}" && ${dunstify} "Mirroring enabled"
bind = $mainMod, R, exec, hyprctl keyword monitor ",preferred,auto,auto" && ${dunstify} "Mirroring disabled" bind = $mainMod, R, exec, hyprctl keyword monitor ",preferred,auto,auto" && ${dunstify} "Mirroring disabled"
bind = $mainMod, P, exec, ${node} ${set-monitor}
## below ## below
#bind = $mainMod, B, exec, ${wl-paste} | xargs -I {} ${pdfgrep} -B 15 -h -i "{}" ${path}/*.pdf | sed 's/[ \t]*$//' | ${wl-copy} #bind = $mainMod, B, exec, ${wl-paste} | xargs -I {} ${pdfgrep} -B 15 -h -i "{}" ${path}/*.pdf | sed 's/[ \t]*$//' | ${wl-copy}
## above ## above

View File

@@ -70,6 +70,7 @@ in {
wl-clipboard wl-clipboard
xarchiver # archive tool xarchiver # archive tool
adwaita-icon-theme adwaita-icon-theme
zenity
]; ];
}; };
} }