• Screen coordinates of cursor position in text and entry widgets

    From Torsten@21:1/5 to All on Sun Jan 29 19:57:23 2023
    I have a context menu for text and entry widgets. When I click the right mouse button, I open it a
    the mouse cursor position.

    When I press the context menu key, i.e. keysym 'App' for Windows and 'Menu' for Linux and macOS, I
    want it to open at the cursor position of the text or entry field.

    How do I get the screen coordinates of the cursor position in that case?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to Torsten on Sun Jan 29 12:45:45 2023
    On Sunday, January 29, 2023 at 7:57:27 PM UTC+1, Torsten wrote:
    I have a context menu for text and entry widgets. When I click the right mouse button, I open it a
    the mouse cursor position.

    When I press the context menu key, i.e. keysym 'App' for Windows and 'Menu' for Linux and macOS, I
    want it to open at the cursor position of the text or entry field.

    How do I get the screen coordinates of the cursor position in that case?

    You probably want [winfo pointerxy], as that returns the x/y coordinates of the pointer wrt the screen that holds the window. I do not think I have ever used it myself, so I simply rely on the man page :).

    Regards,

    Arjen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andreas Leitgeb@21:1/5 to Arjen Markus on Wed Feb 1 00:29:21 2023
    Arjen Markus <[email protected]> wrote:
    On Sunday, January 29, 2023 at 7:57:27 PM UTC+1, Torsten wrote:
    I have a context menu for text and entry widgets. When I click the right mouse button, I open it a
    the mouse cursor position.
    When I press the context menu key, i.e. keysym 'App' for Windows and 'Menu' for Linux and macOS, I
    want it to open at the cursor position of the text or entry field.
    How do I get the screen coordinates of the cursor position in that case?
    You probably want [winfo pointerxy], as that returns the x/y coordinates
    of the pointer wrt the screen that holds the window. I do not think I have ever used it myself, so I simply rely on the man page :).

    My understanding of the question was, that he wanted the coords of the
    widget's "insertion"-cursor - as in: "that blinking thingie"

    For an entry widget .e the following might get you further:
    lassign [.e bbox insert] px py dx dy
    # do some arithmetics to determine the hotspot of that bbox, e.g.:
    set py [expr {$py+$dy/2}]
    # add the widget's global coords:
    incr px [winfo rootx .e]; incr py [winfo rooty .e]

    for text-widgets it might be pretty similar...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Torsten@21:1/5 to All on Thu Feb 2 21:09:13 2023
    -------- Original-Nachricht --------
    Arjen Markus <[email protected]> wrote:

    For an entry widget .e the following might get you further:
    lassign [.e bbox insert] px py dx dy
    # do some arithmetics to determine the hotspot of that bbox, e.g.:
    set py [expr {$py+$dy/2}]
    # add the widget's global coords:
    incr px [winfo rootx .e]; incr py [winfo rooty .e]

    for text-widgets it might be pretty similar...

    That is exactly what I was looking for: The index named "insert".
    I just missed it while reading the man page (and then did not check the entry page).
    Thank you Arjen!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to Torsten on Thu Feb 2 16:56:10 2023
    On 2/2/2023 3:09 PM, Torsten wrote:
    -------- Original-Nachricht --------
    Arjen Markus <[email protected]> wrote:

    For an entry widget .e the following might get you further:
        lassign [.e bbox insert] px py dx dy
        # do some arithmetics to determine the hotspot of that bbox, e.g.:
        set py [expr {$py+$dy/2}]
        # add the widget's global coords:
        incr px [winfo rootx .e]; incr py [winfo rooty .e]

    for text-widgets it might be pretty similar...

    That is exactly what I was looking for: The index named "insert".
    I just missed it while reading the man page (and then did not check the
    entry page).
    Thank you Arjen!


    While they are both very helpful individuals, I think you meant Andreas
    Leitgeb above since you quoted from his message :-)

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