tpaviot / pythonocc-core

Python package for 3D geometry CAD/BIM/CAM
GNU Lesser General Public License v3.0
1.39k stars 379 forks source link

Can't work on wayland #1230

Closed ovo-Tim closed 1 year ago

ovo-Tim commented 1 year ago

When I use qtViewer3d on wayland:

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  3 (X_GetWindowAttributes)
  Resource id in failed request:  0x2
  Serial number of failed request:  29
  Current serial number in output stream:  30

That's because QWidget.winId() can't return right winID on Wayland, more information: https://forum.qt.io/post/764182 So, is there any other way to display on qt?

rainman110 commented 1 year ago

Though I don't have a solution for you, it might be a good idea to look into the occt / qopenglwidget example: https://github.com/gkv311/occt-samples-qopenglwidget

I think we might be able to replicate the code with python and pythonocc.

This code basically move the OpenGl context management to qt. OCCT simply renderes into the context created by qt. This does not need to call winId, since the OpenGl context is already created.

ovo-Tim commented 1 year ago

https://github.com/gkv311/occt-samples-qopenglwidget I found that still can't work on wayland.https://github.com/gkv311/occt-samples-qopenglwidget/issues/15

ovo-Tim commented 1 year ago

I have a idea, it's not final solution, but it can work.

if platform.system() == 'Linux':
    if os.popen('echo $XDG_SESSION_TYPE').read() == 'wayland\n':
        os.environ['QT_QPA_PLATFORM'] = 'xcb'
tpaviot commented 1 year ago

I have been trying to move up to Qt6 (PyQt6 and PySide6), and face, of course, the same issue. The 'QT_QPA_PLATFORM' trick does not work on my linux machine using PyQt6 installed from pip.

A pointer: https://github.com/inviwo/inviwo/blob/aa744757d540dfb9a2b54dba646a878fc70c1478/apps/inviwopyapp/inviwo.py

tpaviot commented 1 year ago

1255 fixes the issue

ovo-Tim commented 1 year ago

1255 fixes the issue

I don't think that is the final solution. We should native support for the wayland instad of using xcb. I think we should rewrite Display3d.cpp, we may need Display3d-qt.cpp. But converting between different languages makes that difficult.

tpaviot commented 1 year ago

@ovo-Tim You're right, a specific linux tweak is required for this specific case, any contribution will be welcome.

ovo-Tim commented 1 year ago

Though I don't have a solution for you, it might be a good idea to look into the occt / qopenglwidget example: https://github.com/gkv311/occt-samples-qopenglwidget

I think we might be able to replicate the code with python and pythonocc.

This code basically move the OpenGl context management to qt. OCCT simply renderes into the context created by qt. This does not need to call winId, since the OpenGl context is already created.

@tpaviot I have no idea about how to realize it. But I think @rainman110 's advice is useful.

@rainman110 Hi, have you made any progress? 😘

tpaviot commented 1 year ago

I guess the key is here: https://github.com/gkv311/occt-samples-qopenglwidget/blob/master/occt-qopenglwidget/OcctQtViewer.cpp#L375

ovo-Tim commented 1 year ago

I guess the key is here: https://github.com/gkv311/occt-samples-qopenglwidget/blob/master/occt-qopenglwidget/OcctQtViewer.cpp#L375

I think so. But I found that it still can't work on wayland. https://github.com/gkv311/occt-samples-qopenglwidget/issues/15

One more thing, I found there is a blog that talks about wayland

However, supporting Wayland in OCCT requires further research and modifying OCCT source code. Unfortunately, there is not much of the Linux community showing an interest in providing Wayland compatibility patches to OCCT – so that this task remains a low priority feature with XWayland as a working fallback.

ovo-Tim commented 1 year ago

OK, I have posted about this problem. https://dev.opencascade.org/content/it-possible-native-support-wayland#comment-25077 https://tracker.dev.opencascade.org/view.php?id=33505

ovo-Tim commented 1 year ago

It shouldn't be closed.