****************************************************************************
transparency2.patch
                                            Authors     Takashi Hiromatsu
                                                        Ryo Yoshitake
                                                        Seiji Zenitani

                            contact: macemacsjp-english@lists.sourceforge.jp
****************************************************************************
Copyright (C) 2005  Takashi Hiromatsu, Ryo Yoshitake, Seiji Zenitani

This program 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
of the License, or (at your option) any later version.

This program 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.

The GNU General Public License can be gotten from
the Free Software Foundation, Inc.,
    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    http://www.gnu.org/licenses/gpl.html

****************************************************************************

1. Introduction

    This patch provides translucent frames to Emacs on Mac OSX and Windows.
    Each frame has two frame parameters for active and non active window.

    * Emacs on Mac OSX  :   'Carbon Emacs'
                            translucent feature is supported on
                            Mac OSX 10.2 or later
    * Emacs on Windows  :   'NTEmacs'
                            translucent feature is supported on
                            Windows XP, 2000, ME

2. How to build

    Patch from top of the Emacs source directly. 
        patch -p0 <../transparency2.patch

    Configuration options are no longer necessary.
    The translucent feature is automatically enabled.

3. Parameters

    Please set alpha value between 0.0 to 1.0.
        0.0:   invisible (danger)
        1.0:   completely opaque (default)

    to set parameters for current frame

        ;; Active alpha for current frame
        (set-active-alpha 0.9)
        ;; InActive Alpha for current frame
        (set-inactive-alpha 0.8)

    to set default frame parameters

        (setq default-frame-alist
              (append
               (list
                '(active-alpha . 0.80)  ;; active frame
                '(inactive-alpha . 0.4) ;; non active frame
                ) default-frame-alist)
              )

4. lisp functions

    (set-active-alpha alpha &optional frame)
        Set the opacity of frame in active state to alpha.
        alpha can take a value between 0.0 (invisible) and 1.0 (completely opaque).
        When called interactively, prompt for the value of the opacity to set.
        frame defaults to the selected frame.  To get the frame's current
        active alpha value state, use `frame-parameters'.

    (set-inactive-alpha alpha &optional frame)
        Set the opacity of frame in inactive state to alpha.
        alpha can take a value between 0.0 (invisible) and 1.0 (completely opaque).
        When called interactively, prompt for the value of the opacity to set.
        frame defaults to the selected frame.  To get the frame's current
        inactive alpha value state, use `frame-parameters'.

5. application

5.1. change opacity of other frames
        (progn
          (setq current-frame (car (car (cdr (current-frame-configuration)))))
          (setq new-frame (make-frame '((top . 40) (left . 200))))
          (select-frame-set-input-focus current-frame)
          )

        (set-inactive-alpha 0.2 new-frame)

5.2. pseudo fade-in/out

    evaluate this, first,
    
        (progn
          (setq frame-current-frame (car (car (cdr (current-frame-configuration)))))
          (setq buffer-current-buffer (current-buffer))
          (setq new-frame1 (make-frame
                            '((top . 40)
                              (left . 300)
                              (inactive-alpha . 1.0)
                              (active-alpha . 1.0))))
          (setq new-frame2 (make-frame
                            '((top . 40)
                              (left . 300)
                              (inactive-alpha . 0.0)
                              (active-alpha . 1.0))))
          (find-file "~/Pictures/hoge1.jpg")
          (find-file "~/Pictures/hoge2.jpg")
          (switch-to-buffer buffer-current-buffer)
          (select-frame new-frame1)
          (switch-to-buffer "hoge1.jpg")
          (select-frame new-frame2)
          (switch-to-buffer "hoge2.jpg")
          (select-frame-set-input-focus frame-current-frame)
          )

    then execute follows
    
        (let 
             ((increment 0.01)
             (alpha-i 0.0)
             (inhibit-eval-during-redisplay t))
          (while (<= alpha-i 1.0)
            (set-inactive-alpha (- 1 alpha-i) new-frame1)
            (set-inactive-alpha alpha-i new-frame2)
            (setq alpha-i (+ alpha-i increment))
            (sleep-for 0.1))
          (select-frame frame-current-frame)
          )
        
5.3. key bindings for transparency

    Thanks, Juanma Barranquero.
    
        (when (fboundp 'set-active-alpha)
          (defun lk-change-alpha (increment)
            (let ((step (abs increment)))
              (/ (round (+ increment
                           (frame-parameter nil 'active-alpha))
                        step)
                 (/ 1.0 step))))
          (defun lk-opaque ()
            (interactive)
            (set-active-alpha (min 1.0 (lk-change-alpha 0.01))))
          (defun lk-transparent ()
            (interactive)
            (set-active-alpha (max 0.0 (lk-change-alpha -0.01))))
          (global-set-key (kbd "M-<down>")   #'lk-transparent)
          (global-set-key (kbd "M-<up>") #'lk-opaque))
        
6. ChangeLog

2005-06-26 2.1.0
    frame.el:(set-active-alpha) (set-inactive-alpha)
        add check routine for input alpha
        add an optional argument for `frame' object
        add explanation to Doc. that Alpha value must be between 0.0 and
        1.0
    frame.h:
        delete "extern x_set_(in)active_alpha"
    (mac|w32)fns.c:
        add "extern void x_set_frame_alpha"
        x_set_inactive_alpha
            extern --> static
            add check routine the value of frame parameter
            add check routine for frame highlight
            call x_set_frame_alpha to reflect alpha value to frame opacity
            immediately
        x_set_active_alpha
            extern --> static
            add check routine the value of frame parameter
            add check routine for frame highlight
            call x_set_frame_alpha instead of own transparency routine     
    w32fns.c:
        add SetLayeredWindowAttributes_Proc set_layered_window_attributes_fn
        use pointer of function to accommodate system version differencies
    macterm.c
        use "Gestalt" routine at executing instead of "#ifdef" when building
    w32term.c
        call set_layered_window_attributes_fn instead of
        SetLayerdWindowAttribute directly
    w32term.h
        add macro definitions

2005-06-13 2.0.1    Bug fix on frame.el

2005-06-10  2.0     Mr. Yoshitake's frame parameter code
                    bug fix for NTEmacs

