Re: window configuration events

Bart Massey <[email protected]> Thu, 25 Jul 2024 09:39:13 -0700
Newsgroups gmane.comp.freedesktop.xcb
Message-ID <CAA6gtpnfFvu-vw1yQPBRL6AYQGJE70w4tcKKAmUZQXU6MN3vjg@mail.gmail.com>
--0000000000001ed61e061e150b82
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

The GetGeometry request is responded to by the server, not the window
manager (
https://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.html#requests:Get=
Geometry).
However, a window manager may choose to reparent a top-level window (
https://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html#reparen=
ting).
Thus, finding out the x,y position of the window manager's window on the
root window requires some doing. I think the way to do this is to send a
ConfigureWindow request that doesn't change anything and then listen for
the synthetic ConfigureNotify event that will have the top-level x,y in
root coordinates (
https://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html#configu=
ring_the_window
).

On Thu, Jul 25, 2024 at 7:04=E2=80=AFAM Steven J Abner <[email protected]=
> wrote:

>   In creating an event loop, I'm trying to avoid having inaccurate
> data. I found that window managers are apparently sending the events
> and not the Xserver. I would like to have the actual position of a
> window for data passed along to others.
>   Unfortunately the xcb_configure_notify_event_t sent by window mangers
> is a guess, at least on 2 that I've tried. Fortunately the width,
> height have tested the same, so can use to configure drawing ports.
>   Sadly I am too much of a newbie and can't figure how to get the
> geometry of a window's x,y position. Here's the code in my attempt:
>
>   xcb_configure_notify_event_t *configure;
>   configure =3D (xcb_configure_notify_event_t*)nvt;
>   int16_t hD =3D configure->width - iface->mete_box.w;
>   int16_t vD =3D configure->height - iface->mete_box.h;
>   if ((hD !=3D 0) || (vD !=3D 0))
>     _interface_configure(iface, hD, vD);
>   if ((configure->x | configure->y) !=3D 0) {
>     xcb_get_geometry_cookie_t cookie;
>     cookie =3D xcb_get_geometry(connection, iface->window);
>     xcb_get_geometry_reply_t *cfg;
>     cfg =3D xcb_get_geometry_reply(connection, cookie, NULL);
>     if ((cfg->x !=3D configure->x) || (cfg->y !=3D configure->y)) {
>       printf("%d, { %d,%d } cfg { %d,%d }\n",
>              iface->window,
>              configure->x, configure->y, cfg->x, cfg->y);
>     }
>     free(cfg);
>
>     master_iface->mete_box.x =3D configure->x;
>     master_iface->mete_box.y =3D configure->y;
>   }
>
> I get a result of this on one manger, that actually provides the
> correct x,y on configure events:
>
> window 71303168, CONFIGURE_NOTIFY. (101,223,800,200)
> 71303168, { 101,223 } cfg { 0,0 }
>
> Can you please help me get the window's position from xcb. I'm not at a
> point to learn Xlib's XGetWindowAttributes() nor desire to write off my
> ignorance on xcb's API.
>
> Steve
>
>
>

--0000000000001ed61e061e150b82
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>The GetGeometry request is responded to by the server=
, not the window manager (<a href=3D"https://www.x.org/releases/X11R7.7/doc=
/xproto/x11protocol.html#requests:GetGeometry">https://www.x.org/releases/X=
11R7.7/doc/xproto/x11protocol.html#requests:GetGeometry</a>). However, a wi=
ndow manager may choose to reparent a top-level window (<a href=3D"https://=
x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html#reparenting">ht=
tps://x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html#reparenti=
ng</a>). Thus, finding out the x,y position of the window manager&#39;s win=
dow on the root window requires some doing. I think the way to do this is t=
o send a ConfigureWindow request that doesn&#39;t change anything and then =
listen for the synthetic ConfigureNotify event that will have the top-level=
 x,y in root coordinates (<a href=3D"https://x.org/releases/X11R7.6/doc/xor=
g-docs/specs/ICCCM/icccm.html#configuring_the_window">https://x.org/release=
s/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html#configuring_the_window</a>).=
</div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_=
attr">On Thu, Jul 25, 2024 at 7:04=E2=80=AFAM Steven J Abner &lt;<a href=3D=
"mailto:[email protected]">[email protected]</a>&gt; wrote:<br></div><b=
lockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-le=
ft:1px solid rgb(204,204,204);padding-left:1ex">=C2=A0 In creating an event=
 loop, I&#39;m trying to avoid having inaccurate <br>
data. I found that window managers are apparently sending the events <br>
and not the Xserver. I would like to have the actual position of a <br>
window for data passed along to others.<br>
=C2=A0 Unfortunately the xcb_configure_notify_event_t sent by window manger=
s <br>
is a guess, at least on 2 that I&#39;ve tried. Fortunately the width, <br>
height have tested the same, so can use to configure drawing ports.<br>
=C2=A0 Sadly I am too much of a newbie and can&#39;t figure how to get the =
<br>
geometry of a window&#39;s x,y position. Here&#39;s the code in my attempt:=
<br>
<br>
=C2=A0 xcb_configure_notify_event_t *configure;<br>
=C2=A0 configure =3D (xcb_configure_notify_event_t*)nvt;<br>
=C2=A0 int16_t hD =3D configure-&gt;width - iface-&gt;mete_box.w;<br>
=C2=A0 int16_t vD =3D configure-&gt;height - iface-&gt;mete_box.h;<br>
=C2=A0 if ((hD !=3D 0) || (vD !=3D 0))<br>
=C2=A0 =C2=A0 _interface_configure(iface, hD, vD);<br>
=C2=A0 if ((configure-&gt;x | configure-&gt;y) !=3D 0) {<br>
=C2=A0 =C2=A0 xcb_get_geometry_cookie_t cookie;<br>
=C2=A0 =C2=A0 cookie =3D xcb_get_geometry(connection, iface-&gt;window);<br=
>
=C2=A0 =C2=A0 xcb_get_geometry_reply_t *cfg;<br>
=C2=A0 =C2=A0 cfg =3D xcb_get_geometry_reply(connection, cookie, NULL);<br>
=C2=A0 =C2=A0 if ((cfg-&gt;x !=3D configure-&gt;x) || (cfg-&gt;y !=3D confi=
gure-&gt;y)) {<br>
=C2=A0 =C2=A0 =C2=A0 printf(&quot;%d, { %d,%d } cfg { %d,%d }\n&quot;,<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0iface-&gt;window,<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0configure-&gt;x, configure-=
&gt;y, cfg-&gt;x, cfg-&gt;y);<br>
=C2=A0 =C2=A0 }<br>
=C2=A0 =C2=A0 free(cfg);<br>
<br>
=C2=A0 =C2=A0 master_iface-&gt;mete_box.x =3D configure-&gt;x;<br>
=C2=A0 =C2=A0 master_iface-&gt;mete_box.y =3D configure-&gt;y;<br>
=C2=A0 }<br>
<br>
I get a result of this on one manger, that actually provides the <br>
correct x,y on configure events:<br>
<br>
window 71303168, CONFIGURE_NOTIFY. (101,223,800,200)<br>
71303168, { 101,223 } cfg { 0,0 }<br>
<br>
Can you please help me get the window&#39;s position from xcb. I&#39;m not =
at a <br>
point to learn Xlib&#39;s XGetWindowAttributes() nor desire to write off my=
 <br>
ignorance on xcb&#39;s API.<br>
<br>
Steve<br>
<br>
<br>
</blockquote></div>

--0000000000001ed61e061e150b82--