|
| 1 | + |
| 2 | + |
| 3 | +# Poke around to see about matching visuals... |
| 4 | +# From https://github.com/garrybodsworth/pyxlib-ctypes |
| 5 | + |
| 6 | +from ctypes import * |
| 7 | +from ctypes import util |
| 8 | +libX11 = CDLL( util.find_library( "X11" )) |
| 9 | + |
| 10 | +XPointer = c_char_p |
| 11 | +XID = c_ulong |
| 12 | +VisualID = c_ulong |
| 13 | +Window = XID |
| 14 | +Bool = c_int |
| 15 | +Colormap = XID |
| 16 | +Status = c_int |
| 17 | + |
| 18 | +class _XExtData(Structure): |
| 19 | + pass |
| 20 | +_XExtData._fields_ = [ |
| 21 | + ('number', c_int), |
| 22 | + ('next', POINTER(_XExtData)), |
| 23 | + ('free_private', c_void_p), |
| 24 | + ('private_data', XPointer), |
| 25 | +] |
| 26 | +XExtData = _XExtData |
| 27 | + |
| 28 | +GContext = XID |
| 29 | +class _XGC(Structure): |
| 30 | + _fields_ = [ |
| 31 | + ('ext_data', POINTER(XExtData)), |
| 32 | + ('gid', GContext), |
| 33 | + ] |
| 34 | +GC = POINTER(_XGC) |
| 35 | + |
| 36 | +class Visual(Structure): |
| 37 | + _fields_ = [ |
| 38 | + ('ext_data', POINTER(XExtData)), |
| 39 | + ('visualid', VisualID), |
| 40 | + ('c_class', c_int), |
| 41 | + ('red_mask', c_ulong), |
| 42 | + ('green_mask', c_ulong), |
| 43 | + ('blue_mask', c_ulong), |
| 44 | + ('bits_per_rgb', c_int), |
| 45 | + ('map_entries', c_int), |
| 46 | + ] |
| 47 | + |
| 48 | +class Depth(Structure): |
| 49 | + _fields_ = [ |
| 50 | + ('depth', c_int), |
| 51 | + ('nvisuals', c_int), |
| 52 | + ('visuals', POINTER(Visual)), |
| 53 | + ] |
| 54 | + |
| 55 | + |
| 56 | +class ScreenFormat(Structure): |
| 57 | + _fields_ = [ |
| 58 | + ('ext_data', POINTER(XExtData)), |
| 59 | + ('depth', c_int), |
| 60 | + ('bits_per_pixel', c_int), |
| 61 | + ('scanline_pad', c_int), |
| 62 | + ] |
| 63 | + |
| 64 | +class _XrmHashBucketRec(Structure): pass |
| 65 | + |
| 66 | +class _XPrivate(Structure): pass |
| 67 | + |
| 68 | +class _XDisplay(Structure): pass |
| 69 | + |
| 70 | +class Screen(Structure): |
| 71 | + _fields_ = [ |
| 72 | + ('ext_data', POINTER(XExtData)), |
| 73 | + ('display', POINTER(_XDisplay)), |
| 74 | + ('root', Window), |
| 75 | + ('width', c_int), |
| 76 | + ('height', c_int), |
| 77 | + ('mwidth', c_int), |
| 78 | + ('mheight', c_int), |
| 79 | + ('ndepths', c_int), |
| 80 | + ('depths', POINTER(Depth)), |
| 81 | + ('root_depth', c_int), |
| 82 | + ('root_visual', POINTER(Visual)), |
| 83 | + ('default_gc', GC), |
| 84 | + ('cmap', Colormap), |
| 85 | + ('white_pixel', c_ulong), |
| 86 | + ('black_pixel', c_ulong), |
| 87 | + ('max_maps', c_int), |
| 88 | + ('min_maps', c_int), |
| 89 | + ('backing_store', c_int), |
| 90 | + ('save_unders', Bool), |
| 91 | + ('root_input_mask', c_long), |
| 92 | + ] |
| 93 | + class _XDisplay(Structure): pass |
| 94 | + |
| 95 | +_XDisplay._fields_ = [ |
| 96 | + ('ext_data', POINTER(XExtData)), |
| 97 | + ('private1', POINTER(_XPrivate)), |
| 98 | + ('fd', c_int), |
| 99 | + ('private2', c_int), |
| 100 | + ('proto_major_version', c_int), |
| 101 | + ('proto_minor_version', c_int), |
| 102 | + ('vendor', c_char_p), |
| 103 | + ('private3', XID), |
| 104 | + ('private4', XID), |
| 105 | + ('private5', XID), |
| 106 | + ('private6', c_int), |
| 107 | + ('resource_alloc', c_void_p), |
| 108 | + ('byte_order', c_int), |
| 109 | + ('bitmap_unit', c_int), |
| 110 | + ('bitmap_pad', c_int), |
| 111 | + ('bitmap_bit_order', c_int), |
| 112 | + ('nformats', c_int), |
| 113 | + ('pixmap_format', POINTER(ScreenFormat)), |
| 114 | + ('private8', c_int), |
| 115 | + ('release', c_int), |
| 116 | + ('private9', POINTER(_XPrivate)), |
| 117 | + ('private10', POINTER(_XPrivate)), |
| 118 | + ('qlen', c_int), |
| 119 | + ('last_request_read', c_ulong), |
| 120 | + ('request', c_ulong), |
| 121 | + ('private11', XPointer), |
| 122 | + ('private12', XPointer), |
| 123 | + ('private13', XPointer), |
| 124 | + ('private14', XPointer), |
| 125 | + ('max_request_size', c_uint), |
| 126 | + ('db', POINTER(_XrmHashBucketRec)), |
| 127 | + ('private15', c_void_p), |
| 128 | + ('display_name', c_char_p), |
| 129 | + ('default_screen', c_int), |
| 130 | + ('nscreens', c_int), |
| 131 | + ('screens', POINTER(Screen)), |
| 132 | + ('motion_buffer', c_ulong), |
| 133 | + ('private16', c_ulong), |
| 134 | + ('min_keycode', c_int), |
| 135 | + ('max_keycode', c_int), |
| 136 | + ('private17', XPointer), |
| 137 | + ('private18', XPointer), |
| 138 | + ('private19', c_int), |
| 139 | + ('xdefaults', c_char_p), |
| 140 | +] |
| 141 | +Display = _XDisplay |
| 142 | + |
| 143 | + |
| 144 | +class XWindowAttributes(Structure): |
| 145 | + _fields_ = [ |
| 146 | + ('x', c_int), |
| 147 | + ('y', c_int), |
| 148 | + ('width', c_int), |
| 149 | + ('height', c_int), |
| 150 | + ('border_width', c_int), |
| 151 | + ('depth', c_int), |
| 152 | + ('visual', POINTER(Visual)), |
| 153 | + ('root', Window), |
| 154 | + ('c_class', c_int), |
| 155 | + ('bit_gravity', c_int), |
| 156 | + ('win_gravity', c_int), |
| 157 | + ('backing_store', c_int), |
| 158 | + ('backing_planes', c_ulong), |
| 159 | + ('backing_pixel', c_ulong), |
| 160 | + ('save_under', Bool), |
| 161 | + ('colormap', Colormap), |
| 162 | + ('map_installed', Bool), |
| 163 | + ('map_state', c_int), |
| 164 | + ('all_event_masks', c_long), |
| 165 | + ('your_event_mask', c_long), |
| 166 | + ('do_not_propagate_mask', c_long), |
| 167 | + ('override_redirect', Bool), |
| 168 | + ('screen', POINTER(Screen)), |
| 169 | + ] |
| 170 | + |
| 171 | +XGetWindowAttributes = libX11.XGetWindowAttributes |
| 172 | +XGetWindowAttributes.restype = Status |
| 173 | +XGetWindowAttributes.argtypes = [POINTER(Display), Window, POINTER(XWindowAttributes)] |
| 174 | + |
| 175 | +XOpenDisplay = libX11.XOpenDisplay |
| 176 | +XOpenDisplay.restype = POINTER(Display) |
| 177 | +XOpenDisplay.argtypes = [c_char_p] |
| 178 | + |
| 179 | +def getXWA( wid ): |
| 180 | + dpy = XOpenDisplay("") |
| 181 | + attrs = XWindowAttributes() |
| 182 | + status = XGetWindowAttributes( dpy, Window(wid), pointer(attrs) ) |
| 183 | + return attrs |
| 184 | + |
| 185 | +__all__ = [ getXWA ] |
| 186 | + |
| 187 | +if __name__ == "__main__": |
| 188 | + import Tkinter |
| 189 | + root = Tkinter.Tk() |
| 190 | + frm = Tkinter.Frame(root, width=200, height=200, bg="" ) |
| 191 | + frm.pack() |
| 192 | + |
| 193 | + def testframe(): |
| 194 | + dpy = XOpenDisplay("") |
| 195 | + attrs = XWindowAttributes() |
| 196 | + print dpy |
| 197 | + print attrs |
| 198 | + status = XGetWindowAttributes( dpy, Window(frm.winfo_id()), pointer(attrs) ) |
| 199 | + print status |
| 200 | + print attrs.visual.contents.bits_per_rgb |
| 201 | + print attrs.visual.contents.visualid |
| 202 | + |
| 203 | + frm.after(100, testframe) |
| 204 | + root.mainloop() |
| 205 | + |
0 commit comments