Detect cursor position

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

Detect cursor position

#1 Post by Argolance »

Hello,
How to detect if the mouse cursor is crossing over or out of a specific area of a GUI? In my case, this area is composed by the lines/items of a tree list: I would like to deactivate mouse cursor events when it is out of the tree list area...

More: is it possible to change mouse cursor when this happens?

Thank you.

Cordialement.

User avatar
puppyluvr
Posts: 3470
Joined: Sun 06 Jan 2008, 23:14
Location: Chickasha Oklahoma
Contact:

#2 Post by puppyluvr »

:D Hello,
You could use "getcurpos" in a function..
Close the Windows, and open your eyes, to a whole new world
I am Lead Dog of the
Puppy Linux Users Group on Facebook
Join us!

Puppy since 2.15CE...

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#3 Post by Argolance »

Hello (Forgot to specify it is a Gtkdialog3 GUI).
Thank you for your fast reply!
Where could I find explanations and examples of the way to use "getcurpos"?

Cordialement.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#4 Post by 8-bit »

Argolance wrote:Hello (Forgot to specify it is a Gtkdialog3 GUI).
Thank you for your fast reply!
Where could I find explanations and examples of the way to use "getcurpos"?

Cordialement.
I have been doing a lot of searching and coding and came up with this:

Code: Select all

#!/bin/sh
   move (){
      sopp="`cat /tmp/who|sed -e 's/^.*\(...\)$/\1/'`"
   where
   if [ $sop = $sopp ];then
   return
   fi
   PRESS_EVENT="`cat /tmp/PRESS_EVENT`"
   grep -Fv "$PRESS_EVENT" /tmp/list > /tmp/tmp
   grep -Fm1 -B500 "$TREE" /tmp/tmp | grep -v "$TREE" > /tmp/tmp1
   echo "$PRESS_EVENT" >> /tmp/tmp1
   grep -Fm1 -A500 "$TREE" /tmp/tmp >> /tmp/tmp1
   mv -f /tmp/tmp1 /tmp/list
}
  where(){
	  getcurpos > /tmp/who
      sop="`cat /tmp/who|sed -e 's/^.*\(...\)$/\1/'`"
}
export -f move
ls -1 /usr/share/backgrounds > /tmp/list
export -f where
export test="
<tree rules_hint="true" hover-selection="true" tooltip-text="Drag'n drop items to move them in list">
 <label>Backgrounds</label>
 <input>cat /tmp/list</input>
 <variable>TREE</variable>
 <height>300</height><width>200</width>
 <action signal="button-press-event">echo \$TREE > /tmp/PRESS_EVENT</action>
 <action signal="button-press-event">where</action>
 <action signal="button-release-event">move</action>
 <action signal="button-release-event">refresh:TREE</action>
</tree>"
gtkdialog3 --center -p test
I did not allow for cursor drift though. So click and release must be at the same position exactly. Modify it as you wish.
Now you do realize I would not do this for just anybody! :wink:

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#5 Post by 8-bit »

I don't think I mentioned this, but I know almost nothing about the use of "sed" in programming. I actually found an example on the forum and cut and pasted it with minor modifications as to the source it was reading from and the number of characters to return.
But who knows.
One of these days, I may actually be able to do a little programming on my own. :)

User avatar
puppyluvr
Posts: 3470
Joined: Sun 06 Jan 2008, 23:14
Location: Chickasha Oklahoma
Contact:

#6 Post by puppyluvr »

:D Hello,
Thanks 8-bit..
I spent most of my lunch writing a script to demo getcurpos, but didnt finish it before I had to go back to work, and when I got home, you already had.. 8)
Here is the first part..
#!/bin/sh
while z=1
do
MOUSE_X="`getcurpos | awk '{print $1}'`"
MOUSE_Y="`getcurpos | awk '{print $2}'`"
echo $MOUSE_X
echo $MOUSE_Y
sleep 1
done
Run in a terminal, it echos the cursor position...
Close the Windows, and open your eyes, to a whole new world
I am Lead Dog of the
Puppy Linux Users Group on Facebook
Join us!

Puppy since 2.15CE...

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#7 Post by 8-bit »

I originally had one similar to yours that worked fine in a terminal.
But for some reason, the same thing dropped into a gtkdialog script did not populate the variables.
I am still trying to figure out why it would work in a terminal and not in a gtkdialog script.

User avatar
Dave_G
Posts: 453
Joined: Thu 21 Jul 2011, 13:53

#8 Post by Dave_G »

Hi guys,

Nice one.
How about:

# ==============================
#!/bin/sh
while z=1
do
tput clear
MOUSE_X="`getcurpos | awk '{print $1}'`"
MOUSE_Y="`getcurpos | awk '{print $2}'`"
echo $MOUSE_X
echo $MOUSE_Y
sleep 1
done
# ==============================

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#9 Post by Argolance »

Hello,
I am just coming back home! Thanks to all of you for your very useful comments and code lines much appreciated.
Now I have to understand... and adapt!
"See" you soon!

Best regards.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#10 Post by 8-bit »

Dave_G wrote:Hi guys,

Nice one.
How about:

# ==============================
#!/bin/sh
while z=1
do
tput clear
MOUSE_X="`getcurpos | awk '{print $1}'`"
MOUSE_Y="`getcurpos | awk '{print $2}'`"
echo $MOUSE_X
echo $MOUSE_Y
sleep 1
done
# ==============================
What does the "tput clear" line do?

The reason I am curious, is that with my attempt at using getcurpos, If I get carried away with mouse clicks, the program tries to execute the returned variable witch messes up the application.

User avatar
puppyluvr
Posts: 3470
Joined: Sun 06 Jan 2008, 23:14
Location: Chickasha Oklahoma
Contact:

#11 Post by puppyluvr »

:D Hello,
What does the "tput clear" line do?


Clears the terminal between inputs...
(Instead of scrolling them in the terminal.)
Close the Windows, and open your eyes, to a whole new world
I am Lead Dog of the
Puppy Linux Users Group on Facebook
Join us!

Puppy since 2.15CE...

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#12 Post by seaside »

Argolance,

Perhaps some signal functions in gtkdialog would help -

Code: Select all

#! /bin/bash

export DIALOG='
<window title="Example Window" icon-name="gtk-dialog-warning">
  <vbox>
    <frame Widgets>
      <text>
        <label>Label</label>
        <action signal="button-press-event">echo Label: button-press-event</action>
        <action signal="button-release-event">echo Label: button-release-event</action>
        <action signal="configure-event">echo Label: configure-event</action>
        <action signal="enter-notify-event">echo Label: enter-notify-event</action>
        <action signal="leave-notify-event">echo Label: leave-notify-event</action>
        <action signal="focus-in-event">echo Label: focus-in-event</action>
        <action signal="focus-out-event">echo Label: focus-out-event</action>
        <action signal="key-press-event">echo Label: key-press-event</action>
        <action signal="key-release-event">echo Label: key-release-event</action>
        <action signal="hide">echo Label: hide</action>
        <action signal="show">echo Label: show</action>
        <action signal="map-event">echo Label: map-event</action>
        <action signal="unmap-event">echo Label: unmap-event</action>
      </text>
      <entry>
        <default>Entry</default>
        <action signal="button-press-event">echo Entry: button-press_event</action>
        <action signal="button-release-event">echo Entry: button-release-event</action>
        <action signal="configure-event">echo Entry: configure-event</action>
        <action signal="enter-notify-event">echo Entry: enter-notify-event</action>
        <action signal="leave-notify-event">echo Entry: leave-notify-event</action>
        <action signal="focus-in-event">echo Entry: focus-in-event</action>
        <action signal="focus-out-event">echo Entry: focus-out-event</action>
        <action signal="key-press-event">echo Entry: key-press-event</action>
        <action signal="key-release-event">echo Entry: key-release-event</action>
        <action signal="hide">echo Entry: hide</action>
        <action signal="show">echo Entry: show</action>
        <action signal="map-event">echo Entry: map-event</action>
        <action signal="unmap-event">echo Entry: unmap-event</action>
      </entry>
    </frame>
    <hbox>
      <button ok>
        <action signal="button-press-event">echo Button: button-press_event</action>
        <action signal="button-release-event">echo Button: button-release-event</action>
        <action signal="configure-event">echo Button: configure-event</action>
        <action signal="enter-notify-event">echo Button: enter-notify-event</action>
        <action signal="leave-notify-event">echo Button: leave-notify-event</action>
        <action signal="focus-in-event">echo Button: focus-in-event</action>
        <action signal="focus-out-event">echo Button: focus-out-event</action>
        <action signal="key-press-event">echo Button: key-press-event</action>
        <action signal="key-release-event">echo Button: key-release-event</action>
        <action signal="hide">echo Button: hide</action>
        <action signal="show">echo Button: show</action>
        <action signal="map-event">echo Button: map-event</action>
        <action signal="unmap-event">echo Button: unmap-event</action>
      </button>
    </hbox>
  </vbox>
  <action signal="button-press-event">echo Window: button-press_event</action>
  <action signal="button-release-event">echo Window: button-release-event</action>
  <action signal="configure-event">echo Window: configure-event</action>
  <action signal="delete-event">echo Window: delete-event</action>
  <action signal="destroy-event">echo Window: destroy-event</action>
  <action signal="enter-notify-event">echo Window: enter-notify-event</action>
  <action signal="leave-notify-event">echo Window: leave-notify-event</action>
  <action signal="focus-in-event">echo Window: focus-in-event</action>
  <action signal="focus-out-event">echo Window: focus-out-event</action>
  <action signal="key-press-event">echo Window: key-press-event</action>
  <action signal="key-release-event">echo Window: key-release-event</action>
  <action signal="hide">echo Window: hide</action>
  <action signal="show">echo Window: show</action>
  <action signal="map-event">echo Window: map-event</action>
  <action signal="unmap-event">echo Window: unmap-event</action>
</window>
'
gtkdialog3 --program=DIALOG
Specifically, the "enter-notify-event" and "leave-notify-event" signals.

Regards,
s

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#13 Post by 8-bit »

Seaside,
Thank you for the signal function example!
It gives one a better idea of what can be done.

User avatar
cat_n_mouse
Posts: 12
Joined: Thu 04 Aug 2011, 18:29
Location: /usr/bin/Paulo

#14 Post by cat_n_mouse »

Thank you seaside, I suspect your example will be of help to many.

Post Reply