qtqt4pyqt4rxvt

PyQT(also C++ QT binding) embedded urxvt terminal loosing focus


I have problem with embedding urxvt terminal within QT application. Below is simplified code example. When i create a QT window and embed urxvt terminal inside(by using -embed parameter), i have a problem with focus. When the window is created, the first click into window make focus on embedded terminal -> everything ok, But when i click into the window second time, the terminal seems to loose the focus, though normal keyboard and mouse input is still working. But the terminal itself seems to think, it has no focus. It seems, like events are still sent to the embed window, though it has no focus. Same problem appears when using C++ QT bindings.

It is nicely visible when add setting to .Xdefaults(and running necessary xrdb -load .Xdefaults): URxvt*fading: -40

Here is simplified example:

import  sys 
from PyQt4.QtCore import *
from PyQt4.QtGui import *


class embterminal(QWidget): 

    def __init__(self):
        QWidget.__init__(self)
        self.setGeometry(1,1,600,400)
        self.process = QProcess(self)

        self.terminal = QX11EmbedContainer(self)
        layout = QVBoxLayout(self)
        layout.addWidget(self.terminal)

        self.terminal.showMaximized();

        self.process.start('urxvt',['-embed', str(self.terminal.winId())])

if __name__ == "__main__":
    app = QApplication(sys.argv)
    main = embterminal()
    main.show()
    sys.exit(app.exec_())`

Solution

  • From the docs for QX11EmbedContainer:

    It is possible for QX11EmbedContainer to embed XEmbed widgets from toolkits other than Qt, such as GTK+. Arbitrary (non-XEmbed) X11 widgets can also be embedded, but the XEmbed-specific features such as window activation and focus handling are then lost.

    So perhaps urxvt (or your version of it) does not support all the necessary features of the XEmbed Protocol.

    A web search turned up this comment:

    urxvt -embed almost works. It claims to support it and everything, but does not send XEMBED_REQUEST_FOCUS when you click in it. This means there's no way to get focus back after it's lost it.