Window activation cleanups.
[wine] / include / x11drv.h
1 /*
2  * X11 driver definitions
3  */
4
5 #ifndef __WINE_X11DRV_H
6 #define __WINE_X11DRV_H
7
8 #ifndef __WINE_CONFIG_H 
9 # error You must include config.h to use this header 
10 #endif 
11
12 #include <X11/Xlib.h>
13 #include <X11/Xresource.h>
14 #include <X11/Xutil.h>
15 #include <X11/Xatom.h>
16 #ifdef HAVE_LIBXXSHM
17 # include <X11/extensions/XShm.h>
18 #endif /* defined(HAVE_LIBXXSHM) */
19
20 #include "windef.h"
21 #include "winbase.h"
22 #include "gdi.h"
23 #include "user.h"
24 #include "win.h"
25 #include "thread.h"
26
27 #define MAX_PIXELFORMATS 8
28
29 struct tagBITMAPOBJ;
30 struct tagCURSORICONINFO;
31 struct tagDC;
32 struct tagDeviceCaps;
33 struct tagPALETTEOBJ;
34 struct tagWINDOWPOS;
35
36   /* X physical pen */
37 typedef struct
38 {
39     int          style;
40     int          endcap;
41     int          linejoin;
42     int          pixel;
43     int          width;
44     char *       dashes;
45     int          dash_len;
46     int          type;          /* GEOMETRIC || COSMETIC */
47 } X_PHYSPEN;
48
49   /* X physical brush */
50 typedef struct
51 {
52     int          style;
53     int          fillStyle;
54     int          pixel;
55     Pixmap       pixmap;
56 } X_PHYSBRUSH;
57
58   /* X physical font */
59 typedef UINT     X_PHYSFONT;
60
61   /* X physical device */
62 typedef struct
63 {
64     GC            gc;          /* X Window GC */
65     Drawable      drawable;
66     X_PHYSFONT    font;
67     X_PHYSPEN     pen;
68     X_PHYSBRUSH   brush;
69     int           backgroundPixel;
70     int           textPixel;
71     int           exposures;   /* count of graphics exposures operations */
72     XVisualInfo  *visuals[MAX_PIXELFORMATS];
73     int           used_visuals;
74     int           current_pf;
75 } X11DRV_PDEVICE;
76
77
78   /* GCs used for B&W and color bitmap operations */
79 extern GC BITMAP_monoGC, BITMAP_colorGC;
80
81 #define BITMAP_GC(bmp) \
82   (((bmp)->bitmap.bmBitsPixel == 1) ? BITMAP_monoGC : BITMAP_colorGC)
83
84 extern unsigned int X11DRV_server_startticks;
85
86 /* Wine driver X11 functions */
87
88 extern BOOL X11DRV_BitBlt( struct tagDC *dcDst, INT xDst, INT yDst,
89                              INT width, INT height, struct tagDC *dcSrc,
90                              INT xSrc, INT ySrc, DWORD rop );
91 extern BOOL X11DRV_EnumDeviceFonts( HDC hdc, LPLOGFONTW plf,
92                                     DEVICEFONTENUMPROC dfeproc, LPARAM lp );
93 extern BOOL X11DRV_GetCharWidth( struct tagDC *dc, UINT firstChar,
94                                    UINT lastChar, LPINT buffer );
95 extern BOOL X11DRV_GetDCOrgEx( struct tagDC *dc, LPPOINT lpp );
96 extern BOOL X11DRV_GetTextExtentPoint( struct tagDC *dc, LPCWSTR str,
97                                          INT count, LPSIZE size );
98 extern BOOL X11DRV_GetTextMetrics(struct tagDC *dc, TEXTMETRICW *metrics);
99 extern BOOL X11DRV_PatBlt( struct tagDC *dc, INT left, INT top,
100                              INT width, INT height, DWORD rop );
101 extern VOID   X11DRV_SetDeviceClipping(struct tagDC *dc);
102 extern BOOL X11DRV_StretchBlt( struct tagDC *dcDst, INT xDst, INT yDst,
103                                  INT widthDst, INT heightDst,
104                                  struct tagDC *dcSrc, INT xSrc, INT ySrc,
105                                  INT widthSrc, INT heightSrc, DWORD rop );
106 extern BOOL X11DRV_LineTo( struct tagDC *dc, INT x, INT y);
107 extern BOOL X11DRV_Arc( struct tagDC *dc, INT left, INT top, INT right,
108                           INT bottom, INT xstart, INT ystart, INT xend,
109                           INT yend );
110 extern BOOL X11DRV_Pie( struct tagDC *dc, INT left, INT top, INT right,
111                           INT bottom, INT xstart, INT ystart, INT xend,
112                           INT yend );
113 extern BOOL X11DRV_Chord( struct tagDC *dc, INT left, INT top,
114                             INT right, INT bottom, INT xstart,
115                             INT ystart, INT xend, INT yend );
116 extern BOOL X11DRV_Ellipse( struct tagDC *dc, INT left, INT top,
117                               INT right, INT bottom );
118 extern BOOL X11DRV_Rectangle(struct tagDC *dc, INT left, INT top,
119                               INT right, INT bottom);
120 extern BOOL X11DRV_RoundRect( struct tagDC *dc, INT left, INT top,
121                                 INT right, INT bottom, INT ell_width,
122                                 INT ell_height );
123 extern COLORREF X11DRV_SetPixel( struct tagDC *dc, INT x, INT y,
124                                  COLORREF color );
125 extern COLORREF X11DRV_GetPixel( struct tagDC *dc, INT x, INT y);
126 extern BOOL X11DRV_PaintRgn( struct tagDC *dc, HRGN hrgn );
127 extern BOOL X11DRV_Polyline( struct tagDC *dc,const POINT* pt,INT count);
128 extern BOOL X11DRV_Polygon( struct tagDC *dc, const POINT* pt, INT count );
129 extern BOOL X11DRV_PolyPolygon( struct tagDC *dc, const POINT* pt, 
130                                   const INT* counts, UINT polygons);
131 extern BOOL X11DRV_PolyPolyline( struct tagDC *dc, const POINT* pt, 
132                                   const DWORD* counts, DWORD polylines);
133
134 extern HGDIOBJ X11DRV_SelectObject( struct tagDC *dc, HGDIOBJ handle );
135
136 extern COLORREF X11DRV_SetBkColor( struct tagDC *dc, COLORREF color );
137 extern COLORREF X11DRV_SetTextColor( struct tagDC *dc, COLORREF color );
138 extern BOOL X11DRV_ExtFloodFill( struct tagDC *dc, INT x, INT y,
139                                    COLORREF color, UINT fillType );
140 extern BOOL X11DRV_ExtTextOut( struct tagDC *dc, INT x, INT y,
141                                  UINT flags, const RECT *lprect,
142                                  LPCWSTR str, UINT count, const INT *lpDx );
143 extern BOOL X11DRV_CreateBitmap( HBITMAP hbitmap );
144 extern BOOL X11DRV_DeleteObject( HGDIOBJ handle );
145 extern LONG X11DRV_BitmapBits( HBITMAP hbitmap, void *bits, LONG count,
146                                WORD flags );
147 extern INT X11DRV_SetDIBitsToDevice( struct tagDC *dc, INT xDest,
148                                        INT yDest, DWORD cx, DWORD cy,
149                                        INT xSrc, INT ySrc,
150                                        UINT startscan, UINT lines,
151                                        LPCVOID bits, const BITMAPINFO *info,
152                                        UINT coloruse );
153 extern INT X11DRV_DeviceBitmapBits( struct tagDC *dc, HBITMAP hbitmap,
154                                       WORD fGet, UINT startscan,
155                                       UINT lines, LPSTR bits,
156                                       LPBITMAPINFO info, UINT coloruse );
157 extern BOOL X11DRV_GetDeviceGammaRamp( struct tagDC *dc, LPVOID ramp );
158 extern BOOL X11DRV_SetDeviceGammaRamp( struct tagDC *dc, LPVOID ramp );
159
160 /* OpenGL / X11 driver functions */
161 extern int X11DRV_ChoosePixelFormat(DC *dc, const PIXELFORMATDESCRIPTOR *pppfd) ;
162 extern int X11DRV_DescribePixelFormat(DC *dc, int iPixelFormat, UINT nBytes, PIXELFORMATDESCRIPTOR *ppfd) ;
163 extern int X11DRV_GetPixelFormat(DC *dc) ;
164 extern BOOL X11DRV_SetPixelFormat(DC *dc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd) ;
165 extern BOOL X11DRV_SwapBuffers(DC *dc) ;
166
167 /* X11 driver internal functions */
168
169 extern BOOL X11DRV_BITMAP_Init(void);
170 extern int X11DRV_FONT_Init( int *log_pixels_x, int *log_pixels_y );
171 extern BOOL X11DRV_OBM_Init(void);
172 extern HBRUSH X11DRV_BRUSH_SelectObject( DC * dc, HBRUSH hbrush );
173 extern HFONT X11DRV_FONT_SelectObject( DC * dc, HFONT hfont );
174 extern HPEN X11DRV_PEN_SelectObject( DC * dc, HPEN hpen );
175 extern HBITMAP X11DRV_BITMAP_SelectObject( DC * dc, HBITMAP hbitmap );
176 extern BOOL X11DRV_BITMAP_DeleteObject( HBITMAP hbitmap );
177
178 struct tagBITMAPOBJ;
179 extern XImage *X11DRV_BITMAP_GetXImage( const struct tagBITMAPOBJ *bmp );
180 extern XImage *X11DRV_DIB_CreateXImage( int width, int height, int depth );
181 extern HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(Pixmap pixmap);
182 extern HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc, BOOL bDeletePixmap);
183 extern HBITMAP X11DRV_BITMAP_CreateBitmapFromPixmap(Pixmap pixmap, BOOL bDeletePixmap);
184 extern Pixmap X11DRV_DIB_CreatePixmapFromDIB( HGLOBAL hPackedDIB, HDC hdc );
185 extern Pixmap X11DRV_BITMAP_CreatePixmapFromBitmap( HBITMAP hBmp, HDC hdc );
186
187 extern void X11DRV_SetDrawable( HDC hdc, Drawable drawable, int mode, int org_x, int org_y );
188 extern void X11DRV_StartGraphicsExposures( HDC hdc );
189 extern void X11DRV_EndGraphicsExposures( HDC hdc, HRGN hrgn );
190
191 extern BOOL X11DRV_SetupGCForPatBlt( struct tagDC *dc, GC gc, BOOL fMapColors );
192 extern BOOL X11DRV_SetupGCForBrush( struct tagDC *dc );
193 extern BOOL X11DRV_SetupGCForPen( struct tagDC *dc );
194 extern BOOL X11DRV_SetupGCForText( struct tagDC *dc );
195
196 extern const int X11DRV_XROPfunction[];
197
198 extern void _XInitImageFuncPtrs(XImage *);
199
200 /* exported dib functions for now */
201
202 /* Additional info for DIB section objects */
203 typedef struct
204 {
205     /* Windows DIB section */
206     DIBSECTION  dibSection;
207
208     /* Mapping status */
209     int         status, p_status;
210
211     /* Color map info */
212     int         nColorMap;
213     int        *colorMap;
214
215     /* Cached XImage */
216     XImage     *image;
217
218 #ifdef HAVE_LIBXXSHM
219     /* Shared memory segment info */
220     XShmSegmentInfo shminfo;
221 #endif
222
223     /* Aux buffer access function */
224     void (*copy_aux)(void*ctx, int req);
225     void *aux_ctx;
226
227     /* GDI access lock */
228     CRITICAL_SECTION lock;
229
230 } X11DRV_DIBSECTION;
231
232 extern int *X11DRV_DIB_BuildColorMap( struct tagDC *dc, WORD coloruse,
233                                       WORD depth, const BITMAPINFO *info,
234                                       int *nColors );
235 extern INT X11DRV_CoerceDIBSection(struct tagDC *dc,INT,BOOL);
236 extern INT X11DRV_LockDIBSection(struct tagDC *dc,INT,BOOL);
237 extern void X11DRV_UnlockDIBSection(struct tagDC *dc,BOOL);
238 extern INT X11DRV_CoerceDIBSection2(HBITMAP bmp,INT,BOOL);
239 extern INT X11DRV_LockDIBSection2(HBITMAP bmp,INT,BOOL);
240 extern void X11DRV_UnlockDIBSection2(HBITMAP bmp,BOOL);
241
242 extern HBITMAP X11DRV_DIB_CreateDIBSection(struct tagDC *dc, BITMAPINFO *bmi, UINT usage,
243                                            LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
244
245 extern struct tagBITMAP_DRIVER X11DRV_BITMAP_Driver;
246
247 extern INT X11DRV_DIB_SetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT startscan,
248                                 UINT lines, LPCVOID bits, const BITMAPINFO *info,
249                                 UINT coloruse, HBITMAP hbitmap);
250 extern INT X11DRV_DIB_GetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT startscan,
251                                 UINT lines, LPVOID bits, BITMAPINFO *info,
252                                 UINT coloruse, HBITMAP hbitmap);
253 extern void X11DRV_DIB_DeleteDIBSection(struct tagBITMAPOBJ *bmp);
254 extern UINT X11DRV_DIB_SetDIBColorTable(struct tagBITMAPOBJ *,struct tagDC*,UINT,UINT,const RGBQUAD *);
255 extern UINT X11DRV_DIB_GetDIBColorTable(struct tagBITMAPOBJ *,struct tagDC*,UINT,UINT,RGBQUAD *);
256 extern INT X11DRV_DIB_Coerce(struct tagBITMAPOBJ *,INT,BOOL);
257 extern INT X11DRV_DIB_Lock(struct tagBITMAPOBJ *,INT,BOOL);
258 extern void X11DRV_DIB_Unlock(struct tagBITMAPOBJ *,BOOL);
259 void X11DRV_DIB_CopyDIBSection(DC *dcSrc, DC *dcDst,     
260                                DWORD xSrc, DWORD ySrc,   
261                                DWORD xDest, DWORD yDest, 
262                                DWORD width, DWORD height);
263 struct _DCICMD;
264 extern INT X11DRV_DCICommand(INT cbInput, const struct _DCICMD *lpCmd, LPVOID lpOutData);
265
266 /**************************************************************************
267  * X11 GDI driver
268  */
269
270 BOOL X11DRV_GDI_Initialize( Display *display );
271 void X11DRV_GDI_Finalize(void);
272
273 extern Display *gdi_display;  /* display to use for all GDI functions */
274
275 /* X11 GDI palette driver */
276
277 #define X11DRV_PALETTE_FIXED    0x0001 /* read-only colormap - have to use XAllocColor (if not virtual) */
278 #define X11DRV_PALETTE_VIRTUAL  0x0002 /* no mapping needed - pixel == pixel color */
279
280 #define X11DRV_PALETTE_PRIVATE  0x1000 /* private colormap, identity mapping */
281 #define X11DRV_PALETTE_WHITESET 0x2000
282
283 extern Colormap X11DRV_PALETTE_PaletteXColormap;
284 extern UINT16 X11DRV_PALETTE_PaletteFlags;
285
286 extern int *X11DRV_PALETTE_PaletteToXPixel;
287 extern int *X11DRV_PALETTE_XPixelToPalette;
288
289 extern int X11DRV_PALETTE_mapEGAPixel[16];
290
291 extern int X11DRV_PALETTE_Init(void);
292 extern void X11DRV_PALETTE_Cleanup(void);
293
294 extern COLORREF X11DRV_PALETTE_ToLogical(int pixel);
295 extern int X11DRV_PALETTE_ToPhysical(struct tagDC *dc, COLORREF color);
296
297 extern struct tagPALETTE_DRIVER X11DRV_PALETTE_Driver;
298
299 extern int X11DRV_PALETTE_SetMapping(struct tagPALETTEOBJ *palPtr, UINT uStart, UINT uNum, BOOL mapOnly);
300 extern int X11DRV_PALETTE_UpdateMapping(struct tagPALETTEOBJ *palPtr);
301 extern BOOL X11DRV_PALETTE_IsDark(int pixel);
302
303 /**************************************************************************
304  * X11 USER driver
305  */
306
307 struct x11drv_thread_data
308 {
309     Display *display;
310     HANDLE   display_fd;
311     int      process_event_count;  /* recursion count for event processing */
312 };
313
314 extern struct x11drv_thread_data *x11drv_init_thread_data(void);
315
316 inline static struct x11drv_thread_data *x11drv_thread_data(void)
317 {
318     struct x11drv_thread_data *data = NtCurrentTeb()->driver_data;
319     if (!data) data = x11drv_init_thread_data();
320     return data;
321 }
322
323 inline static Display *thread_display(void) { return x11drv_thread_data()->display; }
324
325 extern Visual *visual;
326 extern Window root_window;
327 extern unsigned int screen_width;
328 extern unsigned int screen_height;
329 extern unsigned int screen_depth;
330
331 extern Atom wmProtocols;
332 extern Atom wmDeleteWindow;
333 extern Atom wmTakeFocus;
334 extern Atom dndProtocol;
335 extern Atom dndSelection;
336 extern Atom wmChangeState;
337 extern Atom kwmDockWindow;
338 extern Atom _kde_net_wm_system_tray_window_for;
339
340 /* X11 clipboard driver */
341
342 extern void X11DRV_CLIPBOARD_FreeResources( Atom property );
343 extern BOOL X11DRV_CLIPBOARD_RegisterPixmapResource( Atom property, Pixmap pixmap );
344 extern BOOL X11DRV_CLIPBOARD_IsNativeProperty(Atom prop);
345 extern UINT X11DRV_CLIPBOARD_MapPropertyToFormat(char *itemFmtName);
346 extern Atom X11DRV_CLIPBOARD_MapFormatToProperty(UINT id);
347 extern void X11DRV_CLIPBOARD_ReleaseSelection(Atom selType, Window w, HWND hwnd);
348 extern BOOL X11DRV_IsSelectionOwner(void);
349 extern BOOL X11DRV_GetClipboardData(UINT wFormat);
350
351 /* X11 event driver */
352
353 typedef enum {
354   X11DRV_INPUT_RELATIVE,
355   X11DRV_INPUT_ABSOLUTE
356 } INPUT_TYPE;
357 extern INPUT_TYPE X11DRV_EVENT_SetInputMethod(INPUT_TYPE type);
358
359 #ifdef HAVE_LIBXXF86DGA2
360 void X11DRV_EVENT_SetDGAStatus(HWND hwnd, int event_base) ;
361 #endif
362
363 /* x11drv private window data */
364 struct x11drv_win_data
365 {
366     Window  whole_window;   /* X window for the complete window */
367     Window  client_window;  /* X window for the client area */
368     Window  icon_window;    /* X window for the icon */
369     RECT    whole_rect;     /* X window rectangle for the whole window relative to parent */
370     RECT    client_rect;    /* client area relative to whole window */
371     HBITMAP hWMIconBitmap;
372     HBITMAP hWMIconMask;
373 };
374
375 typedef struct x11drv_win_data X11DRV_WND_DATA;
376
377 extern Window X11DRV_get_client_window( HWND hwnd );
378 extern Window X11DRV_get_whole_window( HWND hwnd );
379
380 inline static Window get_client_window( WND *wnd )
381 {
382     struct x11drv_win_data *data = wnd->pDriverData;
383     return data->client_window;
384 }
385
386 inline static Window get_whole_window( WND *wnd )
387 {
388     struct x11drv_win_data *data = wnd->pDriverData;
389     return data->whole_window;
390 }
391
392 extern void X11DRV_SetFocus( HWND hwnd );
393 extern Cursor X11DRV_GetCursor( Display *display, struct tagCURSORICONINFO *ptr );
394
395 extern void X11DRV_expect_error( unsigned char request, unsigned char error, XID id );
396 extern int X11DRV_check_error(void);
397 extern void X11DRV_register_window( Display *display, HWND hwnd, struct x11drv_win_data *data );
398 extern void X11DRV_set_iconic_state( WND *win );
399 extern void X11DRV_window_to_X_rect( WND *win, RECT *rect );
400 extern void X11DRV_X_to_window_rect( WND *win, RECT *rect );
401 extern void X11DRV_create_desktop_thread(void);
402 extern Window X11DRV_create_desktop( XVisualInfo *desktop_vi, const char *geometry );
403 extern int X11DRV_sync_whole_window_position( Display *display, WND *win, int zorder );
404 extern int X11DRV_sync_client_window_position( Display *display, WND *win );
405
406 #endif  /* __WINE_X11DRV_H */