]>
Commit | Line | Data |
---|---|---|
1fd5e000 CF |
1 | /* window.cc: hidden windows for signals/itimer support |
2 | ||
bc837d22 CF |
3 | Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2010, 2011 |
4 | Red Hat, Inc. | |
1fd5e000 CF |
5 | |
6 | Written by Sergey Okhapkin <sos@prospect.com.ru> | |
7 | ||
8 | This file is part of Cygwin. | |
9 | ||
10 | This software is a copyrighted work licensed under the terms of the | |
11 | Cygwin license. Please consult the file "CYGWIN_LICENSE" for | |
12 | details. */ | |
13 | ||
4c8d72de | 14 | #include "winsup.h" |
1fd5e000 | 15 | #include <sys/time.h> |
d0b178fe DD |
16 | #include <wingdi.h> |
17 | #include <winuser.h> | |
d6154fb7 CV |
18 | #define USE_SYS_TYPES_FD_SET |
19 | #include <winsock2.h> | |
f0338f54 | 20 | #include "perprocess.h" |
0c565ab3 CF |
21 | #include "cygtls.h" |
22 | #include "sync.h" | |
23 | #include "wininfo.h" | |
1fd5e000 | 24 | |
0c565ab3 | 25 | wininfo NO_COPY winmsg; |
1fd5e000 | 26 | |
322c131f | 27 | muto NO_COPY wininfo::_lock; |
0c565ab3 CF |
28 | |
29 | int __stdcall | |
30 | wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | |
1fd5e000 CF |
31 | { |
32 | #ifndef NOSTRACE | |
5abc9b83 | 33 | strace.wm (uMsg, wParam, lParam); |
1fd5e000 CF |
34 | #endif |
35 | switch (uMsg) | |
36 | { | |
37 | case WM_PAINT: | |
38 | return 0; | |
39 | case WM_DESTROY: | |
40 | PostQuitMessage (0); | |
41 | return 0; | |
1fd5e000 | 42 | case WM_ASYNCIO: |
f0227ea3 | 43 | if (WSAGETSELECTEVENT (lParam) == FD_OOB) |
2402700d | 44 | raise (SIGURG); |
d6154fb7 CV |
45 | else |
46 | raise (SIGIO); | |
1fd5e000 CF |
47 | return 0; |
48 | default: | |
79e741ef | 49 | return DefWindowProcW (hwnd, uMsg, wParam, lParam); |
1fd5e000 CF |
50 | } |
51 | } | |
52 | ||
0c565ab3 CF |
53 | static LRESULT CALLBACK |
54 | process_window_events (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | |
55 | { | |
56 | return winmsg.process (hwnd, uMsg, wParam, lParam); | |
57 | } | |
1fd5e000 | 58 | |
0c565ab3 CF |
59 | /* Handle windows events. Inherits ownership of the wininfo lock */ |
60 | DWORD WINAPI | |
61 | wininfo::winthread () | |
1fd5e000 CF |
62 | { |
63 | MSG msg; | |
79e741ef CV |
64 | WNDCLASSW wc; |
65 | static NO_COPY WCHAR classname[] = L"CygwinWndClass"; | |
1fd5e000 | 66 | |
322c131f | 67 | _lock.grab (); |
1fd5e000 CF |
68 | /* Register the window class for the main window. */ |
69 | ||
70 | wc.style = 0; | |
0c565ab3 | 71 | wc.lpfnWndProc = (WNDPROC) process_window_events; |
1fd5e000 CF |
72 | wc.cbClsExtra = 0; |
73 | wc.cbWndExtra = 0; | |
74 | wc.hInstance = user_data->hmodule; | |
75 | wc.hIcon = NULL; | |
76 | wc.hCursor = NULL; | |
77 | wc.hbrBackground = NULL; | |
78 | wc.lpszMenuName = NULL; | |
79 | wc.lpszClassName = classname; | |
80 | ||
79e741ef | 81 | if (!RegisterClassW (&wc)) |
0c565ab3 | 82 | api_fatal ("cannot register window class, %E"); |
1fd5e000 CF |
83 | |
84 | /* Create hidden window. */ | |
79e741ef CV |
85 | hwnd = CreateWindowExW (0, classname, classname, WS_POPUP, CW_USEDEFAULT, |
86 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, | |
87 | (HWND) NULL, (HMENU) NULL, user_data->hmodule, | |
88 | (LPVOID) NULL); | |
0c565ab3 CF |
89 | if (!hwnd) |
90 | api_fatal ("couldn't create window, %E"); | |
ec98d19a | 91 | release (); |
aafd8a54 | 92 | |
79e741ef CV |
93 | int ret; |
94 | while ((ret = (int) GetMessageW (&msg, hwnd, 0, 0)) > 0) | |
95 | DispatchMessageW (&msg); | |
1fd5e000 | 96 | |
c350feda | 97 | return 0; |
1fd5e000 CF |
98 | } |
99 | ||
0c565ab3 CF |
100 | static DWORD WINAPI |
101 | winthread (VOID *arg) | |
1fd5e000 | 102 | { |
0c565ab3 CF |
103 | return ((wininfo *) arg)->winthread (); |
104 | } | |
105 | ||
106 | wininfo::operator | |
107 | HWND () | |
108 | { | |
109 | if (hwnd) | |
110 | return hwnd; | |
111 | ||
ec98d19a | 112 | lock (); |
0c565ab3 CF |
113 | if (!hwnd) |
114 | { | |
322c131f | 115 | _lock.upforgrabs (); |
b9874a0c | 116 | cygthread *h = new cygthread (::winthread, this, "win"); |
0c565ab3 CF |
117 | h->SetThreadPriority (THREAD_PRIORITY_HIGHEST); |
118 | h->zap_h (); | |
ec98d19a | 119 | lock (); |
0c565ab3 | 120 | } |
ec98d19a | 121 | release (); |
0c565ab3 | 122 | return hwnd; |
1fd5e000 CF |
123 | } |
124 | ||
ec98d19a CF |
125 | void |
126 | wininfo::lock () | |
4d029f39 | 127 | { |
322c131f | 128 | _lock.init ("wininfo_lock")->acquire (); |
4d029f39 CF |
129 | } |
130 | ||
ec98d19a CF |
131 | void |
132 | wininfo::release () | |
db3137cc | 133 | { |
322c131f | 134 | _lock.release (); |
db3137cc | 135 | } |