From 257e95abe8171789ed19ddc567bbe00a9a526628 Mon Sep 17 00:00:00 2001 From: churchy <129511714+nicefaa6waa@users.noreply.github.com> Date: Fri, 19 Jul 2024 05:57:02 +0300 Subject: [PATCH] Add files via upload --- .../ags/modules/sideleft/tools/changeres.sh | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .config/ags/modules/sideleft/tools/changeres.sh diff --git a/.config/ags/modules/sideleft/tools/changeres.sh b/.config/ags/modules/sideleft/tools/changeres.sh new file mode 100644 index 000000000..0c086c30a --- /dev/null +++ b/.config/ags/modules/sideleft/tools/changeres.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# Function to get the current resolution +get_current_resolution() { + local output + output=$(hyprctl monitors -j) + local width height refreshRate + width=$(echo "$output" | jq -r '.[0].width') + height=$(echo "$output" | jq -r '.[0].height') + refreshRate=$(echo "$output" | jq -r '.[0].refreshRate') + echo "$width $height $refreshRate" +} + +# Function to update the Hyprland configuration with the new resolution +update_resolution_config() { + local newWidth="$1" + local newHeight="$2" + local newRefreshRate="$3" + local currentRes + currentRes=$(get_current_resolution) + local width height refreshRate + width=${newWidth:-$(echo "$currentRes" | awk '{print $1}')} + height=${newHeight:-$(echo "$currentRes" | awk '{print $2}')} + refreshRate=${newRefreshRate:-$(echo "$currentRes" | awk '{print $3}')} + + local modelineOutput + modelineOutput=$(gtf "$width" "$height" "$refreshRate") + local modeline + modeline=$(echo "$modelineOutput" | grep -oP 'Modeline "\K[^"]+') + + if [ -z "$modeline" ]; then + echo "Failed to generate modeline" + exit 1 + fi + + local configPath="${HOME}/.config/hypr/hyprland/general.conf" + local newConfigContent + newConfigContent=$(sed "s/^monitor=.*$/monitor=eDP-1, $modeline, auto, 1/" "$configPath") + + echo "$newConfigContent" > "$configPath" +} + +# Main script +echo "Welcome to the Resolution Configurator" +echo "" +echo " +---------------------------+" +echo " | _____ |" +echo " | | | |" +echo " | | | |" +echo " | |_____| |" +echo " | |" +echo " +---------------------------+" +echo "" +echo "Current resolution and refresh rate:" +currentRes=$(get_current_resolution) +width=$(echo "$currentRes" | awk '{print $1}') +height=$(echo "$currentRes" | awk '{print $2}') +refreshRate=$(echo "$currentRes" | awk '{print $3}') + +echo "Width: $width px" +echo "Height: $height px" +echo "Refresh Rate: $refreshRate Hz" + +echo "" + +read -p "Enter new width (or press Enter to keep current width): " newWidth +read -p "Enter new height (or press Enter to keep current height): " newHeight +read -p "Enter new refresh rate (or press Enter to keep current refresh rate): " newRefreshRate + +# Validate inputs (if provided) +if [[ ! "$newWidth" =~ ^[0-9]+$ && -n "$newWidth" ]]; then + echo "Invalid width value." + exit 1 +fi + +if [[ ! "$newHeight" =~ ^[0-9]+$ && -n "$newHeight" ]]; then + echo "Invalid height value." + exit 1 +fi + +if [[ ! "$newRefreshRate" =~ ^[0-9]+$ && -n "$newRefreshRate" ]]; then + echo "Invalid refresh rate value." + exit 1 +fi + +update_resolution_config "$newWidth" "$newHeight" "$newRefreshRate" + +echo "Resolution updated successfully." \ No newline at end of file