2

Background

I am about to resolve another issue, which consists in reserving screen-space for a Qt Window on X11. For this i use PyQt4 and Python-Xlib.

Situation

The application i want to save screen space for is a frameless Qt Window, 25px high and screen-wide, it's a panel in fact. The simplified code looks like this:

import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
# this module i made myself (see below):
import myXwindow

class QtPanel(QtGui.QWidget):

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        # here i explicitely name the window:
        self.setWindowTitle('QtPanel')
        self.resize(QtGui.QDesktopWidget().screenGeometry().width(), 25)
        self.move(0,0)
        self.setWindowFlags(QtCore.Qt.Widget |
        QtCore.Qt.FramelessWindowHint |
        QtCore.Qt.WindowStaysOnTopHint)
        self.setAttribute(QtCore.Qt.WA_X11NetWmWindowTypeDock)

    def main():
        app = QtGui.QApplication(sys.argv)
        panel = QtPanel()
        panel.show() 
        xwindow = myXwindow.Window(str(panel.windowTitle()))
        sys.exit(app.exec_())

if __name__ == '__main__':
    main()

Now to reserve space for this QtPanel application, i need to call on xlib. Here below i will just show how i intend to 'grab' my window from X. The following module is imported in the code here above to get the Xwindow of my panel:

from Xlib.display import Display
from Xlib import X

class Window(object):

    def __init__(self, title):

        self._title = title
        self._root = Display().screen().root
        self._window = self.find_window()

    def find_window(self):

        my_window = None
        display = Display()

        windowIDs = self._root.get_full_property(
                    display.intern_atom('_NET_CLIENT_LIST'),
                    X.AnyPropertyType).value

        print 'looking for windows:'
        count = 0
        for windowID in windowIDs:
            count += 1
            window = display.create_resource_object('window', windowID)
            title = window.get_wm_name()
            print 'window', count, ':', title
            if self._title in title:
                my_window = window

        return my_window

Problem

Now when i run the QtPanel application, it should return a list of names of all the windows currently displayed by X. Despite having been named explicitly in the code (see here above) the QtPanel application either has no name (i.e. None or '') or is named 'x-nautilus-desktop', here is a sample of what was returned:

$ python ./Qtpanel.py
looking for windows:
window 1 : Bottom Expanded Edge Panel
window 2 : cairo-dock
window 3 : x-nautilus-desktop
window 4 : ReserveSpace - NetBeans IDE 6.9
window 5 : How to provide X11 with a wm_name for a Qt4 window? - Stack Overflow - Mozilla Firefox

Question

How can i 'name' my Qt Application or Qt toplevel window so it shows properly on X? And/or: how can i identify my application in X other than with the application's name?

Community
  • 1
  • 1
neydroydrec
  • 6,973
  • 9
  • 57
  • 89

1 Answers1

0

Although i don't quite know what the unnamed window is (and it seems related to launching the QtPanel application, the Xlib script is not able to find the window on display because it is queried before the event loop QApplication._exec(). A thread may be required to do that outside of the main loop.

neydroydrec
  • 6,973
  • 9
  • 57
  • 89