1

I begin with xlib and I would like to know if it is possible with xlib in C to "catch" a window with its PID for be able to move the window, resize it...?

For example ask my program the width and height of firefox's window. I do not know if my question is clearer.

Thank you

  • It looks that you want to code your Window Manager from scratch. How many years of full time work can you afford spending? – Basile Starynkevitch Feb 25 '17 at 15:34
  • Looks a bit like some [XY problem](http://xyproblem.info). What exactly do you want to achieve? So far, your comments are confusing. And you should *edit your question* to improve it (not explain it partly in comments to e.g. my answer) – Basile Starynkevitch Feb 25 '17 at 16:04

2 Answers2

3

I guess you mean the process-id of the (Linux or POSIX) client owning the window.

But your question has no real sense: the X client could be on some operating system without process-ids, or it could be running on a remote machine (different of the one running the X11 server), e.g. with ssh -X (and then you cannot do much with that pid). Be sure to understand more about the X Window System (and the roles of client, server, window manager).

However, you could study (with pain and care) X11 Window protocols and architecture (include X11 core protocol), the EWMH specifications (and also ICCCM). Look into _NET_WM_PID & XGetWMClientMachine

(Xlib & all the X protocols are really complex; you would need to read thousands of pages to understand all of them; in 2017 that effort might be obsolete, e.g. because of Wayland; it is preferable to use some higher-level toolkit like Qt or GTK).

If you want to write some X window manager (they are complex beasts, because conventions related to X have become very complex), consider studying the source code of some existing one and adapt it to your needs....

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • I begin in this domain, so I do not really know how all of it works. I would like be able with my program to get information of others windows. For example ask my program the width and height of firefox's window. I do not know if my question is clearer. Thank you for your answer –  Feb 25 '17 at 15:25
  • @wammder: that motivation should go into your question, not as a comment to my answer. So please *edit your question* – Basile Starynkevitch Feb 25 '17 at 15:26
  • It looks like you want to code some *compliant* window manager from scratch. How many years can you afford for this task? By the time you'll have something usable, X11 might have become obsolete... Several Linux distributions are switching to Wayland... – Basile Starynkevitch Feb 25 '17 at 15:29
  • Done. Sorry. I want to do it because I want to develop a VNC server, and without the xlib I don't know how I can access to the framebuffer of an other window. –  Feb 25 '17 at 15:35
  • Then I still recommend starting from the code of some *existing* VNC server, or leveraging above some *existing* X toolkit (and/or some window manager). Life is short. Your project could take you a dozen of years of full-time work. Can you afford that much time? – Basile Starynkevitch Feb 25 '17 at 15:39
  • No I have not so much time. So if I understand well, with the xlib it is hard and take long time to get information from others windows, and I have to look for another library ? –  Feb 25 '17 at 15:49
  • You need first to read a lot (in particular study the X11 protocol, the Xlib, EWMH, ICCCM; and reading all that can take months). Then you could decide what to do (and on what existing software can you leverage). Your current goals look very confusing. BTW, X11 is less sexy today than ten years ago (and Wayland could replace X11 in a few years) – Basile Starynkevitch Feb 25 '17 at 15:59
  • Why do you need to know the pid to get information from other windows? X clients usually do this with window ids and client ids, not process ids. – alanc Apr 02 '17 at 07:18
1

You could iterate through all windows and search for the program that you want by it's name. Afterwards you could use XMoveResizeWindow to move and resize as you please.

Rato Zumbi
  • 63
  • 1
  • 7