Skip to content

Commit

Permalink
Merge commit '6d922e7dad67674ff9281c4e70161e722ea9a4b5' into merge-male
Browse files Browse the repository at this point in the history
Conflicts:

	core.lisp
  • Loading branch information
sabetts committed Sep 29, 2007
2 parents 3e42a85 + 6d922e7 commit 8c2a992
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 119 deletions.
9 changes: 5 additions & 4 deletions core.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,11 +1366,12 @@ T (default) then also focus the frame."
(setf (tile-group-current-frame group) f)
;; record the last frame to be used in the fother command.
(unless (eq f last)
(setf (tile-group-last-frame group) last))
(setf (tile-group-last-frame group) last)
(run-hook-with-args *focus-frame-hook* f last))
(if w
(focus-window w)
(no-focus group (frame-window last)))
(run-hook-with-args *focus-frame-hook* f last)))
(focus-window w)
(no-focus group (frame-window last)))))


(defun frame-windows (group f)
(remove-if-not (lambda (w) (eq (window-frame w) f))
Expand Down
58 changes: 10 additions & 48 deletions primitives.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,13 @@ single char keys are supported.")

(defun run-hook-with-args (hook &rest args)
"Call each function in HOOK and pass args to it"
;; FIXME: silently failing is bad
(ignore-errors
(dolist (fn hook)
(apply fn args))))
(dolist (fn hook)
(handler-case (apply fn args)
(error (c) (message "Error in function ~S on hook ~S!~% ~A" fn hook c) (values nil c)))))

(defun run-hook (hook)
"Call each function in HOOK."
;; FIXME: silently failing is bad
(ignore-errors
(run-hook-with-args hook)))
(run-hook-with-args hook))

(defmacro add-hook (hook fn)
"Add a function to a hook."
Expand Down Expand Up @@ -697,60 +694,25 @@ recommended this is assigned using LET.")
current group.")

(defvar *deny-map-request* nil
"A list of window names, window types, and class-id resource-id cons
pairs that stumpwm should deny matching windows' requests to become
mapped for the first time.
If set to T, then deny all map requests.
If a window type is added to the list stumpwm denies map
requests for the window type. Valid window types are :normal,
:transient, :maxsize.
If a the resource-id is nil in a class-id, resource-id cons pair
then only the class ID is matched.")
"A list of window properties that stumpwm should deny matching windows'
requests to become mapped for the first time.")

(defvar *deny-raise-request* nil
"A list of window names, window types, and class-id resource-id
cons pairs that stumpwm should deny matching windows' requests to
be raised and focused.
If set to T, then deny all raise requests.
If a window type is added to the list stumpwm denies
map requests for the window type. Valid window types are :normal,
:transient, :maxsize.
If a the resource-id is nil in a class-id, resource-id cons pair
then only the class ID is matched.")
"A list of window properties that stumpwm should deny matching windows'
requests to be raised and focused.")

(defvar *suppress-deny-messages* nil
"Set this to T so stumpwm doesn't notify you of denied raise/map requests.")

(defvar *honor-window-moves* t
"Allow windows to move between frames.")

;; FIXME: maybe this should be a method to allow user customizable matching?
(defun match-res-or-type (window res)
(or (and (stringp res)
(string-equal (window-name window) res))
(and (symbolp res)
(eq (window-type window) res))
;; if its a cons expect a class . res pair
(and (consp res)
(stringp (car res))
(string-equal (window-class window) (car res))
;; the res can be nil in order to match only the class
(or (null (cdr res))
(and (stringp (cdr res))
(string-equal (window-res window) (cdr res)))))))

(defun deny-request-p (window deny-list)
(or (eq deny-list t)
(and
(listp deny-list)
(find-if (lambda (res)
(match-res-or-type window res))
(find-if (lambda (props)
(apply 'window-matches-properties-p window props))
deny-list)
t)))

Expand Down
7 changes: 7 additions & 0 deletions sample-stumpwmrc.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
(define-key *root-map* (kbd "M-s") "google")
(define-key *root-map* (kbd "i") "imdb")


;; Using run-or-raise
(define-stumpwm-command "emacs" ()
(run-or-raise "emacs" '(:class "Emacs")))

(define-key *root-map* (kbd "E") "emacs")

;; Message window font
(set-font "-xos4-terminus-medium-r-normal--14-140-72-72-c-80-iso8859-15")

Expand Down
25 changes: 7 additions & 18 deletions stumpwm.texi
Original file line number Diff line number Diff line change
Expand Up @@ -945,18 +945,8 @@ A raise request occurs when a client asks the window manager to give
an existing window focus.

@defvar *deny-map-request*
A list of window names, window types, and class-id resource-id cons
pairs that stumpwm should deny matching windows' requests to become
mapped for the first time.

If set to @code{T}, then deny all map requests.

If a window type is added to the list stumpwm denies map requests for
the window type. Valid window types are @code{:normal},
@code{:transient}, @code{:maxsize}.

Furthermore, if a the resource-id is nil in a class-id, resource-id
cons pair then only the class ID is matched.
A list of window properties that stumpwm should deny matching windows'
requests to become mapped for the first time.
@end defvar

@defvar *deny-raise-request*
Expand All @@ -974,16 +964,16 @@ Some examples follow.

@example
;; Deny the firefox window from taking focus when clicked upon.
(push (cons "firefox-bin" "gecko") stumpwm:*deny-raise-request*)
(push '(:class "gecko") stumpwm:*deny-raise-request*)
;; Deny all map requests
(setf stumpwm:*deny-map-request* t)
;; Deny transient raise requests
(push :transient stumpwm:*deny-map-request*)
(push '(:transient) stumpwm:*deny-map-request*)
;; Deny the all windows in the xterm class from taking focus.
(push (cons "xterm" nil) stumpwm:*deny-raise-request*)
(push '(:class "Xterm") stumpwm:*deny-raise-request*)
@end example

@node Programming With Windows, , Controlling Raise And Map Requests, Windows
Expand Down Expand Up @@ -1547,10 +1537,9 @@ then describes the symbol.

@end defmac

@defun run-or-raise @var{command} &key @var{class} @var{instance} @var{title} @var{all-groups}
@defun run-or-raise @var{command} @var{props} @var{all-groups}
Run the shell command, @var{command}, unless an existing window
matches @var{class}, @var{instance}, and @var{title}. At least one
must be supplied.
matches @var{props}

By default, the global @var{*run-or-raise-all-groups*} decides whether
to search all groups or the current one for a running
Expand Down
78 changes: 29 additions & 49 deletions user.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,57 +1160,37 @@ aborted."
(define-stumpwm-command "move-window" ((dir :string "Direction: "))
(move-focus-and-or-window dir t))

(defun run-or-raise (cmd &key class instance title (all-groups *run-or-raise-all-groups*))
"If any of class, title, or instance are set and a matching window can
be found, select it. Otherwise simply run cmd."
(labels ((win-app-info (win)
(list (window-class win)
(window-res win)
(window-name win)))
;; Raise the window win and select its frame. For now, it
;; does not select the screen.
(goto-win (win)
(let* ((group (window-group win))
(frame (window-frame win))
(old-frame (tile-group-current-frame group)))
(switch-to-group group)
(frame-raise-window group frame win)
(focus-frame group frame)
(unless (eq frame old-frame)
(show-frame-indicator group))))
;; Compare two lists of strings representing window
;; attributes. If an element is nil it matches anything.
;; Doesn't handle lists of different lengths: extra
;; elements in one list will be ignored.
(app-info-cmp (match1 match2)
(or (not match1)
(not match2)
(let ((a (car match1))
(b (car match2)))
(and
(or (not a)
(not b)
(string= a b))
(app-info-cmp (cdr match1) (cdr match2))))))
(find-window (group)
(find (list class instance title)
(group-windows group)
:key #'win-app-info
:test #'app-info-cmp)))
(defun run-or-raise (cmd props &optional (all-groups *run-or-raise-all-groups*))
"If a window matching PROPS can be found, select it. Otherwise simply run cmd."
(labels
;; Raise the window win and select its frame. For now, it
;; does not select the screen.
((goto-win (win)
(let* ((group (window-group win))
(frame (window-frame win))
(old-frame (tile-group-current-frame group)))
(switch-to-group group)
(frame-raise-window group frame win)
(focus-frame group frame)
(unless (eq frame old-frame)
(show-frame-indicator group))))
(find-window (group)
(find-if (lambda (w)
(apply 'window-matches-properties-p w props))
(group-windows group))))
(let ((win
;; If no qualifiers are set don't bother looking for a match.
(and (or class instance title)
;; search all groups
(if all-groups
(loop
for g in (screen-groups (current-screen))
for win = (find-window g)
when win
return win)
(find-window (current-group))))))
;; If no qualifiers are set don't bother looking for a match.
;; search all groups
(if all-groups
(loop
for g in (screen-groups (current-screen))
for win = (find-window g)
when win
return win)
(find-window (current-group)))))
(if win
(goto-win win)
(run-shell-command cmd)))))
(goto-win win)
(run-shell-command cmd)))))

(define-stumpwm-command "shell" ()
(run-or-raise "xterm -title '*shell*'" :title "*shell*"))
Expand Down

0 comments on commit 8c2a992

Please sign in to comment.