all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Takashi Hiromatsu <matsuan@ca2.so-net.ne.jp>
Cc: Juanma Barranquero <lekktu@gmail.com>,
	macemacs-dev <macemacsjp-dev@lists.sourceforge.jp>
Subject: Re: [Mac OS X] [Win32] Frame-transparency patch
Date: Tue, 21 Jun 2005 20:18:19 +0900	[thread overview]
Message-ID: <m2zmtkgdqc.wl%matsuan@ca2.so-net.ne.jp> (raw)
In-Reply-To: <f7ccd24b0506201458730b8137@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1281 bytes --]

Thank you for your kindly advices.

At Mon, 20 Jun 2005 23:58:35 +0200,
Juanma Barranquero wrote:
> I'm using Visual Studio .NET 2003 and I'm getting "undefined
> identifier" errors for LWA_ALPHA and WS_EX_LAYERED. They are on
> WinUser.h, of course; I suppose it's a _WIN32_WINNT >= 0x0500 thing.
> Perhaps the easiest fix is just define the constants yourself.
I've done.

>   - In frame.el you should use
....
>   (when (or (eq system-type 'windows-nt) (eq system-type 'darwin))
> 
> because it's nicer and easier to extend if someday other platforms
> support transparent backgrounds.
Done.

>   - Functions `set-active-alpha' and `set-inactive-alpha' do have an
> argument ALPHA-VALUE, referred to in the docstring as ALPHA. Change
> the name of the argument or fix the docstring, please.
Done.

>  - Also, capitalize the interactive messages "active alpha: " and
> "inactive alpha: " to "Active alpha: " and "Inactive alpha: " (it's
> customary on interactive prompt).
Doen.

>>  - Better still would be to document what the ALPHA-VALUE is and what
>> is its range (0.0 to 1.0, I assume, but it is not said anywhere).
...
> wraparound. It'd be better to restrict the values entered to the
> correct range.
Both done.

Could you check new patch.

Kind regards.

T. Hiromatsu


[-- Attachment #2: transparency2.patch --]
[-- Type: application/octet-stream, Size: 11856 bytes --]

--- lisp/frame.el.orig	2005-06-21 10:25:27.358750000 +0900
+++ lisp/frame.el	2005-06-21 12:17:59.468250000 +0900
@@ -927,6 +927,24 @@
   (modify-frame-parameters (selected-frame)
 			   (list (cons 'border-color color-name))))
 
+(when (memq system-type '(windows-nt darwin))
+  (defun set-active-alpha (alpha)
+    "Set the opacity of the selected frame in active state to ALPHA.
+ALPHA can take value between 0.0 (invisible) to 1.0 (completely opaque).
+When called interactively, prompt for the value of the opacity to set.
+To get the frame's current active alpha value state, use `frame-parameters'."
+    (interactive "nActive alpha (0.0 - 1.0): ")
+    (modify-frame-parameters (selected-frame)
+                             (list (cons 'active-alpha alpha))))
+  (defun set-inactive-alpha (alpha)
+    "Set the opacity of the selected frame in inactive state to ALPHA.
+ALPHA can take value between 0.0 (invisible) to 1.0 (completely opaque).
+When called interactively, prompt for the value of the opacity to set.
+To get the frame's current inactive alpha value state, use `frame-parameters'."
+    (interactive "nInactive alpha (0.0 - 1.0): ")
+    (modify-frame-parameters (selected-frame)
+                             (list (cons 'inactive-alpha alpha)))))
+
 (defun auto-raise-mode (arg)
   "Toggle whether or not the selected frame should auto-raise.
 With arg, turn auto-raise mode on if and only if arg is positive.
--- src/frame.c.orig	2005-06-21 10:25:27.671250000 +0900
+++ src/frame.c	2005-06-21 10:26:44.015000000 +0900
@@ -106,6 +106,10 @@
 Lisp_Object Qleft_fringe, Qright_fringe;
 Lisp_Object Qbuffer_predicate, Qbuffer_list;
 Lisp_Object Qtty_color_mode;
+#if defined (HAVE_CARBON) || defined (WINDOWSNT)
+Lisp_Object Qactive_alpha;
+Lisp_Object Qinactive_alpha;
+#endif
 
 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
 
@@ -2575,6 +2579,10 @@
   {"right-fringe",		&Qright_fringe},
   {"wait-for-wm",		&Qwait_for_wm},
   {"fullscreen",                &Qfullscreen},
+#if defined (HAVE_CARBON) || defined (WINDOWSNT)
+  {"active-alpha",		&Qactive_alpha},
+  {"inactive-alpha",		&Qinactive_alpha},
+#endif
 };
 
 #ifdef HAVE_WINDOW_SYSTEM
--- src/frame.h.orig	2005-06-21 10:25:27.827500000 +0900
+++ src/frame.h	2005-06-21 10:26:44.155625000 +0900
@@ -451,6 +451,11 @@
   /* Additional space to put between text lines on this frame.  */
   int extra_line_spacing;
 
+#if defined (HAVE_CARBON) || defined (WINDOWSNT)
+  /* Opacity of the Frame, which should be a number between 0.0 and 1.0  */
+  float active_alpha, inactive_alpha;
+#endif
+
   /* Set to non-zero in change_frame_size when size of frame changed
      Clear the frame in clear_garbaged_frames if set.  */
   unsigned resized_p : 1;
@@ -1003,6 +1008,10 @@
 extern Lisp_Object Qline_spacing;
 extern Lisp_Object Qwait_for_wm;
 extern Lisp_Object Qfullscreen;
+#if defined (HAVE_CARBON) || defined (WINDOWSNT)
+extern Lisp_Object Qactive_alpha;
+extern Lisp_Object Qinactive_alpha;
+#endif
 
 extern Lisp_Object Qleft_fringe, Qright_fringe;
 extern Lisp_Object Qheight, Qwidth;
@@ -1074,6 +1083,11 @@
 					    Lisp_Object));
 extern void x_set_scroll_bar_width P_ ((struct frame *, Lisp_Object,
 					Lisp_Object));
+#if defined (HAVE_CARBON) || defined (WINDOWSNT)
+extern void x_set_active_alpha P_ ((struct frame *, Lisp_Object, Lisp_Object));
+extern void x_set_inactive_alpha P_ ((struct frame *, Lisp_Object, Lisp_Object));
+extern void x_set_frame_alpha P_ ((struct frame *, int));
+#endif
 
 extern Lisp_Object x_icon_type P_ ((struct frame *));
 
--- src/macfns.c.orig	2005-06-21 10:25:28.186875000 +0900
+++ src/macfns.c	2005-06-21 11:20:22.561875000 +0900
@@ -2026,6 +2026,65 @@
 #endif /* not MAC_OSX */
 }
 
+/* Change the opecity of frame F to ALPHA.
+   ALPHA must be a number between 0.0 and 1.0
+
+   The frame will become completely invisible If ALPHA is 0.0,
+   while the value of 1.0 makes it completely opaque.  */
+
+void
+x_set_active_alpha (f, alpha, old_alpha)
+     struct frame *f;
+     Lisp_Object alpha, old_alpha;
+{
+  /* Don't change the alpha if it's already ALPHA.  */
+  if (EQ (alpha, f->active_alpha))
+    return;
+
+  if (NILP (alpha))
+    return;
+
+  if (FLOATP (alpha))
+    {
+      if ((XFLOAT_DATA (alpha) >= 0.0) && (XFLOAT_DATA (alpha) <= 1.0))
+        {
+          f->active_alpha = XFLOAT_DATA (alpha);
+
+#if TARGET_API_MAC_CARBON
+          BLOCK_INPUT;
+
+          x_set_frame_alpha (f, 1);
+
+          UNBLOCK_INPUT;
+#endif
+        }
+    }
+
+  return;
+}
+
+void
+x_set_inactive_alpha (f, alpha, old_alpha)
+     struct frame *f;
+     Lisp_Object alpha, old_alpha;
+{
+  /* Don't change the alpha if it's already ALPHA.  */
+  if (EQ (alpha, f->inactive_alpha))
+    return;
+
+  if (NILP (alpha))
+    return;
+
+  if (FLOATP (alpha))
+    {
+      if ((XFLOAT_DATA (alpha) >= 0.0) && (XFLOAT_DATA (alpha) <= 1.0))
+        {
+          f->inactive_alpha = XFLOAT_DATA (alpha);
+        }
+    }
+
+  return;
+}
 \f
 /* Subroutines of creating a frame.  */
 
@@ -2736,6 +2795,10 @@
   x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
 		       "scrollBarWidth", "ScrollBarWidth",
 		       RES_TYPE_NUMBER);
+  x_default_parameter (f, parms, Qactive_alpha, make_float(1.0),
+		       "activeAlpha", "ActiveAlpha", RES_TYPE_FLOAT);
+  x_default_parameter (f, parms, Qinactive_alpha, make_float(1.0),
+		       "inactiveAlpha", "InactiveAlpha", RES_TYPE_FLOAT);
 
   /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
      Change will not be effected unless different from the current
@@ -4445,6 +4508,8 @@
   x_set_fringe_width,
   0, /* x_set_wait_for_wm, */
   x_set_fullscreen,
+  x_set_active_alpha,
+  x_set_inactive_alpha,
 };
 
 void
--- src/macterm.c.orig	2005-06-21 10:25:28.765000000 +0900
+++ src/macterm.c	2005-06-21 10:26:44.483750000 +0900
@@ -1771,6 +1771,23 @@
   return FONT_TYPE_UNKNOWN;
 }
 
+void
+x_set_frame_alpha (f, activate_p)
+     struct frame *f;
+     int activate_p;
+{
+  SInt32 response;
+  OSErr err;
+
+  BLOCK_INPUT;
+  err = Gestalt (gestaltSystemVersion, &response);
+  UNBLOCK_INPUT;
+
+  if ((err == noErr) && (response >= 0x1020)) {
+    SetWindowAlpha (f->output_data.mac->mWP,
+                    activate_p? f->active_alpha: f->inactive_alpha);
+  }
+}
 
 \f
 /***********************************************************************
@@ -3493,6 +3510,7 @@
     ActivateControl (root_control);
   UNBLOCK_INPUT;
   x_update_cursor (f, 1);
+  x_set_frame_alpha (f, 1);
 }
 
 static void
@@ -3508,6 +3526,7 @@
     DeactivateControl (root_control);
   UNBLOCK_INPUT;
   x_update_cursor (f, 1);
+  x_set_frame_alpha (f, 0);
 }
 
 /* The focus has changed.  Update the frames as necessary to reflect
--- src/w32fns.c.orig	2005-06-21 10:25:29.218125000 +0900
+++ src/w32fns.c	2005-06-21 11:18:16.202500000 +0900
@@ -262,6 +262,7 @@
 TrackMouseEvent_Proc track_mouse_event_fn = NULL;
 ClipboardSequence_Proc clipboard_sequence_fn = NULL;
 extern AppendMenuW_Proc unicode_append_menu;
+extern SetLayeredWindowAttributes_Proc set_layered_window_attributes_fn;
 
 /* W95 mousewheel handler */
 unsigned int msh_mousewheel = 0;
@@ -1978,6 +1979,63 @@
 				      wid - 1) / wid;
 }
 
+/* Change the opecity of frame F to ALPHA.
+   ALPHA must be a number between 0.0 and 1.0
+
+   The frame will become completely invisible If ALPHA is 0.0,
+   while the value of 1.0 makes it completely opaque.  */
+
+void
+x_set_active_alpha (f, alpha, old_alpha)
+     struct frame *f;
+     Lisp_Object alpha, old_alpha;
+{
+  /* Don't change the alpha if it's already ALPHA.  */
+  if (EQ (alpha, f->active_alpha))
+    return;
+
+  if (NILP (alpha))
+    return;
+
+  if (FLOATP (alpha))
+    {
+      if ((XFLOAT_DATA (alpha) >= 0.0) && (XFLOAT_DATA (alpha) <= 1.0))
+        {
+          f->active_alpha = XFLOAT_DATA (alpha);
+
+          BLOCK_INPUT;
+
+          x_set_frame_alpha (f, 1);
+
+          UNBLOCK_INPUT;
+        }
+    }
+
+  return;
+}
+
+void
+x_set_inactive_alpha (f, alpha, old_alpha)
+     struct frame *f;
+     Lisp_Object alpha, old_alpha;
+{
+  /* Don't change the alpha if it's already ALPHA.  */
+  if (EQ (alpha, f->inactive_alpha))
+    return;
+
+  if (NILP (alpha))
+    return;
+
+  if (FLOATP (alpha))
+    {
+      if ((XFLOAT_DATA (alpha) >= 0.0) && (XFLOAT_DATA (alpha) <= 1.0))
+        {
+          f->inactive_alpha = XFLOAT_DATA (alpha);
+        }
+    }
+
+  return;
+}
 \f
 /* Subroutines of creating a frame.  */
 
@@ -4321,6 +4379,10 @@
 		       "cursorType", "CursorType", RES_TYPE_SYMBOL);
   x_default_parameter (f, parameters, Qscroll_bar_width, Qnil,
 		       "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER);
+  x_default_parameter (f, parameters, Qactive_alpha, make_float(1.0),
+		       "activeAlpha", "ActiveAlpha", RES_TYPE_FLOAT);
+  x_default_parameter (f, parameters, Qinactive_alpha, make_float(1.0),
+		       "inactiveAlpha", "InactiveAlpha", RES_TYPE_FLOAT);
 
   /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
      Change will not be effected unless different from the current
@@ -8473,6 +8535,8 @@
   x_set_fringe_width,
   0, /* x_set_wait_for_wm, */
   x_set_fullscreen,
+  x_set_active_alpha,
+  x_set_inactive_alpha,
 };
 
 void
@@ -8912,6 +8976,9 @@
   /* ditto for GetClipboardSequenceNumber.  */
   clipboard_sequence_fn = (ClipboardSequence_Proc)
     GetProcAddress (user32_lib, "GetClipboardSequenceNumber");
+  /* ditto for SetLayeredWindowAttributes.  */
+  set_layered_window_attributes_fn = (SetLayeredWindowAttributes_Proc)
+    GetProcAddress (user32_lib, "SetLayeredWindowAttributes");
 
   DEFVAR_INT ("w32-ansi-code-page",
 	      &w32_ansi_code_page,
--- src/w32term.c.orig	2005-06-21 10:25:29.686875000 +0900
+++ src/w32term.c	2005-06-21 10:26:44.780625000 +0900
@@ -272,6 +272,8 @@
 
 static Lisp_Object Qvendor_specific_keysyms;
 
+SetLayeredWindowAttributes_Proc set_layered_window_attributes_fn = NULL;
+
 \f
 /***********************************************************************
 			      Debugging
@@ -1187,6 +1189,25 @@
     return ANSI_FONT;
 }
 
+void
+x_set_frame_alpha (f, activate_p)
+     struct frame *f;
+     int activate_p;
+{
+  Window window = FRAME_W32_WINDOW (f);
+
+  if (set_layered_window_attributes_fn != NULL) {
+    SetWindowLong (window, GWL_EXSTYLE,
+                   GetWindowLong (window, GWL_EXSTYLE)|WS_EX_LAYERED);
+    set_layered_window_attributes_fn (FRAME_W32_WINDOW (f),
+                                      RGB(255, 255, 255),
+                                      (int)((activate_p?
+                                             f->active_alpha:
+                                             f->inactive_alpha)
+                                            * 255.0),
+                                      LWA_ALPHA);
+  }
+}
 
 \f
 /***********************************************************************
@@ -2786,6 +2807,7 @@
      struct frame *f;
 {
   x_update_cursor (f, 1);
+  x_set_frame_alpha (f, 1);
 }
 
 static void
@@ -2793,6 +2815,7 @@
      struct frame *f;
 {
   x_update_cursor (f, 1);
+  x_set_frame_alpha (f, 0);
 }
 
 /* The focus has changed.  Update the frames as necessary to reflect
--- src/w32term.h.orig	2005-06-21 10:25:29.858750000 +0900
+++ src/w32term.h	2005-06-21 10:34:08.140000000 +0900
@@ -643,6 +643,10 @@
 
 #define WND_EXTRA_BYTES     (WND_LAST_INDEX)
 
+/* for transparency functions */
+#define LWA_ALPHA 2
+#define WS_EX_LAYERED 0x80000   /* w2k */
+
 extern DWORD dwWindowsThreadId;
 extern HANDLE hWindowsThread;
 extern DWORD dwMainThreadId;
@@ -755,6 +759,8 @@
       ? BDF_1D_FONT : BDF_2D_FONT))
 
 typedef DWORD (WINAPI * ClipboardSequence_Proc) ();
+typedef DWORD (WINAPI * SetLayeredWindowAttributes_Proc)
+  (HWND, DWORD, BYTE, DWORD);
 typedef BOOL (WINAPI * AppendMenuW_Proc) (
     IN HMENU,
     IN UINT,

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  parent reply	other threads:[~2005-06-21 11:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-11  8:02 [Mac OS X] [Win32] Frame-transparency patch Seiji Zenitani
2005-06-14 16:57 ` [Macemacsjp-dev 100] " Seiji Zenitani
2005-06-16 16:59   ` [Macemacsjp-dev 103] " Seiji Zenitani
2005-06-17 20:56   ` [Macemacsjp-dev 100] " Michael Mauger
2005-06-18  0:28     ` Takashi Hiromatsu
2005-06-20 20:36       ` Takashi Hiromatsu
2005-06-20 21:58         ` Juanma Barranquero
2005-06-20 22:00           ` Juanma Barranquero
2005-06-21 11:18           ` Takashi Hiromatsu [this message]
2005-06-21 15:29             ` Juanma Barranquero
2005-06-27 11:38               ` Takashi Hiromatsu
2005-06-21 16:23           ` Kevin Rodgers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2zmtkgdqc.wl%matsuan@ca2.so-net.ne.jp \
    --to=matsuan@ca2.so-net.ne.jp \
    --cc=lekktu@gmail.com \
    --cc=macemacsjp-dev@lists.sourceforge.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.