node-mac-recorder 1.10.0 → 1.12.0

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 (2) hide show
  1. package/index.js +36 -77
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -139,21 +139,19 @@ class MacRecorder extends EventEmitter {
139
139
  // WindowId varsa captureArea'yı otomatik ayarla
140
140
  if (this.options.windowId && !this.options.captureArea) {
141
141
  try {
142
- // Window selector'dan seçilen pencere bilgisini al
143
- const WindowSelector = require('./window-selector');
144
- const selector = new WindowSelector();
145
- const selectedWindow = selector.getSelectedWindow();
146
-
147
- // Eğer window selector'dan overlay koordinatları varsa onları kullan
148
- if (selectedWindow && selectedWindow.overlayX !== undefined) {
149
- console.log('🎯 Using overlay coordinates for exact recording match');
150
- console.log(`Overlay coords: (${selectedWindow.overlayX}, ${selectedWindow.overlayY}) ${selectedWindow.overlayWidth}x${selectedWindow.overlayHeight}`);
151
-
152
- const displays = await this.getDisplays();
153
- const targetWindow = selectedWindow;
154
-
155
- // Display ID'yi bul
142
+ const windows = await this.getWindows();
143
+ const displays = await this.getDisplays();
144
+ const targetWindow = windows.find(
145
+ (w) => w.id === this.options.windowId
146
+ );
147
+
148
+ if (targetWindow) {
149
+ // Pencere hangi display'de olduğunu bul
156
150
  let targetDisplayId = null;
151
+ let adjustedX = targetWindow.x;
152
+ let adjustedY = targetWindow.y;
153
+
154
+ // Pencere hangi display'de?
157
155
  for (let i = 0; i < displays.length; i++) {
158
156
  const display = displays[i];
159
157
  const displayWidth = parseInt(display.resolution.split("x")[0]);
@@ -161,73 +159,34 @@ class MacRecorder extends EventEmitter {
161
159
 
162
160
  // Pencere bu display sınırları içinde mi?
163
161
  if (
164
- targetWindow.overlayX >= display.x &&
165
- targetWindow.overlayX < display.x + displayWidth &&
166
- targetWindow.overlayY >= display.y &&
167
- targetWindow.overlayY < display.y + displayHeight
162
+ targetWindow.x >= display.x &&
163
+ targetWindow.x < display.x + displayWidth &&
164
+ targetWindow.y >= display.y &&
165
+ targetWindow.y < display.y + displayHeight
168
166
  ) {
169
- targetDisplayId = display.id;
167
+ targetDisplayId = display.id; // Use actual display ID, not array index
168
+ // Koordinatları display'e göre normalize et
169
+ adjustedX = targetWindow.x - display.x;
170
+ // Dynamic Y coordinate offset calculation
171
+ // Get display bounds using both coordinate systems to calculate difference
172
+ const nativeBinding = require("./build/Release/mac_recorder.node") || require("./build/Debug/mac_recorder.node");
173
+ const displays = nativeBinding.getDisplays();
174
+ const nativeDisplay = displays.find(d => d.id === targetDisplayId);
175
+
176
+ if (nativeDisplay && display) {
177
+ // Calculate Y height difference between coordinate systems
178
+ // display.y comes from NSScreen.frame (window selector)
179
+ // nativeDisplay.y comes from CGDisplayBounds (recording)
180
+ const yOffset = Math.abs(display.y - nativeDisplay.y);
181
+ console.log(`📏 Dynamic Y offset calculated: ${yOffset}px (NSScreen: ${display.y}, CGDisplay: ${nativeDisplay.y})`);
182
+ adjustedY = Math.max(0, targetWindow.y - display.y - yOffset);
183
+ } else {
184
+ // Fallback to fixed offset if dynamic calculation fails
185
+ adjustedY = Math.max(0, targetWindow.y - display.y - 25);
186
+ }
170
187
  break;
171
188
  }
172
189
  }
173
-
174
- // Display ID'yi ayarla
175
- if (targetDisplayId !== null) {
176
- this.options.displayId = targetDisplayId;
177
- const targetDisplay = displays.find(d => d.id === targetDisplayId);
178
- this.recordingDisplayInfo = {
179
- displayId: targetDisplayId,
180
- x: targetDisplay.x,
181
- y: targetDisplay.y,
182
- width: parseInt(targetDisplay.resolution.split("x")[0]),
183
- height: parseInt(targetDisplay.resolution.split("x")[1]),
184
- };
185
- }
186
-
187
- // Overlay koordinatlarını direkt kullan - display offset'ini çıkar
188
- const targetDisplay = displays.find(d => d.id === targetDisplayId);
189
- this.options.captureArea = {
190
- x: targetWindow.overlayX - (targetDisplay ? targetDisplay.x : 0),
191
- y: targetWindow.overlayY - (targetDisplay ? targetDisplay.y : 0),
192
- width: targetWindow.overlayWidth,
193
- height: targetWindow.overlayHeight,
194
- };
195
-
196
- console.log(`🎬 Recording area: x=${this.options.captureArea.x}, y=${this.options.captureArea.y}, w=${this.options.captureArea.width}, h=${this.options.captureArea.height}`);
197
- } else {
198
- // Fallback: Eski yöntem
199
- const windows = await this.getWindows();
200
- const displays = await this.getDisplays();
201
- const targetWindow = windows.find(
202
- (w) => w.id === this.options.windowId
203
- );
204
-
205
- if (targetWindow) {
206
- // Pencere hangi display'de olduğunu bul
207
- let targetDisplayId = null;
208
- let adjustedX = targetWindow.x;
209
- let adjustedY = targetWindow.y;
210
-
211
- // Pencere hangi display'de?
212
- for (let i = 0; i < displays.length; i++) {
213
- const display = displays[i];
214
- const displayWidth = parseInt(display.resolution.split("x")[0]);
215
- const displayHeight = parseInt(display.resolution.split("x")[1]);
216
-
217
- // Pencere bu display sınırları içinde mi?
218
- if (
219
- targetWindow.x >= display.x &&
220
- targetWindow.x < display.x + displayWidth &&
221
- targetWindow.y >= display.y &&
222
- targetWindow.y < display.y + displayHeight
223
- ) {
224
- targetDisplayId = display.id; // Use actual display ID, not array index
225
- // Koordinatları display'e göre normalize et
226
- adjustedX = targetWindow.x - display.x;
227
- adjustedY = targetWindow.y - display.y;
228
- break;
229
- }
230
- }
231
190
 
232
191
  // Eğer display bulunamadıysa ana display kullan
233
192
  if (targetDisplayId === null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-mac-recorder",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "Native macOS screen recording package for Node.js applications",
5
5
  "main": "index.js",
6
6
  "keywords": [