forked from stumpwm/stumpwm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wse.lisp
156 lines (127 loc) · 4.99 KB
/
wse.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
;; Copyright 2011 Michael Raskin
;;
;; Maintainer: Michael Raskin
;;
;; This file is part of stumpwm.
;;
;; stumpwm is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; stumpwm is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this software; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;; Boston, MA 02111-1307 USA
;; Window Selection Expressions
(in-package :stumpwm)
(export '(move-windows-to-group act-on-matching-windows))
(defun move-windows-to-group (windows &optional (arggroup nil))
"Move all windows from the list to the group"
(let*
((group
(if (stringp arggroup)
(or
(find-group (current-screen) arggroup)
(add-group (current-screen) arggroup))
(or arggroup (current-group)))))
(mapcar (lambda (w) (move-window-to-group w group)) windows)))
(defgeneric
list-windows (range)
(:documentation "List all the windows in a set."))
(defmethod list-windows ((range t))
(error "Unknown kind of window set"))
(defmethod list-windows ((range (eql :screen)))
(list-windows (current-screen)))
(defmethod list-windows ((range (eql :group)))
(list-windows (current-group)))
(defmethod list-windows ((range (eql :frame)))
(list-windows (tile-group-current-frame (current-group))))
(defmethod list-windows ((range screen))
(screen-windows range))
(defmethod list-windows ((range group))
(group-windows range))
(defmethod list-windows ((range frame))
(frame-windows (current-group) range))
(defmethod list-windows ((range list)) range)
(defmacro act-on-matching-windows
((var &optional (range '(current-screen))) condition &rest code)
"Run code on all windows matching condition; var is the shared lambda
variable. Range can be any screen/group/frame or :screen/:group/:frame
for the current instance. Condition is just the code to evaluate."
`(let
((range ,range))
(loop for ,var in
(cond
((typep range 'screen) (screen-windows range))
((typep range 'group) (group-windows range))
((typep range 'frame) (frame-windows (current-group) range))
((typep range 'list) range)
((eq range :screen) (screen-windows (current-screen)))
((eq range :group)
(group-windows (current-group)))
((eq range :frame)
(frame-windows (current-group)
(tile-group-current-frame
(current-group))))
(t (error "Unknown kind of window set")))
when ,condition
collect (progn ,@code))))
(defun pull-w (w &optional g)
"Pull the window w: to the current group or to the specified group g."
(move-windows-to-group (list w) (or g (current-group))))
(defun titled-p (w title)
"Check whether window title of the window w is equal to the string
title."
(equal (window-title w) title))
(defun title-re-p (w tre)
"Check whether the window title of the window w matches the regular
expression tre."
(cl-ppcre:scan tre (window-title w)))
(defun classed-p (w class)
"Check whether the window class of the window w is equal to the string
class."
(equal (window-class w) class))
(defun class-re-p (w cre)
"Check whether the window class of the window w matches the regular
expression cre."
(cl-ppcre:scan cre (window-class w)))
(defun typed-p (w type)
"Check whether the window type of the window w is equal to the string
type."
(equal (window-type w) type))
(defun type-re-p (w tre)
"Check whether the window type of the window w matches the regular
expression tre."
(cl-ppcre:scan tre (window-type w)))
(defun roled-p (w role)
"Check whether the window role of the window w is equal to the string
role."
(equal (window-role w) role))
(defun role-re-p (w rre)
"Check whether the window role of the window w matches the regular
expression rre."
(cl-ppcre:scan rre (window-role w)))
(defun resed-p (w res)
"Check whether the window resource of the window w is equal to the
string res."
(equal (window-res w) res))
(defun res-re-p (w rre)
"Check whether the window resource of the window w matches the regular
expression rre."
(cl-ppcre:scan rre (window-res w)))
(defun grouped-p (w &optional name)
"Check whether the window w belongs to the group name or the current
group if name is not specified."
(if name
(equal name (group-name (window-group w)))
(equal (window-group w) (current-group))))
(defun in-frame-p (w &optional f)
"Check whether the window w belongs to the frame f or to the current
frame if the frame is not specified."
(eq (window-frame w)
(or f (tile-group-current-frame
(current-group (current-screen))))))