Skip to content

Commit d4bd851

Browse files
committed
lstopo/windows: no need for a faketoplevel
Use the same window for computing the size and actually displaying the output. We resize it before actually showing it. By the way, it prevents from having to avoid the WM_DESTROY of the fake window kill the program. Signed-off-by: Brice Goglin <[email protected]>
1 parent b1b2658 commit d4bd851

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

utils/lstopo/lstopo-windows.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
301301
}
302302
break;
303303
case WM_DESTROY:
304-
/* only kill the program if closing the actual toplevel, not the fake one */
305-
if (hwnd == the_output.toplevel)
306-
PostQuitMessage(0);
304+
PostQuitMessage(0);
307305
return 0;
308306
case WM_SIZE: {
309307
win_width = LOWORD(lparam);
@@ -414,7 +412,7 @@ int
414412
output_windows (struct lstopo_output *loutput, const char *dummy __hwloc_attribute_unused)
415413
{
416414
WNDCLASS wndclass;
417-
HWND toplevel, faketoplevel;
415+
HWND toplevel;
418416
unsigned width, height;
419417
HFONT font;
420418
MSG msg;
@@ -425,9 +423,6 @@ output_windows (struct lstopo_output *loutput, const char *dummy __hwloc_attribu
425423
loutput->methods = &windows_draw_methods;
426424
loutput->backend_data = &the_output;
427425

428-
/* make sure WM_DESTROY on the faketoplevel won't kill the program */
429-
the_output.toplevel = NULL;
430-
431426
/* create the toplevel window, with random size for now */
432427
memset(&wndclass, 0, sizeof(wndclass));
433428
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
@@ -440,16 +435,15 @@ output_windows (struct lstopo_output *loutput, const char *dummy __hwloc_attribu
440435

441436
/* recurse once for preparing sizes and positions using a fake top level window */
442437
loutput->drawing = LSTOPO_DRAWING_PREPARE;
443-
faketoplevel = CreateWindow("lstopo", loutput->title, WS_OVERLAPPEDWINDOW,
438+
toplevel = CreateWindow("lstopo", loutput->title, WS_OVERLAPPEDWINDOW,
444439
CW_USEDEFAULT, CW_USEDEFAULT,
445440
10, 10, NULL, NULL, NULL, NULL);
446-
BeginPaint(faketoplevel, &the_output.ps);
441+
BeginPaint(toplevel, &the_output.ps);
447442
font = CreateFont(loutput->fontsize, 0, 0, 0, 0, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, NULL);
448443
SelectObject(the_output.ps.hdc, (HGDIOBJ) font);
449444
output_draw(loutput);
450445
DeleteObject(font);
451-
EndPaint(faketoplevel, &the_output.ps);
452-
DestroyWindow(faketoplevel);
446+
EndPaint(toplevel, &the_output.ps);
453447
loutput->drawing = LSTOPO_DRAWING_DRAW;
454448

455449
/* now create the actual toplevel with the sizes */
@@ -471,10 +465,9 @@ output_windows (struct lstopo_output *loutput, const char *dummy __hwloc_attribu
471465
if (win_height > GetSystemMetrics(SM_CYFULLSCREEN))
472466
win_height = GetSystemMetrics(SM_CYFULLSCREEN);
473467

474-
toplevel = CreateWindow("lstopo", loutput->title, WS_OVERLAPPEDWINDOW,
475-
CW_USEDEFAULT, CW_USEDEFAULT,
476-
win_width, win_height, NULL, NULL, NULL, NULL);
477-
the_output.toplevel = toplevel;
468+
ignore_wm_size = 1;
469+
SetWindowPos(toplevel, HWND_TOP, 0, 0, win_width, win_height, SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER);
470+
ignore_wm_size = 0;
478471

479472
the_width = width;
480473
the_height = height;
@@ -488,16 +481,15 @@ output_windows (struct lstopo_output *loutput, const char *dummy __hwloc_attribu
488481
needs_resize = 0;
489482
ignore_wm_size = 0;
490483

491-
/* and display the window */
492-
ShowWindow(toplevel, SW_SHOWDEFAULT);
493-
494-
lstopo_show_interactive_help();
495-
496484
/* ready */
497485
declare_colors(loutput);
498486
lstopo_prepare_custom_styles(loutput);
499487

500-
UpdateWindow(the_output.toplevel);
488+
lstopo_show_interactive_help();
489+
the_output.toplevel = toplevel;
490+
ShowWindow(toplevel, SW_SHOWDEFAULT);
491+
UpdateWindow(toplevel);
492+
501493
while (!finish && GetMessage(&msg, NULL, 0, 0)) {
502494
TranslateMessage(&msg);
503495
DispatchMessage(&msg);

0 commit comments

Comments
 (0)