pyglet 2.1.13__py3-none-any.whl → 3.0.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. pyglet/__init__.py +67 -61
  2. pyglet/__init__.pyi +15 -8
  3. pyglet/app/__init__.py +22 -13
  4. pyglet/app/async_app.py +212 -0
  5. pyglet/app/base.py +2 -1
  6. pyglet/app/{xlib.py → linux.py} +3 -3
  7. pyglet/config/__init__.py +101 -0
  8. pyglet/config/gl/__init__.py +30 -0
  9. pyglet/config/gl/egl.py +120 -0
  10. pyglet/config/gl/macos.py +262 -0
  11. pyglet/config/gl/windows.py +267 -0
  12. pyglet/config/gl/x11.py +142 -0
  13. pyglet/customtypes.py +43 -2
  14. pyglet/display/__init__.py +8 -6
  15. pyglet/display/base.py +3 -63
  16. pyglet/display/cocoa.py +12 -17
  17. pyglet/display/emscripten.py +39 -0
  18. pyglet/display/headless.py +23 -30
  19. pyglet/display/wayland.py +157 -0
  20. pyglet/display/win32.py +5 -21
  21. pyglet/display/xlib.py +19 -27
  22. pyglet/display/xlib_vidmoderestore.py +2 -2
  23. pyglet/enums.py +183 -0
  24. pyglet/event.py +0 -1
  25. pyglet/experimental/geoshader_sprite.py +15 -13
  26. pyglet/experimental/hidraw.py +6 -15
  27. pyglet/experimental/multitexture_sprite.py +31 -19
  28. pyglet/experimental/particles.py +13 -35
  29. pyglet/font/__init__.py +251 -85
  30. pyglet/font/base.py +116 -61
  31. pyglet/font/dwrite/__init__.py +349 -204
  32. pyglet/font/dwrite/dwrite_lib.py +27 -5
  33. pyglet/font/fontconfig.py +14 -6
  34. pyglet/font/freetype.py +138 -87
  35. pyglet/font/freetype_lib.py +19 -0
  36. pyglet/font/group.py +179 -0
  37. pyglet/font/harfbuzz/__init__.py +3 -3
  38. pyglet/font/pyodide_js.py +310 -0
  39. pyglet/font/quartz.py +319 -126
  40. pyglet/font/ttf.py +45 -3
  41. pyglet/font/user.py +14 -19
  42. pyglet/font/win32.py +45 -21
  43. pyglet/graphics/__init__.py +8 -787
  44. pyglet/graphics/allocation.py +115 -1
  45. pyglet/graphics/api/__init__.py +77 -0
  46. pyglet/graphics/api/base.py +299 -0
  47. pyglet/graphics/api/gl/__init__.py +58 -0
  48. pyglet/graphics/api/gl/base.py +24 -0
  49. pyglet/graphics/{vertexbuffer.py → api/gl/buffer.py} +104 -159
  50. pyglet/graphics/api/gl/cocoa/context.py +76 -0
  51. pyglet/graphics/api/gl/context.py +391 -0
  52. pyglet/graphics/api/gl/default_shaders.py +0 -0
  53. pyglet/graphics/api/gl/draw.py +627 -0
  54. pyglet/graphics/api/gl/egl/__init__.py +0 -0
  55. pyglet/graphics/api/gl/egl/context.py +92 -0
  56. pyglet/graphics/api/gl/enums.py +76 -0
  57. pyglet/graphics/api/gl/framebuffer.py +315 -0
  58. pyglet/graphics/api/gl/gl.py +5463 -0
  59. pyglet/graphics/api/gl/gl_info.py +188 -0
  60. pyglet/graphics/api/gl/global_opengl.py +226 -0
  61. pyglet/{gl → graphics/api/gl}/lib.py +34 -18
  62. pyglet/graphics/api/gl/shader.py +1476 -0
  63. pyglet/graphics/api/gl/shapes.py +55 -0
  64. pyglet/graphics/api/gl/sprite.py +102 -0
  65. pyglet/graphics/api/gl/state.py +219 -0
  66. pyglet/graphics/api/gl/text.py +190 -0
  67. pyglet/graphics/api/gl/texture.py +1526 -0
  68. pyglet/graphics/{vertexarray.py → api/gl/vertexarray.py} +11 -13
  69. pyglet/graphics/api/gl/vertexdomain.py +751 -0
  70. pyglet/graphics/api/gl/win32/__init__.py +0 -0
  71. pyglet/graphics/api/gl/win32/context.py +108 -0
  72. pyglet/graphics/api/gl/win32/wgl_info.py +24 -0
  73. pyglet/graphics/api/gl/xlib/__init__.py +0 -0
  74. pyglet/graphics/api/gl/xlib/context.py +174 -0
  75. pyglet/{gl → graphics/api/gl/xlib}/glx_info.py +26 -31
  76. pyglet/graphics/api/gl1/__init__.py +0 -0
  77. pyglet/{gl → graphics/api/gl1}/gl_compat.py +3 -2
  78. pyglet/graphics/api/gl2/__init__.py +0 -0
  79. pyglet/graphics/api/gl2/buffer.py +320 -0
  80. pyglet/graphics/api/gl2/draw.py +600 -0
  81. pyglet/graphics/api/gl2/global_opengl.py +122 -0
  82. pyglet/graphics/api/gl2/shader.py +200 -0
  83. pyglet/graphics/api/gl2/shapes.py +51 -0
  84. pyglet/graphics/api/gl2/sprite.py +79 -0
  85. pyglet/graphics/api/gl2/text.py +175 -0
  86. pyglet/graphics/api/gl2/vertexdomain.py +364 -0
  87. pyglet/graphics/api/webgl/__init__.py +233 -0
  88. pyglet/graphics/api/webgl/buffer.py +302 -0
  89. pyglet/graphics/api/webgl/context.py +234 -0
  90. pyglet/graphics/api/webgl/draw.py +590 -0
  91. pyglet/graphics/api/webgl/enums.py +76 -0
  92. pyglet/graphics/api/webgl/framebuffer.py +360 -0
  93. pyglet/graphics/api/webgl/gl.py +1537 -0
  94. pyglet/graphics/api/webgl/gl_info.py +130 -0
  95. pyglet/graphics/api/webgl/shader.py +1346 -0
  96. pyglet/graphics/api/webgl/shapes.py +92 -0
  97. pyglet/graphics/api/webgl/sprite.py +102 -0
  98. pyglet/graphics/api/webgl/state.py +227 -0
  99. pyglet/graphics/api/webgl/text.py +187 -0
  100. pyglet/graphics/api/webgl/texture.py +1227 -0
  101. pyglet/graphics/api/webgl/vertexarray.py +54 -0
  102. pyglet/graphics/api/webgl/vertexdomain.py +616 -0
  103. pyglet/graphics/api/webgl/webgl_js.pyi +307 -0
  104. pyglet/{image → graphics}/atlas.py +33 -32
  105. pyglet/graphics/base.py +10 -0
  106. pyglet/graphics/buffer.py +245 -0
  107. pyglet/graphics/draw.py +578 -0
  108. pyglet/graphics/framebuffer.py +26 -0
  109. pyglet/graphics/instance.py +178 -69
  110. pyglet/graphics/shader.py +267 -1553
  111. pyglet/graphics/state.py +83 -0
  112. pyglet/graphics/texture.py +703 -0
  113. pyglet/graphics/vertexdomain.py +695 -538
  114. pyglet/gui/ninepatch.py +10 -10
  115. pyglet/gui/widgets.py +120 -10
  116. pyglet/image/__init__.py +20 -1973
  117. pyglet/image/animation.py +12 -12
  118. pyglet/image/base.py +730 -0
  119. pyglet/image/codecs/__init__.py +9 -0
  120. pyglet/image/codecs/bmp.py +53 -30
  121. pyglet/image/codecs/dds.py +53 -31
  122. pyglet/image/codecs/gdiplus.py +38 -14
  123. pyglet/image/codecs/gdkpixbuf2.py +0 -2
  124. pyglet/image/codecs/js_image.py +99 -0
  125. pyglet/image/codecs/ktx2.py +161 -0
  126. pyglet/image/codecs/pil.py +1 -1
  127. pyglet/image/codecs/png.py +1 -1
  128. pyglet/image/codecs/wic.py +11 -2
  129. pyglet/info.py +26 -24
  130. pyglet/input/__init__.py +8 -0
  131. pyglet/input/base.py +163 -105
  132. pyglet/input/controller.py +13 -19
  133. pyglet/input/controller_db.py +39 -24
  134. pyglet/input/emscripten/__init__.py +18 -0
  135. pyglet/input/emscripten/gamepad_js.py +397 -0
  136. pyglet/input/linux/__init__.py +11 -5
  137. pyglet/input/linux/evdev.py +10 -11
  138. pyglet/input/linux/x11_xinput.py +2 -2
  139. pyglet/input/linux/x11_xinput_tablet.py +1 -1
  140. pyglet/input/macos/__init__.py +7 -2
  141. pyglet/input/macos/darwin_gc.py +559 -0
  142. pyglet/input/win32/__init__.py +1 -1
  143. pyglet/input/win32/directinput.py +34 -29
  144. pyglet/input/win32/xinput.py +11 -61
  145. pyglet/lib.py +3 -3
  146. pyglet/libs/__init__.py +1 -1
  147. pyglet/{gl → libs/darwin}/agl.py +1 -1
  148. pyglet/libs/darwin/cocoapy/__init__.py +2 -2
  149. pyglet/libs/darwin/cocoapy/cocoahelpers.py +181 -0
  150. pyglet/libs/darwin/cocoapy/cocoalibs.py +31 -0
  151. pyglet/libs/darwin/cocoapy/cocoatypes.py +27 -0
  152. pyglet/libs/darwin/cocoapy/runtime.py +81 -45
  153. pyglet/libs/darwin/coreaudio.py +4 -4
  154. pyglet/{gl → libs/darwin}/lib_agl.py +9 -8
  155. pyglet/libs/darwin/quartzkey.py +1 -3
  156. pyglet/libs/egl/__init__.py +2 -0
  157. pyglet/libs/egl/egl_lib.py +576 -0
  158. pyglet/libs/egl/eglext.py +51 -5
  159. pyglet/libs/linux/__init__.py +0 -0
  160. pyglet/libs/linux/egl/__init__.py +0 -0
  161. pyglet/libs/linux/egl/eglext.py +22 -0
  162. pyglet/libs/linux/glx/__init__.py +0 -0
  163. pyglet/{gl → libs/linux/glx}/glx.py +13 -14
  164. pyglet/{gl → libs/linux/glx}/glxext_arb.py +408 -192
  165. pyglet/{gl → libs/linux/glx}/glxext_mesa.py +1 -1
  166. pyglet/{gl → libs/linux/glx}/glxext_nv.py +345 -164
  167. pyglet/{gl → libs/linux/glx}/lib_glx.py +3 -2
  168. pyglet/libs/linux/wayland/__init__.py +0 -0
  169. pyglet/libs/linux/wayland/client.py +1068 -0
  170. pyglet/libs/linux/wayland/lib_wayland.py +207 -0
  171. pyglet/libs/linux/wayland/wayland_egl.py +38 -0
  172. pyglet/libs/{wayland → linux/wayland}/xkbcommon.py +26 -0
  173. pyglet/libs/{x11 → linux/x11}/xf86vmode.py +4 -4
  174. pyglet/libs/{x11 → linux/x11}/xinerama.py +2 -2
  175. pyglet/libs/{x11 → linux/x11}/xinput.py +10 -10
  176. pyglet/libs/linux/x11/xrandr.py +0 -0
  177. pyglet/libs/{x11 → linux/x11}/xrender.py +1 -1
  178. pyglet/libs/shared/__init__.py +0 -0
  179. pyglet/libs/shared/spirv/__init__.py +0 -0
  180. pyglet/libs/shared/spirv/lib_shaderc.py +85 -0
  181. pyglet/libs/shared/spirv/lib_spirv_cross.py +126 -0
  182. pyglet/libs/win32/__init__.py +28 -8
  183. pyglet/libs/win32/constants.py +59 -48
  184. pyglet/libs/win32/context_managers.py +20 -3
  185. pyglet/libs/win32/dinput.py +105 -88
  186. pyglet/{gl → libs/win32}/lib_wgl.py +52 -26
  187. pyglet/libs/win32/types.py +58 -23
  188. pyglet/{gl → libs/win32}/wgl.py +32 -25
  189. pyglet/{gl → libs/win32}/wglext_arb.py +364 -2
  190. pyglet/media/__init__.py +9 -10
  191. pyglet/media/codecs/__init__.py +12 -1
  192. pyglet/media/codecs/base.py +99 -96
  193. pyglet/media/codecs/ffmpeg.py +2 -2
  194. pyglet/media/codecs/ffmpeg_lib/libavformat.py +3 -8
  195. pyglet/media/codecs/webaudio_pyodide.py +111 -0
  196. pyglet/media/drivers/__init__.py +9 -4
  197. pyglet/media/drivers/base.py +4 -4
  198. pyglet/media/drivers/openal/__init__.py +1 -1
  199. pyglet/media/drivers/openal/adaptation.py +3 -3
  200. pyglet/media/drivers/pulse/__init__.py +1 -1
  201. pyglet/media/drivers/pulse/adaptation.py +3 -3
  202. pyglet/media/drivers/pyodide_js/__init__.py +8 -0
  203. pyglet/media/drivers/pyodide_js/adaptation.py +288 -0
  204. pyglet/media/drivers/xaudio2/adaptation.py +3 -3
  205. pyglet/media/player.py +276 -193
  206. pyglet/media/player_worker_thread.py +1 -1
  207. pyglet/model/__init__.py +39 -29
  208. pyglet/model/codecs/base.py +4 -4
  209. pyglet/model/codecs/gltf.py +3 -3
  210. pyglet/model/codecs/obj.py +71 -43
  211. pyglet/resource.py +129 -78
  212. pyglet/shapes.py +154 -194
  213. pyglet/sprite.py +47 -164
  214. pyglet/text/__init__.py +44 -54
  215. pyglet/text/caret.py +12 -7
  216. pyglet/text/document.py +19 -17
  217. pyglet/text/formats/html.py +2 -2
  218. pyglet/text/formats/structured.py +10 -40
  219. pyglet/text/layout/__init__.py +20 -13
  220. pyglet/text/layout/base.py +176 -287
  221. pyglet/text/layout/incremental.py +9 -10
  222. pyglet/text/layout/scrolling.py +7 -95
  223. pyglet/window/__init__.py +183 -172
  224. pyglet/window/cocoa/__init__.py +62 -51
  225. pyglet/window/cocoa/pyglet_delegate.py +2 -25
  226. pyglet/window/cocoa/pyglet_view.py +9 -8
  227. pyglet/window/dialog/__init__.py +184 -0
  228. pyglet/window/dialog/base.py +99 -0
  229. pyglet/window/dialog/darwin.py +121 -0
  230. pyglet/window/dialog/linux.py +72 -0
  231. pyglet/window/dialog/windows.py +194 -0
  232. pyglet/window/emscripten/__init__.py +779 -0
  233. pyglet/window/headless/__init__.py +44 -28
  234. pyglet/window/key.py +2 -0
  235. pyglet/window/mouse.py +2 -2
  236. pyglet/window/wayland/__init__.py +377 -0
  237. pyglet/window/win32/__init__.py +101 -46
  238. pyglet/window/xlib/__init__.py +104 -66
  239. {pyglet-2.1.13.dist-info → pyglet-3.0.dev1.dist-info}/METADATA +2 -3
  240. pyglet-3.0.dev1.dist-info/RECORD +322 -0
  241. {pyglet-2.1.13.dist-info → pyglet-3.0.dev1.dist-info}/WHEEL +1 -1
  242. pyglet/gl/__init__.py +0 -208
  243. pyglet/gl/base.py +0 -499
  244. pyglet/gl/cocoa.py +0 -309
  245. pyglet/gl/gl.py +0 -4625
  246. pyglet/gl/gl.pyi +0 -2320
  247. pyglet/gl/gl_compat.pyi +0 -3097
  248. pyglet/gl/gl_info.py +0 -190
  249. pyglet/gl/headless.py +0 -166
  250. pyglet/gl/wgl_info.py +0 -36
  251. pyglet/gl/wglext_nv.py +0 -1096
  252. pyglet/gl/win32.py +0 -268
  253. pyglet/gl/xlib.py +0 -295
  254. pyglet/image/buffer.py +0 -274
  255. pyglet/image/codecs/s3tc.py +0 -354
  256. pyglet/libs/x11/xrandr.py +0 -166
  257. pyglet-2.1.13.dist-info/RECORD +0 -234
  258. /pyglet/{libs/wayland → graphics/api/gl/cocoa}/__init__.py +0 -0
  259. /pyglet/libs/{egl → linux/egl}/egl.py +0 -0
  260. /pyglet/libs/{egl → linux/egl}/lib.py +0 -0
  261. /pyglet/libs/{ioctl.py → linux/ioctl.py} +0 -0
  262. /pyglet/libs/{wayland → linux/wayland}/gbm.py +0 -0
  263. /pyglet/libs/{x11 → linux/x11}/__init__.py +0 -0
  264. /pyglet/libs/{x11 → linux/x11}/cursorfont.py +0 -0
  265. /pyglet/libs/{x11 → linux/x11}/xlib.py +0 -0
  266. /pyglet/libs/{x11 → linux/x11}/xsync.py +0 -0
  267. {pyglet-2.1.13.dist-info/licenses → pyglet-3.0.dev1.dist-info}/LICENSE +0 -0
@@ -23,14 +23,16 @@ from ctypes import (
23
23
  pointer,
24
24
  sizeof,
25
25
  string_at,
26
+ c_float,
26
27
  )
27
28
  from functools import lru_cache
28
29
  from typing import TYPE_CHECKING, Sequence
29
30
 
30
31
  import pyglet
31
- from pyglet.display.xlib import XlibCanvas, XlibScreenXinerama
32
+ from pyglet.display.xlib import XlibScreenXinerama
32
33
  from pyglet.event import EventDispatcher
33
- from pyglet.libs.x11 import cursorfont, xlib
34
+ from pyglet.libs.linux.x11 import cursorfont, xlib
35
+ from pyglet.libs.linux.x11.xrender import XRenderFindVisualFormat
34
36
  from pyglet.util import asbytes
35
37
  from pyglet.window import (
36
38
  BaseWindow,
@@ -46,17 +48,18 @@ from pyglet.window import (
46
48
  )
47
49
 
48
50
  if TYPE_CHECKING:
51
+ from pyglet.config.gl.x11 import XlibGLSurfaceConfig
52
+ from pyglet.libs.linux.x11.xlib import Visual
49
53
  from _ctypes import _Pointer
50
- from pyglet.gl.xlib import XlibDisplayConfig
51
54
 
52
55
  try:
53
- from pyglet.libs.x11 import xsync
56
+ from pyglet.libs.linux.x11 import xsync
54
57
 
55
58
  _have_xsync = True
56
59
  except ImportError:
57
60
  _have_xsync = False
58
61
 
59
- _debug = pyglet.options['debug_x11']
62
+ _debug = pyglet.options.debug_x11
60
63
 
61
64
 
62
65
  class mwmhints_t(Structure):
@@ -111,7 +114,7 @@ class XlibException(WindowException):
111
114
 
112
115
 
113
116
  class XlibMouseCursor(MouseCursor):
114
- gl_drawable: bool = False
117
+ api_drawable: bool = False
115
118
  hw_drawable: bool = True
116
119
 
117
120
  def __init__(self, cursor: xlib.Cursor) -> None:
@@ -124,7 +127,7 @@ ViewEventHandler = _ViewEventHandler
124
127
 
125
128
 
126
129
  class XlibWindow(BaseWindow):
127
- config: XlibDisplayConfig
130
+ config: XlibGLSurfaceConfig
128
131
  _x_display: xlib.Display | None = None # X display connection
129
132
  _x_screen_id: int | None = None # X screen index
130
133
  _x_ic: xlib.XIC | None = None # X input context
@@ -191,7 +194,7 @@ class XlibWindow(BaseWindow):
191
194
  self.context.detach()
192
195
  xlib.XDestroyWindow(self._x_display, self._window)
193
196
  del self.display._window_map[self._window] # noqa: SLF001
194
- del self.display._window_map[self._view] # noqa: SLF001
197
+ del self.display._window_map[self._x_window] # noqa: SLF001
195
198
  self._window = None
196
199
  self._mapped = False
197
200
 
@@ -224,23 +227,36 @@ class XlibWindow(BaseWindow):
224
227
  self._x_display = self.display._display # noqa: SLF001
225
228
  self._x_screen_id = self.display.x_screen
226
229
 
230
+ self._is_transparent = False
231
+
227
232
  # Create X window if not already existing.
228
233
  if not self._window:
229
234
  root = xlib.XRootWindow(self._x_display, self._x_screen_id)
230
235
 
231
- visual_info = self.config.get_visual_info()
236
+ # In OpenGL, it requires you to query GLX for the visual info.
237
+ if pyglet.options.backend is not None and not self._shadow:
238
+ if "gl" in pyglet.options.backend:
239
+ self._assign_config()
232
240
 
233
- visual = visual_info.visual
234
- visual_id = xlib.XVisualIDFromVisual(visual)
235
- default_visual = xlib.XDefaultVisual(self._x_display, self._x_screen_id)
236
- default_visual_id = xlib.XVisualIDFromVisual(default_visual)
237
- window_attributes = xlib.XSetWindowAttributes()
238
- if visual_id != default_visual_id:
239
- window_attributes.colormap = xlib.XCreateColormap(self._x_display, root,
240
- visual, xlib.AllocNone)
241
+ visual_info = self.config.get_visual_info()
242
+
243
+ visual = visual_info.visual
244
+ depth = visual_info.depth
245
+
246
+ # Vulkan just uses the default visual ID
247
+ elif pyglet.options.backend == "vulkan":
248
+ visual = xlib.XDefaultVisual(self._x_display, self._x_screen_id)
249
+ depth = xlib.XDefaultDepth(self._x_display, self._x_screen_id)
250
+ else:
251
+ msg = f"{pyglet.options.backend} Backend not supported."
252
+ raise Exception(msg)
241
253
  else:
242
- window_attributes.colormap = xlib.XDefaultColormap(self._x_display,
243
- self._x_screen_id)
254
+ visual = xlib.XDefaultVisual(self._x_display, self._x_screen_id)
255
+ depth = xlib.XDefaultDepth(self._x_display, self._x_screen_id)
256
+
257
+ window_attributes = xlib.XSetWindowAttributes()
258
+ window_attributes.colormap = xlib.XCreateColormap(self._x_display, root,
259
+ visual, xlib.AllocNone)
244
260
  window_attributes.bit_gravity = xlib.StaticGravity
245
261
 
246
262
  # Issue 287: Compiz on Intel/Mesa doesn't draw window decoration
@@ -264,36 +280,42 @@ class XlibWindow(BaseWindow):
264
280
  else:
265
281
  width, height = self._width, self._height
266
282
  self._view_x = self._view_y = 0
267
- if pyglet.options.dpi_scaling in ("scaled", "stretch"):
283
+ if pyglet.options.dpi_scaling == "stretch":
268
284
  w, h = self.get_requested_size()
269
285
  self._width = width = int(w * self.scale)
270
286
  self._height = height = int(h * self.scale)
271
287
 
272
288
  self._window = xlib.XCreateWindow(self._x_display, root,
273
- 0, 0, width, height, 0, visual_info.depth,
289
+ 0, 0, width, height, 0, depth,
274
290
  xlib.InputOutput, visual, mask,
275
291
  byref(window_attributes))
276
- self._view = xlib.XCreateWindow(self._x_display,
277
- self._window, self._view_x, self._view_y,
278
- self._width, self._height, 0, visual_info.depth,
279
- xlib.InputOutput, visual, mask,
280
- byref(window_attributes))
281
- xlib.XMapWindow(self._x_display, self._view)
282
- xlib.XSelectInput(self._x_display, self._view, self._default_event_mask)
292
+ self._x_window = xlib.XCreateWindow(self._x_display,
293
+ self._window, self._view_x, self._view_y,
294
+ self._width, self._height, 0, depth,
295
+ xlib.InputOutput, visual, mask,
296
+ byref(window_attributes))
297
+ xlib.XMapWindow(self._x_display, self._x_window)
298
+ xlib.XSelectInput(self._x_display, self._x_window, self._default_event_mask)
283
299
 
284
300
  self.display._window_map[self._window] = self.dispatch_platform_event # noqa: SLF001
285
- self.display._window_map[self._view] = self.dispatch_platform_event_view
301
+ self.display._window_map[self._x_window] = self.dispatch_platform_event_view # noqa: SLF001
286
302
 
287
- self.canvas = XlibCanvas(self.display, self._view)
303
+ # Vulkan surface needs to be created after the window. Possibly move surface creation to context.attach.
304
+ if pyglet.options.backend == "vulkan" and not self._shadow:
305
+ self._assign_config()
288
306
 
289
- self.context.attach(self.canvas)
290
- self.context.set_vsync(self._vsync) # XXX ?
307
+ if self.context:
308
+ self.context.attach(self)
309
+ self.context.set_vsync(self._vsync) # XXX ?VulkanWindowConfig
291
310
 
292
- self._enable_xsync = self.display._enable_xsync and self.config.double_buffer
311
+ self._enable_xsync = self.display._enable_xsync and self.config.double_buffer
312
+ else:
313
+ self._enable_xsync = False
293
314
 
294
315
  # Set supported protocols
295
316
  protocols = list()
296
317
  protocols.append(xlib.XInternAtom(self._x_display, asbytes('WM_DELETE_WINDOW'), False))
318
+
297
319
  if self._enable_xsync:
298
320
  protocols.append(xlib.XInternAtom(self._x_display,
299
321
  asbytes('_NET_WM_SYNC_REQUEST'),
@@ -310,14 +332,19 @@ class XlibWindow(BaseWindow):
310
332
  if self._enable_xsync:
311
333
  value = xsync.XSyncValue()
312
334
  self._sync_counter = xlib.XID(xsync.XSyncCreateCounter(self._x_display, value))
313
- atom = xlib.XInternAtom(self._x_display,
314
- asbytes('_NET_WM_SYNC_REQUEST_COUNTER'), False)
335
+ atom = xlib.XInternAtom(self._x_display, asbytes('_NET_WM_SYNC_REQUEST_COUNTER'), False)
315
336
  ptr = pointer(self._sync_counter)
316
337
 
317
- xlib.XChangeProperty(self._x_display, self._window,
318
- atom, XA_CARDINAL, 32,
319
- xlib.PropModeReplace,
320
- cast(ptr, POINTER(c_ubyte)), 1)
338
+ xlib.XChangeProperty(
339
+ self._x_display,
340
+ self._window,
341
+ atom,
342
+ XA_CARDINAL,
343
+ 32,
344
+ xlib.PropModeReplace,
345
+ cast(ptr, POINTER(c_ubyte)),
346
+ 1,
347
+ )
321
348
 
322
349
  # Atoms required for Xdnd
323
350
  self._create_xdnd_atoms(self._x_display)
@@ -435,10 +462,17 @@ class XlibWindow(BaseWindow):
435
462
  if self._visible:
436
463
  self.set_visible(True)
437
464
 
438
- self.set_mouse_platform_visible()
465
+ self.set_mouse_cursor_platform_visible()
439
466
  self._applied_mouse_exclusive = None
440
467
  self._update_exclusivity()
441
468
 
469
+ def _is_visual_transparent(self, visual: _Pointer[Visual]) -> bool:
470
+ if not XRenderFindVisualFormat:
471
+ return False
472
+
473
+ xrender_format = XRenderFindVisualFormat(self._x_display, visual)
474
+ return xrender_format and xrender_format.contents.direct.alphaMask != 0
475
+
442
476
  def set_mouse_passthrough(self, state: bool) -> None:
443
477
  """Sets the clickable area in the application to an empty region if enabled."""
444
478
  if state:
@@ -509,13 +543,14 @@ class XlibWindow(BaseWindow):
509
543
  if not self._window:
510
544
  return
511
545
 
512
- self.context.destroy()
546
+ if self.context:
547
+ self.context.destroy()
513
548
  self._unmap()
514
549
  if self._window:
515
550
  xlib.XDestroyWindow(self._x_display, self._window)
516
551
 
517
552
  del self.display._window_map[self._window] # noqa: SLF001
518
- del self.display._window_map[self._view]
553
+ del self.display._window_map[self._x_window]
519
554
  self._window = None
520
555
 
521
556
  self._view_event_handlers.clear()
@@ -531,18 +566,22 @@ class XlibWindow(BaseWindow):
531
566
  if self.context:
532
567
  self.context.set_current()
533
568
 
569
+ def before_draw(self) -> None:
570
+ if self.context:
571
+ self.context.before_draw()
572
+
534
573
  def flip(self):
535
574
  self.draw_mouse_cursor()
536
575
 
537
- # TODO canvas.flip?
576
+ # TODO window.flip?
538
577
  if self.context:
539
578
  self.context.flip()
540
579
 
541
580
  self._sync_resize()
542
581
 
543
582
  def set_vsync(self, vsync: bool) -> None:
544
- if pyglet.options['vsync'] is not None:
545
- vsync = pyglet.options['vsync']
583
+ if pyglet.options.vsync is not None:
584
+ vsync = pyglet.options.vsync
546
585
 
547
586
  super().set_vsync(vsync)
548
587
  self.context.set_vsync(vsync)
@@ -582,7 +621,7 @@ class XlibWindow(BaseWindow):
582
621
  self.dispatch_event('_on_internal_resize', width, height)
583
622
 
584
623
  def _update_view_size(self) -> None:
585
- xlib.XResizeWindow(self._x_display, self._view, self._width, self._height)
624
+ xlib.XResizeWindow(self._x_display, self._x_window, self._width, self._height)
586
625
 
587
626
  def set_location(self, x: int, y: int) -> None:
588
627
  if self._is_reparented():
@@ -669,7 +708,7 @@ class XlibWindow(BaseWindow):
669
708
  width = texture.width
670
709
  height = texture.height
671
710
 
672
- alpha_luma_bytes = texture.get_image_data().get_data('AL', -width * 2)
711
+ alpha_luma_bytes = texture.get_image_data().get_bytes('AL', -width * 2)
673
712
  mask_data = self._downsample_1bit(alpha_luma_bytes[0::2])
674
713
  bmp_data = self._downsample_1bit(alpha_luma_bytes[1::2])
675
714
 
@@ -687,11 +726,11 @@ class XlibWindow(BaseWindow):
687
726
 
688
727
  return cursor
689
728
 
690
- def set_mouse_platform_visible(self, platform_visible: bool | None = None) -> None:
729
+ def set_mouse_cursor_platform_visible(self, platform_visible: bool | None = None) -> None:
691
730
  if not self._window:
692
731
  return
693
732
  if platform_visible is None:
694
- platform_visible = self._mouse_visible and not self._mouse_cursor.gl_drawable
733
+ platform_visible = self._mouse_visible and not self._mouse_cursor.api_drawable
695
734
 
696
735
  if platform_visible is False:
697
736
  # Hide pointer by creating an empty cursor:
@@ -726,7 +765,7 @@ class XlibWindow(BaseWindow):
726
765
 
727
766
  if mouse_exclusive != self._applied_mouse_exclusive:
728
767
  if mouse_exclusive:
729
- self.set_mouse_platform_visible(False)
768
+ self.set_mouse_cursor_platform_visible(False)
730
769
 
731
770
  # Restrict to client area
732
771
  xlib.XGrabPointer(self._x_display, self._window,
@@ -743,28 +782,28 @@ class XlibWindow(BaseWindow):
743
782
  y = self._height // 2
744
783
  self._mouse_exclusive_client = x, y
745
784
  self.set_mouse_position(x, y)
746
- elif self._fullscreen: # noqa: SLF001
785
+ elif self._fullscreen:
747
786
  if isinstance(self.screen, XlibScreenXinerama) and self.screen._xinerama:
748
787
  return
749
788
 
750
789
  # Restrict to fullscreen area (prevent viewport scrolling)
751
790
  self.set_mouse_position(0, 0)
752
- r = xlib.XGrabPointer(self._x_display, self._view,
791
+ r = xlib.XGrabPointer(self._x_display, self._x_window,
753
792
  True, 0,
754
793
  xlib.GrabModeAsync,
755
794
  xlib.GrabModeAsync,
756
- self._view,
795
+ self._x_window,
757
796
  0,
758
797
  xlib.CurrentTime)
759
798
  if r:
760
799
  # Failed to grab, try again later
761
800
  self._applied_mouse_exclusive = None
762
801
  return
763
- self.set_mouse_platform_visible()
802
+ self.set_mouse_cursor_platform_visible()
764
803
  else:
765
804
  # Unclip
766
805
  xlib.XUngrabPointer(self._x_display, xlib.CurrentTime)
767
- self.set_mouse_platform_visible()
806
+ self.set_mouse_cursor_platform_visible()
768
807
 
769
808
  self._applied_mouse_exclusive = mouse_exclusive
770
809
 
@@ -845,7 +884,7 @@ class XlibWindow(BaseWindow):
845
884
  pitch = -(image.width * len(fmt))
846
885
  s = c_buffer(sizeof(c_ulong) * 2)
847
886
  memmove(s, cast((c_ulong * 2)(image.width, image.height), POINTER(c_ubyte)), len(s))
848
- data += s.raw + image.get_data(fmt, pitch)
887
+ data += s.raw + image.get_bytes(fmt, pitch)
849
888
  buffer = (c_ubyte * len(data))()
850
889
  memmove(buffer, data, len(data))
851
890
  atom = xlib.XInternAtom(self._x_display, asbytes('_NET_WM_ICON'), False)
@@ -960,7 +999,7 @@ class XlibWindow(BaseWindow):
960
999
  name_atom = xlib.XInternAtom(self._x_display, asbytes(name), False)
961
1000
  atoms = [xlib.XInternAtom(self._x_display, asbytes(value), False) for value in values]
962
1001
  atom_type = xlib.XInternAtom(self._x_display, asbytes('ATOM'), False)
963
- if len(atoms):
1002
+ if atoms:
964
1003
  atoms_ar = (xlib.Atom * len(atoms))(*atoms)
965
1004
  xlib.XChangeProperty(self._x_display, self._window,
966
1005
  name_atom, atom_type, 32, mode,
@@ -975,7 +1014,7 @@ class XlibWindow(BaseWindow):
975
1014
  net_wm_state = xlib.XInternAtom(self._x_display, asbytes('_NET_WM_STATE'), False)
976
1015
  atoms = [xlib.XInternAtom(self._x_display, asbytes(state), False) for state in states]
977
1016
  atom_type = xlib.XInternAtom(self._x_display, asbytes('ATOM'), False)
978
- if len(atoms):
1017
+ if atoms:
979
1018
  atoms_ar = (xlib.Atom * len(atoms))(*atoms)
980
1019
  xlib.XChangeProperty(self._x_display, self._window,
981
1020
  net_wm_state, atom_type, 32, xlib.PropModePrepend,
@@ -1008,7 +1047,7 @@ class XlibWindow(BaseWindow):
1008
1047
  # Cache these in case window is closed from an event handler
1009
1048
  _x_display = self._x_display
1010
1049
  _window = self._window
1011
- _view = self._view
1050
+ _x_window = self._x_window
1012
1051
 
1013
1052
  # Check for the events specific to this window
1014
1053
  while xlib.XCheckWindowEvent(_x_display, _window, 0x1ffffff, byref(e)):
@@ -1020,7 +1059,7 @@ class XlibWindow(BaseWindow):
1020
1059
  self.dispatch_platform_event(e)
1021
1060
 
1022
1061
  # Check for the events specific to this view
1023
- while xlib.XCheckWindowEvent(_x_display, _view, 0x1ffffff, byref(e)):
1062
+ while xlib.XCheckWindowEvent(_x_display, _x_window, 0x1ffffff, byref(e)):
1024
1063
  # Key events are filtered by the xlib window event
1025
1064
  # handler so they get a shot at the prefiltered event.
1026
1065
  if e.xany.type not in (xlib.KeyPress, xlib.KeyRelease):
@@ -1059,7 +1098,7 @@ class XlibWindow(BaseWindow):
1059
1098
  event_handler(e)
1060
1099
 
1061
1100
  @staticmethod
1062
- @lru_cache()
1101
+ @lru_cache
1063
1102
  def _translate_modifiers(state: int) -> int:
1064
1103
  modifiers = 0
1065
1104
  if state & xlib.ShiftMask:
@@ -1205,10 +1244,9 @@ class XlibWindow(BaseWindow):
1205
1244
  for auto_event in reversed(saved):
1206
1245
  xlib.XPutBackEvent(self._x_display, byref(auto_event))
1207
1246
  return
1208
- else:
1209
- # Key code of press did not match, therefore no repeating
1210
- # is going on, stop searching.
1211
- break
1247
+ # Key code of press did not match, therefore no repeating
1248
+ # is going on, stop searching.
1249
+ break
1212
1250
  # Whoops, put the events back, it's for real.
1213
1251
  for auto_event in reversed(saved):
1214
1252
  xlib.XPutBackEvent(self._x_display, byref(auto_event))
@@ -1528,7 +1566,7 @@ class XlibWindow(BaseWindow):
1528
1566
  self._current_sync_valid = False
1529
1567
 
1530
1568
  @staticmethod
1531
- @lru_cache()
1569
+ @lru_cache
1532
1570
  def _translate_button(value: int) -> int:
1533
1571
  """Translate mouse button values to match mouse constants.
1534
1572
 
@@ -1,11 +1,10 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.3
2
2
  Name: pyglet
3
- Version: 2.1.13
3
+ Version: 3.0.dev1
4
4
  Summary: pyglet is a cross-platform games and multimedia package.
5
5
  Author-email: Alex Holkner & contributors <Alex.Holkner@gmail.com>
6
6
  Requires-Python: >=3.8
7
7
  Description-Content-Type: text/markdown
8
- License-File: LICENSE
9
8
  Project-URL: Home, https://pyglet.org
10
9
 
11
10
  [![pypi](https://badge.fury.io/py/pyglet.svg)](https://pypi.python.org/pypi/pyglet) [![rtd](https://readthedocs.org/projects/pyglet/badge/?version=latest)](https://pyglet.readthedocs.io) [![PyTest](https://github.com/pyglet/pyglet/actions/workflows/unittests.yml/badge.svg)](https://github.com/pyglet/pyglet/actions/workflows/unittests.yml)