1;; auto-raise.jl -- auto-raise on focus 2 3;; Copyright (C) 1999 John Harper <john@dcs.warwick.ac.uk> 4 5;; This file is part of sawfish. 6 7;; sawfish is free software; you can redistribute it and/or modify it 8;; under the terms of the GNU General Public License as published by 9;; the Free Software Foundation; either version 2, or (at your option) 10;; any later version. 11 12;; sawfish is distributed in the hope that it will be useful, but 13;; WITHOUT ANY WARRANTY; without even the implied warranty of 14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15;; GNU General Public License for more details. 16 17;; You should have received a copy of the GNU General Public License 18;; along with sawfish; see the file COPYING. If not, write to 19;; the Free Software Foundation, 51 Franklin Street, Fifth Floor, 20;; Boston, MA 02110-1301 USA. 21 22(define-structure sawfish.wm.ext.auto-raise 23 24 (export ) 25 26 (open rep 27 rep.system 28 rep.io.timers 29 sawfish.wm.windows 30 sawfish.wm.custom 31 sawfish.wm.util.stacking) 32 33 (define-structure-alias auto-raise sawfish.wm.ext.auto-raise) 34 35 (defgroup auto-raise "Auto-Raise" :group focus) 36 37 (defcustom raise-windows-on-focus t 38 "Raise windows when they are focused." 39 :type boolean 40 :require sawfish.wm.ext.auto-raise 41 :group (focus auto-raise)) 42 43 (defcustom raise-window-timeout 500 44 "Delay in milliseconds until focused windows are raised." 45 :type number 46 :depends raise-windows-on-focus 47 :group (focus auto-raise)) 48 49 ;; Used to suppress temporarily in some commands. 50 (defvar disable-auto-raise nil) 51 52 (define rw-timer nil) 53 (define rw-window nil) 54 55 (define (rw-disable-timer) 56 (when rw-timer 57 (setq rw-window nil) 58 (delete-timer rw-timer) 59 (setq rw-timer nil))) 60 61 (define (rw-on-focus w mode) 62 (declare (unused mode)) 63 (when (not disable-auto-raise) 64 (if (or (window-get w 'raise-on-focus) raise-windows-on-focus) 65 (progn 66 (setq rw-window w) 67 (if rw-timer 68 (set-timer rw-timer) 69 (let ((timer-callback (lambda (timer) 70 (if disable-auto-raise 71 (set-timer timer) 72 (setq rw-timer nil) 73 (raise-window* rw-window)))) 74 (delay (max 1 raise-window-timeout))) 75 (setq rw-timer (make-timer timer-callback 76 (quotient delay 1000) 77 (mod delay 1000)))))) 78 (rw-disable-timer)))) 79 80 (define (rw-out-focus w mode) 81 (declare (unused mode)) 82 (when (and rw-timer (eq rw-window w)) 83 (rw-disable-timer))) 84 85 (add-hook 'focus-in-hook rw-on-focus) 86 (add-hook 'focus-out-hook rw-out-focus)) 87