Results 1 to 2 of 2

Thread: converting X-Window compound strings

  1. #1
    Join Date
    Apr 2006
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default converting X-Window compound strings

    Hello!

    I am hacking some stuff which is dealing with window names which I retrieve via XGetWindowProperty(). These strings may contain special escape sequences to switch between encodings. As I found out, the sequence ESC % G switches the encoding to UTF 8 whereas the sequence ESC % @ switches back to ??? (Seems to be Latin1)

    I was searching the web and I found some statements, that it is similar to ISO 2022 encoding, but Qt's QTextCodec for "ISO 2022-JP" does not a good job :-(

    I also found some paper describing that format, but this one is (at least for me) hard to understand: http://www.x.org/releases/X11R7.7/do...ext/ctext.html

    Does anybody know some standard function, maybe inside the libraries of the X Window system which I can use to translate that encoding into UTF-8?

    To see what strings I mean, use this on the command line
    $ xprop -f WM_NAME 8s | grep WM_NAME
    When you started (for example) kpat (the KDE solitaire) and start some game, then you see that line:
    > WM_NAME(COMPOUND_TEXT) = "Klondike - 1966183630 \033%G\342\200\223\033%@ KPatience"

    As I said, there are more of those escape sequences, when you open rutube.ru in firefox, you can see
    > WM_NAME(COMPOUND_TEXT) = "Rutube \033%G\342\200\224\033%@ \033-L\322\341\361 \322\330\324\325\336 - Mozilla Firefox"
    So here is a sequence ESC - L which seems to switch to cyrillic characters.

  2. #2
    Join Date
    Apr 2006
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [SOLVED] Re: converting X-Window compound strings

    Finally I found a way to decode that string without home-brewed code.

    Qt Code:
    1. QString Reader::toString(QByteArray const &line)
    2. {
    3. if(line.indexOf("\033") == -1)
    4. return QString(line);
    5.  
    6. XTextProperty tp;
    7. tp.value = const_cast<unsigned char *>((unsigned char const *)line.data());
    8. tp.encoding = XInternAtom(QX11Info::display(), "COMPOUND_TEXT", true);
    9. tp.format = 8;
    10. tp.nitems = line.length();
    11.  
    12. char **retList;
    13. int retListLength = -1;
    14. int ret = Xutf8TextPropertyToTextList(QX11Info::display(), &tp, &retList, &retListLength);
    15. if(ret == Success && retListLength == 1) {
    16. QString s = QString::fromUtf8(*retList);
    17. free(*retList);
    18. return s;
    19. }
    20. … some more code if there are multiple lines …
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Creating compound paths
    By bassPenguin in forum Qt Programming
    Replies: 3
    Last Post: 28th March 2012, 11:57
  2. Unicode strings int Qt 4.2.1
    By mkrentovskiy in forum Qt Programming
    Replies: 12
    Last Post: 29th December 2011, 09:02
  3. Replies: 6
    Last Post: 9th November 2011, 04:31
  4. converting strings into enums
    By ugluk in forum Qt Programming
    Replies: 5
    Last Post: 26th August 2011, 10:59
  5. Replies: 12
    Last Post: 24th June 2011, 09:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.