Commits

lg  committed 8c1cf5d

* Makefile (AUTHOR_VERSION): 0.1 -> 0.2

* lisp/xwem-load.el: Removed at last.

* lisp/xwem-worklog.el (general): Autoloads added, fixes due to
new events processing scheme.

* lisp/xwem-win.el (general): Tabbing stuff totally
removed. autoloads added, various fixes and new custom variables
added, also too many changes to list.

* lisp/xwem-time.el (general): Fixes, using backing store X
feature.
* lisp/xwem-time.el (xwem-time): [fix] Exposure waiting removed.

* lisp/xwem-tabbing.el (general): Tabbing now totally independed,
using hooks mechanism to do the job, and fixes too many to list.
* lisp/xwem-tabbing.el (xwem-tabber-map): [new] Tabber keymap,
default bindings is <button1> and <button3>.

* lisp/xwem-strokes.el (general): Autoloads added.
* lisp/xwem-strokes.el (xwem-strokes-go): [fix] Use `xwem-next-event'.
* lisp/xwem-strokes.el (xwem-strokes-gc-function): [fix] typo.

* lisp/xwem-special.el (general): Autoloads added, fixes. Using
safe way when destroing special frame.

* lisp/xwem-rooter.el (xwem-rooter-auto-raised-regexp): [new] Not
yet implemented, sorry. Pretty complicated task, but possible.

* lisp/xwem-root.el (general): Tiny fixes.
* lisp/xwem-root.el (xwem-root-keymap): [addon]
xwem-popup-clients-menu on <button1> by default.

* lisp/xwem-register.el (general): Autoloads added.

* lisp/xwem-osd.el (general): Various tiny bug fixes, cleanup, etc.
* lisp/xwem-osd.el (xwem-osd-create): [addon] Properties
support. OSD can have its own keymap now.
* lisp/xwem-osd.el (xwem-osd-dots-add): [new] To plot dots set.
* lisp/xwem-osd.el (xwem-osd-create-dock): [new] Dockapp that uses
OSD primitives, i.e. dockappable osd.
* lisp/xwem-osd.el (xwem-osd-XXX-prop): [new] osd supports user
props.

* lisp/xwem-mouse.el (general): Autoloads added, little cleanup.
* lisp/xwem-mouse.el (xwem-popup-clients-menu): [new] Popup
clients menu.
* lisp/xwem-mouse.el (xwem-gen-cl-menu): [new] Generate popup menu
for CL.

* lisp/xwem-misc.el (general): Autoloads added, little cleanup,
few usefull functions added.
* lisp/xwem-misc.el (xwem-misc-draw-shadow): [fix] Optimization.
* lisp/xwem-misc.el (xwem-misc-outline): [new] Function to outline
some rectangle.

* lisp/xwem-minibuffer.el (general): Autoloads, new commented code
added, its usage is under argue.

* lisp/xwem-manage.el (general): Autoloads added, cleanup, few
usefull wrappers added.

* lisp/xwem-main.el (general): Autoloads added, little fixes.
* lisp/xwem-main.el (xwem-before-init-wins-hook): [new]
* lisp/xwem-main.el (xwem-after-init-wins-hook): [new]
More hookenization all over the place.

* lisp/xwem-macros.el (general): Autoloads added, little cleanup.

* lisp/xwem-launcher.el (general): Autoloads added.

* lisp/xwem-keymacro.el (general): Autoloads added, tiny fixes.

* lisp/xwem-keyboard.el (general): Autoloads added, minor fixes.
* lisp/xwem-keyboard.el (xwem-universal-key): [fix] `xwem-kbd'
usage eliminated.
* lisp/xwem-keyboard.el (xwem-kbd-evilmasks): [new] Mask
constructed from `xwem-kbd-evillocks'.
* lisp/xwem-keyboard.el (xwem-kbd-evillocks): [new] Locks that
totaly skipped when processing input events.

* lisp/xwem-help.el (general): Autoloads added.

* lisp/xwem-framei.el (xwem-framei-dockapp-XX): [new] Dockapp
support to show current frame in system tray.
* lisp/xwem-framei.el (xwem-framei-stop): [new] Destroy frame
indicator.

* lisp/xwem-frame.el (xwem-frame-imove): [new] Interactively move
frame.
* lisp/xwem-frame.el (xwem-frame-iresize): [new] Interactively
resize frame.
* lisp/xwem-frame.el (general): Tabbing stuff totally removed.
Various fixes: embedded frame fixes, autoloads added.
* lisp/xwem-frame.el (xwem-frame-XXX-hook): [new] More hookenization.
* lisp/xwem-frame.el (xwem-frame-omit-init-frame): [new] Non-nil
mean do not create frames at start time. Usefull if you want to
restore saved frame configuration from file at start time.
* lisp/xwem-frame.el (xwem-frame-autoiconify-mode): [new] Non-nil
mean autoiconify overlapping frames, when switching.
* lisp/xwem-frame.el (xwem-frame-iresize-mode): [new] Mode for
interactive frame resizing.
* lisp/xwem-frame.el (xwem-frame-imove-mode): [new] Mode for
interactive frame moving.
* lisp/xwem-frame.el (xwem-frame-imoveresize-mode-function): [new]
* lisp/xwem-frame.el (xwem-frame-imoveresize-mode-function-default): [new]

  • Participants
  • Parent commits 7664ae1

Comments (0)

Files changed (36)

+2004-05-06  Zajcev Evgeny  <zevlg@yandex.ru>
+
+	* Makefile (AUTHOR_VERSION): 0.1 -> 0.2
+
+	* lisp/xwem-load.el: Removed at last.
+
+	* lisp/xwem-worklog.el (general): Autoloads added, fixes due to
+	new events processing scheme.
+
+	* lisp/xwem-win.el (general): Tabbing stuff totally
+	removed. autoloads added, various fixes and new custom variables
+	added, also too many changes to list.
+
+	* lisp/xwem-time.el (general): Fixes, using backing store X
+	feature.
+	* lisp/xwem-time.el (xwem-time): [fix] Exposure waiting removed.
+
+	* lisp/xwem-tabbing.el (general): Tabbing now totally independed,
+	using hooks mechanism to do the job, and fixes too many to list.
+	* lisp/xwem-tabbing.el (xwem-tabber-map): [new] Tabber keymap,
+	default bindings is <button1> and <button3>.
+
+	* lisp/xwem-strokes.el (general): Autoloads added.
+	* lisp/xwem-strokes.el (xwem-strokes-go): [fix] Use `xwem-next-event'.
+	* lisp/xwem-strokes.el (xwem-strokes-gc-function): [fix] typo.
+
+	* lisp/xwem-special.el (general): Autoloads added, fixes. Using
+	safe way when destroing special frame.
+
+	* lisp/xwem-rooter.el (xwem-rooter-auto-raised-regexp): [new] Not
+	yet implemented, sorry.  Pretty complicated task, but possible.
+	
+	* lisp/xwem-root.el (general): Tiny fixes.
+	* lisp/xwem-root.el (xwem-root-keymap): [addon]
+	xwem-popup-clients-menu on <button1> by default.
+
+	* lisp/xwem-register.el (general): Autoloads added.
+
+	* lisp/xwem-osd.el (general): Various tiny bug fixes, cleanup, etc.
+	* lisp/xwem-osd.el (xwem-osd-create): [addon] Properties
+	support. OSD can have its own keymap now.
+	* lisp/xwem-osd.el (xwem-osd-dots-add): [new] To plot dots set.
+	* lisp/xwem-osd.el (xwem-osd-create-dock): [new] Dockapp that uses
+	OSD primitives, i.e. dockappable osd.
+	* lisp/xwem-osd.el (xwem-osd-XXX-prop): [new] osd supports user
+	props.
+
+	* lisp/xwem-mouse.el (general): Autoloads added, little cleanup.
+	* lisp/xwem-mouse.el (xwem-popup-clients-menu): [new] Popup
+	clients menu.
+	* lisp/xwem-mouse.el (xwem-gen-cl-menu): [new] Generate popup menu
+	for CL.
+
+	* lisp/xwem-misc.el (general): Autoloads added, little cleanup,
+	few usefull functions added.
+	* lisp/xwem-misc.el (xwem-misc-draw-shadow): [fix] Optimization.
+	* lisp/xwem-misc.el (xwem-misc-outline): [new] Function to outline
+	some rectangle.
+
+	* lisp/xwem-minibuffer.el (general): Autoloads, new commented code
+	added, its usage is under argue.
+
+	* lisp/xwem-manage.el (general): Autoloads added, cleanup, few
+	usefull wrappers added.
+
+	* lisp/xwem-main.el (general): Autoloads added, little fixes.
+	* lisp/xwem-main.el (xwem-before-init-wins-hook): [new]
+	* lisp/xwem-main.el (xwem-after-init-wins-hook): [new]
+	More hookenization all over the place.
+
+	* lisp/xwem-macros.el (general): Autoloads added, little cleanup.
+
+	* lisp/xwem-launcher.el (general): Autoloads added.
+
+	* lisp/xwem-keymacro.el (general): Autoloads added, tiny fixes.
+
+	* lisp/xwem-keyboard.el (general): Autoloads added, minor fixes.
+	* lisp/xwem-keyboard.el (xwem-universal-key): [fix] `xwem-kbd'
+	usage eliminated.
+	* lisp/xwem-keyboard.el (xwem-kbd-evilmasks): [new] Mask
+	constructed from `xwem-kbd-evillocks'.
+	* lisp/xwem-keyboard.el (xwem-kbd-evillocks): [new] Locks that
+	totaly skipped when processing input events.
+	
+	* lisp/xwem-help.el (general): Autoloads added.
+
+	* lisp/xwem-framei.el (xwem-framei-dockapp-XX): [new] Dockapp
+	support to show current frame in system tray.
+	* lisp/xwem-framei.el (xwem-framei-stop): [new] Destroy frame
+	indicator.
+
+	* lisp/xwem-frame.el (xwem-frame-imove): [new] Interactively move
+	frame.
+	* lisp/xwem-frame.el (xwem-frame-iresize): [new] Interactively
+	resize frame.
+	* lisp/xwem-frame.el (general): Tabbing stuff totally removed.
+	Various fixes: embedded frame fixes, autoloads added.
+	* lisp/xwem-frame.el (xwem-frame-XXX-hook): [new] More hookenization.
+	* lisp/xwem-frame.el (xwem-frame-omit-init-frame): [new] Non-nil
+	mean do not create frames at start time.  Usefull if you want to
+	restore saved frame configuration from file at start time.
+	* lisp/xwem-frame.el (xwem-frame-autoiconify-mode): [new] Non-nil
+	mean autoiconify overlapping frames, when switching.
+	* lisp/xwem-frame.el (xwem-frame-iresize-mode): [new] Mode for
+	interactive frame resizing.
+	* lisp/xwem-frame.el (xwem-frame-imove-mode): [new] Mode for
+	interactive frame moving.
+	* lisp/xwem-frame.el (xwem-frame-imoveresize-mode-function): [new]
+	* lisp/xwem-frame.el (xwem-frame-imoveresize-mode-function-default): [new]
+
+2004-05-05  Zajcev Evgeny  <zevlg@yandex.ru>
+
+	* lisp/xwem-focus.el (general): Various minor fixes.
+	* lisp/xwem-focus.el (xwem-focus-set): [fix] Do not push by
+	default.
+
+	* lisp/xwem-faces.el (xwem-eface-to-gc): [fix] :graphics-exposures
+	default value X-False now.
+
+	* lisp/xwem-events.el (general): Various fixes.
+	* lisp/xwem-events.el (xwem-parse-message-guess): [new] Events
+	processing restructured, due to reentrance bug in xlib.  xwem now
+	has its own parse-message-guess function to store input events,
+	such ass keypress/buttonpress/buttonrelease/motion separately from
+	dpy's events queue.
+	
+	* lisp/xwem-edmacro.el (general): Autoloads added.
+
+	* lisp/xwem-diagram.el (general): Autoloads added.
+	* lisp/xwem-diagram.el (xwem-diag-draw-3d-sector): [fix] Bug fix,
+	incorrect sector filling.
+
+	* lisp/xwem-compat.el (gerenal): Autoloads added.
+	
+	* lisp/xwem-clients.el (general): Tabbing stuff totally removed.
+	Some minor modifications, more hookenization, etc.
+	
+	* lisp/xwem-clients.el (xwem-cl-create-hook): [new]
+	* lisp/xwem-clients.el (xwem-cl-destroy-hook): [new]
+	* lisp/xwem-clients.el (xwem-cl-refit-hook): [new]
+	* lisp/xwem-clients.el (xwem-cl-iconify-hook): [new]
+	* lisp/xwem-clients.el (xwem-cl-change-hook): [new]
+	
+	* lisp/xwem-clients.el (xwem-cl-use-parent-xwin): [new] Non-nil to
+	reparent client to temporary window when client hides, aka mozilla
+	workaround.
+	
+
 2004-03-29  Norbert Koch  <viteno@xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 1.08 released.
 # Boston, MA 02111-1307, USA.
 
 VERSION = 1.08
-AUTHOR_VERSION = 0.1
+AUTHOR_VERSION = 0.2
 MAINTAINER = Zajcev Evgeny <zevlg@yandex.ru>
 PACKAGE = xwem
 PKG_TYPE = regular

File lisp/xwem-clients.el

 
 ;;; Commentary:
 ;;
-;; This file used to manage X clients windows(move/resize/configure).
+;; This file used for generic X clients management.
 ;;
-;; Client window is vector in form:
-;; 	[XWEM-Client (win) (xwem-win) (mw-hints-list) (cfg)
-;; 	(graphical contexts) manda-element state (transients-list)]
+;; Client state(`xwem-cl-state') is one of:
+;; 
+;;   'managed - Client has `xwem-cl-win' and in WIN's clients list, but
+;;              not current in WIN.
+;;   
+;;   'managed-current - As 'managed, but CL aslo current in WIN.
+;;   
+;;   'demanaged - CL may have valid `xwem-cl-win', but not in WIN's
+;;                clients list and not current in any window.
+;;   
+;;   'iconified - Same as 'demanaged
+;;   
+;;   'destroyed - CL's x window destroyed.
+;;   
+;;   'unknown   - Not any of above.
+
+;; 
+;; Hooks are:
+;; 
+;;   `xwem-cl-create-hook' - Called when new CL just created.
 ;;
-;; STATE is one of: 'managed 'demanaged or 'unknown
+;;   `xwem-cl-destroy-hook' - Called when CL destroyed.
 ;;
-;;; Code
+;;   `xwem-cl-state-change-hook' - Called when CL changes state to one
+;;                                 described above.
+;; 
+;;   `xwem-cl-manage-hook' - Called when CL just managed in some
+;;                           window.
+;;
+;;   `xwem-cl-demanage-hook' - Called when CL just demanaged from some
+;;                             window.
+;;
+;;   `xwem-cl-mark-hook' - Called when CL marked or unmarked.
 
+;;; Code:
+
 (eval-when-compile
   ;; Shutup compiler
   (require 'xwem-macros)
   :prefix "xwem-cl-"
   :group 'xwem)
 
+(defcustom xwem-cl-use-parent-xwin t
+  "*Non-nil mean that CL will use some X window, where it(CL) lowered.
+This is need to fullish some X applications, which accuire clients in such evil manner."
+  :type 'boolean
+  :group 'xwem-cl)
+
 (defcustom xwem-cl-other-strategy 'samewin
   "*Strategy to be used to select other CL.
 One of 'any 'samewin 'sameframe.
   :type 'boolean
   :group 'xwem-cl)
 
-(defcustom xwem-cl-new-client-hook nil
-  "Hook to call when managing new client."
-  :type 'hook
-  :group 'xwem-cl)
-
 (defcustom xwem-cl-mark-ring-max 16
   "*Maximum size of `xwem-cl-mark-ring'.
 Start discarding off end if gets this big."
   :group 'xwem-cl)
 
 ;;;###autoload
+(defcustom xwem-cl-create-hook nil
+  "Hook to call when creating new client."
+  :type 'hook
+  :group 'xwem-cl)
+
+;;;###autoload
+(defcustom xwem-cl-destroy-hook nil
+  "Hooks called with one argument - cl, when cl destroyed.
+NOT USED YET."
+  :type 'hook
+  :group 'xwem-hooks)
+
+;;;###autoload
 (defcustom xwem-cl-manage-hook nil
   "*Hooks to be called with just setuped CL as argument."
   :type 'hook
   :group 'xwem-hooks)
 
 ;;;###autoload
+(defcustom xwem-cl-refit-hook nil
+  "Hooks called when CL just refited."
+  :type 'hook
+  :group 'xwem-hooks)
+
+;;;###autoload
+(defcustom xwem-cl-iconify-hook nil
+  "Hooks called when CL just iconified."
+  :type 'hook
+  :group 'xwem-hooks)
+
+;;;###autoload
+(defcustom xwem-cl-change-hook nil
+  "Hooks called when something changed in CL."
+  :type 'hook
+  :group 'xwem-hooks)
+
+;;;###autoload
 (defcustom xwem-cl-state-change-hook nil
   "*Hooks to run when state of client changes.
 Every hook called with three args - CL OLD-STATE NEW-STATE."
   :group 'xwem-hooks)
 
 ;;;###autoload
+(defcustom xwem-cl-mark-hook nil
+  "*Hooks to run when marking client.
+Hooks called with two args - CL STATE.
+Where STATE is one of 'mark or 'unmark."
+  :type 'hook
+  :group 'xwem-hooks)
+
+;;; CL property change hooks
+;;;###autoload
+(defcustom xwem-cl-wmnh-change-hooks nil
+  "Hooks to be called when WM_NORMAL_HINTS changes."
+  :type 'hook
+  :group 'xwem-hooks)
+
+;;;###autoload
+(defcustom xwem-cl-wmname-change-hooks nil
+  "Hooks to be called when WM_NAME changes."
+  :type 'hook
+  :group 'xwem-hooks)
+
+;;;###autoload
+(defcustom xwem-cl-wmcommand-chage-hooks nil
+  "Hooks to be called when WM_COMMAND changes."
+  :type 'hook
+  :group 'xwem-hooks)
+
+;;;###autoload
+(defcustom xwem-cl-wmclass-change-hooks nil
+  "Hooks to be called when WM_CLASS changes."
+  :type 'hook
+  :group 'xwem-hooks)
+
+;;;###autoload
+(defcustom xwem-cl-wmh-change-hooks nil
+  "Hooks to be called when WM_HINTS changes."
+  :type 'hook
+  :group 'xwem-hooks)
+
+;;;###autoload
 (defvar xwem-clients nil "Clients Windows list")
 
 ;;;###autoload
   wm-protocols)
 
 ;;;###autoload
-(defconst xwem-client-ev-mask (Xmask-or XM-ColormapChange
-					XM-PropertyChange
-					XM-FocusChange
-                                        XM-EnterWindow
-                                        XM-LeaveWindow
-					XM-StructureNotify
-					XM-ResizeRedirect)
+(defconst xwem-client-ev-mask (Xmask-or XM-ColormapChange XM-PropertyChange
+					XM-FocusChange XM-EnterWindow XM-LeaveWindow
+					XM-StructureNotify XM-ResizeRedirect)
   "Event mask for xwem's client.")
 
 ;;;###autoload
   recency				; last time when CL was active
   translist				; list of transient-for windows for this client
 
-  tabitem				; reference to tab item
   plist					; user defined plist
   )
 
   (member cl xwem-cl-mark-ring))
 
 ;;;###autoload
+(defun xwem-cl-destroyed-p (cl)
+  "Return non-nil if CL has already destroyed xwin."
+  (eq (xwem-cl-state cl) 'destroyed))
+
+;;;###autoload
 (defsubst xwem-cl-put-prop (cl prop val)
   "In CL's property list put property PROP with value VAL."
   (setf (xwem-cl-plist cl) (plist-put (xwem-cl-plist cl) prop val)))
+(put 'xwem-cl-put-prop 'lisp-indent-function 2)
 
 ;;;###autoload
 (defsubst xwem-cl-get-prop (cl prop)
 ;;;###autoload
 (defun xwem-remove-client (cl)
   "Delete WIN from clients list."
-;  (when (X-Win-p (xwem-cl-xwin cl))
-;    (X-Win-invalidate (xwem-cl-xwin cl)))
   (setq xwem-clients (delete cl xwem-clients)))
 
 (defun xwem-cl-do-gravity (cl step)
-  "Gravity changing."
+  "Change CL's gravity.
+NOT USED"
   )
 
 ;;;###autoload
 
 ;; cl predicates
 ;;;###autoload
-(defun xwem-cl-inwin-p (cl)
-  "Return non-nil if CL is currently displayed in some xwem's window."
-  (xwem-cl-p cl 'xwem-cl-inwin-p)
-  (and (xwem-win-p (xwem-cl-win cl))
-       (eq cl (xwem-win-cl (xwem-cl-win cl)))))
-
-;;;###autoload
 (defun xwem-cl-alive-p (cl)
   "Return non-nil if CL is alive i.e. in `xwem-clients' list."
   (memq cl xwem-clients))
 	(while cll
 	  (when (not (eq (car cll) cl))	;skip ourself
 	    (if (and (not (xwem-cl-exclude-p (car cll)))
-		     (or visible (not (xwem-cl-inwin-p (car cll)))))
+		     (or visible (not (xwem-win-cl-current-p (car cll)))))
 		(progn
 		  (setq rcl (car cll))
 		  (setq cll nil))
 	(setf (X-Geom-y clgeom) (X-WMSize-y wmnh)))
       )))
 
+(defun xwem-cl-domanage (cl &optional sfwin)
+  "Real manage job."
+  (let* ((old-win (xwem-cl-win cl))
+         (new-win (or sfwin (xwem-win-selected)))
+         (old-cl (and (xwem-win-p new-win) (xwem-win-cl new-win))))
+    ;; When there no xwem window to manage CL, just demanage it
+    (if (not (xwem-win-p new-win))
+        (xwem-manda-demanage cl)
+
+      (if (xwem-win-cl-current-p cl new-win)
+          ;; CL already in NEW-WIN - only refiting needed
+          (xwem-manda-refit cl)
+
+        ;; When client moves from frame to other frame, state should
+        ;; be unknown.  [Hmm, why]?
+;        (when (not (eq (xwem-cl-frame cl)
+;                       (xwem-win-frame new-win)))
+;          (xwem-client-change-state cl 'unknown))
+
+        ;; First of all demanage client CL
+        (when (and (xwem-win-p old-win)
+                   (not (eq old-win new-win)))
+          (xwem-manda-demanage cl))
+
+        (setf (xwem-win-cl new-win) cl)
+        (setf (xwem-cl-win cl) new-win)
+        (xwem-manda-refit cl t)
+        (xwem-client-show cl 'managed-current)
+        
+        ;; Hide OLD-CL
+        (when (xwem-cl-p old-cl)
+          (xwem-client-hide old-cl 'managed))
+        ))
+
+    ;; Update recency field
+    (setf (xwem-cl-recency cl) (current-time))
+
+    ;; Finally run hooks
+    (run-hook-with-args 'xwem-cl-manage-hook cl)
+    ))
+  
 (defun xwem-cl-manage (cl &optional sfwin)
   "Setup CL to be used in SFWIN.
 If SFWIWN is ommited `xwem-win-selected' will be used.
   (when sfwin
     (xwem-win-p sfwin 'xwem-cl-manage))
 
-  (let ((old-win (xwem-cl-win cl))
-	(xwem-win (or sfwin (xwem-win-selected))))
-    ;; XXX -- should we check is window already setuped?
-    (if (eq (xwem-win-cl xwem-win) cl)
-	;; CL already in XWEM-WIN - only refiting needed
-	(xwem-manda-fun-run (xwem-cl-manda cl) 'refit cl)
+  (if (not (xwem-misc-xwin-valid-p (xwem-cl-xwin cl)))
+      ;; CL suddenly died
+      (xwem-cl-hdestroy-notify cl nil)
+        
+    (xwem-cl-domanage cl sfwin))
+  )
 
-      ;; else CL in some other window
-      (let ((old-cl (xwem-win-cl xwem-win)))
-	;; When client moves from frame to other frame, state should
-	;; be unknown
-	(when (not (eq (xwem-cl-frame cl)
-		       (xwem-win-frame xwem-win)))
-	  (xwem-client-change-state cl 'unknown))
-
-	;; First of all demanage client CL
-	(unless (eq old-win xwem-win)
-	  (let ((xwem-cl-demanage-hook nil))
-	    (xwem-manda-fun-run (xwem-cl-manda cl) 'demanage cl)))
-
-	(setf (xwem-cl-win cl) xwem-win)
-	(setf (xwem-win-cl (xwem-cl-win cl)) cl)
-	(xwem-manda-fun-run (xwem-cl-manda cl) 'refit cl t)
-
-	(xwem-client-show cl)
-
-	;; Demanage client which is currently in XWEM-WIN
-	(when (xwem-cl-p old-cl)
-	  (xwem-manda-fun-run (xwem-cl-manda old-cl) 'demanage old-cl))
-
-	;; Regeom tabbers if client moves from other window
-	(unless (eq old-win xwem-win)
-	  (when (xwem-win-p old-win)
-	    (xwem-tabber-regeom-window old-win (xwem-win-selected-p old-win (xwem-win-frame old-win))))
-	  (when (xwem-win-p xwem-win)
-	    (xwem-tabber-regeom-window xwem-win (xwem-win-selected-p xwem-win (xwem-win-frame xwem-win)))))
-      ))
-
-    ;; Update recency field
-    (setf (xwem-cl-recency cl) (current-time))
-
-    ;; Finally run hooks
-    (run-hook-with-args 'xwem-cl-manage-hook cl)
-    ))
-
-(defun xwem-cl-demanage (cl &optional winclr clclr)
+(defun xwem-cl-demanage (cl &optional state)
   "Desetup CL from xwem win.
 Used when deleting window or frame.
 When CLEAR is non-nil then xwem window client for CL will be setted to nil."
-  (xwem-client-hide cl 'managed)
+  (if (eq state 'destroyed)
+      (setf (xwem-cl-state cl) 'destroyed)
+    (xwem-client-hide cl (or state 'demanaged)))
 
-  (when (and winclr (xwem-cl-win cl))
-    (setf (xwem-win-cl (xwem-cl-win cl)) nil))
-  (when (and clclr (xwem-cl-p cl))
-    (setf (xwem-cl-win cl) nil))
+  ;; If demanaged CL is current in it's window try to manage other
+  ;; client.
+  (let ((owin (xwem-cl-win cl))
+        ocl)
+    (when (xwem-win-cl-current-p cl)
+      (setf (xwem-win-cl owin) nil)
+      (when (xwem-cl-p (setq ocl (xwem-cl-other cl)))
+        (xwem-manda-manage ocl owin))))
 
-  ;; Try to manage other xwem-client
-  (let* ((vis-p (xwem-cl-inwin-p cl))
-	 (old-win (if vis-p (xwem-cl-win cl) nil))
-	 (oth-cl (if vis-p (xwem-cl-other cl) nil)))
-
-    ;; Switch to other client in old CL's window
-    (when (xwem-win-p old-win)
-      (setf (xwem-win-cl old-win) nil)
-      (if (xwem-cl-p oth-cl)
-	  (xwem-manda-fun-run (xwem-cl-manda oth-cl) 'manage oth-cl old-win)
-	(setf (xwem-win-cl old-win) nil))
-    ))
-
-  ;; Now run hooks
+  ;; Now run on-demanage hooks
   (run-hook-with-args 'xwem-cl-demanage-hook cl)
   )
 
 ;; I think special CLs should be handled in very different way then
 ;; normals. It is the one of things TODO.
 ;;
-(defun xwem-cl-iconify (cl &optional clear)
+(defun xwem-cl-iconify (cl)
   "Iconify CL. Used to handle Iconify ClientMessage from special CL."
-  ;; XXX
-  (xwem-manda-fun-run (xwem-cl-manda cl) 'demanage cl clear)
-  (xwem-client-change-state cl 'iconified)
+  (xwem-manda-demanage cl 'iconified)
   )
 
+;;;###autoload(autoload 'xwem-client-iconify "xwem-clients" "" t)
 (define-xwem-command xwem-client-iconify (cl)
   "Iconifies selected client."
   (xwem-interactive (list (xwem-cl-selected)))
 
   (if (xwem-cl-p cl)
-      (let ((win (xwem-cl-win cl)))
-	(xwem-cl-iconify cl nil)
-	(setf (xwem-cl-win cl) nil)
-	(xwem-tabber-regeom-window win (xwem-win-selected-p win (xwem-win-frame win))))
+      (xwem-cl-iconify cl)
 
     (xwem-message 'warn "No client in selected window.")))
 
        (setq clns (cdr clns)))
      rcl)))
 
+;;;###autoload(autoload 'xwem-cl-switch "xwem-clients" "" t)
 (define-xwem-command xwem-cl-switch (arg)
   "Interactively switch to some client window, using 'iswitchb.
 When used with prefix ARG, then filter clients to selected widow only."
 				 "XWEM-CL: ")
 			       pred)))
     (when cl
-      (xwem-manda-fun-run (xwem-cl-manda cl) 'manage cl))
+      (xwem-manda-manage cl))
   ))
 
+;;;###autoload(autoload 'xwem-cl-switch-other-win "xwem-clients" "" t)
 (define-xwem-command xwem-cl-switch-other-win (cl &optional arg)
   "Switch to CL in other window.
 When used with prefix ARG, then focuse to that other window."
 	(setq wn (xwem-win-next (xwem-win-selected))))
 
       (when wn
-	(xwem-manda-fun-run (xwem-cl-manda cl) 'manage cl wn)
+	(xwem-manda-manage cl wn)
 
 	(when arg
 	  (xwem-window-select wn)))
       )))
 
+;;;###autoload(autoload 'xwem-cl-switch-other-frame "xwem-clients" "" t)
 (define-xwem-command xwem-cl-switch-other-frame (cl &optional arg)
   "Switch to CL in other XWEM frame.
 When used with prefix ARG, then create embedded frame, if creation is
   (let ((ofr (or (xwem-frame-other (xwem-frame-selected))
 		 (xwem-make-frame-1 arg nil nil t))))
 
-    (xwem-manda-fun-run (xwem-cl-manda cl) 'manage cl (xwem-frame-selwin ofr))
+    (xwem-manda-manage cl (xwem-frame-selwin ofr))
     (xwem-frame-select ofr))
   )
 
+;;;###autoload(autoload 'xwem-cl-switch-to-other "xwem-clients" "" t)
 (define-xwem-command xwem-cl-switch-to-other (n &optional window)
   "Switch to other client."
   (xwem-interactive "p")
       (setq ocl (xwem-cl-other ocl))
       (setq n (- n 1)))
     (if (xwem-cl-p ocl)
-	(xwem-manda-fun-run (xwem-cl-manda ocl) 'manage ocl win)
+	(xwem-manda-manage ocl win)
       (xwem-message 'note "No other client available."))))
 
+;;;###autoload(autoload 'xwem-cl-switch-to-other-in-other-win "xwem-clients" "" t)
 (define-xwem-command xwem-cl-switch-to-other-in-other-win (n)
   "Like `xwem-cl-switch-to-other', but in other window."
   (xwem-interactive "p")
 
   (xwem-cl-switch-to-other n (xwem-window-other 1)))
 	 
+;;;###autoload(autoload 'xwem-kill-cl-and-window "xwem-clients" "" t)
 (define-xwem-command xwem-kill-cl-and-window (arg)
   "Kill selected client and window.
 If used with prefix ARG then kill client in other window and other
     (xwem-frame-redraw (xwem-win-frame win))
   ))
 
-(define-xwem-command xwem-cl-transpose (arg &optional win)
-  "Transpose client with client at right in WIN.
+;;;###autoload(autoload 'xwem-cl-transpose "xwem-clients" "" t)
+(define-xwem-command xwem-cl-transpose (arg &optional cl)
+  "Transpose CL with client at right in CL's WIN.
 If ARG is non-nil transpose with left client.
-If WIN is ommited than selected window will be used."
+If CL is ommited than selected client will be used."
   (xwem-interactive "P")
 
-  (let* ((sw (or win (xwem-win-selected)))
-	 (cl (xwem-win-cl sw))
-	 (tai (cadr (member cl (funcall (if arg 'reverse 'identity)
-					(xwem-win-make-cl-list sw))))))
-
+  (let* ((cl (or cl (xwem-cl-selected)))
+         (sw (xwem-cl-win cl))
+	 (tai (cadr (member cl (funcall (if arg 'reverse 'identity) (xwem-win-make-cl-list sw))))))
     (when (not (xwem-cl-p tai))
-      (setq tai (cadr (member cl (funcall (if arg 'identity 'reverse)
-					  (xwem-win-make-cl-list sw))))))
+      (setq tai (cadr (member cl (funcall (if arg 'identity 'reverse) (xwem-win-make-cl-list sw))))))
 
     (when (and (xwem-cl-p cl) (xwem-cl-p tai))
-      (xwem-list-exchange-els xwem-clients cl tai))
+      (xwem-list-exchange-els xwem-clients cl tai)
 
-    (xwem-tabber-regeom-window sw (xwem-win-selected-p sw (xwem-win-frame sw)))))
+      (run-hook-with-args 'xwem-win-clients-change-hook sw))
+    ))
 
 (defun xwem-client-rearrange-top (cl)
   "Move CL on top of `xwem-clients'."
 
   (setq xwem-clients nil)
 
-  (add-hook 'xwem-cl-manage-hook
-	    (lambda (cl)
-	      (when (and (xwem-win-p (xwem-cl-win cl))
-			 (xwem-win-selected-p (xwem-cl-win cl)))
-		(xwem-tab-item-draw-format (xwem-cl-tabitem cl)))))
-  (add-hook 'xwem-cl-demanage-hook
-	    (lambda (cl)
-	      (when (and (xwem-win-p (xwem-cl-win cl))
-			 (xwem-win-selected-p (xwem-cl-win cl)))
-		(xwem-tab-item-draw-format (xwem-cl-tabitem cl)))))
+  ;; Gentle handling of window splitting
+  (add-hook 'xwem-win-after-split-hook 'xwem-cl-other-on-split)
 
   (when xwem-cl-use-set-focus
     (add-hook 'xwem-cl-manage-hook 'xwem-client-focus))
     (add-hook 'xwem-cl-manage-hook 'xwem-client-rearrange-top))
 ;    (add-hook 'xwem-cl-demanage-hook 'xwem-cl-bury))
 
-  ;; Gentle handling of window splitting
-  (add-hook 'xwem-win-after-split-hook 'xwem-cl-other-on-split)
+  ;; Setup
+  (when xwem-cl-use-parent-xwin
+    (add-hook 'xwem-cl-create-hook 'xwem-cl-parent-on-creation)
+    (add-hook 'xwem-cl-destroy-hook 'xwem-cl-parent-on-destroy)
+    (add-hook 'xwem-cl-state-change-hook 'xwem-cl-parent-on-change-state))
   )
 
 ;;;###autoload
     ))
 
 ;;;###autoload
-(defsubst xwem-cl-managed-p (cl)
+(defsubst xwem-cl-managed-p (cl &optional win)
   "Return non-nil if client CL is managed, i.e. has 'managed or 'normal state."
-  (or (eq (xwem-cl-state cl) 'managed)
-      (eq (xwem-cl-state cl) 'normal)))
+  (and (or (not win) (eq (xwem-cl-win cl) win))
+       (or (eq (xwem-cl-state cl) 'managed)
+           (eq (xwem-cl-state cl) 'managed-current))))
 
 ;;; Creating new client
 (defun xwem-cl-presetup (cl)
   (let ((xwin (xwem-cl-xwin cl)))
 
     (if (not (xwem-frame-p (xwem-frame-find 'xwin xwin)))
-	;; Not an embedded frame
-	(XSelectInput (xwem-dpy) xwin (xwem-cl-ev-mask cl))
+        (progn
+          ;; Normal client(not an embedded frame)
+          (XSelectInput (xwem-dpy) xwin (xwem-cl-ev-mask cl))
+          (X-Win-EventHandler-add-new xwin 'xwem-cl-events-handler 100))
 
       ;; Embedded frame
-      (XSelectInput (xwem-dpy) xwin (Xmask-or xwem-frame-ev-mask
-					      (xwem-cl-ev-mask cl))))
-
-    ;; Add event handlers
-    (X-Win-EventHandler-add-new xwin 'xwem-cl-events-handler 100)
-    (X-Win-EventHandler-add-new xwin 'xwem-ev-property 0 (list X-PropertyNotify))
-
+      (XSelectInput (xwem-dpy) xwin (Xmask-or xwem-frame-ev-mask (xwem-cl-ev-mask cl)))
+      (X-Win-EventHandler-add-new xwin 'xwem-cl-events-handler 100
+                                  (list X-PropertyNotify X-FocusIn X-FocusOut X-LeaveNotify X-EnterNotify)))
+    ;; XXX
     (XSetWindowBorderWidth (xwem-dpy) xwin 0)
 
     ;; Fetch some window properties
     ))
 
 ;;;###autoload
-(defun xwem-make-client (win attrs &optional xwem-win)
-  "Make new client window."
+(defun xwem-make-client (win &optional props xwem-win)
+  "Make new client window.
+WIN   - X Window.
+PROPS - Properties list for new client.
+XWEM-WIN - xwem window where new client should be managed(if possible)."
 
-  (when (XGetWindowAttributes (xwem-dpy) win) ; just to check that window not destroyed
-    (let ((new-cl (make-xwem-cl)))
+  (let (attrs new-cl)
+    (when (setq attrs (xwem-misc-xwin-valid-p win)) ; just to check that window still alive
+      (setq new-cl (make-xwem-cl :plist props))
 
       (setf (xwem-cl-xwin new-cl) win)
+      (X-Win-put-prop win 'xwem-cl new-cl)
       (X-Dpy-log (xwem-dpy) "New Client making name=%s\n" '(XGetWMName (xwem-dpy) win))
 
       (xwem-cl-presetup new-cl)
 
-      (when (null attrs)
-	(setq attrs (XGetWindowAttributes (xwem-dpy) win)))
-
       (setf (xwem-cl-xattrs new-cl) attrs)
       (setf (xwem-cl-xgeom new-cl) (XGetGeometry (xwem-dpy) win))
       (setf (xwem-cl-start-time new-cl) (current-time))
       ;; it.
       (setq xwem-clients (cons new-cl xwem-clients))
 
-      ;; Make tab item for client
-      (setf (xwem-cl-tabitem new-cl)
-	    (make-xwem-tab-item :type 'client
-				:state 'unmapped :rect (make-X-Rect :y 0 :x 0 :width 0 :height 0)
-				:cl new-cl :format xwem-tab-default-format))
-
       ;; Walk manage database to find how to deal with this client
       (let ((mdis (xwem-manda-find-inst new-cl)))
-	(if (not mdis)
-	    (progn
-	      (xwem-message 'err "Client not in manage database")
-	      (error "Client not described in manage database"))
+        (if (not mdis)
+            (progn
+              (xwem-message 'err "Client not in manage database")
+              (error "Client not described in manage database"))
 
-	  (setf (xwem-cl-manda new-cl) mdis)
+          (setf (xwem-cl-manda new-cl) mdis)
 
-	  ;; Check for Win's expectations
-	  (let ((wmcmd (xwem-hints-wm-command (xwem-cl-hints new-cl)))
-		(dwin nil))		;destination win
+          ;; Check for Win's expectations
+          (let ((wmcmd (xwem-hints-wm-command (xwem-cl-hints new-cl)))
+                (dwin nil))		;destination win
 	      
-	    ;; Find a window who expects NEW-CL
-	    (setq dwin
-		  (catch 'dwin
-		    (mapc (lambda (fr)
-			    (xwem-win-map
-			     (lambda (win)
-			       (when (> (xwem-win-get-expt win wmcmd) 0)
-				 (xwem-win-expt-dec win wmcmd)
-				 (throw 'dwin win)))
-			     (xwem-frame-selwin fr)))
-			  xwem-frames-list)))
+            ;; Find a window who expects NEW-CL
+            (setq dwin
+                  (catch 'dwin
+                    (mapc (lambda (fr)
+                            (xwem-win-map
+                             (lambda (win)
+                               (when (> (xwem-win-get-expt win wmcmd) 0)
+                                 (xwem-win-expt-dec win wmcmd)
+                                 (throw 'dwin win)))
+                             (xwem-frame-selwin fr)))
+                          xwem-frames-list)))
 	    
-	    ;; Setup focus mode
+            ;; Setup focus mode
             (xwem-focus-mode-set new-cl xwem-default-focus-mode)
 
-	    ;; Run new client hook
-	    (run-hook-with-args 'xwem-cl-new-client-hook new-cl)
+            ;; Run new client hook
+            (run-hook-with-args 'xwem-cl-create-hook new-cl)
 
-	    (if (xwem-win-p dwin)
-		(xwem-manda-fun-run mdis 'manage new-cl dwin)
-	      (xwem-manda-fun-run mdis 'manage new-cl)))
-	  )))
+            ;; Finnally manage new client
+            (if (xwem-win-p dwin)
+                (xwem-manda-manage new-cl dwin)
+              (xwem-manda-manage new-cl)))
+          )))
     ))
 
 
   "Manage other client to CL in WIN."
   (let ((ocl (xwem-cl-other cl)))
     (when (xwem-cl-p ocl)
-      (xwem-manda-fun-run (xwem-cl-manda ocl) 'manage ocl win))))
+      (xwem-manda-manage ocl win))))
 
 (defun xwem-cl-other-on-split (win how new-size)
   "Manage current WIN's cl in othen window.
 
 
 ;; Commands
+;;;###autoload(autoload 'xwem-client-turn-on-other-on-split "xwem-clients" "" t)
 (define-xwem-command xwem-client-turn-on-other-on-split ()
   "Turn on `xwem-cl-other-on-split' minor mode."
   (xwem-interactive)
   (setq xwem-cl-other-on-split t)
   (xwem-message 'info "Other on split minor mode is ON."))
 
+;;;###autoload(autoload 'xwem-client-turn-off-other-on-split "xwem-clients" "" t)
 (define-xwem-command xwem-client-turn-off-other-on-split ()
   "Turn off `xwem-cl-other-on-split' minor mode."
   (xwem-interactive)
   (setq xwem-cl-other-on-split nil)
   (xwem-message 'info "Other on split minor mode is OFF."))
 
+;;;###autoload(autoload 'xwem-client-toggle-other-on-split "xwem-clients" "" t)
 (define-xwem-command xwem-client-toggle-other-on-split (arg)
   "Toggle `xwem-cl-other-on-split' minor mode.
 Negative ARG turns it off, positive turns it on."
       (xwem-client-turn-off-other-on-split)
     (xwem-client-turn-on-other-on-split)))
   
+;;;###autoload(autoload 'xwem-client-kill "xwem-clients" "" t)
 (define-xwem-command xwem-client-kill (arg &optional cl)
   "Kill xwem client CL. Also destroys CL's X window.
 If used with prefix ARG is given, force CL to die, by default WM_DELETE_WINDOW will be probed.
   (let ((client (or cl (xwem-cl-selected))))
     (if (xwem-cl-p client)
 	(if arg
-	    (progn
-;	      (xwem-remove-client client)
-	      (XDestroyWindow (xwem-dpy) (xwem-cl-xwin client)))
+            ;; Force killing
+            (XDestroyWindow (xwem-dpy) (xwem-cl-xwin client))
+          ;; else try soft killing
 	  (or (xwem-client-close client) (xwem-client-kill t client)))
+
       (xwem-message 'warn "No Active client found."))))
 
+;;;###autoload(autoload 'xwem-client-query-kill "xwem-clients" "" t)
 (define-xwem-command xwem-client-query-kill (arg client)
   "Kill CLIENT.
 Prefix ARG directly passed to `xwem-client-kill'."
     (xwem-client-kill arg client))
   )
 
+;;;###autoload(autoload 'xwem-client-demanage-others "xwem-clients" "" t)
 (define-xwem-command xwem-client-demanage-others (arg)
   "Demanage others then selected client in selected window.
 If ARG given, remain ARG most recent clients."
   (xwem-interactive "p")
 
-  (let ((rcls (nthcdr arg (xwem-win-make-cl-list-sort-by-recency (xwem-win-selected)))))
+  (let* ((win (xwem-win-selected))
+         (rcls (nthcdr arg (xwem-win-make-cl-list-sort-by-recency win))))
     ;; cls in RCLS already demanaged
     (mapc (lambda (cl)
-	    (setf (xwem-cl-win cl) nil))
-	  rcls)
+            (setf (xwem-cl-state cl) 'unknown))
+          rcls)
 
-    ;; Redraw frame's tabber
-    (xwem-tabber-safe-regeom (xwem-frame-tabber (xwem-frame-selected)) t)
+    ;; If something changed, run on-change hooks
+    (when rcls
+      (run-hook-with-args 'xwem-win-clients-change-hook win))
     ))
 
-(define-xwem-command xwem-client-run-copy (arg)
+;;;###autoload(autoload 'xwem-client-run-copy "xwem-clients" "" t)
+(define-xwem-command xwem-client-run-copy (arg &optional cl)
   "Run the same command as selected CL.
 With prefix arg run it in other window.
 With double prefix arg run in other window and select.
 With numeric prefix arg run ARG copies."
   (xwem-interactive "P")
   
-  (let* ((nw (xwem-win-selected))
-	 (cl (xwem-win-cl nw)))
+  (let* ((cl (or cl (xwem-cl-selected)))
+         (nw (and (xwem-cl-p cl) (xwem-cl-win cl))))
 
     (if (not (xwem-cl-p cl))
 	(xwem-message 'warn "No client selected to copy.")
+
       (let ((cmd (xwem-hints-wm-command (xwem-cl-hints cl)))
 	    (cnt (if (numberp arg) arg 1)) ;how many clients to start
 	    (i 0))
 		(xwem-win-expt-inc nw cmd cnt))
 
 	      (when (= (prefix-numeric-value arg) 16)
-		(xwem-window-select nw))))
+		(xwem-window-select-maybe-redraw nw))))
 
 	  (when (xwem-win-p nw)
 	    (while (< i cnt)
 	      (setq i (1+ i))))
     )))))
 
-(define-xwem-command xwem-client-run-copy-other-win (arg)
+;;;###autoload(autoload 'xwem-client-run-copy-other-win "xwem-clients" "" t)
+(define-xwem-command xwem-client-run-copy-other-win (arg &optional cl)
   "Run copy of selected client in other window.
 With prefix ARG, make horizontal split instead of vertical if split
 really needed."
   (xwem-interactive "P")
 
-  (let ((cmd (xwem-hints-wm-command (xwem-cl-hints (xwem-cl-selected))))
-	(own (xwem-window-other 1))
-	(xwem-win-after-split-hook nil)) ; prevent hooks processing
+  (let ((cl (or cl (xwem-cl-selected)))
+        (xwem-win-after-split-hook nil)  ; prevent hooks
+        cmd own)
+    (when (or (not (xwem-cl-p cl))
+              (not (xwem-win-p (xwem-cl-win cl))))
+      (error "Can't run copy of invalid client"))
+
+    (setq cmd (xwem-hints-wm-command (xwem-cl-hints cl)))
+    (setq own (xwem-window-other 1 (xwem-cl-win cl)))
 
     (when cmd
       ;; Check is there split needed
       (xwem-win-expt-inc own cmd)
 
       ;; Finnaly run command
-      (xwem-execute-program cmd))))
+      (xwem-execute-program cmd))
+    ))
 
-(define-xwem-command xwem-client-run-copy-other-frame (arg)
+;;;###autoload(autoload 'xwem-client-run-copy-other-frame "xwem-clients" "" t)
+(define-xwem-command xwem-client-run-copy-other-frame (arg &optional cl)
   "Run copy of selected client in other frame.
 If prefix ARG is specified, create embedded frame, if creation is
 needed at all."
   (xwem-interactive "P")
 
-  (let ((cmd (xwem-hints-wm-command (xwem-cl-hints (xwem-cl-selected))))
-	(ofr (xwem-frame-other (xwem-frame-selected))))
-    (unless (xwem-frame-p ofr)
-      (setq ofr (xwem-make-frame-1 arg nil nil t)))
+  (let ((cl (or cl (xwem-cl-selected)))
+        cmd ofr)
 
-    ;; Setup expectance
-    (xwem-win-expt-inc (xwem-frame-selwin ofr) cmd)
+    (when (or (not (xwem-cl-p cl))
+              (not (xwem-frame-p (xwem-cl-frame cl))))
+      (error "Can't run copy of invalide client"))
 
-    (xwem-frame-select ofr)
+    (setq cmd (xwem-hints-wm-command (xwem-cl-hints cl)))
+    (setq ofr (xwem-frame-other (xwem-cl-frame cl)))
+    (when cmd
+      (unless (xwem-frame-p ofr)
+        (setq ofr (xwem-make-frame-1 arg nil nil t)))
 
-    ;; Finnaly run command
-    (xwem-execute-program cmd)))
+      ;; Setup expectance
+      (xwem-win-expt-inc (xwem-frame-selwin ofr) cmd)
+
+      (xwem-frame-select ofr)
+
+      ;; Finnaly run command
+      (xwem-execute-program cmd))
+    ))
 
 (defun xwem-cl-prog-geom (cl)
   "Get program specified geometry for CL."
 	(setq flst (cdr flst))))
     rup))
 
-;;;###autoload
-(autoload 'xwem-client-info "xwem-clients")
+;;;###autoload(autoload 'xwem-client-info "xwem-clients" "" t)
 (define-xwem-command xwem-client-info (&optional cl)
   "Display info about xwem client CL."
   (xwem-interactive)
       (xwem-message 'warn "No active clients found.")))
   )
 
-;;;###autoload
-(autoload 'xwem-cl-pop-to-client "xwem-clients")
+;;;###autoload(autoload 'xwem-cl-pop-to-client "xwem-clients" "" t)
 (define-xwem-command xwem-cl-pop-to-client (cl &optional warp)
   "Pop to client CL, i.e. switch to its frame and manage it.
 If CL have no frame, popup it in current frame."
 	(xwem-frame-select fr))
       (when (not (xwem-win-selected-p clw))
 	(xwem-window-select-maybe-redraw clw))
-      (xwem-manda-fun-run (xwem-cl-manda cl) 'manage cl clw)
+      (xwem-manda-manage cl clw)
 
       (when warp
 	(XWarpPointer (xwem-dpy) X-None (xwem-cl-xwin cl) 0 0 0 0 10 10)))
 
     (xwem-message 'info "Can't jump to dead client ..")))
 
+;;;###autoload(autoload 'xwem-cl-set-title "xwem-clients" "" t)
 (define-xwem-command xwem-cl-set-title (title &optional cl)
   "Set new TITLE for client CL."
   (xwem-interactive "sNet title: ")
 	(error "No currently selected client.")
       (XSetWMName (xwem-dpy) (xwem-cl-xwin ccl) title))))
 
+;;;###autoload(autoload 'xwem-client-unset-mark "xwem-clients" "" t)
 (define-xwem-command xwem-client-unset-mark (&optional cl)
   "Uset mark on CL."
   (xwem-interactive (list (xwem-cl-selected)))
 
   (when (member cl xwem-cl-mark-ring)
     (setq xwem-cl-mark-ring (delete cl xwem-cl-mark-ring))
-    ;; Tab maybe affected, so redraw it
-    (xwem-tab-item-draw-format (xwem-cl-tabitem cl))))
+
+    ;; Now run on-mark hooks
+    (run-hook-with-args 'xwem-cl-mark-hook cl 'unmark)))
   
+;;;###autoload(autoload 'xwem-client-set-mark "xwem-clients" "" t)
 (define-xwem-command xwem-client-set-mark (arg &optional cl)
   "Mark selected client CL.
 If CL is ommited or `xwem-client-set-mark' called interactively then
     ;; `xwem-cl-mark-ring-max' value if needed.
     (when (= (length xwem-cl-mark-ring) xwem-cl-mark-ring-max)
       ;; Remove last item
-      (let ((rcl (car (last xwem-cl-mark-ring))))
-	(setq xwem-cl-mark-ring (butlast xwem-cl-mark-ring))
-	;; Tab maybe affected, so redraw it
-	(xwem-tab-item-draw-format (xwem-cl-tabitem rcl))))
+      (xwem-client-unset-mark (car (last xwem-cl-mark-ring))))
 
     (push cl xwem-cl-mark-ring)
-    ;; Tab maybe affected, so redraw it
-    (xwem-tab-item-draw-format (xwem-cl-tabitem cl))
+
+    ;; Now run on-mark hooks
+    (run-hook-with-args 'xwem-cl-mark-hook cl 'mark)
 
     (xwem-message 'info "Marking selected client, total ring size %d"
 		  (length xwem-cl-mark-ring))
     ;; TODO: finalize client in (car xwem-clients)
     (setq xwem-clients (cdr xwem-clients))))
 
-;;; New stuff
+;;;###autoload
 (defun xwem-client-hide (cl &optional new-state)
   "Hide CL's window. Optionally you may specify NEW-STATE."
   ;; Just move off the screen
   (xwem-client-change-state cl (or new-state 'iconified))
   )
 
-(defun xwem-client-show (cl)
+;;;###autoload
+(defun xwem-client-show (cl &optional new-state)
   "Show xwem client CL."
+  ;; Make sure CL's frame is CL's parent
+  (XReparentWindow (xwem-dpy) (xwem-cl-xwin cl)
+                   (xwem-frame-xwin (xwem-cl-frame cl))
+                   (X-Geom-width (xwem-rootgeom)) (X-Geom-height (xwem-rootgeom)))
+
   (if (xwem-cl-transient-for cl)
       (XRaiseWindow (xwem-dpy) (xwem-cl-xwin cl))
 
                (X-Geom-y (xwem-cl-xgeom cl)))
 
   (XMapWindow (xwem-dpy) (xwem-cl-xwin cl))
-
-  (xwem-client-change-state cl 'normal)
+  (xwem-client-change-state cl (or new-state 'managed-current))
   )
 
 
 ;;; Events handling for client windows
-(defun xwem-cl-hkeybutton (cl xev)
-  "KeyPress, ButtonPress or ButtonRelease event XEV."
-  (xwem-kbd-handle-keybutton xev)
-  )
-
 (defun xwem-cl-hproperty (cl xev)
   "PropertyNotify."
-  )
+  (let ((xwin (xwem-cl-xwin cl))
+        (atom-id (X-Atom-id (X-Event-xproperty-atom xev)))
+        (state (X-Event-xproperty-state xev))
+        rhook)
+
+    ;; Some CL's property changed
+    (X-Dpy-log (xwem-dpy) "CLIENT .. PropertyNotify: Atom-id = %d\n" 'atom-id)
+
+    (cond 
+     ((and (= atom-id (X-Atom-id XA-wm-normal-hints)) (= state X-PropertyNewValue))
+      (setf (xwem-hints-wm-normal-hints (xwem-cl-hints cl)) (XGetWMNormalHints (xwem-dpy) xwin))
+      (setq rhook 'xwem-cl-wmnh-change-hooks))
+
+     ((and (= atom-id (X-Atom-id XA-wm-hints)) (= state X-PropertyNewValue))
+      (setf (xwem-hints-wm-hints (xwem-cl-hints cl)) (XGetWMHints (xwem-dpy) xwin))
+      (setq rhook 'xwem-cl-wmh-change-hooks))
+
+     ((and (= atom-id (X-Atom-id XA-wm-class)) (= state X-PropertyNewValue))
+      (setf (xwem-hints-wm-class (xwem-cl-hints cl)) (XGetWMClass (xwem-dpy) xwin))
+      (setq rhook 'xwem-cl-wmclass-change-hooks))
+
+     ((and (= atom-id (X-Atom-id XA-wm-command)) (= state X-PropertyNewValue))
+      (setf (xwem-hints-wm-command (xwem-cl-hints cl)) (XGetWMCommand (xwem-dpy) xwin))
+      (setq rhook 'xwem-cl-wmcommand-chage-hooks))
+
+     ((and (= atom-id (X-Atom-id XA-wm-name)) (= state X-PropertyNewValue))
+      (setf (xwem-hints-wm-name (xwem-cl-hints cl)) (XGetWMName (xwem-dpy) xwin))
+      (unless (equal (xwem-hints-wm-name (xwem-cl-hints cl)) (xwem-cl-saved-name cl))
+        (setf (xwem-cl-saved-name cl) (xwem-hints-wm-name (xwem-cl-hints cl)))
+        (setq rhook 'xwem-cl-wmname-change-hooks)))
+     )
+
+    ;; Run RHOOK
+    (when rhook
+      (run-hook-with-args rhook cl))
+    ))
 
 (defun xwem-cl-hconfigure-request (cl xev)
   "ConfigureRequest event XEV."
   )
 
+;;;###autoload
 (defun xwem-cl-hdestroy-notify (cl xev)
   "DestroyNotify event XEV."
-  (let ((ocl (xwem-cl-other cl))
-	(owin (xwem-cl-win cl)))
+  (setf (xwem-cl-state cl) 'destroyed)
+  (xwem-manda-demanage cl 'destroyed)
 
-;    (xwem-manda-fun-run (xwem-cl-manda cl) 'demanage cl)
-    (xwem-remove-client cl)
+  (xwem-remove-client cl)
 
-    (if (xwem-cl-transient-for cl)
-	(xwem-manda-fun-run (xwem-cl-manda cl) 'demanage cl)
+  ;; Now run on-destroy hooks
+  (run-hook-with-args 'xwem-cl-destroy-hook cl)
 
-      ;; Try to switch to other client
-      (when (xwem-cl-inwin-p cl)
-	(when (xwem-win-p owin)
-	  (setf (xwem-win-cl owin) nil)
-
-	  (when (xwem-cl-p ocl)
-	    (xwem-manda-fun-run (xwem-cl-manda ocl) 'manage ocl owin))))
-
-      (when (xwem-win-p owin)
-	(xwem-tabber-regeom-window owin (xwem-win-selected-p owin)))
-      )
-    ))
+  ;; Make client not valid for futher referencing
+  (X-invalidate-cl-struct cl)
+  )
 
 (defun xwem-cl-hunmap-notify (cl xev)
   "UnmapNotify event XEV."
 
   (let ((cl (xwem-find-client (X-Event-win xev))))
     (if (xwem-cl-p cl)
-	(xwem-manda-fun-run (xwem-cl-manda cl) 'manage cl)
+	(xwem-manda-manage cl)
 
-      (xwem-make-client (X-Event-win xev) nil)))
-  )
+      (xwem-make-client (X-Event-win xev)))
+    ))
 
 (defun xwem-cl-hclient-message (cl xev)
   "ClientMessage event XEV."
-  )
+  (let ((type (length (X-Event-xclient-msg xev))))	; 5 -> 32, 10 -> 16, 20 -> 8
+
+    (X-Dpy-log (xwem-dpy) "XWEM-CLIENT: in ClientMessage: type=%S msg(0)=%S\n"
+               'type  '(car (nth 0 (X-Event-xclient-msg xev))))
+
+    (cond ((and (= type 5)
+                (= (car (nth 0 (X-Event-xclient-msg xev))) X-IconicState))
+           (xwem-manda-iconify cl))
+          )
+    ))
 
 (defun xwem-cl-events-handler (xdpy xwin xev)
   "Events handler for root window."
   (X-Dpy-log xdpy "CLIENT HANDLER: xev type=%S, win=%S\n" '(X-Event-name xev) '(X-Win-id (X-Event-win xev)))
 
-  (let ((cl (xwem-find-client xwin)))
+  (let ((cl (X-Win-get-prop xwin 'xwem-cl)))
+    (when (xwem-cl-p cl)
+      (X-Event-CASE xev
+        ((:X-KeyPress :X-ButtonPress :X-ButtonRelease)
+         (xwem-kbd-handle-keybutton xev))
 
-    (X-Event-CASE xev
-      ((:X-KeyPress :X-ButtonPress :X-ButtonRelease)
-       (xwem-cl-hkeybutton cl xev))
+        ;; Focusing mode
+        (:X-FocusIn (xwem-focus-mode-invoke cl 'focus-in xev))
+        (:X-FocusOut (xwem-focus-mode-invoke cl 'focus-out xev))
+        (:X-EnterNotify (xwem-focus-mode-invoke cl 'enter xev))
+        (:X-LeaveNotify (xwem-focus-mode-invoke cl 'leave xev))
 
-      ;; Focusing mode
-      (:X-FocusIn
-       (X-Dpy-log xdpy "CLIENT FOCUSIN: wm_name=%S, mode=%S, detail=%S\n"
-                  '(XGetWMName xdpy (X-Event-win xev)) '(X-Event-xfocus-mode xev) '(X-Event-detail xev))
-       (xwem-focus-mode-invoke cl 'focus-in xev))
-      (:X-FocusOut
-       (xwem-focus-mode-invoke cl 'focus-out xev))
-      (:X-EnterNotify
-       (xwem-focus-mode-invoke cl 'enter xev))
-      (:X-LeaveNotify
-       (xwem-focus-mode-invoke cl 'leave xev))
+        ;; Various events
+        (:X-PropertyNotify (xwem-cl-hproperty cl xev))
+        (:X-MapRequest (xwem-cl-hmap-request cl xev))
+        (:X-ConfigureRequest (xwem-cl-hconfigure-request cl xev))
+        (:X-ClientMessage (xwem-cl-hclient-message cl xev))
 
-      (:X-PropertyNotify
-       (xwem-cl-hproperty cl xev))
+        (:X-DestroyNotify
+         (setq cl (xwem-find-client (X-Event-xdestroywindow-window xev)))
+         (when (xwem-cl-p cl)
+           (xwem-cl-hdestroy-notify cl xev)))
 
-      (:X-ConfigureRequest
-       (xwem-cl-hconfigure-request cl xev))
+        ;; Not really used now, but ...
+        (:X-UnmapNotify (xwem-cl-hunmap-notify cl xev))
+        (:X-MapNotify (xwem-cl-hmap-notify cl xev))
+        )
+      )))
 
-      (:X-DestroyNotify
-       (setq cl (xwem-find-client (X-Event-xdestroywindow-window xev)))
-       (when (xwem-cl-p cl)
-         (xwem-cl-hdestroy-notify cl xev)))
+;;; CL's parent xwin hacks
+(defun xwem-cl-parent-on-creation (cl)
+  "CL just created."
+  (xwem-cl-put-prop cl 'parent-xwin
+    (XCreateWindow (xwem-dpy) nil 0 0 1 1 0 nil nil nil (make-X-Attr))))
 
-      (:X-UnmapNotify
-       ;; Someone issued XUnmapWindow
-       (xwem-cl-hunmap-notify cl xev))
-   
-      (:X-MapNotify
-       ;; Someone issued XMapWindow
-       (xwem-cl-hmap-notify cl xev))
+(defun xwem-cl-parent-on-change-state (cl old-state new-state)
+  "CL changed state."
+  (let ((pwin (xwem-cl-get-prop cl 'parent-xwin)))
+    (when (X-Win-p pwin)
+      (cond ((or (eq new-state 'managed)
+                 (eq new-state 'iconified)
+                 (eq new-state 'demanaged))
+             ;; Some applications, such as mozilla, when running with
+             ;; -remote tries to find another mozilla instance to run
+             ;; in it, it seaches lowerest client, but it is not
+             ;; guarantied, because xwem frame holds many clients.
+             (XReparentWindow (xwem-dpy) (xwem-cl-xwin cl) pwin 0 0)
+             (XLowerWindow (xwem-dpy) (xwem-cl-xwin cl)))
+            )
+      )))
 
-      (:X-MapRequest
-       (xwem-cl-hmap-request cl xev))
-
-      (:X-ClientMessage
-       (xwem-cl-hclient-message cl xev))
-
-      )))
+(defun xwem-cl-parent-on-destroy (cl)
+  "CL is about to be destroyed."
+  (let ((pwin (xwem-cl-get-prop cl 'parent-xwin)))
+    (when (X-Win-p pwin)
+      (XDestroyWindow (xwem-dpy) pwin))))
 
 
 (provide 'xwem-clients)

File lisp/xwem-clswi.el

 	  (setq num (% (+ cclinx arg) (length cls)))
 	  (setq scl (nth (if (natnump num) num (+ (length cls) num)) cls))
 
-	  (xwem-manda-fun-run (xwem-cl-manda scl) 'manage scl)
+	  (xwem-manda-manage scl)
 
 	  (when xwem-clswi-show-info
 	    (xwem-client-info scl)))

File lisp/xwem-compat.el

 
 ;;; Commentary:
 
-;; 
+;; Compatibility layer betwean XEmacs and GNU Emacs.  However xwem
+;; still can't run on GNU Emacs.
 
 ;;; Code:
 
-(defvar xwem-gnuemacs-p nil "Non-nil when running under GNU Emacs.")
-
-(eval-and-compile
-  (setq xwem-gnuemacs-p (string-match "GNU Emacs" emacs-version)))
+;;;###autoload
+(defvar xwem-gnuemacs-p (string-match "GNU Emacs" emacs-version)
+  "Non-nil when running under GNU Emacs.")
 
 ;;;###autoload
 (defun xwem-define-prefix-command (name &optional mapvar)
       (define-prefix-command name)
     (define-prefix-command name t)))
 
+;;;###autoload
 (unless (fboundp 'set-keymap-default-binding)
   (fset 'set-keymap-default-binding
 	(lambda (keym cmd) (define-key keym [t] cmd))))
 
+;;;###autoload
 (unless (fboundp 'events-to-keys)
   (defalias 'events-to-keys 'identity))
 

File lisp/xwem-diagram.el

             (setq buta2 (- a2 (- buta1 a1))))
 
         (setq d0-buta1 180)
-        (setq d0-buta2 (- (+ a1 a2) 270)))
+        (setq d0-buta2 (- (+ a1 a2) 270 270)))
       )
 
     (when (> (+ (or buta1 a1) (or buta2 a2)) 360)
         (progn
           (when fill-gc
             (XFillArc (X-Win-dpy xwin) xwin fill-gc x (+ y sector-width) w h buta1 buta2))
-          (XDrawArc (X-Win-dpy xwin) xwin gc x (+ y sector-width) w h buta1 buta2))
+          (XDrawArc (X-Win-dpy xwin) xwin gc x (+ y sector-width) w h buta1 buta2)
+          )
 
-      (if (or (and d0-buta1 d0-buta1)
+      (if (or (and d0-buta1 d0-buta2)
               (and d2-buta1 d2-buta2))
           (progn
-            (when (and d0-buta1 d0-buta1)
+            (when (and d0-buta1 d0-buta2)
               (when fill-gc
                 (XFillArc (X-Win-dpy xwin) xwin fill-gc x (+ y sector-width) w h d0-buta1 d0-buta2))
-              (XDrawArc (X-Win-dpy xwin) xwin gc x (+ y sector-width) w h d0-buta1 d0-buta2))
+              (XDrawArc (X-Win-dpy xwin) xwin gc x (+ y sector-width) w h d0-buta1 d0-buta2)
+              )
             (when (and d2-buta1 d2-buta2)
               (when fill-gc
                 (XFillArc (X-Win-dpy xwin) xwin fill-gc x (+ y sector-width) w h d2-buta1 d2-buta2))
-              (XDrawArc (X-Win-dpy xwin) xwin gc x (+ y sector-width) w h d2-buta1 d2-buta2)))
+              (XDrawArc (X-Win-dpy xwin) xwin gc x (+ y sector-width) w h d2-buta1 d2-buta2)
+              ))
 
         (when (and (xwem-diag-dot->= 'y (nth 0 ds1) (nth 1 ds1))
                    (xwem-diag-dot->= 'y (nth 2 ds1) (nth 1 ds1)))
                 (list d1 dd1 dd2 dd3 d3 d4 d1 d2 d3 d2 dd2))
   ))
 
+;;;###autoload
 (defun xwem-diag-draw-percentage (type spec d edge-gc x y width height &optional sector-width label-factor label-font)
   "Draw percentage sector of TYPE.
 TYPE is one of 'plain or '3d.
       )))
 
 
+;;;###autoload
 (defun xwem-diag-plot-coordinates (d gc x y w h x-step y-step &rest params)
   "Draw coordinates system."
   (let ((notch-len (or (plist-get params :notch-len) 4))
                                     x-notches y-notches))
     ))
 
+;;;###autoload
 (defun xwem-diag-plot-points (point-type d gc dots &optional point-size)
   "Draw points of TYPE."
   (unless point-size
           )
     ))
 
+;;;###autoload
 (defun xwem-diag-plot-dots (type d gc x y dots &optional point-type point-size)
   "Draw dots in cartesian coordinate system which has 0 at X Y."
     
            ))
     ))
 
+;;;###autoload
 (defun xwem-diag-read-data-file (file &optional using x-scale y-scale)
   "Read data FILE and return list of dots lists.
 USING is cons cell that specifies which columns to use.

File lisp/xwem-edmacro.el

   (setq xwem-edmacro-store-place nil)
   )
 
+;;;###autoload(autoload 'xwem-edmacro-edit-kbd-macro "xwem-edmacro" "" t)
 (define-xwem-command xwem-edmacro-edit-kbd-macro (xwem-keys &optional arg)
   "Edit XWEM keyboard macro specified by XWEM-KEYS.
 With a prefix ARG, format the macro in a more concise way."

File lisp/xwem-events.el

 ;;; Code
 
 
-;; Property change hooks
-;;;###autoload
-(defvar xwem-wmnh-change-hooks nil "Hooks to be called when WM_NORMAL_HINTS changes.")
-;;;###autoload
-(defvar xwem-wmname-change-hooks nil "Hooks to be called when WM_NAME changes.")
-;;;###autoload
-(defvar xwem-wmcommand-chage-hooks nil "Hooks to be called when WM_COMMAND changes.")
-;;;###autoload
-(defvar xwem-wmclass-change-hooks nil "Hooks to be called when WM_CLASS changes.")
-;;;###autoload
-(defvar xwem-wmh-change-hooks nil "Hooks to be called when WM_HINTS changes.")
-
 (defun xwem-ev-defhnd (xdpy win xev)
   "Default X-Events handler."
 
-  (X-Event-CASE
-   xev
-   (:X-ClientMessage
-    (xwem-ev-clnmsg xdpy win xev))
-   (:X-ConfigureRequest
-    (xwem-ev-reconfig xdpy win xev))
-   (:X-MapRequest
-    (xwem-ev-remap xdpy win xev))
-   (:X-DestroyNotify
-    (xwem-ev-destroy xdpy win xev))
-   (:X-PropertyNotify
-    (xwem-ev-property xdpy win xev))
-   (:X-ResizeRequest
-    (xwem-ev-reresize xdpy win xev)))
+  (X-Event-CASE xev
+;   (:X-ClientMessage (xwem-ev-clnmsg xdpy win xev))
+;   (:X-PropertyNotify (xwem-ev-property xdpy win xev))
+   (:X-ConfigureRequest (xwem-ev-reconfig xdpy win xev))
+   (:X-MapRequest (xwem-ev-remap xdpy win xev))
+   (:X-DestroyNotify (xwem-ev-destroy xdpy win xev))
+   (:X-ResizeRequest (xwem-ev-reresize xdpy win xev)))
   )
 
-(defun xwem-ev-clnmsg (xdpy win xev)
-  "Handle ClientMessage event."
-  (X-Dpy-log (xwem-dpy) "XWEM-EVENTS: ClientMessage event: win=%s msg=%s\n"
-	     '(X-Win-id win) '(X-Event-xclient-msg xev))
-
-  (let ((cl (xwem-find-client win))
-	(type (length (X-Event-xclient-msg xev))))	; 5 -> 32, 10 -> 16, 20 -> 8
-
-    (when (xwem-cl-p cl)
-      (X-Dpy-log (xwem-dpy) "XWEM-EVENTS: in ClientMessage: type=%S (car (nth 0 (X-Event-xclient-msg xev)))=%S\n"
-		 'type  '(car (nth 0 (X-Event-xclient-msg xev))))
-      (if (and (= type 5)
-	       (= (car (nth 0 (X-Event-xclient-msg xev)))
-		  X-IconicState))
-	  (xwem-manda-fun-run (xwem-cl-manda cl) 'iconify cl))
-      )
-    nil))
-
 (defun xwem-ev-reconfig (xdpy win xev)
   "Common ConfigureRequest handler."
   (let* ((win (X-Event-xconfigurerequest-window xev))
-	 (cl (xwem-find-client win))
+	 (cl (X-Win-get-prop win 'xwem-cl))
 ;	 (clgeom (if (xwem-cl-p cl) (xwem-cl-xgeom cl) nil))
 	 (vmask (X-Event-xconfigurerequest-value-mask xev)))
 
 				       :border-width (X-Event-xconfigurerequest-border-width xev)))
 
       ;; [else] Client window already in air
-      (progn
-	(if (not (= 0 (Xmask-and vmask (Xmask-or X-CWWidth X-CWHeight X-CWBorderWidth))))
-	    (xwem-manda-fun-run (xwem-cl-manda cl) 'refit cl)
+      (if (not (= 0 (Xmask-and vmask (Xmask-or X-CWWidth X-CWHeight X-CWBorderWidth))))
+          (xwem-manda-refit cl)
 
-	  (xwem-cl-send-config cl))))
+        (xwem-cl-send-config cl)))
     nil))
 
 (defun xwem-ev-remap (xdpy win xev)
 
   (let ((cl (xwem-find-client win)))
     (if (xwem-cl-p cl)
-	(xwem-manda-fun-run (xwem-cl-manda cl) 'manage cl)
-      (xwem-make-client win nil)))
+	(xwem-manda-manage cl)
+      (xwem-make-client win)))
   nil)
 
 (defun xwem-ev-destroy (xdpy win xev)
   ;; TODO: - May this stuff should be moved to `xwem-xdestrnot-hooks'?
   (X-Dpy-log (xwem-dpy) "XWEM-EVENTS: DestroyNotify event handled for win=%s, evwin=%S\n"
 	     '(X-Win-id win) '(X-Win-id (X-Event-xdestroywindow-event xev)))
-
-  (let* ((cl (xwem-find-client win))
-	 (owin (and (xwem-cl-p cl) (xwem-cl-win cl))))
-    (when (xwem-cl-p cl)
-	(xwem-manda-fun-run (xwem-cl-manda cl) 'demanage cl)
-	(xwem-remove-client cl)
-
-	(when (xwem-cl-inwin-p cl)
-	  (when (xwem-win-p owin)
-	    (setf (xwem-win-cl owin) nil)))
-
-	(when (xwem-win-p owin)
-	  (xwem-tabber-regeom-window owin (xwem-win-selected-p owin (xwem-win-frame owin))))
-	))
-  nil)
-
-(defun xwem-ev-property (xdpy win xev)
-  "PropertyNotify handler."
-  ;; TODO: write me
-  (X-Dpy-log (xwem-dpy) "XWEM-EVENTS: PropertyNotify event win=%S, atom=%S, state=%S\n"
-	     '(X-Win-id (X-Event-win xev)) '(X-Atom-id (X-Event-xproperty-atom xev))
-	     '(X-Event-xproperty-state xev))
-
-  (let ((cl (xwem-find-client win))
-	(atom-id (X-Atom-id (X-Event-xproperty-atom xev)))
-	(state (X-Event-xproperty-state xev))
-	(rhook nil))			;hook to be runned after processing
-
-    (if (null cl)
-	;; hmm -- no such client
-	nil
-
-      (cond 
-       ((= atom-id (X-Atom-id XA-wm-normal-hints))
-	(setf (xwem-hints-wm-normal-hints (xwem-cl-hints cl))
-	      (if (= state X-PropertyNewValue)
-		  (XGetWMNormalHints (xwem-dpy) win)
-		nil))
-	(setq rhook 'xwem-wmnh-change-hooks))
-
-       ((= atom-id (X-Atom-id XA-wm-hints))
-	(setf (xwem-hints-wm-hints (xwem-cl-hints cl))
-	      (if (= state X-PropertyNewValue)
-		  (XGetWMHints (xwem-dpy) win)
-		nil))
-	(setq rhook 'xwem-wmh-change-hooks))
-
-       ((= atom-id (X-Atom-id XA-wm-class))
-	(setf (xwem-hints-wm-class (xwem-cl-hints cl))
-	      (if (= state X-PropertyNewValue)
-		  (XGetWMClass (xwem-dpy) win)
-		nil))
-	(setq rhook 'xwem-wmclass-change-hooks))
-
-       ((= atom-id (X-Atom-id XA-wm-command))
-	(setf (xwem-hints-wm-command (xwem-cl-hints cl))
-	      (if (= state X-PropertyNewValue)
-		  (XGetWMCommand (xwem-dpy) win)
-		nil))
-	(setq rhook 'xwem-wmcommand-chage-hooks))
-
-       ((= atom-id (X-Atom-id XA-wm-name))
-	(setf (xwem-hints-wm-name (xwem-cl-hints cl))
-	      (if (= state X-PropertyNewValue)
-		  (XGetWMName (xwem-dpy) win)
-		nil))
-	(setq rhook 'xwem-wmname-change-hooks))
-	     
-       (t (X-Dpy-log (xwem-dpy) "PropertyNotify: Atom-id = %d\n" 'atom-id)))
-      
-      (when rhook
-	(run-hook-with-args rhook cl)))
-
-    nil))
+  )
 
 (defun xwem-ev-reresize (xdpy win xev)
   "On display XDPY handler ResizeRequest for WIN."
 (defun xwem-fini-events ()
   )
 
+;;;###autoload
+(defvar xwem-events-queue nil)
+
+;; Current events execution depth
+(defvar xwem-events-depth 0)
+
+;;; Function to call when there data in XDPY, but noone reading it.
+;;;###autoload
+(defun xwem-parse-message-guess (xdpy)
+  "There is data waiting on XDPY, but no-one is reading it.
+Try to guess what it is."
+  (X-Dpy-p xdpy 'xwem-parse-message-guess)
+
+  (condition-case nil
+      ;; If no-one reading now, mean than error or event arrived.
+      (when (zerop (X-Dpy-readings xdpy))
+
+        (while (> (length (X-Dpy-message-buffer xdpy)) 0)
+          (X-Dpy-eval-error-or-event xdpy))
+
+        (flet ((evmatch (ev)
+                        (let ((evtype (X-Event-type ev)))
+                          (or (= evtype X-KeyPress)
+;                    (= evtype X-KeyRelease)
+                              (= evtype X-ButtonPress)
+                              (= evtype X-ButtonRelease)
+                              (= evtype X-MotionNotify)))))
+
+          (mapc (lambda (ev)
+                  (when (evmatch ev)
+                    (setq xwem-events-queue (append xwem-events-queue (list ev)))))
+                (X-Dpy-evq xdpy))
+
+          ;; Execute normal events
+          (when (zerop (X-Dpy-evq-protects xdpy))
+            (while (X-Dpy-evq xdpy)
+              (let ((ev (X-Dpy-event-dequeue xdpy)))
+                (unless (evmatch ev)
+                  (X-Dpy-event-dispatch ev))
+                ))))
+
+        ;; Execute covertable events
+        (when (>= (recursion-depth) xwem-events-depth)
+          (incf xwem-events-depth)
+          (unwind-protect
+              (while xwem-events-queue
+                (X-Dpy-event-dispatch (pop xwem-events-queue)))
+            (decf xwem-events-depth)))
+        )
+    (X-Error nil)))
+
+;;;###autoload
+(defun xwem-next-event (&optional timeout)
+  "Fetch next xwem keyboard or mouse event.
+If optional argument PEEK is non-nil than do not remove."
+  (incf xwem-events-depth)
+  (let (xev done)
+    (unwind-protect
+        (while (not done)
+          (if xwem-events-queue
+              (setq xev (pop xwem-events-queue)
+                    done t)
+
+            (when (and (not (accept-process-output (X-Dpy-proc (xwem-dpy)) (or timeout 1)))
+                       timeout)
+              (setq xev nil done t))))
+    (decf xwem-events-depth))
+    xev))
+
 (provide 'xwem-events)
 
 ;;; xwem-events.el ends here

File lisp/xwem-faces.el

 
 ;;; Commentary:
 
-;; Faces support.
+;; Faces support.  Main purpose of `xwem-faces' is easify interface to
+;; X-Gc.
 
 ;;; Code:
 (require 'cus-face)			; for `custom-face-get-spec'
 (defun xwem-eface-to-gc (xdpy face &optional d)
   "On display XDPY convert Emacs FACE to X graphical context.
 Drawable D.
-TOOD: - maybe add support for domains?."
+TOOD: - maybe add support for domains?.
+
+NOTE: Default value for graphics-exposures is `X-False'."
   (let* ((cmap (XDefaultColormap xdpy))
 	 (fgcol (xwem-misc-colorspec->rgb-vector-safe (face-foreground-name face) [0 0 0]))
 	 (bgcol (xwem-misc-colorspec->rgb-vector-safe (face-background-name face) [0 0 0]))
 			 :join-style (or (xwem-face-tag face :join-style) X-JoinMiter)
 			 :function (or (xwem-face-tag face :function) X-GXCopy)
 			 :subwindow-mode (or (xwem-face-tag face :subwindow-mode) X-ClipByChildren)
-			 :graphics-exposures (xwem-face-tag face :graphics-exposures)
+			 :graphics-exposures (or (xwem-face-tag face :graphics-exposures) X-False)
 			 :foreground (XAllocColor xdpy cmap
 						  (make-X-Color :id (X-Dpy-get-id xdpy)
 								:cmap cmap
 ;;;###autoload
 (defun xwem-face-get-gc (name &optional xdpy d)
   "Return X-Gc with NAME.
-Name can be symbol or string."
+Name can be symbol or string.
+XDPY - X display.
+D    - X drawable."
   (let ((gc (get name 'xwem-face-gc)))
     (unless (X-Gc-p gc)
       (xwem-eface-to-gc (or xdpy (xwem-dpy)) name d)

File lisp/xwem-focus.el

 (defun xwem-focus-push-set (xwin)
   "Push current focus to `xwem-focus-stack' and set focus to XWIN."
   (xwem-focus-push)
-  (XSetInputFocus (X-Win-dpy xwin) xwin X-RevertToParent))
+  (XSetInputFocus (xwem-dpy) xwin X-RevertToParent))
 
 ;;;###autoload
 (defun xwem-focus-pop-set ()
   "Pop from `xwem-focus-stack' and set focus."
   (let ((xwin (xwem-focus-pop)))
     (when (X-Win-p xwin)
-      (XSetInputFocus (X-Win-dpy xwin) xwin X-RevertToParent))))
+      (XSetInputFocus (xwem-dpy) xwin X-RevertToParent))))
 
 ;;;###autoload
-(defun xwem-focus-set (thing)
+(defun xwem-focus-set (thing &optional push)
   "Set input focus to THING.
-THING is one of X-Win, xwem-frame, or xwem-client."
+THING - one of X-Win, xwem-frame, or xwem-client.
+PUSH  - Non-nil for pushing thing into `xwem-focus-stack'."
   (cond ((or (X-Win-p thing) (numberp thing)) ; X11 window
-	 (xwem-focus-push-set thing))
+         (when push
+           (xwem-focus-push))
+         (XSetInputFocus (xwem-dpy) thing X-RevertToParent))
 
 	;; xwem client
 	((xwem-cl-p thing)
 
 ;;;###autoload
 (defmacro xwem-focus-excursion (xwin &rest forms)
-  "Do FORMS, saving current input focus and under XWIN focus."
+  "Under XWIN focus do FORMS."
   `(prog2
      (xwem-focus-push-set ,xwin)
      ,@forms
      (xwem-focus-pop-set)))
-
 (put 'xwem-focus-excursion 'lisp-indent-function 1)
 
 

File lisp/xwem-frame.el

   :group 'xwem-frame
   :group 'xwem-faces)
 
+(defcustom xwem-frame-iresize-mode 'normal
+  "Default type of drawing outlines when resizing frame interactively.
+It is not recommeded to use 'opaque resize mode."
+  :type '(choice (const :tag "Normal border" normal)
+                 (const :tag "Contiguous borders" contiguous)
+                 (const :tag "Outline Corners" corners)
+                 (const :tag "Grid" grid)
+                 (const :tag "Opaque" opaque)
+                 )
+  :group 'xwem-frame)
+
+(defcustom xwem-frame-imove-mode 'normal
+  "Default type of drawing outlines when moving frame interactively."
+  :type '(choice (const :tag "Normal border" normal)
+                 (const :tag "Contiguous border" contiguous)
+                 (const :tag "Outline Corners" corners)
+                 (const :tag "Grid" grid)
+                 (const :tag "Opaque" opaque)
+                 )
+  :group 'xwem-frame)
+
+(defcustom xwem-frame-imoveresize-mode-function
+  'xwem-frame-imoveresize-mode-function-default
+  "Function to call in way to select move or resize mode.
+It is passed with two arguments - FRAME and WHAT.
+Where FRAME is frame which is about to move/resize and WHAT is one of 'resize or 'move.
+It should return one of:
+ 'normal     - Normal resize/move mode, just outline frame rectangle.
+ 'contiguous - Butified 'normal mode.
+ 'corners    - Outline frame corners.
+ 'grid       - Outline frame and draw grid inside.
+ 'opaque     - Opaque move/resize mode."
+  :type 'function
+  :group 'xwem-frame)
+
+(defun xwem-frame-imoveresize-mode-function-default (frame what)
+  "Default value of `xwem-frame-imoveresize-mode-function'.
+Return `xwem-frame-iresize-mode' if WHAT is 'resize.
+Return `xwem-frame-imove-mode' if WHAT is 'move."
+  (if (eq what 'resize)
+      xwem-frame-iresize-mode
+    xwem-frame-imove-mode))
+  
+(defcustom xwem-frame-omit-init-frame nil
+  "Non-nil mean no frames will be created on startup."
+  :type 'boolean
+  :group 'xwem-frame)
+
 (defcustom xwem-frame-rolling-switch t
   "*Non-nil mean that \\<xwem-global-map>\\[xwem-frame-next] and
 \\<xwem-global-map>\\[xwem-frame-previous] will always switch, even if
   :type 'boolean
   :group 'xwem-frame)
 
+(defcustom xwem-frame-autoiconify-mode nil
+  "Non-nil mean frame possible automatically iconifies when switching.
+If switching from OFR to NFR frame values mean next:
+ nil       - No frame will be iconified.
+ intersect - OFR will be iconified if it intersects with NFR.
+ always    - OFR always iconfied."
+  :type '(choice (const :tag "Disabled" nil)
+                 (conts :tag "Intersect" intersect)
+                 (const :tag "Always" always))
+  :group 'xwem-frame)
+
+;; Hooks
 (defcustom xwem-frame-switch-hook nil
   "Hooks to be called when frame switching occurs (i.e. `xwem-current-frame' changes).
  Function will receive two arguments OLD-FRAME and NEW-FRAME."
   :type 'hook
   :group 'xwem-hooks)
 
+(defcustom xwem-frame-creation-hook nil
+  "Hooks called with one argument - frame, when frame just created."
+  :type 'hook
+  :group 'xwem-hooks)
+
+(defcustom xwem-frame-destroy-hook nil
+  "Hooks called with one argument - frame, when frame destroyed."
+  :type 'hook
+  :group 'xwem-hooks)
+
+(defcustom xwem-frame-resize-hook nil
+  "Hooks called with one argument - frame, when frame resized."
+  :type 'hook
+  :group 'xwem-hooks)
+
+(defcustom xwem-frame-move-hook nil
+  "Hooks called with one argument - frame, when frame moved."
+  :type 'hook
+  :group 'xwem-hooks)
+
+(defcustom xwem-frame-redraw-hook nil
+  "Hooks called with one argument - frame, when frame redrawed."
+  :type 'hook
+  :group 'xwem-hooks)
+  
 ;; Variables
 ;;;###autoload
 (defconst xwem-frame-ev-mask (Xmask-or XM-Exposure
 				       XM-StructureNotify
 				       XM-SubstructureRedirect
 				       XM-SubstructureNotify
-				       XM-EnterWindow XM-LeaveWindow
 				       XM-KeyPress XM-ButtonPress XM-ButtonRelease
-				       XM-FocusChange
 				       XM-ResizeRedirect)
   "Events mask for xwem's frame.")
 
   embedded-p				; Non-nil when frame is embedded
   state					; 'mapped, 'unmapped, 'destroyed
 
-  tabber				; xwem-tabber
   props)				; Properties list
 
 (defstruct xwem-frame-saved
 (defsetf xwem-frame-y (frame) (y)
   `(setf (X-Geom-y (xwem-frame-xgeom ,frame)) ,y))
 (defsetf xwem-frame-width (frame) (width)
-  `(let ((tabber (xwem-frame-tabber ,frame)))
-     (when (xwem-tabber-p tabber)
-       (setf (X-Geom-width (xwem-tabber-xgeom tabber)) ,width))
-
-     (setf (X-Geom-width (xwem-frame-xgeom ,frame)) ,width)))
+  `(setf (X-Geom-width (xwem-frame-xgeom ,frame)) ,width))
 (defsetf xwem-frame-height (frame) (height)
   `(setf (X-Geom-height (xwem-frame-xgeom ,frame)) ,height))
 
     (when (not (xwem-win-selected-p clw))
       (xwem-window-select clw))
 
-    (xwem-manda-fun-run (xwem-cl-manda cl) 'manage cl clw)))
+    (xwem-manda-manage cl clw)))
+
+(defun xwem-frame-unembedd (frame)
+  "Unembedd FRAME."
+  (when (xwem-frame-embedded-p frame)
+    (let* ((cl (xwem-find-client (xwem-frame-xwin frame)))
+           (ngeom (nthcdr 4 (XTranslateCoordinates (xwem-dpy) (xwem-frame-xwin frame)
+                                                   (xwem-rootwin) (xwem-frame-x frame)
+                                                   (xwem-frame-y frame)))))
+      ;; Remove clients stuff
+      (X-Win-EventHandler-rem (xwem-cl-xwin cl) 'xwem-cl-events-handler)
+      (xwem-cl-hdestroy-notify cl nil)
+
+      (XReparentWindow (xwem-dpy) (xwem-frame-xwin frame) (xwem-rootwin)
+                       (car ngeom) (cadr ngeom))
+      (setf (xwem-frame-embedded-p frame) nil)
+      (xwem-frame-set-pos frame (car ngeom) (cadr ngeom))
+      )))
 
 ;;;###autoload
 (defun xwem-frame-select (frame &optional dnr-hooks)
   "Set FRAME as selected frame.
 If DNR-HOOKS is non-nil, than do not run hooks."
 
-  ;; If FRAME is embedded frame we should raise frame in whose
-  ;; window FRAME is embedded.
-  (when (xwem-frame-embedded-p frame)
-    (xwem-frame-embedded-pop frame))
-
   (let ((ofr (xwem-frame-selected))
 	(nfr frame))
+    ;; If FRAME is embedded frame we should raise frame in whose
+    ;; window FRAME is embedded.
+    (when (xwem-frame-embedded-p frame)
+      (xwem-frame-embedded-pop frame))
 
     (setq xwem-current-frame frame)
 
     (when (not dnr-hooks)
       (run-hook-with-args 'xwem-frame-switch-hook ofr nfr))))
 
+(defun xwem-frame-maybe-autoiconify (ofr nfr)
+  "This function aimed to be used in `xwem-frame-switch-hook'.
+According to `xwem-frame-autoiconify-mode' it possible iconfies OFR
+frame."
+  (when (and xwem-frame-autoiconify-mode (not (eq ofr nfr))
+             (or (eq xwem-frame-autoiconify-mode 'always)
+                 (and (eq xwem-frame-autoiconify-mode 'intersect) (xwem-frame-p nfr)
+                      (X-Rect-intersect-p (X-Geom-to-X-Rect (xwem-frame-xgeom nfr))
+                                          (X-Geom-to-X-Rect (xwem-frame-xgeom ofr))))))
+    (xwem-frame-unmap ofr)))
+
 (defun xwem-frame-select-defhook (ofr nfr)
   "Default hook for `xwem-frame-switch-hook'.
 NOT USED."
   (X-Dpy-send-excursion (xwem-dpy)
     (when (and (xwem-frame-p ofr)
 	       (xwem-frame-alive-p ofr))
-      (xwem-tabber-draw (xwem-frame-tabber ofr))
-      (xwem-frame-redraw ofr))
+        (xwem-frame-redraw ofr))
 
     (when (and (xwem-frame-p nfr)
 	       (xwem-frame-alive-p nfr))
-      (xwem-tabber-draw (xwem-frame-tabber nfr))
       (xwem-frame-redraw nfr))
-    nil))				; continue hooks processing
+    ))
 
 ;;;###autoload
 (defun xwem-make-frame-1 (&optional embedded-p params props non-select)
 					   (xwem-dpy) (XDefaultColormap (xwem-dpy))
 					   xwem-frame-background)
 			:border-pixel (XBlackPixel (xwem-dpy))
+                        :backing-store X-WhenMapped
 			:cursor xwem-frame-cursor
 			:event-mask xwem-frame-ev-mask)))
 
-    ;; Create tabber
-    (setf (xwem-frame-tabber frame)
-	  (xwem-tabber-create frame (make-X-Geom :x 0 :y 0 :width (xwem-frame-width frame)