From e78e9b25f1895d52376bfeb6b7b9cc496d98652d Mon Sep 17 00:00:00 2001 From: kokopi-dev Date: Sun, 5 Apr 2026 01:14:21 +0900 Subject: [PATCH] add:mangowm stuff --- README.md | 2 +- mangowm/README.md | 3 ++ mangowm/brightness.py | 77 +++++++++++++++++++++++++++++++++++++++++++ mangowm/sc.sh | 3 ++ mangowm/ss.sh | 17 ++++++++++ 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 mangowm/README.md create mode 100755 mangowm/brightness.py create mode 100755 mangowm/sc.sh create mode 100755 mangowm/ss.sh diff --git a/README.md b/README.md index ddc7797..8b91737 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # Personal Scripts Collection -Collection of scripts I use frequently +Collection of scripts I use frequently. Some of these are tailored specific to my env. ## Complementary Tool diff --git a/mangowm/README.md b/mangowm/README.md new file mode 100644 index 0000000..8c00291 --- /dev/null +++ b/mangowm/README.md @@ -0,0 +1,3 @@ +brightness.py: changes brightness of laptop monitor for framework 13 AMD +sc.sh: record a video of selection of the screen +ss.sh: screenshot a selection or full area of the screen diff --git a/mangowm/brightness.py b/mangowm/brightness.py new file mode 100755 index 0000000..821c99d --- /dev/null +++ b/mangowm/brightness.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +from pathlib import Path +import sys + + +class AMDVideo: + _brightness_filepath: Path = Path("/sys/class/backlight/amdgpu_bl1/brightness") + _max_brightness_filepath: Path = Path("/sys/class/backlight/amdgpu_bl1/max_brightness") + + brightness: int|None + max_brightness: int|None + + def __init__(self): + self.brightness = self._get_file_int_value(self._brightness_filepath) + self.max_brightness = self._get_file_int_value(self._max_brightness_filepath) + + def _get_file_int_value(self, filepath: Path) -> int: + with filepath.open("r", encoding="utf-8") as f: + return int(f.read().strip()) + + def _update_file_value(self, filepath: Path, value) -> None: + with filepath.open("w+") as f: + f.write(str(value)) + + def increase_brightness(self, inc_by: int|None = None): + if not self.max_brightness: + print(f"error: max_brightness file not found {self._max_brightness_filepath}") + return + if not self.brightness: + print(f"error: brightness file not found {self._brightness_filepath}") + return + + if not inc_by: + inc_by = int(self.max_brightness / 15) + + new_val = self.brightness + inc_by + if new_val > self.max_brightness: + new_val = self.max_brightness + + self._update_file_value(self._brightness_filepath, new_val) + + def decrease_brightness(self, dec_by: int|None = None): + if not self.max_brightness: + return + if not self.brightness: + return + + if not dec_by: + dec_by = int(self.max_brightness / 15) + + new_val = self.brightness - dec_by + lowest_brightness = int(self.max_brightness * 0.05) + if new_val < lowest_brightness: + new_val = lowest_brightness + + self._update_file_value(self._brightness_filepath, new_val) + + def print_status(self): + brightness = self._get_file_int_value(self._brightness_filepath) + print(f"brightness: {brightness}") + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("need argument +/-") + exit(1) + a = AMDVideo() + if sys.argv[1] == "+": + a.increase_brightness() + if sys.argv[1] == "-": + a.decrease_brightness() + if sys.argv[1] == "status": + a.print_status() + +# +# command = "" +# +# result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) diff --git a/mangowm/sc.sh b/mangowm/sc.sh new file mode 100755 index 0000000..800867a --- /dev/null +++ b/mangowm/sc.sh @@ -0,0 +1,3 @@ +#!/bin/bash +if pgrep -x wl-screenrec > /dev/null; then pkill -INT wl-screenrec && notify-send "🎥 Recording Stopped" "Saved to ~/videos"; else GEOMETRY=$(slurp); if [ -n "$GEOMETRY" ]; then notify-send "🎥 Recording Started" "Press Super+Alt+v to stop" && wl-screenrec -g "$GEOMETRY" -f ~/videos/recording-$(date +"%Y-%m-%d_%H-%M-%S").mp4 & fi; fi +# if pgrep -x wl-screenrec > /dev/null; then pkill -INT wl-screenrec && notify-send "🎥 Recording Stopped" "Saved to ~/videos"; else GEOMETRY=$(slurp); if [ -n "$GEOMETRY" ]; then wl-screenrec -g "$GEOMETRY" -f ~/videos/recording-$(date +"%Y-%m-%d_%H-%M-%S").mp4 & fi; fi diff --git a/mangowm/ss.sh b/mangowm/ss.sh new file mode 100755 index 0000000..f483224 --- /dev/null +++ b/mangowm/ss.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +MODE=${1:-area} +OUTPUT=~/pictures/$(date +"%Y-%m-%d_%H-%M-%S").png + +case "$MODE" in + area) + grim -g "$(slurp)" - | satty --filename - --output-filename "$OUTPUT" --early-exit --copy-command wl-copy + ;; + screen) + grim -g "$(slurp -o)" - | satty --filename - --output-filename "$OUTPUT" --early-exit --copy-command wl-copy + ;; + *) + echo "Usage: $0 [area|screen]" + exit 1 + ;; +esac