Get X/Y position of caret (input text cursor) under Xorg?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







8















I'd like to display a popover right above where the user is typing, in any Linux app (GTK, Qt, Electron, etc.), running on X.



I figured out creating the popover, now I'm trying to figure out how to get the coordinates of the input text cursor (what blinks while you type, not sure if it's called "caret"?) relative to the screen.



I know I can get info on where the mouse with xdotool:



xdotool getmouselocation


I would need the same thing but for the text cursor, in the currently focused window.



I have no idea how to achieve this. I would love if someone could point me in the right direction.










share|improve this question

























  • X has no idea where the text input caret is. I don't think your idea is implementable (without co-operation from the application or toolkit).

    – jku
    Nov 17 '18 at 13:36













  • I agree with @jku, X doesn't know anything particular about that, just that you clicked somewhere (if even a click is needed) and that it has been handled by an application. It doesn't know at all whether you're typing text or not! Also, I think it's called a cursor

    – Geoffroy
    Nov 26 '18 at 8:47













  • Right. I was told one way would be witha GTK module.

    – nkkollaw
    Nov 27 '18 at 10:24


















8















I'd like to display a popover right above where the user is typing, in any Linux app (GTK, Qt, Electron, etc.), running on X.



I figured out creating the popover, now I'm trying to figure out how to get the coordinates of the input text cursor (what blinks while you type, not sure if it's called "caret"?) relative to the screen.



I know I can get info on where the mouse with xdotool:



xdotool getmouselocation


I would need the same thing but for the text cursor, in the currently focused window.



I have no idea how to achieve this. I would love if someone could point me in the right direction.










share|improve this question

























  • X has no idea where the text input caret is. I don't think your idea is implementable (without co-operation from the application or toolkit).

    – jku
    Nov 17 '18 at 13:36













  • I agree with @jku, X doesn't know anything particular about that, just that you clicked somewhere (if even a click is needed) and that it has been handled by an application. It doesn't know at all whether you're typing text or not! Also, I think it's called a cursor

    – Geoffroy
    Nov 26 '18 at 8:47













  • Right. I was told one way would be witha GTK module.

    – nkkollaw
    Nov 27 '18 at 10:24














8












8








8


1






I'd like to display a popover right above where the user is typing, in any Linux app (GTK, Qt, Electron, etc.), running on X.



I figured out creating the popover, now I'm trying to figure out how to get the coordinates of the input text cursor (what blinks while you type, not sure if it's called "caret"?) relative to the screen.



I know I can get info on where the mouse with xdotool:



xdotool getmouselocation


I would need the same thing but for the text cursor, in the currently focused window.



I have no idea how to achieve this. I would love if someone could point me in the right direction.










share|improve this question
















I'd like to display a popover right above where the user is typing, in any Linux app (GTK, Qt, Electron, etc.), running on X.



I figured out creating the popover, now I'm trying to figure out how to get the coordinates of the input text cursor (what blinks while you type, not sure if it's called "caret"?) relative to the screen.



I know I can get info on where the mouse with xdotool:



xdotool getmouselocation


I would need the same thing but for the text cursor, in the currently focused window.



I have no idea how to achieve this. I would love if someone could point me in the right direction.







linux gtk xorg xdotool






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 18:05







nkkollaw

















asked Nov 16 '18 at 23:31









nkkollawnkkollaw

608719




608719













  • X has no idea where the text input caret is. I don't think your idea is implementable (without co-operation from the application or toolkit).

    – jku
    Nov 17 '18 at 13:36













  • I agree with @jku, X doesn't know anything particular about that, just that you clicked somewhere (if even a click is needed) and that it has been handled by an application. It doesn't know at all whether you're typing text or not! Also, I think it's called a cursor

    – Geoffroy
    Nov 26 '18 at 8:47













  • Right. I was told one way would be witha GTK module.

    – nkkollaw
    Nov 27 '18 at 10:24



















  • X has no idea where the text input caret is. I don't think your idea is implementable (without co-operation from the application or toolkit).

    – jku
    Nov 17 '18 at 13:36













  • I agree with @jku, X doesn't know anything particular about that, just that you clicked somewhere (if even a click is needed) and that it has been handled by an application. It doesn't know at all whether you're typing text or not! Also, I think it's called a cursor

    – Geoffroy
    Nov 26 '18 at 8:47













  • Right. I was told one way would be witha GTK module.

    – nkkollaw
    Nov 27 '18 at 10:24

















X has no idea where the text input caret is. I don't think your idea is implementable (without co-operation from the application or toolkit).

– jku
Nov 17 '18 at 13:36







X has no idea where the text input caret is. I don't think your idea is implementable (without co-operation from the application or toolkit).

– jku
Nov 17 '18 at 13:36















I agree with @jku, X doesn't know anything particular about that, just that you clicked somewhere (if even a click is needed) and that it has been handled by an application. It doesn't know at all whether you're typing text or not! Also, I think it's called a cursor

– Geoffroy
Nov 26 '18 at 8:47







I agree with @jku, X doesn't know anything particular about that, just that you clicked somewhere (if even a click is needed) and that it has been handled by an application. It doesn't know at all whether you're typing text or not! Also, I think it's called a cursor

– Geoffroy
Nov 26 '18 at 8:47















Right. I was told one way would be witha GTK module.

– nkkollaw
Nov 27 '18 at 10:24





Right. I was told one way would be witha GTK module.

– nkkollaw
Nov 27 '18 at 10:24












1 Answer
1






active

oldest

votes


















0














So, after doing some research I was able to figure out one way to implement this:




  • use xdotool to paste some random string

  • use OCR to find coordinates of the random string

  • use xdotool to remove random string


The problem is that this approach is pretty slow (up to 10 seconds depending on how much text there is on the screen).



I'v also tried comparing screenshots (before/after inserting text) and it's much faster, but a lot less precise.






share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346707%2fget-x-y-position-of-caret-input-text-cursor-under-xorg%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    So, after doing some research I was able to figure out one way to implement this:




    • use xdotool to paste some random string

    • use OCR to find coordinates of the random string

    • use xdotool to remove random string


    The problem is that this approach is pretty slow (up to 10 seconds depending on how much text there is on the screen).



    I'v also tried comparing screenshots (before/after inserting text) and it's much faster, but a lot less precise.






    share|improve this answer






























      0














      So, after doing some research I was able to figure out one way to implement this:




      • use xdotool to paste some random string

      • use OCR to find coordinates of the random string

      • use xdotool to remove random string


      The problem is that this approach is pretty slow (up to 10 seconds depending on how much text there is on the screen).



      I'v also tried comparing screenshots (before/after inserting text) and it's much faster, but a lot less precise.






      share|improve this answer




























        0












        0








        0







        So, after doing some research I was able to figure out one way to implement this:




        • use xdotool to paste some random string

        • use OCR to find coordinates of the random string

        • use xdotool to remove random string


        The problem is that this approach is pretty slow (up to 10 seconds depending on how much text there is on the screen).



        I'v also tried comparing screenshots (before/after inserting text) and it's much faster, but a lot less precise.






        share|improve this answer















        So, after doing some research I was able to figure out one way to implement this:




        • use xdotool to paste some random string

        • use OCR to find coordinates of the random string

        • use xdotool to remove random string


        The problem is that this approach is pretty slow (up to 10 seconds depending on how much text there is on the screen).



        I'v also tried comparing screenshots (before/after inserting text) and it's much faster, but a lot less precise.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 23 '18 at 18:03

























        answered Nov 19 '18 at 14:26









        nkkollawnkkollaw

        608719




        608719
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346707%2fget-x-y-position-of-caret-input-text-cursor-under-xorg%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?