FYI: How to control a window position from an external process.
Hiroyuki Komatsu
komatsu at taiyaki.org
Fri Dec 19 17:23:25 CST 2003
FYI, Here is a tip to control a window postion from an external
porcess.
== Windows ==
It is quite easy on Windows. Like here,
import win32gui
def move_window(self, hwnd, x, y):
(x1, y1, x2, y2) = win32gui.GetWindowRect(hwnd)
width = x2 - x1
height = y2 - y1
redraw = 1 # True
win32gui.MoveWindow(hwnd, x, y, width, height, redraw)
The valuable 'hwnd' is a window-id for Windows. The following code
detects all of hwnd values.
def get_hwnd_list(self):
hwnd_list = [] # hwnd is an ID for window system in Windows.
win32gui.EnumWindows(self._handler_EnumWindows, hwnd_list)
return hwnd_list
def _handler_EnumWindows(self, hwnd, window_list):
window_list.append(hwnd)
== X ==
Though the Python-xlib library possibly control a window position of
another process, I have not found it yet. So I wrote a module for it.
The module is available at
<http://www.accessgrid.org/~komatsu/window-control-0.0.1.tar.gz>.
The files of the module are 'winctrl.py' and '_winctrl.so'.
A sample code is here,
import winctrl
winctrl.move_window(xwinid, x, y)
The valuable 'xwinid' is a window-id for X. The following code
detects all of xwinid values.
from Xlib import X, display, Xatom
def __init__(self):
self.display = display.Display()
self.root_window = self.display.screen().root
def get_xwinid_list(self):
xwininfo = self.root_window.query_tree()
return xwininfo.children
You may need to execute the following function _XmuClientWindow to
get non window manager's windows.
def _XmuClientWindow(self, xwin):
if xwin.get_wm_state():
return xwin
else:
xwin_tree = xwin.query_tree()
for child in xwin_tree.children:
if child.get_wm_state():
return child
return xwin
I am thinking I will create a pager to control windows' geometries of
vic, shared apps and so on for AG. In the feature it would be able to
control a window layout of another machine via AG, if you need.
--
Hiro
More information about the ag-dev
mailing list