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 ...
- 09-03-2008 #1Just 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:
Xlib Programming Manual: sXQueryPointerCode: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;
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.
- 09-03-2008 #2
Is this a console program or a GUI program?
- 09-03-2008 #3
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.
- 09-03-2008 #4
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
- 09-04-2008 #5Just 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.
- 09-04-2008 #6My 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:Can I just use the window variable from GTK+ for that or is that something else?
The root window is the overall "window" that consists of the whole screen.What is the root window exactly?
I suggested the root window because of how easy it is to get its value in Xlib. Assuming you have only one screen:where can I get this value?
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.Code:XRootWindow(display,0)
--
Bill
Old age and treachery will overcome youth and skill.
- 09-04-2008 #7
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 */ }
- 09-04-2008 #8Just 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


Reply With Quote