• Re: Jumpy mouse

    From Luc@21:1/5 to All on Thu Mar 14 20:42:05 2024
    On Thu, 14 Mar 2024 17:37:45 -0400, saitology9 wrote:


    ### code follows ###########
    package require Tk

    label .l -text "Move me to move the window" -width 40 -height 10
    pack .l -fill both -expand 1

    bind .l <1> {
    set coords "%x %y"
    lassign $coords ::labelx ::labely
    }
    bind .l <B1-Motion> {
    moveme %W %x %y
    }

    proc moveme {win x y} {
    set top [winfo toplevel $win]
    lassign [split [winfo geometry $top] "+"] dims x1 y1

    set newX [expr {$x1 + $x}]
    set newY [expr {$y1 + $y}]
    set newX [expr {$newX - $::labelx}]
    set newY [expr {$newY - $::labely}]

    wm geometry $top "${dims}+${newX}+${newY}"
    }

    ### end of code ############


    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to [email protected] on Fri Mar 15 01:50:52 2024
    saitology9 <[email protected]> wrote:
    Can anyone spot what is wrong here?
    You can click and drag he label to move the window.
    However, the mouse jumps to the top left corner, instead of
    maintaining its position relative to the window.

    To be padantic, it is not the mouse that jumps, it is the window that
    jumps so that the window's top left is just below the mouse hotspot.
    The mouse remains at exactly the same spot on screen as where it
    started.

    Luc supplied updated code that worked, but did not explain why the code
    worked. You were not accounting for the position of the mouse (offset
    of mouse pointer) from top left corner when setting up your geometry
    string calculations. The geometry string positions the top left corner
    of the window, so you have to include the mouse offset that was present
    when the button was first depressed to keep the window from jumping to
    be aligned top-left with the mouse.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)