Ë
    g
f?8  ã                   ó˜   — d Z dZdZdZdZdZddlmZ ddlmZ dd	lm	Z	 dd
l
mZ ddlmZ dZdZdZdZdZdZ G d„ d«      Z e«       Zd„ Zy)z1Module to manage the focused object, window, etc.z$Id$z
$Revision$z$Date$zQCopyright (c) 2005-2008 Sun Microsystems Inc.Copyright (c) 2016-2023 Igalia, S.L.ÚLGPLé   )Úbraille)Údebug)Úscript_manager)ÚAXObject)ÚAXUtilitieszcaret-trackingzfocus-trackingzflat-reviewzmouse-reviewzobject-navigatorzsay-allc                   ó~   — e Zd ZdZd„ Zdd„Zd„ Zd„ Zd„ Zd„ Z	d„ Z
dd
„Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zy	)ÚFocusManagerz(Manages the focused object, window, etc.c                 ó<   — d | _         d | _        d | _        d | _        y ©N)Ú_windowÚ_focusÚ_object_of_interestÚ_active_mode©Úselfs    ú4/usr/lib/python3/dist-packages/orca/focus_manager.pyÚ__init__zFocusManager.__init__1   s    € ØˆŒØˆŒØ#'ˆÔ Ø ˆÕó    c                 óž   — d}|r|d|› �z  }t        j                  t         j                  |d«       d| _        d| _        d| _        d| _        y)z!Clears everything we're tracking.z!FOCUS MANAGER: Clearing all statez: TN)r   ÚprintMessageÚ
LEVEL_INFOr   r   r   r   )r   ÚreasonÚmsgs      r   Úclear_statezFocusManager.clear_state7   sR   € ð 2ˆÙØ�R˜�x�=Ñ ˆCÜ×Ñœ5×+Ñ+¨S°$Ô7ØˆŒØˆŒØ#'ˆÔ Ø ˆÕr   c                 ó®   — t        j                  | j                  «      }d| j                  d|g}t        j                  t        j
                  |d«       |S )z0Returns the focused object in the active window.z FOCUS MANAGER: Focused object inÚisT)r   Úget_focused_objectr   r   ÚprintTokensr   )r   ÚresultÚtokenss      r   Úfind_focused_objectz FocusManager.find_focused_objectC   sG   € ô ×/Ñ/°·±Ó=ˆØ4°d·l±lÀDÈ&ÐQˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆr   c                 ó”   — | j                   du xr | j                  du }|r'd}t        j                  t        j                  |d«       |S )z;Returns True if we have no knowledge about what is focused.Nz+FOCUS MANAGER: Focus and window are unknownT)r   r   r   r   r   )r   r    r   s      r   Úfocus_and_window_are_unknownz)FocusManager.focus_and_window_are_unknownK   sE   € ð —‘ Ð$Ò=¨¯©¸Ð)=ˆÙØ?ˆCÜ×Ñœu×/Ñ/°°dÔ;àˆr   c                 ó’   — t        j                  | j                  «      syd}t        j                  t        j
                  |d«       y)z+Returns True if the locus of focus is dead.FzFOCUS MANAGER: Focus is deadT)r   Úis_deadr   r   r   r   )r   r   s     r   Úfocus_is_deadzFocusManager.focus_is_deadU   s9   € ô ×Ñ §¡Ô,Øà,ˆÜ×Ñœ5×+Ñ+¨S°$Ô7Ør   c                 óN   — | j                   €y| j                   | j                  k(  S )z8Returns True if the locus of focus is the active window.F)r   r   r   s    r   Úfocus_is_active_windowz#FocusManager.focus_is_active_window_   s$   € ð �;‰;ÐØà�{‰{˜dŸl™lÑ*Ð*r   c                 óv   — | j                   duxr* t        j                  | j                   | j                  «      S )z@Returns True if the locus of focus is inside the current window.N)r   r   Úis_ancestorr   r   s    r   Úfocus_is_in_active_windowz&FocusManager.focus_is_in_active_windowg   s-   € ð �{‰{ $Ð&ÒZ¬8×+?Ñ+?ÀÇÁÈTÏ\É\Ó+ZÐZr   Nc                 óŽ  — |€d}|€|}|€t         }	 |j                  d|z   dd«       || j                  k7  r}d| j                  d	|g}t        j                  t        j
                  |d«       || _        |t        k(  r$t        j                  t        j                  «       nt        j                  «        	 d
|d|› d|› d�g}t        j                  t        j
                  |d«       |j                  d||«       || j                  k7  r=d| j                  d	|g}t        j                  t        j
                  |d«       || _        yy# t        $ r5}d|› �}t        j                  t        j
                  |d«       Y d}~�ŒWd}~ww xY w# t        $ r4}d|› �}t        j                  t        j
                  |d«       Y d}~ŒÆd}~ww xY w)zLNotifies interested clients that the current region of interest has changed.Né    zmode-changed::r   Ú z=FOCUS MANAGER: Exception emitting mode-changed notification: Tz"FOCUS MANAGER: Switching mode fromÚtoz"FOCUS MANAGER: Region of interest:ú(z, ú)zregion-changedz?FOCUS MANAGER: Exception emitting region-changed notification: z0FOCUS MANAGER: Switching object of interest from)ÚFOCUS_TRACKINGÚemitÚ	Exceptionr   r   r   r   r   ÚFLAT_REVIEWr   ÚsetBrlapiPriorityÚBRLAPI_PRIORITY_HIGHr   )r   ÚobjÚstart_offsetÚ
end_offsetÚmodeÚerrorr   r!   s           r   Úemit_region_changedz FocusManager.emit_region_changedl   sº  € ð ÐØˆLØÐØ%ˆJØˆ<Ü!ˆDð	<Ø�H‰HÐ%¨Ñ,¨a°Ô4ð
 �4×$Ñ$Ò$Ø:¸D×<MÑ<MÈtÐUYÐZˆFÜ×Ñœe×.Ñ.°¸Ô=Ø $ˆDÔØ”{Ò"Ü×)Ñ)¬'×*FÑ*FÕGä×)Ñ)Ô+ð	<Ø:¸CÀ1À\ÀNÐRTÐU_ÐT`Ð`aÐAbÐcˆFÜ×Ñœe×.Ñ.°¸Ô=Ø�H‰HÐ% |°ZÔ@ð
 �$×*Ñ*Ò*ØHØ×.Ñ.°°cð;ˆFä×Ñœe×.Ñ.°¸Ô=Ø'*ˆDÕ$ð	 +øô+ ò 	<ØQÐRWÐQXÐYˆCÜ×Ñœu×/Ñ/°°d×;Ò;ûð	<ûô" ò 	<ØSÐTYÐSZÐ[ˆCÜ×Ñœu×/Ñ/°°d×;Ñ;ûð	<ús0   ’E Â5AF Å	FÅ*E?Å?FÆ	GÆ*F?Æ?Gc                 ó°   — d| j                   d| j                  g}t        j                  t        j                  |d«       | j                   | j                  fS )z:Returns the current mode and associated object of interestzFOCUS MANAGER: Active mode:zObject of interest:T)r   r   r   r   r   ©r   r!   s     r   Ú&get_active_mode_and_object_of_interestz3FocusManager.get_active_mode_and_object_of_interest“   sQ   € ð 0°×1BÑ1BØ'¨×)AÑ)AðCˆä×Ñœ%×*Ñ*¨F°DÔ9Ø× Ñ  $×":Ñ":Ð:Ð:r   c                 ó€   — d| j                   g}t        j                  t        j                  |d«       | j                   S )zGReturns the current locus of focus (i.e. the object with visual focus).z FOCUS MANAGER: Locus of focus isT)r   r   r   r   r@   s     r   Úget_locus_of_focuszFocusManager.get_locus_of_focus›   s4   € ð 5°d·k±kÐBˆÜ×Ñœ%×*Ñ*¨F°DÔ9Ø�{‰{Ðr   c                 ó>  — d|g}t        j                  t         j                  |dd«       t        j                  |«      }t        j                  ||d«       |s7|| j                  k(  r(d}t        j                  t         j                  |d«       yt        j                  «       j                  «       }|r|r}|j                  sqt        j                  |j                  «      }	t        j                  «       j                  |	|j                  «      }t        j                  «       j!                  |d«       | j                  }
t        j"                  |
«      rd}
|€/d}t        j                  t         j                  |d«       d| _        yt        j"                  |«      r+d|d	g}t        j                  t         j                  |d«       y|�@t        j$                  |«      s+d|d
g}t        j                  t         j                  |d«       yd|
d|d|g}t        j                  t         j                  |d«       || _        | j'                  |t(        ¬«       |sy|€(d}t        j                  t         j                  |d«       y|j+                  ||
| j                  «       y)z=Sets the locus of focus (i.e., the object with visual focus).z/FOCUS MANAGER: Request to set locus of focus toTzSetting locus of focus.z@FOCUS MANAGER: Setting locus of focus to existing locus of focusNzSetting locus of focusz9FOCUS MANAGER: New locus of focus is null (being cleared)z#FOCUS MANAGER: New locus of focus (z) is dead. Not updating.z) is invalid. Not updating.z+FOCUS MANAGER: Changing locus of focus fromr0   z	. Notify:)r<   zBFOCUS MANAGER: Cannot notify active script because there isn't one)r   r   r   r   Úis_table_cellr   Úclear_cacher   r   r   Ú
getManagerÚgetActiveScriptÚappÚget_applicationÚsourceÚ	getScriptÚsetActiveScriptr&   Úis_validr>   r3   ÚlocusOfFocusChanged)r   Úeventr9   Únotify_scriptÚforcer!   Ú	recursiver   ÚscriptrI   Ú	old_focuss              r   Úset_locus_of_focuszFocusManager.set_locus_of_focus¢   s/  € ð DÀSÐIˆÜ×Ñœ%×*Ñ*¨F°D¸$Ô?ô  ×-Ñ-¨cÓ2ˆ	Ü×Ñ˜S )Ð-FÔGÙ˜ §¡Ò+ØTˆCÜ×Ñœu×/Ñ/°°dÔ;Øô  ×*Ñ*Ó,×<Ñ<Ó>ˆÙ‘f V§Z¢ZÜ×*Ñ*¨5¯<©<Ó8ˆCÜ#×.Ñ.Ó0×:Ñ:¸3ÀÇÁÓMˆFÜ×%Ñ%Ó'×7Ñ7¸Ð@XÔYà—K‘Kˆ	Ü×Ñ˜IÔ&ØˆIàˆ;ØMˆCÜ×Ñœu×/Ñ/°°dÔ;ØˆDŒKØä×Ñ˜CÔ Ø;¸SÐB\Ð]ˆFÜ×Ñœe×.Ñ.°¸Ô=ØàÐÜ×$Ñ$ SÔ)Ø?ÀÐFcÐd�Ü×!Ñ!¤%×"2Ñ"2°F¸DÔAØà?ÀØ˜˜[¨-ð9ˆä×Ñœ%×*Ñ*¨F°DÔ9ØˆŒØ× Ñ  ¬>Ð Ô:áØàˆ>ØVˆCÜ×Ñœu×/Ñ/°°dÔ;Øà×"Ñ" 5¨)°T·[±[ÕAr   c                 óð   — t        j                  | j                  dd«       t        j                  | j                  «      }d| j                  d|g}t        j                  t
        j                  |d«       |S )zKReturns True if the window we think is currently active is actually active.Fz,Ensuring the active window is really active.úFOCUS MANAGER:z
is active:T)r   rF   r   r   Ú	is_activer   r   r   )r   rY   r!   s      r   Úactive_window_is_activez$FocusManager.active_window_is_activeß   s_   € ô 	×Ñ˜TŸ\™\¨5Ð2`ÔaÜ×)Ñ)¨$¯,©,Ó7ˆ	Ø" D§L¡L°,À	ÐJˆÜ×Ñœ%×*Ñ*¨F°DÔ9ØÐr   c                 ó|   — t        j                  |«      syt        j                  |«      j	                  d«      dk(  S )z0Returns True if this object is the desktop frameFz
is-desktopÚtrue)r   Úis_framer   Úget_attributes_dictÚget)r   Úwindows     r   Ú_is_desktop_framezFocusManager._is_desktop_frameè   s6   € ô ×#Ñ# FÔ+Øä×+Ñ+¨FÓ3×7Ñ7¸ÓEÈÑOÐOr   c                 ó@  — |€yt        j                  |dd«       t        j                  |«      }d|d|g}t        j                  |«      s7|j                  d«       t        j                  t        j                  |d«       yt        j                  |«      s7|j                  d«       t        j                  t        j                  |d«       yt        j                  |«      r7|j                  d«       t        j                  t        j                  |d«       yt        j                  |«      d	k(  r7|j                  d
«       t        j                  t        j                  |d«       y|j                  d«       t        j                  t        j                  |d«       y)zCReturns True if window can be the active window based on its state.Fz+Checking if window can be the active windowrX   Úfromzlacks active stateTzlacks showing statezis iconifiedzmutter-x11-framesz3is from app that cannot have the real active windowzcan be active window)r   rF   rJ   r   rY   Úappendr   r   r   Ú
is_showingÚis_iconifiedÚget_name)r   r`   rI   r!   s       r   Úcan_be_active_windowz!FocusManager.can_be_active_windowð   sB  € ð ˆ>Øä×Ñ˜V UÐ,YÔZÜ×&Ñ& vÓ.ˆØ" F¨F°CÐ8ˆä×$Ñ$ VÔ,Ø�M‰MÐ.Ô/Ü×Ñœe×.Ñ.°¸Ô=Øä×%Ñ% fÔ-Ø�M‰MÐ/Ô0Ü×Ñœe×.Ñ.°¸Ô=Øä×#Ñ# FÔ+Ø�M‰M˜.Ô)Ü×Ñœe×.Ñ.°¸Ô=Øä×Ñ˜SÓ!Ð%8Ò8Ø�M‰MÐOÔPÜ×Ñœe×.Ñ.°¸Ô=Øà�‰Ð,Ô-Ü×Ñœ%×*Ñ*¨F°DÔ9Ør   c           	      ó   — g }|xs t        j                  d¬«      }|D ]:  }|j                  t        t	        j
                  || j                  «      «      «       Œ< |s*d|g}t        j                  t        j                  |d«       yt        |«      dk(  r1d|d   g}t        j                  t        j                  |d«       |d   S d|g}t        j                  t        j                  |d«       g d	¢}g }|D ]h  }t	        j                  t	        j                  |«      «      |v r+d
|dg}t        j                  t        j                  |d«       ŒX|j                  |«       Œj t        |«      dk(  r1d|d   g}t        j                  t        j                  |d«       |d   S d}|r.d|g}t        j                  t        j                  |d«       |d   }d|dg}t        j                  t        j                  |d«       |S )z:Tries to locate the active window; may or may not succeed.T)Úmust_have_windowz0FOCUS MANAGER: Unable to find active window fromNr   úFOCUS MANAGER: Active window isr.   z4FOCUS MANAGER: These windows all claim to be active:)ÚslackÚdiscordzoutline-clientzwhatsapp-desktop-linuxzFOCUS MANAGER: Suspectingzis a non-active Electron appz.FOCUS MANAGER: Active window is believed to bez2FOCUS MANAGER: Still have multiple active windows:zFOCUS MANAGER: Returningzas active window)r   Úget_all_applicationsÚextendÚlistr   Úiter_childrenrh   r   r   r   Úlenrg   rJ   rd   )	r   ÚappsÚ
candidatesrI   r!   Úsuspect_app_namesÚfilteredÚframeÚguesss	            r   Úfind_active_windowzFocusManager.find_active_window  sç  € ð ˆ
ØÒN”{×7Ñ7ÈÔNˆØò 	\ˆCØ×Ñœd¤8×#9Ñ#9¸#¸t×?XÑ?XÓ#YÓZÕ[ð	\ñ ØHÈ$ÐOˆFÜ×Ñœe×.Ñ.°¸Ô=Øäˆz‹?˜aÒØ7¸ÀA¹ÐGˆFÜ×Ñœe×.Ñ.°¸Ô=Ø˜a‘=Ð àHÈ*ÐUˆÜ×Ñœ%×*Ñ*¨F°DÔ9ò7Ðð ˆØò 	'ˆEÜ× Ñ ¤×!9Ñ!9¸%Ó!@ÓAÐEVÑVØ5°uÐ>\Ð]�Ü×!Ñ!¤%×"2Ñ"2°F¸DÕAà—‘ Õ&ð	'ô ˆx‹=˜AÒØFÈÐQRÉÐTˆFÜ×Ñœe×.Ñ.°¸Ô=Ø˜A‘;ÐàˆÙØJÈHÐUˆFÜ×Ñœe×.Ñ.°¸Ô=Ø˜Q‘KˆEà,¨eÐ5GÐHˆÜ×Ñœ%×*Ñ*¨F°DÔ9Øˆr   c                 ó‚   — d| j                   g}t        j                  t        j                  |dd«       | j                   S )zJReturns the currently-active window (i.e. without searching or verifying).rk   T)r   r   r   r   r@   s     r   Úget_active_windowzFocusManager.get_active_windowD  s6   € ð 4°T·\±\ÐBˆÜ×Ñœ%×*Ñ*¨F°D¸$Ô?Ø�|‰|Ðr   c                 ó  — d|g}|�|j                  d|g«       t        j                  t        j                  |d«       || j                  k(  r(d}t        j
                  t        j                  |d«       nb|€d| _        nXt        j                  ||«      \  }}||k7  r3d|d|g}t        j                  t        j                  |d«       || _        n|| _        |r| j                  d| j                  |«       y| j                  r}| j                  rp| j                  «       s_d| j                  d| j                  g}t        j                  t        j                  |dd«       | j                  d| j                  d¬	«       yyyy)
zSets the active window.z.FOCUS MANAGER: Request to set active window toNÚinTz>FOCUS MANAGER: Setting active window to existing active windowz*FOCUS MANAGER: Correcting active window tozFOCUS MANAGER: Focusz	is not in)rQ   )ro   r   r   r   r   r   r   Úfind_real_app_and_window_forrV   r   r,   )	r   rw   rI   Úset_window_as_focusrQ   r!   r   Úreal_appÚ
real_frames	            r   Úset_active_windowzFocusManager.set_active_windowK  sK  € ð CÀEÐJˆØˆ?Ø�M‰M˜4 ˜+Ô&Ü×Ñœ%×*Ñ*¨F°DÔ9à�D—L‘LÒ ØRˆCÜ×Ñœu×/Ñ/°°dÕ;Øˆ]ØˆD�Lä#+×#HÑ#HÈÐPSÓ#TÑ ˆH�jØ˜UÒ"ØFÈ
ÐTXÐZbÐc�Ü×!Ñ!¤%×"2Ñ"2°F¸DÔAØ)�•à$�”áØ×#Ñ# D¨$¯,©,¸ÕFØ�\Š\˜dŸkšk°$×2PÑ2PÔ2RØ,¨d¯k©k¸;ÈÏÉÐUˆFÜ×Ñœe×.Ñ.°¸¸dÔCØ×#Ñ# D¨$¯,©,ÀdÐ#ÕKð 3S˜kˆ\r   )r/   )NNN)TF)NFF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r"   r$   r'   r)   r,   r>   rA   rC   rV   rZ   ra   rh   ry   r{   r‚   © r   r   r
   r
   .   sb   „ Ù2ò!ó
!òòòò+ò[ó
%+òN;òó;BòzòPò òD0òdôLr   r
   c                  ó   — t         S r   )Ú_managerr‡   r   r   rG   rG   j  s   € Ü€Or   N)r†   Ú__id__Ú__version__Ú__date__Ú__copyright__Ú__license__r/   r   r   r   Ú	ax_objectr   Úax_utilitiesr   ÚCARET_TRACKINGr3   r6   ÚMOUSE_REVIEWÚOBJECT_NAVIGATORÚSAY_ALLr
   r‰   rG   r‡   r   r   ú<module>r•      sp   ðñ. 8à€Ø€Ø€ð7€à€å Ý Ý Ý Ý %à!€Ø!€Ø€Ø€Ø%Ð Ø
€÷xLñ xLñv	 ‹>€ór   