Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 19 Nov 2017, 10:39
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
gtk: position window
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
arivas_2005

Joined: 25 Feb 2007
Posts: 191

PostPosted: Sat 14 Oct 2017, 23:20    Post subject:  gtk: position window
Subject description: SOLVED!
 

I need to put window top right
I experimented with example GtkDialog - tips page 1, title "How to store window size/placement"
a) script
Quote:
#! /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:
#! /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, 11:18; edited 1 time in total
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1390
Location: Japan

PostPosted: Sun 15 Oct 2017, 03:43    Post subject: Re: gtk: position window  

arivas_2005 wrote:
I experimented with example GtkDialog - tips page 1, title "How to store window size/placement"
a) script
Quote:
#! /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. Embarassed



Quote:
b) script
Code:
#! /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:
gtkdialog -p GUI -G ${WIDTH}x${HEIGHT}+${RIGHT}+${DOWN}


Of course you don't need yo use variables if your values are fixed:
Code:
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:
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.
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 191

PostPosted: Sun 15 Oct 2017, 11:18    Post subject:  

thanks for your reply Very Happy
Now I understand the lines of the example --of the same page--
Quote:
/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/viewtopic.php?t=53382&sid=90b3c1545e6ee4fc0be72326cad056f0
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:
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 Smile
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Sun 15 Oct 2017, 18:17    Post subject:  

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:
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:
<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:
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) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Sun 15 Oct 2017, 20:03    Post subject:  

A short example, to show how it works.

Code:
#!/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) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1390
Location: Japan

PostPosted: Wed 18 Oct 2017, 08:56    Post subject:  

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".
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0478s ][ Queries: 11 (0.0038s) ][ GZIP on ]