@@ -4,11 +4,16 @@ import { gettext as _ } from 'gettext';
44import St from '@girs/st-18' ;
55import GObject from '@girs/gobject-2.0' ;
66import Clutter from '@girs/clutter-18' ;
7+ import type Meta from '@girs/meta-18' ;
78import * as Main from '@girs/gnome-shell/ui/main' ;
89
910import type { ClipboardEntry , ClipboardStore } from '~/clipboard/clipboardStore.ts' ;
1011import { ClipboardList } from '~/clipboard/clipboardList.ts' ;
11- import { placeClipboardPanelNearPointer } from '~/clipboard/clipboardPosition.ts' ;
12+ import {
13+ placeClipboardPanelNearPointer ,
14+ resolveClipboardPanelAnchor ,
15+ type ClipboardPanelWindowPlacement ,
16+ } from '~/clipboard/clipboardPosition.ts' ;
1217
1318const PANEL_WIDTH = 360 ;
1419const PANEL_HEIGHT = 480 ;
@@ -99,7 +104,7 @@ export class ClipboardPanel extends St.BoxLayout {
99104 Main . uiGroup . add_child ( this . _overlay ) ;
100105 Main . uiGroup . add_child ( this ) ; // panel sits above overlay
101106
102- this . _positionNearPointer ( ) ;
107+ this . _positionNearCurrentAnchor ( ) ;
103108
104109 this . show ( ) ;
105110 this . _isOpen = true ;
@@ -230,13 +235,22 @@ export class ClipboardPanel extends St.BoxLayout {
230235 }
231236 }
232237
233- private _positionNearPointer ( ) : void {
238+ private _positionNearCurrentAnchor ( ) : void {
234239 const [ pointerX , pointerY ] = global . get_pointer ( ) ;
235- const monitorIndex = this . _findMonitorIndexAt ( pointerX , pointerY ) ;
236- const workArea = Main . layoutManager . getWorkAreaForMonitor ( monitorIndex ) ;
237- const bounds = placeClipboardPanelNearPointer (
240+ const pointerMonitorIndex = this . _findMonitorIndexAt ( pointerX , pointerY ) ;
241+ const anchor = resolveClipboardPanelAnchor (
238242 pointerX ,
239243 pointerY ,
244+ pointerMonitorIndex ,
245+ this . _getFocusedWindowPlacement ( ) ,
246+ ) ;
247+ const monitorIndex = this . _isMonitorValid ( anchor . monitorIndex )
248+ ? anchor . monitorIndex
249+ : pointerMonitorIndex ;
250+ const workArea = Main . layoutManager . getWorkAreaForMonitor ( monitorIndex ) ;
251+ const bounds = placeClipboardPanelNearPointer (
252+ anchor . x ,
253+ anchor . y ,
240254 workArea ,
241255 PANEL_WIDTH ,
242256 PANEL_HEIGHT ,
@@ -264,4 +278,28 @@ export class ClipboardPanel extends St.BoxLayout {
264278
265279 return Main . layoutManager . primaryIndex ;
266280 }
281+
282+ private _getFocusedWindowPlacement ( ) : ClipboardPanelWindowPlacement | null {
283+ const win = global . display . focus_window as Meta . Window | null ;
284+ if ( ! win || win . minimized ) return null ;
285+
286+ const monitorIndex = win . get_monitor ( ) ;
287+ if ( ! this . _isMonitorValid ( monitorIndex ) ) return null ;
288+
289+ const frame = win . get_frame_rect ( ) ;
290+ return {
291+ monitorIndex,
292+ frame : {
293+ x : frame . x ,
294+ y : frame . y ,
295+ width : frame . width ,
296+ height : frame . height ,
297+ } ,
298+ } ;
299+ }
300+
301+ private _isMonitorValid ( monitorIndex : number ) : boolean {
302+ const monitors = Main . layoutManager . monitors ?? [ ] ;
303+ return monitorIndex >= 0 && monitorIndex < monitors . length ;
304+ }
267305}
0 commit comments