]> sourceware.org Git - newlib-cygwin.git/blame - winsup/cygwin/window.cc
newlib: Add more FreeBSD files for non LDBL_EQ_DBL support
[newlib-cygwin.git] / winsup / cygwin / window.cc
CommitLineData
1fd5e000
CF
1/* window.cc: hidden windows for signals/itimer support
2
1fd5e000
CF
3 Written by Sergey Okhapkin <sos@prospect.com.ru>
4
5This file is part of Cygwin.
6
7This software is a copyrighted work licensed under the terms of the
8Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9details. */
10
4c8d72de 11#include "winsup.h"
1fd5e000 12#include <sys/time.h>
d6154fb7
CV
13#define USE_SYS_TYPES_FD_SET
14#include <winsock2.h>
f0338f54 15#include "perprocess.h"
0c565ab3
CF
16#include "cygtls.h"
17#include "sync.h"
18#include "wininfo.h"
1fd5e000 19
0c565ab3 20wininfo NO_COPY winmsg;
1fd5e000 21
322c131f 22muto NO_COPY wininfo::_lock;
0c565ab3 23
2126f966 24int
0c565ab3 25wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1fd5e000
CF
26{
27#ifndef NOSTRACE
5abc9b83 28 strace.wm (uMsg, wParam, lParam);
1fd5e000
CF
29#endif
30 switch (uMsg)
31 {
32 case WM_PAINT:
33 return 0;
34 case WM_DESTROY:
35 PostQuitMessage (0);
36 return 0;
1fd5e000 37 case WM_ASYNCIO:
f0227ea3 38 if (WSAGETSELECTEVENT (lParam) == FD_OOB)
2402700d 39 raise (SIGURG);
d6154fb7
CV
40 else
41 raise (SIGIO);
1fd5e000
CF
42 return 0;
43 default:
79e741ef 44 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1fd5e000
CF
45 }
46}
47
0c565ab3
CF
48static LRESULT CALLBACK
49process_window_events (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
50{
51 return winmsg.process (hwnd, uMsg, wParam, lParam);
52}
1fd5e000 53
0c565ab3 54/* Handle windows events. Inherits ownership of the wininfo lock */
b28edc7b 55DWORD
0c565ab3 56wininfo::winthread ()
1fd5e000
CF
57{
58 MSG msg;
79e741ef
CV
59 WNDCLASSW wc;
60 static NO_COPY WCHAR classname[] = L"CygwinWndClass";
1fd5e000 61
322c131f 62 _lock.grab ();
1fd5e000
CF
63 /* Register the window class for the main window. */
64
65 wc.style = 0;
0c565ab3 66 wc.lpfnWndProc = (WNDPROC) process_window_events;
1fd5e000
CF
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;
75
79e741ef 76 if (!RegisterClassW (&wc))
0c565ab3 77 api_fatal ("cannot register window class, %E");
1fd5e000
CF
78
79 /* Create hidden window. */
79e741ef
CV
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);
0c565ab3
CF
84 if (!hwnd)
85 api_fatal ("couldn't create window, %E");
ec98d19a 86 release ();
aafd8a54 87
79e741ef
CV
88 int ret;
89 while ((ret = (int) GetMessageW (&msg, hwnd, 0, 0)) > 0)
90 DispatchMessageW (&msg);
1fd5e000 91
c350feda 92 return 0;
1fd5e000
CF
93}
94
b28edc7b 95static DWORD
0c565ab3 96winthread (VOID *arg)
1fd5e000 97{
0c565ab3
CF
98 return ((wininfo *) arg)->winthread ();
99}
100
101wininfo::operator
102HWND ()
103{
104 if (hwnd)
105 return hwnd;
106
ec98d19a 107 lock ();
0c565ab3
CF
108 if (!hwnd)
109 {
322c131f 110 _lock.upforgrabs ();
b9874a0c 111 cygthread *h = new cygthread (::winthread, this, "win");
0c565ab3
CF
112 h->SetThreadPriority (THREAD_PRIORITY_HIGHEST);
113 h->zap_h ();
ec98d19a 114 lock ();
0c565ab3 115 }
ec98d19a 116 release ();
0c565ab3 117 return hwnd;
1fd5e000
CF
118}
119
ec98d19a
CF
120void
121wininfo::lock ()
4d029f39 122{
322c131f 123 _lock.init ("wininfo_lock")->acquire ();
4d029f39
CF
124}
125
ec98d19a
CF
126void
127wininfo::release ()
db3137cc 128{
322c131f 129 _lock.release ();
db3137cc 130}
This page took 0.721021 seconds and 6 git commands to generate.