~ubuntu-branches/ubuntu/lucid/sawfish/lucid-updates

« back to all changes in this revision

Viewing changes to lisp/sawfish/wm/ext/audio-events.jl

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2002-01-20 17:42:28 UTC
  • Revision ID: james.westby@ubuntu.com-20020120174228-4q1ydztbkvfq1ht2
Tags: upstream-1.0.1.20020116
ImportĀ upstreamĀ versionĀ 1.0.1.20020116

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;; audio-events.jl -- map wm actions to audio samples
 
2
;; $Id: audio-events.jl,v 1.12 2001/01/08 00:37:28 jsh Exp $
 
3
 
 
4
;; Copyright (C) 2000 John Harper <john@dcs.warwick.ac.uk>
 
5
 
 
6
;; This file is part of sawmill.
 
7
 
 
8
;; sawmill is free software; you can redistribute it and/or modify it
 
9
;; under the terms of the GNU General Public License as published by
 
10
;; the Free Software Foundation; either version 2, or (at your option)
 
11
;; any later version.
 
12
 
 
13
;; sawmill is distributed in the hope that it will be useful, but
 
14
;; WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
;; GNU General Public License for more details.
 
17
 
 
18
;; You should have received a copy of the GNU General Public License
 
19
;; along with sawmill; see the file COPYING.  If not, write to
 
20
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 
 
22
;;;###autoload (defgroup audio "Sound" :require sawfish.wm.ext.audio-events)
 
23
 
 
24
(define-structure sawfish.wm.ext.audio-events
 
25
 
 
26
    (export audio-event-handler)
 
27
 
 
28
    (open rep
 
29
          rep.system
 
30
          sawfish.wm.custom
 
31
          sawfish.wm.windows
 
32
          sawfish.wm.state.maximize)
 
33
 
 
34
  (define-structure-alias audio-events sawfish.wm.ext.audio-events)
 
35
 
 
36
  (defgroup audio "Sound"
 
37
    :require sawfish.wm.ext.audio-events)
 
38
 
 
39
  ;; XXX it would be cool to merge the customization with the GNOME sound prefs
 
40
 
 
41
  (defcustom audio-events-enabled nil
 
42
    "Play sound effects for window events."
 
43
    :type boolean
 
44
    :user-level novice
 
45
    :require sawfish.wm.ext.audio-events
 
46
    :group audio)
 
47
 
 
48
  (defcustom audio-for-ignored-windows nil
 
49
    "Play sound effects for unmanaged windows."
 
50
    :type boolean
 
51
    :depends audio-events-enabled
 
52
    :group audio)
 
53
 
 
54
  ;; standard events are: iconified, uniconified, shaded, unshaded,
 
55
  ;; maximized, unmaximized, mapped, unmapped, mapped-transient,
 
56
  ;; unmapped-transient, switch-workspace, move-viewport, focused,
 
57
  ;; unfocused
 
58
 
 
59
  (defcustom audio-events-alist '((iconified . "slide.wav")
 
60
                                  (uniconified . "slide.wav")
 
61
                                  (shaded . "slide.wav")
 
62
                                  (unshaded . "slide.wav")
 
63
                                  (maximized . "slide.wav")
 
64
                                  (unmaximized . "slide.wav")
 
65
                                  (mapped . "activate.wav")
 
66
                                  (unmapped . "gameover.wav")
 
67
                                  (mapped-transient . "activate.wav")
 
68
                                  (unmapped-transient . "toggled.wav")
 
69
                                  ;(focused . "clicked.wav")
 
70
                                  (switch-workspace . "toggled.wav")
 
71
                                  (move-viewport . "toggled.wav"))
 
72
    nil
 
73
    :type* `(alist ((symbol iconified uniconified
 
74
                            shaded unshaded
 
75
                            maximized unmaximized
 
76
                            mapped unmapped
 
77
                            mapped-transient unmapped-transient
 
78
                            switch-workspace move-viewport
 
79
                            focused unfocused) ,(_ "Event"))
 
80
                   (file ,(_ "Audio file")))
 
81
    :widget-flags (expand-vertically)
 
82
    :depends audio-events-enabled
 
83
    :group audio)
 
84
 
 
85
  (defun audio-event-handler (event #!optional w)
 
86
    "Possibly play a sound sample for EVENT (a symbol) occurring on window W."
 
87
    (when (and audio-events-enabled
 
88
               (or (null w)
 
89
                   (not (window-get w 'ignored))
 
90
                   audio-for-ignored-windows))
 
91
      (let
 
92
          ((sample (cdr (assq event audio-events-alist))))
 
93
        (when sample
 
94
          (require 'sawfish.wm.util.play-audio)
 
95
          (play-sample sample)))))
 
96
 
 
97
;;; hooks
 
98
 
 
99
  (defun audio-state-change-fun (w states)
 
100
    (mapc (lambda (state)
 
101
            (case state
 
102
              ((iconified)
 
103
               (audio-event-handler (if (window-get w 'iconified)
 
104
                                        'iconified 'uniconified) w))
 
105
              ((shaded)
 
106
               (audio-event-handler (if (window-get w 'shaded)
 
107
                                        'shaded 'unshaded) w))
 
108
              ((maximized)
 
109
               (audio-event-handler (if (window-maximized-p w)
 
110
                                        'maximized 'unmaximized) w)))) states))
 
111
 
 
112
  (call-after-state-changed '(iconified shaded maximized)
 
113
                            audio-state-change-fun)
 
114
 
 
115
  (defun audio-focus-in-fun (w)
 
116
    (audio-event-handler 'focused w))
 
117
 
 
118
  (add-hook 'focus-in-hook audio-focus-in-fun)
 
119
 
 
120
  (defun audio-focus-out-fun (w)
 
121
    (audio-event-handler 'unfocused w))
 
122
 
 
123
  (add-hook 'focus-out-hook audio-focus-out-fun)
 
124
 
 
125
  (defun audio-mapped-fun (w)
 
126
    (audio-event-handler (if (window-transient-p w)
 
127
                             'mapped-transient 'mapped) w))
 
128
 
 
129
  (add-hook 'map-notify-hook audio-mapped-fun)
 
130
 
 
131
  (defun audio-unmapped-fun (w)
 
132
    (audio-event-handler (if (window-transient-p w)
 
133
                             'unmapped-transient 'unmapped) w))
 
134
 
 
135
  (add-hook 'unmap-notify-hook audio-unmapped-fun)
 
136
 
 
137
  (defun audio-enter-ws-fun ()
 
138
    (audio-event-handler 'switch-workspace))
 
139
 
 
140
  (add-hook 'enter-workspace-hook audio-enter-ws-fun)
 
141
 
 
142
  (defun audio-move-vp-fun ()
 
143
    (audio-event-handler 'move-viewport))
 
144
 
 
145
  (add-hook 'viewport-moved-hook audio-move-vp-fun))