mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-22 14:39:24 -05:00
Windows: move GUI timer handling into a utils module.
Previously, the timing.c subsystem worked in Windows PuTTY by means of scheduling WM_TIMER messages to be sent to the terminal window. Now it uses a separate hidden window instead, and all the machinery for handling that window lives on its own in windows/utils/gui-timing.c. Most immediately, this removes a use of wgs.term_hwnd that will become awkward when I move that structure in a following commit. But also, it will make it easier to add the same timing subsystem to unrelated GUI programs, such as Windows Pageant: if we ever decide to implement automatic deletion or re-encryption of unused keys after a timeout, this will help make that easier.
This commit is contained in:
parent
307e909b51
commit
c674b2da4f
@ -16,6 +16,7 @@ add_sources_from_current_dir(utils
|
|||||||
utils/getdlgitemtext_alloc.c
|
utils/getdlgitemtext_alloc.c
|
||||||
utils/get_system_dir.c
|
utils/get_system_dir.c
|
||||||
utils/get_username.c
|
utils/get_username.c
|
||||||
|
utils/gui-timing.c
|
||||||
utils/interprocess_mutex.c
|
utils/interprocess_mutex.c
|
||||||
utils/is_console_handle.c
|
utils/is_console_handle.c
|
||||||
utils/load_system32_dll.c
|
utils/load_system32_dll.c
|
||||||
|
@ -793,4 +793,6 @@ bool aux_match_done(AuxMatchOpt *amo);
|
|||||||
char *save_screenshot(HWND hwnd, const char *outfile);
|
char *save_screenshot(HWND hwnd, const char *outfile);
|
||||||
void gui_terminal_ready(HWND hwnd, Seat *seat, Backend *backend);
|
void gui_terminal_ready(HWND hwnd, Seat *seat, Backend *backend);
|
||||||
|
|
||||||
|
void setup_gui_timing(void);
|
||||||
|
|
||||||
#endif /* PUTTY_WINDOWS_PLATFORM_H */
|
#endif /* PUTTY_WINDOWS_PLATFORM_H */
|
||||||
|
56
windows/utils/gui-timing.c
Normal file
56
windows/utils/gui-timing.c
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "putty.h"
|
||||||
|
|
||||||
|
#define TIMING_CLASS_NAME "PuTTYTimerWindow"
|
||||||
|
#define TIMING_TIMER_ID 1234
|
||||||
|
static long timing_next_time;
|
||||||
|
static HWND timing_hwnd;
|
||||||
|
|
||||||
|
static LRESULT CALLBACK TimingWndProc(HWND hwnd, UINT message,
|
||||||
|
WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
switch (message) {
|
||||||
|
case WM_TIMER:
|
||||||
|
if ((UINT_PTR)wParam == TIMING_TIMER_ID) {
|
||||||
|
unsigned long next;
|
||||||
|
|
||||||
|
KillTimer(hwnd, TIMING_TIMER_ID);
|
||||||
|
if (run_timers(timing_next_time, &next)) {
|
||||||
|
timer_change_notify(next);
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return DefWindowProc(hwnd, message, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup_gui_timing(void)
|
||||||
|
{
|
||||||
|
WNDCLASS wndclass;
|
||||||
|
|
||||||
|
memset(&wndclass, 0, sizeof(wndclass));
|
||||||
|
wndclass.lpfnWndProc = TimingWndProc;
|
||||||
|
wndclass.hInstance = hinst;
|
||||||
|
wndclass.lpszClassName = TIMING_CLASS_NAME;
|
||||||
|
|
||||||
|
RegisterClass(&wndclass);
|
||||||
|
|
||||||
|
timing_hwnd = CreateWindow(
|
||||||
|
TIMING_CLASS_NAME, "PuTTY: hidden timing window",
|
||||||
|
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||||
|
100, 100, NULL, NULL, hinst, NULL);
|
||||||
|
ShowWindow(timing_hwnd, SW_HIDE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void timer_change_notify(unsigned long next)
|
||||||
|
{
|
||||||
|
unsigned long now = GETTICKCOUNT();
|
||||||
|
long ticks;
|
||||||
|
if (now - next < INT_MAX)
|
||||||
|
ticks = 0;
|
||||||
|
else
|
||||||
|
ticks = next - now;
|
||||||
|
KillTimer(timing_hwnd, TIMING_TIMER_ID);
|
||||||
|
SetTimer(timing_hwnd, TIMING_TIMER_ID, ticks, NULL);
|
||||||
|
timing_next_time = next;
|
||||||
|
}
|
@ -142,9 +142,6 @@ static const SessionSpecial *specials = NULL;
|
|||||||
static HMENU specials_menu = NULL;
|
static HMENU specials_menu = NULL;
|
||||||
static int n_specials = 0;
|
static int n_specials = 0;
|
||||||
|
|
||||||
#define TIMING_TIMER_ID 1234
|
|
||||||
static long timing_next_time;
|
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
HMENU menu;
|
HMENU menu;
|
||||||
} popup_menus[2];
|
} popup_menus[2];
|
||||||
@ -564,6 +561,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
|||||||
|
|
||||||
init_winfuncs();
|
init_winfuncs();
|
||||||
|
|
||||||
|
setup_gui_timing();
|
||||||
|
|
||||||
conf = conf_new();
|
conf = conf_new();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2106,19 +2105,6 @@ static void win_seat_notify_remote_exit(Seat *seat)
|
|||||||
queue_toplevel_callback(exit_callback, NULL);
|
queue_toplevel_callback(exit_callback, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_change_notify(unsigned long next)
|
|
||||||
{
|
|
||||||
unsigned long now = GETTICKCOUNT();
|
|
||||||
long ticks;
|
|
||||||
if (now - next < INT_MAX)
|
|
||||||
ticks = 0;
|
|
||||||
else
|
|
||||||
ticks = next - now;
|
|
||||||
KillTimer(wgs.term_hwnd, TIMING_TIMER_ID);
|
|
||||||
SetTimer(wgs.term_hwnd, TIMING_TIMER_ID, ticks, NULL);
|
|
||||||
timing_next_time = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void conf_cache_data(void)
|
static void conf_cache_data(void)
|
||||||
{
|
{
|
||||||
/* Cache some items from conf to speed lookups in very hot code */
|
/* Cache some items from conf to speed lookups in very hot code */
|
||||||
@ -2195,17 +2181,6 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
|||||||
int resize_action;
|
int resize_action;
|
||||||
|
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case WM_TIMER:
|
|
||||||
if ((UINT_PTR)wParam == TIMING_TIMER_ID) {
|
|
||||||
unsigned long next;
|
|
||||||
|
|
||||||
KillTimer(hwnd, TIMING_TIMER_ID);
|
|
||||||
if (run_timers(timing_next_time, &next)) {
|
|
||||||
timer_change_notify(next);
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
break;
|
break;
|
||||||
case WM_CLOSE: {
|
case WM_CLOSE: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user