]> code.delx.au - gnu-emacs/commitdiff
Refactor mouse positioning stuff to avoid code duplication.
authorDmitry Antipov <dmantipov@yandex.ru>
Wed, 28 May 2014 13:53:22 +0000 (17:53 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Wed, 28 May 2014 13:53:22 +0000 (17:53 +0400)
* frame.h (frame_char_to_pixel_position): New function.
(x_set_mouse_position): Rename to...
(frame_set_mouse_position): ...new function.
(frame_set_mouse_pixel_position): Add prototype.
* nsterm.m, w32term.c, xterm.c (x_set_mouse_pixel_position):
Rename to frame_set_mouse_pixel_position.
* frame.c (Fset_mouse_pixel_position, Fset_mouse_position):
Adjust users.
* xterm.h, w32term.h ( x_set_mouse_position)
(x_set_mouse_pixel_position): Remove prototypes.

src/ChangeLog
src/frame.c
src/frame.h
src/nsterm.m
src/w32term.c
src/w32term.h
src/xterm.c
src/xterm.h

index 2c142c5edb7f1e03edb293cf9f901d8d9a7a509c..1fe76c9c75f03605bb25472d039a56a74c747b21 100644 (file)
@@ -1,3 +1,17 @@
+2014-05-28  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       Refactor mouse positioning stuff to avoid code duplication.
+       * frame.h (frame_char_to_pixel_position): New function.
+       (x_set_mouse_position): Rename to...
+       (frame_set_mouse_position): ...new function.
+       (frame_set_mouse_pixel_position): Add prototype.
+       * nsterm.m, w32term.c, xterm.c (x_set_mouse_pixel_position):
+       Rename to frame_set_mouse_pixel_position.
+       * frame.c (Fset_mouse_pixel_position, Fset_mouse_position):
+       Adjust users.
+       * xterm.h, w32term.h ( x_set_mouse_position)
+       (x_set_mouse_pixel_position): Remove prototypes.
+
 2014-05-28  Dmitry Antipov  <dmantipov@yandex.ru>
 
        On X, always make pointer visible when deleting frame (Bug#17609).
index ece0537a2031fa8a5864156c8287bb7fdcc78b5c..482e21bbfbc4d2889555bc2385d8746f7e2a1211 100644 (file)
@@ -1617,7 +1617,7 @@ before calling this function on it, like this.
 #ifdef HAVE_WINDOW_SYSTEM
   if (FRAME_WINDOW_P (XFRAME (frame)))
     /* Warping the mouse will cause enternotify and focus events.  */
-    x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
+    frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
 #else
 #if defined (MSDOS)
   if (FRAME_MSDOS_P (XFRAME (frame)))
@@ -1658,7 +1658,7 @@ before calling this function on it, like this.
 #ifdef HAVE_WINDOW_SYSTEM
   if (FRAME_WINDOW_P (XFRAME (frame)))
     /* Warping the mouse will cause enternotify and focus events.  */
-    x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
+    frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
 #else
 #if defined (MSDOS)
   if (FRAME_MSDOS_P (XFRAME (frame)))
index c0c206d7c6a31544ac5c73981075d276cfc20301..c22b9c2a823b7753378cfff8ae0e3f3d4ddc34b1 100644 (file)
@@ -1313,8 +1313,7 @@ extern void set_frame_menubar (struct frame *f, bool first_time, bool deep_p);
 extern void x_set_window_size (struct frame *f, int change_grav,
                               int width, int height, bool pixelwise);
 extern Lisp_Object x_get_focus_frame (struct frame *);
-extern void x_set_mouse_position (struct frame *f, int h, int v);
-extern void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
+extern void frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
 extern void x_make_frame_visible (struct frame *f);
 extern void x_make_frame_invisible (struct frame *f);
 extern void x_iconify_frame (struct frame *f);
@@ -1366,6 +1365,37 @@ flush_frame (struct frame *f)
     rif->flush_display (f);
 }
 
+/* Convert character coordinates X and Y to pixel
+   coordinates PIX_X and PIX_Y on frame F.  */
+
+INLINE void
+frame_char_to_pixel_position (struct frame *f, int x, int y, int *pix_x, int *pix_y)
+{
+  *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
+  *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
+
+  if (*pix_x < 0)
+    *pix_x = 0;
+  if (*pix_x > FRAME_PIXEL_WIDTH (f))
+    *pix_x = FRAME_PIXEL_WIDTH (f);
+
+  if (*pix_y < 0)
+    *pix_y = 0;
+  if (*pix_y > FRAME_PIXEL_HEIGHT (f))
+    *pix_y = FRAME_PIXEL_HEIGHT (f);
+}
+
+/* Reposition mouse pointer to character coordinates X and Y on frame F.  */
+
+INLINE
+void frame_set_mouse_position (struct frame *f, int x, int y)
+{
+  int pix_x, pix_y;
+
+  frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
+  frame_set_mouse_pixel_position (f, pix_x, pix_y);
+}
+
 /***********************************************************************
                        Multimonitor data
  ***********************************************************************/
index ba94d28b79722f0c8721cde12d19e2abe664d363..f91b86daea6f228d2a03b92a7f3c31a0e69ac09d 100644 (file)
@@ -1812,12 +1812,12 @@ x_set_frame_alpha (struct frame *f)
 
 
 void
-x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
+frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
 /* --------------------------------------------------------------------------
      Programmatically reposition mouse pointer in pixel coordinates
    -------------------------------------------------------------------------- */
 {
-  NSTRACE (x_set_mouse_pixel_position);
+  NSTRACE (frame_set_mouse_pixel_position);
   ns_raise_frame (f);
 #if 0
   /* FIXME: this does not work, and what about GNUstep? */
@@ -1829,28 +1829,6 @@ x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
 #endif
 }
 
-
-void
-x_set_mouse_position (struct frame *f, int h, int v)
-/* --------------------------------------------------------------------------
-     Programmatically reposition mouse pointer in character coordinates
-   -------------------------------------------------------------------------- */
-{
-  int pix_x, pix_y;
-
-  pix_x = FRAME_COL_TO_PIXEL_X (f, h) + FRAME_COLUMN_WIDTH (f) / 2;
-  pix_y = FRAME_LINE_TO_PIXEL_Y (f, v) + FRAME_LINE_HEIGHT (f) / 2;
-
-  if (pix_x < 0) pix_x = 0;
-  if (pix_x > FRAME_PIXEL_WIDTH (f)) pix_x = FRAME_PIXEL_WIDTH (f);
-
-  if (pix_y < 0) pix_y = 0;
-  if (pix_y > FRAME_PIXEL_HEIGHT (f)) pix_y = FRAME_PIXEL_HEIGHT (f);
-
-  x_set_mouse_pixel_position (f, pix_x, pix_y);
-}
-
-
 static int
 note_mouse_movement (struct frame *frame, CGFloat x, CGFloat y)
 /*   ------------------------------------------------------------------------
index 59e9b0ad8a193ba41fec8ad57bc7c89247b3ccb1..5145c840c7192a4d9717e23f7af5c7446bde166f 100644 (file)
@@ -5767,27 +5767,8 @@ x_set_window_size (struct frame *f, int change_gravity, int width, int height, b
 \f
 /* Mouse warping.  */
 
-void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
-
-void
-x_set_mouse_position (struct frame *f, int x, int y)
-{
-  int pix_x, pix_y;
-
-  pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
-  pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
-
-  if (pix_x < 0) pix_x = 0;
-  if (pix_x > FRAME_PIXEL_WIDTH (f)) pix_x = FRAME_PIXEL_WIDTH (f);
-
-  if (pix_y < 0) pix_y = 0;
-  if (pix_y > FRAME_PIXEL_HEIGHT (f)) pix_y = FRAME_PIXEL_HEIGHT (f);
-
-  x_set_mouse_pixel_position (f, pix_x, pix_y);
-}
-
 void
-x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
+frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
 {
   RECT rect;
   POINT pt;
index e3b65f0ffaf75d98eef50a6c3878a072759819b9..561a280b65fcb15e76629e921b1023b5a1421dd6 100644 (file)
@@ -219,8 +219,6 @@ extern void x_set_window_size (struct frame *f, int change_grav,
 extern int x_display_pixel_height (struct w32_display_info *);
 extern int x_display_pixel_width (struct w32_display_info *);
 extern Lisp_Object x_get_focus_frame (struct frame *);
-extern void x_set_mouse_position (struct frame *f, int h, int v);
-extern void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
 extern void x_make_frame_visible (struct frame *f);
 extern void x_make_frame_invisible (struct frame *f);
 extern void x_iconify_frame (struct frame *f);
index ed5d0382eaec7e6683b682570404133d69af0e05..83d3cb1ab733a2f417cf4150c6f3e1cc72a6196a 100644 (file)
@@ -8735,34 +8735,11 @@ x_set_window_size (struct frame *f, int change_gravity, int width, int height, b
 
   unblock_input ();
 }
-\f
-/* Mouse warping.  */
-
-void
-x_set_mouse_position (struct frame *f, int x, int y)
-{
-  int pix_x, pix_y;
-
-  pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
-  pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
-
-  if (pix_x < 0) pix_x = 0;
-  if (pix_x > FRAME_PIXEL_WIDTH (f)) pix_x = FRAME_PIXEL_WIDTH (f);
-
-  if (pix_y < 0) pix_y = 0;
-  if (pix_y > FRAME_PIXEL_HEIGHT (f)) pix_y = FRAME_PIXEL_HEIGHT (f);
-
-  block_input ();
-
-  XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f),
-               0, 0, 0, 0, pix_x, pix_y);
-  unblock_input ();
-}
 
 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F.  */
 
 void
-x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
+frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
 {
   block_input ();
 
index 3e79de109768667d7b92affc4de283e328354b27..8f71cefb02bb34aaae33f20c2fc19d7796610294 100644 (file)
@@ -931,8 +931,6 @@ extern bool x_had_errors_p (Display *);
 extern void x_uncatch_errors (void);
 extern void x_clear_errors (Display *);
 extern void x_set_window_size (struct frame *, int, int, int, bool);
-extern void x_set_mouse_position (struct frame *, int, int);
-extern void x_set_mouse_pixel_position (struct frame *, int, int);
 extern void xembed_request_focus (struct frame *);
 extern void x_ewmh_activate_frame (struct frame *);
 extern void x_delete_terminal (struct terminal *terminal);