File: gui-timing.c

package info (click to toggle)
putty 0.83-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,216 kB
  • sloc: ansic: 148,476; python: 8,466; perl: 1,830; makefile: 128; sh: 117
file content (56 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
}