diff --git a/source/native-plugins/resources/carla-plugin b/source/native-plugins/resources/carla-plugin index 07e64de5c..11bf70016 100755 --- a/source/native-plugins/resources/carla-plugin +++ b/source/native-plugins/resources/carla-plugin @@ -405,48 +405,79 @@ class CarlaMiniW(ExternalUI, HostWindow): # ------------------------------------------------------------------------------------------------------------ # Embed Widget -if LINUX and config_UseQt5: +if config_UseQt5 and LINUX: from PyQt5.QtGui import QMouseEvent class QEmbedWidget(QWidget): - def __init__(self): + def __init__(self, winId): QWidget.__init__(self) self.setAttribute(Qt.WA_LayoutUsesWidgetRect) - - self.fPos = (0, 0) self.move(0, 0) + self.fPos = (0, 0) self.fWinId = 0 - def eventFilter(self, obj, ev): - if isinstance(ev, QMouseEvent): - pos = gCarla.utils.x11_get_window_pos(self.fWinId) - if self.fPos != pos: - self.fPos = pos - self.move(pos[0], pos[1]) - gCarla.utils.x11_move_window(self.fWinId, 0, 0) - return False + def getWidget(self): + return self def finalSetup(self, gui, winId): self.fWinId = int(self.winId()) + gui.ui.centralwidget.installEventFilter(self) gui.ui.menubar.installEventFilter(self) gCarla.utils.x11_reparent_window(self.fWinId, winId) self.show() -elif LINUX and not config_UseQt5: + def fixPosition(self): + pos = gCarla.utils.x11_get_window_pos(self.fWinId) + if self.fPos == pos: + return + self.fPos = pos + self.move(pos[0], pos[1]) + gCarla.utils.x11_move_window(self.fWinId, 0, 0) + + def eventFilter(self, obj, ev): + if isinstance(ev, QMouseEvent): + self.fixPosition() + return False + + def enterEvent(self, ev): + self.fixPosition() + QWidget.enterEvent(self, ev) + +elif config_UseQt5 and not LINUX: + from PyQt5.QtGui import QWindow + + class QEmbedWidget(object): + def __init__(self, winId): + self.fWindow = QWindow.fromWinId(winId) + self.fWidget = QWidget.createWindowContainer(self.fWindow) + self.fWidget.setAttribute(Qt.WA_LayoutUsesWidgetRect) + + # TODO: show/hide/close events + + def getWidget(self): + return self.fWidget + + def finalSetup(self, gui, winId): + self.fWidget.show() + +elif not config_UseQt5 and LINUX: from PyQt4.QtGui import QX11EmbedWidget class QEmbedWidget(QX11EmbedWidget): - def __init__(self): + def __init__(self, winId): QX11EmbedWidget.__init__(self) + def getWidget(self): + return self + def finalSetup(self, gui, winId): self.embedInto(winId) self.show() else: class QEmbedWidget(object): - def __init__(self, winId, width, height): + def __init__(self, winId): print("Cannot use embed UI with this configuration") raise Exception @@ -455,18 +486,19 @@ else: class CarlaEmbedW(QEmbedWidget): def __init__(self, host, winId): - QEmbedWidget.__init__(self) - self.setFixedSize(740, 512) + QEmbedWidget.__init__(self, winId) self.host = host self.fWinId = winId + self.fWidget = self.getWidget() + self.fWidget.setFixedSize(740, 512) - self.fLayout = QVBoxLayout(self) + self.fLayout = QVBoxLayout(self.fWidget) self.fLayout.setContentsMargins(0, 0, 0, 0) self.fLayout.setSpacing(0) - self.setLayout(self.fLayout) + self.fWidget.setLayout(self.fLayout) - self.gui = CarlaMiniW(host, self) + self.gui = CarlaMiniW(host, self.fWidget) self.gui.hide() self.gui.ui.act_file_quit.setEnabled(False) @@ -493,7 +525,7 @@ class CarlaEmbedW(QEmbedWidget): self.addWidget(self.gui.centralWidget()) self.finalSetup(self.gui, winId) - self.gui.send(["ready", int(self.winId())]) + self.gui.send(["ready", int(self.fWidget.winId())]) def addShortcutActions(self, actions): for action in actions: @@ -501,11 +533,11 @@ class CarlaEmbedW(QEmbedWidget): self.fShortcutActions.append(action) def addWidget(self, widget): - widget.setParent(self) + widget.setParent(self.fWidget) self.fLayout.addWidget(widget) def addLine(self): - line = QFrame(self) + line = QFrame(self.fWidget) line.setFrameShadow(QFrame.Sunken) line.setFrameShape(QFrame.HLine) line.setLineWidth(0)