Skip to content

Latest commit

 

History

History
405 lines (284 loc) · 10.5 KB

cm533mu67000t09ma3t4m1cwc.md

File metadata and controls

405 lines (284 loc) · 10.5 KB
title seoDescription datePublished cuid slug cover tags
Hyprland Getting-Started: Configure Screen Lock, Brightness, Volume, Authentication and More
Configure various features in Hyprland, including screen lock, brightness and volume adjustment, screenshot capabilities, wallpaper changes, color picking.
Tue Dec 24 2024 23:30:24 GMT+0000 (Coordinated Universal Time)
cm533mu67000t09ma3t4m1cwc
hyprland-getting-started-configure-screen-lock-brightness-volume-authentication-and-more
programming-blogs, linux, bash, automation, hyprland

You can find the bash scripts and configurations at https://github.com/FlareXes/dotfiles. New scripts are regularly added, and existing ones are kept up to date. Feel free to explore the repository. If you have any questions, I'm here to help!

Screen Lock

Install hyprlock

sudo pacman -S hyprlock

Edit hyprland.conf under ~/.config/hypr/hyprland.conf, to lock screen on super + l.

# Mute and lock the system
bind = $mainMod, L, exec, pactl set-sink-mute @DEFAULT_SINK@ 1 && hyprlock

You can learn more about hyprlock configuration at Hyprland Wiki.

Screen Lock on Timeout

Install hypridle

sudo pacman -S hypridle

Create hypridle.conf under ~/.config/hypr/hypridle.conf, to configure idle state.

general {
    lock_cmd = pidof hyprlock || hyprlock
    before_sleep_cmd = loginctl lock-session    # lock before suspend
    after_sleep_cmd = hyprctl dispatch dpms on
}

# Lock the screen
listener {
    timeout = 300
    on-timeout = loginctl lock-session
}

# Turn off screen
listener {
    timeout = 420
    on-timeout = hyprctl dispatch dpms off
    on-resume = hyprctl dispatch dpms on
}

# Suspend the system
listener {
    timeout = 600
    on-timeout = systemctl suspend
}
  • lock_cmd: only execute hyprlock if not running, to avoid multiple instance of hyprlock.

  • Lock screen after 5 minutes without turning off the screen.

  • Turn off the screen after 7 minutes and turn on when activity is detected.

  • Suspend the system after 10 minutes to save power.

Edit ~/.config/hypr/hyprland.conf to autostart hypridle once user login.

exec-once = hypridle

You can learn more about hypridle configuration at Hyprland Wiki.

Brightness Adjustment

Install

  • bc to calculate brightness via % (percentage), required.

  • brightnessctl for brightness adjustments, required.

  • dunst to show notification or brightness level.

sudo pacman -S bc brightnessctl dunst

Edit ~/.config/hypr/hyprland.conf to control brightness via keyboard fn keys.

bind = , code:232, exec, ~/.scripts/brightness.sh dec
bind = , code:233, exec, ~/.scripts/brightness.sh inc

Create brightness.sh script under ~/.scripts/brightness.sh.

#!/usr/bin/env bash

function notify_brightness() {
  # Function to show brightness notification
  MAX_BRIGHTNESS=$(brightnessctl max)
  CURRENT_BRIGHTNESS=$(brightnessctl get) 

  BRIGHTNESS_PERCENT=$(bc <<< "scale=1; "$CURRENT_BRIGHTNESS" / "$MAX_BRIGHTNESS" * 100")
  dunstify -t 3000 -a "  Brightness" -h int:value:"$BRIGHTNESS_PERCENT" "%"
}

# Check command line arguments
if [[ "$#" != 1 || ! ("$1" == "inc" || "$1" == "dec") ]]; then
    printf "Usage: %s [inc|dec]\n" "$0" >&2
    exit 1
fi

# Check if brightnessctl is available
if ! command -v brightnessctl &> /dev/null; then
  echo "Error: brightnessctl is not installed. Please install it." >&2
  exit 1
fi

# Perform brightness adjustment
if [[ "$1" == "inc" ]]; then
  brightnessctl set +10% > /dev/null
  notify_brightness
elif [[ "$1" == "dec" ]]; then
  brightnessctl set 10%- > /dev/null
  notify_brightness
fi

Volume Adjustment

Install

  • playerctl media player controller for wide range of application. Here, required to pause audio/video.

Edit ~/.config/hypr/hyprland.conf to control volume levels via keyboard fn keys.

bindl = , XF86AudioPlay, exec, playerctl --all-players play-pause     # Pause audio/video
bindl = , XF86AudioMute, exec, ~/.scripts/volume.sh mute              # Mute audio
binde = , XF86AudioLowerVolume, exec, ~/.scripts/volume.sh dec        # Decrease Volume
binde = , XF86AudioRaiseVolume, exec, ~/.scripts/volume.sh inc        # Increase Volume

Create volume.sh script under ~/.scripts/volume.sh.

#!/bin/bash

# Function to get the current volume
get_current_volume() {
    pactl get-sink-volume @DEFAULT_SINK@ | awk '{print $5}' | sed 's/%//'
}

# Check command line arguments
if [[ "$#" != 1 || ! ("$1" == "inc" || "$1" == "dec" || "$1" == "mute" ) ]]; then
    printf "Usage: $0 [inc|dec|mute]\n"
    exit 1
fi

# Check if pactl is installed
if ! command -v pactl &> /dev/null; then
    echo "Error: pactl is not installed. Please install it and try again."
    exit 1
fi

# Perform volume adjustment
if [[ "$1" == "inc" ]]; then
    [ "$(get_current_volume)" -lt 150 ] && pactl set-sink-volume @DEFAULT_SINK@ +10%
elif [[ "$1" == "dec" ]]; then
    pactl set-sink-volume @DEFAULT_SINK@ -10%
elif [[ "$1" == "mute" ]]; then
    pactl set-sink-mute @DEFAULT_SINK@ toggle
fi

Take Screenshots

Install

  • slurp to select a region for screenshot.

  • grim a screenshot utility for Wayland.

  • imagemagick for image adjustments.

  • swappy to edit snapshots.

  • wl-clipboard to copy to clipboard.

sudo pacman -S slurp grim imagemagick swappy wl-clipboard

Create screenshot.sh script under ~/.scripts/screenshot.sh.

#!/bin/bash

# Checking and installing dependencies
dependencies=("slurp" "grim" "convert" "swappy")
for dep in "${dependencies[@]}"; do
    command -v "$dep" &> /dev/null || { echo "$dep not found, please install it."; exit 1; }
done

# Capture screenshot
screenshot="$(slurp)"

# Process the screenshot and copy to clipboard
grim -g "$screenshot" - | convert - -shave 2x2 PNG:- | wl-copy

# Notify screenshot has copied to clipboard
dunstify -t 3000 -u low -a screenshot "Screenshot copied to clipboard"

# Paste to clipboard and use swappy for further processing
wl-paste | swappy -f -

Edit ~/.config/hypr/hyprland.conf to add keybinding to take screenshot on super + s.

bind = $mainMod, S, exec, ~/.scripts/screenshot.sh

Change Wallpaper from Command-line

Install

  • hyprpaper to change wallpaper.

  • imagemagick to convert wallpaper to png.

  • file to get mine-type.

sudo pacman -S hyprpaper imagemagick file

Create hyprpaper.conf under ~/.config/hypr/hyprpaper.conf.

preload = $HOME/.cache/current_wallpaper.png
wallpaper = ,$HOME/.cache/current_wallpaper.png
splash = false

Create change-wall.sh script under ~/.scripts/change-wall.sh. Usage: change-wall.sh <image-file>.

#!/bin/bash

# Author: FlareXes
# GitHub: https://github.com/FlareXes/dotfiles/blob/main/.scripts/change-wall.sh
# Description: A hyprpaper script to updates the current wallpaper.

# Check for required dependencies
dependencies=("convert" "file" "hyprpaper")

for dep in "${dependencies[@]}"; do
    if ! command -v "$dep" >/dev/null 2>&1; then
        echo "Error: Required command '$dep' is not installed."
        echo "Install Required Dependencies: 'file', 'hyprpaper', and 'imagemagick'"
        exit 1
    fi
done

# Check if a file argument was provided
if [ -z "$1" ]; then
    echo "Error: Please provide a wallpaper file as an argument."
    echo "Usage: $0 <image_file>"
    exit 1
fi

# Check if the file exists
if [ ! -f "$1" ]; then
    echo "Error: File not found: $1"
    echo "Usage: $0 <image_file>"
    exit 1
fi

input_file="$1"
wallpaper="$HOME/.cache/current_wallpaper.png"

# Get the file MIME type
file_type=$(file --mime-type -b "$input_file")

# Check if the image is already in PNG format or convert to PNG
if [ "$file_type" == "image/png" ]; then
    echo "[INFO] The file is already in PNG format."

    # Update the current wallpaper
    cp "$input_file" "$wallpaper"
else
    echo "[INFO] Convert the image to PNG format."

    output_file="$(mktemp /tmp/current_wallpaper.XXXXXXXXX.png)"
    convert "$input_file" "$output_file"

    # Check if conversion was successful
    if [ $? -ne 0 ]; then
        echo "Error: Conversion failed."
        exit 1
    fi

    # Update the current wallpaper
    cp "$output_file" "$wallpaper"
fi

# Reload hyprpaper
killall -e hyprpaper & 
sleep 1; 
hyprpaper &

echo "[SUCCESS] Wallpaper updated successfully."

Color Picker

Install

  • hyprpicker, color picker, required.

  • imagemagick for image view in notification.

  • wl-clipboard to copy hex code to clipboard.

Create colorpicker.sh script under ~/.scripts/colorpicker.sh.

#!/bin/bash

 # Checking and installing dependencies
 dependencies=("hyprpicker" "convert")
 for dep in "${dependencies[@]}"; do
     command -v "$dep" &> /dev/null || { echo "$dep not found, please install it."; exit 1; }
 done

# Get color from hyprpicker
color=$(hyprpicker -a)

# Set image path for notification
image=/tmp/${color}.png

# Generate color image using ImageMagick
convert -size 32x32 xc:"$color" "$image"

# Display notification with color information
if [[ "$color" ]]; then
    dunstify -t 3000 -u low -a colorpicker -i "$image" "$color, copied to clipboard."
fi

Edit ~/.config/hypr/hyprland.conf to add keybinding to launch color picker on super + p.

bind = $mainMod, P, exec, ~/.scripts/colorpicker.sh

Quick and Easy

Screen Sharing

sudo pacman -S xdg-desktop-portal-hyprland

Turn Off Laptop Display on Lid Close

Edit ~/.config/hypr/hyprland.conf.

bindl = , switch:on:Lid Switch, exec, hyprctl dispatch dpms off
bindl = , switch:off:Lid Switch, exec, hyprctl dispatch dpms on

GUI Authentication

polkit-kde-agent is a polkit authentication daemon. It is required for GUI applications to be able to request elevated privileges.

sudo pacman -S polkit-kde-agent

Edit ~/.config/hypr/hyprland.conf to autostart polkit-kde-agentonce user login.

exec-once = /usr/lib/polkit-kde-authentication-agent-1