Cygwin: add newgrp release notes
[newlib-cygwin.git] / winsup / cygwin / window.cc
blob69430326aa362eacb407f4a383687f46a5bb4dd1
1 /* window.cc: hidden windows for signals/itimer support
3 Written by Sergey Okhapkin <sos@prospect.com.ru>
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 details. */
11 #include "winsup.h"
12 #include <sys/time.h>
13 #define USE_SYS_TYPES_FD_SET
14 #include <winsock2.h>
15 #include "perprocess.h"
16 #include "cygtls.h"
17 #include "sync.h"
18 #include "wininfo.h"
20 wininfo NO_COPY winmsg;
22 muto NO_COPY wininfo::_lock;
24 int
25 wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
27 #ifndef NOSTRACE
28 strace.wm (uMsg, wParam, lParam);
29 #endif
30 switch (uMsg)
32 case WM_PAINT:
33 return 0;
34 case WM_DESTROY:
35 PostQuitMessage (0);
36 return 0;
37 case WM_ASYNCIO:
38 if (WSAGETSELECTEVENT (lParam) == FD_OOB)
39 raise (SIGURG);
40 else
41 raise (SIGIO);
42 return 0;
43 default:
44 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
48 static LRESULT CALLBACK
49 process_window_events (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
51 return winmsg.process (hwnd, uMsg, wParam, lParam);
54 /* Handle windows events. Inherits ownership of the wininfo lock */
55 DWORD
56 wininfo::winthread ()
58 MSG msg;
59 WNDCLASSW wc;
60 static NO_COPY WCHAR classname[] = L"CygwinWndClass";
62 _lock.grab ();
63 /* Register the window class for the main window. */
65 wc.style = 0;
66 wc.lpfnWndProc = (WNDPROC) process_window_events;
67 wc.cbClsExtra = 0;
68 wc.cbWndExtra = 0;
69 wc.hInstance = user_data->hmodule;
70 wc.hIcon = NULL;
71 wc.hCursor = NULL;
72 wc.hbrBackground = NULL;
73 wc.lpszMenuName = NULL;
74 wc.lpszClassName = classname;
76 if (!RegisterClassW (&wc))
77 api_fatal ("cannot register window class, %E");
79 /* Create hidden window. */
80 hwnd = CreateWindowExW (0, classname, classname, WS_POPUP, CW_USEDEFAULT,
81 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
82 (HWND) NULL, (HMENU) NULL, user_data->hmodule,
83 (LPVOID) NULL);
84 if (!hwnd)
85 api_fatal ("couldn't create window, %E");
86 release ();
88 int ret;
89 while ((ret = (int) GetMessageW (&msg, hwnd, 0, 0)) > 0)
90 DispatchMessageW (&msg);
92 return 0;
95 static DWORD
96 winthread (VOID *arg)
98 return ((wininfo *) arg)->winthread ();
101 wininfo::operator
102 HWND ()
104 if (hwnd)
105 return hwnd;
107 lock ();
108 if (!hwnd)
110 _lock.upforgrabs ();
111 cygthread *h = new cygthread (::winthread, this, "win");
112 h->SetThreadPriority (THREAD_PRIORITY_HIGHEST);
113 h->zap_h ();
114 lock ();
116 release ();
117 return hwnd;
120 void
121 wininfo::lock ()
123 _lock.init ("wininfo_lock")->acquire ();
126 void
127 wininfo::release ()
129 _lock.release ();