Subject: Re: bug#5721: Feature request: Function that returns absolute coordinates

From: Andreas Politz <[email-masked]>
Date: Fri, 04 Oct 2013 12:33:57 +0200

Eli Zaretskii <[email-masked]> writes:

> One more nit, about these fragments: [...] it is better to check the
> frame type at run time, [...]

>  #ifdef HAVE_X_WINDOWS
>    if (FRAME_X_P (f))
>      *add_y += FRAME_X_OUTPUT (f)->y_pixels_outer_diff;
>    else
>  #elif defined (HAVE_NTGUI)
>    if (FRAME_W32_P (f))
>      *add_y += f->y_pixels_diff;
>  #endif
>
> etc., you get the idea.

I don't think that quite does what you have in mind, but I get it.

=== modified file 'src/window.c'
*** src/window.c	2013-10-02 12:08:27 +0000
--- src/window.c	2013-10-04 10:13:26 +0000
***************
*** 935,945 ****
--- 935,974 ----
  		 WINDOW_RIGHT_EDGE_X (w), WINDOW_BOTTOM_EDGE_Y (w));
  }
  
+ #ifdef HAVE_WINDOW_SYSTEM
  static void
  calc_absolute_offset (struct window *w, int *add_x, int *add_y)
  {
    struct frame *f = XFRAME (w->frame);
+ 
+   if (! FRAME_WINDOW_P (f))
+     {
+       *add_x = *add_y = 0;
+       return;
+     }
    *add_y = f->top_pos;
+   *add_x = f->left_pos;
+   switch (f->output_method)
+     {
+ #ifdef HAVE_X_WINDOWS
+     case output_x_window:
+       *add_y += FRAME_X_OUTPUT (f)->y_pixels_outer_diff;
+       *add_x += FRAME_X_OUTPUT (f)->x_pixels_outer_diff;
+       break;
+ #endif
+ #ifdef HAVE_NTGUI
+     case output_w32:
+       *add_y += f->y_pixels_diff;
+       *add_x += f->x_pixels_diff;
+       break;
+ #endif
+ #ifdef HAVE_NS
+     case output_ns:
+       /* FIXME: Add proper offsets. */
+       break;
+ #endif
+     }
+ 
  #ifdef FRAME_MENUBAR_HEIGHT
    *add_y += FRAME_MENUBAR_HEIGHT (f);
  #endif
***************
*** 951,961 ****
  #ifdef FRAME_NS_TITLEBAR_HEIGHT
    *add_y += FRAME_NS_TITLEBAR_HEIGHT (f);
  #endif
!   *add_x = f->left_pos;
  #ifdef FRAME_TOOLBAR_LEFT_WIDTH
    *add_x += FRAME_TOOLBAR_LEFT_WIDTH (f);
  #endif
  }
  
  DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges,
         Swindow_absolute_pixel_edges, 0, 1, 0,
--- 980,991 ----
  #ifdef FRAME_NS_TITLEBAR_HEIGHT
    *add_y += FRAME_NS_TITLEBAR_HEIGHT (f);
  #endif
! 
  #ifdef FRAME_TOOLBAR_LEFT_WIDTH
    *add_x += FRAME_TOOLBAR_LEFT_WIDTH (f);
  #endif
  }
+ #endif /* HAVE_WINDOW_SYSTEM */
  
  DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges,
         Swindow_absolute_pixel_edges, 0, 1, 0,
***************
*** 975,982 ****
    register struct window *w = decode_valid_window (window);
    int add_x, add_y;
  
    calc_absolute_offset (w, &add_x, &add_y);
! 
    return list4i (WINDOW_LEFT_EDGE_X (w) + add_x,
  		 WINDOW_TOP_EDGE_Y (w) + add_y,
  		 WINDOW_RIGHT_EDGE_X (w) + add_x,
--- 1005,1015 ----
    register struct window *w = decode_valid_window (window);
    int add_x, add_y;
  
+ #ifdef HAVE_WINDOW_SYSTEM
    calc_absolute_offset (w, &add_x, &add_y);
! #else
!   add_x = add_y = 0;
! #endif
    return list4i (WINDOW_LEFT_EDGE_X (w) + add_x,
                   WINDOW_TOP_EDGE_Y (w) + add_y,
                   WINDOW_RIGHT_EDGE_X (w) + add_x,
***************
*** 1056,1063 ****
    register struct window *w = decode_live_window (window);
    int add_x, add_y;
  
    calc_absolute_offset (w, &add_x, &add_y);
! 
    return list4i ((WINDOW_BOX_LEFT_EDGE_X (w)
  		  + WINDOW_LEFT_MARGIN_WIDTH (w)
  		  + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x),
--- 1089,1099 ----
    register struct window *w = decode_live_window (window);
    int add_x, add_y;
  
+ #ifdef HAVE_WINDOW_SYSTEM
    calc_absolute_offset (w, &add_x, &add_y);
! #else
!   add_x = add_y = 0;
! #endif
    return list4i ((WINDOW_BOX_LEFT_EDGE_X (w)
                    + WINDOW_LEFT_MARGIN_WIDTH (w)
                    + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x),

-ap