-
Notifications
You must be signed in to change notification settings - Fork 0
/
2002-windows_transparency.diff
162 lines (157 loc) · 4.88 KB
/
2002-windows_transparency.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# HG changeset patch
# Parent fde93adeda8d91c54211d002010c4476c27e8dcc
# Parent 04bb907f937cefc1a013ccdaa2e54569944b57a8
implement 'transparency' for Windows GUI
diff --git a/src/gui_w32.c b/src/gui_w32.c
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -50,6 +50,13 @@ static int gui_mswin_get_menu_height(int
# define gui_mswin_get_menu_height(fix_window) 0
#endif
+/*
+ * For Transparent Window.
+ */
+typedef DWORD (WINAPI *FWINLAYER)(HWND hwnd, DWORD crKey, BYTE bAlpha,
+ DWORD dwFlags);
+static void w32_set_transparency(HWND hwnd, BYTE bAlpha);
+
#if defined(FEAT_RENDER_OPTIONS) || defined(PROTO)
int
gui_mch_set_rendering_options(char_u *s)
@@ -5358,6 +5365,8 @@ gui_mch_init(void)
if (s_hwnd == NULL)
return FAIL;
+ w32_set_transparency(s_hwnd, p_transparency);
+
if (pGetDpiForWindow != NULL)
{
s_dpi = pGetDpiForWindow(s_hwnd);
@@ -5658,6 +5667,44 @@ gui_mch_set_sp_color(guicolor_T color)
gui.currSpColor = color;
}
+ void
+w32_set_transparency(HWND hwnd, BYTE bAlpha)
+{
+ FWINLAYER pfLayer;
+ HANDLE hDll;
+
+ if (!hwnd)
+ hwnd = s_hwnd;
+
+ // Turn off transpareny
+ if (bAlpha == 255)
+ {
+ SetWindowLong(hwnd, GWL_EXSTYLE, ~WS_EX_LAYERED &
+ GetWindowLong(hwnd, GWL_EXSTYLE));
+ return;
+ }
+
+ // Obtain pointer to function set transparecy rate
+ if (!(hDll = LoadLibrary("user32.dll")))
+ return;
+ pfLayer = (FWINLAYER)GetProcAddress(hDll, "SetLayeredWindowAttributes");
+
+ if (pfLayer)
+ {
+ SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED |
+ GetWindowLong(hwnd, GWL_EXSTYLE));
+ pfLayer(hwnd, 0, bAlpha, LWA_ALPHA);
+ }
+
+ FreeLibrary(hDll);
+}
+
+ void
+gui_mch_set_transparency(int alpha)
+{
+ w32_set_transparency(NULL, (BYTE)alpha);
+}
+
#ifdef FEAT_MBYTE_IME
/*
* Multi-byte handling, originally by Sung-Hoon Baek.
diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -4217,6 +4217,24 @@ did_set_textwidth(char *errmsg)
return errmsg;
}
+#if defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
+/*
+ * Process the new 'transparency' option value.
+ */
+ char *
+did_set_transparency(optset_T *args UNUSED)
+{
+ if (p_transparency < 1 || p_transparency > 255)
+ p_transparency = 255;
+# ifdef VIMDLL
+ if (gui.in_use)
+# endif
+ gui_mch_set_transparency(p_transparency);
+ return NULL;
+}
+#endif
+
+
/*
* When some number options are changed, need to take some action.
*/
diff --git a/src/option.h b/src/option.h
--- a/src/option.h
+++ b/src/option.h
@@ -983,6 +983,7 @@ EXTERN long p_titlelen; // 'titlelen'
EXTERN char_u *p_titleold; // 'titleold'
EXTERN char_u *p_titlestring; // 'titlestring'
EXTERN char_u *p_tsr; // 'thesaurus'
+EXTERN long p_transparency; // 'transparency'
EXTERN int p_ttimeout; // 'ttimeout'
EXTERN long p_ttm; // 'ttimeoutlen'
EXTERN int p_tbi; // 'ttybuiltin'
diff --git a/src/optiondefs.h b/src/optiondefs.h
--- a/src/optiondefs.h
+++ b/src/optiondefs.h
@@ -2591,6 +2591,10 @@ static struct vimoption options[] =
{(char_u *)0L, (char_u *)0L}
#endif
SCTX_INIT},
+ {"transparency", "tra", P_NUM|P_VI_DEF,
+ (char_u *)&p_transparency, PV_NONE, did_set_transparency,
+ {(char_u *)255L, (char_u *)0L}
+ SCTX_INIT},
{"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
(char_u *)&p_ttimeout, PV_NONE,
{(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
diff --git a/src/proto/gui_w32.pro b/src/proto/gui_w32.pro
--- a/src/proto/gui_w32.pro
+++ b/src/proto/gui_w32.pro
@@ -71,6 +71,7 @@ void gui_mch_set_font(GuiFont font);
void gui_mch_set_fg_color(guicolor_T color);
void gui_mch_set_bg_color(guicolor_T color);
void gui_mch_set_sp_color(guicolor_T color);
+void gui_mch_set_transparency(int alpha);
void im_set_font(LOGFONTW *lf);
void im_set_position(int row, int col);
void im_set_active(int active);
diff --git a/src/proto/optionstr.pro b/src/proto/optionstr.pro
--- a/src/proto/optionstr.pro
+++ b/src/proto/optionstr.pro
@@ -169,6 +169,7 @@ char *did_set_toolbar(optset_T *args);
int expand_set_toolbar(optexpand_T *args, int *numMatches, char_u ***matches);
char *did_set_toolbariconsize(optset_T *args);
int expand_set_toolbariconsize(optexpand_T *args, int *numMatches, char_u ***matches);
+char *did_set_transparency(optset_T *args);
char *did_set_ttymouse(optset_T *args);
char *did_set_varsofttabstop(optset_T *args);
char *did_set_vartabstop(optset_T *args);
diff --git a/src/testdir/gen_opt_test.vim b/src/testdir/gen_opt_test.vim
--- a/src/testdir/gen_opt_test.vim
+++ b/src/testdir/gen_opt_test.vim
@@ -148,6 +148,7 @@ let test_values = {
\ 'termwintype': [['', 'winpty', 'conpty'], ['xxx']],
\ 'toolbar': [['', 'icons', 'text'], ['xxx']],
\ 'toolbariconsize': [['', 'tiny', 'huge'], ['xxx']],
+ \ 'transparency': [['0', '128', '255'], ['xxx']],
\ 'ttymouse': [['', 'xterm'], ['xxx']],
\ 'ttytype': [[], []],
\ 'varsofttabstop': [['8', '4,8,16,32'], ['xxx', '-1', '4,-1,20']],