~kris/dots

srice

ref: e98f3b030dc24445bd55c68d95d2d81933fd68b3 srice/.local/bin/system/laptop -rw-r--r-- 6.5 KiB
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/sh
# ==============================================================
#  Laptop HiDPI Setup Script
# --------------------------------------------------------------
#  Author   : Kris Yotam (aka. khr1st)
#  Contact  : krisyotam@protonmail.com
#  License  : GNU GPLv3
#  Date     : 2025-09-29
# --------------------------------------------------------------
#  Description:
#    - Set xrandr DPI for HiDPI displays (immediate effect).
#    - Update xprofile to persist DPI across reboots.
#    - Update ~/.Xresources for terminal fonts and DPI.
#    - Update dwm/st config.def.h files for git-safe persistence.
#    - Creates device flag file for permanent laptop designation.
#    - Backups are made before modifying files.
#    - Created for Macbook Pro 2015 13" Retina (Model A1502)
# ==============================================================

DPI_VALUE=150
FONT="Monospace:size=12"
DWM_FONT_SIZE=11
DWM_EMOJI_SIZE=16
ST_FONT_SIZE=14

# Device flag directory and file
DEVICE_FLAG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/lazykris"
DEVICE_FLAG_FILE="$DEVICE_FLAG_DIR/device-type"

# ==============================================================
# Create device flag for permanent laptop designation
# ==============================================================
mkdir -p "$DEVICE_FLAG_DIR"
echo "laptop" > "$DEVICE_FLAG_FILE"
echo "[ok] Device marked as laptop in $DEVICE_FLAG_FILE"

# ==============================================================
# Apply DPI change immediately
# ==============================================================
xrandr --dpi "$DPI_VALUE"

# ==============================================================
# Backup and patch xprofile for persistent DPI
# ==============================================================
XPROFILE_XDG="${XDG_CONFIG_HOME:-$HOME/.config}/x11/xprofile"
XPROFILE_HOME="$HOME/.xprofile"

if [ -f "$XPROFILE_XDG" ]; then
    XPROFILE="$XPROFILE_XDG"
elif [ -f "$XPROFILE_HOME" ]; then
    XPROFILE="$XPROFILE_HOME"
else
    XPROFILE="$XPROFILE_XDG"
    mkdir -p "$(dirname "$XPROFILE")"
fi

if [ -f "$XPROFILE" ]; then
    cp "$XPROFILE" "$XPROFILE.bak.$(date +%s)"
    if grep -q "^xrandr --dpi" "$XPROFILE"; then
        sed -i "s/^xrandr --dpi.*/xrandr --dpi $DPI_VALUE\t\t# Set DPI for laptop HiDPI/" "$XPROFILE"
    else
        if head -1 "$XPROFILE" | grep -q "^#!"; then
            sed -i "2i xrandr --dpi $DPI_VALUE\t\t# Set DPI for laptop HiDPI" "$XPROFILE"
        else
            sed -i "1i xrandr --dpi $DPI_VALUE\t\t# Set DPI for laptop HiDPI" "$XPROFILE"
        fi
    fi
else
    cat > "$XPROFILE" << EOF
#!/bin/sh
xrandr --dpi $DPI_VALUE		# Set DPI for laptop HiDPI
EOF
fi
echo "[ok] Updated $XPROFILE"

# ==============================================================
# Backup and patch ~/.Xresources
# ==============================================================
XRES="$HOME/.Xresources"
[ -f "$XRES" ] && cp "$XRES" "$XRES.bak.$(date +%s)"

# Ensure DPI line
if grep -q "^Xft.dpi:" "$XRES" 2>/dev/null; then
    sed -i "s/^Xft.dpi:.*/Xft.dpi: $DPI_VALUE/" "$XRES"
else
    echo "Xft.dpi: $DPI_VALUE" >> "$XRES"
fi

# Ensure terminal font line
if grep -q "^st.font:" "$XRES" 2>/dev/null; then
    sed -i "s/^st.font:.*/st.font: $FONT/" "$XRES"
else
    echo "st.font: $FONT" >> "$XRES"
fi

xrdb -merge "$XRES"
echo "[ok] Updated $XRES"

# ==============================================================
# Patch dwm config files (both config.h AND config.def.h)
# ==============================================================
DWM_DIR="$HOME/.local/src/dwm"
DWM_CONFIG="$DWM_DIR/config.h"
DWM_CONFIG_DEF="$DWM_DIR/config.def.h"

patch_dwm_config() {
    local config_file="$1"
    if [ -f "$config_file" ]; then
        cp "$config_file" "$config_file.bak.$(date +%s)"
        sed -i "s/monospace:size=[0-9]*/monospace:size=$DWM_FONT_SIZE/" "$config_file"
        sed -i "s/NotoColorEmoji:pixelsize=[0-9]*/NotoColorEmoji:pixelsize=$DWM_EMOJI_SIZE/" "$config_file"
        echo "[ok] Updated $config_file"
    fi
}

if [ -d "$DWM_DIR" ]; then
    patch_dwm_config "$DWM_CONFIG"
    patch_dwm_config "$DWM_CONFIG_DEF"
    echo "[..] Rebuilding dwm..."
    cd "$DWM_DIR" && sudo make clean install >/dev/null 2>&1
    echo "[ok] dwm rebuilt with bar font size=$DWM_FONT_SIZE"
fi

# ==============================================================
# Patch st config files (both config.h AND config.def.h)
# ==============================================================
ST_DIR="$HOME/.local/src/st"
ST_CONFIG="$ST_DIR/config.h"
ST_CONFIG_DEF="$ST_DIR/config.def.h"

patch_st_config() {
    local config_file="$1"
    if [ -f "$config_file" ]; then
        cp "$config_file" "$config_file.bak.$(date +%s)"
        # Update default font size in st
        sed -i "s/pixelsize=[0-9]*/pixelsize=$ST_FONT_SIZE/" "$config_file"
        echo "[ok] Updated $config_file"
    fi
}

if [ -d "$ST_DIR" ]; then
    patch_st_config "$ST_CONFIG"
    patch_st_config "$ST_CONFIG_DEF"
    echo "[..] Rebuilding st..."
    cd "$ST_DIR" && sudo make clean install >/dev/null 2>&1
    echo "[ok] st rebuilt with font pixelsize=$ST_FONT_SIZE"
fi

# ==============================================================
# Patch dwmblocks config if exists
# ==============================================================
DWMBLOCKS_DIR="$HOME/.local/src/dwmblocks"
if [ -d "$DWMBLOCKS_DIR" ]; then
    echo "[..] Rebuilding dwmblocks..."
    cd "$DWMBLOCKS_DIR" && sudo make clean install >/dev/null 2>&1
    echo "[ok] dwmblocks rebuilt"
    # Kill and restart dwmblocks with proper signal handling for clickability
    pkill -x dwmblocks
    sleep 0.5
    setsid -f dwmblocks
    echo "[ok] dwmblocks restarted with clickability"
fi

# ==============================================================
# Summary
# ==============================================================
echo ""
echo "=============================================================="
echo " Laptop mode enabled with persistent settings"
echo "=============================================================="
echo " DPI:            $DPI_VALUE"
echo " Terminal font:  $FONT"
echo " DWM bar font:   monospace:size=$DWM_FONT_SIZE"
echo " DWM emoji:      NotoColorEmoji:pixelsize=$DWM_EMOJI_SIZE"
echo " ST font:        pixelsize=$ST_FONT_SIZE"
echo " Device flag:    $DEVICE_FLAG_FILE"
echo ""
echo " Settings are now permanent and will persist across:"
echo "   - Reboots (via xprofile and Xresources)"
echo "   - Git pulls (config.def.h files updated)"
echo ""
echo " [!!] Restart dwm (Mod+Shift+Ctrl+q) for changes to take effect"
echo "=============================================================="