Commit fea86e44 authored by Yuanle Song's avatar Yuanle Song
Browse files

update `zero-get-point-position'

in emacs 25+, now it's accurate when tool-bar, menu-bar is enabled.
in emacs 24 or lower, tool-bar, menu-bar are not well supported.
parent 8230b89a
Loading
Loading
Loading
Loading
+26 −3
Original line number Diff line number Diff line
@@ -59,9 +59,32 @@ respectively."

(defun zero-get-point-position ()
  "return current point's position (x y) based on origin of screen top left corner"
  (destructuring-bind (x y h) (ibus-compute-pixel-position)
    (list (+ (frame-parameter nil 'left) x)
	  (+ (frame-parameter nil 'top) h y))))
  (destructuring-bind (x y line-height) (ibus-compute-pixel-position)
    (cond
     ((functionp 'window-absolute-pixel-position)
      ;; introduced in emacs 26
      (destructuring-bind (x . y) (window-absolute-pixel-position)
	(list x (+ y line-height))))
     ((functionp 'frame-edges)
      ;; introduced in emacs 25
      (destructuring-bind (frame-x frame-y &rest _)
	  (frame-edges nil 'inner-edges)
	(list (+ frame-x x) (+ frame-y y line-height))))
     (t
      ;; <= emacs 24, used guessed pixel size for tool-bar, menu-bar, WM title
      ;; bar. Since I can't get that from elisp.
      (list (+ (frame-parameter nil 'left)
	       (if (and (> (frame-parameter nil 'tool-bar-lines) 0)
			(eq (frame-parameter nil 'tool-bar-position) 'left))
		   96 0)
	       x)
	    (+ (frame-parameter nil 'top)
	       (if (and (> (frame-parameter nil 'tool-bar-lines) 0)
			(eq (frame-parameter nil 'tool-bar-position) 'top))
		   42 0)
	       (if (> (frame-parameter nil 'menu-bar-lines) 0) (+ 30 30) 0)
	       line-height
	       y))))))

(defun zero-cycle-list (lst item)
  "return the object next to given item in lst, if item is the last object, return the first object in lst.