Ë
    ‹±šf*›  ã                   ó†  — d Z ddlmZmZmZ ddlZddlmZmZ ddl	m
Z
  e
«        ddlmZmZmZ ddlmZmZ ddlmZ dd	lmZmZ ddlmZ ddlZ ej4                  d
«      Z G d„ de«      Z G d„ d«      Z G d„ d«      Z G d„ de«      Z d„ Z! G d„ de«      Z"d"d„Z#d„ Z$d„ Z%d„ Z&d„ Z'd#d„Z(d„ Z)d"d„Z*d$d„Z+d„ Z,d „ Z-d!„ Z.y)%z' Window manipulation and other helpers é    )ÚdivisionÚprint_functionÚunicode_literalsN)ÚsqrtÚpi)Úrequire_gi_versions)ÚGLibÚGtkÚGdk)ÚRectÚVersion)ÚTimer)ÚHandleÚHandleFunctionÚWindowUtilsc                   ó:  — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd2d„Zd2d„Zd„ Zd„ Zd„ Zd„ Zd„ Zd3d„Zd„ Zd„ Zd4d„Zd„ Zd4d„Z d4d „Z!d!„ Z"d"„ Z#d#„ Z$d$„ Z%d%„ Z&d&„ Z'd'„ Z(d(„ Z)d)„ Z*d*„ Z+d+„ Z,d,„ Z-d-„ Z.d5d.„Z/d/„ Z0d5d0„Z1d1„ Z2y)6ÚWindowManipulatoraD  
    Adds resize and move capability to windows.
    Meant for resizing windows without decoration or resize gripper.

    Quirks to remember:

    Keyboard window:
        - Always use threshold when move button was pressed
          in order to support long press to show the touch handles.
        - Never use the threshold for the enlarged touch handles.
          They are only temporarily visible and thus don't need protection.

    IconPalette:
        - Always use threshold when trying to move, otherwise
          clicking to unhide the keyboard window won't work.
    c                 ó  — d| _         d| _        d | _        d| _        d| _        d | _        d | _        d | _        d | _        t        j                  | _        d| _        d| _        d| _        d| _        d| _        d | _        d | _        y )Né
   Tg      @)é2   r   Fé   é   )Úhit_frame_widthÚdrag_protectionÚ_temporary_unlock_timeÚtemporary_unlock_delayÚmin_window_sizeÚ_drag_start_pointerÚ_drag_start_offsetÚ_drag_start_rectÚ_drag_handler   ÚALLÚ_drag_handlesÚ_drag_activeÚ_drag_thresholdÚ_drag_snap_thresholdÚ_lock_x_axisÚ_lock_y_axisÚ_last_drag_handleÚ_monitor_rects©Úselfs    ú5/usr/lib/python3/dist-packages/Onboard/WindowUtils.pyÚ__init__zWindowManipulator.__init__<   s�   € Ø!ˆÔØ#ˆÔØ&*ˆÔ#ð '*ˆÔ#à'ˆÔà#'ˆÔ Ø#'ˆÔØ#'ˆÔØ#'ˆÔÜ#ŸZ™ZˆÔØ#(ˆÔØ#$ˆÔØ$&ˆÔ!à$)ˆÔØ$)ˆÔà$(ˆÔØ$(ˆÕó    c                 ó   — ||f| _         y ©N©r   ©r,   ÚwÚhs      r-   Úset_min_window_sizez%WindowManipulator.set_min_window_sizeX   s   € Ø ! 1˜vˆÕr/   c                 ó   — | j                   S r1   r2   r+   s    r-   Úget_min_window_sizez%WindowManipulator.get_min_window_size[   ó   € Ø×#Ñ#Ð#r/   c                 ó   — | j                   S r1   )r   r+   s    r-   Úget_hit_frame_widthz%WindowManipulator.get_hit_frame_width^   r9   r/   c                 ó   — || _         y r1   )r   )r,   Úenables     r-   Úenable_drag_protectionz(WindowManipulator.enable_drag_protectiona   s
   € Ø%ˆÕr/   c                 ó   — d | _         y r1   )r   r+   s    r-   Úreset_drag_protectionz'WindowManipulator.reset_drag_protectiond   s
   € Ø&*ˆÕ#r/   c                 ó–   — 	 | j                  «       S # t        $ r- t        dd| j                  «       | j	                  «       «      cY S w xY w)Nr   )Úget_keyboard_frame_rectÚAttributeErrorr   Úget_allocated_widthÚget_allocated_heightr+   s    r-   Úget_resize_frame_rectz'WindowManipulator.get_resize_frame_rectg   sN   € ð	5Ø×/Ñ/Ó1Ð1øÜò 	5Ü˜˜1Ø×0Ñ0Ó2Ø×1Ñ1Ó3ó5ò 5ð	5ús   ‚ ’3AÁAc                 ó   — | j                   S r1   )r    r+   s    r-   Úget_drag_start_rectz%WindowManipulator.get_drag_start_recto   s   € Ø×$Ñ$Ð$r/   c                 ó   — | S r1   © r+   s    r-   Úget_drag_windowz!WindowManipulator.get_drag_windowr   ó   € Øˆr/   c                 ó   — | j                   S r1   ©r#   r+   s    r-   Úget_drag_handlesz"WindowManipulator.get_drag_handlesu   s   € Ø×!Ñ!Ð!r/   c                 ó   — || _         y r1   rN   )r,   Úhandless     r-   Úset_drag_handlesz"WindowManipulator.set_drag_handlesx   s
   € Ø$ˆÕr/   c                 ó"   — t         j                  S r1   )r   ÚNORMAL)r,   Úhandles     r-   Úget_handle_functionz%WindowManipulator.get_handle_function{   s   € Ü×$Ñ$Ð$r/   c                  ó   — y)Nr   rJ   r+   s    r-   Úget_drag_thresholdz$WindowManipulator.get_drag_threshold~   s   € Ør/   c                  ó   — y)zA Rectangle in canvas coordinates that must not leave the screen. NrJ   r+   s    r-   Úget_always_visible_rectz)WindowManipulator.get_always_visible_rect�   s   € àr/   c                 ó   — || _         y)z+ Set to False to constraint movement in x. N)r'   ©r,   Úlocks     r-   Úlock_x_axiszWindowManipulator.lock_x_axis…   ó
   € à ˆÕr/   c                 ó   — || _         y)z* Set to True to constraint movement in y. N)r(   r\   s     r-   Úlock_y_axiszWindowManipulator.lock_y_axis‰   r_   r/   c                 óº  — | j                  |j                  «      }|�€|t        j                  k(  r| j	                  |j
                  «       y| j                  ||j
                  «       | j                  |«      }|t        j                  k(  r| j                  «        y|r<t        j                  | j                  «       v r| j	                  |j
                  «       yy)NTF)Úhit_test_move_resizeÚpointr   ÚMOVEÚstart_move_windowÚ
root_pointÚstart_resize_windowrV   r   ÚASPECT_RATIOÚon_handle_aspect_ratio_pressedrO   )r,   ÚsequenceÚmove_on_backgroundÚhitÚfunctions        r-   Úhandle_presszWindowManipulator.handle_press�   s·   € Ø×'Ñ'¨¯©Ó7ˆØˆ{Ø”f—k‘kÒ!Ø×&Ñ& x×':Ñ':Ô;ð ð ×(Ñ(¨¨h×.AÑ.AÔBà×3Ñ3°CÓ8�Øœ~×:Ñ:Ò:Ø×7Ñ7Ô9àáÜ�K‰K˜4×0Ñ0Ó2Ñ2Ø×"Ñ" 8×#6Ñ#6Ô7Øàr/   c                 ó¨  — | j                  «       sy d}|j                  \  }}|| j                  d   z
  }|| j                  d   z
  }| j                  sºt	        ||z  ||z  z   «      }| j
                   }	| j
                  rq| j                  €V|| j                  k\  rGd| _        || j                  k\  rd}n.| j                  dxx   |z  cc<   | j                  dxx   |z  cc<   | j                  �
d}	nd| _        | xj                  |	z  c_        | j                  r:|r| j                  ||«       n| j                  ||||«       | j                  «        y y )NFr   é   T)Úis_drag_initiatedrg   r   r$   r   r   r   r%   r&   r   Ú_handle_motion_fallbackÚ_handle_motion_systemÚon_drag_activated)
r,   rk   ÚfallbackÚsnap_to_cursorÚx_rootÚy_rootÚdxÚdyÚdÚdrag_actives
             r-   Úhandle_motionzWindowManipulator.handle_motion¢   sY  € Ø×%Ñ%Ô'ØàˆØ!×,Ñ,‰ˆ�Ø�d×.Ñ.¨qÑ1Ñ1ˆØ�d×.Ñ.¨qÑ1Ñ1ˆð × Ò Ü�R˜‘U˜R ™U‘]Ó#ˆAØ"×2Ñ2Ð2ˆKà×#Ò#à×.Ñ.Ð6Ø˜×,Ñ,Ò,Ø23�DÔ/ð ˜D×5Ñ5Ò5Ø)-™à×/Ñ/°Ó2°bÑ8Ó2Ø×/Ñ/°Ó2°bÑ8Ó2à×2Ñ2Ð:Ø"&‘Kà./�Ô+à×Ò Ñ,Õð ×ÒÙØ×,Ñ,¨R°Õ4à×*Ñ*¨2¨r°>À8ÔLð ×"Ñ"Õ$ð r/   c                 ó„  — | j                  «       }|r®|j                  \  }}| j                  «       r+|r
||z
  }||z
  }|j                  d|||j                  «       y| j                  «       rS|r'| j                  j                  ||f«      s
||z   ||z   }}|j                  | j                  d|||j                  «       yyy)a  
        Let the window manager do the moving
        This fixes issues like not reaching edges at high move speed
        and not being able to snap off a maximized window.
        Does nothing in force-to-top mode (override redirect or
        type hint "DOCK").
        rq   N)
rK   rg   Ú	is_movingÚbegin_move_dragÚtimeÚis_resizingr    Úis_point_withinÚbegin_resize_dragr!   )r,   rz   r{   rw   rk   ÚwindowÚxÚys           r-   rt   z'WindowManipulator._handle_motion_systemÑ   sÂ   € ð ×%Ñ%Ó'ˆÙØ×&Ñ&‰DˆAˆqØ�~‰~ÔÙ!Ø˜B™�AØ˜B™�AØ×&Ñ& q¨!¨Q°·±Õ>Ø×!Ñ!Ô#ñ "Ø×0Ñ0×@Ñ@À!ÀQÀÔHØ  2™v q¨2¡v˜1˜à×(Ñ(¨×):Ñ):¸AØ)*¨A¨x¯}©}õ>ð $ð r/   c                 ó$   — | j                  «        y)zƒ
        Call this when the system drag has ended.
        We need this to kick off the on_drag_done() call for KbdWindow.
        N©Ú	stop_dragr+   s    r-   Ústop_system_dragz"WindowManipulator.stop_system_dragì   s   € ð
 	�‰Õr/   c                 óÎ  — | j                  «       sy| j                  | j                  «      }|t        j                  k(  r5| j                  t
        j                  k(  r|dz  }| j                  ||«       y| j                  d   |z   | j                  d   z
  }| j                  d   |z   | j                  d   z
  }| j                  t
        j                  k(  rv| j                  r!| j                  «       j                  «       d   }| j                  r!| j                  «       j                  «       d   }| j                  ||«      \  }}d\  }}	�n†| j!                  «       \  }
}| j"                  }|j%                  «       \  }}}}|j'                  «       \  }}	| j                  t
        j(                  t
        j*                  t
        j,                  fv rt/        |||z
  «      }| j                  t
        j                  t
        j*                  t
        j0                  fv rt/        |||
z
  «      }| j                  t
        j2                  t
        j,                  t
        j4                  fv rt7        ||z   ||
z   «      }| j                  t
        j8                  t
        j0                  t
        j4                  fv rt7        ||	z   ||z   «      }||||z
  ||z
  f\  }}}}	| j;                  ||||	«       y)z, handle dragging for window move and resize Néÿÿÿÿr   rq   ©NN)rr   rV   r!   r   ri   r   ÚWESTÚon_handle_aspect_ratio_motionr   r   re   r'   rK   Úget_positionr(   Úlimit_positionr8   r    Ú
to_extentsÚget_sizeÚNORTHÚ
NORTH_WESTÚ
NORTH_EASTÚminÚ
SOUTH_WESTÚEASTÚ
SOUTH_EASTÚmaxÚSOUTHÚ_move_resize)r,   rz   r{   rn   ÚwxÚwyr‡   rˆ   r4   r5   ÚwminÚhminÚrectÚx0Úy0Úx1Úy1s                    r-   rs   z)WindowManipulator._handle_motion_fallbackó   s—  € à×%Ñ%Ô'Øà×+Ñ+¨D×,=Ñ,=Ó>ˆØ”~×2Ñ2Ò2à× Ñ ¤F§K¡KÒ/Ø�b‘�à×.Ñ.¨r°2Õ6à×)Ñ)¨!Ñ,¨rÑ1°D×4KÑ4KÈAÑ4NÑNˆBØ×)Ñ)¨!Ñ,¨rÑ1°D×4KÑ4KÈAÑ4NÑNˆBà× Ñ ¤F§K¡KÒ/à×$Ò$Ø×-Ñ-Ó/×<Ñ<Ó>¸qÑA�BØ×$Ò$Ø×-Ñ-Ó/×<Ñ<Ó>¸qÑA�Bð ×*Ñ*¨2¨rÓ2‘��1Ø!‘�’1ð "×5Ñ5Ó7‘
��dØ×,Ñ,�Ø!%§¡Ó!2‘��B˜˜BØ—}‘}“‘��1à×$Ñ$¬¯©Ü(.×(9Ñ(9Ü(.×(9Ñ(9ð);ñ ;ô ˜R  d¡Ó+�BØ×$Ñ$¬¯©Ü(.×(9Ñ(9Ü(.×(9Ñ(9ð);ñ ;ô ˜R  d¡Ó+�BØ×$Ñ$¬¯©Ü(.×(9Ñ(9Ü(.×(9Ñ(9ð);ñ ;ô ˜R !™V R¨$¡YÓ/�BØ×$Ñ$¬¯©Ü(.×(9Ñ(9Ü(.×(9Ñ(9ð);ñ ;ô ˜R !™V R¨$¡YÓ/�Bà  R¨¡V¨R°"©WÐ4‘
��1�a˜à×Ñ˜a  A qÕ)r/   c                  ó   — y)zk
        Overload this to process start of dragging of
        handles with ASPECT_RATIO function.
        NrJ   r+   s    r-   rj   z0WindowManipulator.on_handle_aspect_ratio_pressed)  ó   € ð
 	r/   c                  ó   — y)zi
        Overload this to process motion changes of 
        handles with ASPECT_RATIO function.
        NrJ   )r,   r    r¡   s      r-   r‘   z/WindowManipulator.on_handle_aspect_ratio_motion0  rª   r/   c                 óæ   — | j                  «       }|syd}|s| j                  �| j                  |«      }|�*t        j                  |«      }|r|j                  |«       yy|j                  d«       y©z set the mouse cursor N)Ú
get_windowr!   Úget_drag_cursor_atr   ÚCursorÚ
set_cursor)r,   rd   Úallow_drag_cursorsr†   Úcursor_typeÚcursors         r-   Úset_drag_cursor_atz$WindowManipulator.set_drag_cursor_at7  st   € à—‘Ó"ˆÙØàˆÙØ× Ñ Ð(Ø×1Ñ1°%Ó8ˆKð Ð"Ü—Z‘Z Ó,ˆFÙØ×!Ñ! &Õ)ð ð ×Ñ˜dÕ#r/   c                 óf   — | j                  «       }|sy| j                  €|j                  d«       yyr­   )r®   r!   r±   )r,   r†   s     r-   Úreset_drag_cursorz#WindowManipulator.reset_drag_cursorJ  s3   € à—‘Ó"ˆÙØà×ÑÐ$Ø×Ñ˜dÕ#ð %r/   c                 ó²   — | j                   }|€| j                  |«      }|�|t        j                  k(  r| j	                  «       rt        j
                  |   S y r1   )r!   rc   r   re   Úis_drag_activeÚCURSOR_TYPES)r,   rd   rm   s      r-   r¯   z$WindowManipulator.get_drag_cursor_atS  sR   € Ø×ÑˆØˆ;Ø×*Ñ*¨5Ó1ˆ3Øˆ{Ø”f—k‘kÒ! T×%8Ñ%8Ô%:Ü×&Ñ& sÑ+Ð+Ør/   Nc                 ór   — | j                  |«       t        j                  | _        | j                  | _        y r1   )Ú
start_dragr   re   r!   r)   )r,   rd   s     r-   rf   z#WindowManipulator.start_move_window\  s(   € Ø�‰˜ÔÜ"ŸK™KˆÔØ!%×!2Ñ!2ˆÕr/   c                 ó$   — | j                  «        y r1   rŠ   r+   s    r-   Ústop_move_windowz"WindowManipulator.stop_move_windowa  s   € Ø�‰Õr/   c                 óV   — | j                  |«       || _        | j                  | _        y r1   )r¼   r!   r)   )r,   rU   rd   s      r-   rh   z%WindowManipulator.start_resize_windowd  s$   € Ø�‰˜ÔØ"ˆÔØ!%×!2Ñ!2ˆÕr/   c                 óN  — d | _         |s-t        j                  «       }|j                  «       \  }}}}||f}| j	                  «       }|j                  «       \  }}	|| _        |d   |z
  |d   |	z
  g| _        t        j                  |j                  «       |j                  «       «      | _        d| _        | j                  «       | _        | j                  r:| j                   �5t#        j"                  «       | j                   z
  | j$                  kD  rd | _        | j'                  «        y )Nr   rq   F)r*   r   Úget_default_root_windowÚget_pointerrK   r’   r   r   r   Úfrom_position_sizer•   r    r$   rX   r%   r   r   r‚   r   Úon_drag_initiated)
r,   rd   ÚrootwinÚdunnorx   ry   Úmaskr†   r‡   rˆ   s
             r-   r¼   zWindowManipulator.start_dragi  s  € Ø"ˆÔñ Ü×1Ñ1Ó3ˆGØ*1×*=Ñ*=Ó*?Ñ'ˆE�6˜6 4Ø˜VÐ$ˆEð ×%Ñ%Ó'ˆØ×"Ñ"Ó$‰ˆˆ1Ø#(ˆÔ Ø#(¨¡8¨a¡<°°q±¸A±Ð">ˆÔÜ $× 7Ñ 7¸×8KÑ8KÓ8MØ8>¿¹Ó8Ió!KˆÔð "ˆÔð  $×6Ñ6Ó8ˆÔð ×#Ò#Ø×*Ñ*Ð2Ü�9‰9‹;˜×4Ñ4Ñ4Ø×4Ñ4ò5à*.ˆDÔ'ð 	×ÑÕ r/   c                 ó&  — | j                  «       r�| j                  €&| j                  r3 | j                  | j                  Ž  nt        j
                  «       | _        d | _        d | _        d| _        | j                  «        | j                  «        y y )NF)rr   r   r   rŸ   r    r‚   r   r!   r$   Úmove_into_viewÚon_drag_doner+   s    r-   r‹   zWindowManipulator.stop_dragŠ  s€   € Ø×!Ñ!Ô#à×*Ñ*Ð2à×'Ò'Ø%�D×%Ñ% t×'<Ñ'<Ò=ô /3¯i©i«k�Ô+à&*ˆDÔ#Ø $ˆDÔØ %ˆDÔà×ÑÔ!ð ×ÑÕð# $r/   c                  ó   — y)zU
        User controlled drag initiated, but drag hasn't actually begun yet.
        NrJ   r+   s    r-   rÄ   z#WindowManipulator.on_drag_initiatedž  ó   € ð 	r/   c                  ó   — y)z,
        Moving/resizing has begun.
        NrJ   r+   s    r-   ru   z#WindowManipulator.on_drag_activated¤  rÌ   r/   c                  ó   — y)zW
        User controlled drag ended.
        overload this in derived classes.
        NrJ   r+   s    r-   rÊ   zWindowManipulator.on_drag_doneª  rª   r/   c                 ó,   — t        | j                  «      S )zA Button pressed down on a drag handle, not yet actually dragging )Úboolr   r+   s    r-   rr   z#WindowManipulator.is_drag_initiated±  s   € ä�D×+Ñ+Ó,Ð,r/   c                 ó>   — | j                  «       xr | j                  S )z! Are we actually moving/resizing )rr   r$   r+   s    r-   r¹   z WindowManipulator.is_drag_activeµ  s   € à×%Ñ%Ó'Ò=¨D×,=Ñ,=Ð=r/   c                 ó`   — | j                  «       xr | j                  t        j                  k(  S r1   ©rr   r!   r   re   r+   s    r-   r€   zWindowManipulator.is_moving¹  s%   € Ø×%Ñ%Ó'ÒL¨D×,=Ñ,=ÄÇÁÑ,LÐLr/   c                 ó<   — | j                   t        j                  k(  S r1   )r)   r   re   r+   s    r-   Ú
was_movingzWindowManipulator.was_moving¼  s   € Ø×%Ñ%¬¯©Ñ4Ð4r/   c                 ó`   — | j                  «       xr | j                  t        j                  k7  S r1   rÓ   r+   s    r-   rƒ   zWindowManipulator.is_resizing¿  s%   € Ø×%Ñ%Ó'ÒM¨D×,=Ñ,=Ä&Ç+Á+Ñ,MÐMr/   c                 ó´   — | j                  «       }|rF|j                  «       \  }}| j                  ||«      \  }}||k7  s||k7  r| j                  ||«       yyy)zu
        If the window has somehow ended up off-screen,
        move the always-visible-rect back into view.
        N)rK   r’   r“   rŸ   ©r,   r†   r‡   rˆ   Ú_xÚ_ys         r-   rÉ   z WindowManipulator.move_into_viewÂ  sd   € ð
 ×%Ñ%Ó'ˆÙØ×&Ñ&Ó(‰DˆAˆqØ×(Ñ(¨¨AÓ.‰FˆB�Ø�QŠw˜" š'Ø×!Ñ! " bÕ)ð "ð r/   c                 ó$   — | j                  «        y r1   )rÉ   r	   Úidle_addÚ_do_force_into_viewr+   s    r-   Úforce_into_viewz!WindowManipulator.force_into_viewÎ  s   € Ø×ÑÔØr/   c                 óî   — | j                  «       }|j                  «       \  }}| j                  ||«      \  }}||k7  s||k7  r3|j                  «        | j	                  ||«       |j                  «        yy)z9 Works mostly, but occasionally the window disappears... N)rK   r’   r“   ÚhiderŸ   ÚshowrØ   s         r-   rÝ   z%WindowManipulator._do_force_into_viewÓ  sl   € à×%Ñ%Ó'ˆØ×"Ñ"Ó$‰ˆˆ1Ø×$Ñ$ Q¨Ó*‰ˆˆBØ�Š7�b˜A’gØ�K‰KŒMØ×Ñ˜b "Ô%Ø�K‰K�Mð r/   c                 ón  — | j                  «       }t        dd|j                  «       |j                  «       «      }|j	                  «       }|j                  «       sZ|j                  |j                  kD  r|j                  dz
  |_        |j                  |j                  kD  r|j                  dz
  |_        |S )z?
        Limit the given window rect to fit on screen.
        r   é(   é   )Ú
get_screenr   Ú	get_widthÚ
get_heightÚcopyÚis_emptyr4   r5   )r,   r¤   ÚscreenÚlimitsÚrs        r-   Ú
limit_sizezWindowManipulator.limit_sizeÝ  sˆ   € ð —‘Ó"ˆÜ�a˜˜F×,Ñ,Ó.°×0AÑ0AÓ0CÓDˆØ�I‰I‹KˆØ�‰Ô Ø�s‰s�V—X‘XŠ~Ø—h‘h ‘m�”Ø�s‰s�V—X‘XŠ~Ø—h‘h ‘m�”Øˆr/   c                 óÀ   — |€| j                  «       }|s6| j                  st        | j                  «       «      | _        | j                  }t	        ||||«      \  }}||fS )zq
        Limits the given window position to keep the current
        always_visible_rect fully in view.
        )rZ   r*   Úget_monitor_rectsrå   Úlimit_window_position)r,   r‡   rˆ   Úvisible_rectÚlimit_rectss        r-   r“   z WindowManipulator.limit_positionë  s`   € ð ÐØ×7Ñ7Ó9ˆLáØ×&Ò&Ü&7¸¿¹Ó8IÓ&J�Ô#Ø×-Ñ-ˆKä$ Q¨¨<¸ÓE‰ˆˆ1Ø�!ˆtˆr/   c                 óÂ  — | j                  «       }| j                  «       }| j                  «       }t        |j                  dz  |«      }t        |j
                  dz  |«      }|\  }}|j                  «       \  }	}
}}|D ]Ê  }|t        j                  k(  r||	k\  r||	|z   k  r||
k\  r||
|z   k  r|c S |t        j                  k(  r||k  r|||z
  kD  r||
k\  r||
|z   k  r|c S |t        j                  k(  r||k  r|||z
  kD  r||k  r|||z
  kD  r|c S |t        j                  k(  sŒª||	k\  sŒ°||	|z   k  sŒ¹||k  sŒ¿|||z
  kD  sŒÈ|c S  |D ]�  }|t        j                  k(  r||	|z   k  r||	dz
  k\  r|c S |t        j                  k(  r|||z
  kD  r||dz   k  r|c S |t        j                  k(  r||
|z   k  r|c S |t        j                  k(  sŒ„|||z
  kD  sŒ�|c S  y )Né   rq   )rF   rO   r;   r™   r4   r5   r”   r   r—   r˜   rœ   rš   r�   r›   r–   rž   )r,   rd   Úcanvas_rectrQ   r   r4   r5   r‡   rˆ   r¥   r¦   r§   r¨   rU   s                 r-   rc   z&WindowManipulator.hit_test_move_resizeü  sô  € Ø×0Ñ0Ó2ˆØ×'Ñ'Ó)ˆØ×2Ñ2Ó4ˆä�—‘ Ñ! ?Ó3ˆÜ�—‘ Ñ! ?Ó3ˆà‰ˆˆ1Ø$×/Ñ/Ó1‰ˆˆB��Bð ò 	"ˆFØœ×*Ñ*Ò*Ø˜’7˜q 2¨¡6šzØ˜’7˜q 2¨¡6šzØ!’Màœ×*Ñ*Ò*Ø˜’7˜q 2¨¡6šzØ˜’7˜q 2¨¡6šzØ!’Màœ×*Ñ*Ò*Ø˜’7˜q 2¨¡6šzØ˜’7˜q 2¨¡6šzØ!’Màœ×*Ñ*Ó*Ø˜“7˜q 2¨¡6›zØ˜“7˜q 2¨¡6›zØ!’Mð'	"ð, ò 	"ˆFØœŸ™Ò$Ø�r˜A‘v’: ! r¨A¡v¢+Ø!’MØœŸ™Ò$Ø�r˜A‘v’: ! r¨A¡v¢+Ø!’MØœŸ™Ò%Ø�r˜A‘v’:Ø!’MØœŸ™Ó%Ø�r˜A‘v“:Ø!’Mð	"ð r/   c                 óØ   — | j                  «       }|j                  «       }|€|j                  ||«       y t        |d«      r|j	                  ||||«       y |j	                  ||||«       y )NÚmove_resize)rK   r®   ÚmoveÚhasattrr÷   )r,   r‡   rˆ   r4   r5   r†   Úgdk_wins          r-   rŸ   zWindowManipulator._move_resize.  sg   € à×%Ñ%Ó'ˆØ×#Ñ#Ó%ˆØˆ9ð
 �K‰K˜˜1Õô �v˜}Ô-Ø×"Ñ" 1 a¨¨AÕ.à×#Ñ# A q¨!¨QÕ/r/   c                 óž  — | j                  «       }|}|}|j                  «       }|j                  «       }|d   |j                  «       kD  r#||j                  «       k  r|j                  «       }|d   |d   z   |j	                  «       k  r)||d   z   |j	                  «       kD  r|j	                  «       }|d   |j                  «       kD  r#||j                  «       k  r|j                  «       }|d   |d   z   |j                  «       k  r)||d   z   |j                  «       kD  r|j	                  «       }||k7  s||k7  r|j                  ||«       yy)aQ  
        Compiz and potentially other window managers silently ignore
        moves outside of some screen edges. When hitting the edge at
        high speed, onboard gets stuck some distance away from it.
        Fix this by inserting an intermediate move right to the edge.
        Does not help with the edge below unity bar.
        r   rq   N)Úget_screen_limitsr’   r•   ÚleftÚrightÚtopÚbottomrø   )	r,   r†   r‡   rˆ   rë   Ú
one_more_xÚ
one_more_yÚposÚsizes	            r-   Ú_insert_edge_movez#WindowManipulator._insert_edge_move@  s&  € ð ×'Ñ'Ó)ˆØˆ
Øˆ
Ø×!Ñ!Ó#ˆØ�‰Ó ˆàˆq‰6�F—K‘K“MÒ!Ø�F—K‘K“MÒ!ØŸ™›ˆJØˆq‰6�D˜‘GÑ˜fŸl™l›nÒ,Ø�D˜‘GÑ˜fŸl™l›nÒ,ØŸ™›ˆJØˆq‰6�F—J‘J“LÒ Ø�F—J‘J“LÒ ØŸ™›ˆJØˆq‰6�D˜‘GÑ˜fŸm™m›oÒ-Ø�D˜‘GÑ˜fŸm™m›oÒ-ØŸ™›ˆJà˜Š?˜j¨AšoØ�K‰K˜
 JÕ/ð .r/   ©F)Tr1   r�   )3Ú__name__Ú
__module__Ú__qualname__Ú__doc__r.   r6   r8   r;   r>   r@   rF   rH   rK   rO   rR   rV   rX   rZ   r^   ra   ro   r~   rt   rŒ   rs   rj   r‘   rµ   r·   r¯   rf   r¾   rh   r¼   r‹   rÄ   ru   rÊ   rr   r¹   r€   rÕ   rƒ   rÉ   rÞ   rÝ   rí   r“   rc   rŸ   r  rJ   r/   r-   r   r   +   sø   „ ñò )ò8&ò$ò$ò&ò+ò5ò%òò"ò%ò%òòò!ò!óó*-%ò^>ò6ò4*òlòó$ò&$òó3ò
ó3ó
!òB ò(òòò-ò>òMò5òNò
*ò4ò
òóò"0ód0ó$0r/   r   c                   ó8   — e Zd ZdZ G d„ d«      Z G d„ d«      Zy)ÚOrientationz enum for screen orientation c                   ó   — e Zd Zy)úOrientation.LANDSCAPEN©r  r  r	  rJ   r/   r-   Ú	LANDSCAPEr  b  ó   … r/   r  c                   ó   — e Zd Zy)úOrientation.PORTRAITNr  rJ   r/   r-   ÚPORTRAITr  c  r  r/   r  N)r  r  r	  r
  r  r  rJ   r/   r-   r  r  _  s   „ Ù'çÑßÒr/   r  c                   óp   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚWindowRectTrackera  
    Keeps track of the window rectangle when moving/resizing.
    Gtk only updates the position and size asynchrounously on
    configure events and hidden windows return invalid values.
    Auto-show et al need valid values from get_position and
    get_size at all times.
    c                 ó<   — d | _         d | _        d| _        d| _        y )N©r   r   F)Ú_window_rectÚ_originÚ_client_offsetÚ_override_redirectr+   s    r-   r.   zWindowRectTracker.__init__n  s!   € Ø ˆÔØˆŒØ$ˆÔØ"'ˆÕr/   c                  ó   — y r1   rJ   r+   s    r-   ÚcleanupzWindowRectTracker.cleanupt  s   € Ør/   c                 ó  — | j                  «       }|�rzt        j                  j                  | «      }t        j                  j	                  | «      }| j                  «       j                  «       }t        |«      dk(  r|dd }t        j                  t        j                  «      r&t        j                  dj                  |||«      «       | j                  |«      }t        j                   ||«      | _        || _        |d   |d   z
  |d   |d   z
  f| _        | j)                  «       | _        t        j                  t        j                  «      r;t        j                  dj                  || j&                  | j*                  «      «       yyy)zw
        Call this on configure event, the only time when
        get_position, get_size, etc. can be trusted.
        é   rq   Nz/update_window_rect1: pos {}, size {}, origin {}r   zDupdate_window_rect2: pos {}, client_offset {}, screen_orientation {})Ú
is_visibler
   ÚWindowr’   r•   r®   Ú
get_originÚlenÚ_loggerÚisEnabledForÚloggingÚDEBUGÚdebugÚformatÚ_apply_window_scaling_factorr   rÃ   r  r  r  Úget_screen_orientationÚ_screen_orientation)r,   Úvisibler  r  Úorigins        r-   Úupdate_window_rectz$WindowRectTracker.update_window_rectw  sG  € ð
 —/‘/Ó#ˆÚÜ—:‘:×*Ñ*¨4Ó0ˆCÜ—:‘:×&Ñ& tÓ,ˆDØ—_‘_Ó&×1Ñ1Ó3ˆFÜ�6‹{˜aÒØ  ˜�ä×#Ñ#¤G§M¡MÔ2Ü—‘ÐOß ™&  d¨FÓ3ô5à×3Ñ3°CÓ8ˆCä $× 7Ñ 7¸¸TÓ BˆDÔØ!ˆDŒLØ#)¨!¡9¨s°1©vÑ#5°v¸a±yÀ3ÀqÁ6Ñ7IÐ"JˆDÔØ'+×'BÑ'BÓ'DˆDÔ$ä×#Ñ#¤G§M¡MÔ2Ü—‘ð 6ç%™v cØ&*×&9Ñ&9Ø&*×&>Ñ&>ó @õAð 3ð# r/   c                 óF   — t         j                  j                  | ||«       y r1   )r
   r"  rø   )r,   r‡   rˆ   s      r-   rø   zWindowRectTracker.move•  s   € Ü�
‰
�‰˜˜a Õ#r/   c                 óF   — t         j                  j                  | ||«       y r1   )r
   r"  Úresizer3   s      r-   r3  zWindowRectTracker.resize˜  s   € Ü�
‰
×Ñ˜$  1Õ%r/   c                 óR   — | j                  «       }|r|j                  ||||«       y y r1   )r®   r÷   )r,   r‡   rˆ   r4   r5   Úwins         r-   r÷   zWindowRectTracker.move_resize›  s(   € Ø�o‰oÓˆÙØ�O‰O˜A˜q ! QÕ'ð r/   c                 ó¶   — | j                   €2t        j                  j                  | «      }| j	                  |«      }|S | j                   j                  «       }|S r1   )r  r
   r"  r’   r+  )r,   r  s     r-   r’   zWindowRectTracker.get_position   sT   € Ø×ÑÐ$Ü—*‘*×)Ñ)¨$Ó/ˆCØ×3Ñ3°CÓ8ˆCð ˆ
ð ×#Ñ#×0Ñ0Ó2ˆCØˆ
r/   c                 óŒ   — | j                   €t        j                  j                  | «      S | j                   j                  «       S r1   )r  r
   r"  r•   r+   s    r-   r•   zWindowRectTracker.get_size¨  s8   € Ø×ÑÐ$Ü—:‘:×&Ñ& tÓ,Ð,à×$Ñ$×-Ñ-Ó/Ð/r/   c                 ó¢   — | j                   €8| j                  «       }|r%|j                  «       }t        |«      dk(  r|dd  }|S y| j                   S )Nr   rq   r   )r  r®   r#  r$  )r,   r5  r/  s      r-   r#  zWindowRectTracker.get_origin®  sP   € Ø�<‰<ÐØ—/‘/Ó#ˆCÙØŸ™Ó)�Ü�v“; !Ò#Ø# A B˜Z�FØ�Øà—<‘<Ðr/   c                 ó   — | j                   S r1   )r  r+   s    r-   Úget_client_offsetz#WindowRectTracker.get_client_offsetº  s   € Ø×"Ñ"Ð"r/   c                 ó   — | j                   S r1   )r  r+   s    r-   Úget_rectzWindowRectTracker.get_rect½  s   € Ø× Ñ Ð r/   c                 ó   — | j                   S r1   )r  r+   s    r-   Úget_override_redirectz'WindowRectTracker.get_override_redirectÀ  s   € Ø×&Ñ&Ð&r/   c                 óP   — || _         | j                  «       j                  d«       y )NT)r  r®   Úset_override_redirect)r,   Úvalues     r-   r@  z'WindowRectTracker.set_override_redirectÃ  s   € Ø"'ˆÔØ�‰Ó×/Ñ/°Õ5r/   c                 óh   — | j                  «       }|r	 |j                  «       S y # t        $ r Y y w xY wr1   )r®   Úget_scale_factorrC   )r,   rú   s     r-   rC  z"WindowRectTracker.get_scale_factorÇ  sA   € Ø—/‘/Ó#ˆÙðØ×/Ñ/Ó1Ð1ð øô "ò ØØðús   ”% ¥	1°1c                 ól   — | j                   r'| j                  «       }|�d|z  }|d   |z  |d   |z  f}|S )zR
        Gdk doesn't scale position of override redirect windows (Trusty)
        ç      ð?r   rq   )r  rC  )r,   ÚvaluesÚscales      r-   r+  z.WindowRectTracker._apply_window_scaling_factorÐ  sJ   € ð ×"Ò"Ø×)Ñ)Ó+ˆEØ�=Ø˜e™�Ø  ™) eÑ+¨V°A©Y¸Ñ->Ð?�Øˆr/   c                 ó¤   — | j                  «       }|j                  «       |j                  «       k\  rt        j                  S t        j
                  S )a  
        Current orientation of the screen (tablet rotation).
        Only the aspect ratio is taken into account at this time.
        This appears to cover more cases than looking at monitor rotation,
        in particular with multi-monitor screens.
        )rå   ræ   rç   r  r  r  ©r,   rê   s     r-   r,  z(WindowRectTracker.get_screen_orientationÛ  sB   € ð —‘Ó"ˆØ×ÑÓ ×!2Ñ!2Ó!4Ò4Ü×(Ñ(Ð(ä×'Ñ'Ð'r/   N)r  r  r	  r
  r.   r  r0  rø   r3  r÷   r’   r•   r#  r:  r<  r>  r@  rC  r+  r,  rJ   r/   r-   r  r  f  sX   „ ñò(òòAò<$ò&ò(ò
ò0ò
 ò#ò!ò'ò6òò	ó(r/   r  c                   ób   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zdd„Z	d„ Z
dd
„Zd„ Zd„ Zd„ Zd„ Zd„ Zy	)ÚWindowRectPersistz4
    Save and restore window position and size.
    c                 ó²   — t         j                  | «       d | _        t        «       | _        | j                  «       }|j                  d| j                  «       y )Nzsize-changed)r  r.   r-  r   Ú_save_position_timerrå   ÚconnectÚon_screen_size_changedrI  s     r-   r.   zWindowRectPersist.__init__í  sD   € Ü×"Ñ" 4Ô(Ø#'ˆÔ Ü$)£GˆÔ!ð —‘Ó"ˆØ�‰�~ t×'BÑ'BÕCr/   c                 ó8   — | j                   j                  «        y r1   )rM  Úfinishr+   s    r-   r  zWindowRectPersist.cleanupö  s   € Ø×!Ñ!×(Ñ(Õ*r/   c                 ó@   — t         j                  j                  | «      S )z! This is overloaded in KbdWindow )r
   r"  Úget_visibler+   s    r-   r!  zWindowRectPersist.is_visibleù  s   € ä�z‰z×%Ñ% dÓ+Ð+r/   c                 ó2   — t        d| j                  |«       y)z! detect screen rotation (tablets)g      ø?N)r   Úon_screen_size_changed_delayedrI  s     r-   rO  z(WindowRectPersist.on_screen_size_changedý  s   € ô 	ˆc�4×6Ñ6¸Õ?r/   c                 ó$   — | j                  «        y r1   )Úrestore_window_rectrI  s     r-   rU  z0WindowRectPersist.on_screen_size_changed_delayed  s   € Ø× Ñ Õ"r/   c                 ó¬  — | j                   j                  «        | j                  «       }| j                  |«      }|| _        || _        t        j                  dj                  ||¬«      «       | j                  |«      }|| _        |rM| j                  |j                  |j                  «       | j                  |j                  |j                  «       n<| j!                  |j                  |j                  |j                  |j                  «       |r@|j#                  «       | _        |j%                  «       | _        | j                  «       | _        yy)z3
        Restore window size and position.
        z)restore_window_rect {rect}, {orientation}©r¤   ÚorientationN)rM  rQ  r,  Úread_window_rectr-  r  r%  r)  r*  Úon_restore_window_rectÚset_default_sizer4   r5   rø   r‡   rˆ   r÷   rè   Úleft_topr  )r,   ÚstartuprZ  r¤   s       r-   rW  z%WindowRectPersist.restore_window_rect	  s  € ð 	×!Ñ!×(Ñ(Ô*à×1Ñ1Ó3ˆØ×$Ñ$ [Ó1ˆà#.ˆÔ Ø ˆÔÜ�‰ÐAß‘v T¸�vÓEô	Gð
 ×*Ñ*¨4Ó0ˆØ ˆÔñ ð ×!Ñ! $§&¡&¨$¯&©&Ô1Ø�I‰I�d—f‘f˜dŸf™fÕ%à×Ñ˜TŸV™V T§V¡V¨T¯V©V°T·V±VÔ<ñ
 Ø $§	¡	£ˆDÔà $§¡£ˆDŒLØ'+×'BÑ'BÓ'DˆDÕ$ð	 r/   c                 ó   — |S r1   rJ   ©r,   r¤   s     r-   r\  z(WindowRectPersist.on_restore_window_rect1  rL   r/   Nc                 óÎ   — |€| j                   }|€| j                  }| j                  |«      }| j                  ||«       t        j                  dj                  ||¬«      «       y)z0
        Save window size and position.
        Nz&save_window_rect {rect}, {orientation}rY  )r-  r  Úon_save_window_rectÚwrite_window_rectr%  r)  r*  ©r,   rZ  r¤   s      r-   Úsave_window_rectz"WindowRectPersist.save_window_rect4  se   € ð ÐØ×2Ñ2ˆKØˆ<Ø×$Ñ$ˆDð ×'Ñ'¨Ó-ˆà×Ñ˜{¨DÔ1ä�‰Ð>ß‘v 4°[�vÓAõ	Cr/   c                 ó   — |S r1   rJ   ra  s     r-   rc  z%WindowRectPersist.on_save_window_rectF  rL   r/   c                 ó   — t        «       ‚)z\
        Read orientation dependent rect.
        Overload this in derived classes.
        ©ÚNotImplementedErrorre  s      r-   r[  z"WindowRectPersist.read_window_rectI  ó   € ô
 "Ó#Ð#r/   c                 ó   — t        «       ‚)z]
        Write orientation dependent rect.
        Overload this in derived classes.
        ri  re  s      r-   rd  z#WindowRectPersist.write_window_rectP  rk  r/   c                 óŒ   — | j                   j                  d| j                  | j                  «       | j	                  «       «       y)zõ
        Trigger saving position and size to gsettings
        Delay this a few seconds to avoid excessive disk writes.

        Remember the current rect and rotation as the screen may have been
        rotated when the saving happens.
        é   N)rM  Ústartrf  r,  r<  r+   s    r-   Ústart_save_position_timerz+WindowRectPersist.start_save_position_timerW  s8   € ð 	×!Ñ!×'Ñ'¨Ø(,×(=Ñ(=Ø(,×(CÑ(CÓ(EØ(,¯©«õ	9r/   c                 ó8   — | j                   j                  «        y r1   )rM  Ústopr+   s    r-   Ústop_save_position_timerz*WindowRectPersist.stop_save_position_timerd  s   € Ø×!Ñ!×&Ñ&Õ(r/   r  r�   )r  r  r	  r
  r.   r  r!  rO  rU  rW  r\  rf  rc  r[  rd  rp  rs  rJ   r/   r-   rK  rK  é  sM   „ ñòDò+ò,ò@ò#ó&EòPóCò$ò$ò$ò9ó)r/   rK  c                 ó®   — | j                  «       }|rCt        |d«      r6|j                  «       }t        j                  «       j                  |dd«       yyy)a-  
    Set custom X window property to tell unity 3D this is an on-screen
    keyboard that wants to be raised on top of dash. See LP 739812, 915250.
    Since onboard started detecting dash itself this isn't really needed
    for unity anymore. Leave it anyway, it may come in handy in the future.
    Úget_xidÚONSCREEN_KEYBOARDrq   N)r®   rù   ru  ÚoskÚUtilÚset_x_property)r†   rú   Úxids      r-   Úset_unity_propertyr{  h  sN   € ð ×ÑÓ!€GÙÜ�7˜IÔ&Ø—/‘/Ó#ˆCÜ�H‰H‹J×%Ñ% cÐ+>ÀÕBð 'ð r/   c                   ó>   — e Zd ZdZdZdZd„ Zd„ Zd„ Zd„ Z	d
d„Z
d	„ Zy)ÚDwellProgressé   NrE  c                 ó   — | j                   d uS r1   ©Údwell_start_timer+   s    r-   Úis_dwellingzDwellProgress.is_dwelling€  s   € Ø×$Ñ$¨DÐ0Ð0r/   c                 ó^   — t        j                   «       | j                  | j                  z   kD  S r1   )r‚   r�  Údwell_delayr+   s    r-   Úis_donezDwellProgress.is_doneƒ  s$   € Ü�y‰y‹{˜T×2Ñ2°T×5EÑ5EÑEÑEÐEr/   c                 ó6   — t        j                   «       | _        y r1   )r‚   r�  r+   s    r-   Ústart_dwellingzDwellProgress.start_dwelling†  s   € Ü $§	¡	£ˆÕr/   c                 ó   — d | _         y r1   r€  r+   s    r-   Ústop_dwellingzDwellProgress.stop_dwelling‰  s
   € Ø $ˆÕr/   c                 óÆ  — | j                  «       rÑ| j                  dk  r	 | j                  dk\  r| j                  ||||«       y |j                  «         |j                  |j                  «       Ž  |j                  «        |j                  «        | j                  ||||«       |j                  «        |j                  | j                  «       |j                  «        y y )Ng        rE  )r‚  ÚopacityÚ_draw_dwell_progressÚsaveÚ	rectangleÚintÚclipÚ
push_groupÚpop_group_to_sourceÚpaint_with_alphaÚrestore)r,   Úcontextr¤   ÚrgbaÚrgba_bgs        r-   ÚdrawzDwellProgress.drawŒ  s²   € Ø×ÑÔØ�|‰|˜sÒ"ØØ�|‰|˜sÒ"Ø×)Ñ)¨'°4¸¸wÕGà—‘”Ø!�×!Ñ! 4§8¡8£:Ñ.Ø—‘”Ø×"Ñ"Ô$à×)Ñ)¨'°4¸¸wÔGà×+Ñ+Ô-Ø×(Ñ(¨¯©Ô6Ø—‘Õ!ð r/   c                 óê  — |j                  «       \  }}t        |j                  |j                  «      dz  }t         dz  }t        j
                  «       | j                  z
  | j                  z  }	t        |	d«      }	|	t        z  dz  }
|r] |j                  |Ž  |j                  ||«       |j                  |||ddt        z  «       |j                  «        |j                  «        |j                  ||«       |j                  ||||||
z   «       |j                  «         |j                  |Ž  |j                  «        |j                  dddd«       |j                  d«       |j                  «        y )Ng       @rE  r   rô   rq   )Ú
get_centerr™   r4   r5   r   r‚   r�  r„  Úset_source_rgbaÚmove_toÚarcÚ
close_pathÚfillÚfill_preserveÚset_line_widthÚstroke)r,   r•  r¤   r–  r—  ÚxcÚycÚradiusÚalpha0ÚkÚalphas              r-   rŒ  z"DwellProgress._draw_dwell_progressž  s7  € Ø—_‘_Ó&‰FˆB�ä˜Ÿ™ §¡Ó(¨3Ñ.ˆFä�S˜3‘YˆFÜ—‘“˜t×4Ñ4Ñ4¸×8HÑ8HÑHˆAÜ�A�s“ˆAØœ‘F˜S‘LˆEáØ'�×'Ñ'¨Ñ1Ø—‘  BÔ'Ø—‘˜B  F¨A¨q´2©vÔ6Ø×"Ñ"Ô$Ø—‘”à�O‰O˜B Ô#Ø�K‰K˜˜B ¨°¸±Ô?Ø×ÑÔ à#ˆG×#Ñ# TÑ*Ø×!Ñ!Ô#à×#Ñ# A q¨!¨QÔ/Ø×"Ñ" 1Ô%Ø�N‰NÕr/   ))rq   r   r   g      è?N)r  r  r	  r„  r�  r‹  r‚  r…  r‡  r‰  r˜  rŒ  rJ   r/   r-   r}  r}  v  s5   „ ð €Kð Ðà€Gò1òFò,ò%ó"ó$r/   r}  c                 ó|  — |}|��´|j                  «       }|j                  «       }|xj                  | z  c_        |xj                  |z  c_        d}d}|D �].  }|j                  «       }	t	        |	j                  |j                  «       «      |	_        t        |	j                  |j                  «       |	j                  z
  «      |	_        t	        |	j                  |j                  «       «      |	_        t        |	j                  |j                  «       |	j                  z
  «      |	_        |	j                  «       \  }
}|j                  |	j                  z
  |j                  |	j                  z
  }}||z  ||z  z   }|�||k  s�Œ+|}|	}�Œ1 |j                  |j                  z
  } |j                  |j                  z
  }| |fS )z]
    Limits the given window position to keep the
    always_visible_rect fully in view.
    N)r�  rè   r‡   rˆ   r�   rý   r™   rþ   r4   rÿ   r   r5   rš  )r‡   rˆ   Úalways_visible_rectrò   rì   ÚrsÚdminÚrsminrë   ÚrscÚcxÚcyrz   r{   r|   s                  r-   rð   rð   »  s]  € ð 	€Aà�}Ø�E‰E‹Gˆð �V‰V‹XˆØ
�Š�‰	�Ø
�Š�‰	�àˆØˆØ!ó 	ˆFà—'‘'“)ˆCÜ˜Ÿ™˜vŸ{™{›}Ó-ˆCŒEÜ˜Ÿ™˜vŸ|™|›~°·±Ñ5Ó6ˆCŒEÜ˜Ÿ™˜vŸz™z›|Ó,ˆCŒEÜ˜Ÿ™˜vŸ}™}›°·±Ñ6Ó7ˆCŒEð —^‘^Ó%‰FˆB�Ø—T‘T˜CŸE™E‘\ 2§4¡4¨#¯%©%¡<�ˆBØ�R‘˜"˜r™'Ñ!ˆAØˆ|˜q 4œxØ�Ø’ð	ð  �G‰G�a—c‘c‰MˆØ�G‰G�a—c‘c‰Mˆàˆaˆ4€Kr/   c           	      óÈ  — g }| rvt        | j                  «       «      D ]X  }| j                  |«      }|j                  t	        |j
                  |j                  |j                  |j                  «      «       ŒZ |S t        j                  «       }t	        j                  |j                  «       |j                  «       |j                  «       f«      }|j                  |«       |S )zv
    Screen limits, one rect per monitor. Monitors may have
    different sizes and arbitrary relative positions.
    )ÚrangeÚget_n_monitorsÚget_monitor_geometryÚappendr   r‡   rˆ   ÚwidthÚheightr   rÁ   rÃ   r’   ræ   rç   )rê   ÚrectsÚirì   rÅ   s        r-   rï   rï   ã  s½   € ð
 €EÙÜ�v×,Ñ,Ó.Ó/ò 	<ˆAØ×+Ñ+¨AÓ.ˆAØ�L‰Lœ˜aŸc™c 1§3¡3¨¯©°·±Ó:Õ;ð	<ð €Lô	 ×-Ñ-Ó/ˆÜ×#Ñ# G×$8Ñ$8Ó$:Ø!(×!2Ñ!2Ó!4°g×6HÑ6HÓ6JÐ KóMˆà�‰�QŒØ€Lr/   c                 óJ  — | j                  «       }|r†|j                  |j                  |j                  «      \  }}|j                  |j                  |j                  z   |j                  |j
                  z   «      \  }}t        j                  ||||«      }|S t        «       }|S )zH
    Convert rect in canvas coordinates to root window coordinates.
    )r®   Úget_root_coordsr‡   rˆ   r4   r5   r   Úfrom_extents)r†   r¤   rú   r¥   r¦   r§   r¨   s          r-   Úcanvas_to_root_window_rectr½  ô  s�   € ð ×ÑÓ!€GÙØ×(Ñ(¨¯©°·±Ó8‰ˆˆBØ×(Ñ(¨¯©°$·&±&©Ø)-¯©°$·&±&©ó:‰ˆˆBä× Ñ   R¨¨RÓ0ˆð €Kô ‹vˆà€Kr/   c                 ó^   — | j                  «       }|r |j                  |Ž }|S  |dd«       |S )zI
    Convert point in canvas coordinates to root window coordinates.
    r   )r®   r»  )r†   rd   rú   s      r-   Úcanvas_to_root_window_pointr¿    s>   € ð ×ÑÓ!€GÙØ'�×'Ñ'¨Ð/ˆð €Lñ 	ˆa�ŒØ€Lr/   c                 ó8  — | j                  «       }| j                  «       }|rx|rv|j                  |«      }|j                  |«      }|j                  |j
                  f}|j                  |«      |j                  |«      f}d}|dk(  rd}||fS |dk(  rd}d}||fS y)z6 Geometry and physical size of the monitor at window. Nr   r  rq   )i   i   )é–   é^   )r  r  )r®   rå   Úget_monitor_at_windowr´  r¶  r·  Úget_monitor_width_mmÚget_monitor_height_mm)r†   rú   rê   Úmonitorrì   r  Úsize_mmÚdevices           r-   Úget_monitor_dimensionsrÉ    s·   € à×ÑÓ!€GØ×ÑÓ €FÙ‘6Ø×.Ñ.¨wÓ7ˆØ×'Ñ'¨Ó0ˆØ—‘˜Ÿ™Ð"ˆØ×.Ñ.¨wÓ7Ø×/Ñ/°Ó8ð:ˆð ˆà�QŠ;ØˆGð
 �Wˆ}Ðð	 �qŠ[ØˆDØˆGà�Wˆ}Ðàr/   c                 óä   — t        | «      \  }}|d   dkD  rR|d   dkD  rJ|d   dkD  rB|d   dkD  r:|d   r|d   |d   z  |d   z  n|d   }|d   r|d   |d   z  |d   z  n|d   }||fS |\  }}||fS )zG
    Convert a physical size in mm to pixels of windows's monitor,
    r   rq   )rÉ  )r†   rÇ  Úfallback_sizeÚszÚsz_mmr4   r5   s          r-   Úphysical_to_monitor_pixel_sizerÎ  &  s»   € ô ' vÓ.�I€BˆØ	ˆ!�uˆq‚y�R˜‘U˜Q’YØˆQ�x�!‚|˜˜a™ 1šà�QŠxð ˆq‰E�G˜A‘JÑ  q¡Ò)Ø*¨1Ñ-ð 	
ð �QŠxð ˆq‰E�G˜A‘JÑ  q¡Ò)Ø*¨1Ñ-ð 	
ð ˆaˆ4€Kð ‰ˆˆ1Øˆaˆ4€Kr/   c                 óÔ   — t        j                  t         j                  j                  | t         j                  j
                  ¬«      }|j                  «        |j                  «        y)z Show an error dialog )Úmessage_typeÚmessage_formatÚbuttonsN)r
   ÚMessageDialogÚMessageTypeÚERRORÚButtonsTypeÚOKÚrunÚdestroy)Úerror_stringÚ	error_dlgs     r-   Úshow_error_dialogrÜ  5  sG   € ô ×!Ñ!¬s¯©×/DÑ/DØ1=Ü*-¯/©/×*<Ñ*<ô>€Ið ‡M�M„OØ×ÑÕr/   c                 ó,  ‡— t        j                  t         j                  j                  t         j                  j
                  ¬«      Š|r‰j                  |«       ‰j                  | «       t        j                  «       }|j                  dˆfd„«       ‰j                  «       j                  |«       ‰j                  «        ‰j                  «       }|t         j                  j                  k(  r|j!                  «       nd }‰j#                  «        |S )N)rÐ  rÒ  Úactivatec                 óV   •— ‰j                  t        j                  j                  «      S r1   )Úresponser
   ÚResponseTyper×  )ÚeventÚquestion_dialogs    €r-   ú<lambda>z(show_ask_string_dialog.<locals>.<lambda>E  s"   ø€ Ø× Ñ ¤×!1Ñ!1×!4Ñ!4Ó5ð r/   )r
   rÓ  rÔ  ÚQUESTIONrÖ  Ú	OK_CANCELÚset_transient_forÚ
set_markupÚEntryrN  Úget_message_areaÚaddÚshow_allrØ  rá  r×  Úget_textrÙ  )ÚquestionÚparentÚentryrà  Útextrã  s        @r-   Úshow_ask_string_dialogrò  >  sÍ   ø€ Ü×'Ñ'´S·_±_×5MÑ5MÜ03·±×0IÑ0IôK€OáØ×)Ñ)¨&Ô1Ø×Ñ˜xÔ(Ü�I‰I‹K€EØ	‡M�M�*ó 6ô 7à×$Ñ$Ó&×*Ñ*¨5Ô1Ø×ÑÔØ×"Ñ"Ó$€HØ'¬3×+;Ñ+;×+>Ñ+>Ò>ˆ5�>‰>ÔÀD€DØ×ÑÔØ€Kr/   c                 ó¤  — |€t        d«      }t        j                  t        j                  j                  | |t        j
                  j                  ¬«      }|r|j                  |«       |r)|j                  t        j                  j                  «       |j                  «       }|j                  «        |t        j                  j                  k(  S )zG
    Show this dialog to ask confirmation before executing a task.
    ÚOnboard)rÐ  rñ  ÚtitlerÒ  )Ú_r
   rÓ  rÔ  rå  rÖ  ÚYES_NOrç  Úset_positionÚWindowPositionÚCENTERrØ  rÙ  rá  ÚYES)rî  rï  Úcenterrõ  Údlgrà  s         r-   Úshow_confirmation_dialogrþ  N  sœ   € ð €}ä�)“ˆÜ
×
Ñ
¬¯©×)AÑ)AØ!)Ø"'Ü$'§O¡O×$:Ñ$:ô<€Cñ Ø×Ñ˜fÔ%áØ×Ñœ×+Ñ+×2Ñ2Ô3à�w‰w‹y€HØ‡K�K„MØ”s×'Ñ'×+Ñ+Ñ+Ð+r/   c                 ó  — t        j                  t         j                  j                  t	        d«      t	        d«      ¬«      }|r?|j                  t        j                  dt         j                  j                  ¬«      «       n>|j                  t        j                  dt         j                  j                  ¬«      «       dj                  | «      }|t	        d«      z  }|j                  |«       |j                  t	        d	«      t         j                  j                  «       |j                  t	        d
«      t         j                  j                  «      j                  «        |j!                  dt"        ||«       |j%                  «        y)z+
    Show a "New Input Device" dialog.
    zNew Input Devicez'Onboard has detected a new input device)rÐ  rõ  rñ  zinput-mouse)Ú	icon_nameÚ	icon_sizezinput-keyboardz<i>{}</i>

z5Do you want to use this device for keyboard scanning?Ú_Cancelz
Use devicerà  N)r
   rÓ  rÔ  ÚOTHERrö  Ú	set_imageÚImageÚIconSizeÚDIALOGr*  Úformat_secondary_markupÚ
add_buttonrá  ÚCANCELÚACCEPTÚgrab_defaultrN  Ú _show_new_device_dialog_responserì  )ÚnameÚconfig_stringÚ
is_pointerÚcallbackÚdialogÚ	secondarys         r-   Úshow_new_device_dialogr  c  s*  € ô ×Ñ¬C¯O©O×,AÑ,AÜ%&Ð'9Ó%:Ü$%Ð&OÓ$PôR€Fñ Ø×ÑœŸ™¨]Ü-0¯\©\×-@Ñ-@ôBõ 	Cð 	×ÑœŸ™Ð-=Ü-0¯\©\×-@Ñ-@ôBô 	Cð !×'Ñ'¨Ó-€IØ”ÐJÓKÑK€Ià
×"Ñ" 9Ô-ð ×Ñ”a˜	“l¤C×$4Ñ$4×$;Ñ$;Ô<Ø
×Ñ”a˜“o¤s×'7Ñ'7×'>Ñ'>Ó?×LÑLÔNØ
‡N�N�:Ô?Ø˜]ô,à
‡O�OÕr/   c                 ón   — |t         j                  j                  k(  r ||«       | j                  «        y)z- Callback for the "New Input Device" dialog. N)r
   rá  r  rÙ  )r  rà  r  r  s       r-   r  r  ~  s(   € à”3×#Ñ#×*Ñ*Ò*Ù�ÔØ
‡N�NÕr/   c                  óp   — t        t        j                  t        j                  «      } | t        dd«      k  S )z% Gtk from 3.14 removes resize grips. r   é   )r   r
   ÚMAJOR_VERSIONÚMINOR_VERSION)Úgtk_versions    r-   Úgtk_has_resize_grip_supportr  „  s+   € äœ#×+Ñ+¬S×->Ñ->Ó?€KØœ  B›Ñ'Ð'r/   r1   )r  )NFN)/r
  Ú
__future__r   r   r   r‚   Úmathr   r   ÚOnboard.Versionr   Úgi.repositoryr	   r
   r   ÚOnboard.utilsr   r   ÚOnboard.Timerr   ÚOnboard.definitionsr   r   ÚOnboard.oskrw  r'  Ú	getLoggerr%  Úobjectr   r  r  rK  r{  r}  rð   rï   r½  r¿  rÉ  rÎ  rÜ  rò  rþ  r  r  r  rJ   r/   r-   ú<module>r&     sÐ   ðñ( .ç AÑ Aã ß å /Ù Ô ß (Ñ (ç 'Ý ß 6å ó Ø
ˆ'×
Ñ
˜MÓ
*€ôq0˜ô q0÷hñ ÷@(ñ @(ôF|)Ð)ô |)ò~CôB�Fô BóJ&òPò"ò	òó0òóó ,ò*ò6ó(r/   