gtk: position window

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
arivas_2005
Posts: 212
Joined: Sun 25 Feb 2007, 14:39

gtk: position window

#1 Post by arivas_2005 »

I need to put window top right
I experimented with example GtkDialog - tips page 1, title "How to store window size/placement"
a) script
#! /bin/bas
save_geometry (){
....
not work for me (the window does not change to the position)
and and does not create the file /tmp/geometry
b) script

Code: Select all

#! /bin/sh
RIGHT=800 DOWN=36 WIDTH=200 HEIGHT=80 
export GUI
GUI=' 
<window>
 <vbox>
  <button cancel></button>
 </vbox>
 </window>'
gtkdialog -p GUI -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}}
its works when executing directly (s positioned to the right and up)
but If I run through "Open With", then not works! is positioned in any place, but not to the right above and loses the dimensions
help me to do the positioning when running with "open with"
(I use gtkdialog version 0.8.4)
Thanks you!
Last edited by arivas_2005 on Sun 15 Oct 2017, 15:18, edited 1 time in total.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: gtk: position window

#2 Post by MochiMoppel »

arivas_2005 wrote:I experimented with example GtkDialog - tips page 1, title "How to store window size/placement"
a) script
#! /bin/bas
save_geometry (){
....
not work for me (the window does not change to the position)
Confirmed. This example is buggy. Funny that you are the first to notice. Maybe you should post in the Gtkdialog-tips thread and ask zigbert to fix it. If you want to make it work you could call the function from an action of the OK button. [Update]: No, even then it won't work. Still a couple of spelling and quotation errors and wrong attributes in the main dialog. :oops:


b) script

Code: Select all

#! /bin/sh
RIGHT=800 DOWN=36 WIDTH=200 HEIGHT=80 
export GUI
GUI=' 
<window>
 <vbox>
  <button cancel></button>
 </vbox>
 </window>'
gtkdialog -p GUI -G ${1-${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}}
its works when executing directly (s positioned to the right and up)
but If I run through "Open With", then not works! is positioned in any place, but not to the right above and loses the dimensions
This example is tricky. It expects an geometry string as argument, otherwise uses the defaults. If the argument is not a valid geometry, the defaults are ignored.
To avoid this trouble change the last line to

Code: Select all

gtkdialog -p GUI -G ${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}
Of course you don't need yo use variables if your values are fixed:

Code: Select all

gtkdialog -p GUI -G 200x80+800+36
I also noticed that my window manager (JWM) ignores values that would push the window beyond the screen limits, so for me the code

Code: Select all

gtkdialog -p GUI -G +9999+0
would place the dialog into the top right corner, no matter if I run the code on the 800x600 screen of my netbook or the attached 1600x1200 external monitor.

arivas_2005
Posts: 212
Joined: Sun 25 Feb 2007, 14:39

#3 Post by arivas_2005 »

thanks for your reply :D
Now I understand the lines of the example --of the same page--
/tmp/gui 200x200+500+500 or
/tmp/gui 75x75 or
/tmp/gui +0+0 or
/tmp/gui for the default geometry
the fraction / tmp / is incomprehensible to me

and luckily at the time of reading your answer I also found this example
http://www.murga-linux.com/puppy/viewto ... 26cad056f0
with your explanation and this example I can solve my need
I tell you:
hat after much googlear, build an option:
with xdotool position the mouse pointer in the upper right corner

Code: Select all

xdotool mousemove 900 100 click 1
then included the option <window window_position="2"> en el script
your suggestion is better
Thank you for your support. I can solve my need. Good day :)

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#4 Post by LazY Puppy »

This is what I'm using to be able to have a gtkdialog GUI opening at preferred coordinates.

A file called wingeo.cfg where I'm storing last used coordinates:

Code: Select all

export WIN_POS=+117+122
export WIN_HGT=722
export WIN_WTH=1038
export MIN_WINHGT=480
export MIN_WINWTH=720
Window width and height defined in gtkdialog window widget (this is a single line of code):

Code: Select all

<window icon-name="arsuite" title="'"$TITLE"'" height-request="'"$MIN_WINHGT"'" default-height="'"$WIN_HGT"'" width-request="'"$MIN_WINWTH"'" default-width="'"$WIN_WTH"'">
Window position:

Code: Select all

gtkdialog4 -G $WIN_POS --class=ARSUITE_GUI -p ARSUITE_GUI >/dev/null
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#5 Post by LazY Puppy »

A short example, to show how it works.

Code: Select all

#!/bin/bash -a
#------------------------------------------------------------------------------

# Get Application Directory
#--------------------------
APPDIR="`dirname "$0"`" # Application Directory
APPDIRAPP="`basename "$0"`" # Application Name
[ "$APPDIR" = "." ] && APPDIR="`pwd`"
export APPDIR="$APPDIR"
export APPDIR=`dirname "$0"`
[ "$APPDIR" = '.' ] && export APPDIR=`pwd`

# Win Geometry
WINGEOCONFIG="$APPDIR/wingeo.cfg"
MIN_WINHGT=360; MIN_WINWTH=560; DEF_WINHGT=600; DEF_WINWTH=800;
ScreenSizew=`xrandr | grep current | awk '{print $8}'`
ScreenSizeh=`xrandr | grep current | awk '{print $10}' | tr -cd '[[:digit:]]'`
POSY=$(( $ScreenSizeh / 2 - $DEF_WINHGT / 2 ))
POSX=$(( $ScreenSizew / 2 - $DEF_WINWTH / 2 ))
if [ -f "$WINGEOCONFIG" ]; then
	. "$WINGEOCONFIG"
	else
	echo "WIN_POS=+$POSX+$POSY" > "$WINGEOCONFIG"
	echo "WIN_HGT=$DEF_WINHGT" >> "$WINGEOCONFIG"
	echo "WIN_WTH=$DEF_WINWTH" >> "$WINGEOCONFIG"
	. "$WINGEOCONFIG"
fi

###############################################################################
# Functions
###############################################################################

# Save current Size of Window
function savewinsize(){
	WINGEOCONFIG="$1"
	if [ ! -f "$WINGEOCONFIG" ]; then
		echo 'export WIN_POS=+190+160
export WIN_HGT=620
export WIN_WTH=930
export MIN_WINHGT=470
export MIN_WINWTH=780' > "$WINGEOCONFIG"
	fi
	WINID=$(xprop -root|sed -n s/^_NET_ACTIVE[^0]*//p)
	WINFO=$(xwininfo -id $WINID)
	H=$(awk '/Height:/               {print $NF}' <<< "$WINFO")
	W=$(awk '/Width:/                {print $NF}' <<< "$WINFO")
	AX=$(awk '/Absolute upper-left X/ {print $NF}' <<< "$WINFO")
	AY=$(awk '/Absolute upper-left Y/ {print $NF}' <<< "$WINFO")
	RX=$(awk '/Relative upper-left X/ {print $NF}' <<< "$WINFO")
	RY=$(awk '/Relative upper-left Y/ {print $NF}' <<< "$WINFO")
	X=$((AX-RX)); Y=$((AY-RY)); P="+$X+$Y";
	H=$(( H / 2 * 2)); W=$(( W / 2 * 2));
	[ "$H" != "$WIN_HGT" ] && sed -i '0,/WIN_HGT=.*/ s//WIN_HGT='$H'/' "$WINGEOCONFIG"
	[ "$W" != "$WIN_WTH" ] && sed -i '0,/WIN_WTH=.*/ s//WIN_WTH='$W'/' "$WINGEOCONFIG"
	[ "$P" != "$WIN_POS" ] && sed -i '0,/WIN_POS=.*/ s//WIN_POS='$P'/' "$WINGEOCONFIG"
} # savewinsize
export -f savewinsize

###############################################################################
# End of Functions
###############################################################################

###############################################################################
# Init GtkDialog GUI
###############################################################################

# Scale Grip to resize window
SCALEGRIP="`/usr/lib/gtkdialog/xml_scalegrip`"

# Set some Paths for the use of some Icons
GTKDIALOG_PIXMAP_PATH=/usr/share/icons/hicolor/48x48/apps:/usr/share/pixmaps:/usr/local/lib/X11/pixmaps
export GTKDIALOG_PIXMAP_PATH

# Simple GUI with entry widget plus OK and Cancel buttons
#--------------------------------------------------------
SimpleGUI='<window title="Titel hier eingeben" icon-name="$ICONONLY" height-request="'$MIN_WINHGT'" default-height="'$WIN_HGT'" width-request="'$MIN_WINWTH'" default-width="'$WIN_WTH'">
<vbox>
	<menubar>

		<menu>
			<menuitem icon-name="close" accel-key="0xff1b" accel-mods="0" tooltip-text="Quit">
				<label>Quit</label>
				<action>savewinsize "'$WINGEOCONFIG'"</action>
				<action>exit:Quit</action>
			</menuitem>

			<label>Datei</label>
		</menu>

	</menubar>

	<hbox space-fill="true" space-expand="true">
		<entry>
			<variable>EntryVar</variable>
		</entry>
	</hbox>

	<hbox space-fill="false" space-expand="false">
		'"$SCALEGRIP"'
	</hbox>

</vbox>
</window>'

export SimpleGUI=$(echo "$SimpleGUI" | sed 's/#[#~].*$//') # Strip comments
gtkdialog4 --class=ontop -p SimpleGUI -G $WIN_POS >/dev/null

unset SimpleGUI

exit 0

#------------------------------------------------------------------------------
# End
#------------------------------------------------------------------------------
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#6 Post by MochiMoppel »

Setting geometry with the -G option can have unpleasant consequences.
When launching subwindows from the main window all subwindows will inherit the -G setting, i.e. by default they will be as big as the main window. As a result in all subwindows the width-request and height-request attributes must be set to override the inherited dimension.

Utterly annoying: Most window-position attributes will not work anymore. E.g. it will not be possible to open a subwindow under the mouse cursor (window-position="2"). The only position that will still work is window-position="3".

Post Reply