add monitor config script for presentations
This commit is contained in:
74
.config/hypr/monitor-config.js
Executable file
74
.config/hypr/monitor-config.js
Executable 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"`);
|
||||
}
|
||||
@@ -17,6 +17,7 @@ in
|
||||
config = lib.mkIf cfg.enable {
|
||||
#programs.swaylock.enable = true;
|
||||
services.hyprpaper.enable = true;
|
||||
home.file.".config/hypr/monitor-config.js".source = ../../.config/hypr/monitor-config.js;
|
||||
wayland.windowManager.hyprland = {
|
||||
enable = true;
|
||||
#enableNvidiaPatches = true;
|
||||
@@ -299,6 +300,10 @@ in
|
||||
"$mainMod, mouse:273, resizewindow"
|
||||
];
|
||||
|
||||
windowrule = [
|
||||
"float, class:zenity"
|
||||
"center, class:zenity"
|
||||
];
|
||||
windowrulev2 = [
|
||||
|
||||
#"center, class:jetbrains-idea"
|
||||
@@ -349,6 +354,8 @@ in
|
||||
dunstctl = "${pkgs.dunst}/bin/dunstctl";
|
||||
pdfgrep = "${pkgs.pdfgrep}/bin/pdfgrep --cache";
|
||||
path = "/synced/fh/os-hardening/**/slides";
|
||||
node = "${pkgs.nodejs}/bin/node";
|
||||
set-monitor = "~/.config/hypr/monitor-config.js";
|
||||
in
|
||||
''
|
||||
bind = $mainMod, A, submap, notes
|
||||
@@ -356,6 +363,7 @@ in
|
||||
submap = notes
|
||||
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, P, exec, ${node} ${set-monitor}
|
||||
## below
|
||||
#bind = $mainMod, B, exec, ${wl-paste} | xargs -I {} ${pdfgrep} -B 15 -h -i "{}" ${path}/*.pdf | sed 's/[ \t]*$//' | ${wl-copy}
|
||||
## above
|
||||
|
||||
@@ -70,6 +70,7 @@ in {
|
||||
wl-clipboard
|
||||
xarchiver # archive tool
|
||||
adwaita-icon-theme
|
||||
zenity
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user