ntk 3.6.0 → 3.7.1

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.
package/lib/events_map.js CHANGED
@@ -9,6 +9,10 @@ eventName[5] = 'mouseup';
9
9
  eventName[6] = 'mousemove';
10
10
  eventName[7] = 'mouseover';
11
11
  eventName[8] = 'mouseout';
12
+ // FocusIn/FocusOut: keyboard focus arriving at or leaving this window,
13
+ // usually because the window manager moved it
14
+ eventName[9] = 'focus';
15
+ eventName[10] = 'blur';
12
16
  eventName[12] = 'expose';
13
17
  eventName[17] = 'destroy';
14
18
  eventName[18] = 'unmap';
@@ -40,6 +44,8 @@ export const mask = {
40
44
  resize: x11.eventMask.StructureNotify,
41
45
  reparent: x11.eventMask.StructureNotify,
42
46
  keydown: x11.eventMask.KeyPress,
47
+ focus: x11.eventMask.FocusChange,
48
+ blur: x11.eventMask.FocusChange,
43
49
  expose: x11.eventMask.Exposure,
44
50
  map_request: x11.eventMask.SubstructureRedirect,
45
51
  configure_request: x11.eventMask.SubstructureRedirect,
@@ -74,6 +80,8 @@ export const toSnake = {
74
80
  onResize: 'resize',
75
81
  onReparent: 'reparent',
76
82
  onKeyDown: 'keydown',
83
+ onFocus: 'focus',
84
+ onBlur: 'blur',
77
85
  onExpose: 'expose',
78
86
  onMapRequest: 'map_request',
79
87
  onConfigureRequest: 'configure_request',
@@ -17,7 +17,7 @@ import {
17
17
  } from './path.js';
18
18
  import Picture from './picture.js';
19
19
  import Pixmap from './pixmap.js';
20
- import { drawGlyphRuns } from './text/glyphs.js';
20
+ import { compositeTraps, drawGlyphRuns } from './text/glyphs.js';
21
21
  import { TextLayout } from './text/layout.js';
22
22
  import { reorderRuns } from './text/shape.js';
23
23
  import { trapezoidize } from './trapezoid.js';
@@ -810,6 +810,39 @@ class RenderingContext2d {
810
810
  this._markDirty();
811
811
  }
812
812
 
813
+ /**
814
+ * Trapezoid coverage under the clip — `drawGlyphs` for vector shapes that
815
+ * are already trapezoidized (KaTeX radicals and rules go this way).
816
+ * Without it they composite straight to the destination picture and spill
817
+ * out of clipped boxes, which is what glyphs used to do.
818
+ */
819
+ drawTraps(op, src, traps) {
820
+ if (!traps.length) return;
821
+ const app = this.window.app;
822
+ const R = this.Render;
823
+ if (!this.clipMask) {
824
+ compositeTraps(app, op, src.id, this.picture.id, traps);
825
+ this._markDirty();
826
+ return;
827
+ }
828
+ const rect = this._clipRect();
829
+ if (rect) {
830
+ if (rect.w === 0 || rect.h === 0) return;
831
+ R.SetPictureClipRectangles(this.picture.id, 0, 0, [rect.x, rect.y, rect.w, rect.h]);
832
+ compositeTraps(app, op, src.id, this.picture.id, traps);
833
+ R.SetPictureClipRectangles(this.picture.id, 0, 0, [0, 0, this.width, this.height]);
834
+ this._markDirty();
835
+ return;
836
+ }
837
+ this._ensureFillMask();
838
+ this._glyphSource ??= this.createSolidPicture(1, 1, 1, 1);
839
+ R.FillRectangles(R.PictOp.Src, this.fillMask.id, [0, 0, 0, 0], [0, 0, this.width, this.height]);
840
+ compositeTraps(app, R.PictOp.Over, this._glyphSource.id, this.fillMask.id, traps);
841
+ R.Composite(R.PictOp.In, this.clipMask.id, 0, this.fillMask.id, 0, 0, 0, 0, 0, 0, this.width, this.height);
842
+ R.Composite(op, src.id, this.fillMask.id, this.picture.id, 0, 0, 0, 0, 0, 0, this.width, this.height);
843
+ this._markDirty();
844
+ }
845
+
813
846
  // combined clip ∩ globalAlpha mask for direct composites (rect/image
814
847
  // fast paths); returns a picture id or 0. Reuses the fill scratch mask.
815
848
  _compositeMask() {
@@ -22,7 +22,6 @@ import { parseSvgPath } from '../path.js';
22
22
  import { flatten } from '../rasterize.js';
23
23
  import { trapezoidize } from '../trapezoid.js';
24
24
  import Font from '../text/font.js';
25
- import { compositeTraps, drawGlyphRuns } from '../text/glyphs.js';
26
25
 
27
26
  // node builtins are fetched lazily so browser bundles never resolve them;
28
27
  // there, inject the assets with configureTex() instead.
@@ -571,7 +570,7 @@ export class TexBox {
571
570
  Render.Composite(
572
571
  Render.PictOp.Over,
573
572
  src.id,
574
- ctx.clipMask ? ctx.clipMask.id : 0,
573
+ ctx._compositeMask(),
575
574
  ctx.picture.id,
576
575
  Math.round(x + item.x),
577
576
  Math.round(base + item.y),
@@ -598,7 +597,9 @@ export class TexBox {
598
597
  }
599
598
  trapezoidize([clipped], x + item.x, base + item.y, traps);
600
599
  }
601
- compositeTraps(app, Render.PictOp.Over, src.id, ctx.picture.id, traps);
600
+ // through the context, so the clip applies — compositing straight to
601
+ // ctx.picture spills out of scrollviews and clipped boxes
602
+ ctx.drawTraps(Render.PictOp.Over, src, traps);
602
603
  }
603
604
 
604
605
  // batch every run of the same color into a single CompositeGlyphs
@@ -612,7 +613,7 @@ export class TexBox {
612
613
  }
613
614
  for (const { color, runs } of byColor.values()) {
614
615
  const src = color ? ctx._stylePicture(color) : ctx._backgroundPicture;
615
- drawGlyphRuns(app, Render.PictOp.Over, src.id, ctx.picture.id, runs);
616
+ ctx.drawGlyphs(Render.PictOp.Over, src, runs);
616
617
  }
617
618
 
618
619
  ctx._markDirty();
package/lib/window.js CHANGED
@@ -922,8 +922,77 @@ export default class Window extends Drawable {
922
922
  return this;
923
923
  }
924
924
 
925
- grabPointer() {
926
- this.X.GrabPointer(this.id, true, x11.eventMask.PointerMotion, 0, 1, 0, 0, 0);
925
+ /**
926
+ * Take the keyboard focus (X SetInputFocus). `revertTo` says where focus
927
+ * goes if this window becomes unviewable: 0 None, 1 PointerRoot,
928
+ * 2 Parent (the default, and the sane choice for a child window).
929
+ *
930
+ * Note a window manager may take focus back — the authority is the
931
+ * 'focus'/'blur' events, not the request.
932
+ */
933
+ focus(revertTo = 2) {
934
+ safeRelease(this.X, () => this.X.SetInputFocus(this.id, revertTo));
935
+ return this;
936
+ }
937
+
938
+ /** Which window the server currently gives keyboard input to. */
939
+ queryFocus(callback) {
940
+ this.X.GetInputFocus(callback);
941
+ return this;
942
+ }
943
+
944
+ /**
945
+ * Take a pointer grab (X GrabPointer). This is how menus work on X: while
946
+ * the grab is held, presses anywhere on the screen are reported to this
947
+ * window instead of going to the window under the pointer — including the
948
+ * window manager's frames — so a click outside can dismiss the menu.
949
+ *
950
+ * With `ownerEvents` (the default) events over the client's *own* windows
951
+ * are still delivered to them normally, so a submenu keeps working.
952
+ *
953
+ * @param {object} [options] { ownerEvents, events, cursor, confineTo, time }
954
+ * @param {function} [callback] cb(err, status) — 0 is Success, 1 is
955
+ * AlreadyGrabbed by another client
956
+ */
957
+ grabPointer(options = {}, callback) {
958
+ const {
959
+ ownerEvents = true,
960
+ events = x11.eventMask.ButtonPress | x11.eventMask.ButtonRelease | x11.eventMask.PointerMotion,
961
+ pointerMode = 1, // Asynchronous
962
+ keyboardMode = 1,
963
+ confineTo = 0,
964
+ cursor = 0,
965
+ time = 0 // CurrentTime
966
+ } = options;
967
+ this.X.GrabPointer(
968
+ this.id,
969
+ ownerEvents,
970
+ events,
971
+ pointerMode,
972
+ keyboardMode,
973
+ confineTo,
974
+ cursor,
975
+ time,
976
+ callback ?? (() => {})
977
+ );
978
+ return this;
979
+ }
980
+
981
+ ungrabPointer(time = 0) {
982
+ safeRelease(this.X, () => this.X.UngrabPointer(time));
983
+ return this;
984
+ }
985
+
986
+ /** Keyboard counterpart: keys go here while the grab is held. */
987
+ grabKeyboard(options = {}, callback) {
988
+ const { ownerEvents = true, pointerMode = 1, keyboardMode = 1, time = 0 } = options;
989
+ this.X.GrabKeyboard(this.id, ownerEvents, time, pointerMode, keyboardMode, callback ?? (() => {}));
990
+ return this;
991
+ }
992
+
993
+ ungrabKeyboard(time = 0) {
994
+ safeRelease(this.X, () => this.X.UngrabKeyboard(time));
995
+ return this;
927
996
  }
928
997
 
929
998
  reparentTo(newParent, x, y) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ntk",
3
- "version": "3.6.0",
3
+ "version": "3.7.1",
4
4
  "description": "Desktop UI toolkit for X11 with canvas-like 2d and OpenGL rendering",
5
5
  "author": "Andrey Sidorov <sidorares@yandex.ru>",
6
6
  "license": "MIT",