1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00
putty-source/windows/win-gui-seat.h

166 lines
3.7 KiB
C
Raw Permalink Normal View History

GUI PuTTY: stop using the global 'hwnd'. This was the difficult part of cleaning up that global variable. The main Windows PuTTY GUI is split between source files, so that _does_ actually need to refer to the main window from multiple places. But all the places where windlg.c needed to use 'hwnd' are seat methods, so they were already receiving a Seat pointer as a parameter. In other words, the methods of the Windows GUI Seat were already split between source files. So it seems only fair that they should be able to share knowledge of the seat's data as well. Hence, I've created a small 'WinGuiSeat' structure which both window.c and windlg.c can see the layout of, and put the main terminal window handle in there. Then the seat methods implemented in windlg.c, like win_seat_verify_ssh_host_key, can use container_of to turn the Seat pointer parameter back into the address of that structure, just as the methods in window.c can do (even though they currently don't need to). (Who knows: now that it _exists_, perhaps that structure can be gradually expanded in future to turn it into a proper encapsulation of all the Windows frontend's state, like we should have had all along...) I've also moved the Windows GUI LogPolicy implementation into the same object (i.e. WinGuiSeat implements both traits at once). That allows win_gui_logging_error to recover the same WinGuiSeat from its input LogPolicy pointer, which means it can get from there to the Seat facet of the same object, so that I don't need the extern variable 'win_seat' any more either.
2020-02-02 10:00:43 +00:00
/*
windows/window.c: move (most) static vars into WinGuiSeat. This is a piece of refactoring that's been overdue forever. In the Unix front end, all the variables specific to a particular SSH session live in a big 'inst' structure, and calls to any of the trait APIs like Seat or TermWin can recover the right 'inst' from their input context pointer. But the Windows frontend was written before that kind of thing became habitual to me, and all its variables have been just lying around at the top level of window.c, and most of those context pointers were just ignored. Now I've swept them all up and put them where they ought to be, in a big context structure. This was made immeasurably easier by the very nifty 'clang-rename' tool, which can rename a single variable in a C source file, and find just the right set of identifiers to change even if other variables in the file have the same name, even in sub-scopes. So I started by clang-renaming all the top-level variables in question to have names beginning with a prefix that didn't previously appear anywhere in the code; checked that still worked; and then moved all the declarations into the struct type and did a purely textual search-and-replace of the prefix with 'wgs->'. One potential benefit of this change is that it allows more than one instance of the WinGuiSeat structure to exist in the same process. I don't have any immediate plans to actually do that, but it's nice to know it wouldn't be ruled out if we ever did need it. But that's not the main reason I did it. The main reason is that I recently looked at the output of a Windows build using clang -Wall, and was horrified by the number of casual shadowings of generically-named global variables like 'term' and 'conf' with local variables of the same name. That seemed like a recipe for confusion, and I decided the best way to disambiguate them all was to do this refactoring that I'd wanted anyway for years. A few uses of the global variables occurred in functions that didn't have convenient access to the right WinGuiSeat via a callback parameter of some kind. Those had to be treated specially. Most were cleaned up in advance by the previous few commits; the remaining fixes in this commit itself were in functions like modalfatalbox(), nonfatal() and cleanup_exit(). The error reporting functions want the terminal HWND to use as a MessageBox parameter; they also have the side effect of un-hiding the mouse pointer in the terminal window, in case it's hidden; and cleanup_exit wanted to free some resources dangling off the WinGuiSeat. For most of those cases, I've made a linked list of all currently live WinGuiSeat structures, so that they can loop over _all_ live instances (whether there's one as usual, none, or maybe more than one in future). The parent window for non-connection-specific error messages is found by simply picking one arbitrarily off the linked list (if any); the cleanups are done by iterating over the _whole_ list. The mouse-pointer unhiding is dealt with by simply allowing show_mouseptr to take a _null_ WinGuiSeat pointer. The only thing it needs the context for at all is to check whether pointer-hiding is enabled in the session's Conf; so if we're _un_-hiding the pointer we don't need to check, and can unhide it unconditionally. The remaining global variables in window.c are the new linked list of all WinGuiSeat structures; 'wm_mousewheel' and 'trust_icon' which really should be global across all WinGuiSeats even if we were to have more than one; and there's a static variable 'cursor_visible' in show_mouseptr() which is likewise legitimately Seat-independent (since it records the last value we passed to the Win32 API ShowCursor function, and _that's_ global across the whole process state). All of this should cause no functional change whatsoever.
2022-09-13 08:00:19 +00:00
* Main state structure for an instance of the Windows PuTTY front
* end, containing all the PuTTY objects and all the Windows API
* resources like the window handle.
GUI PuTTY: stop using the global 'hwnd'. This was the difficult part of cleaning up that global variable. The main Windows PuTTY GUI is split between source files, so that _does_ actually need to refer to the main window from multiple places. But all the places where windlg.c needed to use 'hwnd' are seat methods, so they were already receiving a Seat pointer as a parameter. In other words, the methods of the Windows GUI Seat were already split between source files. So it seems only fair that they should be able to share knowledge of the seat's data as well. Hence, I've created a small 'WinGuiSeat' structure which both window.c and windlg.c can see the layout of, and put the main terminal window handle in there. Then the seat methods implemented in windlg.c, like win_seat_verify_ssh_host_key, can use container_of to turn the Seat pointer parameter back into the address of that structure, just as the methods in window.c can do (even though they currently don't need to). (Who knows: now that it _exists_, perhaps that structure can be gradually expanded in future to turn it into a proper encapsulation of all the Windows frontend's state, like we should have had all along...) I've also moved the Windows GUI LogPolicy implementation into the same object (i.e. WinGuiSeat implements both traits at once). That allows win_gui_logging_error to recover the same WinGuiSeat from its input LogPolicy pointer, which means it can get from there to the Seat facet of the same object, so that I don't need the extern variable 'win_seat' any more either.
2020-02-02 10:00:43 +00:00
*/
typedef struct WinGuiSeat WinGuiSeat;
windows/window.c: move (most) static vars into WinGuiSeat. This is a piece of refactoring that's been overdue forever. In the Unix front end, all the variables specific to a particular SSH session live in a big 'inst' structure, and calls to any of the trait APIs like Seat or TermWin can recover the right 'inst' from their input context pointer. But the Windows frontend was written before that kind of thing became habitual to me, and all its variables have been just lying around at the top level of window.c, and most of those context pointers were just ignored. Now I've swept them all up and put them where they ought to be, in a big context structure. This was made immeasurably easier by the very nifty 'clang-rename' tool, which can rename a single variable in a C source file, and find just the right set of identifiers to change even if other variables in the file have the same name, even in sub-scopes. So I started by clang-renaming all the top-level variables in question to have names beginning with a prefix that didn't previously appear anywhere in the code; checked that still worked; and then moved all the declarations into the struct type and did a purely textual search-and-replace of the prefix with 'wgs->'. One potential benefit of this change is that it allows more than one instance of the WinGuiSeat structure to exist in the same process. I don't have any immediate plans to actually do that, but it's nice to know it wouldn't be ruled out if we ever did need it. But that's not the main reason I did it. The main reason is that I recently looked at the output of a Windows build using clang -Wall, and was horrified by the number of casual shadowings of generically-named global variables like 'term' and 'conf' with local variables of the same name. That seemed like a recipe for confusion, and I decided the best way to disambiguate them all was to do this refactoring that I'd wanted anyway for years. A few uses of the global variables occurred in functions that didn't have convenient access to the right WinGuiSeat via a callback parameter of some kind. Those had to be treated specially. Most were cleaned up in advance by the previous few commits; the remaining fixes in this commit itself were in functions like modalfatalbox(), nonfatal() and cleanup_exit(). The error reporting functions want the terminal HWND to use as a MessageBox parameter; they also have the side effect of un-hiding the mouse pointer in the terminal window, in case it's hidden; and cleanup_exit wanted to free some resources dangling off the WinGuiSeat. For most of those cases, I've made a linked list of all currently live WinGuiSeat structures, so that they can loop over _all_ live instances (whether there's one as usual, none, or maybe more than one in future). The parent window for non-connection-specific error messages is found by simply picking one arbitrarily off the linked list (if any); the cleanups are done by iterating over the _whole_ list. The mouse-pointer unhiding is dealt with by simply allowing show_mouseptr to take a _null_ WinGuiSeat pointer. The only thing it needs the context for at all is to check whether pointer-hiding is enabled in the session's Conf; so if we're _un_-hiding the pointer we don't need to check, and can unhide it unconditionally. The remaining global variables in window.c are the new linked list of all WinGuiSeat structures; 'wm_mousewheel' and 'trust_icon' which really should be global across all WinGuiSeats even if we were to have more than one; and there's a static variable 'cursor_visible' in show_mouseptr() which is likewise legitimately Seat-independent (since it records the last value we passed to the Win32 API ShowCursor function, and _that's_ global across the whole process state). All of this should cause no functional change whatsoever.
2022-09-13 08:00:19 +00:00
struct PopupMenu {
HMENU menu;
};
enum { SYSMENU, CTXMENU }; /* indices into popup_menus field */
#define FONT_NORMAL 0
#define FONT_BOLD 1
#define FONT_UNDERLINE 2
#define FONT_BOLDUND 3
#define FONT_WIDE 0x04
#define FONT_HIGH 0x08
#define FONT_NARROW 0x10
#define FONT_OEM 0x20
#define FONT_OEMBOLD 0x21
#define FONT_OEMUND 0x22
#define FONT_OEMBOLDUND 0x23
#define FONT_MAXNO 0x40
#define FONT_SHIFT 5
enum BoldMode {
BOLD_NONE, BOLD_SHADOW, BOLD_FONT
};
enum UnderlineMode {
UND_LINE, UND_FONT
};
struct _dpi_info {
POINT cur_dpi;
RECT new_wnd_rect;
};
/*
* Against the future possibility of having more than one of these
* in a process (and the current possibility of having zero), we
* keep a linked list of all live WinGuiSeats, so that cleanups
* can be done to any that exist.
*/
struct WinGuiSeatListNode {
struct WinGuiSeatListNode *next, *prev;
};
extern struct WinGuiSeatListNode wgslisthead; /* static end pointer */
GUI PuTTY: stop using the global 'hwnd'. This was the difficult part of cleaning up that global variable. The main Windows PuTTY GUI is split between source files, so that _does_ actually need to refer to the main window from multiple places. But all the places where windlg.c needed to use 'hwnd' are seat methods, so they were already receiving a Seat pointer as a parameter. In other words, the methods of the Windows GUI Seat were already split between source files. So it seems only fair that they should be able to share knowledge of the seat's data as well. Hence, I've created a small 'WinGuiSeat' structure which both window.c and windlg.c can see the layout of, and put the main terminal window handle in there. Then the seat methods implemented in windlg.c, like win_seat_verify_ssh_host_key, can use container_of to turn the Seat pointer parameter back into the address of that structure, just as the methods in window.c can do (even though they currently don't need to). (Who knows: now that it _exists_, perhaps that structure can be gradually expanded in future to turn it into a proper encapsulation of all the Windows frontend's state, like we should have had all along...) I've also moved the Windows GUI LogPolicy implementation into the same object (i.e. WinGuiSeat implements both traits at once). That allows win_gui_logging_error to recover the same WinGuiSeat from its input LogPolicy pointer, which means it can get from there to the Seat facet of the same object, so that I don't need the extern variable 'win_seat' any more either.
2020-02-02 10:00:43 +00:00
struct WinGuiSeat {
windows/window.c: move (most) static vars into WinGuiSeat. This is a piece of refactoring that's been overdue forever. In the Unix front end, all the variables specific to a particular SSH session live in a big 'inst' structure, and calls to any of the trait APIs like Seat or TermWin can recover the right 'inst' from their input context pointer. But the Windows frontend was written before that kind of thing became habitual to me, and all its variables have been just lying around at the top level of window.c, and most of those context pointers were just ignored. Now I've swept them all up and put them where they ought to be, in a big context structure. This was made immeasurably easier by the very nifty 'clang-rename' tool, which can rename a single variable in a C source file, and find just the right set of identifiers to change even if other variables in the file have the same name, even in sub-scopes. So I started by clang-renaming all the top-level variables in question to have names beginning with a prefix that didn't previously appear anywhere in the code; checked that still worked; and then moved all the declarations into the struct type and did a purely textual search-and-replace of the prefix with 'wgs->'. One potential benefit of this change is that it allows more than one instance of the WinGuiSeat structure to exist in the same process. I don't have any immediate plans to actually do that, but it's nice to know it wouldn't be ruled out if we ever did need it. But that's not the main reason I did it. The main reason is that I recently looked at the output of a Windows build using clang -Wall, and was horrified by the number of casual shadowings of generically-named global variables like 'term' and 'conf' with local variables of the same name. That seemed like a recipe for confusion, and I decided the best way to disambiguate them all was to do this refactoring that I'd wanted anyway for years. A few uses of the global variables occurred in functions that didn't have convenient access to the right WinGuiSeat via a callback parameter of some kind. Those had to be treated specially. Most were cleaned up in advance by the previous few commits; the remaining fixes in this commit itself were in functions like modalfatalbox(), nonfatal() and cleanup_exit(). The error reporting functions want the terminal HWND to use as a MessageBox parameter; they also have the side effect of un-hiding the mouse pointer in the terminal window, in case it's hidden; and cleanup_exit wanted to free some resources dangling off the WinGuiSeat. For most of those cases, I've made a linked list of all currently live WinGuiSeat structures, so that they can loop over _all_ live instances (whether there's one as usual, none, or maybe more than one in future). The parent window for non-connection-specific error messages is found by simply picking one arbitrarily off the linked list (if any); the cleanups are done by iterating over the _whole_ list. The mouse-pointer unhiding is dealt with by simply allowing show_mouseptr to take a _null_ WinGuiSeat pointer. The only thing it needs the context for at all is to check whether pointer-hiding is enabled in the session's Conf; so if we're _un_-hiding the pointer we don't need to check, and can unhide it unconditionally. The remaining global variables in window.c are the new linked list of all WinGuiSeat structures; 'wm_mousewheel' and 'trust_icon' which really should be global across all WinGuiSeats even if we were to have more than one; and there's a static variable 'cursor_visible' in show_mouseptr() which is likewise legitimately Seat-independent (since it records the last value we passed to the Win32 API ShowCursor function, and _that's_ global across the whole process state). All of this should cause no functional change whatsoever.
2022-09-13 08:00:19 +00:00
struct WinGuiSeatListNode wgslistnode;
GUI PuTTY: stop using the global 'hwnd'. This was the difficult part of cleaning up that global variable. The main Windows PuTTY GUI is split between source files, so that _does_ actually need to refer to the main window from multiple places. But all the places where windlg.c needed to use 'hwnd' are seat methods, so they were already receiving a Seat pointer as a parameter. In other words, the methods of the Windows GUI Seat were already split between source files. So it seems only fair that they should be able to share knowledge of the seat's data as well. Hence, I've created a small 'WinGuiSeat' structure which both window.c and windlg.c can see the layout of, and put the main terminal window handle in there. Then the seat methods implemented in windlg.c, like win_seat_verify_ssh_host_key, can use container_of to turn the Seat pointer parameter back into the address of that structure, just as the methods in window.c can do (even though they currently don't need to). (Who knows: now that it _exists_, perhaps that structure can be gradually expanded in future to turn it into a proper encapsulation of all the Windows frontend's state, like we should have had all along...) I've also moved the Windows GUI LogPolicy implementation into the same object (i.e. WinGuiSeat implements both traits at once). That allows win_gui_logging_error to recover the same WinGuiSeat from its input LogPolicy pointer, which means it can get from there to the Seat facet of the same object, so that I don't need the extern variable 'win_seat' any more either.
2020-02-02 10:00:43 +00:00
Seat seat;
windows/window.c: move (most) static vars into WinGuiSeat. This is a piece of refactoring that's been overdue forever. In the Unix front end, all the variables specific to a particular SSH session live in a big 'inst' structure, and calls to any of the trait APIs like Seat or TermWin can recover the right 'inst' from their input context pointer. But the Windows frontend was written before that kind of thing became habitual to me, and all its variables have been just lying around at the top level of window.c, and most of those context pointers were just ignored. Now I've swept them all up and put them where they ought to be, in a big context structure. This was made immeasurably easier by the very nifty 'clang-rename' tool, which can rename a single variable in a C source file, and find just the right set of identifiers to change even if other variables in the file have the same name, even in sub-scopes. So I started by clang-renaming all the top-level variables in question to have names beginning with a prefix that didn't previously appear anywhere in the code; checked that still worked; and then moved all the declarations into the struct type and did a purely textual search-and-replace of the prefix with 'wgs->'. One potential benefit of this change is that it allows more than one instance of the WinGuiSeat structure to exist in the same process. I don't have any immediate plans to actually do that, but it's nice to know it wouldn't be ruled out if we ever did need it. But that's not the main reason I did it. The main reason is that I recently looked at the output of a Windows build using clang -Wall, and was horrified by the number of casual shadowings of generically-named global variables like 'term' and 'conf' with local variables of the same name. That seemed like a recipe for confusion, and I decided the best way to disambiguate them all was to do this refactoring that I'd wanted anyway for years. A few uses of the global variables occurred in functions that didn't have convenient access to the right WinGuiSeat via a callback parameter of some kind. Those had to be treated specially. Most were cleaned up in advance by the previous few commits; the remaining fixes in this commit itself were in functions like modalfatalbox(), nonfatal() and cleanup_exit(). The error reporting functions want the terminal HWND to use as a MessageBox parameter; they also have the side effect of un-hiding the mouse pointer in the terminal window, in case it's hidden; and cleanup_exit wanted to free some resources dangling off the WinGuiSeat. For most of those cases, I've made a linked list of all currently live WinGuiSeat structures, so that they can loop over _all_ live instances (whether there's one as usual, none, or maybe more than one in future). The parent window for non-connection-specific error messages is found by simply picking one arbitrarily off the linked list (if any); the cleanups are done by iterating over the _whole_ list. The mouse-pointer unhiding is dealt with by simply allowing show_mouseptr to take a _null_ WinGuiSeat pointer. The only thing it needs the context for at all is to check whether pointer-hiding is enabled in the session's Conf; so if we're _un_-hiding the pointer we don't need to check, and can unhide it unconditionally. The remaining global variables in window.c are the new linked list of all WinGuiSeat structures; 'wm_mousewheel' and 'trust_icon' which really should be global across all WinGuiSeats even if we were to have more than one; and there's a static variable 'cursor_visible' in show_mouseptr() which is likewise legitimately Seat-independent (since it records the last value we passed to the Win32 API ShowCursor function, and _that's_ global across the whole process state). All of this should cause no functional change whatsoever.
2022-09-13 08:00:19 +00:00
TermWin termwin;
GUI PuTTY: stop using the global 'hwnd'. This was the difficult part of cleaning up that global variable. The main Windows PuTTY GUI is split between source files, so that _does_ actually need to refer to the main window from multiple places. But all the places where windlg.c needed to use 'hwnd' are seat methods, so they were already receiving a Seat pointer as a parameter. In other words, the methods of the Windows GUI Seat were already split between source files. So it seems only fair that they should be able to share knowledge of the seat's data as well. Hence, I've created a small 'WinGuiSeat' structure which both window.c and windlg.c can see the layout of, and put the main terminal window handle in there. Then the seat methods implemented in windlg.c, like win_seat_verify_ssh_host_key, can use container_of to turn the Seat pointer parameter back into the address of that structure, just as the methods in window.c can do (even though they currently don't need to). (Who knows: now that it _exists_, perhaps that structure can be gradually expanded in future to turn it into a proper encapsulation of all the Windows frontend's state, like we should have had all along...) I've also moved the Windows GUI LogPolicy implementation into the same object (i.e. WinGuiSeat implements both traits at once). That allows win_gui_logging_error to recover the same WinGuiSeat from its input LogPolicy pointer, which means it can get from there to the Seat facet of the same object, so that I don't need the extern variable 'win_seat' any more either.
2020-02-02 10:00:43 +00:00
LogPolicy logpolicy;
windows/window.c: move (most) static vars into WinGuiSeat. This is a piece of refactoring that's been overdue forever. In the Unix front end, all the variables specific to a particular SSH session live in a big 'inst' structure, and calls to any of the trait APIs like Seat or TermWin can recover the right 'inst' from their input context pointer. But the Windows frontend was written before that kind of thing became habitual to me, and all its variables have been just lying around at the top level of window.c, and most of those context pointers were just ignored. Now I've swept them all up and put them where they ought to be, in a big context structure. This was made immeasurably easier by the very nifty 'clang-rename' tool, which can rename a single variable in a C source file, and find just the right set of identifiers to change even if other variables in the file have the same name, even in sub-scopes. So I started by clang-renaming all the top-level variables in question to have names beginning with a prefix that didn't previously appear anywhere in the code; checked that still worked; and then moved all the declarations into the struct type and did a purely textual search-and-replace of the prefix with 'wgs->'. One potential benefit of this change is that it allows more than one instance of the WinGuiSeat structure to exist in the same process. I don't have any immediate plans to actually do that, but it's nice to know it wouldn't be ruled out if we ever did need it. But that's not the main reason I did it. The main reason is that I recently looked at the output of a Windows build using clang -Wall, and was horrified by the number of casual shadowings of generically-named global variables like 'term' and 'conf' with local variables of the same name. That seemed like a recipe for confusion, and I decided the best way to disambiguate them all was to do this refactoring that I'd wanted anyway for years. A few uses of the global variables occurred in functions that didn't have convenient access to the right WinGuiSeat via a callback parameter of some kind. Those had to be treated specially. Most were cleaned up in advance by the previous few commits; the remaining fixes in this commit itself were in functions like modalfatalbox(), nonfatal() and cleanup_exit(). The error reporting functions want the terminal HWND to use as a MessageBox parameter; they also have the side effect of un-hiding the mouse pointer in the terminal window, in case it's hidden; and cleanup_exit wanted to free some resources dangling off the WinGuiSeat. For most of those cases, I've made a linked list of all currently live WinGuiSeat structures, so that they can loop over _all_ live instances (whether there's one as usual, none, or maybe more than one in future). The parent window for non-connection-specific error messages is found by simply picking one arbitrarily off the linked list (if any); the cleanups are done by iterating over the _whole_ list. The mouse-pointer unhiding is dealt with by simply allowing show_mouseptr to take a _null_ WinGuiSeat pointer. The only thing it needs the context for at all is to check whether pointer-hiding is enabled in the session's Conf; so if we're _un_-hiding the pointer we don't need to check, and can unhide it unconditionally. The remaining global variables in window.c are the new linked list of all WinGuiSeat structures; 'wm_mousewheel' and 'trust_icon' which really should be global across all WinGuiSeats even if we were to have more than one; and there's a static variable 'cursor_visible' in show_mouseptr() which is likewise legitimately Seat-independent (since it records the last value we passed to the Win32 API ShowCursor function, and _that's_ global across the whole process state). All of this should cause no functional change whatsoever.
2022-09-13 08:00:19 +00:00
HWND term_hwnd;
windows/window.c: move more variables into WinGuiSeat. In commit f9e572595bb8cb6 I claimed that I'd removed very nearly all the global and static variables from windows/window.c. It turns out that this was wildly overoptimistic - I missed quite a few of them! I'm not quite sure how I managed that; my best guess is that I used an underpowered 'nm' command that failed to find some classes of variable. Some of the remaining function-scope statics were removed completely by commit afb3dab1e97a09f just now. In this commit, I've swept up some more and turn them into fields of WinGuiSeat, where they should have been moved last September. The (hopefully complete this time) list of remaining variables, generated by running this rune in the Windows build directory: nm windows/CMakeFiles/putty.dir/window.c.obj | grep -E '^([^ ]+)? *[bBcCdDgGsS] [^\.]' consists of the following variables which are legitimately global across the whole process and not related to a particular window: - 'hinst' and 'hprev', instance handles for Windows loadable modules - 'classname' in the terminal_window_class_a() and terminal_window_class_w() functions, which allocate a window class reusably - some pointers to Windows API functions retrieved via the DECL_WINDOWS_FUNCTION / GET_WINDOWS_FUNCTION system, such as p_AdjustWindowRectExForDpi and p_FlashWindowEx - some pointers to Windows API functions set up by assigning them at startup to the right one of the ANSI or Unicode version depending on the Windows version, e.g. sw_DefWindowProc and sw_DispatchMessage - 'unicode_window', a boolean flag set at the same time as those sw_Foo function pointers - 'sesslist', storing the last-retrieved version of the saved sessions menu - 'cursor_visible' in show_mouseptr() and 'forced_visible' in update_mouse_pointer(), each of which tracks the cumulative number of times that function has shown or hidden the mouse pointer, so as to manage its effect on the global state updated by ShowCursor - 'trust_icon', loaded from the executable's resources - 'wgslisthead', the list of all active WinGuiSeats - 'wm_mousewheel', the window-message id we use for mouse wheel events and the following which are nothing to do with our code: - '_OptionsStorage' in __local_stdio_printf_options() and __local_stdio_scanf_options(), which I'd never noticed before, but apparently are internal to a standard library header.
2023-05-27 13:59:20 +00:00
int extra_width, extra_height;
int font_width, font_height;
bool font_dualwidth, font_varpitch;
int offset_width, offset_height;
bool was_zoomed;
int prev_rows, prev_cols; // FIXME I don't think these are even used
HBITMAP caretbm;
windows/window.c: move (most) static vars into WinGuiSeat. This is a piece of refactoring that's been overdue forever. In the Unix front end, all the variables specific to a particular SSH session live in a big 'inst' structure, and calls to any of the trait APIs like Seat or TermWin can recover the right 'inst' from their input context pointer. But the Windows frontend was written before that kind of thing became habitual to me, and all its variables have been just lying around at the top level of window.c, and most of those context pointers were just ignored. Now I've swept them all up and put them where they ought to be, in a big context structure. This was made immeasurably easier by the very nifty 'clang-rename' tool, which can rename a single variable in a C source file, and find just the right set of identifiers to change even if other variables in the file have the same name, even in sub-scopes. So I started by clang-renaming all the top-level variables in question to have names beginning with a prefix that didn't previously appear anywhere in the code; checked that still worked; and then moved all the declarations into the struct type and did a purely textual search-and-replace of the prefix with 'wgs->'. One potential benefit of this change is that it allows more than one instance of the WinGuiSeat structure to exist in the same process. I don't have any immediate plans to actually do that, but it's nice to know it wouldn't be ruled out if we ever did need it. But that's not the main reason I did it. The main reason is that I recently looked at the output of a Windows build using clang -Wall, and was horrified by the number of casual shadowings of generically-named global variables like 'term' and 'conf' with local variables of the same name. That seemed like a recipe for confusion, and I decided the best way to disambiguate them all was to do this refactoring that I'd wanted anyway for years. A few uses of the global variables occurred in functions that didn't have convenient access to the right WinGuiSeat via a callback parameter of some kind. Those had to be treated specially. Most were cleaned up in advance by the previous few commits; the remaining fixes in this commit itself were in functions like modalfatalbox(), nonfatal() and cleanup_exit(). The error reporting functions want the terminal HWND to use as a MessageBox parameter; they also have the side effect of un-hiding the mouse pointer in the terminal window, in case it's hidden; and cleanup_exit wanted to free some resources dangling off the WinGuiSeat. For most of those cases, I've made a linked list of all currently live WinGuiSeat structures, so that they can loop over _all_ live instances (whether there's one as usual, none, or maybe more than one in future). The parent window for non-connection-specific error messages is found by simply picking one arbitrarily off the linked list (if any); the cleanups are done by iterating over the _whole_ list. The mouse-pointer unhiding is dealt with by simply allowing show_mouseptr to take a _null_ WinGuiSeat pointer. The only thing it needs the context for at all is to check whether pointer-hiding is enabled in the session's Conf; so if we're _un_-hiding the pointer we don't need to check, and can unhide it unconditionally. The remaining global variables in window.c are the new linked list of all WinGuiSeat structures; 'wm_mousewheel' and 'trust_icon' which really should be global across all WinGuiSeats even if we were to have more than one; and there's a static variable 'cursor_visible' in show_mouseptr() which is likewise legitimately Seat-independent (since it records the last value we passed to the Win32 API ShowCursor function, and _that's_ global across the whole process state). All of this should cause no functional change whatsoever.
2022-09-13 08:00:19 +00:00
int caret_x, caret_y;
int kbd_codepage;
Ldisc *ldisc;
Backend *backend;
cmdline_get_passwd_input_state cmdline_get_passwd_state;
struct unicode_data ucsdata;
bool session_closed;
bool reconfiguring;
const SessionSpecial *specials;
HMENU specials_menu;
int n_specials;
struct PopupMenu popup_menus[2];
HMENU savedsess_menu;
Conf *conf;
LogContext *logctx;
Terminal *term;
int cursor_type;
int vtmode;
HFONT fonts[FONT_MAXNO];
LOGFONT lfont;
bool fontflag[FONT_MAXNO];
enum BoldMode bold_font_mode;
bool bold_colours;
enum UnderlineMode und_mode;
int descent, font_strikethrough_y;
COLORREF colours[OSC4_NCOLOURS];
HPALETTE pal;
LPLOGPALETTE logpal;
bool tried_pal;
COLORREF colorref_modifier;
struct _dpi_info dpi_info;
int dbltime, lasttime, lastact;
Mouse_Button lastbtn;
bool send_raw_mouse;
int wheel_accumulator;
bool pointer_indicates_raw_mouse;
BusyStatus busy_status;
wchar_t *window_name, *icon_name;
windows/window.c: move more variables into WinGuiSeat. In commit f9e572595bb8cb6 I claimed that I'd removed very nearly all the global and static variables from windows/window.c. It turns out that this was wildly overoptimistic - I missed quite a few of them! I'm not quite sure how I managed that; my best guess is that I used an underpowered 'nm' command that failed to find some classes of variable. Some of the remaining function-scope statics were removed completely by commit afb3dab1e97a09f just now. In this commit, I've swept up some more and turn them into fields of WinGuiSeat, where they should have been moved last September. The (hopefully complete this time) list of remaining variables, generated by running this rune in the Windows build directory: nm windows/CMakeFiles/putty.dir/window.c.obj | grep -E '^([^ ]+)? *[bBcCdDgGsS] [^\.]' consists of the following variables which are legitimately global across the whole process and not related to a particular window: - 'hinst' and 'hprev', instance handles for Windows loadable modules - 'classname' in the terminal_window_class_a() and terminal_window_class_w() functions, which allocate a window class reusably - some pointers to Windows API functions retrieved via the DECL_WINDOWS_FUNCTION / GET_WINDOWS_FUNCTION system, such as p_AdjustWindowRectExForDpi and p_FlashWindowEx - some pointers to Windows API functions set up by assigning them at startup to the right one of the ANSI or Unicode version depending on the Windows version, e.g. sw_DefWindowProc and sw_DispatchMessage - 'unicode_window', a boolean flag set at the same time as those sw_Foo function pointers - 'sesslist', storing the last-retrieved version of the saved sessions menu - 'cursor_visible' in show_mouseptr() and 'forced_visible' in update_mouse_pointer(), each of which tracks the cumulative number of times that function has shown or hidden the mouse pointer, so as to manage its effect on the global state updated by ShowCursor - 'trust_icon', loaded from the executable's resources - 'wgslisthead', the list of all active WinGuiSeats - 'wm_mousewheel', the window-message id we use for mouse wheel events and the following which are nothing to do with our code: - '_OptionsStorage' in __local_stdio_printf_options() and __local_stdio_scanf_options(), which I'd never noticed before, but apparently are internal to a standard library header.
2023-05-27 13:59:20 +00:00
int alt_numberpad_accumulator;
windows/window.c: move (most) static vars into WinGuiSeat. This is a piece of refactoring that's been overdue forever. In the Unix front end, all the variables specific to a particular SSH session live in a big 'inst' structure, and calls to any of the trait APIs like Seat or TermWin can recover the right 'inst' from their input context pointer. But the Windows frontend was written before that kind of thing became habitual to me, and all its variables have been just lying around at the top level of window.c, and most of those context pointers were just ignored. Now I've swept them all up and put them where they ought to be, in a big context structure. This was made immeasurably easier by the very nifty 'clang-rename' tool, which can rename a single variable in a C source file, and find just the right set of identifiers to change even if other variables in the file have the same name, even in sub-scopes. So I started by clang-renaming all the top-level variables in question to have names beginning with a prefix that didn't previously appear anywhere in the code; checked that still worked; and then moved all the declarations into the struct type and did a purely textual search-and-replace of the prefix with 'wgs->'. One potential benefit of this change is that it allows more than one instance of the WinGuiSeat structure to exist in the same process. I don't have any immediate plans to actually do that, but it's nice to know it wouldn't be ruled out if we ever did need it. But that's not the main reason I did it. The main reason is that I recently looked at the output of a Windows build using clang -Wall, and was horrified by the number of casual shadowings of generically-named global variables like 'term' and 'conf' with local variables of the same name. That seemed like a recipe for confusion, and I decided the best way to disambiguate them all was to do this refactoring that I'd wanted anyway for years. A few uses of the global variables occurred in functions that didn't have convenient access to the right WinGuiSeat via a callback parameter of some kind. Those had to be treated specially. Most were cleaned up in advance by the previous few commits; the remaining fixes in this commit itself were in functions like modalfatalbox(), nonfatal() and cleanup_exit(). The error reporting functions want the terminal HWND to use as a MessageBox parameter; they also have the side effect of un-hiding the mouse pointer in the terminal window, in case it's hidden; and cleanup_exit wanted to free some resources dangling off the WinGuiSeat. For most of those cases, I've made a linked list of all currently live WinGuiSeat structures, so that they can loop over _all_ live instances (whether there's one as usual, none, or maybe more than one in future). The parent window for non-connection-specific error messages is found by simply picking one arbitrarily off the linked list (if any); the cleanups are done by iterating over the _whole_ list. The mouse-pointer unhiding is dealt with by simply allowing show_mouseptr to take a _null_ WinGuiSeat pointer. The only thing it needs the context for at all is to check whether pointer-hiding is enabled in the session's Conf; so if we're _un_-hiding the pointer we don't need to check, and can unhide it unconditionally. The remaining global variables in window.c are the new linked list of all WinGuiSeat structures; 'wm_mousewheel' and 'trust_icon' which really should be global across all WinGuiSeats even if we were to have more than one; and there's a static variable 'cursor_visible' in show_mouseptr() which is likewise legitimately Seat-independent (since it records the last value we passed to the Win32 API ShowCursor function, and _that's_ global across the whole process state). All of this should cause no functional change whatsoever.
2022-09-13 08:00:19 +00:00
int compose_state;
windows/window.c: move more variables into WinGuiSeat. In commit f9e572595bb8cb6 I claimed that I'd removed very nearly all the global and static variables from windows/window.c. It turns out that this was wildly overoptimistic - I missed quite a few of them! I'm not quite sure how I managed that; my best guess is that I used an underpowered 'nm' command that failed to find some classes of variable. Some of the remaining function-scope statics were removed completely by commit afb3dab1e97a09f just now. In this commit, I've swept up some more and turn them into fields of WinGuiSeat, where they should have been moved last September. The (hopefully complete this time) list of remaining variables, generated by running this rune in the Windows build directory: nm windows/CMakeFiles/putty.dir/window.c.obj | grep -E '^([^ ]+)? *[bBcCdDgGsS] [^\.]' consists of the following variables which are legitimately global across the whole process and not related to a particular window: - 'hinst' and 'hprev', instance handles for Windows loadable modules - 'classname' in the terminal_window_class_a() and terminal_window_class_w() functions, which allocate a window class reusably - some pointers to Windows API functions retrieved via the DECL_WINDOWS_FUNCTION / GET_WINDOWS_FUNCTION system, such as p_AdjustWindowRectExForDpi and p_FlashWindowEx - some pointers to Windows API functions set up by assigning them at startup to the right one of the ANSI or Unicode version depending on the Windows version, e.g. sw_DefWindowProc and sw_DispatchMessage - 'unicode_window', a boolean flag set at the same time as those sw_Foo function pointers - 'sesslist', storing the last-retrieved version of the saved sessions menu - 'cursor_visible' in show_mouseptr() and 'forced_visible' in update_mouse_pointer(), each of which tracks the cumulative number of times that function has shown or hidden the mouse pointer, so as to manage its effect on the global state updated by ShowCursor - 'trust_icon', loaded from the executable's resources - 'wgslisthead', the list of all active WinGuiSeats - 'wm_mousewheel', the window-message id we use for mouse wheel events and the following which are nothing to do with our code: - '_OptionsStorage' in __local_stdio_printf_options() and __local_stdio_scanf_options(), which I'd never noticed before, but apparently are internal to a standard library header.
2023-05-27 13:59:20 +00:00
int compose_char;
WPARAM compose_keycode;
windows/window.c: move (most) static vars into WinGuiSeat. This is a piece of refactoring that's been overdue forever. In the Unix front end, all the variables specific to a particular SSH session live in a big 'inst' structure, and calls to any of the trait APIs like Seat or TermWin can recover the right 'inst' from their input context pointer. But the Windows frontend was written before that kind of thing became habitual to me, and all its variables have been just lying around at the top level of window.c, and most of those context pointers were just ignored. Now I've swept them all up and put them where they ought to be, in a big context structure. This was made immeasurably easier by the very nifty 'clang-rename' tool, which can rename a single variable in a C source file, and find just the right set of identifiers to change even if other variables in the file have the same name, even in sub-scopes. So I started by clang-renaming all the top-level variables in question to have names beginning with a prefix that didn't previously appear anywhere in the code; checked that still worked; and then moved all the declarations into the struct type and did a purely textual search-and-replace of the prefix with 'wgs->'. One potential benefit of this change is that it allows more than one instance of the WinGuiSeat structure to exist in the same process. I don't have any immediate plans to actually do that, but it's nice to know it wouldn't be ruled out if we ever did need it. But that's not the main reason I did it. The main reason is that I recently looked at the output of a Windows build using clang -Wall, and was horrified by the number of casual shadowings of generically-named global variables like 'term' and 'conf' with local variables of the same name. That seemed like a recipe for confusion, and I decided the best way to disambiguate them all was to do this refactoring that I'd wanted anyway for years. A few uses of the global variables occurred in functions that didn't have convenient access to the right WinGuiSeat via a callback parameter of some kind. Those had to be treated specially. Most were cleaned up in advance by the previous few commits; the remaining fixes in this commit itself were in functions like modalfatalbox(), nonfatal() and cleanup_exit(). The error reporting functions want the terminal HWND to use as a MessageBox parameter; they also have the side effect of un-hiding the mouse pointer in the terminal window, in case it's hidden; and cleanup_exit wanted to free some resources dangling off the WinGuiSeat. For most of those cases, I've made a linked list of all currently live WinGuiSeat structures, so that they can loop over _all_ live instances (whether there's one as usual, none, or maybe more than one in future). The parent window for non-connection-specific error messages is found by simply picking one arbitrarily off the linked list (if any); the cleanups are done by iterating over the _whole_ list. The mouse-pointer unhiding is dealt with by simply allowing show_mouseptr to take a _null_ WinGuiSeat pointer. The only thing it needs the context for at all is to check whether pointer-hiding is enabled in the session's Conf; so if we're _un_-hiding the pointer we don't need to check, and can unhide it unconditionally. The remaining global variables in window.c are the new linked list of all WinGuiSeat structures; 'wm_mousewheel' and 'trust_icon' which really should be global across all WinGuiSeats even if we were to have more than one; and there's a static variable 'cursor_visible' in show_mouseptr() which is likewise legitimately Seat-independent (since it records the last value we passed to the Win32 API ShowCursor function, and _that's_ global across the whole process state). All of this should cause no functional change whatsoever.
2022-09-13 08:00:19 +00:00
HDC wintw_hdc;
bool resizing;
windows/window.c: move more variables into WinGuiSeat. In commit f9e572595bb8cb6 I claimed that I'd removed very nearly all the global and static variables from windows/window.c. It turns out that this was wildly overoptimistic - I missed quite a few of them! I'm not quite sure how I managed that; my best guess is that I used an underpowered 'nm' command that failed to find some classes of variable. Some of the remaining function-scope statics were removed completely by commit afb3dab1e97a09f just now. In this commit, I've swept up some more and turn them into fields of WinGuiSeat, where they should have been moved last September. The (hopefully complete this time) list of remaining variables, generated by running this rune in the Windows build directory: nm windows/CMakeFiles/putty.dir/window.c.obj | grep -E '^([^ ]+)? *[bBcCdDgGsS] [^\.]' consists of the following variables which are legitimately global across the whole process and not related to a particular window: - 'hinst' and 'hprev', instance handles for Windows loadable modules - 'classname' in the terminal_window_class_a() and terminal_window_class_w() functions, which allocate a window class reusably - some pointers to Windows API functions retrieved via the DECL_WINDOWS_FUNCTION / GET_WINDOWS_FUNCTION system, such as p_AdjustWindowRectExForDpi and p_FlashWindowEx - some pointers to Windows API functions set up by assigning them at startup to the right one of the ANSI or Unicode version depending on the Windows version, e.g. sw_DefWindowProc and sw_DispatchMessage - 'unicode_window', a boolean flag set at the same time as those sw_Foo function pointers - 'sesslist', storing the last-retrieved version of the saved sessions menu - 'cursor_visible' in show_mouseptr() and 'forced_visible' in update_mouse_pointer(), each of which tracks the cumulative number of times that function has shown or hidden the mouse pointer, so as to manage its effect on the global state updated by ShowCursor - 'trust_icon', loaded from the executable's resources - 'wgslisthead', the list of all active WinGuiSeats - 'wm_mousewheel', the window-message id we use for mouse wheel events and the following which are nothing to do with our code: - '_OptionsStorage' in __local_stdio_printf_options() and __local_stdio_scanf_options(), which I'd never noticed before, but apparently are internal to a standard library header.
2023-05-27 13:59:20 +00:00
bool need_backend_resize;
windows/window.c: move (most) static vars into WinGuiSeat. This is a piece of refactoring that's been overdue forever. In the Unix front end, all the variables specific to a particular SSH session live in a big 'inst' structure, and calls to any of the trait APIs like Seat or TermWin can recover the right 'inst' from their input context pointer. But the Windows frontend was written before that kind of thing became habitual to me, and all its variables have been just lying around at the top level of window.c, and most of those context pointers were just ignored. Now I've swept them all up and put them where they ought to be, in a big context structure. This was made immeasurably easier by the very nifty 'clang-rename' tool, which can rename a single variable in a C source file, and find just the right set of identifiers to change even if other variables in the file have the same name, even in sub-scopes. So I started by clang-renaming all the top-level variables in question to have names beginning with a prefix that didn't previously appear anywhere in the code; checked that still worked; and then moved all the declarations into the struct type and did a purely textual search-and-replace of the prefix with 'wgs->'. One potential benefit of this change is that it allows more than one instance of the WinGuiSeat structure to exist in the same process. I don't have any immediate plans to actually do that, but it's nice to know it wouldn't be ruled out if we ever did need it. But that's not the main reason I did it. The main reason is that I recently looked at the output of a Windows build using clang -Wall, and was horrified by the number of casual shadowings of generically-named global variables like 'term' and 'conf' with local variables of the same name. That seemed like a recipe for confusion, and I decided the best way to disambiguate them all was to do this refactoring that I'd wanted anyway for years. A few uses of the global variables occurred in functions that didn't have convenient access to the right WinGuiSeat via a callback parameter of some kind. Those had to be treated specially. Most were cleaned up in advance by the previous few commits; the remaining fixes in this commit itself were in functions like modalfatalbox(), nonfatal() and cleanup_exit(). The error reporting functions want the terminal HWND to use as a MessageBox parameter; they also have the side effect of un-hiding the mouse pointer in the terminal window, in case it's hidden; and cleanup_exit wanted to free some resources dangling off the WinGuiSeat. For most of those cases, I've made a linked list of all currently live WinGuiSeat structures, so that they can loop over _all_ live instances (whether there's one as usual, none, or maybe more than one in future). The parent window for non-connection-specific error messages is found by simply picking one arbitrarily off the linked list (if any); the cleanups are done by iterating over the _whole_ list. The mouse-pointer unhiding is dealt with by simply allowing show_mouseptr to take a _null_ WinGuiSeat pointer. The only thing it needs the context for at all is to check whether pointer-hiding is enabled in the session's Conf; so if we're _un_-hiding the pointer we don't need to check, and can unhide it unconditionally. The remaining global variables in window.c are the new linked list of all WinGuiSeat structures; 'wm_mousewheel' and 'trust_icon' which really should be global across all WinGuiSeats even if we were to have more than one; and there's a static variable 'cursor_visible' in show_mouseptr() which is likewise legitimately Seat-independent (since it records the last value we passed to the Win32 API ShowCursor function, and _that's_ global across the whole process state). All of this should cause no functional change whatsoever.
2022-09-13 08:00:19 +00:00
long next_flash;
bool flashing;
windows/window.c: move more variables into WinGuiSeat. In commit f9e572595bb8cb6 I claimed that I'd removed very nearly all the global and static variables from windows/window.c. It turns out that this was wildly overoptimistic - I missed quite a few of them! I'm not quite sure how I managed that; my best guess is that I used an underpowered 'nm' command that failed to find some classes of variable. Some of the remaining function-scope statics were removed completely by commit afb3dab1e97a09f just now. In this commit, I've swept up some more and turn them into fields of WinGuiSeat, where they should have been moved last September. The (hopefully complete this time) list of remaining variables, generated by running this rune in the Windows build directory: nm windows/CMakeFiles/putty.dir/window.c.obj | grep -E '^([^ ]+)? *[bBcCdDgGsS] [^\.]' consists of the following variables which are legitimately global across the whole process and not related to a particular window: - 'hinst' and 'hprev', instance handles for Windows loadable modules - 'classname' in the terminal_window_class_a() and terminal_window_class_w() functions, which allocate a window class reusably - some pointers to Windows API functions retrieved via the DECL_WINDOWS_FUNCTION / GET_WINDOWS_FUNCTION system, such as p_AdjustWindowRectExForDpi and p_FlashWindowEx - some pointers to Windows API functions set up by assigning them at startup to the right one of the ANSI or Unicode version depending on the Windows version, e.g. sw_DefWindowProc and sw_DispatchMessage - 'unicode_window', a boolean flag set at the same time as those sw_Foo function pointers - 'sesslist', storing the last-retrieved version of the saved sessions menu - 'cursor_visible' in show_mouseptr() and 'forced_visible' in update_mouse_pointer(), each of which tracks the cumulative number of times that function has shown or hidden the mouse pointer, so as to manage its effect on the global state updated by ShowCursor - 'trust_icon', loaded from the executable's resources - 'wgslisthead', the list of all active WinGuiSeats - 'wm_mousewheel', the window-message id we use for mouse wheel events and the following which are nothing to do with our code: - '_OptionsStorage' in __local_stdio_printf_options() and __local_stdio_scanf_options(), which I'd never noticed before, but apparently are internal to a standard library header.
2023-05-27 13:59:20 +00:00
long last_beep_time;
bool ignore_clip;
bool fullscr_on_max;
bool processed_resize;
bool in_scrollbar_loop;
UINT last_mousemove;
WPARAM last_wm_mousemove_wParam, last_wm_ncmousemove_wParam;
LPARAM last_wm_mousemove_lParam, last_wm_ncmousemove_lParam;
wchar_t pending_surrogate;
GUI PuTTY: stop using the global 'hwnd'. This was the difficult part of cleaning up that global variable. The main Windows PuTTY GUI is split between source files, so that _does_ actually need to refer to the main window from multiple places. But all the places where windlg.c needed to use 'hwnd' are seat methods, so they were already receiving a Seat pointer as a parameter. In other words, the methods of the Windows GUI Seat were already split between source files. So it seems only fair that they should be able to share knowledge of the seat's data as well. Hence, I've created a small 'WinGuiSeat' structure which both window.c and windlg.c can see the layout of, and put the main terminal window handle in there. Then the seat methods implemented in windlg.c, like win_seat_verify_ssh_host_key, can use container_of to turn the Seat pointer parameter back into the address of that structure, just as the methods in window.c can do (even though they currently don't need to). (Who knows: now that it _exists_, perhaps that structure can be gradually expanded in future to turn it into a proper encapsulation of all the Windows frontend's state, like we should have had all along...) I've also moved the Windows GUI LogPolicy implementation into the same object (i.e. WinGuiSeat implements both traits at once). That allows win_gui_logging_error to recover the same WinGuiSeat from its input LogPolicy pointer, which means it can get from there to the Seat facet of the same object, so that I don't need the extern variable 'win_seat' any more either.
2020-02-02 10:00:43 +00:00
};
extern const LogPolicyVtable win_gui_logpolicy_vt; /* in dialog.c */
windows/window.c: move (most) static vars into WinGuiSeat. This is a piece of refactoring that's been overdue forever. In the Unix front end, all the variables specific to a particular SSH session live in a big 'inst' structure, and calls to any of the trait APIs like Seat or TermWin can recover the right 'inst' from their input context pointer. But the Windows frontend was written before that kind of thing became habitual to me, and all its variables have been just lying around at the top level of window.c, and most of those context pointers were just ignored. Now I've swept them all up and put them where they ought to be, in a big context structure. This was made immeasurably easier by the very nifty 'clang-rename' tool, which can rename a single variable in a C source file, and find just the right set of identifiers to change even if other variables in the file have the same name, even in sub-scopes. So I started by clang-renaming all the top-level variables in question to have names beginning with a prefix that didn't previously appear anywhere in the code; checked that still worked; and then moved all the declarations into the struct type and did a purely textual search-and-replace of the prefix with 'wgs->'. One potential benefit of this change is that it allows more than one instance of the WinGuiSeat structure to exist in the same process. I don't have any immediate plans to actually do that, but it's nice to know it wouldn't be ruled out if we ever did need it. But that's not the main reason I did it. The main reason is that I recently looked at the output of a Windows build using clang -Wall, and was horrified by the number of casual shadowings of generically-named global variables like 'term' and 'conf' with local variables of the same name. That seemed like a recipe for confusion, and I decided the best way to disambiguate them all was to do this refactoring that I'd wanted anyway for years. A few uses of the global variables occurred in functions that didn't have convenient access to the right WinGuiSeat via a callback parameter of some kind. Those had to be treated specially. Most were cleaned up in advance by the previous few commits; the remaining fixes in this commit itself were in functions like modalfatalbox(), nonfatal() and cleanup_exit(). The error reporting functions want the terminal HWND to use as a MessageBox parameter; they also have the side effect of un-hiding the mouse pointer in the terminal window, in case it's hidden; and cleanup_exit wanted to free some resources dangling off the WinGuiSeat. For most of those cases, I've made a linked list of all currently live WinGuiSeat structures, so that they can loop over _all_ live instances (whether there's one as usual, none, or maybe more than one in future). The parent window for non-connection-specific error messages is found by simply picking one arbitrarily off the linked list (if any); the cleanups are done by iterating over the _whole_ list. The mouse-pointer unhiding is dealt with by simply allowing show_mouseptr to take a _null_ WinGuiSeat pointer. The only thing it needs the context for at all is to check whether pointer-hiding is enabled in the session's Conf; so if we're _un_-hiding the pointer we don't need to check, and can unhide it unconditionally. The remaining global variables in window.c are the new linked list of all WinGuiSeat structures; 'wm_mousewheel' and 'trust_icon' which really should be global across all WinGuiSeats even if we were to have more than one; and there's a static variable 'cursor_visible' in show_mouseptr() which is likewise legitimately Seat-independent (since it records the last value we passed to the Win32 API ShowCursor function, and _that's_ global across the whole process state). All of this should cause no functional change whatsoever.
2022-09-13 08:00:19 +00:00
static inline void wgs_link(WinGuiSeat *wgs)
{
wgs->wgslistnode.prev = wgslisthead.prev;
wgs->wgslistnode.next = &wgslisthead;
wgs->wgslistnode.prev->next = &wgs->wgslistnode;
wgs->wgslistnode.next->prev = &wgs->wgslistnode;
}
static inline void wgs_unlink(WinGuiSeat *wgs)
{
wgs->wgslistnode.prev->next = wgs->wgslistnode.next;
wgs->wgslistnode.next->prev = wgs->wgslistnode.prev;
}