aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2003-01-18 09:55:37 +0000
committerJan Djärv2003-01-18 09:55:37 +0000
commita894238b8c88e9f574a0b106f6f1c0097cd537f7 (patch)
treee2b417a998a62681131796f5f328be5060f10dd4 /src
parent2ee398c4c253f33628a7ceed3d428dd5f9e9d872 (diff)
downloademacs-a894238b8c88e9f574a0b106f6f1c0097cd537f7.tar.gz
emacs-a894238b8c88e9f574a0b106f6f1c0097cd537f7.zip
(mouse_position_for_popup): New function.
(Fx_popup_menu): Call mouse_position_for_popup for X and mouse_position_hook for others.
Diffstat (limited to 'src')
-rw-r--r--src/xmenu.c118
1 files changed, 81 insertions, 37 deletions
diff --git a/src/xmenu.c b/src/xmenu.c
index d4c09edfa5d..e4b039808ec 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -669,6 +669,56 @@ list_of_items (pane)
669 } 669 }
670} 670}
671 671
672#ifdef HAVE_X_WINDOWS
673/* Return the mouse position in *X and *Y. The coordinates are window
674 relative for the edit window in frame F.
675 This is for Fx_popup_menu. The mouse_position_hook can not
676 be used for X, as it returns window relative coordinates
677 for the window where the mouse is in. This could be the menu bar,
678 the scroll bar or the edit window. Fx_popup_menu needs to be
679 sure it is the edit window. */
680static void
681mouse_position_for_popup(f, x, y)
682 FRAME_PTR f;
683 int *x;
684 int *y;
685{
686 Window root, dummy_window;
687 int dummy;
688
689 BLOCK_INPUT;
690
691 XQueryPointer (FRAME_X_DISPLAY (f),
692 DefaultRootWindow (FRAME_X_DISPLAY (f)),
693
694 /* The root window which contains the pointer. */
695 &root,
696
697 /* Window pointer is on, not used */
698 &dummy_window,
699
700 /* The position on that root window. */
701 x, y,
702
703 /* x/y in dummy_window coordinates, not used. */
704 &dummy, &dummy,
705
706 /* Modifier keys and pointer buttons, about which
707 we don't care. */
708 (unsigned int *) &dummy);
709
710 UNBLOCK_INPUT;
711
712 /* xmenu_show expects window coordinates, not root window
713 coordinates. Translate. */
714 *x -= f->output_data.x->left_pos
715 + FRAME_OUTER_TO_INNER_DIFF_X (f);
716 *y -= f->output_data.x->top_pos
717 + FRAME_OUTER_TO_INNER_DIFF_Y (f);
718}
719
720#endif /* HAVE_X_WINDOWS */
721
672DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, 722DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0,
673 doc: /* Pop up a deck-of-cards menu and return user's selection. 723 doc: /* Pop up a deck-of-cards menu and return user's selection.
674POSITION is a position specification. This is either a mouse button event 724POSITION is a position specification. This is either a mouse button event
@@ -730,44 +780,38 @@ cached information about equivalent key sequences. */)
730 { 780 {
731 /* Use the mouse's current position. */ 781 /* Use the mouse's current position. */
732 FRAME_PTR new_f = SELECTED_FRAME (); 782 FRAME_PTR new_f = SELECTED_FRAME ();
733 Window root, dummy_window; 783#ifdef HAVE_X_WINDOWS
734 int cur_x, cur_y, dummy; 784 /* Can't use mouse_position_hook for X since it returns
735 785 coordinates relative to the window the mouse is in,
736 BLOCK_INPUT; 786 we need coordinates relative to the edit widget always. */
787 if (new_f != 0)
788 {
789 int cur_x, cur_y;
790
791 mouse_position_for_popup (new_f, &cur_x, &cur_y);
792 /* cur_x/y may be negative, so use make_number. */
793 x = make_number (cur_x);
794 y = make_number (cur_y);
795 }
737 796
738 XQueryPointer (FRAME_X_DISPLAY (new_f), 797#else /* not HAVE_X_WINDOWS */
739 DefaultRootWindow (FRAME_X_DISPLAY (new_f)), 798 Lisp_Object bar_window;
740 799 enum scroll_bar_part part;
741 /* The root window which contains the pointer. */ 800 unsigned long time;
742 &root, 801
743 802 if (mouse_position_hook)
744 /* Window pointer is on, not used */ 803 (*mouse_position_hook) (&new_f, 1, &bar_window,
745 &dummy_window, 804 &part, &x, &y, &time);
746 805#endif /* not HAVE_X_WINDOWS */
747 /* The position on that root window. */ 806
748 &cur_x, &cur_y, 807 if (new_f != 0)
749 808 XSETFRAME (window, new_f);
750 /* x/y in dummy_window coordinates, not used. */ 809 else
751 &dummy, &dummy, 810 {
752 811 window = selected_window;
753 /* Modifier keys and pointer buttons, about which 812 XSETFASTINT (x, 0);
754 we don't care. */ 813 XSETFASTINT (y, 0);
755 (unsigned int *) &dummy); 814 }
756
757 UNBLOCK_INPUT;
758
759 /* xmenu_show expects window coordinates, not root window
760 coordinates. Translate. */
761 cur_x -= new_f->output_data.x->left_pos
762 + FRAME_OUTER_TO_INNER_DIFF_X (new_f);
763 cur_y -= new_f->output_data.x->top_pos
764 + FRAME_OUTER_TO_INNER_DIFF_Y (new_f);
765
766 /* cur_x/y may be negative, so use make_number. */
767 x = make_number (cur_x);
768 y = make_number (cur_y);
769
770 XSETFRAME (window, new_f);
771 } 815 }
772 else 816 else
773 { 817 {