Win11 中已经默认使用 wslg 来显示 WSL2 中的 GUI,不再需要额外开启 Xserver,这个确实是很方便实用的功能,但目前(2021.12)似乎还不是特别完美。我在体验的过程中就遇到了一个比较蛋疼的问题:meld 比较文件时出现异常。
meld 是一个开源的用于比较文件/文件夹的工具,类似 Beyond Compare。它可以设置为 git merge.tool,从而用于解决 git 合并时的冲突。之前 Win10+WSL2+Xserver 环境中用 meld 一直都没遇到任何问题,但在 Win11 中却会报一堆错:
Traceback (most recent call last): File "/usr/lib/python3/dist-packages/meld/diffgrid.py", line 34, in do_realize self._handle1.realize(self) File "/usr/lib/python3/dist-packages/meld/diffgrid.py", line 270, in realize attr.cursor = Gdk.Cursor.new_for_display(widget.get_display(), TypeError: constructor returned NULL Traceback (most recent call last): File "/usr/lib/python3/dist-packages/meld/diffgrid.py", line 46, in do_map self._handle1.set_visible(True) File "/usr/lib/python3/dist-packages/meld/diffgrid.py", line 288, in set_visible self._window.show() AttributeError: 'NoneType' object has no attribute 'show' Traceback (most recent call last): File "/usr/lib/python3/dist-packages/meld/diffgrid.py", line 201, in do_size_allocate self._handle1.set_visible(mapped and wlink1 > 0) File "/usr/lib/python3/dist-packages/meld/diffgrid.py", line 288, in set_visible self._window.show() AttributeError: 'NoneType' object has no attribute 'show' ...
这个问题我目前还没有在网上找到相关的解决方法,看起来是 GTK 的问题,最接近的一个帖子是:TypeError constructor returned NULL in wayland session。正巧 wslg 使用的也是 wayland,抱着试一试的心态,我打开 /usr/lib/python3/dist-packages/meld/diffgrid.py,将其中第 270 行改成:
#attr.cursor = Gdk.Cursor.new_for_display(widget.get_display(), # Gdk.CursorType. # SB_H_DOUBLE_ARROW) attr.cursor = Gdk.Cursor.new_from_name(widget.get_display(), "col-resize")
再次测试,一切正常~~
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)