You are not logged in.

#1 2017-07-20 23:51:46

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

[SOLVED-ish]Can't get window id when run from within script

I am trying to run a yad dialog from a script, then get the window position after a move so it can be restored to the same place. When started from a terminal, the script fails to output the geometry when using xwininfo or wmctrl.

But running the xwininfo or wmctrl command in another terminal, when the dialog is on the screen, it shows up fine hmm

Script snippet:

#!/bin/bash
##
## yad-test

color=$(yad --color --button=gtk-close:1 --undecorated --center --init-color="#ffffff" \
	--button=gtk-copy:2 \
	--title="Select Color"
	)
			
xwininfo -name "Select Color"

wmctrl -lG | grep "Select Color"

Running from terminal:

damo@helium:~$ yad-test
xwininfo: error: No window with name "Select Color" exists!

Getting the info from another terminal, no problem:

damo@helium:~$ xwininfo -name "Select Color"

xwininfo: Window id: 0x3800007 "Select Color"

  Absolute upper-left X:  640
  Absolute upper-left Y:  390
  Relative upper-left X:  0
  Relative upper-left Y:  0
  Width: 639
  Height: 268
  Depth: 24
  Visual: 0xc1
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x3800006 (not installed)
  Bit Gravity State: NorthWestGravity
  Window Gravity State: NorthWestGravity
  Backing Store State: NotUseful
  Save Under State: no
  Map State: IsViewable
  Override Redirect State: no
  Corners:  +640+390  -641+390  -641-422  +640-422
  -geometry 639x268+640+390

damo@helium:~$ wmctrl -lG | grep "Select Color"
0x03800007  1 640  390  639  268  helium Select Color

Any hints as to where I should be searching for answers, because googling hasn't worked so far?

Last edited by damo (2017-07-21 01:22:21)


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#2 2017-07-21 01:21:59

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: [SOLVED-ish]Can't get window id when run from within script

I've found an ugly way of doing it, by using yad's '--print-xid' to send stderr to a variable

TMP=$(mktemp)
			
color=$(yad --color --button=gtk-close:1 --undecorated --center --init-color="#ffffff" \
			--button=gtk-copy:2 \
			--title="Select Color" \
			--print-xid 2> "$TMP" \
			)

ID="$(<$TMP)"
rm "$TMP"

echo "Window ID=  $ID"

This outputs

damo@helium:~$ yad-test
Window ID=  0x3800007

...which matches the value given by the other commands in a different shell. Now to see how to use it hmm


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2017-07-21 02:11:19

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: [SOLVED-ish]Can't get window id when run from within script

Rats sad

damo@helium:~$ yad-color
Window ID=  0x3800007
Passed ID= 0x3800007
X Error: 9: Bad Drawable: 0x3800007
  Request Major code: 14
  Request serial number: 3
xwininfo: error: No such window with id 0x3800007.

But there is, I can see it, and so can xwininfo from another shell!!


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#4 2017-07-21 05:34:47

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,671
Website

Re: [SOLVED-ish]Can't get window id when run from within script

...er damo, this might seem too obvious, but by the time you reach the xwininfo and wmctrl commands in your script, hasn't the yad window already closed?

Try forking it with an & and add a bit of sleep so the window is properly made before hitting xwininfo:

#!/bin/bash
##
## yad-test

color=$(yad --color --button=gtk-close:1 --center --undecorated --init-color="#ffffff" \
	--button=gtk-copy:2 \
	--title="Select Color"
	) &

sleep 0.5

xwininfo -name "Select Color"

wmctrl -lG | grep "Select Color"
john@bunsen1:~$ ./yad-test.sh 

xwininfo: Window id: 0x5000007 "Select Color"

  Absolute upper-left X:  383
  Absolute upper-left Y:  309
  Relative upper-left X:  0
  Relative upper-left Y:  0
  Width: 673
  Height: 257
  Depth: 24
  Visual: 0x21
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x20 (installed)
  Bit Gravity State: NorthWestGravity
  Window Gravity State: NorthWestGravity
  Backing Store State: NotUseful
  Save Under State: no
  Map State: IsViewable
  Override Redirect State: no
  Corners:  +383+309  -384+309  -384-334  +383-334
  -geometry 673x257+383+309

0x05000007  0 383  309  673  257  bunsen1 Select Color

Whether that now allows you to do what you want is another question...
(But there's already a simple alternative for the color-picker code.)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Online

#5 2017-07-21 13:27:58

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: [SOLVED-ish]Can't get window id when run from within script

^ I had a thought that it might be a timing issue, and I must have done the wrong thing when trying to fork it  8o  :8 

I'm already using the simple code, but I was thinking of being able to keep the window up while making multiple colour picks. Actually, the yad window closes and restarts, but wherever it is set to appear. I'd like to be able to move it wherever is convenient, and when it pops up again after a pick it is in the new place. That's why I want to store the geometry.

On the plus side, I can now find window geometry with xwininfo, xdotool, wmctrl, xprop and obxprop!


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#6 2017-07-21 21:43:41

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: [SOLVED-ish]Can't get window id when run from within script

Whether that now allows you to do what you want is another question...

Unfortunately not. Unless there is a way of getting the return values from a forked process...


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#7 2017-07-22 02:41:52

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,671
Website

Re: [SOLVED-ish]Can't get window id when run from within script

Make a temp file? Feels messy but works.

You might try creating a fifo, passing its location to the subprocess and reading back from it. Haven't tried that though, and fifos can be tricky. 'man mkfifo' has little to say.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Online

Board footer

Powered by FluxBB