From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Takashi Hiromatsu Newsgroups: gmane.emacs.devel Subject: Re: [Mac OS X] [Win32] Frame-transparency patch Date: Tue, 21 Jun 2005 20:18:19 +0900 Message-ID: References: <47B1D513-959C-4F8E-8FD1-CCE29BFFB9D4@mac.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Tue_Jun_21_20:18:19_2005-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1119353519 20483 80.91.229.2 (21 Jun 2005 11:31:59 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 21 Jun 2005 11:31:59 +0000 (UTC) Cc: Juanma Barranquero , macemacs-dev Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 21 13:31:48 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Dkgyp-0007D4-4j for ged-emacs-devel@m.gmane.org; Tue, 21 Jun 2005 13:31:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dkh5E-0007P9-HC for ged-emacs-devel@m.gmane.org; Tue, 21 Jun 2005 07:38:24 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DkgzM-0005Ff-W5 for emacs-devel@gnu.org; Tue, 21 Jun 2005 07:32:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DkgzA-00059z-Jq for emacs-devel@gnu.org; Tue, 21 Jun 2005 07:32:15 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DkgzA-00052u-19 for emacs-devel@gnu.org; Tue, 21 Jun 2005 07:32:08 -0400 Original-Received: from [202.238.82.7] (helo=mx07.ms.so-net.ne.jp) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Dkgpy-0008Rh-6B for emacs-devel@gnu.org; Tue, 21 Jun 2005 07:22:38 -0400 Original-Received: from localhost (kcc-202-43-28-144.kamakuranet.ne.jp [202.43.28.144]) by mx07.ms.so-net.ne.jp with ESMTP id j5LBJaLr022564; Tue, 21 Jun 2005 20:19:36 +0900 (JST) Original-To: emacs-devel In-Reply-To: User-Agent: Wanderlust/2.15.1 (Almost Unreal) SEMI/1.14.6 (Maruoka) LIMIT/1.14.9 (Domyoji) APEL/10.6 Emacs/22.0.50 (powerpc-apple-darwin8.1.0) MULE/5.0 (SAKAKI) X-Dispatcher: imput version 20050308(IM148) Original-Lines: 449 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:39224 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:39224 --Multipart_Tue_Jun_21_20:18:19_2005-1 Content-Type: text/plain; charset=US-ASCII 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 --Multipart_Tue_Jun_21_20:18:19_2005-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="transparency2.patch" Content-Transfer-Encoding: 7bit --- 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; +} /* 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); + } +} /*********************************************************************** @@ -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; +} /* 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; + /*********************************************************************** 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); + } +} /*********************************************************************** @@ -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, --Multipart_Tue_Jun_21_20:18:19_2005-1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --Multipart_Tue_Jun_21_20:18:19_2005-1--