stumpwm-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[STUMP] Elementary ruler


From: sea
Subject: [STUMP] Elementary ruler
Date: Tue, 02 Sep 2014 01:36:26 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Hi all, I just made this simple ruler for use with mapwork. It prints
the current mouse position, and for any two consecutive calls, it prints
the distance the mouse has travelled between the two. It's meant to be
bound to a hotkey.


(defvar *last-cursor-queried-position* (list 0 0))

(defun euclidean-distance (a b)
  (expt (apply #'+ (mapcar (lambda (x) (* x x)) (mapcar #'- a b)))))

(defun cursor-position ()
  (let ((x (multiple-value-list
            (xlib:pointer-position 
             (stumpwm::screen-root (stumpwm:current-screen))))))
    (list (first x) (second x))))

(defcommand show-cursor-position () ()
            (let* ((pos (cursor-position))
                   (last-point *last-cursor-queried-position*)
                   (distance-from-last-point
                    (if *last-cursor-queried-position* 
                        (euclidean-distance *last-cursor-queried-position* pos)
                        nil)))
              (setf *last-cursor-queried-position* pos)
              (stumpwm:message 
               (format nil 
                       "Now: ~A Distance from last queried point (~A): ~A~%"
                       pos last-point distance-from-last-point))))


There's no error checking or documentation or anything but I doubt it
will ever fail.

It's handy when bound to <key>. Put the cursor at the start of a line,
hit <key>, then put the cursor at the end of the line, hit <key>, it
prints the length of the line, with a small error down to the accuracy
of your cursor positioning. Handy for measuring distances on maps, as
long as you have a scale line to compare the lengths to.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]