Python: say X to reserve screen space for application

I am trying to solve the problem of screen space reservation for an application with X Window Manager (i.e. on Linux platforms). I saw this problem addressed and resolved for Gtk , and I asked the same question invited using Qt . Since no one responded to a Qt-specific question (which I also addressed in other forums), I thought I would summarize my question:

Is there a universal pythonic way to tell X to reserve screen space for an application?

Thanks,
Benjamin

+4
source share
2 answers

After some research, I found a solution using Python-Xlib .

In the code that generates the window, you can get the window identifier, which is the link for the window to X. Depending on the GUI set used, the method for obtaining this identifier may differ. Qt4 provides QWidget.winId() , Gtk + 2 has its own tools for reserving window space, and I have not tried with Gtk + 3, but I was told that there should be a window_id attribute.

Since the call to X to reserve space for the window can be made only after the window is displayed, in most cases it will be necessary to make a request after the main event loop has been entered.

The example below shows an example with Qt4 using PyQt4. To get a window after it is displayed, the thread starts before QApplication enters its main loop, and this thread continues polling X until it can "capture" the window. In the following example, space is reserved at the top of the screen, with a height equivalent to the height of QWidget, reserve space for.

 def fix_window(self): set = False while set == False: try: window = myXwindow.Window(self.parent().winId()) if window != None: height = self.parent().height() window.reserve_space(0, 0, height, 0) set = True else: self.sleep(1) except: raise 

In the above example, myXwindow is a custom module using Python-Xlib. The content of the module is shown below, where Xlib requests X for Display () and subsequently creates a window object, which is an abstract model for linking to our window displayed by X. After changing the attributes of this model, we can display (). sync () to apply the changes. The space reservation method change_property() , in which a series of arguments are passed in accordance with the Freedesktop.org Standards .

class Window (object):

 def __init__(self, windowID): self._display = Display() self._window = self._display.create_resource_object('window', windowID) def reserve_space(self, left=0, right=0, top=0, bottom=0): LEFT = left RIGHT = right TOP = top BOTTOM = bottom self._window.change_property(self._display.intern_atom('_NET_WM_STRUT'), self._display.intern_atom('CARDINAL'), 32, [LEFT, RIGHT, TOP, BOTTOM]) self._display.sync() 

NB: it is important to keep the same Display () instance that created the window object in order to change the properties of the window, so it is stored in a variable.

+5
source

Hm, I'm not sure you can. Your OS reserves a page in memory for user processes. A process may have malloc () memory space, but it will be within the reserved fragments provided by the kernel for the current process address space. Will you use the application as a child process? or executing a new instance?

0
source

All Articles