Added an unknown VxD error code.
[wine] / dlls / x11drv / desktop.c
1 /*
2  * X11DRV desktop window handling
3  *
4  * Copyright 2001 Alexandre Julliard
5  */
6
7 #include "config.h"
8 #include <X11/cursorfont.h>
9
10 #include "ts_xlib.h"
11
12 #include "win.h"
13 #include "x11drv.h"
14 #include "debugtools.h"
15
16 DEFAULT_DEBUG_CHANNEL(x11drv);
17
18
19 /* desktop window procedure */
20 static LRESULT WINAPI desktop_winproc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
21 {
22     switch(message)
23     {
24     case WM_ERASEBKGND:
25         PaintDesktop( (HDC)wParam );
26         ValidateRect( hwnd, NULL );
27         break;
28
29     case WM_SYSCOMMAND:
30         if ((wParam & 0xfff0) == SC_CLOSE) ExitWindows( 0, 0 );
31         break;
32
33     case WM_SETCURSOR:
34         return SetCursor( LoadCursorA( 0, IDC_ARROWA ) );
35
36     case WM_NCHITTEST:
37         return HTCLIENT;
38     }
39     return 0;
40 }
41
42
43 /* desktop window manager thread */
44 static DWORD CALLBACK desktop_thread( LPVOID driver_data )
45 {
46     Display *display;
47     MSG msg;
48     HWND hwnd;
49     WND *win;
50
51     NtCurrentTeb()->driver_data = driver_data;
52     display = thread_display();
53     hwnd = GetDesktopWindow();
54
55     /* patch the desktop window queue to point to our queue */
56     win = WIN_FindWndPtr( hwnd );
57     win->hmemTaskQ = GetFastQueue16();
58     WIN_ReleaseWndPtr( win );
59
60     SetWindowLongW( hwnd, GWL_WNDPROC, (LONG)desktop_winproc );
61     X11DRV_register_window( display, hwnd, root_window );
62     TSXMapWindow( display, root_window );
63
64     while (GetMessageW( &msg, hwnd, 0, 0 )) DispatchMessageW( &msg );
65     return 0;
66 }
67
68
69 /***********************************************************************
70  *              X11DRV_create_desktop_thread
71  *
72  * Create the thread that manages the desktop window
73  */
74 void X11DRV_create_desktop_thread(void)
75 {
76     HANDLE handle = CreateThread( NULL, 0, desktop_thread, NtCurrentTeb()->driver_data, 0, NULL );
77     if (!handle)
78     {
79         MESSAGE( "Could not create desktop thread\n" );
80         ExitProcess(1);
81     }
82     /* we transferred our driver data to the new thread */
83     NtCurrentTeb()->driver_data = NULL;
84     CloseHandle( handle );
85 }
86
87
88 /***********************************************************************
89  *              X11DRV_create_desktop
90  *
91  * Create the X11 desktop window for the desktop mode.
92  */
93 Window X11DRV_create_desktop( XVisualInfo *desktop_vi, const char *geometry )
94 {
95     int x = 0, y = 0, flags;
96     unsigned int width = 640, height = 480;  /* Default size = 640x480 */
97     char *name = "Wine desktop";
98     XSizeHints *size_hints;
99     XWMHints   *wm_hints;
100     XClassHint *class_hints;
101     XSetWindowAttributes win_attr;
102     XTextProperty window_name;
103     Window win;
104     Display *display = thread_display();
105
106     wine_tsx11_lock();
107     flags = XParseGeometry( geometry, &x, &y, &width, &height );
108     screen_width  = width;
109     screen_height = height;
110
111     /* Create window */
112     win_attr.background_pixel = BlackPixel(display, 0);
113     win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
114                           PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
115     win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
116
117     if (desktop_vi)
118         win_attr.colormap = XCreateColormap( display, DefaultRootWindow(display),
119                                              visual, AllocNone );
120     else
121         win_attr.colormap = None;
122
123     win = XCreateWindow( display, DefaultRootWindow(display),
124                          x, y, width, height, 0, screen_depth, InputOutput, visual,
125                          CWBackPixel | CWEventMask | CWCursor | CWColormap, &win_attr );
126
127     /* Set window manager properties */
128     size_hints  = XAllocSizeHints();
129     wm_hints    = XAllocWMHints();
130     class_hints = XAllocClassHint();
131     if (!size_hints || !wm_hints || !class_hints)
132     {
133         MESSAGE("Not enough memory for window manager hints.\n" );
134         ExitProcess(1);
135     }
136     size_hints->min_width = size_hints->max_width = width;
137     size_hints->min_height = size_hints->max_height = height;
138     size_hints->flags = PMinSize | PMaxSize;
139     if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
140     if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
141     else size_hints->flags |= PSize;
142
143     wm_hints->flags = InputHint | StateHint;
144     wm_hints->input = True;
145     wm_hints->initial_state = NormalState;
146     class_hints->res_name  = "wine";
147     class_hints->res_class = "Wine";
148
149     XStringListToTextProperty( &name, 1, &window_name );
150     XSetWMProperties( display, win, &window_name, &window_name,
151                       NULL, 0, size_hints, wm_hints, class_hints );
152     XFree( size_hints );
153     XFree( wm_hints );
154     XFree( class_hints );
155     XFlush( display );
156     wine_tsx11_unlock();
157     return win;
158 }