Documentation fixes.
[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     X11DRV_register_window( display, hwnd, win->pDriverData );
59     WIN_ReleaseWndPtr( win );
60
61     SetWindowLongW( hwnd, GWL_WNDPROC, (LONG)desktop_winproc );
62     wine_tsx11_lock();
63     XSetWMProtocols( display, root_window, &wmDeleteWindow, 1 );
64     XMapWindow( display, root_window );
65     wine_tsx11_unlock();
66
67     while (GetMessageW( &msg, hwnd, 0, 0 )) DispatchMessageW( &msg );
68     return 0;
69 }
70
71
72 /***********************************************************************
73  *              X11DRV_create_desktop_thread
74  *
75  * Create the thread that manages the desktop window
76  */
77 void X11DRV_create_desktop_thread(void)
78 {
79     HANDLE handle = CreateThread( NULL, 0, desktop_thread, NtCurrentTeb()->driver_data, 0, NULL );
80     if (!handle)
81     {
82         MESSAGE( "Could not create desktop thread\n" );
83         ExitProcess(1);
84     }
85     /* we transferred our driver data to the new thread */
86     NtCurrentTeb()->driver_data = NULL;
87     CloseHandle( handle );
88 }
89
90
91 /***********************************************************************
92  *              X11DRV_create_desktop
93  *
94  * Create the X11 desktop window for the desktop mode.
95  */
96 Window X11DRV_create_desktop( XVisualInfo *desktop_vi, const char *geometry )
97 {
98     int x = 0, y = 0, flags;
99     unsigned int width = 640, height = 480;  /* Default size = 640x480 */
100     char *name = "Wine desktop";
101     XSizeHints *size_hints;
102     XWMHints   *wm_hints;
103     XClassHint *class_hints;
104     XSetWindowAttributes win_attr;
105     XTextProperty window_name;
106     Window win;
107     Display *display = thread_display();
108
109     wine_tsx11_lock();
110     flags = XParseGeometry( geometry, &x, &y, &width, &height );
111     screen_width  = width;
112     screen_height = height;
113
114     /* Create window */
115     win_attr.background_pixel = BlackPixel(display, 0);
116     win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
117                           PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
118     win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
119
120     if (desktop_vi)
121         win_attr.colormap = XCreateColormap( display, DefaultRootWindow(display),
122                                              visual, AllocNone );
123     else
124         win_attr.colormap = None;
125
126     win = XCreateWindow( display, DefaultRootWindow(display),
127                          x, y, width, height, 0, screen_depth, InputOutput, visual,
128                          CWBackPixel | CWEventMask | CWCursor | CWColormap, &win_attr );
129
130     /* Set window manager properties */
131     size_hints  = XAllocSizeHints();
132     wm_hints    = XAllocWMHints();
133     class_hints = XAllocClassHint();
134     if (!size_hints || !wm_hints || !class_hints)
135     {
136         MESSAGE("Not enough memory for window manager hints.\n" );
137         ExitProcess(1);
138     }
139     size_hints->min_width = size_hints->max_width = width;
140     size_hints->min_height = size_hints->max_height = height;
141     size_hints->flags = PMinSize | PMaxSize;
142     if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
143     if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
144     else size_hints->flags |= PSize;
145
146     wm_hints->flags = InputHint | StateHint;
147     wm_hints->input = True;
148     wm_hints->initial_state = NormalState;
149     class_hints->res_name  = "wine";
150     class_hints->res_class = "Wine";
151
152     XStringListToTextProperty( &name, 1, &window_name );
153     XSetWMProperties( display, win, &window_name, &window_name,
154                       NULL, 0, size_hints, wm_hints, class_hints );
155     XFree( size_hints );
156     XFree( wm_hints );
157     XFree( class_hints );
158     XFlush( display );
159     wine_tsx11_unlock();
160     return win;
161 }