Re: toggle-or-exec added to 1.7.0



On Fri, 17 Sep 2010 19:14:30 +0200, Christopher Roy Bratusek wrote:
> I've added toggle-or-exec.

The idea is really nice, but I'm hesitant for reasons given below. Can
it be postponed for 1.7.1?

A. I propose to merge it to jump-or-exec; scattered codes are difficult
to maintain. (By using #!key, the syntax won't be messed.) See also my
3 apr message.

B. defvar part is wrong. Suppose, 
1. call toggle-or-exec-leave. Then the animator is saved.
2. (setq default-window-animator 'xyz)
3. call toggle-or-exec-leave again.
4. default-window-animator -> orig-value != xyz

Isn't it enough to use simply `let'?:
------------------------------------------------------------------------
(define (toggle-or-exec-leave re #!optional class)
  (let ((wind (if class
                  (get-window-by-class-re re)
                (get-window-by-name-re re)))
        (default-window-animator 'none))
    (when (eq wind (current-event-window))
      (iconify-window wind))))
------------------------------------------------------------------------

If you want to store per-window animation rule, (I don't know if it's
possible at all), alist or plist can be used.

C.
> a) is there a better way then first (remove-hook) and then (add-hook) each time? (see the
> toggle-or-exec.jl in HEAD)

Add `add-hook' at the top level, i.e. call it when the module is loaded.

------------------------------------------------------------------------
A 30-sec lisp lecture.

(list (lambda ()) (lambda ()))
-> (#<closure 1e6caf0 @ user> #<closure 1e6c910 @ user>)
The two are not equal.

Each time `lambda' is called, a new instance of a closure is generated.
So remove-hook has no effect in the HEAD code.
------------------------------------------------------------------------

Register only one function to the hook. Matching rules for
iconification can be stored in a module private variable.

D.
(windowp wind) should be checked before display-window, no?

E. (in 1 min.)
autoload-command is necessary.

F.
If it'll be an independent func / module, how about the name
`show-hide-or-exec'?

Considering these points, I don't feel like tinkering at the eleventh
hour. For your interest, I've attached a half fixed version. 

b) is there a window-matcher which makes a window overlap a dock-window?

Good question. No.

Dock windows are given 'avoid' property. (It's a misomer, read
"avoided".)  Avoided windows are not covered.

What you can do now are:
1. delete 'avoid' from dock-window-property. Then *all* dock windows
   are not avoided.
2. There's a window matcher rule to add 'avoid'. But you can't delete
   it. Addition only.

Notice that there's no "avoider" option.

There're some other matcher rules (I've never counted.) of which deletion
would be nice.


I haven't reviewed  new matchers yet.

Regards,
Teika (Teika kazura)

;;; toggle-or-exec.jl -- turn window into drop-down-app (v0.1)

;; Copyright (C) 2010 Christopher Roy Bratusek <zanghar freenet de>

;; This file is part of sawfish.

;; sawfish 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.

;; sawfish 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 sawfish; see the file COPYING.  If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

;;; Description

;; This function either focusss a given window, or starts
;; the application instead, if called on the same window again,
;; it will be hidden, optionally leaving the window may hide it, too.
;;
;; In other words: toggle-or-exec turns the window into an drop-down
;; window like for example Guake or Yakuake drop-down-terminals.
;;
;; Examples:
;;
;; NOTE: If the third arg is or a `nil', it matches a window named
;;       "Geany".
;; ( bind-keys global-keymap "W-F10"
;;   `( toggle-or-exec "Geany" "geany" nil ) )
;;
;; NOTE: the `t' tells jump-or-exec to match on WM_CLASS
;; ( bind-keys global-keymap "W-F2"
;;   `( toggle-or-exec "Gnome-run-dialog" "gnome-run-dialog" t ) )
;;
;; NOTE: With the 4th arg `t', hide the window when the pointer leaves.
;; ( bind-keys global-keymap "W-F11"
;;   `( toggle-or-exec "Opera" nil t ) )

(define-structure sawfish.wm.commands.toggle-or-exec

    (export toggle-or-exec)

    (open rep
          rep.system
	  rep.regexp
          sawfish.wm.misc
          sawfish.wm.windows
          sawfish.wm.events
	  sawfish.wm.util.display-window
	  sawfish.wm.state.iconify
	  sawfish.wm.commands)

  (define (toggle-or-exec re prog #!optional class exit-when-leave)
    "Jump to a window matched by regular expression RE, or start
program otherwise."
    (let ((wind (if class
                    (get-window-by-class-re re)
		  (get-window-by-name-re re))))
      (if (string-match re (window-name (input-focus)))
	  ;; Iconify it, and that's all
	  (toggle-or-exec-leave re class)
	;; Focus or exec
	(cond
	 ((windowp wind)
	  (display-window wind))
	 ((functionp prog)
	  (funcall prog))
	 (t
	  (system (concat prog " &"))))
	(when exit-when-leave
	  ;; is there a better way?
	  (remove-hook 'leave-notify-hook (lambda () (toggle-or-exec-leave re class)))
          (add-hook 'leave-notify-hook (lambda () (toggle-or-exec-leave re class)))))))

  (define (toggle-or-exec-leave re #!optional class)
    (let ((wind (if class
                    (get-window-by-class-re re)
		  (get-window-by-name-re re)))
	  (default-window-animator 'none))
      (when (eq wind (current-event-window))
	(iconify-window wind))))

  (define-command 'toggle-or-exec toggle-or-exec #:class 'default))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]