From: Dmitry Antipov Date: Sun, 22 Jun 2014 05:00:14 +0000 (+0400) Subject: * xmenu.c (mouse_position_for_popup): X-Git-Url: http://git.hcoop.net/bpt/emacs.git/commitdiff_plain/b0358ef86903ac021110b54ee1acce11211c200f?ds=sidebyside;hp=38852a76958ec456e01420ae2b26240d9f3bc63c * xmenu.c (mouse_position_for_popup): * xselect.c (mouse_position_for_drop): Do not duplicate ... * xfns.c (x_relative_mouse_position): ... and prefer this function. * menu.c (Fx_popup_menu): * xselect.c (x_handle_dnd_message): Adjust users. * menu.h (mouse_position_for_popup): Remove prototype. * xterm.h (x_relative_mouse_position): Add prototype. * xterm.c (x_find_topmost_parent): Break from the loop and do not call XFree if XQueryTree returns zero. --- diff --git a/src/ChangeLog b/src/ChangeLog index c845568ddc..ca45462cab 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2014-06-22 Dmitry Antipov + + * xmenu.c (mouse_position_for_popup): + * xselect.c (mouse_position_for_drop): Do not duplicate ... + * xfns.c (x_relative_mouse_position): ... and prefer this function. + * menu.c (Fx_popup_menu): + * xselect.c (x_handle_dnd_message): Adjust users. + * menu.h (mouse_position_for_popup): Remove prototype. + * xterm.h (x_relative_mouse_position): Add prototype. + * xterm.c (x_find_topmost_parent): Break from the loop and do not + call XFree if XQueryTree returns zero. + 2014-06-21 Eli Zaretskii * indent.c (Fvertical_motion): Doc fix. diff --git a/src/menu.c b/src/menu.c index 460dc7967b..a523cfc601 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1233,7 +1233,7 @@ no quit occurs and `x-popup-menu' returns nil. */) { int cur_x, cur_y; - mouse_position_for_popup (new_f, &cur_x, &cur_y); + x_relative_mouse_position (new_f, &cur_x, &cur_y); /* cur_x/y may be negative, so use make_number. */ x = make_number (cur_x); y = make_number (cur_y); diff --git a/src/menu.h b/src/menu.h index 643ff40fef..30a89bead2 100644 --- a/src/menu.h +++ b/src/menu.h @@ -54,9 +54,6 @@ extern widget_value *make_widget_value (const char *, char *, bool, Lisp_Object) extern widget_value *digest_single_submenu (int, int, bool); #endif -#ifdef HAVE_X_WINDOWS -extern void mouse_position_for_popup (struct frame *f, int *x, int *y); -#endif #if defined (HAVE_X_WINDOWS) || defined (MSDOS) extern Lisp_Object x_menu_show (struct frame *, int, int, int, Lisp_Object, const char **); diff --git a/src/xfns.c b/src/xfns.c index a7caa53e52..c3d9900207 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -330,8 +330,43 @@ x_real_positions (struct frame *f, int *xptr, int *yptr) *yptr = real_y; } - +/* Get the mouse position in frame relative coordinates. */ + +void +x_relative_mouse_position (struct frame *f, int *x, int *y) +{ + Window root, dummy_window; + int dummy; + + eassert (FRAME_X_P (f)); + + block_input (); + + XQueryPointer (FRAME_X_DISPLAY (f), + DefaultRootWindow (FRAME_X_DISPLAY (f)), + /* The root window which contains the pointer. */ + &root, + + /* Window pointer is on, not used */ + &dummy_window, + + /* The position on that root window. */ + x, y, + + /* x/y in dummy_window coordinates, not used. */ + &dummy, &dummy, + + /* Modifier keys and pointer buttons, about which + we don't care. */ + (unsigned int *) &dummy); + + unblock_input (); + + /* Translate root window coordinates to window coordinates. */ + *x -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); + *y -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); +} /* Gamma-correct COLOR on frame F. */ diff --git a/src/xmenu.c b/src/xmenu.c index 2d41350e73..e04a801ef7 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -139,53 +139,6 @@ menubar_id_to_frame (LWLIB_ID id) } #endif - -#ifdef HAVE_X_WINDOWS -/* Return the mouse position in *X and *Y. The coordinates are window - relative for the edit window in frame F. - This is for Fx_popup_menu. The mouse_position_hook can not - be used for X, as it returns window relative coordinates - for the window where the mouse is in. This could be the menu bar, - the scroll bar or the edit window. Fx_popup_menu needs to be - sure it is the edit window. */ -void -mouse_position_for_popup (struct frame *f, int *x, int *y) -{ - Window root, dummy_window; - int dummy; - - eassert (FRAME_X_P (f)); - - block_input (); - - XQueryPointer (FRAME_X_DISPLAY (f), - DefaultRootWindow (FRAME_X_DISPLAY (f)), - - /* The root window which contains the pointer. */ - &root, - - /* Window pointer is on, not used */ - &dummy_window, - - /* The position on that root window. */ - x, y, - - /* x/y in dummy_window coordinates, not used. */ - &dummy, &dummy, - - /* Modifier keys and pointer buttons, about which - we don't care. */ - (unsigned int *) &dummy); - - unblock_input (); - - /* x_menu_show expects window coordinates, not root window - coordinates. Translate. */ - *x -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); - *y -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); -} - -#endif /* HAVE_X_WINDOWS */ #ifndef MSDOS diff --git a/src/xselect.c b/src/xselect.c index 28f2d770a7..89ec1da30b 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -2373,43 +2373,6 @@ x_property_data_to_lisp (struct frame *f, const unsigned char *data, data, size * format_bytes, type, format); } -/* Get the mouse position in frame relative coordinates. */ - -static void -mouse_position_for_drop (struct frame *f, int *x, int *y) -{ - Window root, dummy_window; - int dummy; - - block_input (); - - XQueryPointer (FRAME_X_DISPLAY (f), - DefaultRootWindow (FRAME_X_DISPLAY (f)), - - /* The root window which contains the pointer. */ - &root, - - /* Window pointer is on, not used */ - &dummy_window, - - /* The position on that root window. */ - x, y, - - /* x/y in dummy_window coordinates, not used. */ - &dummy, &dummy, - - /* Modifier keys and pointer buttons, about which - we don't care. */ - (unsigned int *) &dummy); - - - /* Absolute to relative. */ - *x -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); - *y -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); - - unblock_input (); -} - DEFUN ("x-get-atom-name", Fx_get_atom_name, Sx_get_atom_name, 1, 2, 0, doc: /* Return the X atom name for VALUE as a string. @@ -2529,7 +2492,7 @@ x_handle_dnd_message (struct frame *f, const XClientMessageEvent *event, event->format, size)); - mouse_position_for_drop (f, &x, &y); + x_relative_mouse_position (f, &x, &y); bufp->kind = DRAG_N_DROP_EVENT; bufp->frame_or_window = frame; bufp->timestamp = CurrentTime; diff --git a/src/xterm.c b/src/xterm.c index c817174bb3..a7f77bdb28 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -358,8 +358,10 @@ x_find_topmost_parent (struct frame *f) unsigned int nchildren; win = wi; - XQueryTree (dpy, win, &root, &wi, &children, &nchildren); - XFree (children); + if (XQueryTree (dpy, win, &root, &wi, &children, &nchildren)) + XFree (children); + else + break; } return win; diff --git a/src/xterm.h b/src/xterm.h index 6f6441a7f6..6d80d1253a 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -914,6 +914,7 @@ struct selection_input_event /* From xfns.c. */ extern void x_free_gcs (struct frame *); +extern void x_relative_mouse_position (struct frame *, int *, int *); /* From xrdb.c. */