Function: menu-bar-item-at-x

menu-bar-item-at-x is a byte-compiled function defined in menu-bar.el.gz.

Signature

(menu-bar-item-at-x X-POSITION)

Documentation

Return a cons of the form (KEY . X) for a menu item.

The returned X is the left X coordinate for that menu item.

X-POSITION is the X coordinate being queried. If nothing is clicked on, returns nil.

Source Code

;; Defined in /usr/src/emacs/lisp/menu-bar.el.gz
(defun menu-bar-item-at-x (x-position)
  "Return a cons of the form (KEY . X) for a menu item.
The returned X is the left X coordinate for that menu item.

X-POSITION is the X coordinate being queried.  If nothing is clicked on,
returns nil."
  (let ((column 0)
        (menu-bar (menu-bar-keymap))
        prev-key
        prev-column
        found)
    (catch 'done
      (map-keymap
       (lambda (key binding)
         (when (> column x-position)
           (setq found t)
           (throw 'done nil))
         (setq prev-key key)
         (pcase binding
           ((or `(,(and (pred stringp) name) . ,_) ;Simple menu item.
                `(menu-item ,name ,_cmd            ;Extended menu item.
                            . ,(and props
                                    (guard (let ((visible
                                                  (plist-get props :visible)))
                                             (or (null visible)
                                                 (eval visible)))))))
            (setq prev-column column
                  column (+ column (length name) 1)))))
       menu-bar)
      ;; Check the last menu item.
      (when (> column x-position)
        (setq found t)))
    (if found
        (cons prev-key prev-column)
      nil)))