When using desktop mode attach all thread inputs together, so that
[wine] / include / x11drv.h
1 /*
2  * X11 driver definitions
3  *
4  * Copyright 1996 Alexandre Julliard
5  * Copyright 1999 Patrik Stridvall
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef __WINE_X11DRV_H
23 #define __WINE_X11DRV_H
24
25 #ifndef __WINE_CONFIG_H
26 # error You must include config.h to use this header
27 #endif
28
29 #include <X11/Xlib.h>
30 #include <X11/Xresource.h>
31 #include <X11/Xutil.h>
32 #include <X11/Xatom.h>
33 #ifdef HAVE_LIBXXSHM
34 # include <X11/extensions/XShm.h>
35 #endif /* defined(HAVE_LIBXXSHM) */
36
37 #undef Status  /* avoid conflict with wintrnl.h */
38 typedef int Status;
39
40 #include "windef.h"
41 #include "winbase.h"
42 #include "gdi.h"
43 #include "user.h"
44 #include "win.h"
45 #include "thread.h"
46
47 #define MAX_PIXELFORMATS 8
48
49 struct tagBITMAPOBJ;
50 struct tagCURSORICONINFO;
51 struct tagPALETTEOBJ;
52 struct tagWINDOWPOS;
53
54   /* X physical pen */
55 typedef struct
56 {
57     int          style;
58     int          endcap;
59     int          linejoin;
60     int          pixel;
61     int          width;
62     char *       dashes;
63     int          dash_len;
64     int          type;          /* GEOMETRIC || COSMETIC */
65 } X_PHYSPEN;
66
67   /* X physical brush */
68 typedef struct
69 {
70     int          style;
71     int          fillStyle;
72     int          pixel;
73     Pixmap       pixmap;
74 } X_PHYSBRUSH;
75
76   /* X physical font */
77 typedef UINT     X_PHYSFONT;
78
79 typedef struct tagXRENDERINFO *XRENDERINFO;
80
81   /* X physical device */
82 typedef struct
83 {
84     HDC           hdc;
85     DC           *dc;          /* direct pointer to DC, should go away */
86     GC            gc;          /* X Window GC */
87     Drawable      drawable;
88     POINT         org;          /* DC origin relative to drawable */
89     POINT         drawable_org; /* Origin of drawable relative to screen */
90     X_PHYSFONT    font;
91     X_PHYSPEN     pen;
92     X_PHYSBRUSH   brush;
93     int           backgroundPixel;
94     int           textPixel;
95     int           exposures;   /* count of graphics exposures operations */
96     XVisualInfo  *visuals[MAX_PIXELFORMATS];
97     int           used_visuals;
98     int           current_pf;
99     XRENDERINFO   xrender;
100 } X11DRV_PDEVICE;
101
102
103   /* GCs used for B&W and color bitmap operations */
104 extern GC BITMAP_monoGC, BITMAP_colorGC;
105 extern Pixmap BITMAP_stock_pixmap;   /* pixmap for the default stock bitmap */
106
107 #define BITMAP_GC(bmp) \
108   (((bmp)->bitmap.bmBitsPixel == 1) ? BITMAP_monoGC : BITMAP_colorGC)
109
110 extern unsigned int X11DRV_server_startticks;
111
112 /* Wine driver X11 functions */
113
114 extern BOOL X11DRV_BitBlt( X11DRV_PDEVICE *physDevDst, INT xDst, INT yDst,
115                              INT width, INT height, X11DRV_PDEVICE *physDevSrc,
116                              INT xSrc, INT ySrc, DWORD rop );
117 extern BOOL X11DRV_EnumDeviceFonts( X11DRV_PDEVICE *physDev, LPLOGFONTW plf,
118                                     DEVICEFONTENUMPROC dfeproc, LPARAM lp );
119 extern LONG X11DRV_GetBitmapBits( HBITMAP hbitmap, void *bits, LONG count );
120 extern BOOL X11DRV_GetCharWidth( X11DRV_PDEVICE *physDev, UINT firstChar,
121                                    UINT lastChar, LPINT buffer );
122 extern BOOL X11DRV_GetDCOrgEx( X11DRV_PDEVICE *physDev, LPPOINT lpp );
123 extern BOOL X11DRV_GetTextExtentPoint( X11DRV_PDEVICE *physDev, LPCWSTR str,
124                                          INT count, LPSIZE size );
125 extern BOOL X11DRV_GetTextMetrics(X11DRV_PDEVICE *physDev, TEXTMETRICW *metrics);
126 extern BOOL X11DRV_PatBlt( X11DRV_PDEVICE *physDev, INT left, INT top,
127                              INT width, INT height, DWORD rop );
128 extern BOOL X11DRV_StretchBlt( X11DRV_PDEVICE *physDevDst, INT xDst, INT yDst,
129                                  INT widthDst, INT heightDst,
130                                  X11DRV_PDEVICE *physDevSrc, INT xSrc, INT ySrc,
131                                  INT widthSrc, INT heightSrc, DWORD rop );
132 extern BOOL X11DRV_LineTo( X11DRV_PDEVICE *physDev, INT x, INT y);
133 extern BOOL X11DRV_Arc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
134                           INT bottom, INT xstart, INT ystart, INT xend,
135                           INT yend );
136 extern BOOL X11DRV_Pie( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
137                           INT bottom, INT xstart, INT ystart, INT xend,
138                           INT yend );
139 extern BOOL X11DRV_Chord( X11DRV_PDEVICE *physDev, INT left, INT top,
140                             INT right, INT bottom, INT xstart,
141                             INT ystart, INT xend, INT yend );
142 extern BOOL X11DRV_Ellipse( X11DRV_PDEVICE *physDev, INT left, INT top,
143                               INT right, INT bottom );
144 extern BOOL X11DRV_Rectangle(X11DRV_PDEVICE *physDev, INT left, INT top,
145                               INT right, INT bottom);
146 extern BOOL X11DRV_RoundRect( X11DRV_PDEVICE *physDev, INT left, INT top,
147                                 INT right, INT bottom, INT ell_width,
148                                 INT ell_height );
149 extern COLORREF X11DRV_SetPixel( X11DRV_PDEVICE *physDev, INT x, INT y,
150                                  COLORREF color );
151 extern COLORREF X11DRV_GetPixel( X11DRV_PDEVICE *physDev, INT x, INT y);
152 extern BOOL X11DRV_PaintRgn( X11DRV_PDEVICE *physDev, HRGN hrgn );
153 extern BOOL X11DRV_Polyline( X11DRV_PDEVICE *physDev,const POINT* pt,INT count);
154 extern BOOL X11DRV_Polygon( X11DRV_PDEVICE *physDev, const POINT* pt, INT count );
155 extern BOOL X11DRV_PolyPolygon( X11DRV_PDEVICE *physDev, const POINT* pt,
156                                   const INT* counts, UINT polygons);
157 extern BOOL X11DRV_PolyPolyline( X11DRV_PDEVICE *physDev, const POINT* pt,
158                                   const DWORD* counts, DWORD polylines);
159
160 extern COLORREF X11DRV_SetBkColor( X11DRV_PDEVICE *physDev, COLORREF color );
161 extern COLORREF X11DRV_SetTextColor( X11DRV_PDEVICE *physDev, COLORREF color );
162 extern BOOL X11DRV_ExtFloodFill( X11DRV_PDEVICE *physDev, INT x, INT y,
163                                    COLORREF color, UINT fillType );
164 extern BOOL X11DRV_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y,
165                                  UINT flags, const RECT *lprect,
166                                  LPCWSTR str, UINT count, const INT *lpDx );
167 extern LONG X11DRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count );
168 extern INT X11DRV_SetDIBitsToDevice( X11DRV_PDEVICE *physDev, INT xDest,
169                                        INT yDest, DWORD cx, DWORD cy,
170                                        INT xSrc, INT ySrc,
171                                        UINT startscan, UINT lines,
172                                        LPCVOID bits, const BITMAPINFO *info,
173                                        UINT coloruse );
174 extern BOOL X11DRV_GetDeviceGammaRamp( X11DRV_PDEVICE *physDev, LPVOID ramp );
175 extern BOOL X11DRV_SetDeviceGammaRamp( X11DRV_PDEVICE *physDev, LPVOID ramp );
176
177 /* OpenGL / X11 driver functions */
178 extern int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
179                                       const PIXELFORMATDESCRIPTOR *pppfd);
180 extern int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
181                                         int iPixelFormat, UINT nBytes,
182                                         PIXELFORMATDESCRIPTOR *ppfd);
183 extern int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev);
184 extern BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev);
185
186 /* X11 driver internal functions */
187
188 extern BOOL X11DRV_BITMAP_Init(void);
189 extern void X11DRV_FONT_Init( int *log_pixels_x, int *log_pixels_y );
190
191 struct tagBITMAPOBJ;
192 extern XImage *X11DRV_BITMAP_GetXImage( const struct tagBITMAPOBJ *bmp );
193 extern XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth );
194 extern HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(Pixmap pixmap);
195 extern HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixmap);
196 extern HBITMAP X11DRV_BITMAP_CreateBitmapFromPixmap(Pixmap pixmap, BOOL bDeletePixmap);
197 extern Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc );
198 extern Pixmap X11DRV_BITMAP_CreatePixmapFromBitmap( HBITMAP hBmp, HDC hdc );
199
200 extern RGNDATA *X11DRV_GetRegionData( HRGN hrgn, HDC hdc_lptodp );
201 extern void X11DRV_SetDrawable( HDC hdc, Drawable drawable, int mode, const POINT *org,
202                                 const POINT *drawable_org );
203 extern void X11DRV_StartGraphicsExposures( HDC hdc );
204 extern void X11DRV_EndGraphicsExposures( HDC hdc, HRGN hrgn );
205
206 extern BOOL X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE *physDev, GC gc, BOOL fMapColors );
207 extern BOOL X11DRV_SetupGCForBrush( X11DRV_PDEVICE *physDev );
208 extern BOOL X11DRV_SetupGCForPen( X11DRV_PDEVICE *physDev );
209 extern BOOL X11DRV_SetupGCForText( X11DRV_PDEVICE *physDev );
210
211 extern const int X11DRV_XROPfunction[];
212
213 extern void _XInitImageFuncPtrs(XImage *);
214
215 extern int client_side_with_core;
216 extern int client_side_with_render;
217 extern int client_side_antialias_with_core;
218 extern int client_side_antialias_with_render;
219 extern int using_client_side_fonts;
220 extern void X11DRV_XRender_Init(void);
221 extern void X11DRV_XRender_Finalize(void);
222 extern BOOL X11DRV_XRender_SelectFont(X11DRV_PDEVICE*, HFONT);
223 extern void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE*);
224 extern BOOL X11DRV_XRender_ExtTextOut(X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
225                                       const RECT *lprect, LPCWSTR wstr,
226                                       UINT count, const INT *lpDx);
227 extern void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE *physDev);
228
229 extern void X11DRV_OpenGL_Init(Display *display);
230 extern XVisualInfo *X11DRV_setup_opengl_visual(Display *display);
231
232 /* exported dib functions for now */
233
234 /* Additional info for DIB section objects */
235 typedef struct
236 {
237     /* Windows DIB section */
238     DIBSECTION  dibSection;
239
240     /* Mapping status */
241     int         status, p_status;
242
243     /* Color map info */
244     int         nColorMap;
245     int        *colorMap;
246
247     /* Cached XImage */
248     XImage     *image;
249
250 #ifdef HAVE_LIBXXSHM
251     /* Shared memory segment info */
252     XShmSegmentInfo shminfo;
253 #endif
254
255     /* Aux buffer access function */
256     void (*copy_aux)(void*ctx, int req);
257     void *aux_ctx;
258
259     /* GDI access lock */
260     CRITICAL_SECTION lock;
261
262 } X11DRV_DIBSECTION;
263
264 extern int *X11DRV_DIB_BuildColorMap( X11DRV_PDEVICE *physDev, WORD coloruse,
265                                       WORD depth, const BITMAPINFO *info,
266                                       int *nColors );
267 extern INT X11DRV_CoerceDIBSection(X11DRV_PDEVICE *physDev,INT,BOOL);
268 extern INT X11DRV_LockDIBSection(X11DRV_PDEVICE *physDev,INT,BOOL);
269 extern void X11DRV_UnlockDIBSection(X11DRV_PDEVICE *physDev,BOOL);
270 extern INT X11DRV_CoerceDIBSection2(HBITMAP bmp,INT,BOOL);
271 extern INT X11DRV_LockDIBSection2(HBITMAP bmp,INT,BOOL);
272 extern void X11DRV_UnlockDIBSection2(HBITMAP bmp,BOOL);
273
274 extern HBITMAP X11DRV_DIB_CreateDIBSection(X11DRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage,
275                                            LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
276 extern void X11DRV_DIB_DeleteDIBSection(struct tagBITMAPOBJ *bmp);
277 extern INT X11DRV_DIB_Coerce(struct tagBITMAPOBJ *,INT,BOOL);
278 extern INT X11DRV_DIB_Lock(struct tagBITMAPOBJ *,INT,BOOL);
279 extern void X11DRV_DIB_Unlock(struct tagBITMAPOBJ *,BOOL);
280 void X11DRV_DIB_CopyDIBSection(X11DRV_PDEVICE *physDevSrc, X11DRV_PDEVICE *physDevDst,
281                                DWORD xSrc, DWORD ySrc, DWORD xDest, DWORD yDest,
282                                DWORD width, DWORD height);
283 struct _DCICMD;
284 extern INT X11DRV_DCICommand(INT cbInput, const struct _DCICMD *lpCmd, LPVOID lpOutData);
285
286 /**************************************************************************
287  * X11 GDI driver
288  */
289
290 BOOL X11DRV_GDI_Initialize( Display *display );
291 void X11DRV_GDI_Finalize(void);
292
293 extern Display *gdi_display;  /* display to use for all GDI functions */
294
295 /* X11 GDI palette driver */
296
297 #define X11DRV_PALETTE_FIXED    0x0001 /* read-only colormap - have to use XAllocColor (if not virtual) */
298 #define X11DRV_PALETTE_VIRTUAL  0x0002 /* no mapping needed - pixel == pixel color */
299
300 #define X11DRV_PALETTE_PRIVATE  0x1000 /* private colormap, identity mapping */
301 #define X11DRV_PALETTE_WHITESET 0x2000
302
303 extern Colormap X11DRV_PALETTE_PaletteXColormap;
304 extern UINT16 X11DRV_PALETTE_PaletteFlags;
305
306 extern int *X11DRV_PALETTE_PaletteToXPixel;
307 extern int *X11DRV_PALETTE_XPixelToPalette;
308
309 extern int X11DRV_PALETTE_mapEGAPixel[16];
310
311 extern int X11DRV_PALETTE_Init(void);
312 extern void X11DRV_PALETTE_Cleanup(void);
313 extern BOOL X11DRV_IsSolidColor(COLORREF color);
314
315 extern COLORREF X11DRV_PALETTE_ToLogical(int pixel);
316 extern int X11DRV_PALETTE_ToPhysical(X11DRV_PDEVICE *physDev, COLORREF color);
317
318 /* GDI escapes */
319
320 #define X11DRV_ESCAPE 6789
321 enum x11drv_escape_codes
322 {
323     X11DRV_GET_DISPLAY,   /* get X11 display for a DC */
324     X11DRV_GET_DRAWABLE,  /* get current drawable for a DC */
325     X11DRV_GET_FONT,      /* get current X font for a DC */
326 };
327
328 /**************************************************************************
329  * X11 USER driver
330  */
331
332 struct x11drv_thread_data
333 {
334     Display *display;
335     HANDLE   display_fd;
336     int      process_event_count;  /* recursion count for event processing */
337     Cursor   cursor;               /* current cursor */
338     Window   cursor_window;        /* current window that contains the cursor */
339     HWND     last_focus;           /* last window that had focus */
340     XIM      xim;                  /* input method */
341 };
342
343 extern struct x11drv_thread_data *x11drv_init_thread_data(void);
344
345 inline static struct x11drv_thread_data *x11drv_thread_data(void)
346 {
347     struct x11drv_thread_data *data = NtCurrentTeb()->driver_data;
348     if (!data) data = x11drv_init_thread_data();
349     return data;
350 }
351
352 inline static Display *thread_display(void) { return x11drv_thread_data()->display; }
353
354 extern Visual *visual;
355 extern Window root_window;
356 extern DWORD desktop_tid;
357 extern unsigned int screen_width;
358 extern unsigned int screen_height;
359 extern unsigned int screen_depth;
360 extern unsigned int text_caps;
361 extern int use_take_focus;
362 extern int managed_mode;
363
364 extern Atom wmProtocols;
365 extern Atom wmDeleteWindow;
366 extern Atom wmTakeFocus;
367 extern Atom dndProtocol;
368 extern Atom dndSelection;
369 extern Atom wmChangeState;
370 extern Atom kwmDockWindow;
371 extern Atom _kde_net_wm_system_tray_window_for;
372
373 /* X11 clipboard driver */
374
375 extern void X11DRV_CLIPBOARD_FreeResources( Atom property );
376 extern BOOL X11DRV_CLIPBOARD_RegisterPixmapResource( Atom property, Pixmap pixmap );
377 extern BOOL X11DRV_CLIPBOARD_IsNativeProperty(Atom prop);
378 extern UINT X11DRV_CLIPBOARD_MapPropertyToFormat(char *itemFmtName);
379 extern Atom X11DRV_CLIPBOARD_MapFormatToProperty(UINT id);
380 extern void X11DRV_CLIPBOARD_ReleaseSelection(Atom selType, Window w, HWND hwnd);
381 extern BOOL X11DRV_IsSelectionOwner(void);
382 extern BOOL X11DRV_GetClipboardData(UINT wFormat);
383 extern HANDLE X11DRV_CLIPBOARD_SerializeMetafile(INT wformat, HANDLE hdata, INT cbytes, BOOL out);
384
385 /* X11 event driver */
386
387 typedef enum {
388   X11DRV_INPUT_RELATIVE,
389   X11DRV_INPUT_ABSOLUTE
390 } INPUT_TYPE;
391 extern INPUT_TYPE X11DRV_EVENT_SetInputMethod(INPUT_TYPE type);
392
393 #ifdef HAVE_LIBXXF86DGA2
394 void X11DRV_EVENT_SetDGAStatus(HWND hwnd, int event_base) ;
395 #endif
396
397 /* x11drv private window data */
398 struct x11drv_win_data
399 {
400     Window  whole_window;   /* X window for the complete window */
401     Window  client_window;  /* X window for the client area */
402     Window  icon_window;    /* X window for the icon */
403     RECT    whole_rect;     /* X window rectangle for the whole window relative to parent */
404     RECT    client_rect;    /* client area relative to whole window */
405     XIC     xic;            /* X input context */
406     HBITMAP hWMIconBitmap;
407     HBITMAP hWMIconMask;
408 };
409
410 typedef struct x11drv_win_data X11DRV_WND_DATA;
411
412 extern Window X11DRV_get_client_window( HWND hwnd );
413 extern Window X11DRV_get_whole_window( HWND hwnd );
414 extern XIC X11DRV_get_ic( HWND hwnd );
415
416 inline static Window get_client_window( WND *wnd )
417 {
418     struct x11drv_win_data *data = wnd->pDriverData;
419     return data->client_window;
420 }
421
422 inline static Window get_whole_window( WND *wnd )
423 {
424     struct x11drv_win_data *data = wnd->pDriverData;
425     return data->whole_window;
426 }
427
428 inline static BOOL is_window_top_level( WND *win )
429 {
430     return (root_window == DefaultRootWindow(gdi_display) && win->parent == GetDesktopWindow());
431 }
432
433 extern void X11DRV_SetFocus( HWND hwnd );
434 extern Cursor X11DRV_GetCursor( Display *display, struct tagCURSORICONINFO *ptr );
435
436 typedef int (*x11drv_error_callback)( Display *display, XErrorEvent *event, void *arg );
437
438 extern void X11DRV_expect_error( Display *display, x11drv_error_callback callback, void *arg );
439 extern int X11DRV_check_error(void);
440 extern void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data );
441 extern void X11DRV_set_iconic_state( WND *win );
442 extern void X11DRV_window_to_X_rect( WND *win, RECT *rect );
443 extern void X11DRV_X_to_window_rect( WND *win, RECT *rect );
444 extern void X11DRV_create_desktop_thread(void);
445 extern Window X11DRV_create_desktop( XVisualInfo *desktop_vi, const char *geometry );
446 extern void X11DRV_sync_window_style( Display *display, WND *win );
447 extern int X11DRV_sync_whole_window_position( Display *display, WND *win, int zorder );
448 extern int X11DRV_sync_client_window_position( Display *display, WND *win );
449 extern void X11DRV_set_wm_hints( Display *display, WND *win );
450
451 #endif  /* __WINE_X11DRV_H */