Skip to content

Commit 2c09368

Browse files
mao-yiningchrisbra
authored andcommitted
patch 9.1.1834: MS-Windows: not possible to highlight the title bar
Problem: MS-Windows: not possible to highlight the title bar Solution: Make the title/caption bar configurable by introducing the 'go-C' option value which allows to highlight it using the TitleBar and TitleBarNC highlighting groups (Mao-Yining). Introduce titlebar color customization for Windows 11 GUI through highlight groups and new 'guioptions' flag: - Add 'C' flag to enable titlebar color customization (opt-in) - New highlight groups: TitleBar (active) and TitleBarNC (inactive) - Uses DWMWA_CAPTION_COLOR and DWMWA_TEXT_COLOR DWM attributes - Dynamically loads dwmapi.dll for Windows 11 compatibility - Defaults to system colors when set to NONE or feature disabled closes: #18449 Signed-off-by: Mao-Yining <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent f8b9251 commit 2c09368

File tree

16 files changed

+255
-15
lines changed

16 files changed

+255
-15
lines changed

ci/hlgroups.ignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ TabLineFill
5151
TabLineSel
5252
Terminal
5353
Title
54+
TitleBar
55+
TitleBarNC
5456
TOhtmlProgress
5557
TOhtml-progress-color
5658
ToolbarButton

runtime/doc/gui_w32.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*gui_w32.txt* For Vim version 9.1. Last change: 2025 Aug 06
1+
*gui_w32.txt* For Vim version 9.1. Last change: 2025 Oct 07
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -488,4 +488,20 @@ VIM_KEYCODE_TRANS_STRATEGY can be set to the desired value ("experimental" or
488488
set VIM_KEYCODE_TRANS_STRATEGY=experimental
489489
gvim.exe
490490
<
491+
492+
Title Bar *gui-w32-title-bar*
493+
494+
Starting with Windows 11, you can customize the gVim title bar (also known as
495+
the caption bar) by enabling the |'go-C'| option.
496+
497+
Once enabled, the appearance is controlled by two highlighting groups:
498+
1. |hl-TitleBar| -- Sets the color of the title bar for the active window.
499+
2. |hl-TitleBarNC| -- Sets the color of the title bar for inactive windows.
500+
501+
To use the system's default title bar colors, set highlighting groups to
502+
`NONE`: >
503+
504+
hi TitleBar guibg=NONE guifg=NONE
505+
hi TitleBarNC guibg=NONE guifg=NONE
506+
491507
vim:tw=78:sw=4:ts=8:noet:ft=help:norl:

runtime/doc/options.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 9.1. Last change: 2025 Oct 03
1+
*options.txt* For Vim version 9.1. Last change: 2025 Oct 07
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -4487,6 +4487,10 @@ A jump table for the options with a short description can be found at |Q_op|.
44874487
*'go-c'*
44884488
'c' Use console dialogs instead of popup dialogs for simple
44894489
choices.
4490+
*'go-C'*
4491+
'C' Use |hl-TitleBar| and |hl-TitleBarNC| if available.
4492+
Currently only works for MS-Window GUI.
4493+
See |gui-w32-title-bar| for details.
44904494
*'go-d'*
44914495
'd' Use dark theme variant if available. Currently only works for
44924496
GTK+ GUI.

runtime/doc/syntax.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6092,6 +6092,16 @@ TabPanelSel TabPanel, active tab page label.
60926092
Terminal |terminal| window (see |terminal-size-color|).
60936093
*hl-Title*
60946094
Title Titles for output from ":set all", ":autocmd" etc.
6095+
*hl-TitleBar*
6096+
TitleBar Title bar for the active Gui's window.
6097+
This feature is supported only in the MS-Windows GUI.
6098+
See |gui-w32-title-bar| for details
6099+
Only the `guibg` and `guifg` highlight arguments are effective.
6100+
*hl-TitleBarNC*
6101+
TitleBarNC Title bar for inactive Gui's window.
6102+
This feature is supported only in the MS-Windows GUI.
6103+
See |gui-w32-title-bar| for details
6104+
Only the `guibg` and `guifg` highlight arguments are effective.
60956105
*hl-Visual*
60966106
Visual Visual mode selection.
60976107
*hl-VisualNOS*

runtime/doc/tags

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ $quote eval.txt /*$quote*
355355
'go' options.txt /*'go'*
356356
'go-!' options.txt /*'go-!'*
357357
'go-A' options.txt /*'go-A'*
358+
'go-C' options.txt /*'go-C'*
358359
'go-F' options.txt /*'go-F'*
359360
'go-L' options.txt /*'go-L'*
360361
'go-M' options.txt /*'go-M'*
@@ -8224,6 +8225,7 @@ gui-w32-cmdargs gui_w32.txt /*gui-w32-cmdargs*
82248225
gui-w32-dialogs gui_w32.txt /*gui-w32-dialogs*
82258226
gui-w32-printing gui_w32.txt /*gui-w32-printing*
82268227
gui-w32-start gui_w32.txt /*gui-w32-start*
8228+
gui-w32-title-bar gui_w32.txt /*gui-w32-title-bar*
82278229
gui-w32-various gui_w32.txt /*gui-w32-various*
82288230
gui-w32-windowid gui_w32.txt /*gui-w32-windowid*
82298231
gui-w32s os_win32.txt /*gui-w32s*
@@ -8417,6 +8419,8 @@ hl-TabPanelFill syntax.txt /*hl-TabPanelFill*
84178419
hl-TabPanelSel syntax.txt /*hl-TabPanelSel*
84188420
hl-Terminal syntax.txt /*hl-Terminal*
84198421
hl-Title syntax.txt /*hl-Title*
8422+
hl-TitleBar syntax.txt /*hl-TitleBar*
8423+
hl-TitleBarNC syntax.txt /*hl-TitleBarNC*
84208424
hl-ToolbarButton gui.txt /*hl-ToolbarButton*
84218425
hl-ToolbarLine gui.txt /*hl-ToolbarLine*
84228426
hl-Tooltip syntax.txt /*hl-Tooltip*

runtime/doc/version9.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2025 Oct 05
1+
*version9.txt* For Vim version 9.1. Last change: 2025 Oct 07
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41715,6 +41715,8 @@ Options: ~
4171541715
- Setting 'nowrap' in a modeline could cause long lines to be hidden
4171641716
off-screen. To make this visible, the listchars "extend" suboption is set
4171741717
to ">" by default, indicating text that extends beyond the window width.
41718+
- 'guioptions': New value |'go-C'| to style the title/caption bar on Windows 11
41719+
(see also the below platform specific change).
4171841720

4171941721
Ex commands: ~
4172041722
- allow to specify a priority when defining a new sign |:sign-define|
@@ -41750,6 +41752,8 @@ Plugins~
4175041752
Platform specific ~
4175141753
- MS-Winodws: Paths like "\Windows" and "/Windows" are now considered to be
4175241754
absolute paths (to the current drive) and no longer relative.
41755+
- MS-Windows: The title bar follows the |hl-TitleBar| and |hl-TitleBarNC|
41756+
highlighting group |gui-w32-title-bar|.
4175341757
- macOS: increase default scheduler priority to TASK_DEFAULT_APPLICATION.
4175441758

4175541759
Others: ~
@@ -41841,6 +41845,8 @@ Highlighting: ~
4184141845
|hl-TabPanel| |tabpanel|: not active tab page label
4184241846
|hl-TabPanelFill| |tabpanel|: filler space
4184341847
|hl-TabPanelSel| |tabpanel|: active tab page label
41848+
|hl-TitleBarNC| Configure the inactive title/bar on MS-Windows 11
41849+
|hl-TitleBar| Configure the active title/bar on MS-Windows 11
4184441850

4184541851
Commands: ~
4184641852

runtime/syntax/vim.vim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Vim script
33
" Maintainer: Hirohito Higashi <h.east.727 ATMARK gmail.com>
44
" Doug Kearns <[email protected]>
5-
" Last Change: 2025 Sep 27
5+
" Last Change: 2025 Oct 07
66
" Former Maintainer: Charles E. Campbell
77

88
" DO NOT CHANGE DIRECTLY.
@@ -34,8 +34,8 @@ syn cluster vimCommentGroup contains=vimTodo,@Spell
3434

3535
" regular vim commands {{{2
3636
" GEN_SYN_VIM: vimCommand normal, START_STR='syn keyword vimCommand contained', END_STR='nextgroup=vimBang'
37-
syn keyword vimCommand contained al[l] ar[gs] arga[dd] argd[elete] argdo argded[upe] arge[dit] argg[lobal] argl[ocal] argu[ment] as[cii] b[uffer] bN[ext] ba[ll] bad[d] balt bd[elete] bf[irst] bl[ast] bm[odified] bn[ext] bp[revious] br[ewind] brea[k] breaka[dd] breakd[el] breakl[ist] bro[wse] buffers bufd[o] bun[load] bw[ipeout] c[hange] cN[ext] cNf[ile] cabo[ve] cad[dbuffer] cadde[xpr] caddf[ile] caf[ter] cb[uffer] cbe[fore] cbel[ow] cbo[ttom] cc ccl[ose] cd cdo ce[nter] cex[pr] cf[ile] cfd[o] cfir[st] cg[etfile] cgetb[uffer] cgete[xpr] changes che[ckpath] checkt[ime] chi[story] cl[ist] clip[reset] cla[st] clo[se] cle[arjumps] cn[ext] cnew[er] cnf[ile] col[der] colo[rscheme] com[mand] comc[lear] comp[iler] con[tinue] conf[irm] cons[t] cope[n] cp[revious] cpf[ile] nextgroup=vimBang
38-
syn keyword vimCommand contained cq[uit] cr[ewind] cs[cope] cst[ag] cw[indow] delm[arks] deb[ug] defc[ompile] di[splay] dif[fupdate] diffg[et] diffo[ff] diffp[atch] diffpu[t] diffs[plit] difft[his] dig[raphs] disa[ssemble] dj[ump] dli[st] dr[op] ds[earch] dsp[lit] e[dit] ea[rlier] em[enu] endfo[r] endt[ry] endw[hile] ene[w] ex exi[t] exu[sage] f[ile] files fin[d] fina[lly] fini[sh] fir[st] fix[del] fo[ld] foldc[lose] foldd[oopen] folddoc[losed] foldo[pen] g[lobal] go[to] gu[i] gv[im] h[elp] helpc[lose] helpf[ind] helpt[ags] ha[rdcopy] hi[ghlight] his[tory] ij[ump] il[ist] int[ro] ip[ut] is[earch] isp[lit] ju[mps] l[ist] lN[ext] lNf[ile] la[st] lab[ove] lan[guage] lad[dexpr] laddb[uffer] laddf[ile] laf[ter] lat[er] lb[uffer] lbe[fore] lbel[ow] lbo[ttom] lc[d] lch[dir] nextgroup=vimBang
37+
syn keyword vimCommand contained al[l] ar[gs] arga[dd] argd[elete] argdo argded[upe] arge[dit] argg[lobal] argl[ocal] argu[ment] as[cii] b[uffer] bN[ext] ba[ll] bad[d] balt bd[elete] bf[irst] bl[ast] bm[odified] bn[ext] bp[revious] br[ewind] brea[k] breaka[dd] breakd[el] breakl[ist] bro[wse] buffers bufd[o] bun[load] bw[ipeout] c[hange] cN[ext] cNf[ile] cabo[ve] cad[dbuffer] cadde[xpr] caddf[ile] caf[ter] cb[uffer] cbe[fore] cbel[ow] cbo[ttom] cc ccl[ose] cd cdo ce[nter] cex[pr] cf[ile] cfd[o] cfir[st] cg[etfile] cgetb[uffer] cgete[xpr] changes che[ckpath] checkt[ime] chi[story] cl[ist] clip[reset] cla[st] clo[se] cle[arjumps] cn[ext] cnew[er] cnf[ile] col[der] colo[rscheme] comc[lear] comp[iler] con[tinue] conf[irm] cons[t] cope[n] cp[revious] cpf[ile] cq[uit] nextgroup=vimBang
38+
syn keyword vimCommand contained cr[ewind] cs[cope] cst[ag] cw[indow] delm[arks] deb[ug] defc[ompile] di[splay] dif[fupdate] diffg[et] diffo[ff] diffp[atch] diffpu[t] diffs[plit] difft[his] dig[raphs] disa[ssemble] dj[ump] dli[st] dr[op] ds[earch] dsp[lit] e[dit] ea[rlier] em[enu] endfo[r] endt[ry] endw[hile] ene[w] ex exi[t] exu[sage] f[ile] files fin[d] fina[lly] fini[sh] fir[st] fix[del] fo[ld] foldc[lose] foldd[oopen] folddoc[losed] foldo[pen] g[lobal] go[to] gu[i] gv[im] h[elp] helpc[lose] helpf[ind] helpt[ags] ha[rdcopy] hi[ghlight] his[tory] ij[ump] il[ist] int[ro] ip[ut] is[earch] isp[lit] ju[mps] l[ist] lN[ext] lNf[ile] la[st] lab[ove] lan[guage] lad[dexpr] laddb[uffer] laddf[ile] laf[ter] lat[er] lb[uffer] lbe[fore] lbel[ow] lbo[ttom] lc[d] lch[dir] nextgroup=vimBang
3939
syn keyword vimCommand contained lcl[ose] lcs[cope] ld[o] le[ft] lex[pr] lf[ile] lfd[o] lfir[st] lg[etfile] lgetb[uffer] lgete[xpr] lgr[ep] lgrepa[dd] lhi[story] ll lla[st] lli[st] lmak[e] lne[xt] lnew[er] lnf[ile] lo[adview] lockv[ar] lol[der] lop[en] lp[revious] lpf[ile] lr[ewind] lt[ag] lw[indow] ls m[ove] marks menut[ranslate] mes[sages] mk[exrc] mks[ession] mksp[ell] mkv[imrc] mkvie[w] mod[e] n[ext] nb[key] nbc[lose] nbs[tart] noh[lsearch] nu[mber] o[pen] ol[dfiles] on[ly] opt[ions] ow[nsyntax] p[rint] pa[ckadd] packl[oadall] pb[uffer] pc[lose] ped[it] po[p] pp[op] pre[serve] prev[ious] pro[mptfind] promptr[epl] ps[earch] pt[ag] ptN[ext] ptf[irst] ptj[ump] ptl[ast] ptn[ext] ptp[revious] ptr[ewind] pts[elect] pu[t] pw[d] q[uit] quita[ll] qa[ll] r[ead] rec[over] nextgroup=vimBang
4040
syn keyword vimCommand contained red[o] redr[aw] redraws[tatus] redrawt[abline] redrawtabp[anel] reg[isters] res[ize] ret[ab] rew[ind] ri[ght] ru[ntime] rub[y] rubyd[o] rubyf[ile] rund[o] rv[iminfo] sN[ext] sa[rgument] sal[l] sav[eas] sb[uffer] sbN[ext] sba[ll] sbf[irst] sbl[ast] sbm[odified] sbn[ext] sbp[revious] sbr[ewind] scr[iptnames] scripte[ncoding] scriptv[ersion] scs[cope] setf[iletype] sf[ind] sfir[st] sh[ell] sim[alt] sig[n] sla[st] sn[ext] so[urce] spe[llgood] spelld[ump] spelli[nfo] spellr[epall] spellra[re] spellu[ndo] spellw[rong] spr[evious] sre[wind] st[op] sta[g] star[tinsert] startg[replace] startr[eplace] stopi[nsert] stj[ump] sts[elect] sun[hide] sus[pend] sv[iew] synti[me] sync[bind] smi[le] t tN[ext] ta[g] tags tabc[lose] tabd[o] tabe[dit] nextgroup=vimBang
4141
syn keyword vimCommand contained tabf[ind] tabfir[st] tabm[ove] tabl[ast] tabn[ext] tabnew tabo[nly] tabp[revious] tabN[ext] tabr[ewind] tabs tc[d] tch[dir] te[aroff] tf[irst] tj[ump] tl[ast] tn[ext] tp[revious] tr[ewind] try ts[elect] u[ndo] undoj[oin] undol[ist] unh[ide] unlo[ckvar] up[date] v[global] ve[rsion] vi[sual] vie[w] viu[sage] vne[w] vs[plit] w[rite] wN[ext] wa[ll] wi[nsize] wind[o] winp[os] wl[restore] wn[ext] wp[revious] wq wqa[ll] wu[ndo] wv[iminfo] x[it] xa[ll] xr[estore] y[ank] z dl dell delel deletl deletel dp dep delp delep deletp deletep a i nextgroup=vimBang
@@ -146,8 +146,8 @@ syn keyword vimGroup contained Added Bold BoldItalic Boolean Changed Character C
146146

147147
" Default highlighting groups {{{2
148148
" GEN_SYN_VIM: vimHLGroup, START_STR='syn keyword vimHLGroup contained', END_STR=''
149-
syn keyword vimHLGroup contained ErrorMsg IncSearch ModeMsg NonText StatusLine StatusLineNC EndOfBuffer VertSplit VisualNOS DiffText DiffTextAdd PmenuSbar TabLineSel TabLineFill TabPanel TabPanelSel TabPanelFill Cursor lCursor QuickFixLine CursorLineSign CursorLineFold CurSearch PmenuKind PmenuKindSel PmenuMatch PmenuMatchSel PmenuExtra PmenuExtraSel PopupSelected MessageWindow PopupNotification PreInsert Normal Directory LineNr CursorLineNr MoreMsg Question Search SpellBad SpellCap SpellRare SpellLocal PmenuThumb Pmenu PmenuSel SpecialKey Title WarningMsg WildMenu Folded FoldColumn SignColumn Visual DiffAdd DiffChange DiffDelete TabLine CursorColumn CursorLine ColorColumn MatchParen StatusLineTerm StatusLineTermNC ToolbarLine ToolbarButton Menu Tooltip Scrollbar
150-
syn keyword vimHLGroup contained CursorIM ComplMatchIns LineNrAbove LineNrBelow MsgArea Terminal User1 User2 User3 User4 User5 User6 User7 User8 User9
149+
syn keyword vimHLGroup contained ErrorMsg IncSearch ModeMsg NonText StatusLine StatusLineNC EndOfBuffer VertSplit VisualNOS DiffText DiffTextAdd PmenuSbar TabLineSel TabLineFill TabPanel TabPanelSel TabPanelFill Cursor lCursor TitleBar TitleBarNC QuickFixLine CursorLineSign CursorLineFold CurSearch PmenuKind PmenuKindSel PmenuMatch PmenuMatchSel PmenuExtra PmenuExtraSel PopupSelected MessageWindow PopupNotification PreInsert Normal Directory LineNr CursorLineNr MoreMsg Question Search SpellBad SpellCap SpellRare SpellLocal PmenuThumb Pmenu PmenuSel SpecialKey Title WarningMsg WildMenu Folded FoldColumn SignColumn Visual DiffAdd DiffChange DiffDelete TabLine CursorColumn CursorLine ColorColumn MatchParen StatusLineTerm StatusLineTermNC ToolbarLine ToolbarButton
150+
syn keyword vimHLGroup contained TitleBar TitleBarNC Menu Tooltip Scrollbar CursorIM ComplMatchIns LineNrAbove LineNrBelow MsgArea Terminal User1 User2 User3 User4 User5 User6 User7 User8 User9
151151
syn match vimHLGroup contained "\<Conceal\>"
152152
syn case match
153153

@@ -1368,7 +1368,7 @@ syn region vimEval
13681368
\ end="\ze|"
13691369
\ excludenl end="$"
13701370
\ nextgroup=vimCmdSep
1371-
\ contains=@vimContinue,@vimExprList,vimComment,vim9Comment
1371+
\ contains=@vimContinue,@vimExprList,vim9Comment
13721372
\ transparent
13731373

13741374
" Filter: {{{2

src/gui.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,6 +3491,10 @@ gui_init_which_components(char_u *oldval UNUSED)
34913491
#ifdef FEAT_GUI_TABLINE
34923492
int using_tabline;
34933493
#endif
3494+
#ifdef FEAT_GUI_MSWIN
3495+
static int prev_titlebar = -1;
3496+
int using_titlebar = FALSE;
3497+
#endif
34943498
#if defined(FEAT_MENU)
34953499
static int prev_tearoff = -1;
34963500
int using_tearoff = FALSE;
@@ -3560,6 +3564,11 @@ gui_init_which_components(char_u *oldval UNUSED)
35603564
case GO_GREY:
35613565
// make menu's have grey items, ignored here
35623566
break;
3567+
#ifdef FEAT_GUI_MSWIN
3568+
case GO_TITLEBAR:
3569+
using_titlebar = TRUE;
3570+
break;
3571+
#endif
35633572
#ifdef FEAT_TOOLBAR
35643573
case GO_TOOLBAR:
35653574
using_toolbar = TRUE;
@@ -3581,6 +3590,14 @@ gui_init_which_components(char_u *oldval UNUSED)
35813590
need_set_size = 0;
35823591
fix_size = FALSE;
35833592

3593+
#ifdef FEAT_GUI_MSWIN
3594+
if (using_titlebar != prev_titlebar)
3595+
{
3596+
gui_mch_set_titlebar_colors();
3597+
prev_titlebar = using_titlebar;
3598+
}
3599+
#endif
3600+
35843601
#ifdef FEAT_GUI_DARKTHEME
35853602
if (using_dark_theme != prev_dark_theme)
35863603
{
@@ -4751,6 +4768,10 @@ gui_focus_change(int in_focus)
47514768
gui.in_focus = in_focus;
47524769
out_flush_cursor(TRUE, FALSE);
47534770

4771+
# ifdef FEAT_GUI_MSWIN
4772+
gui_mch_set_titlebar_colors();
4773+
# endif
4774+
47544775
# ifdef FEAT_XIM
47554776
xim_set_focus(in_focus);
47564777
# endif

src/gui.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,11 @@ typedef struct Gui
422422
guicolor_T currFgColor; // Current foreground text color
423423
guicolor_T currBgColor; // Current background text color
424424
guicolor_T currSpColor; // Current special text color
425+
426+
guicolor_T title_bg_pixel; // window title bar color
427+
guicolor_T title_fg_pixel; // window title bar's text color
428+
guicolor_T titlenc_bg_pixel; // window title bar color not current
429+
guicolor_T titlenc_fg_pixel; // window title bar's text color not current
425430
#endif
426431

427432
#ifdef FEAT_GUI_HAIKU

src/gui_w32.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,14 @@ gui_mch_set_rendering_options(char_u *s)
318318
# define SPI_SETWHEELSCROLLCHARS 0x006D
319319
#endif
320320

321+
#ifndef DWMWA_CAPTION_COLOR
322+
# define DWMWA_CAPTION_COLOR 35
323+
#endif
324+
325+
#ifndef DWMWA_TEXT_COLOR
326+
# define DWMWA_TEXT_COLOR 36
327+
#endif
328+
321329
#ifdef PROTO
322330
/*
323331
* Define a few things for generating prototypes. This is just to avoid
@@ -468,6 +476,10 @@ static int (WINAPI *pGetSystemMetricsForDpi)(int, UINT) = NULL;
468476
static DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT dpiContext) = NULL;
469477
static DPI_AWARENESS (WINAPI *pGetAwarenessFromDpiAwarenessContext)(DPI_AWARENESS_CONTEXT) = NULL;
470478

479+
static HINSTANCE hLibDwm = NULL;
480+
static HRESULT (WINAPI *pDwmSetWindowAttribute)(HWND, DWORD, LPCVOID, DWORD);
481+
static void dyn_dwm_load(void);
482+
471483
static int WINAPI
472484
stubGetSystemMetricsForDpi(int nIndex, UINT dpi UNUSED)
473485
{
@@ -1591,6 +1603,67 @@ _TextAreaWndProc(
15911603
}
15921604
}
15931605

1606+
static void
1607+
dyn_dwm_load(void)
1608+
{
1609+
hLibDwm = vimLoadLib("dwmapi.dll");
1610+
if (hLibDwm == NULL)
1611+
return;
1612+
1613+
pDwmSetWindowAttribute = (HRESULT (WINAPI *)(HWND, DWORD, LPCVOID, DWORD))
1614+
GetProcAddress(hLibDwm, "DwmSetWindowAttribute");
1615+
1616+
if (pDwmSetWindowAttribute == NULL)
1617+
{
1618+
FreeLibrary(hLibDwm);
1619+
hLibDwm = NULL;
1620+
return;
1621+
}
1622+
}
1623+
1624+
extern BOOL win11_or_later; // this is in os_win32.c
1625+
1626+
/*
1627+
* Set TitleBar's color. Handle hl-TitleBar and hl-TitleBarNC.
1628+
*
1629+
* Only enabled when 'guioptions' has 'C'.
1630+
* if "TitleBar guibg=NONE guifg=NONE" reset the window back to using the
1631+
* system's default behavior for the border color.
1632+
*/
1633+
void
1634+
gui_mch_set_titlebar_colors(void)
1635+
{
1636+
if (pDwmSetWindowAttribute == NULL || !win11_or_later)
1637+
return;
1638+
1639+
guicolor_T captionColor = 0xFFFFFFFF;
1640+
guicolor_T textColor = 0xFFFFFFFF;
1641+
1642+
if (vim_strchr(p_go, GO_TITLEBAR) != NULL)
1643+
{
1644+
if (gui.in_focus)
1645+
{
1646+
captionColor = gui.title_bg_pixel;
1647+
textColor = gui.title_fg_pixel;
1648+
}
1649+
else
1650+
{
1651+
captionColor = gui.titlenc_bg_pixel;
1652+
textColor = gui.titlenc_fg_pixel;
1653+
}
1654+
1655+
if (captionColor == INVALCOLOR)
1656+
captionColor = 0xFFFFFFFF;
1657+
if (textColor == INVALCOLOR)
1658+
textColor = 0xFFFFFFFF;
1659+
}
1660+
1661+
pDwmSetWindowAttribute(s_hwnd, DWMWA_CAPTION_COLOR,
1662+
&captionColor, sizeof(captionColor));
1663+
pDwmSetWindowAttribute(s_hwnd, DWMWA_TEXT_COLOR,
1664+
&textColor, sizeof(textColor));
1665+
}
1666+
15941667
/*
15951668
* Called when the foreground or background color has been changed.
15961669
*/
@@ -5636,6 +5709,8 @@ gui_mch_init(void)
56365709

56375710
load_dpi_func();
56385711

5712+
dyn_dwm_load();
5713+
56395714
s_dpi = pGetDpiForSystem();
56405715
update_scrollbar_size();
56415716

0 commit comments

Comments
 (0)