ó
ñKXPc           @   s]  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l 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 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d d „ Z" d d „ Z# d S(   iÿÿÿÿNc          C   sp   t  d t j t j ƒ t t j ƒ r= t j d t j d f Sd GHt j j ƒ  }  |  j	 d ƒ } | j
 | j f S(   s   Get Desktop Width and Heightt   _NET_WORKAREAi   i   sH   The WM does not set _NET_WORKAREA properly, x-tile may not work properlyi    (   t   get_propertyt   globt   roott   XA_CARDINALt   boolt   ret_pointert   gtkt   gdkt   screen_get_defaultt   get_monitor_geometryt   widtht   height(   t   screent   rect(    (    s   modules/support.pyt   get_desktop_width_n_height    s     c         C   sW   t  | ƒ \ } } } } } | d k  sK | |  k sK | d k  sK | | k rO t St Sd S(   sI   Check the Window to be in the Current Viewport assuming Compiz is Runningi    N(   t   get_geomt   Falset   True(   t   desktop_widtht   desktop_heightt   win_idt   xt   yR   R   R   (    (    s   modules/support.pyt   is_window_in_curr_viewport)   s    0 c          C   sx  t  d t j t j ƒ t t j ƒ t k ro t  d t j t j ƒ t t j ƒ t k r_ d GHt St j d }  n t j d }  t  d |  t j ƒ t t j ƒ t k rØ t  d |  t j	 ƒ t t j ƒ t k rØ d GHt Sn  d } t
 } d } xn | rZt j | } xJ t d ƒ D]< } | d | ?d @} | d k r;t } Pn  | d	 | 7} qW| d
 7} qí Wd G| GH| d k rtt
 St S(   s    Return True if Compiz is runningt   _NET_SUPPORTING_WM_CHECKs   no 1!i    t   _NET_WM_NAMEs   no 2!t    i   iÿ   s   %ci   s   WM =t   Compiz(   R   R   R   t	   XA_WINDOWR   R   R   R   t   str_atomt	   XA_STRINGR   t   range(   t
   sup_windowt   bufft
   keep_goingt   it
   eightcharst   jt	   curr_char(    (    s   modules/support.pyt   is_compiz_running/   s<    		 c         C   sx   t  j s t St |  ƒ \ } } } } } | t  j d d k rt | t  j d d k rt t |  ƒ rt t |  ƒ rt t St S(   s)   Is this a candidate Compiz Desktop windowi    i   i   (   R   R(   R   R   t   monitors_areast   is_window_Hmaxt   is_window_VmaxR   (   t   winR   R   t   wt   ht   r(    (    s   modules/support.pyt   is_candidate_compiz_desktopQ   s    	 c   
      C   sp  t  j ƒ  } t  j ƒ  } t  j ƒ  } t  j ƒ  } t j j t j |  t  j | ƒ t  j | ƒ t  j | ƒ t  j | ƒ ƒ t j | j	 k r‘ | }  n  t
 j ƒ  } t j j t j |  t  j | ƒ ƒ t d |  t j ƒ t t j ƒ t k rü d \ } } } }	 n: t j d t j d t j d t j d f \ } } } }	 | j | | j | | j | | | j | |	 | j f S(   s  
    Status XQueryTree(display, w, root_return, parent_return, children_return, nchildren_return)
       Display *display;
       Window w;
       Window *root_return;
       Window *parent_return;
       Window **children_return;
       unsigned int *nchildren_return;
    t   _NET_FRAME_EXTENTSi    i   i   i   (   i    i    i    i    (   t   ctypest   c_ulongt   c_uintR   t   x11t
   XQueryTreet   dispt   byrefR   t   valuet   globst   XWindowAttributest   XGetWindowAttributesR   R   R   R   R   R   R   R   R   (
   R,   t   root_returnt   parent_returnt   children_returnt   nchildren_returnt   xwat   lR/   t   tt   b(    (    s   modules/support.pyR   \   s    
*	":c         C   s   t  j j t  j |  t ƒ } t  j j t  j | | d d t | t j t  j ƒ t j t  j	 ƒ t j t  j
 ƒ t j t  j ƒ t j t  j ƒ ƒ d S(   so      gets an x property puts in global return variables
          property name, window, return data type atom   i    i€   i   Ni €  (   R   R5   t   XInternAtomR7   R   t   XGetWindowPropertyR2   R8   t   ret_typet
   ret_formatt	   num_itemst   bytes_afterR   (   t	   prop_namet   windowt	   data_typet	   prop_atom(    (    s   modules/support.pyR   }   s    !-c      	   C   s  t  d |  t j ƒ t j s  d St j d } t j d } | | } d } d } x | | k  rÑ t j | d } | d 7} | d | d ?d @} | d | d	 ?d @} | d | d @} | d | d
 ?d @} qS Wt j j | t j j t	 d	 | | | d ƒ } | S(   sh      this returns a gtk.gdk.pixbuf of the windows icon
          converts argb into rgba in the process   t   _NET_WM_ICONi    i   R   i   s   %ci   iÿ   i   i   i   N(
   R   R   R   R   t   NoneR   R   t   pixbuf_new_from_datat   COLORSPACE_RGBR   (   R,   R-   R.   t   sR"   R$   t   argbt   pxbuf(    (    s   modules/support.pyt   get_icon…   s"    	 

.c         C   sD   t  j d ƒ } t j j t j |  t  j t j ƒ t  j | ƒ ƒ d S(   s:    returns the minimum window size and its resize increment i    N(   R2   t   c_longR   R5   t   XGetWMNormalHintsR7   R8   t   size_hints_return(   R,   t   supplied_return(    (    s   modules/support.pyt   get_min_size™   s    !c         C   sÅ   t  j ƒ  } d | _ d | _ t | _ t j j t j	 | t
 ƒ | _ |  | _ d | _ | | _ | | _ | | _ | | _ | | _ t j j t j	 t j t
 d	 d
 Bt j | ƒ ƒ sÁ d G| GHn  d S(   sC      sends a client message event used to change window properties   i!   i    i    i   i   i   s   can't send message Ni   i   (   R:   t   XClientMessageEventt   typet   serialR   t   sendR   R5   RE   R7   R   t   msgtypeRL   t   formatt   data0t   data1t   data2t   data3t   data4t
   XSendEventR   R2   R8   (   R,   t   msgt   d0t   d1t   d2t   d3t   d4t   event(    (    s   modules/support.pyt
   client_msgŸ   s    										1c   
   	   C   sÏ  t  j j t  j t ƒ t d |  t  j ƒ t t  j ƒ t k rS d \ } } } }	 n: t  j d t  j d t  j d t  j d f \ } } } }	 | d k  r¿ t d t  j	 t  j ƒ t  j d } n  t
 t  j	 d | d d d d ƒ t
 |  d | d d d d ƒ t
 |  d d t  j d d d ƒ t
 |  d d t  j t  j d d ƒ t
 |  d	 d d d d d ƒ t  j j t  j |  ƒ t  j j t  j t ƒ t  j j t  j |  | | | | | | | |	 ƒ t  j j t  j t ƒ d
 S(   s±      moves window to the users current desktop removes states like
          maximised and fullscreen activates the window,
          raises it then finally! moves and resizes it R1   i    i   i   i   t   _NET_CURRENT_DESKTOPt   _NET_WM_DESKTOPt   _NET_WM_STATEt   _NET_ACTIVE_WINDOWN(   i    i    i    i    (   R   R5   t   XSyncR7   R   R   R   R   R   R   Ro   t   fscreen_atomt	   maxv_atomt	   maxh_atomt
   XMapRaisedt   XMoveResizeWindow(
   R,   R   R   R-   R.   t   dest_workspaceRB   R/   RC   RD   (    (    s   modules/support.pyt
   moveresize±   s"    :"2c         C   s{   t  d t j t j ƒ t j d } t |  d | d d d d ƒ t |  d d t j t j d d ƒ t j j	 t j
 t ƒ d S(   s8    moves a window to the current desktop and maximises it Rp   i    Rq   Rr   i   N(   R   R   R   R   R   Ro   Rv   Rw   R5   Rt   R7   R   (   R,   t   cdt(    (    s   modules/support.pyt   maximizeÌ   s
    "c         C   s{   t  d t j t j ƒ t j d } t |  d | d d d d ƒ t |  d d t j t j d d ƒ t j j	 t j
 t ƒ d S(   s<    moves a window to the current desktop and 'unmaximises' it Rp   i    Rq   Rr   N(   R   R   R   R   R   Ro   Rv   Rw   R5   Rt   R7   R   (   R,   R|   (    (    s   modules/support.pyt
   unmaximizeÔ   s
    "c           C   sR   t  d t j t j ƒ t j j rN t j d t j d t j d t j d f Sd S(   s5      gets the "work area" usually space between panels R    i    i   i   i   (   i    i    i    i    (   R   R   R   R   RI   R9   R   (    (    (    s   modules/support.pyt   desktop_sizeÜ   s    ,c         C   s*   |  | d | k o) |  | d | | k  S(   s6   Returns True if p <---> p+dim is between a <---> a+dimi   (    (   t   pt   pdimt   at   adim(    (    s   modules/support.pyt	   is_insideã   s    c         C   sE  t  | d | d |  d |  d ƒ sL t  | d | d |  d |  d ƒ rP |  S| d |  d d k r„ | d |  d d k r„ |  S| d | d k  rî | d |  d k r× |  d c | d 7<|  d c | d 8<qA|  d c | d 8<nS | d |  d k r-|  d c | d 7<|  d c | d 8<n |  d c | d 8<|  S(   s-   Returns the white_area without the black_areai    i   i   i   (   R„   (   t
   white_areat
   black_area(    (    s   modules/support.pyt   subtract_areasç   s    &&0c      
   C   sz   t  j ƒ  } t  j ƒ  } t  j ƒ  } t j j t j |  t j | | t  j | ƒ t  j | ƒ t  j | ƒ ƒ | j	 | j	 f S(   s(  
    Bool XTranslateCoordinates(display, src_w, dest_w, src_x, src_y, dest_x_return, 
                               dest_y_return, child_return)
      Display *display;
      Window src_w, dest_w;
      int src_x, src_y;
      int *dest_x_return, *dest_y_return;
      Window *child_return;
    (
   R2   R3   t   c_intR   R5   t   XTranslateCoordinatesR7   R   R8   R9   (   R,   R   R   t   child_returnt   dest_x_returnt   dest_y_return(    (    s   modules/support.pyt   translate_coords  s    
c         C   s  g  } t  j ƒ  } t  j ƒ  } t  j t  j ƒ  ƒ } t  j ƒ  } t  j ƒ  } t  j ƒ  } t  j ƒ  }	 t  j ƒ  }
 t  j ƒ  } t d | t j ƒ t j j rCt j	 j
 |  | t  j | ƒ t  j | ƒ t  j | ƒ t  j |	 ƒ t  j |
 ƒ t  j | ƒ t  j | ƒ ƒ	 t | | j | j ƒ } | j | d | d |	 j |
 j g ƒ n  t j	 j |  | t  j | ƒ t  j | ƒ t  j | ƒ t  j | ƒ ƒ } | j rýxV t d | j ƒ D]B } t  j | | t  j t  j ƒ ƒ } | j t |  | | ƒ ƒ q¤Wt j	 j | ƒ n  | S(   s'   Retrieve the Strut Windows (the panels)t   _NET_WM_STRUT_PARTIALi    i   (   R2   R3   t   pointerRˆ   R   R   R   RI   R9   R5   t   XGetGeometryR8   R   t   appendR6   R    t   castt   POINTERR4   t   extendt   enumerate_strut_windowst   XFree(   t   displayt
   rootwindowt   strut_windowst   rootrt   parentt   childrent   noOfChildrent   x_returnt   y_returnt   width_returnt   height_returnt   dummyt   struct_origint   statusR$   t   ptr(    (    s   modules/support.pyR•     s.    34*E	"c          C   sJ   t  j ƒ  }  t j j t j t j t j |  ƒ ƒ t j j	 |  j
 ƒ } | S(   s   Get Screen Index(   R:   R;   R   R5   R<   R7   R   R2   R8   t   XScreenNumberOfScreenR   (   RA   t   screen_index(    (    s   modules/support.pyt   get_root_screen_index5  s    %c         C   sB  |  d k r d Sy t  j d |  ƒ } Wn~ t k
 r§ t  j j d |  ƒ sQ d St d |  ƒ } z5 | j ƒ  j d ƒ d j d d ƒ j d	 d ƒ } Wd  | j	 ƒ  Xn Xt  j j
 | ƒ rÕ t  j j | ƒ \ } } n d } | } | d d
 !d k r>t d |  ƒ } z | j ƒ  j t d ƒ ƒ } Wd  | j	 ƒ  X| d } n  | S(   Ni    t   ?s   /proc/%s/exes   /proc/%s/statt    i   t   (R   t   )i   t   pythons   /proc/%s/cmdline(   t   ost   readlinkt   OSErrort   patht   existst   opent   readt   splitt   replacet   closet   isabst   chr(   R€   t   _exet   fR±   t   namet   cmdp(    (    s   modules/support.pyt   get_process_name<  s,      5c         C   sQ   t  d |  t j ƒ x7 t d t j j ƒ D]  } t j | t j k r) t Sq) Wt	 S(   s%    is a window hidden ie "minimised" ? Rr   i    (
   R   R   t   XA_ATOMR    RI   R9   R   t   hidden_atomR   R   (   R,   R$   (    (    s   modules/support.pyt   is_window_hidden]  s
     c         C   sQ   t  d |  t j ƒ x7 t d t j j ƒ D]  } t j | t j k r) t Sq) Wt	 S(   s    is a window sticky ? Rr   i    (
   R   R   R¿   R    RI   R9   R   t   sticky_atomR   R   (   R,   R$   (    (    s   modules/support.pyt   is_window_stickyd  s
     c         C   sQ   t  d |  t j ƒ x7 t d t j j ƒ D]  } t j | t j k r) t Sq) Wt	 S(   s$    is a window vertically maximised ? Rr   i    (
   R   R   R¿   R    RI   R9   R   Rv   R   R   (   R,   R$   (    (    s   modules/support.pyR+   k  s
     c         C   sQ   t  d |  t j ƒ x7 t d t j j ƒ D]  } t j | t j k r) t Sq) Wt	 S(   s&    is a window horizontally maximised ? Rr   i    (
   R   R   R¿   R    RI   R9   R   Rw   R   R   (   R,   R$   (    (    s   modules/support.pyR*   r  s
     c      	   C   s}   t  |  ƒ s t |  ƒ r! d } n d } t |  ƒ } t |  ƒ t | ƒ t | d ƒ t | d ƒ t | d ƒ t | d ƒ g S(   s    From win_id to Undo Snap Elementi   i    i   i   (   R+   R*   R   t   str(   R   t   is_maximizedt   win_geom(    (    s   modules/support.pyt   get_undo_element_from_win_idy  s     			c         C   sV   d } x% | D] } | d j  | ƒ d 7} q W| d  } |  j t j t j | ƒ d S(   s   Write Undo Snap to DiskR   t   ,Rª   iÿÿÿÿN(   t   joint
   set_stringt   const
   GCONF_UNDOR   R§   (   t   gconf_clientt   undo_snap_vect   undo_snap_strt   element(    (    s   modules/support.pyt   undo_snap_write…  s
    
c      	   C   s{   t  j d t  j t  j Bd t  j d t  j d |  ƒ } | d k rP | j | ƒ n  | j t	 d ƒ ƒ | j
 ƒ  | j ƒ  d S(   s   The Info dialogt   flagsR]   t   buttonst   message_formatt   InfoN(   R   t   MessageDialogt   DIALOG_MODALt   DIALOG_DESTROY_WITH_PARENTt   MESSAGE_INFOt
   BUTTONS_OKRP   t   set_transient_fort	   set_titlet   _t   runt   destroy(   t   messageR›   t   dialog(    (    s   modules/support.pyt   dialog_info  s    			 
c      	   C   s{   t  j d t  j t  j Bd t  j d t  j d |  ƒ } | d k rP | j | ƒ n  | j t	 d ƒ ƒ | j
 ƒ  | j ƒ  d S(   s   The Warning dialogRÒ   R]   RÓ   RÔ   t   WarningN(   R   RÖ   R×   RØ   t   MESSAGE_WARNINGRÚ   RP   RÛ   RÜ   RÝ   RÞ   Rß   (   Rà   R›   Rá   (    (    s   modules/support.pyt   dialog_warning˜  s    			 
($   R   t   gobjectR®   t
   subprocessR2   t   reR:   RË   R   R   R(   R0   R   R   RV   R[   Ro   R{   R}   R~   R   R„   R‡   R   R•   R¨   R¾   RÁ   RÃ   R+   R*   RÇ   RÑ   RP   Râ   Rå   (    (    (    s   modules/support.pyt   <module>   s:   0				"		!										!				!						