Skip to content

Commit 5468925

Browse files
committed
lstopo/x11+windows: refresh the topology+binding when hitting F5 key
Closes #402 Signed-off-by: Brice Goglin <[email protected]>
1 parent 8027016 commit 5468925

File tree

7 files changed

+47
-19
lines changed

7 files changed

+47
-19
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Version 2.3.0
3030
+ Tools that have a --restrict option may now receive a nodeset or
3131
some custom flags for restricting the topology.
3232
+ Fix lstopo drawing when autoresizing on Windows 10.
33+
+ Pressing the F5 key in lstopo X11 and Windows graphical/interactive outputs
34+
now refreshes the display according to the current topology and binding.
3335
+ Add a tikz lstopo graphical backend to generate picture easily included into
3436
LaTeX documents.
3537

tests/hwloc/ports/include/windows/windows.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ HGDIOBJ SelectObject(HDC hdc, HGDIOBJ hgdiobj);
148148

149149
HWND WINAPI CreateWindow(LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
150150
BOOL WINAPI ShowWindow(HWND hWnd, int nCmdShow);
151+
BOOL InvalidateRect(HWND hWnd, const RECT *lpRect, BOOL bErase);
151152
BOOL UpdateWindow(HWND hWnd);
152153
BOOL RedrawWindow(HWND hWnd, const RECT *lprcUpdate, HRGN hrgnUpdate, UINT flags);
153154
BOOL DestroyWindow(HWND hWnd);
@@ -191,6 +192,7 @@ VOID WINAPI PostQuitMessage(int nExitCode);
191192
#define VK_UP 38
192193
#define VK_RIGHT 39
193194
#define VK_DOWN 40
195+
#define VK_F5 0x74
194196

195197
#define RDW_INVALIDATE 1
196198

utils/lstopo/lstopo-cairo.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2019 Inria. All rights reserved.
3+
* Copyright © 2009-2020 Inria. All rights reserved.
44
* Copyright © 2009-2010, 2014, 2017, 2020 Université Bordeaux
55
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -376,7 +376,7 @@ output_x11(struct lstopo_output *loutput, const char *dummy __hwloc_attribute_un
376376

377377
topo_cairo_paint(coutput);
378378

379-
while (!finish) {
379+
while (!finish && !loutput->needs_topology_refresh) {
380380
XEvent e;
381381
if (!XEventsQueued(disp->dpy, QueuedAfterFlush)) {
382382
/* No pending event, flush moving windows before waiting for next event */
@@ -441,6 +441,9 @@ output_x11(struct lstopo_output *loutput, const char *dummy __hwloc_attribute_un
441441
case XK_Escape:
442442
finish = 1;
443443
break;
444+
case XK_F5:
445+
loutput->needs_topology_refresh = 1;
446+
break;
444447
case XK_Left:
445448
disp->x -= disp->screen_width/10;
446449
move_x11(disp);

utils/lstopo/lstopo-draw.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ destroy_colors(void)
112112
free(tmp);
113113
tmp = next;
114114
}
115+
116+
colors = NULL; /* so that it works after refresh */
115117
}
116118

117119
static struct lstopo_color *

utils/lstopo/lstopo-windows.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
290290
case VK_CONTROL:
291291
control = 1;
292292
break;
293+
case VK_F5:
294+
loutput->needs_topology_refresh = 1;
295+
break;
293296
}
294297
break;
295298
case WM_KEYUP:
@@ -407,11 +410,11 @@ struct draw_methods windows_draw_methods = {
407410
windows_textsize,
408411
};
409412

413+
static HWND toplevel = NULL;
414+
410415
int
411416
output_windows (struct lstopo_output *loutput, const char *dummy __hwloc_attribute_unused)
412417
{
413-
WNDCLASS wndclass;
414-
HWND toplevel;
415418
unsigned width, height;
416419
HFONT font;
417420
MSG msg;
@@ -422,21 +425,25 @@ output_windows (struct lstopo_output *loutput, const char *dummy __hwloc_attribu
422425
loutput->methods = &windows_draw_methods;
423426
loutput->backend_data = &the_output;
424427

425-
/* create the toplevel window, with random size for now */
426-
memset(&wndclass, 0, sizeof(wndclass));
427-
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
428-
wndclass.hCursor = LoadCursor(NULL, IDC_SIZEALL);
429-
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
430-
wndclass.lpfnWndProc = WndProc;
431-
wndclass.lpszClassName = "lstopo";
432-
433-
RegisterClass(&wndclass);
428+
if (!toplevel) {
429+
/* create the toplevel window, with random size for now */
430+
WNDCLASS wndclass;
431+
memset(&wndclass, 0, sizeof(wndclass));
432+
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
433+
wndclass.hCursor = LoadCursor(NULL, IDC_SIZEALL);
434+
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
435+
wndclass.lpfnWndProc = WndProc;
436+
wndclass.lpszClassName = "lstopo";
437+
438+
RegisterClass(&wndclass);
439+
440+
toplevel = CreateWindow("lstopo", loutput->title, WS_OVERLAPPEDWINDOW,
441+
CW_USEDEFAULT, CW_USEDEFAULT,
442+
10, 10, NULL, NULL, NULL, NULL);
443+
}
434444

435445
/* recurse once for preparing sizes and positions using a fake top level window */
436446
loutput->drawing = LSTOPO_DRAWING_PREPARE;
437-
toplevel = CreateWindow("lstopo", loutput->title, WS_OVERLAPPEDWINDOW,
438-
CW_USEDEFAULT, CW_USEDEFAULT,
439-
10, 10, NULL, NULL, NULL, NULL);
440447
BeginPaint(toplevel, &the_output.ps);
441448
font = CreateFont(loutput->fontsize, 0, 0, 0, 0, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, NULL);
442449
SelectObject(the_output.ps.hdc, (HGDIOBJ) font);
@@ -486,14 +493,16 @@ output_windows (struct lstopo_output *loutput, const char *dummy __hwloc_attribu
486493

487494
lstopo_show_interactive_help();
488495
ShowWindow(toplevel, SW_SHOWDEFAULT);
496+
InvalidateRect(toplevel, NULL, 1); /* make sure UpdateWindow() will update something when refreshing the topology */
489497
UpdateWindow(toplevel);
490498

491-
while (!finish && GetMessage(&msg, NULL, 0, 0)) {
499+
while (!finish && !loutput->needs_topology_refresh && GetMessage(&msg, NULL, 0, 0)) {
492500
TranslateMessage(&msg);
493501
DispatchMessage(&msg);
494502
}
495503

496-
DestroyWindow(toplevel);
504+
if (!loutput->needs_topology_refresh)
505+
DestroyWindow(toplevel);
497506
destroy_colors();
498507
return 0;
499508
}

utils/lstopo/lstopo.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ void lstopo_show_interactive_help(void)
452452
printf(" Scroll horizontally ................. Left Right Ctrl+PageUp/Down\n");
453453
printf(" Scroll to the top-left corner ....... Home\n");
454454
printf(" Scroll to the bottom-right corner ... End\n");
455+
printf(" Refresh the topology ................ F5\n");
455456
printf(" Show this help ...................... h H ?\n");
456457
printf(" Exit ................................ q Q Esc\n");
457458
printf(" Configuration tweaks:\n");
@@ -1315,6 +1316,9 @@ main (int argc, char *argv[])
13151316
goto out_usagefailure;
13161317
}
13171318

1319+
refresh:
1320+
loutput.needs_topology_refresh = 0;
1321+
13181322
/*************************
13191323
* Configure the topology
13201324
*/
@@ -1494,6 +1498,9 @@ main (int argc, char *argv[])
14941498

14951499
hwloc_topology_destroy (topology);
14961500

1501+
if (loutput.needs_topology_refresh)
1502+
goto refresh;
1503+
14971504
for(i=0; i<loutput.legend_append_nr; i++)
14981505
free(loutput.legend_append[i]);
14991506
free(loutput.legend_append);

utils/lstopo/lstopo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2019 Inria. All rights reserved.
3+
* Copyright © 2009-2020 Inria. All rights reserved.
44
* Copyright © 2009-2010, 2012, 2015 Université Bordeaux
55
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
66
* Copyright © 2020 Hewlett-Packard Enterprise. All rights reserved.
@@ -42,6 +42,9 @@ struct lstopo_output {
4242
hwloc_topology_t topology;
4343
unsigned depth;
4444

45+
/* when an interactive backends want a refresh of the topology */
46+
int needs_topology_refresh;
47+
4548
/* file config */
4649
FILE *file;
4750
int overwrite;

0 commit comments

Comments
 (0)