How to manage my application window with python-xlib?
Asked Answered
R

2

7

I would like to find a linux-wide (insofar as it uses X11) way to control the window geometry of my application, which I program using Python. All my researches point to using python-xlib, which happens to be very poorly documented.

What I'd like to achieve is:

  • define position of window on screen
  • define minimum and maximum size
  • enable / disable window resizing
  • reserve screen-space for window
  • keep window above/below
  • skip or not task-bar (aka window list)
  • set window decorated / undecorated
  • set window flags (normal, pop-up, dialogue, splash, dock, ignored)

NB: I don't want to create the with Xlib, instead I want to tell X what to do with the window i created with some GUI library (PyQt for instance).

How can I go about doing this? I realise this question is quite a big one: do you have hints at least as to how I can get hold of my window? Where in the module can I find my answers?

Edit: n.m.'s answer offered great resources, and there is also another Q&A on Unix StackExchange that provides a great example on how to get control on an application window displayed by X.

Rakish answered 30/5, 2011 at 8:25 Comment(0)
A
2

The first keyword you need to know is ICCCM. You need to be familiar with the ICCCM manual (see http://tronche.com/gui/x/icccm/) and the FreeDesktop extensions to the same (see http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html). As for your question

how I can get hold of my window?

I don't quite understand it. You call create_window and the function returns your Window object. Or do you mean something else?

Avan answered 30/5, 2011 at 13:20 Comment(3)
Thanks i'll look into the doc. By "getting hold of the window" i mean: i want to create my window in Python with PyGI, PyQt, PyWx or Kivy for instance, then i want to find this window among those X is managing, and tell X this window should be handled as i want eg. have reserved space on screen. So i don't want to create the window with xlib, i just want to tell X Window Manager what to do with it. I think i got some interesting clues from this post.Rakish
Ha! the ICCM looks like what i needed to start with. I still need some Python-xlib specific info now.Rakish
create_window returns a Python object of class Window that should contain a low-level window handle a.k.a. window ID (some integer number) in it. You probably should never use this handle directly. The library ought to wrap all necessary services in methods of the Window class, and probably in a few other functions that accept the Window object as an argument.Avan
C
1

Just discovered this yesterday and I think it's awesome compared to using variety of xdotool, wmctrl, gtk and tkinter to move windows around:

def x11_move_window(window_id_dec, x, y, width, height):
    """ Use x11 library to move window From:
        https://gist.github.com/chipolux/13963019c6ca4a2fed348a36c17e1277
    """

    import Xlib.display

    d = Xlib.display.Display()
    window = d.create_resource_object('window', window_id_dec)
    window.configure(x=x, y=y, width=width, height=height, border_width=0,
                     stack_mode=Xlib.X.Above)
    d.sync()

Note if you used wmctrl to get your window ID you need to convert it from hexadecimal to decimal before calling x11_move_window:

    window_id_hex = \
        os.popen('wmctrl -l | grep gone_fishing.png').read().strip().split()[0]

    window_id_dec = int(window_id_hex, 16)
Chore answered 22/6, 2021 at 0:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.