• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Révision4482dd5f886952d16cb9a018a3319245b55e22fb (tree)
l'heure2022-01-16 23:30:04
AuteurBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Message de Log

patch 8.2.4109: MS-Windows: high dpi support is outdated

Commit: https://github.com/vim/vim/commit/c81e9bf4f07d350b860b934aa6bf0c2a7c91d07e
Author: K.Takata <kentkt@csc.jp>
Date: Sun Jan 16 14:15:49 2022 +0000

patch 8.2.4109: MS-Windows: high dpi support is outdated
Problem: MS-Windows: high dpi support is outdated.
Solution: Improve High DPI support by using PerMonitorV2. (closes https://github.com/vim/vim/issues/9525,
closes #3102)

Change Summary

Modification

diff -r d0a330b84595 -r 4482dd5f8869 src/gui.c
--- a/src/gui.c Sun Jan 16 15:00:05 2022 +0100
+++ b/src/gui.c Sun Jan 16 15:30:04 2022 +0100
@@ -1433,10 +1433,6 @@
14331433 if (gui.menu_is_active)
14341434 text_area_y += gui.menu_height;
14351435 #endif
1436-#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_MSWIN)
1437- if (vim_strchr(p_go, GO_TOOLBAR) != NULL)
1438- text_area_y = TOOLBAR_BUTTON_HEIGHT + TOOLBAR_BORDER_HEIGHT;
1439-#endif
14401436
14411437 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \
14421438 || defined(FEAT_GUI_MOTIF))
@@ -1445,7 +1441,7 @@
14451441 #endif
14461442
14471443 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) \
1448- || defined(FEAT_GUI_HAIKU))
1444+ || defined(FEAT_GUI_HAIKU) || defined(FEAT_GUI_MSWIN))
14491445 if (vim_strchr(p_go, GO_TOOLBAR) != NULL)
14501446 {
14511447 # if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_HAIKU)
@@ -1529,11 +1525,7 @@
15291525 # endif
15301526 # ifdef FEAT_TOOLBAR
15311527 if (vim_strchr(p_go, GO_TOOLBAR) != NULL)
1532-# if defined(FEAT_GUI_MSWIN) && defined(FEAT_TOOLBAR)
1533- base_height += (TOOLBAR_BUTTON_HEIGHT + TOOLBAR_BORDER_HEIGHT);
1534-# else
15351528 base_height += gui.toolbar_height;
1536-# endif
15371529 # endif
15381530 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \
15391531 || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_HAIKU))
@@ -4342,13 +4334,7 @@
43424334 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_ATHENA) \
43434335 || defined(FEAT_GUI_HAIKU))
43444336 if (vim_strchr(p_go, GO_TOOLBAR) != NULL)
4345-# if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_HAIKU)
43464337 y += gui.toolbar_height;
4347-# else
4348-# ifdef FEAT_GUI_MSWIN
4349- y += TOOLBAR_BUTTON_HEIGHT + TOOLBAR_BORDER_HEIGHT;
4350-# endif
4351-# endif
43524338 #endif
43534339
43544340 #if defined(FEAT_GUI_TABLINE) && defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_HAIKU)
diff -r d0a330b84595 -r 4482dd5f8869 src/gui.h
--- a/src/gui.h Sun Jan 16 15:00:05 2022 +0100
+++ b/src/gui.h Sun Jan 16 15:30:04 2022 +0100
@@ -424,7 +424,7 @@
424424 #endif
425425
426426 #if defined(FEAT_TOOLBAR) \
427- && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_HAIKU))
427+ && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_HAIKU) || defined(FEAT_GUI_MSWIN))
428428 int toolbar_height; // height of the toolbar
429429 #endif
430430
diff -r d0a330b84595 -r 4482dd5f8869 src/gui_w32.c
--- a/src/gui_w32.c Sun Jan 16 15:00:05 2022 +0100
+++ b/src/gui_w32.c Sun Jan 16 15:30:04 2022 +0100
@@ -40,6 +40,8 @@
4040
4141 #ifdef FEAT_MENU
4242 static int gui_mswin_get_menu_height(int fix_window);
43+#else
44+# define gui_mswin_get_menu_height(fix_window) 0
4345 #endif
4446
4547 #if defined(FEAT_RENDER_OPTIONS) || defined(PROTO)
@@ -230,6 +232,10 @@
230232 # define MK_XBUTTON2 0x0040
231233 #endif
232234
235+#ifndef WM_DPICHANGED
236+# define WM_DPICHANGED 0x02E0
237+#endif
238+
233239 #ifdef PROTO
234240 /*
235241 * Define a few things for generating prototypes. This is just to avoid
@@ -314,7 +320,7 @@
314320 static int destroying = FALSE; // call DestroyWindow() ourselves
315321
316322 #ifdef MSWIN_FIND_REPLACE
317-static UINT s_findrep_msg = 0; // set in gui_w[16/32].c
323+static UINT s_findrep_msg = 0;
318324 static FINDREPLACEW s_findrep_struct;
319325 static HWND s_findrep_hwnd = NULL;
320326 static int s_findrep_is_find; // TRUE for find dialog, FALSE
@@ -358,6 +364,63 @@
358364 # define MyTranslateMessage(x) TranslateMessage(x)
359365 #endif
360366
367+#ifndef _DPI_AWARENESS_CONTEXTS_
368+typedef HANDLE DPI_AWARENESS_CONTEXT;
369+
370+typedef enum DPI_AWARENESS {
371+ DPI_AWARENESS_INVALID = -1,
372+ DPI_AWARENESS_UNAWARE = 0,
373+ DPI_AWARENESS_SYSTEM_AWARE = 1,
374+ DPI_AWARENESS_PER_MONITOR_AWARE = 2
375+} DPI_AWARENESS;
376+
377+# define DPI_AWARENESS_CONTEXT_UNAWARE ((DPI_AWARENESS_CONTEXT)-1)
378+# define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ((DPI_AWARENESS_CONTEXT)-2)
379+# define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ((DPI_AWARENESS_CONTEXT)-3)
380+# define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((DPI_AWARENESS_CONTEXT)-4)
381+# define DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED ((DPI_AWARENESS_CONTEXT)-5)
382+#endif
383+
384+#define DEFAULT_DPI 96
385+static int s_dpi = DEFAULT_DPI;
386+static BOOL s_in_dpichanged = FALSE;
387+static DPI_AWARENESS s_process_dpi_aware = DPI_AWARENESS_INVALID;
388+
389+static UINT (WINAPI *pGetDpiForSystem)(void) = NULL;
390+static UINT (WINAPI *pGetDpiForWindow)(HWND hwnd) = NULL;
391+static int (WINAPI *pGetSystemMetricsForDpi)(int, UINT) = NULL;
392+//static INT (WINAPI *pGetWindowDpiAwarenessContext)(HWND hwnd) = NULL;
393+static DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT dpiContext) = NULL;
394+static DPI_AWARENESS (WINAPI *pGetAwarenessFromDpiAwarenessContext)(DPI_AWARENESS_CONTEXT) = NULL;
395+
396+ static UINT WINAPI
397+stubGetDpiForSystem(void)
398+{
399+ HWND hwnd = GetDesktopWindow();
400+ HDC hdc = GetWindowDC(hwnd);
401+ UINT dpi = GetDeviceCaps(hdc, LOGPIXELSY);
402+ ReleaseDC(hwnd, hdc);
403+ return dpi;
404+}
405+
406+ static int WINAPI
407+stubGetSystemMetricsForDpi(int nIndex, UINT dpi)
408+{
409+ return GetSystemMetrics(nIndex);
410+}
411+
412+ static int
413+adjust_fontsize_by_dpi(int size)
414+{
415+ return size * s_dpi / (int)pGetDpiForSystem();
416+}
417+
418+ static int
419+adjust_by_system_dpi(int size)
420+{
421+ return size * (int)pGetDpiForSystem() / DEFAULT_DPI;
422+}
423+
361424 #if defined(FEAT_DIRECTX)
362425 static int
363426 directx_enabled(void)
@@ -1348,7 +1411,7 @@
13481411 #ifdef FEAT_TOOLBAR
13491412 if (vim_strchr(p_go, GO_TOOLBAR) != NULL)
13501413 SendMessage(s_toolbarhwnd, WM_SIZE,
1351- (WPARAM)0, (LPARAM)(w + ((long)(TOOLBAR_BUTTON_HEIGHT+8)<<16)));
1414+ (WPARAM)0, MAKELPARAM(w, gui.toolbar_height));
13521415 #endif
13531416 #if defined(FEAT_GUI_TABLINE)
13541417 if (showing_tabline)
@@ -1358,7 +1421,7 @@
13581421
13591422 # ifdef FEAT_TOOLBAR
13601423 if (vim_strchr(p_go, GO_TOOLBAR) != NULL)
1361- top = TOOLBAR_BUTTON_HEIGHT + TOOLBAR_BORDER_HEIGHT;
1424+ top = gui.toolbar_height;
13621425 # endif
13631426 GetClientRect(s_hwnd, &rect);
13641427 MoveWindow(s_tabhwnd, 0, top, rect.right, gui.tabline_height, TRUE);
@@ -1414,8 +1477,8 @@
14141477 GetWindowRect(s_textArea, &rcTxt);
14151478 GetWindowRect(s_hwnd, &rcWnd);
14161479 xpad = rcWnd.right - rcTxt.right - gui.scrollbar_width
1417- - GetSystemMetrics(SM_CXFRAME)
1418- - GetSystemMetrics(SM_CXPADDEDBORDER);
1480+ - pGetSystemMetricsForDpi(SM_CXFRAME, s_dpi)
1481+ - pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, s_dpi);
14191482 return (xpad < 0) ? 0 : xpad;
14201483 }
14211484
@@ -1428,8 +1491,8 @@
14281491 GetWindowRect(s_textArea, &rcTxt);
14291492 GetWindowRect(s_hwnd, &rcWnd);
14301493 ypad = rcWnd.bottom - rcTxt.bottom - gui.scrollbar_height
1431- - GetSystemMetrics(SM_CYFRAME)
1432- - GetSystemMetrics(SM_CXPADDEDBORDER);
1494+ - pGetSystemMetricsForDpi(SM_CYFRAME, s_dpi)
1495+ - pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, s_dpi);
14331496 return (ypad < 0) ? 0 : ypad;
14341497 }
14351498
@@ -1467,6 +1530,13 @@
14671530 return NULL;
14681531 }
14691532
1533+ static void
1534+update_scrollbar_size(void)
1535+{
1536+ gui.scrollbar_width = pGetSystemMetricsForDpi(SM_CXVSCROLL, s_dpi);
1537+ gui.scrollbar_height = pGetSystemMetricsForDpi(SM_CYHSCROLL, s_dpi);
1538+}
1539+
14701540 /*
14711541 * Get the character size of a font.
14721542 */
@@ -1545,7 +1615,10 @@
15451615 GuiFont font = NOFONT;
15461616
15471617 if (get_logfont(&lf, name, NULL, giveErrorIfMissing) == OK)
1618+ {
1619+ lf.lfHeight = adjust_fontsize_by_dpi(lf.lfHeight);
15481620 font = get_font_handle(&lf);
1621+ }
15491622 if (font == NOFONT && giveErrorIfMissing)
15501623 semsg(_(e_unknown_font_str), name);
15511624 return font;
@@ -2858,14 +2931,12 @@
28582931 int cx,
28592932 int cy)
28602933 {
2861- if (!IsMinimized(hwnd))
2934+ if (!IsMinimized(hwnd) && !s_in_dpichanged)
28622935 {
28632936 gui_resize_shell(cx, cy);
28642937
2865-#ifdef FEAT_MENU
28662938 // Menu bar may wrap differently now
28672939 gui_mswin_get_menu_height(TRUE);
2868-#endif
28692940 }
28702941 }
28712942
@@ -2949,16 +3020,13 @@
29493020 int base_width, base_height;
29503021
29513022 base_width = gui_get_base_width()
2952- + (GetSystemMetrics(SM_CXFRAME) +
2953- GetSystemMetrics(SM_CXPADDEDBORDER)) * 2;
3023+ + (pGetSystemMetricsForDpi(SM_CXFRAME, s_dpi) +
3024+ pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, s_dpi)) * 2;
29543025 base_height = gui_get_base_height()
2955- + (GetSystemMetrics(SM_CYFRAME) +
2956- GetSystemMetrics(SM_CXPADDEDBORDER)) * 2
2957- + GetSystemMetrics(SM_CYCAPTION)
2958-#ifdef FEAT_MENU
2959- + gui_mswin_get_menu_height(FALSE)
2960-#endif
2961- ;
3026+ + (pGetSystemMetricsForDpi(SM_CYFRAME, s_dpi) +
3027+ pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, s_dpi)) * 2
3028+ + pGetSystemMetricsForDpi(SM_CYCAPTION, s_dpi)
3029+ + gui_mswin_get_menu_height(FALSE);
29623030 *cols = (w - base_width) / gui.char_width;
29633031 *rows = (h - base_height) / gui.char_height;
29643032 *valid_w = base_width + *cols * gui.char_width;
@@ -3245,12 +3313,12 @@
32453313 #ifdef FEAT_MBYTE_IME
32463314 /*
32473315 * Set correct LOGFONTW to IME. Use 'guifontwide' if available, otherwise use
3248- * 'guifont'
3316+ * 'guifont'.
32493317 */
32503318 static void
32513319 update_im_font(void)
32523320 {
3253- LOGFONTW lf_wide;
3321+ LOGFONTW lf_wide, lf;
32543322
32553323 if (p_guifontwide != NULL && *p_guifontwide != NUL
32563324 && gui.wide_font != NOFONT
@@ -3258,7 +3326,12 @@
32583326 norm_logfont = lf_wide;
32593327 else
32603328 norm_logfont = sub_logfont;
3261- im_set_font(&norm_logfont);
3329+
3330+ lf = norm_logfont;
3331+ if (s_process_dpi_aware == DPI_AWARENESS_UNAWARE)
3332+ // Work around when PerMonitorV2 is not enabled in the process level.
3333+ lf.lfHeight = lf.lfHeight * DEFAULT_DPI / s_dpi;
3334+ im_set_font(&lf);
32623335 }
32633336 #endif
32643337
@@ -3310,13 +3383,17 @@
33103383 int
33113384 gui_mch_init_font(char_u *font_name, int fontset UNUSED)
33123385 {
3313- LOGFONTW lf;
3386+ LOGFONTW lf, lfOrig;
33143387 GuiFont font = NOFONT;
33153388 char_u *p;
33163389
33173390 // Load the font
33183391 if (get_logfont(&lf, font_name, NULL, TRUE) == OK)
3392+ {
3393+ lfOrig = lf;
3394+ lf.lfHeight = adjust_fontsize_by_dpi(lf.lfHeight);
33193395 font = get_font_handle(&lf);
3396+ }
33203397 if (font == NOFONT)
33213398 return FAIL;
33223399
@@ -3329,20 +3406,20 @@
33293406 sub_logfont = lf;
33303407 #endif
33313408 #ifdef FEAT_MBYTE_IME
3332- update_im_font();
3409+ if (!s_in_dpichanged)
3410+ update_im_font();
33333411 #endif
33343412 gui_mch_free_font(gui.norm_font);
33353413 gui.norm_font = font;
3336- current_font_height = lf.lfHeight;
3414+ current_font_height = lfOrig.lfHeight;
33373415 GetFontSize(font);
33383416
3339- p = logfont2name(lf);
3417+ p = logfont2name(lfOrig);
33403418 if (p != NULL)
33413419 {
33423420 hl_set_font_name(p);
33433421
33443422 // When setting 'guifont' to "*" replace it with the actual font name.
3345- //
33463423 if (STRCMP(font_name, "*") == 0 && STRCMP(p_guifont, "*") == 0)
33473424 {
33483425 vim_free(p_guifont);
@@ -3428,26 +3505,19 @@
34283505 if (win_socket_id == 0)
34293506 {
34303507 gui_resize_shell(rect.right - rect.left
3431- - (GetSystemMetrics(SM_CXFRAME) +
3432- GetSystemMetrics(SM_CXPADDEDBORDER)) * 2,
3508+ - (pGetSystemMetricsForDpi(SM_CXFRAME, s_dpi) +
3509+ pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, s_dpi)) * 2,
34333510 rect.bottom - rect.top
3434- - (GetSystemMetrics(SM_CYFRAME) +
3435- GetSystemMetrics(SM_CXPADDEDBORDER)) * 2
3436- - GetSystemMetrics(SM_CYCAPTION)
3437-#ifdef FEAT_MENU
3438- - gui_mswin_get_menu_height(FALSE)
3439-#endif
3440- );
3511+ - (pGetSystemMetricsForDpi(SM_CYFRAME, s_dpi) +
3512+ pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, s_dpi)) * 2
3513+ - pGetSystemMetricsForDpi(SM_CYCAPTION, s_dpi)
3514+ - gui_mswin_get_menu_height(FALSE));
34413515 }
34423516 else
34433517 {
34443518 // Inside another window, don't use the frame and border.
34453519 gui_resize_shell(rect.right - rect.left,
3446- rect.bottom - rect.top
3447-#ifdef FEAT_MENU
3448- - gui_mswin_get_menu_height(FALSE)
3449-#endif
3450- );
3520+ rect.bottom - rect.top - gui_mswin_get_menu_height(FALSE));
34513521 }
34523522 }
34533523
@@ -4101,7 +4171,7 @@
41014171 #if defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE)
41024172 // Older MSVC compilers don't have LPNMTTDISPINFO[AW] thus we need to define
41034173 // it here if LPNMTTDISPINFO isn't defined.
4104-// MingW doesn't define LPNMTTDISPINFO but typedefs it. Thus we need to check
4174+// MinGW doesn't define LPNMTTDISPINFO but typedefs it. Thus we need to check
41054175 // _MSC_VER.
41064176 # if !defined(LPNMTTDISPINFO) && defined(_MSC_VER)
41074177 typedef struct tagNMTTDISPINFOA {
@@ -4178,8 +4248,11 @@
41784248 static int s_usenewlook; // emulate W95/NT4 non-bold dialogs
41794249 #ifdef FEAT_TOOLBAR
41804250 static void initialise_toolbar(void);
4251+static void update_toolbar_size(void);
41814252 static LRESULT CALLBACK toolbar_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
41824253 static int get_toolbar_bitmap(vimmenu_T *menu);
4254+#else
4255+# define update_toolbar_size()
41834256 #endif
41844257
41854258 #ifdef FEAT_GUI_TABLINE
@@ -4419,6 +4492,7 @@
44194492 if (gui_w32_get_menu_font(&lfSysmenu) != OK)
44204493 return;
44214494
4495+ lfSysmenu.lfHeight = adjust_fontsize_by_dpi(lfSysmenu.lfHeight);
44224496 font = CreateFontIndirectW(&lfSysmenu);
44234497
44244498 SendMessage(s_tabhwnd, WM_SETFONT, (WPARAM)font, TRUE);
@@ -4441,6 +4515,8 @@
44414515 */
44424516 gui.tabline_height = tm.tmHeight + tm.tmInternalLeading + 7;
44434517 }
4518+#else
4519+# define set_tabline_font()
44444520 #endif
44454521
44464522 /*
@@ -4452,10 +4528,8 @@
44524528 if (n == SPI_SETWHEELSCROLLLINES)
44534529 SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
44544530 &mouse_scroll_lines, 0);
4455-#if defined(FEAT_GUI_TABLINE) && defined(USE_SYSMENU_FONT)
44564531 if (n == SPI_SETNONCLIENTMETRICS)
44574532 set_tabline_font();
4458-#endif
44594533 return 0;
44604534 }
44614535
@@ -4556,6 +4630,28 @@
45564630 return TRUE;
45574631 }
45584632
4633+ static LRESULT
4634+_OnDpiChanged(HWND hwnd, UINT xdpi, UINT ydpi, RECT *rc)
4635+{
4636+ s_dpi = ydpi;
4637+ s_in_dpichanged = TRUE;
4638+ //TRACE("DPI: %d", ydpi);
4639+
4640+ update_scrollbar_size();
4641+ update_toolbar_size();
4642+ set_tabline_font();
4643+
4644+ gui_init_font(*p_guifont == NUL ? hl_get_font_name() : p_guifont, FALSE);
4645+ gui_get_wide_font();
4646+ gui_mswin_get_menu_height(FALSE);
4647+#ifdef FEAT_MBYTE_IME
4648+ im_set_position(gui.row, gui.col);
4649+#endif
4650+ InvalidateRect(hwnd, NULL, TRUE);
4651+
4652+ s_in_dpichanged = FALSE;
4653+ return 0L;
4654+}
45594655
45604656
45614657 static LRESULT CALLBACK
@@ -4916,6 +5012,9 @@
49165012 return MyWindowProc(hwnd, uMsg, wParam, lParam);
49175013 return 1L;
49185014 #endif
5015+ case WM_DPICHANGED:
5016+ return _OnDpiChanged(hwnd, (UINT)LOWORD(wParam), (UINT)HIWORD(wParam),
5017+ (RECT*)lParam);
49195018
49205019 default:
49215020 #ifdef MSWIN_FIND_REPLACE
@@ -5216,6 +5315,49 @@
52165315 #endif
52175316 }
52185317
5318+ static void
5319+load_dpi_func(void)
5320+{
5321+ HMODULE hUser32;
5322+
5323+ hUser32 = GetModuleHandle("user32.dll");
5324+ if (hUser32 == NULL)
5325+ goto fail;
5326+
5327+ pGetDpiForSystem = (void*)GetProcAddress(hUser32, "GetDpiForSystem");
5328+ pGetDpiForWindow = (void*)GetProcAddress(hUser32, "GetDpiForWindow");
5329+ pGetSystemMetricsForDpi = (void*)GetProcAddress(hUser32, "GetSystemMetricsForDpi");
5330+ //pGetWindowDpiAwarenessContext = (void*)GetProcAddress(hUser32, "GetWindowDpiAwarenessContext");
5331+ pSetThreadDpiAwarenessContext = (void*)GetProcAddress(hUser32, "SetThreadDpiAwarenessContext");
5332+ pGetAwarenessFromDpiAwarenessContext = (void*)GetProcAddress(hUser32, "GetAwarenessFromDpiAwarenessContext");
5333+
5334+ if (pSetThreadDpiAwarenessContext != NULL)
5335+ {
5336+ DPI_AWARENESS_CONTEXT oldctx = pSetThreadDpiAwarenessContext(
5337+ DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
5338+ if (oldctx != NULL)
5339+ {
5340+ TRACE("DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 enabled");
5341+ s_process_dpi_aware = pGetAwarenessFromDpiAwarenessContext(oldctx);
5342+#ifdef DEBUG
5343+ if (s_process_dpi_aware == DPI_AWARENESS_UNAWARE)
5344+ {
5345+ TRACE("WARNING: PerMonitorV2 is not enabled in the process level for some reasons. IME window may not shown correctly.");
5346+ }
5347+#endif
5348+ return;
5349+ }
5350+ }
5351+
5352+fail:
5353+ // Disable PerMonitorV2 APIs.
5354+ pGetDpiForSystem = stubGetDpiForSystem;
5355+ pGetDpiForWindow = NULL;
5356+ pGetSystemMetricsForDpi = stubGetSystemMetricsForDpi;
5357+ pSetThreadDpiAwarenessContext = NULL;
5358+ pGetAwarenessFromDpiAwarenessContext = NULL;
5359+}
5360+
52195361 /*
52205362 * Initialise the GUI. Create all the windows, set up all the call-backs
52215363 * etc.
@@ -5242,12 +5384,18 @@
52425384 s_htearbitmap = LoadBitmap(g_hinst, "IDB_TEAROFF");
52435385 #endif
52445386
5245- gui.scrollbar_width = GetSystemMetrics(SM_CXVSCROLL);
5246- gui.scrollbar_height = GetSystemMetrics(SM_CYHSCROLL);
5387+ load_dpi_func();
5388+
5389+ s_dpi = pGetDpiForSystem();
5390+ update_scrollbar_size();
5391+
52475392 #ifdef FEAT_MENU
52485393 gui.menu_height = 0; // Windows takes care of this
52495394 #endif
52505395 gui.border_width = 0;
5396+#ifdef FEAT_TOOLBAR
5397+ gui.toolbar_height = TOOLBAR_BUTTON_HEIGHT + TOOLBAR_BORDER_HEIGHT;
5398+#endif
52515399
52525400 s_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
52535401
@@ -5336,6 +5484,13 @@
53365484 if (s_hwnd == NULL)
53375485 return FAIL;
53385486
5487+ if (pGetDpiForWindow != NULL)
5488+ {
5489+ s_dpi = pGetDpiForWindow(s_hwnd);
5490+ update_scrollbar_size();
5491+ //TRACE("System DPI: %d, DPI: %d", pGetDpiForSystem(), s_dpi);
5492+ }
5493+
53395494 #ifdef GLOBAL_IME
53405495 global_ime_init(atom, s_hwnd);
53415496 #endif
@@ -5391,7 +5546,7 @@
53915546 DragAcceptFiles(s_hwnd, TRUE);
53925547
53935548 // Do we need to bother with this?
5394- // m_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT);
5549+ // m_fMouseAvail = pGetSystemMetricsForDpi(SM_MOUSEPRESENT, s_dpi);
53955550
53965551 // Get background/foreground colors from the system
53975552 gui_mch_def_colors();
@@ -5533,15 +5688,12 @@
55335688 GetWindowRect(s_hwnd, &window_rect);
55345689
55355690 // compute the size of the outside of the window
5536- win_width = width + (GetSystemMetrics(SM_CXFRAME) +
5537- GetSystemMetrics(SM_CXPADDEDBORDER)) * 2;
5538- win_height = height + (GetSystemMetrics(SM_CYFRAME) +
5539- GetSystemMetrics(SM_CXPADDEDBORDER)) * 2
5540- + GetSystemMetrics(SM_CYCAPTION)
5541-#ifdef FEAT_MENU
5542- + gui_mswin_get_menu_height(FALSE)
5543-#endif
5544- ;
5691+ win_width = width + (pGetSystemMetricsForDpi(SM_CXFRAME, s_dpi) +
5692+ pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, s_dpi)) * 2;
5693+ win_height = height + (pGetSystemMetricsForDpi(SM_CYFRAME, s_dpi) +
5694+ pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, s_dpi)) * 2
5695+ + pGetSystemMetricsForDpi(SM_CYCAPTION, s_dpi)
5696+ + gui_mswin_get_menu_height(FALSE);
55455697
55465698 // The following should take care of keeping Vim on the same monitor, no
55475699 // matter if the secondary monitor is left or right of the primary
@@ -5568,10 +5720,8 @@
55685720 SetActiveWindow(s_hwnd);
55695721 SetFocus(s_hwnd);
55705722
5571-#ifdef FEAT_MENU
55725723 // Menu may wrap differently now
55735724 gui_mswin_get_menu_height(!gui.starting);
5574-#endif
55755725 }
55765726
55775727
@@ -5669,7 +5819,11 @@
56695819 case IMN_SETOPENSTATUS:
56705820 if (pImmGetOpenStatus(hImc))
56715821 {
5672- pImmSetCompositionFontW(hImc, &norm_logfont);
5822+ LOGFONTW lf = norm_logfont;
5823+ if (s_process_dpi_aware == DPI_AWARENESS_UNAWARE)
5824+ // Work around when PerMonitorV2 is not enabled in the process level.
5825+ lf.lfHeight = lf.lfHeight * DEFAULT_DPI / s_dpi;
5826+ pImmSetCompositionFontW(hImc, &lf);
56735827 im_set_position(gui.row, gui.col);
56745828
56755829 // Disable langmap
@@ -5837,6 +5991,12 @@
58375991 cfs.ptCurrentPos.x = FILL_X(col);
58385992 cfs.ptCurrentPos.y = FILL_Y(row);
58395993 MapWindowPoints(s_textArea, s_hwnd, &cfs.ptCurrentPos, 1);
5994+ if (s_process_dpi_aware == DPI_AWARENESS_UNAWARE)
5995+ {
5996+ // Work around when PerMonitorV2 is not enabled in the process level.
5997+ cfs.ptCurrentPos.x = cfs.ptCurrentPos.x * DEFAULT_DPI / s_dpi;
5998+ cfs.ptCurrentPos.y = cfs.ptCurrentPos.y * DEFAULT_DPI / s_dpi;
5999+ }
58406000 pImmSetCompositionWindow(hImc, &cfs);
58416001
58426002 pImmReleaseContext(s_hwnd, hImc);
@@ -6438,20 +6598,17 @@
64386598 get_work_area(&workarea_rect);
64396599
64406600 *screen_w = workarea_rect.right - workarea_rect.left
6441- - (GetSystemMetrics(SM_CXFRAME) +
6442- GetSystemMetrics(SM_CXPADDEDBORDER)) * 2;
6601+ - (pGetSystemMetricsForDpi(SM_CXFRAME, s_dpi) +
6602+ pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, s_dpi)) * 2;
64436603
64446604 // FIXME: dirty trick: Because the gui_get_base_height() doesn't include
64456605 // the menubar for MSwin, we subtract it from the screen height, so that
64466606 // the window size can be made to fit on the screen.
64476607 *screen_h = workarea_rect.bottom - workarea_rect.top
6448- - (GetSystemMetrics(SM_CYFRAME) +
6449- GetSystemMetrics(SM_CXPADDEDBORDER)) * 2
6450- - GetSystemMetrics(SM_CYCAPTION)
6451-#ifdef FEAT_MENU
6452- - gui_mswin_get_menu_height(FALSE)
6453-#endif
6454- ;
6608+ - (pGetSystemMetricsForDpi(SM_CYFRAME, s_dpi) +
6609+ pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, s_dpi)) * 2
6610+ - pGetSystemMetricsForDpi(SM_CYCAPTION, s_dpi)
6611+ - gui_mswin_get_menu_height(FALSE);
64556612 }
64566613
64576614
@@ -6905,6 +7062,9 @@
69057062 # endif
69067063 garray_T ga;
69077064 int l;
7065+ int dlg_icon_width;
7066+ int dlg_icon_height;
7067+ int dpi;
69087068
69097069 # ifndef NO_CONSOLE
69107070 // Don't output anything in silent mode ("ex -s")
@@ -6916,7 +7076,13 @@
69167076 # endif
69177077
69187078 if (s_hwnd == NULL)
7079+ {
7080+ load_dpi_func();
7081+ s_dpi = dpi = pGetDpiForSystem();
69197082 get_dialog_font_metrics();
7083+ }
7084+ else
7085+ dpi = pGetDpiForSystem();
69207086
69217087 if ((type < 0) || (type > VIM_LAST_TYPE))
69227088 type = 0;
@@ -6974,7 +7140,7 @@
69747140 else
69757141 # endif
69767142 font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6977- VARIABLE_PITCH , DLG_FONT_NAME);
7143+ VARIABLE_PITCH, DLG_FONT_NAME);
69787144 if (s_usenewlook)
69797145 {
69807146 oldFont = SelectFont(hdc, font);
@@ -7001,8 +7167,8 @@
70017167 // We don't have a window, use the desktop area.
70027168 get_work_area(&workarea_rect);
70037169 maxDialogWidth = workarea_rect.right - workarea_rect.left - 100;
7004- if (maxDialogWidth > 600)
7005- maxDialogWidth = 600;
7170+ if (maxDialogWidth > adjust_by_system_dpi(600))
7171+ maxDialogWidth = adjust_by_system_dpi(600);
70067172 // Leave some room for the taskbar.
70077173 maxDialogHeight = workarea_rect.bottom - workarea_rect.top - 150;
70087174 }
@@ -7011,17 +7177,17 @@
70117177 // Use our own window for the size, unless it's very small.
70127178 GetWindowRect(s_hwnd, &rect);
70137179 maxDialogWidth = rect.right - rect.left
7014- - (GetSystemMetrics(SM_CXFRAME) +
7015- GetSystemMetrics(SM_CXPADDEDBORDER)) * 2;
7016- if (maxDialogWidth < DLG_MIN_MAX_WIDTH)
7017- maxDialogWidth = DLG_MIN_MAX_WIDTH;
7180+ - (pGetSystemMetricsForDpi(SM_CXFRAME, dpi) +
7181+ pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi)) * 2;
7182+ if (maxDialogWidth < adjust_by_system_dpi(DLG_MIN_MAX_WIDTH))
7183+ maxDialogWidth = adjust_by_system_dpi(DLG_MIN_MAX_WIDTH);
70187184
70197185 maxDialogHeight = rect.bottom - rect.top
7020- - (GetSystemMetrics(SM_CYFRAME) +
7021- GetSystemMetrics(SM_CXPADDEDBORDER)) * 4
7022- - GetSystemMetrics(SM_CYCAPTION);
7023- if (maxDialogHeight < DLG_MIN_MAX_HEIGHT)
7024- maxDialogHeight = DLG_MIN_MAX_HEIGHT;
7186+ - (pGetSystemMetricsForDpi(SM_CYFRAME, dpi) +
7187+ pGetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi)) * 4
7188+ - pGetSystemMetricsForDpi(SM_CYCAPTION, dpi);
7189+ if (maxDialogHeight < adjust_by_system_dpi(DLG_MIN_MAX_HEIGHT))
7190+ maxDialogHeight = adjust_by_system_dpi(DLG_MIN_MAX_HEIGHT);
70257191 }
70267192
70277193 // Set dlgwidth to width of message.
@@ -7057,7 +7223,8 @@
70577223 if (last_white != NULL)
70587224 {
70597225 // break the line just after a space
7060- ga.ga_len -= (int)(pend - (last_white + 1));
7226+ if (pend > last_white)
7227+ ga.ga_len -= (int)(pend - (last_white + 1));
70617228 pend = last_white + 1;
70627229 last_white = NULL;
70637230 }
@@ -7082,12 +7249,15 @@
70827249
70837250 messageWidth += 10; // roundoff space
70847251
7252+ dlg_icon_width = adjust_by_system_dpi(DLG_ICON_WIDTH);
7253+ dlg_icon_height = adjust_by_system_dpi(DLG_ICON_HEIGHT);
7254+
70857255 // Add width of icon to dlgwidth, and some space
7086- dlgwidth = messageWidth + DLG_ICON_WIDTH + 3 * dlgPaddingX
7087- + GetSystemMetrics(SM_CXVSCROLL);
7088-
7089- if (msgheight < DLG_ICON_HEIGHT)
7090- msgheight = DLG_ICON_HEIGHT;
7256+ dlgwidth = messageWidth + dlg_icon_width + 3 * dlgPaddingX
7257+ + pGetSystemMetricsForDpi(SM_CXVSCROLL, dpi);
7258+
7259+ if (msgheight < dlg_icon_height)
7260+ msgheight = dlg_icon_height;
70917261
70927262 /*
70937263 * Check button names. A long one will make the dialog wider.
@@ -7175,7 +7345,7 @@
71757345 dlgheight = maxDialogHeight;
71767346 scroll_flag = WS_VSCROLL;
71777347 // Make sure scrollbar doesn't appear in the middle of the dialog
7178- messageWidth = dlgwidth - DLG_ICON_WIDTH - 3 * dlgPaddingX;
7348+ messageWidth = dlgwidth - dlg_icon_width - 3 * dlgPaddingX;
71797349 }
71807350
71817351 add_word(PixelToDialogY(dlgheight));
@@ -7272,14 +7442,14 @@
72727442 p = add_dialog_element(p, SS_ICON,
72737443 PixelToDialogX(dlgPaddingX),
72747444 PixelToDialogY(dlgPaddingY),
7275- PixelToDialogX(DLG_ICON_WIDTH),
7276- PixelToDialogY(DLG_ICON_HEIGHT),
7445+ PixelToDialogX(dlg_icon_width),
7446+ PixelToDialogY(dlg_icon_height),
72777447 DLG_NONBUTTON_CONTROL + 0, (WORD)0x0082,
72787448 dlg_icons[type]);
72797449
72807450 // Dialog message
72817451 p = add_dialog_element(p, ES_LEFT|scroll_flag|ES_MULTILINE|ES_READONLY,
7282- PixelToDialogX(2 * dlgPaddingX + DLG_ICON_WIDTH),
7452+ PixelToDialogX(2 * dlgPaddingX + dlg_icon_width),
72837453 PixelToDialogY(dlgPaddingY),
72847454 (WORD)(PixelToDialogX(messageWidth) + 1),
72857455 PixelToDialogY(msgheight),
@@ -7573,7 +7743,7 @@
75737743 else
75747744 #endif
75757745 hfontTools = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0,
7576- 0, 0, 0, 0, VARIABLE_PITCH , DLG_FONT_NAME);
7746+ 0, 0, 0, 0, VARIABLE_PITCH, DLG_FONT_NAME);
75777747
75787748 if (hfontTools)
75797749 {
@@ -7679,7 +7849,7 @@
76797849 else
76807850 # endif
76817851 font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7682- VARIABLE_PITCH , DLG_FONT_NAME);
7852+ VARIABLE_PITCH, DLG_FONT_NAME);
76837853 if (s_usenewlook)
76847854 oldFont = SelectFont(hdc, font);
76857855 else
@@ -7978,6 +8148,33 @@
79788148 s_toolbar_wndproc = SubclassWindow(s_toolbarhwnd, toolbar_wndproc);
79798149
79808150 gui_mch_show_toolbar(vim_strchr(p_go, GO_TOOLBAR) != NULL);
8151+
8152+ update_toolbar_size();
8153+}
8154+
8155+ static void
8156+update_toolbar_size(void)
8157+{
8158+ int w, h;
8159+ TBMETRICS tbm = {sizeof(TBMETRICS)};
8160+
8161+ tbm.dwMask = TBMF_PAD | TBMF_BUTTONSPACING;
8162+ SendMessage(s_toolbarhwnd, TB_GETMETRICS, 0, (LPARAM)&tbm);
8163+ //TRACE("Pad: %d, %d", tbm.cxPad, tbm.cyPad);
8164+ //TRACE("ButtonSpacing: %d, %d", tbm.cxButtonSpacing, tbm.cyButtonSpacing);
8165+
8166+ w = (TOOLBAR_BUTTON_WIDTH + tbm.cxPad) * s_dpi / DEFAULT_DPI;
8167+ h = (TOOLBAR_BUTTON_HEIGHT + tbm.cyPad) * s_dpi / DEFAULT_DPI;
8168+ //TRACE("button size: %d, %d", w, h);
8169+ SendMessage(s_toolbarhwnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(w, h));
8170+ gui.toolbar_height = h + 6;
8171+
8172+ //DWORD s = SendMessage(s_toolbarhwnd, TB_GETBUTTONSIZE, 0, 0);
8173+ //TRACE("actual button size: %d, %d", LOWORD(s), HIWORD(s));
8174+
8175+ // TODO:
8176+ // Currently, this function only updates the size of toolbar buttons.
8177+ // It would be nice if the toolbar images are resized based on DPI.
79818178 }
79828179
79838180 static LRESULT CALLBACK
@@ -8071,9 +8268,7 @@
80718268
80728269 gui.tabline_height = TABLINE_HEIGHT;
80738270
8074-# ifdef USE_SYSMENU_FONT
80758271 set_tabline_font();
8076-# endif
80778272 }
80788273
80798274 /*
@@ -8090,7 +8285,7 @@
80908285 {
80918286 TCHITTESTINFO htinfo;
80928287 htinfo.pt = pt;
8093- // ignore if a window under cusor is not tabcontrol.
8288+ // ignore if a window under cursor is not tabcontrol.
80948289 if (s_tabhwnd == hWnd)
80958290 {
80968291 int idx = TabCtrl_HitTest(s_tabhwnd, &htinfo);
@@ -8136,7 +8331,8 @@
81368331 {
81378332 pt.x = GET_X_LPARAM(lParam);
81388333 pt.y = s_pt.y;
8139- if (abs(pt.x - s_pt.x) > GetSystemMetrics(SM_CXDRAG))
8334+ if (abs(pt.x - s_pt.x) >
8335+ pGetSystemMetricsForDpi(SM_CXDRAG, s_dpi))
81408336 {
81418337 SetCursor(LoadCursor(NULL, IDC_SIZEWE));
81428338
diff -r d0a330b84595 -r 4482dd5f8869 src/version.c
--- a/src/version.c Sun Jan 16 15:00:05 2022 +0100
+++ b/src/version.c Sun Jan 16 15:30:04 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4109,
755+/**/
754756 4108,
755757 /**/
756758 4107,
diff -r d0a330b84595 -r 4482dd5f8869 src/vim.manifest
--- a/src/vim.manifest Sun Jan 16 15:00:05 2022 +0100
+++ b/src/vim.manifest Sun Jan 16 15:30:04 2022 +0100
@@ -5,7 +5,7 @@
55 Do ":help uganda" in Vim to read copying and usage conditions.
66 Do ":help credits" in Vim to see a list of people who contributed.
77 -->
8-<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
8+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
99 <assemblyIdentity
1010 processorArchitecture="*"
1111 version="8.2.0.0"
@@ -37,8 +37,9 @@
3737 </trustInfo>
3838 <!-- Vista High DPI aware -->
3939 <asmv3:application>
40- <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
41- <dpiAware>true</dpiAware>
40+ <asmv3:windowsSettings>
41+ <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
42+ <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
4243 </asmv3:windowsSettings>
4344 </asmv3:application>
4445 <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
@@ -51,7 +52,7 @@
5152 <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
5253 <!--The ID below indicates application support for Windows 8.1 -->
5354 <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
54- <!--The ID below indicates application support for Windows 10 -->
55+ <!--The ID below indicates application support for Windows 10 and 11 -->
5556 <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
5657 </application>
5758 </compatibility>
Afficher sur ancien navigateur de dépôt.