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

« back to all changes in this revision

Viewing changes to lisp/sawfish/wm/util/prompt-wm.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
;; prompt-wm.jl -- prompt variants for windows/workspaces
 
2
;; $Id: prompt-wm.jl,v 1.6 2000/09/11 07:44:42 john Exp $
 
3
 
 
4
;; Contributed by Dave Pearson <davep@davep.org>
 
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
(declare (in-module sawfish.wm.util.prompt))
 
23
 
 
24
(require 'sawfish.wm.workspace)
 
25
(require 'sawfish.wm.windows)
 
26
 
 
27
(define (prompt-for-window #!optional title)
 
28
  "Prompt for a window title, return the window associated with that title."
 
29
  (letrec ((show-in-list-p
 
30
            (lambda (w)
 
31
              (and
 
32
               (not (window-get w 'ignored))
 
33
               (window-get w 'workspaces))))
 
34
           (window-names
 
35
            (lambda (windows)
 
36
              (when windows
 
37
                (if (show-in-list-p (car windows))
 
38
                    (cons (window-name (car windows))
 
39
                          (window-names (cdr windows)))
 
40
                  (window-names (cdr windows))))))
 
41
           (names-matching
 
42
            (lambda (re names)
 
43
              (when names
 
44
                (if (string-match re (car names))
 
45
                    (cons (car names) (names-matching re (cdr names)))
 
46
                  (names-matching re (cdr names))))))
 
47
           (prompt-completion-fun
 
48
            (lambda (text)
 
49
              (names-matching (format nil "^%s" text)
 
50
                              (sort (window-names (managed-windows)))))))
 
51
    (let ((window-title (prompt (or title (_ "Window:")))))
 
52
      (unless (zerop (length window-title))
 
53
        (cdr (assoc window-title (mapcar (lambda (w)
 
54
                                           (cons (window-name w) w))
 
55
                                         (managed-windows))))))))
 
56
 
 
57
(define (prompt-for-workspace #!optional title)
 
58
  "Prompt for a workspace title, return the workspace number."
 
59
  (letrec ((make-workspace-list
 
60
            (lambda (ws)
 
61
              (unless (zerop ws)
 
62
                (cons (or (nth (1- ws) workspace-names)
 
63
                          (format nil (_ "Workspace %d") ws))
 
64
                      (make-workspace-list (1- ws))))))
 
65
           (workspaces
 
66
            (lambda ()
 
67
              (reverse (make-workspace-list (1+ (cdr (workspace-limits)))))))
 
68
           (names-matching
 
69
            (lambda (re names)
 
70
              (when names
 
71
                (if (string-match re (car names))
 
72
                    (cons (car names) (names-matching re (cdr names)))
 
73
                  (names-matching re (cdr names))))))
 
74
           (prompt-completion-fun
 
75
            (lambda (text)
 
76
              (names-matching (format nil "^%s" text) (workspaces)))))
 
77
    (let ((ws-title (prompt (or title (_ "Workspace:"))))
 
78
          (wsl (workspaces)))
 
79
      (unless (zerop (length ws-title))
 
80
        (let ((where (member ws-title wsl)))
 
81
          (when where
 
82
            (- (length wsl) (length where))))))))