1 ;;; xwem-transient.el --- Transient for clients support.
3 ;; Copyright (C) 2004,2005 by XWEM Org.
5 ;; Author: Zajcev Evgeny <zevlg@yandex.ru>
6 ;; Steve Youngs <steve@youngs.au.com>
7 ;; Created: Sat Jun 5 01:33:25 MSD 2004
9 ;; X-CVS: $Id: xwem-transient.el,v 1.6 2005-04-04 19:54:16 lg Exp $
11 ;; This file is part of XWEM.
13 ;; XWEM is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; XWEM is distributed in the hope that it will be useful, but WITHOUT
19 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
21 ;; License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 ;;; Synched up with: Not in FSF
38 (require 'xwem-manage)
41 (defgroup xwem-transient nil
42 "Group to customize transient clients support."
43 :prefix "xwem-transient-"
46 (defcustom xwem-transient-client-properties
47 '(x-border-width 2 x-border-color "blue4")
48 "*Client properties to use when managing transient clients."
50 :group 'xwem-transient)
52 (defcustom xwem-transient-switch-back t
53 "*Non-nil mean when transient client dies, switch to client who created it."
55 :group 'xwem-transient)
57 ;;; Internal variables
59 (defvar xwem-transient-keymap
60 (let ((map (make-sparse-keymap)))
61 (define-key map (xwem-kbd "C-<button1>") 'xwem-client-imove)
62 (define-key map (xwem-kbd "C-<button2>") 'xwem-client-idestroy)
63 (define-key map (xwem-kbd "C-<button3>") 'xwem-client-iresize)
65 "Local keymap for transient-for clients.")
67 (define-xwem-deffered xwem-transient-on-select-cl (&optional cl)
68 "CL just selected, check if it has transient-for windows.
71 (setq cl (xwem-cl-selected)))
74 (let ((trfcls (xwem-cl-list-sort-by-recency (xwem-cl-translist cl))))
76 (when (eq (xwem-cl-state (car trfcls)) 'active)
77 (xwem-select-client (car trfcls))
79 (setq trfcls (cdr trfcls)))
82 ;;;; ---- Transient for manage methods ----
84 ;; NOTE: Uses default refit
85 (defun xwem-cl-transient-for-p (cl)
86 "Return non-nil if CL is transient for client."
87 (xwem-hints-wm-transient-for (xwem-cl-hints cl)))
89 (defun xwem-manage-transient-for (cl)
90 "Manage CL that have transient-for flag."
91 ;; Map window for witch CL is transient and just map and raise CL
93 (let ((xwin (xwem-cl-xwin cl))
94 (trc (xwem-xwin-cl (xwem-cl-transient-for cl))))
96 ;; Apply properties specific to transient-for clients
97 (xwem-cl-apply-plist cl xwem-transient-client-properties)
99 ;; XXX make root window be parent
100 (XReparentWindow (xwem-dpy) xwin (xwem-rootwin)
101 (X-Geom-x (xwem-cl-xgeom cl))
102 (X-Geom-y (xwem-cl-xgeom cl)))
104 (when (xwem-cl-p trc)
105 (setf (xwem-cl-translist trc)
106 (cons cl (xwem-cl-translist trc)))
107 ;; And inherit always on top rank
108 (xwem-misc-set-xwin-always-on-top
109 (xwem-cl-xwin cl) (xwem-xwin-rank (xwem-cl-xwin trc))))
111 ;; Install transient local keymap
112 (xwem-use-local-map xwem-transient-keymap cl)
114 ;; Select it if needed
116 (xwem-cl-selected-p trc))
117 (xwem-select-client cl))))
119 (define-xwem-deffered xwem-transient-apply-state (cl)
120 "Apply CL's state to life."
121 (cond ((eq (xwem-cl-state cl) 'active)
122 (xwem-misc-raise-xwin (xwem-cl-xwin cl))
123 (XMapWindow (xwem-dpy) (xwem-cl-xwin cl)))
125 ((eq (xwem-cl-state cl) 'inactive)
126 (xwem-misc-lower-xwin (xwem-cl-xwin cl)))
127 ((eq (xwem-cl-state cl) 'iconified)
128 (XUnmapWindow (xwem-dpy) (xwem-cl-xwin cl)))))
130 (defun xwem-activate-transient-for (cl &optional type)
131 "Activate method for transient-for client CL."
132 (cond ((eq type 'select)
133 (let ((trc (xwem-xwin-cl (xwem-cl-transient-for cl))))
134 (when (xwem-cl-p trc)
135 (xwem-activate trc)))
136 (xwem-deffered-funcall 'xwem-misc-raise-xwin (xwem-cl-xwin cl)))
139 (xwem-transient-apply-state cl)
140 (let ((trc (xwem-xwin-cl (xwem-cl-transient-for cl))))
141 (when (and (xwem-cl-p trc)
142 (xwem-cl-selected-p trc))
143 (xwem-select-client cl))))
146 (defun xwem-deactivate-transient-for (cl &optional type)
147 "Deactivate method for transient-for client CL."
148 (cond ((eq type 'deactivate)
149 (xwem-transient-apply-state cl))))
151 (defun xwem-iconify-transient-for (cl &optional type)
152 "Iconify method for transient-for client CL."
153 (xwem-transient-apply-state cl))
155 (defun xwem-withdraw-transient-for (cl)
156 "Withdraw method for transient-for CL."
157 (let ((trc (xwem-xwin-cl (xwem-cl-transient-for cl))))
158 (when (and (xwem-cl-selected-p cl)
159 (xwem-cl-p trc) (xwem-cl-active-p trc))
160 (xwem-select-client trc))))
162 ;;; Additional methods
163 (define-xwem-method on-kill transient-for (cl)
164 "On-kill method for transient-for clients."
165 (let ((trc (xwem-xwin-cl (xwem-cl-transient-for cl))))
166 (when (xwem-cl-p trc)
167 (setf (xwem-cl-translist trc)
168 (delq cl (xwem-cl-translist trc)))
170 (when (and (xwem-cl-selected-p cl)
171 (xwem-cl-active-p trc))
172 (xwem-select-client trc)))))
175 (provide 'xwem-transient)
178 (define-xwem-manage-model transient-for
179 "Manage models for clients with TRANSIENT_FOR property."
180 :match-spec '(function xwem-cl-transient-for-p)
182 :manage-properties '(override-manage-list t)
183 :manage-method 'xwem-manage-transient-for
184 :activate-method 'xwem-activate-transient-for
185 :deactivate-method 'xwem-deactivate-transient-for
186 :iconify-method 'xwem-iconify-transient-for
187 :withdraw-method 'xwem-withdraw-transient-for)
189 (add-hook 'xwem-client-select-hook 'xwem-transient-on-select-cl)
191 ;;; xwem-transient.el ends here