summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog12
-rw-r--r--src/menu.c2
-rw-r--r--src/menu.h3
-rw-r--r--src/xfns.c37
-rw-r--r--src/xmenu.c47
-rw-r--r--src/xselect.c39
-rw-r--r--src/xterm.c6
-rw-r--r--src/xterm.h1
8 files changed, 55 insertions, 92 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c845568ddcf..ca45462cab3 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,15 @@
+2014-06-22 Dmitry Antipov <dmantipov@yandex.ru>
+
+ * 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 <eliz@gnu.org>
* indent.c (Fvertical_motion): Doc fix.
diff --git a/src/menu.c b/src/menu.c
index 460dc7967b5..a523cfc6010 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 643ff40fef8..30a89bead26 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 a7caa53e522..c3d9900207f 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 2d41350e737..e04a801ef71 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 28f2d770a77..89ec1da30b2 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 c817174bb3f..a7f77bdb282 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 6f6441a7f68..6d80d1253ae 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. */