Find the answer to your Linux question:
Results 1 to 8 of 8
Hi everyone, I am new to this forum and I hoped that someone on this forum knows the answer to my question. I am trying to write an application that ...
  1. #1
    Just Joined!
    Join Date
    Sep 2008
    Posts
    4

    Xlib question

    Hi everyone,

    I am new to this forum and I hoped that someone on this forum knows the answer to my question.

    I am trying to write an application that can tell me the coordinates of the mouse pointer on the screen. I have figured out that I will have to use the xQueryPointer function:
    Code:
    Bool XQueryPointer(display, w, root_return, child_return, root_x_return, root_y_return, 
                         win_x_return, win_y_return, mask_return)
    Display *display;
          Window w;
          Window *root_return, *child_return;
          int *root_x_return, *root_y_return;
          int *win_x_return, *win_y_return;
          unsigned int *mask_return;
    Xlib Programming Manual: sXQueryPointer
    But I don't understand the w argument, is this the application wherefrom the mouse coordinates are calculated? and wherefrom can I get this value?

    Hope you can help.

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Is this a console program or a GUI program?

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    You need to specify which screen the pointer position is to be returned for. To do that, pick any window on that screen, and pass it as w.

    Since most situations involve just one screen, pick any old window (the root window will do just fine) and use that.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    try this web page

    Xlib programming tutorial: anatomy of the most basic Xlib program

    I used the example code above and then added the XQueryPointer function and it returned the mouse position

  5. #5
    Just Joined!
    Join Date
    Sep 2008
    Posts
    4
    Actualy I am writing a GUI app that is using GTK+. So I have created a window with GTK+ functions.Can I just use the window variable from GTK+ for that or is that something else?
    What is the root window exactly? and where can I get this value?
    P.S.: I am just using one screen.

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Can I just use the window variable from GTK+ for that or is that something else?
    My experience is with bare-bones Xlib, but I'm guessing you can just use the window variable from GTK+. That way, you don't have to worry about the following questions:
    What is the root window exactly?
    The root window is the overall "window" that consists of the whole screen.
    where can I get this value?
    I suggested the root window because of how easy it is to get its value in Xlib. Assuming you have only one screen:
    Code:
    XRootWindow(display,0)
    I would have said you have to look it up for GTK+ yourself, but as I said above, it looks as though you won't have to.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    If your looking for the mouse coor. in GTK+ this code
    might help....


    Code:
    gboolean
    on_key_press (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
    {
       
        gint x=0, y=0, xadd=0, yadd=0;
        GdkDisplay *display = NULL;
        GdkScreen *screen = NULL;
       
        /* check for up/down/left/right arrow key press */
        switch (event->keyval)
        {
            case GDK_Left:
                xadd -= 5;
                break;
            case GDK_Right:
                xadd += 5;
                break;
            case GDK_Up:
                yadd -= 5;
                break;
            case GDK_Down:
                yadd += 5;
                break;   
            default:
                return FALSE; /* propogate event */
        }
       
        /* get default display and screen */
        display = gdk_display_get_default ();
        screen = gdk_display_get_default_screen (display);
       
        /* get cursor position */
        gdk_display_get_pointer (display, NULL, &x, &y, NULL);
       
        /* set new cusor position */
        x += xadd;
        y += yadd;
        gdk_display_warp_pointer (display, screen, x, y);
       
        return FALSE; /* propogate event */
    }

  8. #8
    Just Joined!
    Join Date
    Sep 2008
    Posts
    4
    thanks for clearing things up, I didn't know that you could get info about the mouse via GTK+ code.
    thank you everybody

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...