How can I move a window created using PySide using the window manager?
I see that kdeui has a class NETRootInfowith a method moveResizeRequestthat does exactly what I want. Following:
from PySide.QtCore import Qt
from PyKDE4 import kdeui
from PySide.QtGui import QX11Info
import sys
from ctypes import CDLL
Xlib = CDLL('libX11.so.6')
def move_window(window, event):
if event.buttons() & Qt.LeftButton:
pos = event.buttonDownScreenPos(Qt.LeftButton)
Xlib.XUngrabPointer(QX11Info.display(), QX11Info.appTime())
rootinfo = kdeui.NETRootInfo(QX11Info.display(), kdeui.NET.WMMoveResize)
rootinfo.moveResizeRequest(window.winId(), pos.x(), pos.y(), kdeui.NET.Move)
gives me:
TypeError: NETRootInfo(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'int'
overload 2: argument 1 has unexpected type 'int'
overload 3: argument 1 has unexpected type 'int'
overload 4: argument 1 has unexpected type 'int'
This error is caused by the fact that it QX11Info.display()returns a long (pointer), and not a display structure.
I can use PyQt4 QX11Info.display()as the first parameter for the constructor NETRootInfoinstead of PySide, for example:
...
from PySide.QtGui import QX11Info
from PyQt4.QtGui import QX11Info as QX11InfoQt
...
def move_window(window, event):
if event.buttons() & Qt.LeftButton:
pos = event.buttonDownScreenPos(Qt.LeftButton)
Xlib.XUngrabPointer(QX11Info.display(), QX11Info.appTime())
rootinfo = kdeui.NETRootInfo(QX11InfoQt.display(), kdeui.NET.WMMoveResize)
rootinfo.moveResizeRequest(window.winId(), pos.x(), pos.y(), kdeui.NET.Move)
But this adds PyQt4 dependency in addition to PySide.
In addition, I tried to use the Xlib function XMoveWindow, but this does not allow partially dragging the window off the screen and does not provide movement feedback (for example, transparency effects) provided by window managers such as Compiz or KWin.
:
- PySide
QX11Info.display() "", kdeui.NETRootInfo, - Python Xlib (
python-xlib, libX11.so) _NET_WM_MOVERESIZE ?