xpra icon
Bug tracker and wiki

Ticket #526: win32-utf16-title.patch

File win32-utf16-title.patch, 2.1 KB (added by Antoine Martin, 6 years ago)

tries to use SetWindowTextW to set the window title

  • xpra/client/client_window_base.py

     
    2626        return x
    2727
    2828
     29#ugly workaround for buggy gtk set_title:
     30try:
     31    import ctypes
     32    from ctypes.wintypes import BOOL, HANDLE, LPCWSTR
     33    user32 = ctypes.windll.user32
     34    IsWindowUnicode = user32.IsWindowUnicode
     35    IsWindowUnicode.restype = BOOL
     36    IsWindowUnicode.argtypes = [HANDLE]
     37    SetWindowTextW = user32.SetWindowTextW
     38    SetWindowTextW.restype = BOOL
     39    SetWindowTextW.argtypes = [HANDLE, LPCWSTR]
     40except:
     41    SetWindowTextW, IsWindowUnicode = None, None
     42
     43
    2944class ClientWindowBase(ClientWidgetBase):
    3045
    3146    def __init__(self, client, group_leader, wid, x, y, w, h, metadata, override_redirect, client_properties, auto_refresh_delay, border):
     
    139154                            value = value.decode("utf-8")
    140155                        return value
    141156                    title = re.sub("@[\w\-]*@", metadata_replace, title)
    142                 utf8_title = title.encode("utf-8")
    143157            except Exception, e:
    144158                log.error("error parsing window title: %s", e)
    145                 utf8_title = ""
    146             self.set_title(utf8_title)
     159            try:
     160                log.info("user32=%s", user32)
     161                if SetWindowTextW and IsWindowUnicode:
     162                    if not self.is_realized():
     163                        self.realize()
     164                    log.info("user32.IsWindowUnicode=%s", IsWindowUnicode(self.window.handle))
     165                    log.info("user32.SetWindowTextW=%s, hwnd=%s", SetWindowTextW, self.window.handle)
     166                    SetWindowTextW(HANDLE(self.window.handle), LPCWSTR(title))
     167                else:
     168                    self.set_title(title.encode("utf-8"))
     169            except Exception, e:
     170                log.error("error setting window title: %s", e, exc_info=True)
    147171
    148172        if "icon-title" in metadata:
    149173            icon_title = metadata["icon-title"]