+
   Q\
tc                   s*   R t ^ RIHt ^ RIHt ^ RIt^ RIt^ RIHt ]! RR4       ]! RR4       ^ RIH	t	H
t
 R	]P                  R
&   ^ RIHtHt ]'       d	   ^ RIHtHt  ! R R]P                  4      t]R8X  d   ]! 4       t]P'                  4        R# R# )a  
This helper uses GTK 4 to access the primary selection (mouse selection).
On Wayland, GTK 3 cannot access the primary selection at all, but GTK 4 can,
if built with support for the zwp_primary_selection_v1 protocol.

ibus-typing-booster uses GTK 3 and cannot safely mix GTK 3 and GTK 4 in the
same process. Therefore, this helper runs as a separate subprocess to
retrieve the primary selection text using GTK 4, even when the main program
is using GTK 3.
)Optional)TYPE_CHECKINGN)require_versionGLibz2.0Gio)r   r   Z4ZITB_GTK_VERSION)GdkGtk)r   r   c                   sf   a a ] tR t^0t oRtV3R lV 3R lltV3R lR ltV3R lR ltRtVt	V ;t
# )	ClipboardAppz Class used to read the clipboardc                   < V ^8  d   QhRR/#    returnN format__classdict__   ";/usr/share/ibus-typing-booster/engine/get_clipboard_gtk4.py__annotate__ClipboardApp.__annotate__2   s     > >$ >    c                s|   < \         SV `  R R7       RV n        \        P                  P                  4       V n        R# )z7org.freedesktop.ibus.engine.typing_booster.GetSelection)Zapplication_idN)Zsuper__init__windowr   ZDisplayZget_defaultdisplay)self	__class__s   &r   r   ZClipboardApp.__init__2   s/    (ab7;$'KK$;$;$=r   c                r   r	   r   r   r   r   r   r   7   s     & &T &r   c                s   R V P                   P                  4       P                  4       9   d   \        P                  ! V R7      V n        V P
                  P                  ^^4       V P
                  P                  R4       V P
                  P                  4        \        P                  ! ^V P                  4       R# V P                  4        R# )Zwayland)ZapplicationFN)r   Zget_nameZlowerr   ZApplicationWindowr   Zset_default_sizeZset_decoratedZpresentr   Ztimeout_addtry_read_clipboard)r   s   &r   do_activateZClipboardApp.do_activate7   s    --/5577 //DADKKK((A.KK%%e,KK!S$"9"9:##%r   c                s    < V ^8  d   QhRS[ /# )r
   r   )Zboolr   r   r   r   r   G   s      D r   c                sj    V P                   P                  4       pR R lpVP                  RV4       R# )z1Method to read the clipboard and print the resultc                s@    V ^8  d   QhRRR\         P                  RR/# )r
   	clipboardzGdk.Clipboardresultr   N)r   ZAsyncResult)r   s   "r   r   Z5ClipboardApp.try_read_clipboard.<locals>.__annotate__K   s(     		 		*		47OO		HL		r   c                 s     V P                  V4      pVe   \        V4       \        P                  4        R #   \        P                   d)   p\        RT 2\        P
                  R7        R p?LNR p?ii ; i)Nz!Error reading primary selection: )Zfile)Zread_text_finishZprintr   ZErrorsysZstderrappZquit)r   r   ZtextZerrors   &&  r   on_text_receivedZ9ClipboardApp.try_read_clipboard.<locals>.on_text_receivedK   sc    '&/&@&@&H#$K HHJ :: '9%A::' ''s    8 A5A00A5NF)r   Zget_primary_clipboardZread_text_async)r   r   r    s   &  r   r   ZClipboardApp.try_read_clipboardG   s/    #'<<#E#E#G			 	!!$(89r   )r   r   )__name__Z
__module__Z__qualname__Z__firstlineno____doc__r   r   r   Z__static_attributes__Z__classdictcell__Z__classcell__)r   r   s   @@r   r   r   0   s+     *> >
& &   r   r   Z__main__)r"   Ztypingr    r   r   ZosZgir   Zgi.repositoryr   r   ZenvironZitb_gtkr   r   ZApplicationr   r!   r   Zrunr   r   r   <module>r#      s|   &	    
 	    u  # #

   ''3?? 'R z
.CGGI r   