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: Mon, 27 Jun 2005 20:38:28 +0900 Message-ID: References: <47B1D513-959C-4F8E-8FD1-CCE29BFFB9D4@mac.com> Reply-To: takashi-hiromatsu@isuzu.co.jp NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Mon_Jun_27_20:38:28_2005-1" X-Trace: sea.gmane.org 1119872088 13728 80.91.229.2 (27 Jun 2005 11:34:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 27 Jun 2005 11:34:48 +0000 (UTC) Cc: Juanma Barranquero , macemacs-dev Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 27 13:34:42 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Dmrs8-0000Jm-4m for ged-emacs-devel@m.gmane.org; Mon, 27 Jun 2005 13:33:57 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dmrzh-0004eq-Ih for ged-emacs-devel@m.gmane.org; Mon, 27 Jun 2005 07:41:41 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DmrzH-0004d7-6R for emacs-devel@gnu.org; Mon, 27 Jun 2005 07:41:15 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DmrzD-0004bC-DU for emacs-devel@gnu.org; Mon, 27 Jun 2005 07:41:12 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DmrzD-0004aj-8d for emacs-devel@gnu.org; Mon, 27 Jun 2005 07:41:11 -0400 Original-Received: from [202.238.82.6] (helo=mx06.ms.so-net.ne.jp) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Dms1T-0004mO-Os for emacs-devel@gnu.org; Mon, 27 Jun 2005 07:43:32 -0400 Original-Received: from localhost (kcc-202-43-28-144.kamakuranet.ne.jp [202.43.28.144]) by mx06.ms.so-net.ne.jp with ESMTP id j5RBcvKd029184; Mon, 27 Jun 2005 20:38:59 +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: 474 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:39647 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:39647 --Multipart_Mon_Jun_27_20:38:28_2005-1 Content-Type: text/plain; charset=US-ASCII New patch is attached. In this patch. Lisp functions are modified. Add frame object as optional arguments. (set-(in)active-alpha alpha &optional frame) Parmeter check routines are added. Although non-highlighted frame, inactive-alpha value is reflected immediately Thank you, Juanma Barranquero, for your many advices. T.Hiromatsu --Multipart_Mon_Jun_27_20:38:28_2005-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="transparency2.patch" Content-Transfer-Encoding: 7bit --- lisp/frame.el.orig_t 2005-06-25 06:27:47.000000000 +0900 +++ lisp/frame.el 2005-06-25 06:28:20.000000000 +0900 @@ -927,6 +927,30 @@ (modify-frame-parameters (selected-frame) (list (cons 'border-color color-name)))) +(when (memq system-type '(windows-nt darwin)) + (defun set-active-alpha (alpha &optional frame) + "Set the opacity of FRAME in active state to ALPHA. A floating-point +parameter ALPHA should range from 0.0 (invisible) to 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'." + (interactive "nActive alpha (0.0 - 1.0): ") + (when (or (< alpha 0.0) (> alpha 1.0)) + (error "Alpha value must be between 0.0 and 1.0, inclusive")) + (modify-frame-parameters frame + (list (cons 'active-alpha alpha)))) + (defun set-inactive-alpha (alpha &optional frame) + "Set the opacity of FRAME in active state to ALPHA. A floating-point +parameter ALPHA should range from 0.0 (invisible) to 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'." + (interactive "nInactive alpha (0.0 - 1.0): ") + (when (or (< alpha 0.0) (> alpha 1.0)) + (error "Alpha value must be between 0.0 and 1.0, inclusive")) + (modify-frame-parameters 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_t 2005-06-25 06:27:47.000000000 +0900 +++ src/frame.c 2005-06-25 06:28:21.000000000 +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; @@ -2581,6 +2585,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_t 2005-06-25 06:27:47.000000000 +0900 +++ src/frame.h 2005-06-25 06:28:21.000000000 +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; --- src/macfns.c.orig_t 2005-06-25 06:27:47.000000000 +0900 +++ src/macfns.c 2005-06-25 09:58:37.000000000 +0900 @@ -302,6 +302,8 @@ extern void mac_get_window_bounds P_ ((struct frame *, Rect *, Rect *)); +extern void x_set_frame_alpha P_ ((struct frame *, int)); + /* Store the screen positions of frame F into XPTR and YPTR. These are the positions of the containing window manager window, not Emacs's own window. */ @@ -2026,6 +2028,82 @@ #endif /* not MAC_OSX */ } +/* Change the opacity 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. */ + +static void +x_set_active_alpha (f, alpha, old_alpha) + struct frame *f; + Lisp_Object alpha, old_alpha; +{ + struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); + + /* Don't change the alpha if it's already ALPHA. */ + if (EQ (alpha, f->active_alpha)) + return; + + if (NILP (alpha)) + return; + + if ((XFLOAT_DATA (alpha) < 0.0) || (XFLOAT_DATA (alpha) > 1.0)) + { + f->active_alpha = XFLOAT_DATA (old_alpha); + return; + } + + if (FLOATP (alpha)) + { + f->active_alpha = XFLOAT_DATA (alpha); + +#if TARGET_API_MAC_CARBON + BLOCK_INPUT; + + if(dpyinfo->x_highlight_frame == f) + { + x_set_frame_alpha (f, 1); + } + + UNBLOCK_INPUT; +#endif + } + + return; +} + +static void +x_set_inactive_alpha (f, alpha, old_alpha) + struct frame *f; + Lisp_Object alpha, old_alpha; +{ + struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f); + + /* Don't change the alpha if it's already ALPHA. */ + if (EQ (alpha, f->inactive_alpha)) + return; + + if (NILP (alpha)) + return; + + if ((XFLOAT_DATA (alpha) < 0.0) || (XFLOAT_DATA (alpha) > 1.0)) + { + f->inactive_alpha = XFLOAT_DATA (old_alpha); + return; + } + + if (FLOATP (alpha)) + { + f->inactive_alpha = XFLOAT_DATA (alpha); + if(dpyinfo->x_highlight_frame != f) + { + x_set_frame_alpha (f, 0); + } + } + + return; +} /* Subroutines of creating a frame. */ @@ -2736,6 +2814,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 +4527,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_t 2005-06-25 06:27:47.000000000 +0900 +++ src/macterm.c 2005-06-25 09:58:38.000000000 +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_t 2005-06-25 06:27:47.000000000 +0900 +++ src/w32fns.c 2005-06-25 09:56:21.000000000 +0900 @@ -70,6 +70,8 @@ extern char *lispy_function_keys[]; +extern void x_set_frame_alpha P_ ((struct frame *, int)); + /* The gray bitmap `bitmaps/gray'. This is done because w32term.c uses it, and including `bitmaps/gray' more than once is a problem when config.h defines `static' as an empty replacement string. */ @@ -262,6 +264,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 +1981,80 @@ wid - 1) / wid; } +/* Change the opacity 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. */ + +static void +x_set_active_alpha (f, alpha, old_alpha) + struct frame *f; + Lisp_Object alpha, old_alpha; +{ + struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); + + /* Don't change the alpha if it's already ALPHA. */ + if (EQ (alpha, f->active_alpha)) + return; + + if (NILP (alpha)) + return; + + if ((XFLOAT_DATA (alpha) < 0.0) || (XFLOAT_DATA (alpha) > 1.0)) + { + f->active_alpha = XFLOAT_DATA (old_alpha); + return; + } + + if (FLOATP (alpha)) + { + f->active_alpha = XFLOAT_DATA (alpha); + + BLOCK_INPUT; + + if(dpyinfo->x_highlight_frame == f) + { + x_set_frame_alpha (f, 1); + } + + UNBLOCK_INPUT; + } + + return; +} + +static void +x_set_inactive_alpha (f, alpha, old_alpha) + struct frame *f; + Lisp_Object alpha, old_alpha; +{ + struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); + + /* Don't change the alpha if it's already ALPHA. */ + if (EQ (alpha, f->inactive_alpha)) + return; + + if (NILP (alpha)) + return; + + if ((XFLOAT_DATA (alpha) < 0.0) || (XFLOAT_DATA (alpha) > 1.0)) + { + f->inactive_alpha = XFLOAT_DATA (old_alpha); + return; + } + + if (FLOATP (alpha)) + { + f->inactive_alpha = XFLOAT_DATA (alpha); + if(dpyinfo->x_highlight_frame != f) + { + x_set_frame_alpha (f, 0); + } + } + + return; +} /* Subroutines of creating a frame. */ @@ -4321,6 +4398,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 +8554,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 +8995,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_t 2005-06-25 06:27:47.000000000 +0900 +++ src/w32term.c 2005-06-25 06:28:21.000000000 +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_t 2005-06-25 06:27:47.000000000 +0900 +++ src/w32term.h 2005-06-25 06:29:12.000000000 +0900 @@ -643,6 +643,14 @@ #define WND_EXTRA_BYTES (WND_LAST_INDEX) +/* for transparency functions */ +#ifndef LWA_ALPHA +#define LWA_ALPHA 2 +#endif +#ifndef WS_EX_LAYERED +#define WS_EX_LAYERED 0x80000 /* w2k */ +#endif + extern DWORD dwWindowsThreadId; extern HANDLE hWindowsThread; extern DWORD dwMainThreadId; @@ -755,6 +763,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_Mon_Jun_27_20:38:28_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_Mon_Jun_27_20:38:28_2005-1--