Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMonad.Hooks.DynamicLog corrupt non-ASC characters #377

Closed
2 tasks
PRESFIL opened this issue Sep 6, 2020 · 15 comments · Fixed by #471
Closed
2 tasks

XMonad.Hooks.DynamicLog corrupt non-ASC characters #377

PRESFIL opened this issue Sep 6, 2020 · 15 comments · Fixed by #471

Comments

@PRESFIL
Copy link
Contributor

PRESFIL commented Sep 6, 2020

Problem Description

I switched from xmonad-contrib==0.16-31+xmonad==0.15-51 to xmonad-contrib-git+xmonad-git. Now, in xmobar==0.35.31 characters are corrupted:
изображение
изображение

NOTE: last commit on git version - 58feba91d96fee8339d7cf56fb33537be819eb4b

Then, i switching back to xmonad-contrib==0.16-31+xmonad==0.15-51 and:
изображение
изображение

Is there are some default behavior of xmonad/X.H.DynamicLog changed or maintainer has forgotten some compile parameters for support utf-8?

Configuration File

My test configuration:

import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.EwmhDesktops
import XMonad.Layout.NoBorders
import XMonad.Util.SpawnOnce

import qualified Data.Map as M

myStartupHook = do
  spawnOnce "systemctl --user start dunst"
  spawnOnce "trayer --edge top --align right --SetDockType true --SetPartialStrut true --expand true --height 20 --transparent true --alpha 0 --tint 0x000000 --widthtype request --monitor 0"
  spawnOnce "xss-lock --transfer-sleep-lock -- sh -c \"xkb-switch -s us ; exec i3lock --nofork -c \\#000000\""

myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList
  [ ((modm .|. shiftMask, xK_z), spawn "loginctl lock-session")
  ]

myLayouts = smartBorders $ layoutHook def

main = do
  xmonad =<< xmobar (ewmhFullscreen (ewmh def
    { modMask = mod4Mask
    , keys = myKeys <+> keys def
    , startupHook = myStartupHook
    , layoutHook = myLayouts
    , handleEventHook = ewmhDesktopsEventHook <+> handleEventHook def
    }))

My fallback configuration:

import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.EwmhDesktops
import XMonad.Layout.NoBorders
import XMonad.Util.SpawnOnce

import qualified Data.Map as M

myStartupHook = do
  spawnOnce "systemctl --user start dunst"
  spawnOnce "trayer --edge top --align right --SetDockType true --SetPartialStrut true --expand true --height 20 --transparent true --alpha 0 --tint 0x000000 --widthtype request --monitor 0"
  spawnOnce "xss-lock --transfer-sleep-lock -- sh -c \"xkb-switch -s us ; exec i3lock --nofork -c \\#000000\""

myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList
  [ ((modm .|. shiftMask, xK_z), spawn "loginctl lock-session")
  ]

myLayouts = smartBorders $ layoutHook def

main = do
  xmonad =<< xmobar (ewmh def
    { modMask = mod4Mask
    , keys = myKeys <+> keys def
    , startupHook = myStartupHook
    , layoutHook = myLayouts
    })

Checklist

Other

My Linux distribution: Manjaro 20.1

I newbie. I wanted to try a new feature to use the normal fullscreen-mode implementation for Firefox (for me that worked, but this thing has appeared ;В). Thanks in advance.

@slotThe
Copy link
Member

slotThe commented Sep 6, 2020 via email

@PRESFIL
Copy link
Contributor Author

PRESFIL commented Sep 6, 2020

I updated from xmobar==0.35-31 to xmobar-git (0.36-1), but nothing changed.

My xmobar config:

Config { font = "-misc-fixed-*-*-*-*-14-*-*-*-*-*-*-*"
       , additionalFonts = []
       , wmClass = "xmobar"
       , wmName = "xmobar"
       , bgColor = "#000000"
       , fgColor = "#BFBFBF"
       , alpha   = 255
       , position = TopSize R 100 20
       , border = NoBorder
       , borderColor = "#BFBFBF"
       , borderWidth = 1
       , textOffset = -1
       , iconOffset = -1
       , textOffsets = []
       , hideOnStart = False
       , lowerOnStart = True
       , persistent = False
       , allDesktops = True
       , overrideRedirect = True
       , pickBroadest = False
       , iconRoot = "."
       , commands = [ Run Date "%a %b %_d %Y * %H:%M:%S" "theDate" 10
                    , Run StdinReader
                    , Run Battery [] 60
                    , Run Com ".config/xmobar/padding-icon.sh" [] "trayerpad" 30
                    ]
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%StdinReader% }{ %battery% * <fc=#FF0000>%theDate%</fc> * %trayerpad%"
       , verbose = False
       }

As i know, this config does not requires recompilation.

@PRESFIL
Copy link
Contributor Author

PRESFIL commented Sep 12, 2020

Temporary solved via changing xmobar font:

diff --git a/.config/xmobar/xmobarrc b/.config/xmobar/xmobarrc
index 8bd56a2..cdcbc56 100644
--- a/.config/xmobar/xmobarrc
+++ b/.config/xmobar/xmobarrc
@@ -1,4 +1,4 @@
-Config { font = "-misc-fixed-*-*-*-*-14-*-*-*-*-*-*-*"
+Config { font = "xft:monospace:size=10"
        , additionalFonts = []
        , wmClass = "xmobar"
        , wmName = "xmobar"

@TheMC47
Copy link
Member

TheMC47 commented Sep 14, 2020

Also having the issue as of yesterday, using this font="xft:SFN display:size=10,FontAwesome:size=10"

@slotThe
Copy link
Member

slotThe commented Feb 3, 2021

I guess this connected to #348 and hence the discussion in #349

(just keeping track of things so we can close this when #349 lands)

@liskin
Copy link
Member

liskin commented Feb 16, 2021

This actually sounds like #338 (comment)

@liskin
Copy link
Member

liskin commented Feb 16, 2021

@PRESFIL Just so that you understand why upgrading xmobar didn't help but switching to xft did: the ugly hack/workaround @psibi submitted to xmobar in https://github.com/jaor/xmobar/pull/482 was only implemented for xft. The xlfd code path still expects a proper unicode String (not double-utf8 encoded garbage).

I'll create a PR to fix this (#338 (comment)).

@PRESFIL
Copy link
Contributor Author

PRESFIL commented Feb 16, 2021

The screenshots in the header show that only non-latin characters are corrupted. Perhaps they remain correct because in utf-8, ASCII characters are unique and cannot be prefixes of multibyte sequences, so decoding occurs uniquely. And the rest of the characters are encoded twice.

I can still reproduce this behavior, although the xmonad's, xmonad's and xmonad-contrib's versions have go ahead.

Another question is why changing fonts solves the problem. Maybe in the XLFT handler (I don't know if I call this one -misc-fixed-*-*-*-*-14-*-*-*-*-*-*-* format correctly).
I also did not change the spawnPipe associated with it because I use it implicitly (xmonad =<< xmobar). It used to work out of the box, I would like to fix it.

In any case, I will be able to confirm if your solution works, on my host.

@liskin
Copy link
Member

liskin commented Feb 16, 2021

Another question is why changing fonts solves the problem.

“the ugly hack/workaround @psibi submitted to xmobar in jaor/xmobar#482 was only implemented for xft”

@PRESFIL
Copy link
Contributor Author

PRESFIL commented Feb 16, 2021

Ok I have nothing more to say. It seems I told you something you already know...

liskin added a commit to liskin/xmonad-contrib that referenced this issue Feb 16, 2021
…pLog'

For many (10+) years, we had a cascade of ugly workarounds:

 * X.U.Run.spawnPipe returned a binary handle, so the String passed to
   it must have been encoded by C.B.UTF8.String.encodeString

 * X.H.DynamicLog.dynamicLogString therefore returned such an encoded
   String, so one could use it directly in a hPutStrLn, but literal
   Strings wouldn't work

 * xmonadPropLog' also expected an encoded String to make it easier to
   use together with dynamicLogString, again breaking usage with String
   literals and other normal unicode Strings

Then in 1d0eadd Sibi fixed spawnPipe to return a handle usable with
normal Strings, which then obviously broke the entire cascade. But,
instead of using the opportunity to remove all the ugly workarounds, he
decided to add some more on top, so now spawnPipe with dynamicLogString
outputs doubly encoded UTF-8 and xmobar has a hack to strip this double
encoding (https://github.com/jaor/xmobar/pull/482), which only works
when XFT is in use and breaks on some long unicode codepoints. :-(

There is a better way: make everything just use normal Strings and only
encode when it goes out the wire. This means dynamicLogString can be
freely mixed with String literals, manual uses of xmonadPropLog' don't
need encodeString, and everything just works nicely.

This obviously breaks configs that used some of these pieces in
isolation (like mine), but that's a small price to pay. After all, right
now all users of spawnPipe/dynamicLogString are getting doubly encoded
UTF-8 which might or might not work in xmobar and probably breaks
horribly everywhere else, so this fix should be a clear improvement. :-)

Fixes: 1d0eadd ("Make spawnPipe to use system's locale encoding")
Fixes: xmonad#377
Fixes: https://github.com/jaor/xmobar/issues/476
Related: xmonad#334
Related: https://github.com/jaor/xmobar/pull/482
@liskin
Copy link
Member

liskin commented Feb 16, 2021

@PRESFIL Can you try #471?

liskin added a commit to liskin/xmonad-contrib that referenced this issue Feb 16, 2021
…pLog'

For many (10+) years, we had a cascade of ugly workarounds:

 * X.U.Run.spawnPipe returned a binary handle, so the String passed to
   it must have been encoded by C.B.UTF8.String.encodeString

 * X.H.DynamicLog.dynamicLogString therefore returned such an encoded
   String, so one could use it directly in a hPutStrLn, but literal
   Strings wouldn't work

 * xmonadPropLog' also expected an encoded String to make it easier to
   use together with dynamicLogString, again breaking usage with String
   literals and other normal unicode Strings

Then in 1d0eadd Sibi fixed spawnPipe to return a handle usable with
normal Strings, which then obviously broke the entire cascade. But,
instead of using the opportunity to remove all the ugly workarounds, he
decided to add some more on top, so now spawnPipe with dynamicLogString
outputs doubly encoded UTF-8 and xmobar has a hack to strip this double
encoding (https://github.com/jaor/xmobar/pull/482), which only works
when XFT is in use and breaks on some long unicode codepoints. :-(

There is a better way: make everything just use normal Strings and only
encode when it goes out the wire. This means dynamicLogString can be
freely mixed with String literals, manual uses of xmonadPropLog' don't
need encodeString, and everything just works nicely.

This obviously breaks configs that used some of these pieces in
isolation (like mine), but that's a small price to pay. After all, right
now all users of spawnPipe/dynamicLogString are getting doubly encoded
UTF-8 which might or might not work in xmobar and probably breaks
horribly everywhere else, so this fix should be a clear improvement. :-)

Fixes: 1d0eadd ("Make spawnPipe to use system's locale encoding")
Fixes: xmonad#377
Fixes: https://github.com/jaor/xmobar/issues/476
Related: xmonad#334
Related: https://github.com/jaor/xmobar/pull/482
liskin added a commit to liskin/xmonad-contrib that referenced this issue Feb 16, 2021
…pLog'

For many (10+) years, we had a cascade of ugly workarounds:

 * X.U.Run.spawnPipe returned a binary handle, so the String passed to
   it must have been encoded by C.B.UTF8.String.encodeString

 * X.H.DynamicLog.dynamicLogString therefore returned such an encoded
   String, so one could use it directly in a hPutStrLn, but literal
   Strings wouldn't work

 * xmonadPropLog' also expected an encoded String to make it easier to
   use together with dynamicLogString, again breaking usage with String
   literals and other normal unicode Strings

Then in 1d0eadd Sibi fixed spawnPipe to return a handle usable with
normal Strings, which then obviously broke the entire cascade. But,
instead of using the opportunity to remove all the ugly workarounds, he
decided to add some more on top, so now spawnPipe with dynamicLogString
outputs doubly encoded UTF-8 and xmobar has a hack to strip this double
encoding (https://github.com/jaor/xmobar/pull/482), which only works
when XFT is in use and breaks on some long unicode codepoints. :-(

There is a better way: make everything just use normal Strings and only
encode when it goes out the wire. This means dynamicLogString can be
freely mixed with String literals, manual uses of xmonadPropLog' don't
need encodeString, and everything just works nicely.

This obviously breaks configs that used some of these pieces in
isolation (like mine), but that's a small price to pay. After all, right
now all users of spawnPipe/dynamicLogString are getting doubly encoded
UTF-8 which might or might not work in xmobar and probably breaks
horribly everywhere else, so this fix should be a clear improvement. :-)

Fixes: 1d0eadd ("Make spawnPipe to use system's locale encoding")
Fixes: xmonad#377
Fixes: https://github.com/jaor/xmobar/issues/476
Related: xmonad#334
Related: https://github.com/jaor/xmobar/pull/482
@PRESFIL
Copy link
Contributor Author

PRESFIL commented Feb 17, 2021

It seems to work now with #471:
image

I hope this PR doesn't damage other bars like dzen.

@liskin
Copy link
Member

liskin commented Feb 17, 2021

I hope this PR doesn't damage other bars like dzen.

It should actually fix them rather than break them. :-)

@PRESFIL
Copy link
Contributor Author

PRESFIL commented Feb 17, 2021

Ok... 👀

slotThe pushed a commit to liskin/xmonad-contrib that referenced this issue Mar 20, 2021
…pLog'

For many (10+) years, we had a cascade of ugly workarounds:

 * X.U.Run.spawnPipe returned a binary handle, so the String passed to
   it must have been encoded by C.B.UTF8.String.encodeString

 * X.H.DynamicLog.dynamicLogString therefore returned such an encoded
   String, so one could use it directly in a hPutStrLn, but literal
   Strings wouldn't work

 * xmonadPropLog' also expected an encoded String to make it easier to
   use together with dynamicLogString, again breaking usage with String
   literals and other normal unicode Strings

Then in 1d0eadd Sibi fixed spawnPipe to return a handle usable with
normal Strings, which then obviously broke the entire cascade. But,
instead of using the opportunity to remove all the ugly workarounds, he
decided to add some more on top, so now spawnPipe with dynamicLogString
outputs doubly encoded UTF-8 and xmobar has a hack to strip this double
encoding (https://github.com/jaor/xmobar/pull/482), which only works
when XFT is in use and breaks on some long unicode codepoints. :-(

There is a better way: make everything just use normal Strings and only
encode when it goes out the wire. This means dynamicLogString can be
freely mixed with String literals, manual uses of xmonadPropLog' don't
need encodeString, and everything just works nicely.

This obviously breaks configs that used some of these pieces in
isolation (like mine), but that's a small price to pay. After all, right
now all users of spawnPipe/dynamicLogString are getting doubly encoded
UTF-8 which might or might not work in xmobar and probably breaks
horribly everywhere else, so this fix should be a clear improvement. :-)

Fixes: 1d0eadd ("Make spawnPipe to use system's locale encoding")
Fixes: xmonad#377
Fixes: https://github.com/jaor/xmobar/issues/476
Related: xmonad#334
Related: https://github.com/jaor/xmobar/pull/482
@PRESFIL
Copy link
Contributor Author

PRESFIL commented Mar 21, 2021

Thanks! 🚀

liskin added a commit to liskin/xmobar that referenced this issue Apr 27, 2021
This reverts commits c6669e2 (partially; (changelog entry kept),
73e0293, 78efa59.

These commits were introduced as a workaround for a double UTF-8
encoding bug in xmonad-contrib which itself was meant to be a
fix/workaround for another issue. We have now identified the underlying
issue and fixed it right at the root, so this entire cascade of hacky
(and wrong) workarounds can be safely reverted. Thankfully, none of the
xmonad-contrib hacks made it into a release, so there's no backward
compat to worry about.

Should anyone be interested in the details,
xmonad/xmonad-contrib@63e31cc
provides a summary and links to all the related issues and PRs.

Related: https://github.com/jaor/xmobar/pull/482
Related: https://github.com/jaor/xmobar/issues/476
Related: xmonad/xmonad-contrib@63e31cc
Related: xmonad/xmonad-contrib#471
Related: xmonad/xmonad-contrib#377
liskin added a commit to liskin/xmobar that referenced this issue Apr 27, 2021
This reverts commits c6669e2 (partially; changelog entry kept),
73e0293, 78efa59.

These commits were introduced as a workaround for a double UTF-8
encoding bug in xmonad-contrib which itself was meant to be a
fix/workaround for another issue. We have now identified the underlying
issue and fixed it right at the root, so this entire cascade of hacky
(and wrong) workarounds can be safely reverted. Thankfully, none of the
xmonad-contrib hacks made it into a release, so there's no backward
compat to worry about.

Should anyone be interested in the details,
xmonad/xmonad-contrib@63e31cc
provides a summary and links to all the related issues and PRs.

Related: https://github.com/jaor/xmobar/pull/482
Related: https://github.com/jaor/xmobar/issues/476
Related: xmonad/xmonad-contrib@63e31cc
Related: xmonad/xmonad-contrib#471
Related: xmonad/xmonad-contrib#377
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants