Bug 376813 - Does not render non-BMP characters in window titles
Summary: Does not render non-BMP characters in window titles
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: core (show other bugs)
Version: git master
Platform: Other Linux
: NOR minor
Target Milestone: ---
Assignee: Christoph Feck
URL: https://phabricator.kde.org/D19052
Keywords:
: 393740 399510 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-02-22 17:09 UTC by Christoph Feck
Modified: 2019-04-26 08:58 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.15.5
mgraesslin: Wayland-
mgraesslin: X11+
cfeck: ReviewRequest+


Attachments
Works fine on Wayland (33.07 KB, image/png)
2017-02-22 21:10 UTC, Martin Flöser
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Feck 2017-02-22 17:09:49 UTC
To reproduce:

mkdir /tmp/Test😣.txt
kwrite /tmp/Test😣.txt

The Unicode emoticon character '😣' is not rendered in the window title. It looks like it is replaced with a Space.

Happens with all decorations I tested, also with other applications like Dolphin and Konsole.
Comment 1 Christoph Feck 2017-02-22 17:10:33 UTC
ouch, replace "mkdir" with "touch". I tested both files as well as dirs for Konsole/Dolphin.
Comment 2 Martin Flöser 2017-02-22 21:10:47 UTC
Created attachment 104176 [details]
Works fine on Wayland
Comment 3 Martin Flöser 2017-02-22 21:13:08 UTC
For X11 windows I can confirm. For further investigation xprop output:

_NET_WM_USER_TIME(CARDINAL) = 5889445
_NET_WM_ALLOWED_ACTIONS(ATOM) = _NET_WM_ACTION_MOVE, _NET_WM_ACTION_RESIZE, _NET_WM_ACTION_MINIMIZE, _NET_WM_ACTION_SHADE, _NET_WM_ACTION_MAXIMIZE_VERT, _NET_WM_ACTION_MAXIMIZE_HORZ, _NET_WM_ACTION_FULLSCREEN, _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_CLOSE
_KDE_NET_WM_FRAME_STRUT(CARDINAL) = 4, 4, 29, 4
_NET_FRAME_EXTENTS(CARDINAL) = 4, 4, 29, 4
_NET_WM_DESKTOP(CARDINAL) = 0
_KDE_NET_WM_ACTIVITIES(STRING) = "24635a97-5872-486c-a356-f3951f014844"
WM_STATE(WM_STATE):
                window state: Normal
                icon window: 0x0
_NET_WM_STATE(ATOM) = 
WM_WINDOW_ROLE(STRING) = "MainWindow#1"
_KDE_NET_WM_APPMENU_OBJECT_PATH(STRING) = "/MenuBar/1"
_KDE_NET_WM_APPMENU_SERVICE_NAME(STRING) = ":1.57"
_NET_WM_ICON_NAME(UTF8_STRING) = 
_KDE_NET_WM_DESKTOP_FILE(UTF8_STRING) = "org.kde.kwrite"
_NET_WM_ICON(CARDINAL) =        Icon (16 x 16):
                        
                        
                        
                        
                        
                   ░  ░ 
                      ░ 
                      ░ 
                      ░ 
                      ░ 
                      ░ 
         ░            ░ 
         ░            ░ 
         ░            ░ 
         ░ ░          ░ 
          ░░░░░░░░░░░░  

        Icon (22 x 22):
                              
                              
                              
                              
                         ░    
                         ░    
                         ░    
                      ░  ░    
                         ░    
                         ░    
                         ░    
                         ░    
                         ░    
            ░            ░    
            ░            ░    
            ░            ░    
            ░            ░    
            ░            ░    
            ░ ░          ░    
            ░░░░░░░░░░░░░░    
                              
                              

        Icon (32 x 32):
                                        
                                        
                                        
                                        
                                  ░     
                                  ░     
                  ░░░░░ ░░░░      ░     
                                  ░     
                  ░░░░░░░ ░░      ░     
                                  ░     
                  ░░░░░░░░ ░░░░░  ░     
                                  ░     
                  ░░░░░░ ░░░░░░░  ░     
                                  ░     
                  ░░░░ ░░░░       ░     
                                  ░     
                                  ░     
                                  ░     
                  ░░░░░░░░░░ ░░░  ░     
             ░                    ░     
             ░    ░░░░ ░░░░░░░░   ░     
             ░                    ░     
             ░    ░░░░░░░         ░     
             ░                    ░     
             ░                    ░     
             ░                    ░     
             ░                    ░     
             ░                    ░     
             ░░░░░░░░░░░░░░░░░░░░░░     
              ░░░░░░░░░░░░░░░░░░░░      
                                        
                                        

        Icon (48 x 48):
                                                        
                                                        
                                                        
                                                        
                                                        
                                                        
                                                        
                                              ░         
                                              ░░        
                                              ░░        
                       ░░░░░ ░░░░ ░░░░░       ░░        
                                              ░░        
                       ░░░░░░░ ░░░ ░░░░       ░░        
                                              ░░        
                       ░░░░░░░░ ░░░░░ ░░░░    ░░        
                                              ░░        
                       ░░░░░░ ░░░ ░░░░ ░░░    ░░        
                                              ░░        
                       ░░░░ ░░░░░░░           ░░        
                                              ░░        
                                              ░░        
                                              ░░        
                       ░░░░░░░░░░ ░░░░░ ░░    ░░        
                                              ░░        
                       ░░░░ ░░░░░░░░ ░░░░     ░░        
                                              ░░        
                       ░░░░░░░ ░░░            ░░        
                                              ░░        
                ░░                            ░░        
                ░░                            ░░        
                ░░     ░░░░░░░░░░ ░░░░ ░░░    ░░        
                ░░                            ░░        
                ░░     ░░░░░░░ ░░░░ ░░░░░░    ░░        
                ░░                            ░░        
                ░░     ░░░░ ░░░░░░░░          ░░        
                ░░                            ░░        
                ░░     ░░░░░░░ ░░░░░░░        ░░        
                ░░                            ░░        
                ░░                            ░░        
                ░░                            ░░        
                ░░                            ░░        
                ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░        
                ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░        
                 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░        
                                                        
                                                        
                                                        
                                                        

        Icon (64 x 64):
                                                                        
                                                                        
                                                                        
                                                                        
                                                                        
                                                                        
                                                                        
                                                                        
                                                                        
                                                           ░            
                                                           ░░           
                           ░░░░░ ░░░░ ░░░░░░ ░░░░          ░░           
                                                           ░░           
                           ░░░░░░░ ░░░ ░░░░░░░ ░░          ░░           
                                                           ░░           
                           ░░░░░░░░ ░░░░░ ░░░░░░░          ░░           
                                                           ░░           
                           ░░░░░░ ░░░ ░░░░ ░░░░░░          ░░           
                                                           ░░           
                           ░░░░ ░░░░░░░                    ░░           
                                                           ░░           
                                                           ░░           
                                                           ░░           
                           ░░░░░░░░░░ ░░░░░ ░░ ░░░░░ ░░    ░░           
                                                           ░░           
                           ░░░░ ░░░░░░░░ ░░░░░ ░░░░░░░░    ░░           
                                                           ░░           
                           ░░░░░░░ ░░░                     ░░           
                                                           ░░           
                                                           ░░           
                                                           ░░           
                           ░░░░░░░░░░ ░░░░ ░░░░░ ░░░░░░    ░░           
                                                           ░░           
                           ░░░░░░░ ░░░░ ░░░░░░ ░░░░░ ░░    ░░           
                                                           ░░           
                           ░░░░ ░░░░░░░░ ░░░░ ░░░░░░░░░    ░░           
                                                           ░░           
                           ░░░░░░░ ░░░░░░░                 ░░           
                                                           ░░           
                                                           ░░           
                                                           ░░           
                           ░░░░░░░░░░ ░░░░░ ░░ ░░░░░ ░░    ░░           
                   ░░                                      ░░           
                   ░░      ░░░░ ░░░░░░░░ ░░░░░ ░░░░░░░░    ░░           
                   ░░                                      ░░           
                   ░░      ░░░░░░░ ░░░░ ░░░░░░ ░░░░░ ░░    ░░           
                   ░░                                      ░░           
                   ░░      ░░░░ ░░░░░░░░ ░░░░ ░░░░░░░░░    ░░           
                   ░░                                      ░░           
                   ░░      ░░░░░░░ ░░░░░░░                 ░░           
                   ░░                                      ░░           
                   ░░                                      ░░           
                   ░░                                      ░░           
                   ░░                                      ░░           
                   ░░                                      ░░           
                   ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░           
                   ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░           
                   ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░           
                                                                        
                                                                        
                                                                        
                                                                        
                                                                        
                                                                        

        Icon (128 x 128):
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                              ░                         
                                                                                                              ░░                        
                                                                                                              ░░░                       
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░  ░░░░░░░░                    ░░░░                      
                                              ░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░  ░░░░░░░░                    ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░░░░░░░  ░░░░░░  ░░░░░░░░░░░░░░  ░░░░                    ░░░░                      
                                              ░░░░░░░░░░░░░░  ░░░░░░  ░░░░░░░░░░░░░░  ░░░░                    ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░░░░░░░░░░░                    ░░░░                      
                                              ░░░░░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░░░░░░░░░░░                    ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░░░░░  ░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░                    ░░░░                      
                                              ░░░░░░░░░░░░  ░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░                    ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░  ░░░░░░░░░░░░░░                                        ░░░░                      
                                              ░░░░░░░░  ░░░░░░░░░░░░░░                                        ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░  ░░░░░░░░░░  ░░░░        ░░░░                      
                                              ░░░░░░░░░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░  ░░░░░░░░░░  ░░░░        ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░  ░░░░░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░░░░░░░░░░░░░        ░░░░                      
                                              ░░░░░░░░  ░░░░░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░░░░░░░░░░░░░        ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░░░░░░░  ░░░░░░                                          ░░░░                      
                                              ░░░░░░░░░░░░░░  ░░░░░░                                          ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░░░░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░  ░░░░░░░░░░░░        ░░░░                      
                                              ░░░░░░░░░░░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░  ░░░░░░░░░░░░        ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░        ░░░░                      
                                              ░░░░░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░        ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░  ░░░░░░░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░░░░░░░        ░░░░                      
                                              ░░░░░░░░  ░░░░░░░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░░░░░░░        ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░░░░░░░  ░░░░░░░░░░░░░░                                  ░░░░                      
                                              ░░░░░░░░░░░░░░  ░░░░░░░░░░░░░░                                  ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                                                                                              ░░░░                      
                                              ░░░░░░░░░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░  ░░░░░░░░░░  ░░░░        ░░░░                      
                                              ░░░░░░░░░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░  ░░░░░░░░░░  ░░░░        ░░░░                      
                                                                                                              ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░            ░░░░░░░░  ░░░░░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░░░░░░░░░░░░░        ░░░░                      
                              ░░░░            ░░░░░░░░  ░░░░░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░░░░░░░░░░░░░        ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░            ░░░░░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░        ░░░░                      
                              ░░░░            ░░░░░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░  ░░░░░░░░░░  ░░░░        ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░            ░░░░░░░░  ░░░░░░░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░░░░░░░        ░░░░                      
                              ░░░░            ░░░░░░░░  ░░░░░░░░░░░░░░░░  ░░░░░░░░  ░░░░░░░░░░░░░░░░░░        ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░            ░░░░░░░░░░░░░░  ░░░░░░░░░░░░░░                                  ░░░░                      
                              ░░░░            ░░░░░░░░░░░░░░  ░░░░░░░░░░░░░░                                  ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░                                                                            ░░░░                      
                              ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░                      
                              ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░                      
                              ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░                      
                              ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░                      
                              ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░                      
                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░                       
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        
                                                                                                                                        


XdndAware(ATOM) = BITMAP
WM_NAME(COMPOUND_TEXT) = "Test😣.txt "
_NET_WM_NAME(UTF8_STRING) = "Test😣.txt  — KWrite"
_KDE_NET_WM_USER_CREATION_TIME(CARDINAL) = 5881197
_MOTIF_WM_HINTS(_MOTIF_WM_HINTS) = 0x3, 0x3e, 0x7e, 0x0, 0x0
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL
_XEMBED_INFO(_XEMBED_INFO) = 0x0, 0x1
WM_CLIENT_LEADER(WINDOW): window id # 0x1400007
WM_HINTS(WM_HINTS):
                Client accepts input or input focus: True
                Initial state is Normal State.
_NET_WM_PID(CARDINAL) = 3175
_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 20971526
WM_CLASS(STRING) = "kwrite", "kwrite"
WM_PROTOCOLS(ATOM): protocols  WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST
WM_NORMAL_HINTS(WM_SIZE_HINTS):
                user specified size: 1193 by 924
                program specified minimum size: 484 by 116
                window gravity: Static
Comment 4 Martin Flöser 2017-10-22 18:31:17 UTC
I understand why it is happening (after working on caption support for wayland): on X11 bin printable characters are replaced by spaces. Relevant code is client.cpp line 1445.

Now I have two questions: what was the idea behind the string replacement and why is an emoticon not considered as a printable character?
Comment 5 Christoph Feck 2017-10-24 20:58:32 UTC
The code mentioned in comment #4 does not handle surrogate pairs correctly. A QString is UTF-16 encoded, so the U+1F623 code point for the 😣 character appears as 0xD83D 0xDE23, and both are non-printable surrogate code points.

There is a QChar::isPrint(uint) static method that works on full 32 bit code points.
Comment 6 Christoph Feck 2017-10-25 13:34:05 UTC
Untested. If this does not work, I will try a tested patch later.

        for (int i = 0; i < s.length(); ++i)
            if (!s[i].isPrint()) {
                if (s[i].isHighSurrogate() && i + 1 < s.length() && s[i + 1].isLowSurrogate()) {
                    uint uc = QChar::surrogateToUcs4(s[i], s[i + 1]);
                    if (QChar::isPrint(uc)) {
                        // also skip low surrogate
                        ++i;
                        continue;
                    }
                }
                s[i] = QChar(u' ');
            }

This only replaces wrong surrogates (not paired), and unprintable paired surrogates with spaces.
Comment 7 Martin Flöser 2018-05-01 18:53:03 UTC
*** Bug 393740 has been marked as a duplicate of this bug. ***
Comment 8 Karl Ove Hufthammer 2018-05-01 19:49:18 UTC
Bug #393740 was marked as duplicate of this bug. That that bug was about soft hyphens being rendered as spaces. But note that soft hyphens are not non-BMP characters; they’re even part of ISO 8859-1. Is the problem with rendering soft hyphens that they’re defined as ‘non-printable’?
Comment 9 Christoph Feck 2018-10-08 10:00:09 UTC
*** Bug 399510 has been marked as a duplicate of this bug. ***
Comment 10 Christoph Feck 2019-02-15 19:14:39 UTC
Patch from comment would not fix bug 393740. I plan to change it to simply omit unprintable characters.
Comment 11 Christoph Feck 2019-04-26 08:58:28 UTC
Git commit 57440d1d6b490cdad51266977d0269a08918b82f by Christoph Feck.
Committed on 26/04/2019 at 08:52.
Pushed by cfeck into branch 'Plasma/5.15'.

Fix captions with non-BMP characters

KWin replaces any non-printable character with a space. This check does not
handle surrogate pairs correctly. Additionally, translators sometimes insert
non-printable soft-hyphens into titles, which also cause KWin to display a
space instead.

This code adds the missing surrogate handling, and (to fix both issues), also
removes non-printable characters instead of replacing them with a space.

Also moved the changed test after these changes, so that changes in non-
printable characters do not cause unneeded redraws.

Unit tests adapted by Vlad Zagorodniy.

Test Plan:

kwrite /tmp/Test😣.txt shows correct title. I also tested actual non-printable
characters, such as 0x1A, and these are correctly omitted.
FIXED-IN: 5.15.5

Reviewers: #kwin, zzag

Reviewed By: #kwin, zzag

Subscribers: zzag, grasslin, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D19052

M  +20   -9    autotests/integration/x11_client_test.cpp
M  +19   -5    client.cpp

https://commits.kde.org/kwin/57440d1d6b490cdad51266977d0269a08918b82f