Drag-n-drop support on Linux
[blender-staging.git] / intern / ghost / intern / GHOST_WindowX11.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file ghost/intern/GHOST_WindowX11.cpp
29  *  \ingroup GHOST
30  */
31
32
33 #include "GHOST_WindowX11.h"
34 #include "GHOST_SystemX11.h"
35 #include "GHOST_DropTargetX11.h"
36 #include "STR_String.h"
37 #include "GHOST_Debug.h"
38
39 // For standard X11 cursors
40 #include <X11/cursorfont.h>
41 #include <X11/Xatom.h>
42
43 #if defined(__sun__) || defined( __sun ) || defined (__sparc) || defined (__sparc__) || defined (_AIX)
44 #include <strings.h>
45 #endif
46
47 #include <cstring>
48 #include <cstdio>
49
50 #include <algorithm>
51 #include <string>
52
53 // For obscure full screen mode stuuf
54 // lifted verbatim from blut.
55
56 typedef struct {
57         long flags;
58         long functions;
59         long decorations;
60         long input_mode;
61 } MotifWmHints;
62
63 #define MWM_HINTS_DECORATIONS         (1L << 1)
64
65
66 // #define GHOST_X11_GRAB
67
68 /*
69  * A Client can't change the window property, that is
70  * the work of the window manager. In case, we send
71  * a ClientMessage to the RootWindow with the property
72  * and the Action (WM-spec define this):
73  */
74 #define _NET_WM_STATE_REMOVE 0
75 #define _NET_WM_STATE_ADD 1
76 #define _NET_WM_STATE_TOGGLE 2
77
78 /*
79 import bpy
80 I = bpy.data.images['blender.png'] # the 48x48 icon
81
82 # Write to a file that can be 
83 # used within static unsigned char BLENDER_ICON_48x48x24[] = {...}
84 f = open('/myicon.txt', 'w')
85 for j in xrange(48):
86         for k in xrange(48):
87                 v = I.getPixelI(j,47-k)
88                 v.pop()
89                 for p in v:
90                         f.write(str(hex(p))+',')
91
92         f.write('\n')
93 */
94
95 // See the python script above to regenerate the 48x48 icon within blender
96 #define BLENDER_ICON_WIDTH 48
97 #define BLENDER_ICON_HEIGHT 48
98 static unsigned char BLENDER_ICON_48x48x24[] = {
99 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
100 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x4f,0x2a,0xd,0xa7,0x5b,0x1f,0xb8,0x66,0x22,0x6c,0x3b,0x14,0x5,0x3,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
101 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x6f,0x3a,0x13,0xea,0x7f,0x2c,0xee,0x7e,0x2b,0xee,0x7e,0x2b,0xef,0x85,0x2e,0x5f,0x35,0x12,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
102 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x43,0x22,0xb,0xed,0x7f,0x2c,0xed,0x7c,0x2b,0xee,0x7f,0x2c,0xee,0x80,0x2c,0xee,0x80,0x2c,0xa8,0x5f,0x20,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
103 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x2e,0x16,0x6,0xd0,0x6f,0x26,0xed,0x7b,0x2a,0xed,0x7d,0x2b,0xee,0x7f,0x2c,0xee,0x80,0x2c,0xee,0x82,0x2d,0x9a,0x57,0x1d,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
104 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x17,0xb,0x4,0xb9,0x60,0x21,0xed,0x7a,0x2a,0xed,0x7b,0x2a,0xed,0x7e,0x2b,0xee,0x7f,0x2c,0xee,0x7f,0x2c,0xee,0x86,0x2e,0x4e,0x2b,0xe,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
105 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x1,0x0,0x0,0x96,0x4d,0x19,0xee,0x7a,0x2a,0xed,0x79,0x2a,0xed,0x7c,0x2b,0xed,0x7e,0x2b,0xed,0x7e,0x2b,0xef,0x83,0x2d,0x98,0x55,0x1c,0x3,0x1,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
106 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x20,0xf,0x5,0x4b,0x27,0xe,0x21,0x11,0x5,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x67,0x34,0x11,0xed,0x7b,0x2a,0xec,0x79,0x29,0xed,0x7b,0x2a,0xed,0x7c,0x2b,0xed,0x7d,0x2b,0xee,0x7f,0x2c,0xbb,0x69,0x24,0x11,0x9,0x3,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
107 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x38,0x1c,0x9,0xc9,0x6d,0x2c,0xf1,0x86,0x36,0xd7,0x79,0x2a,0x22,0x12,0x5,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x3b,0x1d,0x9,0xe0,0x74,0x27,0xed,0x7a,0x2a,0xed,0x7c,0x2a,0xed,0x7d,0x2b,0xed,0x7d,0x2b,0xed,0x7d,0x2b,0xdc,0x7a,0x2a,0x1e,0xf,0x5,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
108 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xa6,0x56,0x23,0xee,0x83,0x3b,0xed,0x7d,0x2c,0xf0,0x85,0x2e,0x75,0x43,0x17,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x25,0x12,0x5,0xc9,0x68,0x24,0xed,0x7b,0x2a,0xed,0x7d,0x2b,0xed,0x7e,0x2b,0xee,0x7e,0x2c,0xed,0x7d,0x2b,0xe3,0x7d,0x2b,0x3b,0x1f,0xa,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
109 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x1c,0xd,0x4,0xd9,0x74,0x35,0xee,0x83,0x3a,0xee,0x7f,0x2b,0xf0,0x86,0x2e,0x83,0x4d,0x1a,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xa,0x5,0x1,0xa1,0x54,0x1c,0xee,0x7e,0x2c,0xed,0x7e,0x2c,0xed,0x7f,0x2c,0xed,0x80,0x2c,0xed,0x7f,0x2b,0xec,0x81,0x2d,0x60,0x33,0x11,0x1,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
110 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x24,0x11,0x5,0xe0,0x7a,0x38,0xee,0x84,0x3a,0xee,0x82,0x2c,0xf0,0x88,0x2f,0x82,0x4d,0x1a,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x6f,0x39,0x13,0xef,0x82,0x30,0xed,0x82,0x2f,0xee,0x82,0x2e,0xee,0x82,0x2d,0xee,0x81,0x2c,0xf0,0x83,0x2d,0x88,0x49,0x18,0x3,0x2,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
111 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x24,0x11,0x5,0xe0,0x7c,0x3a,0xee,0x86,0x3b,0xee,0x84,0x2d,0xf1,0x8b,0x30,0x82,0x4d,0x1a,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0x54,0x2b,0xf,0xe9,0x80,0x30,0xee,0x87,0x33,0xef,0x88,0x32,0xef,0x88,0x30,0xee,0x85,0x2f,0xef,0x83,0x2e,0xae,0x5f,0x20,0x4,0x2,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
112 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x24,0x11,0x5,0xe0,0x7e,0x3d,0xef,0x8a,0x3d,0xef,0x88,0x2e,0xf1,0x8d,0x31,0x81,0x4d,0x1a,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0x29,0x15,0x7,0xd2,0x74,0x2d,0xf0,0x8b,0x36,0xf0,0x8d,0x35,0xef,0x8d,0x35,0xef,0x8b,0x33,0xef,0x88,0x30,0xc4,0x6d,0x26,0x18,0xc,0x4,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
113 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x24,0x11,0x5,0xe1,0x80,0x3f,0xf0,0x8d,0x3f,0xef,0x8a,0x2f,0xf1,0x8f,0x32,0x81,0x4e,0x1a,0x0,0x0,0x0,0x0,0x0,0x0,0x9,0x3,0x0,0xb1,0x61,0x26,0xf1,0x8e,0x3a,0xf1,0x90,0x3a,0xf0,0x90,0x38,0xf0,0x90,0x36,0xef,0x8e,0x35,0xd3,0x7a,0x2c,0x22,0x11,0x6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
114 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x24,0x12,0x5,0xe1,0x83,0x42,0xf0,0x90,0x42,0xf0,0x8d,0x30,0xf2,0x92,0x33,0x80,0x4e,0x1b,0x0,0x0,0x0,0x3,0x2,0x0,0x81,0x45,0x1b,0xf1,0x90,0x3e,0xf1,0x94,0x3d,0xf1,0x95,0x3c,0xf0,0x94,0x3b,0xf0,0x92,0x39,0xf0,0x90,0x35,0xd0,0x7b,0x2b,0xc2,0x6e,0x26,0xbe,0x6c,0x25,0x94,0x54,0x1c,0x5b,0x33,0x11,0x1a,0xe,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
115 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x25,0x14,0x6,0xe2,0x86,0x44,0xf1,0x94,0x45,0xf0,0x90,0x31,0xf2,0x94,0x33,0x80,0x4e,0x1b,0x0,0x0,0x0,0x60,0x34,0x14,0xed,0x8c,0x3e,0xf0,0x96,0x42,0xf1,0x97,0x40,0xf1,0x95,0x3f,0xf0,0x91,0x39,0xef,0x8e,0x33,0xef,0x8d,0x31,0xf0,0x8d,0x31,0xef,0x8c,0x30,0xef,0x8c,0x30,0xf0,0x8d,0x31,0xf1,0x8e,0x31,0xe1,0x85,0x2e,0x92,0x55,0x1d,0x25,0x14,0x7,0x1,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
116 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x26,0x14,0x6,0xe2,0x89,0x46,0xf2,0x97,0x47,0xf1,0x92,0x32,0xf2,0x96,0x34,0x80,0x4e,0x1a,0x32,0x1a,0xa,0xe3,0x87,0x3d,0xf1,0x97,0x45,0xf1,0x98,0x44,0xf1,0x95,0x41,0xf0,0x90,0x39,0xef,0x8d,0x30,0xef,0x8f,0x31,0xf0,0x90,0x32,0xf0,0x92,0x33,0xf1,0x93,0x33,0xf1,0x94,0x34,0xf1,0x94,0x34,0xf0,0x93,0x34,0xf0,0x91,0x32,0xf1,0x91,0x33,0xe2,0x8a,0x30,0x6b,0x3f,0x15,0x1,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
117 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x26,0x14,0x6,0xe3,0x8b,0x49,0xf2,0x9a,0x49,0xf1,0x93,0x32,0xf2,0x98,0x35,0x8f,0x57,0x1d,0xcf,0x7c,0x38,0xf2,0x99,0x48,0xf1,0x98,0x47,0xf1,0x96,0x44,0xf0,0x90,0x39,0xef,0x8d,0x31,0xf0,0x90,0x31,0xf0,0x92,0x33,0xf1,0x94,0x33,0xf1,0x96,0x35,0xf1,0x98,0x35,0xf1,0x9a,0x36,0xf1,0x9c,0x37,0xf2,0x9d,0x37,0xf2,0x9c,0x37,0xf2,0x99,0x36,0xf0,0x94,0x34,0xf3,0x97,0x35,0x9f,0x60,0x21,0x13,0xb,0x3,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
118 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x26,0x14,0x6,0xe3,0x8d,0x4b,0xf2,0x9b,0x4c,0xf1,0x93,0x32,0xf1,0x97,0x35,0xea,0x98,0x43,0xf2,0x9d,0x4d,0xf1,0x9a,0x4b,0xf1,0x99,0x49,0xf0,0x93,0x3d,0xf0,0x8d,0x30,0xf0,0x90,0x32,0xf0,0x92,0x32,0xf0,0x94,0x34,0xf1,0x96,0x34,0xf1,0x98,0x36,0xf1,0x9a,0x36,0xf2,0x9c,0x38,0xf2,0x9f,0x38,0xf2,0xa2,0x39,0xf3,0xa2,0x39,0xf3,0xa2,0x39,0xf2,0x9f,0x38,0xf1,0x99,0x35,0xf2,0x97,0x35,0xba,0x74,0x29,0x13,0xb,0x4,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
119 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x26,0x14,0x6,0xe4,0x8e,0x4d,0xf2,0x9d,0x4e,0xf1,0x93,0x32,0xf2,0x9d,0x3f,0xf3,0xa4,0x54,0xf2,0x9d,0x50,0xf1,0x9b,0x4d,0xf2,0x98,0x46,0xef,0x8d,0x31,0xf0,0x8f,0x31,0xf0,0x91,0x32,0xf0,0x93,0x32,0xf1,0x94,0x32,0xf1,0x95,0x32,0xf1,0x98,0x34,0xf1,0x9b,0x36,0xf2,0x9e,0x38,0xf2,0xa1,0x39,0xf2,0xa4,0x3a,0xf3,0xa6,0x3b,0xf4,0xa8,0x3c,0xf3,0xa7,0x3c,0xf3,0xa4,0x3a,0xf2,0x9c,0x37,0xf2,0x99,0x36,0xa9,0x69,0x25,0x2,0x1,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
120 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x26,0x14,0x6,0xe4,0x90,0x50,0xf2,0x9e,0x51,0xf1,0x95,0x35,0xf4,0xa6,0x54,0xf3,0xa2,0x55,0xf2,0x9e,0x51,0xf2,0x9c,0x4e,0xf0,0x8f,0x35,0xf0,0x8e,0x31,0xf0,0x90,0x32,0xf3,0xa5,0x56,0xf7,0xc4,0x8e,0xfa,0xd8,0xb6,0xfb,0xdf,0xc2,0xfa,0xd8,0xb2,0xf7,0xc4,0x89,0xf4,0xae,0x59,0xf2,0xa1,0x38,0xf3,0xa5,0x3b,0xf4,0xa8,0x3c,0xf4,0xab,0x3d,0xf4,0xac,0x3e,0xf4,0xab,0x3d,0xf3,0xa7,0x3b,0xf2,0x9e,0x38,0xf4,0x9e,0x38,0x6f,0x45,0x17,0x1,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
121 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x19,0xc,0x5,0x63,0x36,0x18,0x3f,0x20,0x9,0x2,0x1,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x26,0x14,0x6,0xe4,0x91,0x52,0xf3,0xa2,0x55,0xf2,0x9d,0x43,0xf4,0xa7,0x5b,0xf3,0xa2,0x57,0xf3,0xa0,0x55,0xf1,0x97,0x43,0xf0,0x8d,0x30,0xf2,0x9d,0x4c,0xfa,0xda,0xbc,0xfe,0xfb,0xf7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfb,0xf6,0xfa,0xdc,0xb5,0xf4,0xae,0x4e,0xf4,0xa9,0x3c,0xf4,0xac,0x3d,0xf4,0xae,0x3f,0xf4,0xaf,0x3f,0xf4,0xad,0x3f,0xf3,0xa8,0x3d,0xf2,0x9d,0x38,0xe2,0x94,0x34,0x23,0x14,0x6,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
122 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x11,0x8,0x3,0x9e,0x62,0x39,0xf2,0x91,0x4e,0xe7,0x79,0x29,0x48,0x25,0xc,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0x27,0x13,0x6,0xe5,0x93,0x54,0xf3,0xa7,0x59,0xf4,0xa6,0x56,0xf4,0xa7,0x5d,0xf3,0xa4,0x59,0xf3,0xa2,0x57,0xf1,0x90,0x36,0xf4,0xa7,0x5d,0xfe,0xf4,0xeb,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfd,0xf2,0xe3,0xf6,0xb8,0x5f,0xf4,0xac,0x3e,0xf4,0xaf,0x3f,0xf4,0xb1,0x40,0xf4,0xb2,0x40,0xf5,0xaf,0x3f,0xf3,0xa6,0x3c,0xf3,0x9f,0x38,0x90,0x5d,0x21,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
123 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x3d,0x1f,0xf,0xed,0x9c,0x6a,0xef,0x8b,0x4a,0xec,0x78,0x29,0xe4,0x79,0x2a,0x29,0x15,0x7,0x0,0x0,0x0,0xff,0x0,0xff,0x28,0x14,0x6,0xe6,0x97,0x57,0xf5,0xad,0x63,0xf5,0xac,0x62,0xf4,0xa8,0x5f,0xf4,0xa6,0x5c,0xf3,0xa0,0x53,0xf4,0xa9,0x64,0xfe,0xf8,0xf4,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xff,0xf2,0xf7,0xfa,0xed,0xf4,0xf8,0xfd,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xf7,0xed,0xf5,0xb5,0x53,0xf5,0xb0,0x3f,0xf5,0xb3,0x41,0xf5,0xb4,0x42,0xf5,0xb3,0x41,0xf4,0xad,0x3f,0xf3,0xa1,0x39,0xe4,0x98,0x37,0x1d,0x11,0x5,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
124 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x43,0x23,0x10,0xf2,0xa1,0x70,0xf1,0x99,0x61,0xec,0x78,0x2a,0xed,0x7b,0x2a,0xc4,0x69,0x23,0x15,0xa,0x3,0x0,0x0,0x0,0x1d,0xf,0x5,0xe7,0x9b,0x5b,0xf5,0xb1,0x68,0xf5,0xad,0x65,0xf4,0xaa,0x62,0xf4,0xa8,0x5f,0xf3,0xa4,0x59,0xfd,0xec,0xde,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xfd,0xfe,0xc3,0xda,0xe9,0x5c,0x9a,0xc5,0x2a,0x7b,0xb4,0x17,0x6f,0xae,0x36,0x81,0xb8,0x91,0xbb,0xd9,0xf0,0xf6,0xfa,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xe7,0xc7,0xf5,0xb2,0x43,0xf6,0xb3,0x41,0xf5,0xb5,0x43,0xf5,0xb6,0x43,0xf5,0xb3,0x42,0xf4,0xa8,0x3c,0xf4,0xa2,0x3a,0x66,0x41,0x17,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
125 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x22,0x10,0x7,0xd6,0x88,0x5b,0xf2,0xa5,0x76,0xee,0x84,0x3f,0xed,0x7a,0x2a,0xee,0x80,0x2c,0xa5,0x59,0x1e,0x7,0x3,0x1,0x19,0xd,0x4,0xe7,0x9e,0x5e,0xf6,0xb2,0x6b,0xf5,0xae,0x67,0xf5,0xac,0x65,0xf4,0xa9,0x61,0xf8,0xcc,0xa1,0xff,0xff,0xfe,0xff,0xff,0xff,0xfd,0xfe,0xfe,0x97,0xbf,0xdb,0x33,0x83,0xbb,0x24,0x7e,0xb9,0x3,0x6a,0xae,0x0,0x66,0xab,0x0,0x64,0xa9,0x1,0x63,0xa9,0x3c,0x87,0xbd,0xee,0xf5,0xf9,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfd,0xf8,0xc7,0x76,0xf6,0xb4,0x41,0xf5,0xb7,0x43,0xf6,0xb8,0x44,0xf6,0xb6,0x43,0xf5,0xae,0x3f,0xf3,0xa2,0x3a,0xac,0x71,0x29,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
126 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x52,0x2c,0x16,0xf0,0xa1,0x71,0xf2,0xa2,0x6f,0xed,0x7e,0x32,0xed,0x7e,0x2b,0xef,0x82,0x2d,0x8a,0x49,0x18,0x1b,0xe,0x4,0xe7,0xa2,0x61,0xf6,0xb3,0x6e,0xf6,0xb0,0x6a,0xf5,0xae,0x67,0xf5,0xab,0x64,0xfe,0xf4,0xeb,0xff,0xff,0xff,0xff,0xff,0xff,0xb4,0xd1,0xe5,0x3e,0x8d,0xc3,0x37,0x8e,0xc5,0x16,0x7a,0xb9,0x0,0x6b,0xaf,0x0,0x68,0xac,0x0,0x65,0xaa,0x0,0x65,0xab,0x0,0x66,0xac,0x4d,0x93,0xc4,0xf8,0xfb,0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xe7,0xc5,0xf6,0xb3,0x40,0xf6,0xb7,0x43,0xf6,0xb9,0x44,0xf6,0xb8,0x45,0xf5,0xb2,0x41,0xf3,0xa5,0x3b,0xe2,0x98,0x37,0x3,0x1,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
127 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x86,0x4e,0x2e,0xf3,0xa6,0x77,0xf1,0x9e,0x66,0xed,0x7e,0x2d,0xee,0x82,0x2c,0xf0,0x85,0x2d,0x7e,0x47,0x17,0xe8,0xa6,0x64,0xf6,0xb5,0x70,0xf6,0xb2,0x6d,0xf5,0xb0,0x6a,0xf7,0xbb,0x80,0xff,0xff,0xff,0xff,0xff,0xff,0xf9,0xfb,0xfd,0x5b,0x9c,0xca,0x42,0x96,0xcb,0x3c,0x93,0xc9,0x9,0x73,0xb6,0x0,0x6b,0xb0,0x0,0x69,0xad,0x0,0x66,0xab,0x0,0x66,0xab,0x0,0x67,0xad,0x4,0x6a,0xaf,0xbb,0xd7,0xe9,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xf8,0xee,0xf6,0xb9,0x4f,0xf6,0xb7,0x44,0xf6,0xba,0x45,0xf6,0xba,0x45,0xf5,0xb5,0x43,0xf4,0xa8,0x3d,0xf5,0xa7,0x3d,0x1b,0xf,0x4,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
128 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x11,0x8,0x3,0xb0,0x6d,0x45,0xf4,0xaa,0x7b,0xf1,0x9a,0x5b,0xee,0x82,0x2d,0xef,0x86,0x2e,0xee,0x91,0x36,0xf5,0xb5,0x70,0xf6,0xb7,0x73,0xf6,0xb4,0x70,0xf5,0xb1,0x6c,0xf9,0xcc,0xa1,0xff,0xff,0xff,0xff,0xff,0xff,0xd1,0xe2,0xef,0x4b,0x97,0xca,0x47,0x9a,0xce,0x3f,0x95,0xcb,0x3,0x71,0xb5,0x0,0x6c,0xb0,0x0,0x69,0xae,0x0,0x67,0xac,0x0,0x66,0xac,0x0,0x67,0xad,0x0,0x69,0xaf,0x66,0xa5,0xcf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfd,0xfa,0xf8,0xc3,0x67,0xf6,0xb8,0x44,0xf6,0xba,0x45,0xf6,0xbb,0x46,0xf6,0xb7,0x44,0xf4,0xab,0x3e,0xf8,0xab,0x3f,0x2a,0x19,0x8,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
129 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x2b,0x15,0x9,0xd4,0x8a,0x5c,0xf4,0xac,0x7c,0xf1,0x98,0x54,0xee,0x85,0x2e,0xf1,0x93,0x38,0xf6,0xba,0x75,0xf6,0xb9,0x75,0xf6,0xb6,0x72,0xf6,0xb3,0x6f,0xfa,0xd5,0xb1,0xff,0xff,0xff,0xff,0xff,0xff,0xb0,0xcf,0xe5,0x51,0x9e,0xcf,0x4b,0x9d,0xd0,0x43,0x97,0xcc,0x3,0x71,0xb5,0x0,0x6d,0xb1,0x0,0x6a,0xae,0x0,0x67,0xac,0x0,0x67,0xad,0x0,0x68,0xae,0x0,0x6a,0xb0,0x3b,0x8c,0xc2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xf9,0xc9,0x77,0xf6,0xb8,0x44,0xf6,0xba,0x45,0xf6,0xbc,0x46,0xf6,0xb8,0x44,0xf4,0xad,0x3f,0xf8,0xac,0x3f,0x2a,0x1a,0x8,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
130 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x47,0x26,0x12,0xee,0xa3,0x72,0xf4,0xae,0x7b,0xf1,0x97,0x4e,0xf1,0x92,0x38,0xf6,0xbb,0x78,0xf6,0xbb,0x78,0xf6,0xb7,0x75,0xf6,0xb5,0x71,0xfa,0xd6,0xb2,0xff,0xff,0xff,0xff,0xff,0xff,0xad,0xcd,0xe4,0x54,0xa0,0xd1,0x4e,0xa0,0xd1,0x48,0x9b,0xce,0xb,0x76,0xb8,0x0,0x6d,0xb2,0x0,0x6a,0xaf,0x0,0x68,0xad,0x0,0x68,0xad,0x0,0x69,0xae,0x0,0x6b,0xb1,0x36,0x89,0xc1,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xf9,0xc9,0x76,0xf6,0xb9,0x44,0xf6,0xbb,0x46,0xf6,0xbc,0x47,0xf6,0xb9,0x44,0xf4,0xad,0x3f,0xf8,0xad,0x40,0x2a,0x1a,0x8,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
131 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x70,0x42,0x26,0xf4,0xad,0x7b,0xf5,0xb1,0x7d,0xf3,0x9f,0x50,0xf7,0xbc,0x7b,0xf7,0xbc,0x7b,0xf6,0xb9,0x78,0xf6,0xb7,0x74,0xf9,0xd0,0xa6,0xff,0xff,0xff,0xff,0xff,0xff,0xc3,0xda,0xeb,0x56,0xa0,0xd0,0x51,0xa1,0xd2,0x4a,0x9c,0xcf,0x20,0x82,0xbf,0x0,0x6e,0xb2,0x0,0x6b,0xb0,0x0,0x68,0xae,0x0,0x68,0xae,0x0,0x69,0xaf,0x0,0x6b,0xb1,0x50,0x98,0xc9,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfd,0xf9,0xf8,0xc3,0x66,0xf6,0xb9,0x45,0xf7,0xbb,0x46,0xf6,0xbc,0x47,0xf6,0xb8,0x45,0xf4,0xad,0x3f,0xf8,0xac,0x3f,0x2a,0x19,0x7,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
132 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xc,0x5,0x0,0xa5,0x67,0x40,0xf5,0xb1,0x7f,0xf5,0xb7,0x7e,0xf7,0xbf,0x80,0xf7,0xbe,0x7d,0xf7,0xbb,0x7b,0xf6,0xb9,0x78,0xf8,0xc2,0x8b,0xff,0xff,0xff,0xff,0xff,0xff,0xee,0xf5,0xf9,0x5b,0xa0,0xce,0x53,0xa2,0xd2,0x4c,0x9e,0xd0,0x3c,0x93,0xc8,0x6,0x71,0xb4,0x0,0x6c,0xb0,0x0,0x69,0xae,0x0,0x69,0xae,0x0,0x6a,0xaf,0x0,0x6b,0xb1,0x9b,0xc5,0xe0,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xf7,0xec,0xf6,0xba,0x4e,0xf6,0xb9,0x45,0xf7,0xbb,0x46,0xf6,0xbc,0x47,0xf5,0xb7,0x44,0xf4,0xab,0x3e,0xf5,0xa8,0x3e,0x18,0xd,0x4,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
133 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x1f,0x10,0x7,0xc9,0x84,0x56,0xf5,0xb5,0x81,0xf7,0xbf,0x82,0xf8,0xc0,0x80,0xf7,0xbd,0x7d,0xf7,0xba,0x7a,0xf6,0xb8,0x77,0xfe,0xf5,0xec,0xff,0xff,0xff,0xff,0xff,0xff,0x9a,0xc2,0xdf,0x55,0x9f,0xd0,0x4e,0x9f,0xd0,0x47,0x99,0xcc,0x2a,0x87,0xc1,0x3,0x6d,0xb1,0x0,0x69,0xaf,0x0,0x6a,0xaf,0x0,0x6a,0xb0,0x27,0x80,0xbc,0xec,0xf4,0xf9,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xe5,0xbf,0xf6,0xb6,0x42,0xf6,0xba,0x46,0xf7,0xbb,0x46,0xf7,0xbb,0x47,0xf5,0xb5,0x43,0xf3,0xa8,0x3d,0xdd,0x97,0x37,0x2,0x1,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
134 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x32,0x1a,0xb,0xe4,0x9d,0x6a,0xf7,0xbd,0x84,0xf8,0xc1,0x83,0xf8,0xbe,0x80,0xf7,0xbd,0x7d,0xf7,0xba,0x79,0xfa,0xd9,0xb6,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0xf6,0xfa,0x74,0xac,0xd4,0x4f,0x9b,0xcd,0x48,0x99,0xcc,0x41,0x94,0xc8,0x2c,0x85,0xbe,0xb,0x70,0xb3,0x1,0x6a,0xb0,0xb,0x6e,0xb2,0xbf,0xd9,0xeb,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfd,0xf8,0xc8,0x74,0xf6,0xb7,0x44,0xf6,0xba,0x46,0xf7,0xbb,0x46,0xf7,0xb9,0x46,0xf6,0xb2,0x42,0xf4,0xa7,0x3d,0xa6,0x70,0x29,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
135 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x4f,0x2e,0x18,0xef,0xaf,0x78,0xf8,0xc1,0x85,0xf8,0xc0,0x82,0xf7,0xbe,0x7f,0xf7,0xbc,0x7d,0xf7,0xbe,0x81,0xfe,0xf3,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0xf2,0xf7,0xfa,0x91,0xbd,0xdb,0x4f,0x97,0xc8,0x40,0x8e,0xc3,0x37,0x8a,0xc0,0x34,0x88,0xbf,0x57,0x9c,0xca,0xcc,0xe1,0xef,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xe4,0xbf,0xf5,0xb6,0x45,0xf6,0xb8,0x45,0xf6,0xba,0x46,0xf7,0xba,0x46,0xf6,0xb7,0x45,0xf5,0xad,0x3f,0xf4,0xa9,0x40,0x5c,0x3d,0x18,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
136 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x85,0x55,0x31,0xf7,0xbd,0x84,0xf8,0xc2,0x85,0xf8,0xc0,0x82,0xf7,0xbe,0x80,0xf7,0xbc,0x7d,0xf9,0xcb,0x99,0xfe,0xf9,0xf4,0xff,0xff,0xff,0xff,0xff,0xff,0xfd,0xfe,0xfe,0xe5,0xef,0xf6,0xc1,0xda,0xeb,0xba,0xd5,0xe9,0xd8,0xe8,0xf2,0xf9,0xfb,0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xf3,0xe4,0xf6,0xb9,0x51,0xf5,0xb5,0x43,0xf6,0xb8,0x45,0xf6,0xb9,0x46,0xf6,0xb8,0x46,0xf6,0xb3,0x43,0xf4,0xa7,0x3e,0xdf,0x9d,0x43,0x17,0xd,0x4,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
137 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x14,0xa,0x4,0xb2,0x7b,0x4b,0xf8,0xc2,0x88,0xf8,0xc1,0x85,0xf7,0xbf,0x82,0xf7,0xbe,0x80,0xf7,0xbd,0x7d,0xf9,0xca,0x97,0xfe,0xf9,0xf4,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfd,0xf2,0xe1,0xf7,0xbc,0x5d,0xf5,0xb3,0x42,0xf5,0xb6,0x44,0xf5,0xb7,0x45,0xf6,0xb8,0x45,0xf6,0xb5,0x44,0xf5,0xad,0x40,0xf6,0xae,0x4c,0x88,0x5d,0x27,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
138 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x1d,0x10,0x6,0xdb,0xa0,0x68,0xf8,0xc3,0x88,0xf7,0xc1,0x85,0xf7,0xc0,0x82,0xf7,0xbf,0x80,0xf7,0xbe,0x7e,0xf8,0xc4,0x88,0xfc,0xe6,0xcc,0xfe,0xfb,0xf7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfa,0xf3,0xfa,0xda,0xa9,0xf5,0xb3,0x4a,0xf5,0xb2,0x42,0xf5,0xb3,0x43,0xf5,0xb6,0x44,0xf5,0xb7,0x45,0xf5,0xb5,0x44,0xf5,0xb0,0x42,0xf5,0xad,0x4d,0xdd,0x9e,0x4a,0x19,0xf,0x5,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
139 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x50,0x33,0x19,0xec,0xb4,0x7a,0xf8,0xc2,0x87,0xf7,0xc1,0x85,0xf7,0xc1,0x83,0xf7,0xc0,0x80,0xf7,0xc0,0x7f,0xf7,0xc0,0x7c,0xf7,0xc2,0x7e,0xf8,0xcc,0x92,0xfa,0xda,0xb0,0xfb,0xdf,0xb9,0xfa,0xd9,0xad,0xf7,0xc8,0x84,0xf5,0xb4,0x54,0xf4,0xad,0x3f,0xf4,0xaf,0x41,0xf5,0xb2,0x42,0xf5,0xb4,0x43,0xf5,0xb5,0x44,0xf5,0xb4,0x44,0xf5,0xb2,0x46,0xf5,0xb2,0x54,0xf5,0xb4,0x5a,0x5e,0x3e,0x1a,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
140 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x71,0x4b,0x29,0xf8,0xc0,0x86,0xf7,0xc3,0x87,0xf7,0xc2,0x85,0xf7,0xc1,0x83,0xf7,0xc2,0x82,0xf7,0xc2,0x7f,0xf7,0xc2,0x7e,0xf6,0xc0,0x76,0xf4,0xb4,0x59,0xf3,0xa8,0x3e,0xf3,0xa7,0x39,0xf3,0xa9,0x3d,0xf4,0xab,0x3e,0xf4,0xad,0x40,0xf4,0xb0,0x41,0xf4,0xb2,0x42,0xf5,0xb2,0x42,0xf5,0xb3,0x45,0xf6,0xb7,0x54,0xf6,0xb7,0x60,0xf6,0xb5,0x5f,0x9d,0x6b,0x31,0x2,0x1,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
141 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x8b,0x5f,0x36,0xf9,0xc1,0x87,0xf7,0xc3,0x88,0xf8,0xc3,0x86,0xf7,0xc3,0x84,0xf8,0xc3,0x81,0xf7,0xc4,0x80,0xf7,0xc4,0x7e,0xf7,0xc4,0x7d,0xf7,0xc3,0x7a,0xf6,0xbd,0x6c,0xf5,0xb7,0x5c,0xf5,0xb5,0x54,0xf5,0xb4,0x50,0xf5,0xb6,0x52,0xf6,0xb9,0x58,0xf6,0xbd,0x62,0xf7,0xbf,0x6a,0xf6,0xba,0x66,0xf6,0xb6,0x63,0xab,0x78,0x39,0xa,0x6,0x2,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
142 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x83,0x58,0x32,0xf0,0xb9,0x7f,0xf7,0xc3,0x88,0xf7,0xc3,0x86,0xf8,0xc4,0x84,0xf7,0xc5,0x82,0xf7,0xc5,0x80,0xf7,0xc5,0x7f,0xf8,0xc5,0x7d,0xf7,0xc4,0x7b,0xf7,0xc4,0x79,0xf7,0xc4,0x78,0xf7,0xc3,0x76,0xf7,0xc3,0x74,0xf7,0xc2,0x71,0xf6,0xbe,0x6d,0xf6,0xba,0x6a,0xf4,0xb6,0x65,0x8a,0x5e,0x2c,0xc,0x7,0x3,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
143 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x4f,0x33,0x1a,0xd2,0x99,0x60,0xf8,0xc4,0x89,0xf8,0xc3,0x86,0xf8,0xc4,0x84,0xf7,0xc5,0x82,0xf7,0xc5,0x80,0xf7,0xc5,0x7f,0xf7,0xc4,0x7e,0xf7,0xc4,0x7b,0xf7,0xc3,0x79,0xf7,0xc2,0x77,0xf6,0xc0,0x74,0xf6,0xbd,0x71,0xf6,0xbb,0x6e,0xe1,0xa4,0x59,0x5c,0x3d,0x1b,0x1,0x1,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
144 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xe,0x6,0x0,0x72,0x4b,0x28,0xd0,0x9a,0x62,0xf7,0xbf,0x80,0xf8,0xc4,0x85,0xf7,0xc3,0x82,0xf7,0xc3,0x80,0xf7,0xc3,0x7e,0xf7,0xc1,0x7c,0xf6,0xc0,0x7a,0xf7,0xbf,0x78,0xf8,0xbc,0x72,0xde,0xa2,0x5d,0x80,0x57,0x2b,0x13,0xb,0x4,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
145 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x19,0xe,0x5,0x44,0x2c,0x15,0x81,0x59,0x32,0xb2,0x80,0x4c,0xcb,0x95,0x5b,0xd2,0x9c,0x5f,0xcd,0x97,0x5a,0xb9,0x86,0x4d,0x8b,0x61,0x34,0x4a,0x30,0x17,0x15,0xc,0x5,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
146 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x0,0x0,0x0,0x1,0x0,0x0,0x3,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,
147 };
148
149
150 GLXContext GHOST_WindowX11::s_firstContext = NULL;
151
152 GHOST_WindowX11::
153 GHOST_WindowX11(
154         GHOST_SystemX11 *system,
155         Display * display,
156         const STR_String& title, 
157         GHOST_TInt32 left,
158         GHOST_TInt32 top,
159         GHOST_TUns32 width,     
160         GHOST_TUns32 height,
161         GHOST_TWindowState state,
162         const GHOST_TEmbedderWindowID parentWindow,
163         GHOST_TDrawingContextType type,
164         const bool stereoVisual,
165         const GHOST_TUns16 numOfAASamples
166 ) :
167         GHOST_Window(width,height,state,type,stereoVisual,numOfAASamples),
168         m_context(NULL),
169         m_display(display),
170         m_normal_state(GHOST_kWindowStateNormal),
171         m_system (system),
172         m_valid_setup (false),
173         m_invalid_window(false),
174         m_empty_cursor(None),
175         m_custom_cursor(None)
176 {
177         
178         // Set up the minimum atrributes that we require and see if
179         // X can find us a visual matching those requirements.
180
181         int attributes[40], i, samples;
182         Atom atoms[2];
183         int natom;
184         int glxVersionMajor, glxVersionMinor; // As in GLX major.minor
185
186 #ifdef WITH_X11_XINPUT
187         /* initialize incase X11 fails to load */
188         memset(&m_xtablet, 0, sizeof(m_xtablet));
189 #endif
190
191         m_visual= NULL;
192
193         if (!glXQueryVersion(m_display, &glxVersionMajor, &glxVersionMinor)) {
194                 printf("%s:%d: X11 glXQueryVersion() failed, verify working openGL system!\n", __FILE__, __LINE__);
195                 
196                 /* exit if this is the first window */
197                 if(s_firstContext==NULL) {
198                         printf("initial window could not find the GLX extension, exit!\n");
199                         exit(1);
200                 }
201
202                 return;
203         }
204
205         /* Find the display with highest samples, starting at level requested */
206         for (samples = m_numOfAASamples; samples >= 0; samples--) {
207                 i = 0; /* Reusing attributes array, so reset counter */
208
209                 if(m_stereoVisual)
210                         attributes[i++] = GLX_STEREO;
211
212                 attributes[i++] = GLX_RGBA;
213                 attributes[i++] = GLX_DOUBLEBUFFER;
214                 attributes[i++] = GLX_RED_SIZE;   attributes[i++] = 1;
215                 attributes[i++] = GLX_BLUE_SIZE;  attributes[i++] = 1;
216                 attributes[i++] = GLX_GREEN_SIZE; attributes[i++] = 1;
217                 attributes[i++] = GLX_DEPTH_SIZE; attributes[i++] = 1;
218                 /* GLX >= 1.4 required for multi-sample */
219                 if(samples && (glxVersionMajor >= 1) && (glxVersionMinor >= 4)) {
220                         attributes[i++] = GLX_SAMPLE_BUFFERS; attributes[i++] = 1;
221                         attributes[i++] = GLX_SAMPLES; attributes[i++] = samples;
222                 }
223                 attributes[i] = None;
224
225                 m_visual = glXChooseVisual(m_display, DefaultScreen(m_display), attributes);
226
227                 /* Any sample level or even zero, which means oversampling disabled, is good
228                    but we need a valid visual to continue */
229                 if (m_visual == NULL) {
230                         if (samples == 0) {
231                                 /* All options exhausted, cannot continue */
232                                 printf("%s:%d: X11 glXChooseVisual() failed, verify working openGL system!\n", __FILE__, __LINE__);
233                                 
234                                 if(s_firstContext==NULL) {
235                                         printf("initial window could not find the GLX extension, exit!\n");
236                                         exit(1);
237                                 }
238                                 
239                                 return;
240                         }
241                 } else {
242                         if (m_numOfAASamples && (m_numOfAASamples > samples)) {
243                                 printf("%s:%d: oversampling requested %i but using %i samples\n",
244                                        __FILE__, __LINE__, m_numOfAASamples, samples);
245                         }
246                         break;
247                 }
248         }
249
250         // Create a bunch of attributes needed to create an X window.
251
252
253         // First create a colormap for the window and visual. 
254         // This seems pretty much a legacy feature as we are in rgba mode anyway.
255
256         XSetWindowAttributes xattributes;
257         memset(&xattributes, 0, sizeof(xattributes));
258
259         xattributes.colormap= XCreateColormap(
260                 m_display, 
261                 RootWindow(m_display, m_visual->screen),
262                 m_visual->visual,
263                 AllocNone
264         );
265
266         xattributes.border_pixel= 0;
267
268         // Specify which events we are interested in hearing.   
269
270         xattributes.event_mask= 
271                 ExposureMask | StructureNotifyMask | 
272                 KeyPressMask | KeyReleaseMask |
273                 EnterWindowMask | LeaveWindowMask |
274                 ButtonPressMask | ButtonReleaseMask |
275                 PointerMotionMask | FocusChangeMask | PropertyChangeMask;
276
277         // create the window!
278
279         ;
280         if (parentWindow == 0) {
281                 m_window = 
282                         XCreateWindow(
283                                 m_display, 
284                                 RootWindow(m_display, m_visual->screen), 
285                                 left,
286                                 top,
287                                 width,
288                                 height,
289                                 0, // no border.
290                                 m_visual->depth,
291                                 InputOutput, 
292                                 m_visual->visual,
293                                 CWBorderPixel|CWColormap|CWEventMask, 
294                                 &xattributes
295                         );
296         } else {
297
298                 Window root_return;
299                 int x_return,y_return;
300                 unsigned int w_return,h_return,border_w_return,depth_return;
301                 
302                 XGetGeometry(m_display, parentWindow, &root_return, &x_return, &y_return,
303                         &w_return, &h_return, &border_w_return, &depth_return );
304
305                 left = 0;
306                 top = 0;
307                 width = w_return;
308                 height = h_return;
309
310
311                 m_window = XCreateWindow(
312                                 m_display, 
313                                 parentWindow,  // reparent against embedder 
314                                 left,
315                                 top,
316                                 width,
317                                 height,
318                                 0, // no border.
319                                 m_visual->depth,
320                                 InputOutput, 
321                                 m_visual->visual,
322                                 CWBorderPixel|CWColormap|CWEventMask, 
323                                 &xattributes
324                         );
325
326                 XSelectInput(m_display , parentWindow, SubstructureNotifyMask);
327                 
328         }       
329         
330         /* initialize drop target for newly created window */
331         m_dropTarget = new GHOST_DropTargetX11(this, m_system);
332         GHOST_PRINT("Set drop target\n");
333
334         /*
335          * One of the problem with WM-spec is that can't set a property
336          * to a window that isn't mapped. That is why we can't "just
337          * call setState" here.
338          *
339          * To fix this, we first need know that the window is really
340          * map waiting for the MapNotify event.
341          *
342          * So, m_post_init indicate that we need wait for the MapNotify
343          * event and then set the Window state to the m_post_state.
344          */
345         if ((state != GHOST_kWindowStateNormal) && (state != GHOST_kWindowStateMinimized)) {
346                 m_post_init = True;
347                 m_post_state = state;
348         }
349         else {
350                 m_post_init = False;
351                 m_post_state = GHOST_kWindowStateNormal;
352         }
353         
354         // Create some hints for the window manager on how
355         // we want this window treated.
356
357         XSizeHints * xsizehints = XAllocSizeHints();
358         xsizehints->flags = PPosition | PSize | PMinSize | PMaxSize;
359         xsizehints->x = left;
360         xsizehints->y = top;
361         xsizehints->width = width;
362         xsizehints->height = height;
363         xsizehints->min_width= 320;     // size hints, could be made apart of the ghost api
364         xsizehints->min_height= 240;    // limits are also arbitrary, but should not allow 1x1 window
365         xsizehints->max_width= 65535;
366         xsizehints->max_height= 65535;
367         XSetWMNormalHints(m_display, m_window, xsizehints);
368         XFree(xsizehints);
369
370         XClassHint * xclasshint = XAllocClassHint();
371         int len = title.Length() +1 ;
372         char *wmclass = (char *)malloc(sizeof(char) * len);
373         strncpy(wmclass, (const char*)title, sizeof(char) * len);
374         xclasshint->res_name = wmclass;
375         xclasshint->res_class = wmclass;
376         XSetClassHint(m_display, m_window, xclasshint);
377         free(wmclass);
378         XFree(xclasshint);
379
380         /* The basic for a good ICCCM "work" */
381         if (m_system->m_wm_protocols) {
382                 natom= 0;
383
384                 if (m_system->m_delete_window_atom) {
385                         atoms[natom]= m_system->m_delete_window_atom;
386                         natom++;
387                 }
388
389                 if (m_system->m_wm_take_focus) {
390                         atoms[natom]= m_system->m_wm_take_focus;
391                         natom++;
392                 }
393
394                 if (natom) {
395                         /* printf("Register atoms: %d\n", natom); */
396                         XSetWMProtocols(m_display, m_window, atoms, natom);
397                 }
398         }
399
400 #if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING)
401         m_xic = XCreateIC(m_system->getX11_XIM(), XNClientWindow, m_window, XNFocusWindow, m_window,
402                           XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
403                           XNResourceName, GHOST_X11_RES_NAME, XNResourceClass,
404                           GHOST_X11_RES_CLASS, NULL);
405 #endif
406
407         // Set the window icon
408         XWMHints *xwmhints = XAllocWMHints();
409         XImage *x_image, *mask_image;
410         Pixmap icon_pixmap, mask_pixmap;
411         icon_pixmap = XCreatePixmap(display, m_window, BLENDER_ICON_WIDTH, BLENDER_ICON_HEIGHT, 24);
412         mask_pixmap = XCreatePixmap(display, m_window, BLENDER_ICON_WIDTH, BLENDER_ICON_HEIGHT, 1);
413         GC gc_icon = XCreateGC(display, icon_pixmap, 0, NULL);
414         GC gc_mask = XCreateGC(display, mask_pixmap, 0, NULL);
415         
416         x_image = XCreateImage( display, m_visual->visual, 24, ZPixmap, 0, NULL, BLENDER_ICON_WIDTH, BLENDER_ICON_HEIGHT, 32, 0 );
417         mask_image = XCreateImage( display, m_visual->visual, 1, ZPixmap, 0, NULL,  BLENDER_ICON_WIDTH, BLENDER_ICON_HEIGHT, 8, 0);
418         
419         x_image->data = (char *)malloc(x_image->bytes_per_line * BLENDER_ICON_HEIGHT);
420         mask_image->data = (char *)malloc( mask_image->bytes_per_line * BLENDER_ICON_HEIGHT);
421         
422         /* copy the BLENDER_ICON_48x48x24 into the XImage */
423         unsigned char *col = BLENDER_ICON_48x48x24;
424         int px, py;
425         for (px=0; px<BLENDER_ICON_WIDTH; px++) {
426                 for (py=0; py<BLENDER_ICON_HEIGHT; py++, col+=3) {
427                         /* mask out pink */
428                         if (col[0]==255 && col[1] == 0 && col[2]== 255) {
429                                 XPutPixel(mask_image, px, py, 0 );
430                         } else {
431                                 XPutPixel(x_image, px, py, (col[0]<<16)+(col[1]<<8)+col[2] );
432                                 XPutPixel(mask_image, px, py, 1 );
433                         }
434                 }
435         }
436         
437         XPutImage(display, icon_pixmap, gc_icon, x_image, 0, 0, 0, 0, BLENDER_ICON_WIDTH, BLENDER_ICON_HEIGHT);
438         XPutImage(display, mask_pixmap, gc_mask, mask_image, 0, 0, 0, 0, BLENDER_ICON_WIDTH, BLENDER_ICON_HEIGHT);
439         
440         // Now the pixmap is ok to assign to the window as a hint
441         xwmhints->icon_pixmap = icon_pixmap;
442         xwmhints->icon_mask = mask_pixmap;
443         XFreeGC (display, gc_icon);
444         XFreeGC (display, gc_mask);
445         XDestroyImage( x_image ); /* frees x_image->data too */
446         XDestroyImage( mask_image );
447         
448         xwmhints->initial_state = NormalState;
449         xwmhints->input= True;
450         xwmhints->flags= InputHint|IconPixmapHint|IconMaskHint|StateHint;
451         XSetWMHints(display, m_window, xwmhints );
452         XFree(xwmhints);
453         // done setting the icon
454
455         setTitle(title);
456
457 #ifdef WITH_X11_XINPUT
458         initXInputDevices();
459 #endif
460
461         // now set up the rendering context.
462         if (installDrawingContext(type) == GHOST_kSuccess) {
463                 m_valid_setup = true;
464                 GHOST_PRINT("Created window\n");
465         }
466
467         XMapWindow(m_display, m_window);
468         GHOST_PRINT("Mapped window\n");
469
470         XFlush(m_display);
471 }
472
473 #ifdef WITH_X11_XINPUT
474 /* 
475         Dummy function to get around IO Handler exiting if device invalid
476         Basically it will not crash blender now if you have a X device that 
477         is configured but not plugged in.
478
479 */
480 static int ApplicationErrorHandler(Display *display, XErrorEvent *theEvent)
481 {
482         fprintf(stderr, "Ignoring Xlib error: error code %d request code %d\n",
483                 theEvent->error_code, theEvent->request_code) ;
484
485         /* No exit! - but keep lint happy */
486         return 0 ;
487 }
488
489 /* These C functions are copied from Wine 1.1.13's wintab.c */
490 #define BOOL int
491 #define TRUE 1
492 #define FALSE 0
493
494 static bool match_token(const char *haystack, const char *needle)
495 {
496         const char *p, *q;
497         for (p = haystack; *p; )
498         {
499                 while (*p && isspace(*p))
500                         p++;
501                 if (! *p)
502                         break;
503
504                 for (q = needle; *q && *p && tolower(*p) == tolower(*q); q++)
505                         p++;
506                 if (! *q && (isspace(*p) || !*p))
507                         return TRUE;
508
509                 while (*p && ! isspace(*p))
510                         p++;
511         }
512         return FALSE;
513 }
514
515
516 /*      Determining if an X device is a Tablet style device is an imperfect science.
517 **  We rely on common conventions around device names as well as the type reported
518 **  by Wacom tablets.  This code will likely need to be expanded for alternate tablet types
519 **
520 **      Wintab refers to any device that interacts with the tablet as a cursor,
521 **  (stylus, eraser, tablet mouse, airbrush, etc)
522 **  this is not to be confused with wacom x11 configuration "cursor" device.
523 **  Wacoms x11 config "cursor" refers to its device slot (which we mirror with
524 **  our gSysCursors) for puck like devices (tablet mice essentially).
525 */
526 #if 0 // unused
527 static BOOL is_tablet_cursor(const char *name, const char *type)
528 {
529         int i;
530         static const char *tablet_cursor_whitelist[] = {
531                 "wacom",
532                 "wizardpen",
533                 "acecad",
534                 "tablet",
535                 "cursor",
536                 "stylus",
537                 "eraser",
538                 "pad",
539                 NULL
540         };
541
542         for (i=0; tablet_cursor_whitelist[i] != NULL; i++) {
543                 if (name && match_token(name, tablet_cursor_whitelist[i]))
544                         return TRUE;
545                 if (type && match_token(type, tablet_cursor_whitelist[i]))
546                         return TRUE;
547         }
548         return FALSE;
549 }
550 #endif
551 static BOOL is_stylus(const char *name, const char *type)
552 {
553         int i;
554         static const char* tablet_stylus_whitelist[] = {
555                 "stylus",
556                 "wizardpen",
557                 "acecad",
558                 NULL
559         };
560
561         for (i=0; tablet_stylus_whitelist[i] != NULL; i++) {
562                 if (name && match_token(name, tablet_stylus_whitelist[i]))
563                         return TRUE;
564                 if (type && match_token(type, tablet_stylus_whitelist[i]))
565                         return TRUE;
566         }
567
568         return FALSE;
569 }
570
571 static BOOL is_eraser(const char *name, const char *type)
572 {
573         if (name && match_token(name, "eraser"))
574                 return TRUE;
575         if (type && match_token(type, "eraser"))
576                 return TRUE;
577         return FALSE;
578 }
579 #undef BOOL
580 #undef TRUE
581 #undef FALSE
582 /* end code copied from wine */
583
584 void GHOST_WindowX11::initXInputDevices()
585 {
586         static XErrorHandler old_handler = (XErrorHandler) 0 ;
587         XExtensionVersion *version = XGetExtensionVersion(m_display, INAME);
588
589         if(version && (version != (XExtensionVersion*)NoSuchExtension)) {
590                 if(version->present) {
591                         int device_count;
592                         XDeviceInfo* device_info = XListInputDevices(m_display, &device_count);
593                         m_xtablet.StylusDevice = NULL;
594                         m_xtablet.EraserDevice = NULL;
595                         m_xtablet.CommonData.Active= GHOST_kTabletModeNone;
596
597                         /* Install our error handler to override Xlib's termination behavior */
598                         old_handler = XSetErrorHandler(ApplicationErrorHandler) ;
599
600                         for(int i=0; i<device_count; ++i) {
601                                 char *device_type = device_info[i].type ? XGetAtomName(m_display, device_info[i].type) : NULL;
602                                 
603 //                              printf("Tablet type:'%s', name:'%s', index:%d\n", device_type, device_info[i].name, i);
604
605
606                                 if(m_xtablet.StylusDevice==NULL && is_stylus(device_info[i].name, device_type)) {
607 //                                      printf("\tfound stylus\n");
608                                         m_xtablet.StylusID= device_info[i].id;
609                                         m_xtablet.StylusDevice = XOpenDevice(m_display, m_xtablet.StylusID);
610
611                                         if (m_xtablet.StylusDevice != NULL) {
612                                                 /* Find how many pressure levels tablet has */
613                                                 XAnyClassPtr ici = device_info[i].inputclassinfo;
614                                                 for(int j=0; j<m_xtablet.StylusDevice->num_classes; ++j) {
615                                                         if(ici->c_class==ValuatorClass) {
616 //                                                              printf("\t\tfound ValuatorClass\n");
617                                                                 XValuatorInfo* xvi = (XValuatorInfo*)ici;
618                                                                 m_xtablet.PressureLevels = xvi->axes[2].max_value;
619                                                         
620                                                                 /* this is assuming that the tablet has the same tilt resolution in both
621                                                                  * positive and negative directions. It would be rather weird if it didn't.. */
622                                                                 m_xtablet.XtiltLevels = xvi->axes[3].max_value;
623                                                                 m_xtablet.YtiltLevels = xvi->axes[4].max_value;
624                                                                 break;
625                                                         }
626                                                 
627                                                         ici = (XAnyClassPtr)(((char *)ici) + ici->length);
628                                                 }
629                                         } else {
630                                                 m_xtablet.StylusID= 0;
631                                         }
632                                 }
633                                 else if(m_xtablet.EraserDevice==NULL && is_eraser(device_info[i].name, device_type)) {
634 //                                      printf("\tfound eraser\n");
635                                         m_xtablet.EraserID= device_info[i].id;
636                                         m_xtablet.EraserDevice = XOpenDevice(m_display, m_xtablet.EraserID);
637                                         if (m_xtablet.EraserDevice == NULL) m_xtablet.EraserID= 0;
638                                 }
639
640                                 if(device_type) {
641                                         XFree((void*)device_type);
642                                 }
643                         }
644
645                         /* Restore handler */
646                         (void) XSetErrorHandler(old_handler) ;
647
648                         XFreeDeviceList(device_info);
649
650
651                         XEventClass xevents[10], ev;
652                         int dcount = 0;
653
654                         if(m_xtablet.StylusDevice) {
655                                 DeviceMotionNotify(m_xtablet.StylusDevice, m_xtablet.MotionEvent, ev);
656                                 if(ev) xevents[dcount++] = ev;
657                                 ProximityIn(m_xtablet.StylusDevice, m_xtablet.ProxInEvent, ev);
658                                 if(ev) xevents[dcount++] = ev;
659                                 ProximityOut(m_xtablet.StylusDevice, m_xtablet.ProxOutEvent, ev);
660                                 if(ev) xevents[dcount++] = ev;
661                         }
662                         if(m_xtablet.EraserDevice) {
663                                 DeviceMotionNotify(m_xtablet.EraserDevice, m_xtablet.MotionEvent, ev);
664                                 if(ev) xevents[dcount++] = ev;
665                                 ProximityIn(m_xtablet.EraserDevice, m_xtablet.ProxInEvent, ev);
666                                 if(ev) xevents[dcount++] = ev;
667                                 ProximityOut(m_xtablet.EraserDevice, m_xtablet.ProxOutEvent, ev);
668                                 if(ev) xevents[dcount++] = ev;
669                         }
670
671                         XSelectExtensionEvent(m_display, m_window, xevents, dcount);
672                 }
673                 XFree(version);
674         }
675 }
676
677 #endif /* WITH_X11_XINPUT */
678
679         Window 
680 GHOST_WindowX11::
681 getXWindow(
682 ){
683         return m_window;
684 }
685
686         bool 
687 GHOST_WindowX11::
688 getValid(
689 ) const {
690         return m_valid_setup;
691 }
692
693         void 
694 GHOST_WindowX11::
695 setTitle(
696         const STR_String& title
697 ){
698         Atom name = XInternAtom(m_display, "_NET_WM_NAME", 0);
699         Atom utf8str = XInternAtom(m_display, "UTF8_STRING", 0);
700         XChangeProperty(m_display, m_window,
701                         name, utf8str, 8, PropModeReplace,
702                         (const unsigned char*) title.ReadPtr(),
703                         title.Length());
704
705 // This should convert to valid x11 string
706 //  and getTitle would need matching change
707         XStoreName(m_display,m_window,title);
708
709         XFlush(m_display);
710 }
711
712         void 
713 GHOST_WindowX11::
714 getTitle(
715         STR_String& title
716 ) const {
717         char *name = NULL;
718         
719         XFetchName(m_display,m_window,&name);
720         title= name?name:"untitled";
721         XFree(name);
722 }
723         
724         void 
725 GHOST_WindowX11::
726 getWindowBounds(
727         GHOST_Rect& bounds
728 ) const {
729                 // Getting the window bounds under X11 is not
730                 // really supported (nor should it be desired).
731         getClientBounds(bounds);
732 }
733
734         void 
735 GHOST_WindowX11::
736 getClientBounds(
737         GHOST_Rect& bounds
738 ) const {
739         Window root_return;
740         int x_return,y_return;
741         unsigned int w_return,h_return,border_w_return,depth_return;
742         GHOST_TInt32 screen_x, screen_y;
743         
744         XGetGeometry(m_display,m_window,&root_return,&x_return,&y_return,
745                 &w_return,&h_return,&border_w_return,&depth_return);
746
747         clientToScreen(0, 0, screen_x, screen_y);
748         
749         bounds.m_l = screen_x;
750         bounds.m_r = bounds.m_l + w_return;
751         bounds.m_t = screen_y;
752         bounds.m_b = bounds.m_t + h_return;
753
754 }
755
756         GHOST_TSuccess 
757 GHOST_WindowX11::
758 setClientWidth(
759         GHOST_TUns32 width
760 ){      
761         XWindowChanges values;
762         unsigned int value_mask= CWWidth;               
763         values.width = width;
764         XConfigureWindow(m_display,m_window,value_mask,&values);
765
766         return GHOST_kSuccess;
767 }
768
769         GHOST_TSuccess 
770 GHOST_WindowX11::
771 setClientHeight(
772         GHOST_TUns32 height
773 ){
774         XWindowChanges values;
775         unsigned int value_mask= CWHeight;              
776         values.height = height;
777         XConfigureWindow(m_display,m_window,value_mask,&values);
778         return GHOST_kSuccess;
779
780 }
781
782         GHOST_TSuccess 
783 GHOST_WindowX11::
784 setClientSize(
785         GHOST_TUns32 width,
786         GHOST_TUns32 height
787 ){
788         XWindowChanges values;
789         unsigned int value_mask= CWWidth | CWHeight;            
790         values.width = width;
791         values.height = height;
792         XConfigureWindow(m_display,m_window,value_mask,&values);
793         return GHOST_kSuccess;
794
795 }       
796
797         void 
798 GHOST_WindowX11::
799 screenToClient(
800         GHOST_TInt32 inX,
801         GHOST_TInt32 inY,
802         GHOST_TInt32& outX,
803         GHOST_TInt32& outY
804 ) const {
805         // This is correct!
806
807         int ax,ay;
808         Window temp;
809
810         XTranslateCoordinates(
811                         m_display,
812                         RootWindow(m_display, m_visual->screen),
813                         m_window,
814                         inX,
815                         inY,
816                         &ax,
817                         &ay,
818                         &temp
819                 );
820         outX = ax;
821         outY = ay;
822 }
823                  
824         void 
825 GHOST_WindowX11::
826 clientToScreen(
827         GHOST_TInt32 inX,
828         GHOST_TInt32 inY,
829         GHOST_TInt32& outX,
830         GHOST_TInt32& outY
831 ) const {
832         int ax,ay;
833         Window temp;
834
835         XTranslateCoordinates(
836                         m_display,
837                         m_window,
838                         RootWindow(m_display, m_visual->screen),
839                         inX,
840                         inY,
841                         &ax,
842                         &ay,
843                         &temp
844                 );
845         outX = ax;
846         outY = ay;
847 }
848
849 void GHOST_WindowX11::icccmSetState(int state)
850 {
851         XEvent xev;
852
853         if (state != IconicState)
854                 return;
855
856         xev.xclient.type = ClientMessage;
857         xev.xclient.serial = 0;
858         xev.xclient.send_event = True;
859         xev.xclient.display = m_display;
860         xev.xclient.window = m_window;
861         xev.xclient.format = 32;
862         xev.xclient.message_type = m_system->m_wm_change_state;
863         xev.xclient.data.l[0] = state;
864         XSendEvent (m_display, RootWindow(m_display, DefaultScreen(m_display)),
865                 False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
866 }
867
868 int GHOST_WindowX11::icccmGetState(void) const
869 {
870         unsigned char *prop_ret;
871         unsigned long bytes_after, num_ret;
872         Atom type_ret;
873         int format_ret, st;
874
875         prop_ret = NULL;
876         st = XGetWindowProperty(m_display, m_window, m_system->m_wm_state, 0,
877                         0x7fffffff, False, m_system->m_wm_state, &type_ret,
878                         &format_ret, &num_ret, &bytes_after, &prop_ret);
879
880         if ((st == Success) && (prop_ret) && (num_ret == 2))
881                 st = prop_ret[0];
882         else
883                 st = NormalState;
884
885         if (prop_ret)
886                 XFree(prop_ret);
887         return (st);
888 }
889
890 void GHOST_WindowX11::netwmMaximized(bool set)
891 {
892         XEvent xev;
893
894         xev.xclient.type = ClientMessage;
895         xev.xclient.serial = 0;
896         xev.xclient.send_event = True;
897         xev.xclient.window = m_window;
898         xev.xclient.message_type = m_system->m_net_state;
899         xev.xclient.format = 32;
900
901         if (set == True)
902                 xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
903         else
904                 xev.xclient.data.l[0] = _NET_WM_STATE_REMOVE;
905
906         xev.xclient.data.l[1] = m_system->m_net_max_horz;
907         xev.xclient.data.l[2] = m_system->m_net_max_vert;
908         xev.xclient.data.l[3] = 0;
909         xev.xclient.data.l[4] = 0;
910         XSendEvent(m_display, RootWindow(m_display, DefaultScreen(m_display)),
911                 False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
912 }
913
914 bool GHOST_WindowX11::netwmIsMaximized(void) const
915 {
916         unsigned char *prop_ret;
917         unsigned long bytes_after, num_ret, i;
918         Atom type_ret;
919         bool st;
920         int format_ret, ret, count;
921
922         prop_ret = NULL;
923         st = False;
924         ret = XGetWindowProperty(m_display, m_window, m_system->m_net_state, 0,
925                         0x7fffffff, False, XA_ATOM, &type_ret, &format_ret,
926                         &num_ret, &bytes_after, &prop_ret);
927         if ((ret == Success) && (prop_ret) && (format_ret == 32)) {
928                 count = 0;
929                 for (i = 0; i < num_ret; i++) {
930                         if (((unsigned long *) prop_ret)[i] == m_system->m_net_max_horz)
931                                 count++;
932                         if (((unsigned long *) prop_ret)[i] == m_system->m_net_max_vert)
933                                 count++;
934                         if (count == 2) {
935                                 st = True;
936                                 break;
937                         }
938                 }
939         }
940
941         if (prop_ret)
942                 XFree(prop_ret);
943         return (st);
944 }
945
946 void GHOST_WindowX11::netwmFullScreen(bool set)
947 {
948         XEvent xev;
949
950         xev.xclient.type = ClientMessage;
951         xev.xclient.serial = 0;
952         xev.xclient.send_event = True;
953         xev.xclient.window = m_window;
954         xev.xclient.message_type = m_system->m_net_state;
955         xev.xclient.format = 32;
956
957         if (set == True)
958                 xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
959         else
960                 xev.xclient.data.l[0] = _NET_WM_STATE_REMOVE;
961
962         xev.xclient.data.l[1] = m_system->m_net_fullscreen;
963         xev.xclient.data.l[2] = 0;
964         xev.xclient.data.l[3] = 0;
965         xev.xclient.data.l[4] = 0;
966         XSendEvent(m_display, RootWindow(m_display, DefaultScreen(m_display)),
967                 False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
968 }
969
970 bool GHOST_WindowX11::netwmIsFullScreen(void) const
971 {
972         unsigned char *prop_ret;
973         unsigned long bytes_after, num_ret, i;
974         Atom type_ret;
975         bool st;
976         int format_ret, ret;
977
978         prop_ret = NULL;
979         st = False;
980         ret = XGetWindowProperty(m_display, m_window, m_system->m_net_state, 0,
981                         0x7fffffff, False, XA_ATOM, &type_ret, &format_ret,
982                         &num_ret, &bytes_after, &prop_ret);
983         if ((ret == Success) && (prop_ret) && (format_ret == 32)) {
984                 for (i = 0; i < num_ret; i++) {
985                         if (((unsigned long *) prop_ret)[i] == m_system->m_net_fullscreen) {
986                                 st = True;
987                                 break;
988                         }
989                 }
990         }
991
992         if (prop_ret)
993                 XFree(prop_ret);
994         return (st);
995 }
996
997 void GHOST_WindowX11::motifFullScreen(bool set)
998 {
999         MotifWmHints hints;
1000
1001         hints.flags = MWM_HINTS_DECORATIONS;
1002         if (set == True)
1003                 hints.decorations = 0;
1004         else
1005                 hints.decorations = 1;
1006
1007         XChangeProperty(m_display, m_window, m_system->m_motif,
1008                         m_system->m_motif, 32, PropModeReplace,
1009                         (unsigned char *) &hints, 4);
1010 }
1011
1012 bool GHOST_WindowX11::motifIsFullScreen(void) const
1013 {
1014         unsigned char *prop_ret;
1015         unsigned long bytes_after, num_ret;
1016         MotifWmHints *hints;
1017         Atom type_ret;
1018         bool state;
1019         int format_ret, st;
1020
1021         prop_ret = NULL;
1022         state = False;
1023         st = XGetWindowProperty(m_display, m_window, m_system->m_motif, 0,
1024                                 0x7fffffff, False, m_system->m_motif,
1025                                 &type_ret, &format_ret, &num_ret,
1026                                 &bytes_after, &prop_ret);
1027         if ((st == Success) && (prop_ret)) {
1028                 hints = (MotifWmHints *) prop_ret;
1029                 if (hints->flags & MWM_HINTS_DECORATIONS) {
1030                         if (!hints->decorations)
1031                                 state = True;
1032                 }
1033         }
1034
1035         if (prop_ret)
1036                 XFree(prop_ret);
1037         return (state);
1038 }
1039
1040 GHOST_TWindowState GHOST_WindowX11::getState() const
1041 {
1042         GHOST_TWindowState state_ret;
1043         int state;
1044
1045         state_ret = GHOST_kWindowStateNormal;
1046         state = icccmGetState();
1047         /*
1048          * In the Iconic and Withdrawn state, the window
1049          * is unmaped, so only need return a Minimized state.
1050          */
1051         if ((state == IconicState) || (state == WithdrawnState))
1052                 state_ret = GHOST_kWindowStateMinimized;
1053         else if (netwmIsMaximized() == True)
1054                 state_ret = GHOST_kWindowStateMaximized;
1055         else if (netwmIsFullScreen() == True)
1056                 state_ret = GHOST_kWindowStateFullScreen;
1057         else if (motifIsFullScreen() == True)
1058                 state_ret = GHOST_kWindowStateFullScreen;
1059         return (state_ret);
1060 }
1061
1062 GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
1063 {
1064         GHOST_TWindowState cur_state;
1065         bool is_max, is_full, is_motif_full;
1066
1067         cur_state = getState();
1068         if (state == (int)cur_state)
1069                 return GHOST_kSuccess;
1070
1071         if (cur_state != GHOST_kWindowStateMinimized) {
1072                 /*
1073                  * The window don't have this property's
1074                  * if it's not mapped.
1075                  */
1076                 is_max = netwmIsMaximized();
1077                 is_full = netwmIsFullScreen();
1078         }
1079         else {
1080                 is_max = False;
1081                 is_full = False;
1082         }
1083
1084         is_motif_full = motifIsFullScreen();
1085
1086         if (state == GHOST_kWindowStateNormal)
1087                 state = m_normal_state;
1088
1089         if (state == GHOST_kWindowStateNormal) {
1090                 if (is_max == True)
1091                         netwmMaximized(False);
1092                 if (is_full == True)
1093                         netwmFullScreen(False);
1094                 if (is_motif_full == True)
1095                         motifFullScreen(False);
1096                 icccmSetState(NormalState);
1097                 return (GHOST_kSuccess);
1098         }
1099
1100         if (state == GHOST_kWindowStateFullScreen) {
1101                 /*
1102                  * We can't change to full screen if the window
1103                  * isn't mapped.
1104                  */
1105                 if (cur_state == GHOST_kWindowStateMinimized)
1106                         return (GHOST_kFailure);
1107
1108                 m_normal_state = cur_state;
1109
1110                 if (is_max == True)
1111                         netwmMaximized(False);
1112                 if (is_full == False)
1113                         netwmFullScreen(True);
1114                 if (is_motif_full == False)
1115                         motifFullScreen(True);
1116                 return (GHOST_kSuccess);
1117         }
1118
1119         if (state == GHOST_kWindowStateMaximized) {
1120                 /*
1121                  * We can't change to Maximized if the window
1122                  * isn't mapped.
1123                  */
1124                 if (cur_state == GHOST_kWindowStateMinimized)
1125                         return (GHOST_kFailure);
1126
1127                 if (is_full == True)
1128                         netwmFullScreen(False);
1129                 if (is_motif_full == True)
1130                         motifFullScreen(False);
1131                 if (is_max == False)
1132                         netwmMaximized(True);
1133                 return (GHOST_kSuccess);
1134         }
1135
1136         if (state == GHOST_kWindowStateMinimized) {
1137                 /*
1138                  * The window manager need save the current state of
1139                  * the window (maximized, full screen, etc).
1140                  */
1141                 icccmSetState(IconicState);
1142                 return (GHOST_kSuccess);
1143         }
1144
1145         return (GHOST_kFailure);
1146 }
1147
1148 #include <iostream>
1149 using namespace std;
1150
1151         GHOST_TSuccess 
1152 GHOST_WindowX11::
1153 setOrder(
1154         GHOST_TWindowOrder order
1155 ){
1156         if (order == GHOST_kWindowOrderTop) {
1157                 XWindowAttributes attr;   
1158                 Atom atom;
1159
1160                 /* We use both XRaiseWindow and _NET_ACTIVE_WINDOW, since some
1161                    window managers ignore the former (e.g. kwin from kde) and others
1162                    don't implement the latter (e.g. fluxbox pre 0.9.9) */
1163
1164                 XRaiseWindow(m_display, m_window);
1165
1166                 atom = XInternAtom(m_display, "_NET_ACTIVE_WINDOW", True);
1167
1168                 if (atom != None) {
1169                         Window root;
1170                         XEvent xev;
1171                         long eventmask;
1172
1173                         xev.xclient.type = ClientMessage;
1174                         xev.xclient.serial = 0;
1175                         xev.xclient.send_event = True;
1176                         xev.xclient.window = m_window;
1177                         xev.xclient.message_type = atom;
1178
1179                         xev.xclient.format = 32;
1180                         xev.xclient.data.l[0] = 1;
1181                         xev.xclient.data.l[1] = CurrentTime;
1182                         xev.xclient.data.l[2] = m_window;
1183                         xev.xclient.data.l[3] = 0;
1184                         xev.xclient.data.l[4] = 0;
1185
1186                         root = RootWindow(m_display, m_visual->screen),
1187                         eventmask = SubstructureRedirectMask | SubstructureNotifyMask;
1188
1189                         XSendEvent(m_display, root, False, eventmask, &xev);
1190                 }
1191
1192                 XGetWindowAttributes(m_display, m_window, &attr);
1193
1194                 /* iconized windows give bad match error */
1195                 if (attr.map_state == IsViewable)
1196                         XSetInputFocus(m_display, m_window, RevertToPointerRoot,
1197                                                  CurrentTime);
1198                 XFlush(m_display);
1199         } else if (order == GHOST_kWindowOrderBottom) {
1200                 XLowerWindow(m_display,m_window);
1201                 XFlush(m_display);
1202         } else {
1203                 return GHOST_kFailure;
1204         }
1205         
1206         return GHOST_kSuccess;
1207 }
1208
1209         GHOST_TSuccess 
1210 GHOST_WindowX11::
1211 swapBuffers(
1212 ){
1213         if (getDrawingContextType() == GHOST_kDrawingContextTypeOpenGL) {
1214                 glXSwapBuffers(m_display,m_window);
1215                 return GHOST_kSuccess;
1216         } else {
1217                 return GHOST_kFailure;
1218         }
1219 }
1220
1221         GHOST_TSuccess 
1222 GHOST_WindowX11::
1223 activateDrawingContext(
1224 ){
1225         if (m_context !=NULL) {
1226                 glXMakeCurrent(m_display, m_window,m_context);                                          
1227                 return GHOST_kSuccess;
1228         } 
1229         return GHOST_kFailure;
1230 }
1231
1232         GHOST_TSuccess
1233 GHOST_WindowX11::
1234 invalidate(
1235 ){
1236
1237         // So the idea of this function is to generate an expose event
1238         // for the window.
1239         // Unfortunately X does not handle expose events for you and 
1240         // it is the client's job to refresh the dirty part of the window.
1241         // We need to queue up invalidate calls and generate GHOST events 
1242         // for them in the system.
1243
1244         // We implement this by setting a boolean in this class to concatenate 
1245         // all such calls into a single event for this window.
1246
1247         // At the same time we queue the dirty windows in the system class
1248         // and generate events for them at the next processEvents call.
1249
1250         if (m_invalid_window == false) {
1251                 m_system->addDirtyWindow(this);
1252                 m_invalid_window = true;
1253         } 
1254  
1255         return GHOST_kSuccess;
1256 }
1257
1258 /**
1259  * called by the X11 system implementation when expose events
1260  * for the window have been pushed onto the GHOST queue
1261  */
1262  
1263         void
1264 GHOST_WindowX11::
1265 validate(
1266 ){
1267         m_invalid_window = false;
1268 }       
1269  
1270  
1271 /**
1272  * Destructor.
1273  * Closes the window and disposes resources allocated.
1274  */
1275
1276 GHOST_WindowX11::
1277 ~GHOST_WindowX11(
1278 ){
1279         static Atom Primary_atom, Clipboard_atom;
1280         Window p_owner, c_owner;
1281         /*Change the owner of the Atoms to None if we are the owner*/
1282         Primary_atom = XInternAtom(m_display, "PRIMARY", False);
1283         Clipboard_atom = XInternAtom(m_display, "CLIPBOARD", False);
1284         
1285         p_owner = XGetSelectionOwner(m_display, Primary_atom);
1286         c_owner = XGetSelectionOwner(m_display, Clipboard_atom);
1287         
1288         std::map<unsigned int, Cursor>::iterator it = m_standard_cursors.begin();
1289         for (; it != m_standard_cursors.end(); it++) {
1290                 XFreeCursor(m_display, it->second);
1291         }
1292
1293         if (m_empty_cursor) {
1294                 XFreeCursor(m_display, m_empty_cursor);
1295         }
1296         if (m_custom_cursor) {
1297                 XFreeCursor(m_display, m_custom_cursor);
1298         }
1299
1300 #ifdef WITH_X11_XINPUT
1301         /* close tablet devices */
1302         if(m_xtablet.StylusDevice)
1303                 XCloseDevice(m_display, m_xtablet.StylusDevice);
1304         
1305         if(m_xtablet.EraserDevice)
1306                 XCloseDevice(m_display, m_xtablet.EraserDevice);
1307 #endif /* WITH_X11_XINPUT */
1308
1309         if (m_context != s_firstContext) {
1310                 glXDestroyContext(m_display, m_context);
1311         }
1312         
1313         if (p_owner == m_window) {
1314                 XSetSelectionOwner(m_display, Primary_atom, None, CurrentTime);
1315         }
1316         if (c_owner == m_window) {
1317                 XSetSelectionOwner(m_display, Clipboard_atom, None, CurrentTime);
1318         }
1319         
1320 #if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING)
1321         if (m_xic) {
1322                 XDestroyIC(m_xic);
1323         }
1324 #endif
1325
1326         delete m_dropTarget;
1327
1328         XDestroyWindow(m_display, m_window);
1329         XFree(m_visual);
1330 }
1331
1332
1333
1334
1335 /**
1336  * Tries to install a rendering context in this window.
1337  * @param type  The type of rendering context installed.
1338  * @return Indication as to whether installation has succeeded.
1339  */
1340         GHOST_TSuccess 
1341 GHOST_WindowX11::
1342 installDrawingContext(
1343         GHOST_TDrawingContextType type
1344 ){
1345         // only support openGL for now.
1346         GHOST_TSuccess success;
1347         switch (type) {
1348         case GHOST_kDrawingContextTypeOpenGL:
1349                 m_context = glXCreateContext(m_display, m_visual, s_firstContext, True);
1350                 if (m_context !=NULL) {
1351                         if (!s_firstContext) {
1352                                 s_firstContext = m_context;
1353                         }
1354                         glXMakeCurrent(m_display, m_window,m_context);
1355                         glClearColor(0.447, 0.447, 0.447, 0);
1356                         glClear(GL_COLOR_BUFFER_BIT);
1357                         success = GHOST_kSuccess;
1358                 } else {
1359                         success = GHOST_kFailure;
1360                 }
1361
1362                 break;
1363
1364         case GHOST_kDrawingContextTypeNone:
1365                 success = GHOST_kSuccess;
1366                 break;
1367
1368         default:
1369                 success = GHOST_kFailure;
1370         }
1371         return success;
1372 }
1373
1374
1375
1376 /**
1377  * Removes the current drawing context.
1378  * @return Indication as to whether removal has succeeded.
1379  */
1380         GHOST_TSuccess 
1381 GHOST_WindowX11::
1382 removeDrawingContext(
1383 ){
1384         GHOST_TSuccess success;
1385
1386         if (m_context != NULL) {
1387                 glXDestroyContext(m_display, m_context);
1388                 success = GHOST_kSuccess;
1389         } else {
1390                 success = GHOST_kFailure;
1391         }
1392         return success; 
1393 }
1394
1395
1396         Cursor
1397 GHOST_WindowX11::
1398 getStandardCursor(
1399         GHOST_TStandardCursor g_cursor
1400 ){
1401         unsigned int xcursor_id;
1402
1403 #define GtoX(gcurs, xcurs)      case gcurs: xcursor_id = xcurs
1404         switch (g_cursor) {
1405         GtoX(GHOST_kStandardCursorRightArrow, XC_arrow); break;
1406         GtoX(GHOST_kStandardCursorLeftArrow, XC_top_left_arrow); break;
1407         GtoX(GHOST_kStandardCursorInfo, XC_hand1); break;
1408         GtoX(GHOST_kStandardCursorDestroy, XC_pirate); break;
1409         GtoX(GHOST_kStandardCursorHelp, XC_question_arrow); break; 
1410         GtoX(GHOST_kStandardCursorCycle, XC_exchange); break;
1411         GtoX(GHOST_kStandardCursorSpray, XC_spraycan); break;
1412         GtoX(GHOST_kStandardCursorWait, XC_watch); break;
1413         GtoX(GHOST_kStandardCursorText, XC_xterm); break;
1414         GtoX(GHOST_kStandardCursorCrosshair, XC_crosshair); break;
1415         GtoX(GHOST_kStandardCursorUpDown, XC_sb_v_double_arrow); break;
1416         GtoX(GHOST_kStandardCursorLeftRight, XC_sb_h_double_arrow); break;
1417         GtoX(GHOST_kStandardCursorTopSide, XC_top_side); break;
1418         GtoX(GHOST_kStandardCursorBottomSide, XC_bottom_side); break;
1419         GtoX(GHOST_kStandardCursorLeftSide, XC_left_side); break;
1420         GtoX(GHOST_kStandardCursorRightSide, XC_right_side); break;
1421         GtoX(GHOST_kStandardCursorTopLeftCorner, XC_top_left_corner); break;
1422         GtoX(GHOST_kStandardCursorTopRightCorner, XC_top_right_corner); break;
1423         GtoX(GHOST_kStandardCursorBottomRightCorner, XC_bottom_right_corner); break;
1424         GtoX(GHOST_kStandardCursorBottomLeftCorner, XC_bottom_left_corner); break;
1425         GtoX(GHOST_kStandardCursorPencil, XC_pencil); break;
1426         GtoX(GHOST_kStandardCursorCopy, XC_arrow); break;
1427         default:
1428                 xcursor_id = 0;
1429         }
1430 #undef GtoX
1431
1432         if (xcursor_id) {
1433                 Cursor xcursor = m_standard_cursors[xcursor_id];
1434                 
1435                 if (!xcursor) {
1436                         xcursor = XCreateFontCursor(m_display, xcursor_id);
1437
1438                         m_standard_cursors[xcursor_id] = xcursor;
1439                 }
1440                 
1441                 return xcursor;
1442         } else {
1443                 return None;
1444         }
1445 }
1446
1447         Cursor 
1448 GHOST_WindowX11::
1449 getEmptyCursor(
1450 ) {
1451         if (!m_empty_cursor) {
1452                 Pixmap blank;
1453                 XColor dummy;
1454                 char data[1] = {0};
1455                         
1456                 /* make a blank cursor */
1457                 blank = XCreateBitmapFromData (
1458                         m_display, 
1459                         RootWindow(m_display,DefaultScreen(m_display)),
1460                         data, 1, 1
1461                 );
1462
1463                 m_empty_cursor = XCreatePixmapCursor(m_display, blank, blank, &dummy, &dummy, 0, 0);
1464                 XFreePixmap(m_display, blank);
1465         }
1466
1467         return m_empty_cursor;
1468 }
1469
1470         GHOST_TSuccess
1471 GHOST_WindowX11::
1472 setWindowCursorVisibility(
1473         bool visible
1474 ){
1475         Cursor xcursor;
1476         
1477         if (visible) {
1478                 xcursor = getStandardCursor( getCursorShape() );
1479         } else {
1480                 xcursor = getEmptyCursor();
1481         }
1482
1483         XDefineCursor(m_display, m_window, xcursor);
1484         XFlush(m_display);
1485         
1486         return GHOST_kSuccess;
1487 }
1488
1489         GHOST_TSuccess
1490 GHOST_WindowX11::
1491 setWindowCursorGrab(
1492         GHOST_TGrabCursorMode mode
1493 ){
1494         if(mode != GHOST_kGrabDisable) {
1495                 if(mode != GHOST_kGrabNormal) {
1496                         m_system->getCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
1497                         setCursorGrabAccum(0, 0);
1498
1499                         if(mode == GHOST_kGrabHide)
1500                                 setWindowCursorVisibility(false);
1501
1502                 }
1503 #ifdef GHOST_X11_GRAB
1504                 XGrabPointer(m_display, m_window, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
1505                              GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
1506 #endif
1507         }
1508         else {
1509                 if (m_cursorGrab==GHOST_kGrabHide) {
1510                         m_system->setCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
1511                         setWindowCursorVisibility(true);
1512                 }
1513
1514                 if(m_cursorGrab != GHOST_kGrabNormal) {
1515                         /* use to generate a mouse move event, otherwise the last event
1516                          * blender gets can be outside the screen causing menus not to show
1517                          * properly unless the user moves the mouse */
1518                         XWarpPointer(m_display,None,None,0,0,0,0,0,0);
1519                 }
1520
1521                 /* Almost works without but important otherwise the mouse GHOST location can be incorrect on exit */
1522                 setCursorGrabAccum(0, 0);
1523                 m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1; /* disable */
1524 #ifdef GHOST_X11_GRAB
1525                 XUngrabPointer(m_display, CurrentTime);
1526 #endif
1527         }
1528
1529         XFlush(m_display);
1530         
1531         return GHOST_kSuccess;
1532 }
1533
1534         GHOST_TSuccess
1535 GHOST_WindowX11::
1536 setWindowCursorShape(
1537         GHOST_TStandardCursor shape
1538 ){
1539         Cursor xcursor = getStandardCursor( shape );
1540         
1541         XDefineCursor(m_display, m_window, xcursor);
1542         XFlush(m_display);
1543
1544         return GHOST_kSuccess;
1545 }
1546
1547         GHOST_TSuccess
1548 GHOST_WindowX11::
1549 setWindowCustomCursorShape(
1550         GHOST_TUns8 bitmap[16][2], 
1551         GHOST_TUns8 mask[16][2], 
1552         int hotX, 
1553         int hotY
1554 ){
1555
1556 setWindowCustomCursorShape((GHOST_TUns8*)bitmap, (GHOST_TUns8*)mask, 
1557                                                                         16, 16, hotX, hotY, 0, 1);
1558         return GHOST_kSuccess;
1559 }
1560
1561         GHOST_TSuccess
1562 GHOST_WindowX11::
1563 setWindowCustomCursorShape(     
1564         GHOST_TUns8 *bitmap, 
1565         GHOST_TUns8 *mask, 
1566         int sizex, 
1567         int sizey, 
1568         int hotX, 
1569         int hotY, 
1570         int fg_color, 
1571         int bg_color
1572 ){
1573         Colormap colormap= DefaultColormap(m_display, DefaultScreen(m_display));
1574         Pixmap bitmap_pix, mask_pix;
1575         XColor fg, bg;
1576         
1577         if(XAllocNamedColor(m_display, colormap, "White", &fg, &fg) == 0) return GHOST_kFailure;
1578         if(XAllocNamedColor(m_display, colormap, "Black", &bg, &bg) == 0) return GHOST_kFailure;
1579
1580         if (m_custom_cursor) {
1581                 XFreeCursor(m_display, m_custom_cursor);
1582         }
1583
1584         bitmap_pix = XCreateBitmapFromData(m_display, m_window, (char*) bitmap, sizex, sizey);
1585         mask_pix = XCreateBitmapFromData(m_display, m_window, (char*) mask, sizex, sizey);
1586                 
1587         m_custom_cursor = XCreatePixmapCursor(m_display, bitmap_pix, mask_pix, &fg, &bg, hotX, hotY);
1588         XDefineCursor(m_display, m_window, m_custom_cursor);
1589         XFlush(m_display);
1590         
1591         XFreePixmap(m_display, bitmap_pix);
1592         XFreePixmap(m_display, mask_pix);
1593
1594     XFreeColors(m_display, colormap, &fg.pixel, 1, 0L);
1595     XFreeColors(m_display, colormap, &bg.pixel, 1, 0L);
1596
1597         return GHOST_kSuccess;
1598 }