You are not logged in.

#1 2022-04-21 21:17:29

omega_sine
Member
Registered: 2022-04-21
Posts: 6

DWMBlocks displaying weird symbols

I'm trying to customize my status bar on dwm using dwmblocks (I'm using Luke Smith's version of dwmblocks, if that makes a difference). I was able to find/make simple scripts that give the information I want and also managed to add emojis (downloaded libxftgra and removed the code in drw.c that prevented color emojis), but for some reason there are extra characters showing that I don't expect to be there. I don't think my scripts are the problem. Here are the ones for the cpu temp and wifi:

 sensors | awk '/Core 0/ {print "? " $3}' 
 wifi="$(cat /sys/class/net/wlp3s0/operstate)"; [ $wifi == "up" ] && echo "?" || echo "?"

Is there perhaps some font I need to additionally download? My config.h for dwm currently has this:

 static const char *fonts[]          = { "monospace:size=10", "JoyPixels:pixelsize=10:antialias=true:autohint=true" }; 
 static const char dmenufont[]       = "monospace:size=10"; 

Status bar with unrecognized characters

EDIT: Upon further research I was able to find the exact values being printed to the root window (dwm uses WM_NAME X11 property to determine what to put in the status bar):
\022ð\302\237\302\214¡+43.0°C \012ð\302\237\302\224\302\21146% \003ð\302\237\302\224\302\21368% \001Thu 04/21/22 17:51 \004ð\302\237\302\223¶

Last edited by omega_sine (2022-04-21 21:56:31)

Offline

#2 2022-04-22 07:08:24

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,691

Re: DWMBlocks displaying weird symbols

That's not a font but a locale issue.
1.

localectl; locale; locale -a

2. Post your script, notably the unicode points you're trying to pass there
3. WM_NAME is a 7-bit string property and therefore a bad choice because it will require some undefined forth-and-back decoding, if you somehow can at all, use eg. _NET_WM_NAME (which is utf-8)

Offline

#3 2022-04-22 13:08:33

omega_sine
Member
Registered: 2022-04-21
Posts: 6

Re: DWMBlocks displaying weird symbols

 [erick@arch ~]$ localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: n/a
      X11 Layout: n/a
[erick@arch ~]$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
[erick@arch ~]$ locale -a
C
en_US
en_US.iso88591
en_US.utf8
ja_JP.utf8
POSIX

These are the rest of the scripts I am using (replaced the emojis with their unicode equivalent here):

[erick@arch .scripts]$ cat blocks-volume
#!/bin/sh

vol=$(amixer get Master | awk -F'[][]' 'NR == 5 {print $2}' | tr -d %)


if [ "$vol" -gt "70" ]; then
        icon="U+1F50A" # Is a speaker on high volume
elif [ "$vol" -gt "30" ]; then
        icon="U+1F509" # Is a speaker on mid volume
elif [ "$vol" -gt "0" ]; then
        icon="U+1F508" # Is a speaker on low volume
else
        echo "U+1F507" && exit # Is a speaker on mute
fi

echo "$icon$vol%"
[erick@arch .scripts]$ cat blocks-battery
#!/bin/sh

battery="$(cat /sys/class/power_supply/BAT0/capacity)"

case $(cat /sys/class/power_supply/BAT0/status) in
        "Full") status="U+26A1" ;; # High voltage symbol
        "Discharging") status="U+1F50B" ;; # Battery symbol
        "Charging") status="U+1F50C" ;; # Electric plug symbol
        "Not charging") status="U+1F50B" ;; # Battery symbol
        "Unknown") status="U+267B" ;; # Recycling symbol
        *) exit 1 ;;
esac

[ "$status" = "U+1F50B" -a "$battery" -lt "10" ] && echo "U+2757$battery%" && exit #Battery symbol, exclamation mark

echo "$status$battery%"
#!/bin/sh

date '+%a %D %H:%M'

Not sure how helpful this is but I peeked through some of the dwm source code and it does seem to use _NET_WM_NAME already, so that was a mistake on my part:

 /* init atoms */
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);

Offline

#4 2022-04-22 14:03:20

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,691

Re: DWMBlocks displaying weird symbols

The locale looks ok.
https://www.compart.com/en/unicode/U+1F509 is "0xF0 0x9F 0x94 0x8A", octal "\360 \237 \224 \211" but the token you posted for WM_NAME (did you check _NET_WM_NAME ?) is "\012ð\302\237\302\224\302\211" so the leading byte is off and there seem stray \302 which is 0xC2 which is "Â" which is an incredibly strong indication for some bogus 8-bit encoding that transitions eg. some iso-8859 locale (what makes, well, not really but somewhat, sense in the case WM_NAME)

What if you just straight up put the utf-8 glyphs into the scripts?

Offline

#5 2022-04-22 14:58:42

omega_sine
Member
Registered: 2022-04-21
Posts: 6

Re: DWMBlocks displaying weird symbols

I did two things:
1. replaced the emojis and just inserted the unicode instead (so instead of echo "emoji" it is now echo "\U1F321").
2. Replaced my version of dwmblocks (a patched version) with the original.
Doing the first one by itself didn't change anything but doing the second seemed to fixed it. I guess there was a bug or something in the patched version, it works fine now! Thanks for the help!

Offline

Board footer

Powered by FluxBB