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 1/5] 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 From ddc0497c162a3e6118f2aea65784e11dc07e5b84 Mon Sep 17 00:00:00 2001 From: churchy <129511714+nicefaa6waa@users.noreply.github.com> Date: Fri, 19 Jul 2024 05:59:22 +0300 Subject: [PATCH 2/5] Update quickscripts.js --- .config/ags/modules/sideleft/tools/quickscripts.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.config/ags/modules/sideleft/tools/quickscripts.js b/.config/ags/modules/sideleft/tools/quickscripts.js index c928cc4cd..e1c4ea11c 100644 --- a/.config/ags/modules/sideleft/tools/quickscripts.js +++ b/.config/ags/modules/sideleft/tools/quickscripts.js @@ -40,6 +40,12 @@ const scripts = [ name: 'Update packages', command: `sudo pacman -Syyu`, enabled: isArchDistro, + }, + { + icon: 'arch-symbolic', + name: 'Change resolution', + command: `bash .config/ags/modules/sideleft/tools/changeres.sh`, + enabled: isArchDistro, }, { icon: 'arch-symbolic', From e4628194920b992047f491733b037bb0231c72d7 Mon Sep 17 00:00:00 2001 From: churchy <129511714+nicefaa6waa@users.noreply.github.com> Date: Sat, 20 Jul 2024 12:47:45 +0300 Subject: [PATCH 3/5] Update quickscripts.js --- .config/ags/modules/sideleft/tools/quickscripts.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.config/ags/modules/sideleft/tools/quickscripts.js b/.config/ags/modules/sideleft/tools/quickscripts.js index e1c4ea11c..f99bf0b66 100644 --- a/.config/ags/modules/sideleft/tools/quickscripts.js +++ b/.config/ags/modules/sideleft/tools/quickscripts.js @@ -42,11 +42,11 @@ const scripts = [ enabled: isArchDistro, }, { - icon: 'arch-symbolic', - name: 'Change resolution', - command: `bash .config/ags/modules/sideleft/tools/changeres.sh`, - enabled: isArchDistro, - }, + icon: 'desktop-symbolic', + name: 'Change resolution', + command: `bash ${App.configDir}/modules/sideleft/tools/changeres.sh`, + enabled: true, + }, { icon: 'arch-symbolic', name: 'Remove orphan packages', From 07028aec4f718607e462163785e8c2fb2039d8c2 Mon Sep 17 00:00:00 2001 From: churchy <129511714+nicefaa6waa@users.noreply.github.com> Date: Sat, 20 Jul 2024 12:48:33 +0300 Subject: [PATCH 4/5] Update changeres.sh --- .config/ags/modules/sideleft/tools/changeres.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.config/ags/modules/sideleft/tools/changeres.sh b/.config/ags/modules/sideleft/tools/changeres.sh index 0c086c30a..333f09881 100644 --- a/.config/ags/modules/sideleft/tools/changeres.sh +++ b/.config/ags/modules/sideleft/tools/changeres.sh @@ -33,9 +33,20 @@ update_resolution_config() { exit 1 fi + # Extract the resolution and refresh rate from the modeline + local resolution + resolution=$(echo "$modeline" | grep -oP '^[0-9]+x[0-9]+') + local rate + rate=$(echo "$modeline" | grep -oP '[0-9]+.[0-9]+$') + + if [ -z "$resolution" ] || [ -z "$rate" ]; then + echo "Failed to extract resolution or refresh rate from 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") + newConfigContent=$(sed "s/^monitor=.*$/monitor=eDP-1, $resolution@$rate, auto, 1/" "$configPath") echo "$newConfigContent" > "$configPath" } @@ -85,4 +96,4 @@ fi update_resolution_config "$newWidth" "$newHeight" "$newRefreshRate" -echo "Resolution updated successfully." \ No newline at end of file +echo "Resolution updated successfully." From a45f7b4b9f30912b507fafa81888240762ede884 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 28 Jul 2024 14:57:50 +0700 Subject: [PATCH 5/5] change resolution script position --- .config/ags/modules/sideleft/tools/quickscripts.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.config/ags/modules/sideleft/tools/quickscripts.js b/.config/ags/modules/sideleft/tools/quickscripts.js index f99bf0b66..09fdb1b15 100644 --- a/.config/ags/modules/sideleft/tools/quickscripts.js +++ b/.config/ags/modules/sideleft/tools/quickscripts.js @@ -11,6 +11,12 @@ import { setupCursorHover } from '../../.widgetutils/cursorhover.js'; import { distroID, isArchDistro, isDebianDistro, hasFlatpak } from '../../.miscutils/system.js'; const scripts = [ + { + icon: 'desktop-symbolic', + name: 'Change screen resolution', + command: `bash ${App.configDir}/modules/sideleft/tools/changeres.sh`, + enabled: true, + }, { icon: 'nixos-symbolic', name: 'Trim system generations to 5', @@ -41,12 +47,6 @@ const scripts = [ command: `sudo pacman -Syyu`, enabled: isArchDistro, }, - { - icon: 'desktop-symbolic', - name: 'Change resolution', - command: `bash ${App.configDir}/modules/sideleft/tools/changeres.sh`, - enabled: true, - }, { icon: 'arch-symbolic', name: 'Remove orphan packages',