From 31caf2c3910164c74f4a2c973c804007bf54e248 Mon Sep 17 00:00:00 2001 From: Dmitri Date: Fri, 7 Nov 2025 09:36:15 +0100 Subject: [PATCH] notifications for media controls --- .zshrc | 2 + sway/config | 67 +++++++++++---------------- sway/scripts/notification-control.sh | 69 ++++++++++++++++++++++++++++ sway/scripts/screen-recording.sh | 30 ++++++++++++ 4 files changed, 127 insertions(+), 41 deletions(-) create mode 100755 sway/scripts/notification-control.sh create mode 100755 sway/scripts/screen-recording.sh diff --git a/.zshrc b/.zshrc index c872adc..585b1d8 100644 --- a/.zshrc +++ b/.zshrc @@ -23,6 +23,8 @@ plug "romkatv/powerlevel10k" # # nvm initialization # source /usr/share/nvm/init-nvm.sh +XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:-sway}" +MOZ_ENABLE_WAYLAND=1 alias v="nvim" alias conservation-on="sudo ectool chargecontrol normal 80 80" diff --git a/sway/config b/sway/config index 5851374..5847c10 100644 --- a/sway/config +++ b/sway/config @@ -177,36 +177,15 @@ bindsym $mod+r mode "resize" ### Notifiche e Controlli Audio/Luminosità set $notification_time 1000 -# Comandi per le notifiche (volume, mute, mic, luminosità) -set $audio_notification_cmd command -v notify-send >/dev/null && \ - VALUE=$(pactl get-sink-volume @DEFAULT_SINK@ | head -n 1 | awk '{print substr($5, 1, length($5)-1)}') && \ - notify-send -e -h string:x-canonical-private-synchronous:audio \ - -h "int:value:$VALUE" -t $notification_time "Volume: ${VALUE}%" +# Audio controls +bindsym XF86AudioMute exec ~/.config/sway/scripts/notification-control.sh mute-toggle +bindsym XF86AudioLowerVolume exec ~/.config/sway/scripts/notification-control.sh volume-down +bindsym XF86AudioRaiseVolume exec ~/.config/sway/scripts/notification-control.sh volume-up +bindsym XF86AudioMicMute exec ~/.config/sway/scripts/notification-control.sh mic-mute-toggle -set $mute_notification_cmd command -v notify-send >/dev/null && \ - VALUE=$(pactl get-sink-mute @DEFAULT_SINK@ | head -n 1 | awk '{print $2}') && \ - notify-send -e -h string:x-canonical-private-synchronous:audio \ - -h "string:x-canonical-private-synchronous:audio" -t $notification_time "Mute: ${VALUE}" - -set $mute_mic_notification_cmd command -v notify-send >/dev/null && \ - VALUE=$(pactl get-source-mute @DEFAULT_SOURCE@ | head -n 1 | awk '{print $2}') && \ - notify-send -e -h string:x-canonical-private-synchronous:audio \ - -h "string:x-canonical-private-synchronous:audio" -t $notification_time "Mic Mute: ${VALUE}" - -set $brightness_notification_cmd command -v notify-send >/dev/null && \ - VALUE=$(brightnessctl get) && \ - MAX=255 && \ - PERCENT=$((VALUE * 100 / MAX)) && \ - notify-send -e -h string:x-canonical-private-synchronous:brightness \ - -h "int:value:$PERCENT" -t $notification_time "Brightness: ${PERCENT}%" - -# Key bindings per audio e luminosità -bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle; exec $mute_notification_cmd -bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5% && $audio_notification_cmd -bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5% && $audio_notification_cmd -bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle && $mute_mic_notification_cmd -bindsym XF86MonBrightnessDown exec brightnessctl s 10%- && $brightness_notification_cmd -bindsym XF86MonBrightnessUp exec brightnessctl s 10%+ && $brightness_notification_cmd +# Brightness controls +bindsym XF86MonBrightnessDown exec ~/.config/sway/scripts/notification-control.sh brightness-down +bindsym XF86MonBrightnessUp exec ~/.config/sway/scripts/notification-control.sh brightness-up # Controlli multimediali bindsym XF86AudioPlay exec playerctl play-pause @@ -214,18 +193,24 @@ bindsym XF86AudioNext exec playerctl next bindsym XF86AudioPrev exec playerctl previous ### Screenshot e Registrazione Schermo -bindsym Print exec grimshot --notify copy output -bindsym $mod+Print exec grimshot --notify copy area -bindsym $mod+P exec grimshot --notify copy output -bindsym $mod+Shift+P exec grimshot --notify copy area +bindsym Print exec grimshot --notify copy output && \ + notify-send -u normal "📸 Screenshot" "Full screen copied to clipboard" -bindsym $mod+XF86AudioMedia exec --no-startup-id \ - (pgrep -x wf-recorder > /dev/null && killall -s SIGINT wf-recorder && notify-send "Recording Stopped") || \ - (notify-send "Recording Started + Audio." && wf-recorder --audio --file ~/Videos/$(date +'%Y-%m-%d-%H-%M-%S').mp4) +# Screenshot selected area +bindsym $mod+Print exec grimshot --notify copy area && \ + notify-send -u normal "📸 Screenshot" "Selected area copied to clipboard" -bindsym XF86AudioMedia exec --no-startup-id \ - (pgrep -x wf-recorder > /dev/null && killall -s SIGINT wf-recorder && notify-send "Recording Stopped") || \ - (notify-send "Recording Started" && wf-recorder --file ~/Videos/$(date +'%Y-%m-%d-%H-%M-%S').mp4) +# Alternative bindings +bindsym $mod+P exec grimshot --notify copy output && \ + notify-send -u normal "📸 Screenshot" "Full screen copied to clipboard" + +bindsym $mod+Shift+P exec grimshot --notify copy area && \ + notify-send -u normal "📸 Screenshot" "Selected area copied to clipboard" + +# this one includes audio track in the recording +bindsym $mod+XF86AudioMedia exec ~/.config/sway/scripts/screen-recording.sh audio +# this one not +bindsym XF86AudioMedia exec ~/.config/sway/scripts/screen-recording.sh ### Modalità per azioni di sistema (lock, logout, reboot, suspend, shutdown) set $mode_system "What to do? (l) lock, (e) logout, (r) reboot, (Shift+s) shutdown" @@ -248,8 +233,8 @@ bar { ### Borders e Gaps default_border pixel smart_gaps on -gaps outer 3 -gaps inner 5 +gaps outer 2 +gaps inner 3 # Impostazioni dei colori per il focus delle finestre client.focused $gruvbox_orange $gruvbox_orange $gruvbox_bg_dark $gruvbox_orange diff --git a/sway/scripts/notification-control.sh b/sway/scripts/notification-control.sh new file mode 100755 index 0000000..fbe6206 --- /dev/null +++ b/sway/scripts/notification-control.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +ACTION="$1" +NOTIFICATION_TIME=1000 + +case "$ACTION" in + volume-up) + pactl set-sink-volume @DEFAULT_SINK@ +5% + VALUE=$(pactl get-sink-volume @DEFAULT_SINK@ | head -n 1 | awk '{print substr($5, 1, length($5)-1)}') + notify-send -e -h string:x-canonical-private-synchronous:audio \ + -h "int:value:$VALUE" -t $NOTIFICATION_TIME "🔊 Volume" "${VALUE}%" + ;; + + volume-down) + pactl set-sink-volume @DEFAULT_SINK@ -5% + VALUE=$(pactl get-sink-volume @DEFAULT_SINK@ | head -n 1 | awk '{print substr($5, 1, length($5)-1)}') + notify-send -e -h string:x-canonical-private-synchronous:audio \ + -h "int:value:$VALUE" -t $NOTIFICATION_TIME "🔉 Volume" "${VALUE}%" + ;; + + mute-toggle) + pactl set-sink-mute @DEFAULT_SINK@ toggle + MUTED=$(pactl get-sink-mute @DEFAULT_SINK@ | awk '{print $2}') + if [ "$MUTED" = "yes" ]; then + notify-send -e -h string:x-canonical-private-synchronous:audio \ + -t $NOTIFICATION_TIME "🔇 Audio Muted" "Output muted" + else + notify-send -e -h string:x-canonical-private-synchronous:audio \ + -t $NOTIFICATION_TIME "🔊 Audio Unmuted" "Output active" + fi + ;; + + mic-mute-toggle) + pactl set-source-mute @DEFAULT_SOURCE@ toggle + MUTED=$(pactl get-source-mute @DEFAULT_SOURCE@ | awk '{print $2}') + if [ "$MUTED" = "yes" ]; then + notify-send -e -h string:x-canonical-private-synchronous:audio \ + -t $NOTIFICATION_TIME "🎤 Microphone Muted" "Mic muted" + else + notify-send -e -h string:x-canonical-private-synchronous:audio \ + -t $NOTIFICATION_TIME "🎤 Microphone Active" "Mic unmuted" + fi + ;; + + brightness-up) + brightnessctl s 10%+ + # Get current and max brightness values + CURRENT=$(brightnessctl get) + MAX=$(brightnessctl max) + PERCENT=$((CURRENT * 100 / MAX)) + notify-send -e -h string:x-canonical-private-synchronous:brightness \ + -h "int:value:$PERCENT" -t $NOTIFICATION_TIME "☀️ Brightness" "${PERCENT}%" + ;; + + brightness-down) + brightnessctl s 10%- + # Get current and max brightness values + CURRENT=$(brightnessctl get) + MAX=$(brightnessctl max) + PERCENT=$((CURRENT * 100 / MAX)) + notify-send -e -h string:x-canonical-private-synchronous:brightness \ + -h "int:value:$PERCENT" -t $NOTIFICATION_TIME "🔅 Brightness" "${PERCENT}%" + ;; + + *) + echo "Usage: $0 {volume-up|volume-down|mute-toggle|mic-mute-toggle|brightness-up|brightness-down}" + exit 1 + ;; +esac diff --git a/sway/scripts/screen-recording.sh b/sway/scripts/screen-recording.sh new file mode 100755 index 0000000..2c2649d --- /dev/null +++ b/sway/scripts/screen-recording.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +RECORD_DIR="$HOME/Videos" +TIMESTAMP=$(date +'%Y-%m-%d-%H-%M-%S') +AUDIO_FLAG="$1" + +# Create directory if it doesn't exist +if [ ! -d "$RECORD_DIR" ]; then + mkdir -p "$RECORD_DIR" + notify-send -u low "📁 Directory Created" "$RECORD_DIR" +fi + +if pgrep -x wf-recorder > /dev/null; then + killall -s SIGINT wf-recorder + notify-send -u normal "🛑 Recording Stopped" "Saved to $RECORD_DIR/" +else + if [ "$AUDIO_FLAG" = "audio" ]; then + notify-send -u normal "🔴 Recording Started" "With audio enabled" + wf-recorder --audio --file "$RECORD_DIR/${TIMESTAMP}.mp4" + else + notify-send -u normal "🔴 Recording Started" "Video only" + wf-recorder --file "$RECORD_DIR/${TIMESTAMP}.mp4" + fi + + if [ $? -eq 0 ]; then + notify-send -u normal "✅ Recording Complete" "Saved as ${TIMESTAMP}.mp4" + else + notify-send -u critical "❌ Recording Failed" "Check your configuration" + fi +fi