+
    uj8iH                         ^ RI t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t	H
t
Ht ^ RIHt ^ RIHt ^ RIHt  ! R R	4      t ! R
 R4      tR# )    N	Namespace)Path)AnyDictOptional)hypr)log_message)user_config_pathc                   2   a  ] tR t^t o V 3R lR ltRtV tR# )
WindowRulec                H   < V ^8  d   QhRS[ RS[ RS[ RS[ RS[S[ ,          /# )   name
match_typewidthheightactions)strlist)format__classdict__s   "B/usr/lib/python3.14/site-packages/caelestia/subcommands/resizer.py__annotate__WindowRule.__annotate__   s7      S c # s UYZ]U^     c                B    Wn         W n        W0n        W@n        WPn        R # N)r   r   r   r   r   )selfr   r   r   r   r   s   &&&&&&r   __init__WindowRule.__init__   s    	$
r   )r   r   r   r   r   N)__name__
__module____qualname____firstlineno__r    __static_attributes____classdictcell__r   s   @r   r   r      s      r   r   c                   @  a  ] tR t^t o V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR  ltR!tV tR"# )#Commandc                $   < V ^8  d   QhRS[ RR/# )r   argsreturnNr   )r   r   s   "r   r   Command.__annotate__   s     6 6Y 64 6r   c                J    Wn         / V n        V P                  4       V n        R # r   )r,   timeout_tracker_load_window_ruleswindow_rules)r   r,   s   &&r   r    Command.__init__   s     	13 335r   c                0   < V ^8  d   QhRS[ S[,          /# )r   r-   )r   r   )r   r   s   "r   r   r.      s      D$4 r   c                2   \        R RRRRR.4      \        RRRRRR.4      \        R	RR
RRR.4      \        RRRRR.4      .p \        P                  ! \        P                  ! 4       4      pRV9   dk   RVR,          9   d]   . pVR,          R,           FD  pVP                  \        VR,          VR,          VR,          VR,          VR,          4      4       KF  	  V# V#   \        P                  \        3 d    \        R4        T# \         d     T# i ; i)z
(BitwardentitleContainsz20%z54%floatcenterzSign in - Google Accountsz35%z65%oauthz30%z60%z"^[Pp]icture(-| )in(-| )[Pp]icture$
titleRegex pipresizerrulesr   	matchTyper   r   r   zERROR: invalid config)
r   jsonloadsr   	read_textappendJSONDecodeErrorKeyErrorr
   FileNotFoundError)r   default_rulesconfigr>   rule_configs   &    r   r1   Command._load_window_rules   s8   |_eUWhDWX2OUET[]eSfgw?RS;\2rTYSZ[	
	ZZ 0 : : <=FF"w&2C'C#))#4W#=#=KLL"'/'4'0'1'	2 $>   $$h/ 	1/0  ! 		s   BC &DDDDc                &   < V ^8  d   QhRS[ RS[/# )r   keyr-   )r   bool)r   r   s   "r   r   r.   ;   s      C D r   c                    \         P                   ! 4       pV P                  P                  V^ 4      pW#^,           8  d   R# W P                  V&   R# )r   TF)timer0   get)r   rL   current_time	last_times   &&  r   _is_rate_limitedCommand._is_rate_limited;   sC    yy{((,,S!4	a-'$0S!r   c                L   < V ^8  d   QhRS[ RS[S[S[ S[3,          ,          /# )r   	window_idr-   )r   r   r   r   )r   r   s   "r   r   r.   E   s(     
 
# 
(4S>2J 
r   c                     \         P                  ! R 4      p\        V\        4      '       d?   V F8  p\        V\        4      '       g   K  VP                  R4      RV 28X  g   K6  Vu # 	  R#   \         d     R# i ; i)clientsaddress0xN)r	   message
isinstancer   dictrP   	Exception)r   rV   rX   clients   &&  r   _get_window_infoCommand._get_window_infoE   ss    	ll9-G'4((%F!&$//FJJy4IrR[Q\M]4]% &   		s$   AA. A. &A. *A. .A=<A=c                $   < V ^8  d   QhRS[ RR/# )r   rV   r-   Nr   )r   r   s   "r   r   r.   Q   s#     ^[ ^[3 ^[4 ^[r   c                    R V 2p\         P                  ! R4      p\        V\        4      '       g   R# RpV F5  p\        V\        4      '       g   K  VP                  R4      V8X  g   K3  Tp M	  V'       d/   \        V\        4      '       d   VP                  RR4      '       g   R# \         P                  ! R4      p\        V\        4      '       g   R# VP                  R4      p\        V\        4      '       g   R# VP                  R4      pRp	V F5  p
\        V
\        4      '       g   K  V
P                  R4      V8X  g   K3  T
p	 M	  V	'       d   \        V	\        4      '       g   R# \         P                  ! R	4      p\        V\        4      '       g   R# V	P                  R
4      pRpV F5  p\        V\        4      '       g   K  VP                  R4      V8X  g   K3  Tp M	  V'       d   \        V\        4      '       g   R# VP                  R4      p\        V\        4      '       d   \        V4      ^8  d   R# V^ ,          V^,          pp\        V\        \        34      '       d   \        V\        \        34      '       g   R# VP                  R4      pVP                  R4      pVP                  R4      pVP                  R4      pVP                  R4      p\        ;QJ d!    R VVVVV3 4       F  '       d   K   RM	  RM! R VVVVV3 4       4      '       g   R# VV,          pVV,          pV^,          V,          p\        VV,          4      p\        VV,          4      p^p^p\        VV4      p\        VV4      p\        VV4      R,          pVV,           V,
          V,
          pVV,           V,
          V,
          pRV RV RV 2pR\        V4       R\        V4       RV 2p \         P                  ! VV 4       \        RV RV RV RV RV R24       R#   \         d   p!\        RT RT! 24        Rp!?!R# Rp!?!ii ; i)rZ   rX   NrY   floatingF
workspaces	workspacer   monitors	monitorIDidsizer   r   scalexyc              3   N   "   T F  p\        V\        \        34      x  K  	  R # 5ir   )r\   intr7   ).0rm   s   & r   	<genexpr>,Command._apply_pip_action.<locals>.<genexpr>   s)       B  =Aqz!c5\22  =As   #%TgQ?!dispatch resizewindowpixel exact  z	,address:zdispatch movewindowpixel exact zApplied PiP action to window : z at (, )z.ERROR: Failed to apply PiP action to window 0x)r	   r[   r\   r   r]   rP   lenrp   r7   allmaxminbatchr
   r^   )"r   rV   rY   clients_resultwindowcworkspaces_resultworkspace_infoworkspace_namerg   wmonitors_result
monitor_idmonitormwindow_sizer   r   monitor_heightmonitor_widthmonitor_scale	monitor_x	monitor_yscale_factorscaled_widthscaled_height	min_width
min_heightoffsetmove_xmove_ycommand1command2es"   &&                                r   _apply_pip_actionCommand._apply_pip_actionQ   s   ]	[9+&G!\\)4Nnd33F#a&&155+;w+FF $
 FD!9!9JX]A^A^ $\ :/66#ZZ4Nnd33+//7NI&a&&155=N+J !I '
 Jy$$?$?"ll:6Oot44"{3JG$a&&155;*+DG %
 *Wd";"; **V,Kk400C4Dq4H'NKN6Eec5\22*VcSX\:Z:Z$[[2N#KK0M#KK0MC(IC(I3  B^]\iktv  =A  B333  B^]\iktv  =A  B  B  B+m;N)M9M)A-6Lu|34L 56M IJ|Y7Lz:M 7$>F .=FF/-?&HF:<.-XabiajkH8VQs6{mS\]d\efHJJx*/y<.-X]^d]eeghngoopq  	[HSUVWUXYZZ	[s   1P* P* P* ,P* :-P* *,P* 'P* +P* 1P* 	P* P* /,P* +P* P* %P* 3P* 7P* A
P* AP* 0P* 	P* +C=P* *Q5QQc          
      H   < V ^8  d   QhRS[ RS[ RS[ RS[S[ ,          RS[/# )r   rV   r   r   r   r-   )r   r   rM   )r   r   s   "r   r   r.      s8      s 3  VZ[^V_ dh r   c                   . pR V9   dF   V P                  V4      pV'       d-   VP                  RR4      '       g   VP                  RV 24       RV9   d   V P                  V4       R# VP                  RV RV RV 24       R	V9   d   VP                  R
4        \        P
                  ! V!   \        RV RV RV RRP                  V4       R2	4       R#   \         d   p\        RT RT 24        Rp?R# Rp?ii ; i)r7   re   Fz"dispatch togglefloating address:0xr<   Trt   ru   z,address:0xr8   zdispatch centerwindowzApplied actions to window 0xrv   z x z (rw   rx   z3ERROR: Failed to apply window actions for window 0xN)	r`   rP   rC   r   r	   r}   r
   joinr^   )r   rV   r   r   r   dispatch_commandswindow_infor   s   &&&&&   r   _apply_window_actionsCommand._apply_window_actions   s   g//	:K;??:u#E#E!((+Mi[)YZG""9-  #DUG1VHT_`i_j!klw$$%<=	JJ)*6ykE7#fXUWX\XaXabiXjWkklmn 	Mi[XZ[\Z]^_	s   ;C D $C;;D c                :   < V ^8  d   QhRS[ RS[ RS[R,          /# )r   window_titleinitial_titler-   N)r   r   )r   r   s   "r   r   r.      s(      s 3 :X\K\ r   c                    V P                    F  pVP                  R 8X  d   W#P                  8X  d   Vu # K*  VP                  R8X  d   VP                  V9   d   Vu # KR  VP                  R8X  d   WP                  8X  d   Vu # Ky  VP                  R8X  g   K   \        P                  ! VP                  V4      '       d   Vu # K  	  R#   \        P
                   d    \        RTP                   R24        K  i ; i)initialTitler6   
titleExactr:   z&ERROR: Invalid regex pattern in rule ''N)r2   r   r   researcherrorr
   )r   r   r   rules   &&& r   _match_window_ruleCommand._match_window_rule   s    %%D.0 II-K .O399,K -L099,K -L0WyyL99# : &"  xx W"HST UVWs   &CC.C=<C=c                $   < V ^8  d   QhRS[ RR/# r   eventr-   Nrc   )r   r   s   "r   r   r.      s     + +# +$ +r   c                    VP                  R 4      '       d   V P                  V4       R# VP                  R4      '       d   V P                  V4       R# R# )windowtitle
openwindowN)
startswith_handle_title_event_handle_open_event)r   r   s   &&r   _handle_window_eventCommand._handle_window_event   sE    M**$$U+l++##E* ,r   c                $   < V ^8  d   QhRS[ RR/# r   rc   )r   r   s   "r   r   r.      s     "K "K "K "Kr   c           	         R V9   d0   VP                  R 4      ^,          P                  R4      ^ ,          pM.VP                  R4      ^,          P                  R4      ^ ,          pVP                  R4      p\        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        RV 24       R# V P	                  V4      pV'       g   R# VP                  R	R
4      pVP                  RR
4      p\        RV RV RV R24       V P                  WE4      pV'       dv   V P                  V4      '       d   \        RV 24       R# \        RVP                   RV 24       V P                  W&P                  VP                  VP                  4       R# R#   \        \        3 d   p\        RT 24        Rp?R# Rp?ii ; i)z>>>,z>>>c              3   *   "   T F	  qR 9   x  K  	  R# 5i0123456789abcdefABCDEFN rq   r   s   & r   rr   .Command._handle_title_event.<locals>.<genexpr>        Hi44i   FT!ERROR: Invalid window ID format: Ntitler;   r   zDEBUG: Window 0x - Title: 'z' | Initial: 'r    Rate limited: skipping window 0xMatched rule 'z' for window 0xz+ERROR: Failed to parse window title event: )splitlstriprz   r
   r`   rP   r   rS   r   r   r   r   r   
IndexError
ValueError)r   r   rV   r   r   r   r   r   s   &&      r   r   Command._handle_title_event   s   !	K~!KK.q177<Q?	!KK-a066s;A>	 "((-I3HiH333HiHHH?	{KL//	:K&??7B7L'OONB?M*9+[n]j\kklmn**<GD((33"B9+ NOnTYYKykRS**9jj$++t||\  J' 	KEaSIJJ	KsD   A?F% F% F% 1F% F% A(F% F% AF% %G6G

Gc                $   < V ^8  d   QhRS[ RR/# r   rc   )r   r   s   "r   r   r.     s     J J J Jr   c           	         R V9   d   VR,          pM	VR,          pVP                  R^4      w  r4rVVP                  R4      p\        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        RV 24       R	# \        R
V RV RV R24       V P	                  Wf4      pV'       dv   V P                  V4      '       d   \        RV 24       R	# \        RVP                   RV 24       V P                  W7P                  VP                  VP                  4       R	# R	#   \        \        3 d   p\        RT 24        R	p?R	# R	p?ii ; i)zopenwindow>>>:   NN:   NNr   r   c              3   *   "   T F	  qR 9   x  K  	  R# 5ir   r   r   s   & r   rr   -Command._handle_open_event.<locals>.<genexpr>  r   r   FTr   NzDEBUG: New window 0xr   z' | Class: 'r   r   r   z' for new window 0xz*ERROR: Failed to parse window open event: )r   r   rz   r
   r   rS   r   r   r   r   r   r   r   )	r   r   datarV   rg   window_classr   r   r   s	   &&       r   r   Command._handle_open_event  s>   	J%'SzSz8<

38J5I, "((-I3HiH333HiHHH?	{KL.ykUG<XdWeefgh**58D((33"B9+ NOnTYYK7J9+VW**9jj$++t||\  J' 	JDQCHII	Js8   AD1 !D1 <D1 AD1 D1 !AD1 1EEEc                   < V ^8  d   QhRR/# r   r-   Nr   )r   r   s   "r   r   r.   '  s      T r   c                  a  S P                   P                  '       d   S P                  4        R# \        S P                   R 4      '       d.   S P                   P                  R8X  d   S P                  4        R# \        ;QJ d    V 3R lR 4       F  '       d   K   RM	  RM! V 3R lR 4       4      '       d   S P                  4        R# \        R4       R# )patternr<   c              3      <"   T F9  p\        SP                  V4      ;'       d    \        SP                  V4      x  K;  	  R # 5ir   )hasattrr,   getattr)rq   attrr   s   & r   rr   Command.run.<locals>.<genexpr>,  s9      
O DIIt$AAD)AAOs
   !AAFTzResizer daemon - use --daemon to start, 'pip' for quick pip mode, or provide pattern, match_type, width, height, and actions for active modeN)r   r   r   r   r   )	r,   daemon_run_daemonr   r   _run_pip_moderz   _run_active_modeprint)r   s   fr   runCommand.run'  s    99TYY	**tyy/@/@E/I S 
O
SSS 
O
 
 
 !!# _r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r.   6  s     G Gt Gr   c                    \         P                  ! R4      p\        V\        4      '       d   VP	                  R4      '       g   \        R4       R# VP	                  RR4      p\        V\        4      '       d   VP                  R4      '       g   \        R4       R# VR,          pVP	                  R	R4      pVP	                  R
R4      '       g   \        RV R24       \        R4       R# \        RV R24       V P                  V4       \        R4       R#   \         d   p\        RT 24        Rp?R# Rp?ii ; i)zIQuick pip mode - applies pip action to the active window if it's floatingactivewindowrY   ERROR: No active window foundNr;   rZ   ERROR: Invalid window addressr   NNr   re   FzWindow 'z6' is not floating. PIP only works on floating windows.zBTry making it floating first with: hyprctl dispatch togglefloatingz Applying PIP to active window: 'r   zPIP applied successfullyz-ERROR: Failed to apply PIP to active window: )
r	   r[   r\   r]   rP   r   r   r   r   r^   )r   active_window_resultrY   rV   r   r   s   &     r   r   Command._run_pip_mode6  s   	G#'<<#? 2D99AUAYAYZcAdAd56*..y"=Ggs++73E3Ed3K3K56I/33GR@L'++J>>.defZ[4\N!DE""9-,- 	GA!EFF	Gs<   AD D >D D 2D D -+D D>%D99D>c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r.   R  s     "7 "7$ "7r   c                    V P                   P                  '       d&   V P                   P                  P                  R 4      M. p\        V P                   P                  V P                   P
                  V P                   P                  V P                   P                  V4      pVP                  P                  4       R8X  d   V P                  V4       R# V P                  V4      pV'       g)   \        RVP                   RVP
                   R24       R# \        R\        V4       R24       ^ pV F{  pVR,          R	,          pVP                  R
R4      p\        RV RV R24       V P                  WbP                  VP                  VP                  4      pV'       g   Kr  V^,          pK}  	  \        RV R\        V4       R24       R#   \          d   p	\        RT	 24        Rp	?	R# Rp	?	ii ; i)r   activeNz#No windows found matching pattern 'z' with match type 'r   zFound z matching window(s)rY   r   r   r;   zApplying rule to window 0x: 'zSuccessfully applied rule to /z windowszERROR: Failed to apply rule: )r,   r   r   r   r   r   r   r   r   lower_apply_to_active_window_find_matching_windowsr   ry   rP   r   r^   )
r   r   	temp_rulematching_windowssuccess_countr   rV   r   successr   s
   &         r   r   Command._run_active_modeR  s   !	76:ii6G6G6Gdii''--c2RG"499#4#4dii6J6JDIIOO]a]f]f]m]movwI ~~##%1,,Y7  $::9E#;INN;KK^_h_s_s^ttuvwF3/011DEF M*"9-b1	%zz'2629+SaPQ44YQZQaQaclctctu7!Q&M + 1-#FVBWAXX`ab 	71!566	7s6   G B6G G /&G B	G %(G G3G..G3c                $   < V ^8  d   QhRS[ RR/# )r   r   r-   N)r   )r   r   s   "r   r   r.   v  s     H H H Hr   c                    \         P                  ! R4      p\        V\        4      '       d   VP	                  R4      '       g   \        R4       R# VP	                  RR4      pVP	                  RR4      p\        V\        4      '       d   VP                  R4      '       g   \        R4       R# VR	,          p\        R
V RV R24       V P                  WQP                  VP                  VP                  4      pV'       d   \        R4       R# \        R4       R#   \         d   p\        RT 24        Rp?R# Rp?ii ; i)z.Apply rule only to the currently active windowr   rY   r   Nr   r;   rZ   r   r   z!Applying rule to active window 0xr   r   zRule applied successfullyzFailed to apply rulez.ERROR: Failed to apply rule to active window: )r	   r[   r\   r]   rP   r   r   r   r   r   r   r   r^   )r   r   r   r   rY   rV   r   r   s   &&      r   r   Command._apply_to_active_windowv  s   	H#'<<#? 2D99AUAYAYZcAdAd56/33GR@L*..y"=Ggs++73E3Ed3K3K56I5i[L>QRST00OOYM]M]_h_p_pqG12,- 	HB1#FGG	Hs8   AD D AD #D 0AD D E)D==Ec                &   < V ^8  d   QhRS[ RS[/# )r   r   r-   )r   r   )r   r   s   "r   r   r.     s     % %
 %t %r   c                &    \         P                  ! R4      p\        V\        4      '       g   . # . pV F  p\        V\        4      '       g   K  VP                  RR4      pVP                  RR4      pRpVP                  R8X  d   WaP                  8H  pM}VP                  R8X  d   VP                  V9   pM\VP                  R8X  d   WQP                  8H  pM<VP                  R8X  d,    \        \        P                  ! VP                  V4      4      pV'       g   K  VP                  V4       K  	  V#   \        P                   d!    \        R	TP                   R
24       . u u # i ; i  \         d   p\        RT 24       . u Rp?# Rp?ii ; i)z2Find all windows that match the given rule patternrX   r   r;   r   Fr6   r   r:   zERROR: Invalid regex pattern 'r   z(ERROR: Failed to find matching windows: N)r	   r[   r\   r   r]   rP   r   r   rM   r   r   r   r   rC   r^   )	r   r   r~   r   r   r   r   matchesr   s	   &&       r   r   Command._find_matching_windows  s^   #	!\\)4Nnd33	!(!&$//%zz'26 &

>2 >  ''>9+~~=G))_<'nn<G))\9*nn<G))\9""&ryy'N"O
 7$++F3/ )2 $# 88 " >y~~>NaPQ!	"  	<QC@AI	sM   -E+ B7E+ (*D3E+ E+ 30E(#E+ 'E((E+ +F6FFFc                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r.     s     ' 'T 'r   c                (   \        R 4       \        R\        V P                  4       R24       \        \        P
                  4      pVP                  4       '       g   \        RV 24       R#  \        P                  ! \        P                  \        P                  4      ;_uu_ 4       pVP                  \        P
                  4       \        R4        VP                  R4      P                  4       pV'       g   K*  VP                  4       P                  R4       F  pV'       g   K  V P                  V4       K   	  Km    + '       g   i     R# ; i  \          d    \        R4        R# \"         d   p\        R	T 24        Rp?R# Rp?ii ; i)
zHyprland window resizer startedzLoaded z window rulesz$ERROR: Hyprland socket not found at Nz5Connected to Hyprland socket, listening for events...i   
zResizer daemon stoppedzERROR: )r
   ry   r2   r   r	   socket2_pathexistssocketAF_UNIXSOCK_STREAMconnectrecvdecodestripr   r   KeyboardInterruptr^   )r   socket_pathsockr   liner   s   &     r   r   Command._run_daemon  s#   56gc$"3"345]CD4,,-!!##>{mLM	'v~~v/A/ABBdT../ST99T?113Dt$(JJL$6$6t$<D#t $ 9 9$ ? %= CBB ! 	201 	''!&&	'sI   .;E )AE>'E*EE	E E F.F7F8FF)r,   r0   r2   N)r"   r#   r$   r%   r    r1   rS   r`   r   r   r   r   r   r   r   r   r   r   r   r   r&   r'   r(   s   @r   r*   r*      s     6 6
 < 
 
^[ ^[@ 2 (+ +"K "KHJ J> G G8"7 "7HH H4% %N' 'r   r*   )r@   r   r  rO   argparser   pathlibr   typingr   r   r   caelestia.utilsr	   caelestia.utils.loggingr
   caelestia.utils.pathsr   r   r*   r   r   r   <module>r     s<     	     & &   / 2 y' y'r   