;; focus-tracker.jl
;;
;; Adam Spiers <adam@spiers.net>
;;
;; Logs events associated to focus change to a logfile
;;
;; See homepage for latest version and accompanying statistics program:
;; http://adamspiers.org/computing/sawfish/
;;
;; $Id$
;;

(setq focus-tracker-logfile "~/.sawfish/focus.log")

(defun track-focus-in (w)
  "track-focus-in logs a focus-in event to the file specified by
`focus-tracker-logfile'"
  (let
      ((logfile (open-file focus-tracker-logfile 'append)))
    (format logfile "%s %5d: ws{%d} name{%s} class{%s}\n"
            (current-time-string nil "%d/%m/%Y")
            (cdr (current-time))
            current-workspace
            (window-full-name w)
            (nth 2 (get-x-property w 'WM_CLASS)))
    (close-file logfile)))

(add-hook 'focus-in-hook track-focus-in)

(defun remove-first-focus-in-hook ()
  "Removes first hook from `focus-in-hook' hook-list."
  (setq focus-in-hook (cdr focus-in-hook)))

(provide 'focus-tracker)
