diff options
| author | Jan D | 2015-02-25 20:16:44 +0100 |
|---|---|---|
| committer | Jan D | 2015-02-25 20:16:44 +0100 |
| commit | 719fd9334634dfc91e145d0a7320387a8bb4b75f (patch) | |
| tree | f8291b946d6c23dd60b564dda4ccae43a7a70c9a /src | |
| parent | 0731a2e857f6d328a06a12d9d7540f41f3a8ae04 (diff) | |
| download | emacs-719fd9334634dfc91e145d0a7320387a8bb4b75f.tar.gz emacs-719fd9334634dfc91e145d0a7320387a8bb4b75f.zip | |
Redo the whole window offsets and coordinate translation for X.
* frame.h (struct frame): Remove x_pixels_diff, y_pixels_diff.
* w32fns.c (x_real_positions): Remove setting of x_pixels_diff,
y_pixels_diff.
* xfns.c (x_real_pos_and_offsets): New function, basically the code
from x_real_positions.
(x_real_positions): Call x_real_pos_and_offsets.
(x_relative_mouse_position): Use XTranslateCoordinates instead of
OUTER_TO_INNER_DIFF macros.
(Fx_frame_geometry): Get offsets with x_real_pos_and_offsets,
border from window attributes. Adjust tool bar and menu widths.
* xmenu.c (create_and_show_popup_menu): Use XTranslateCoordinates
instead of OUTER_TO_INNER_DIFF macros.
* xterm.h (struct x_output): Remove x_pixels_outer_diff,
y_pixels_outer_diff, FRAME_OUTER_TO_INNER_DIFF_X,
FRAME_OUTER_TO_INNER_DIFF_Y. Declare x_real_pos_and_offsets.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 22 | ||||
| -rw-r--r-- | src/frame.h | 4 | ||||
| -rw-r--r-- | src/w32fns.c | 4 | ||||
| -rw-r--r-- | src/xfns.c | 106 | ||||
| -rw-r--r-- | src/xmenu.c | 16 | ||||
| -rw-r--r-- | src/xterm.h | 28 |
6 files changed, 121 insertions, 59 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 1f0781fef10..e4506968baa 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,25 @@ | |||
| 1 | 2015-02-25 Jan Djärv <jan.h.d@swipnet.se> | ||
| 2 | |||
| 3 | * xterm.h (struct x_output): Remove x_pixels_outer_diff, | ||
| 4 | y_pixels_outer_diff, FRAME_OUTER_TO_INNER_DIFF_X, | ||
| 5 | FRAME_OUTER_TO_INNER_DIFF_Y. Declare x_real_pos_and_offsets. | ||
| 6 | |||
| 7 | * xmenu.c (create_and_show_popup_menu): Use XTranslateCoordinates | ||
| 8 | instead of OUTER_TO_INNER_DIFF macros. | ||
| 9 | |||
| 10 | * xfns.c (x_real_pos_and_offsets): New function, basically the code | ||
| 11 | from x_real_positions. | ||
| 12 | (x_real_positions): Call x_real_pos_and_offsets. | ||
| 13 | (x_relative_mouse_position): Use XTranslateCoordinates instead of | ||
| 14 | OUTER_TO_INNER_DIFF macros. | ||
| 15 | (Fx_frame_geometry): Get offsets with x_real_pos_and_offsets, | ||
| 16 | border from window attributes. Adjust tool bar and menu widths. | ||
| 17 | |||
| 18 | * w32fns.c (x_real_positions): Remove setting of x_pixels_diff, | ||
| 19 | y_pixels_diff. | ||
| 20 | |||
| 21 | * frame.h (struct frame): Remove x_pixels_diff, y_pixels_diff. | ||
| 22 | |||
| 1 | 2015-02-25 Paul Eggert <eggert@cs.ucla.edu> | 23 | 2015-02-25 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 24 | ||
| 3 | Backtrace after malloc arena is corrupted | 25 | Backtrace after malloc arena is corrupted |
diff --git a/src/frame.h b/src/frame.h index 6f5de3f5689..ddbf93e98f5 100644 --- a/src/frame.h +++ b/src/frame.h | |||
| @@ -396,10 +396,6 @@ struct frame | |||
| 396 | widths) in pixels. */ | 396 | widths) in pixels. */ |
| 397 | int pixel_width, pixel_height; | 397 | int pixel_width, pixel_height; |
| 398 | 398 | ||
| 399 | /* These many pixels are the difference between the outer window (i.e. the | ||
| 400 | left and top of the window manager decoration) and FRAME_X_WINDOW. */ | ||
| 401 | int x_pixels_diff, y_pixels_diff; | ||
| 402 | |||
| 403 | /* This is the gravity value for the specified window position. */ | 399 | /* This is the gravity value for the specified window position. */ |
| 404 | int win_gravity; | 400 | int win_gravity; |
| 405 | 401 | ||
diff --git a/src/w32fns.c b/src/w32fns.c index 1e685ad6d98..6f404e98a62 100644 --- a/src/w32fns.c +++ b/src/w32fns.c | |||
| @@ -346,10 +346,6 @@ x_real_positions (struct frame *f, int *xptr, int *yptr) | |||
| 346 | /* Convert (0, 0) in the client area to screen co-ordinates. */ | 346 | /* Convert (0, 0) in the client area to screen co-ordinates. */ |
| 347 | ClientToScreen (FRAME_W32_WINDOW (f), &pt); | 347 | ClientToScreen (FRAME_W32_WINDOW (f), &pt); |
| 348 | 348 | ||
| 349 | /* Remember x_pixels_diff and y_pixels_diff. */ | ||
| 350 | f->x_pixels_diff = pt.x - rect.left; | ||
| 351 | f->y_pixels_diff = pt.y - rect.top; | ||
| 352 | |||
| 353 | *xptr = rect.left; | 349 | *xptr = rect.left; |
| 354 | *yptr = rect.top; | 350 | *yptr = rect.top; |
| 355 | } | 351 | } |
diff --git a/src/xfns.c b/src/xfns.c index 80be6ac257c..afbd460b7c8 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -168,12 +168,25 @@ check_x_display_info (Lisp_Object object) | |||
| 168 | return dpyinfo; | 168 | return dpyinfo; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | /* Store the screen positions of frame F into XPTR and YPTR. | 171 | /* Return the screen positions and offsets of frame F. |
| 172 | Store the offsets between FRAME_OUTER_WINDOW and the containing | ||
| 173 | window manager window into LEFT_OFFSET_X, RIGHT_OFFSET_X, | ||
| 174 | TOP_OFFSET_Y and BOTTOM_OFFSET_Y. | ||
| 175 | Store the offsets between FRAME_X_WINDOW and the containing | ||
| 176 | window manager window into X_PIXELS_DIFF and Y_PIXELS_DIFF. | ||
| 177 | Store the screen positions of frame F into XPTR and YPTR. | ||
| 172 | These are the positions of the containing window manager window, | 178 | These are the positions of the containing window manager window, |
| 173 | not Emacs's own window. */ | 179 | not Emacs's own window. */ |
| 174 | |||
| 175 | void | 180 | void |
| 176 | x_real_positions (struct frame *f, int *xptr, int *yptr) | 181 | x_real_pos_and_offsets (struct frame *f, |
| 182 | int *left_offset_x, | ||
| 183 | int *right_offset_x, | ||
| 184 | int *top_offset_y, | ||
| 185 | int *bottom_offset_y, | ||
| 186 | int *x_pixels_diff, | ||
| 187 | int *y_pixels_diff, | ||
| 188 | int *xptr, | ||
| 189 | int *yptr) | ||
| 177 | { | 190 | { |
| 178 | int win_x, win_y, outer_x IF_LINT (= 0), outer_y IF_LINT (= 0); | 191 | int win_x, win_y, outer_x IF_LINT (= 0), outer_y IF_LINT (= 0); |
| 179 | int real_x = 0, real_y = 0; | 192 | int real_x = 0, real_y = 0; |
| @@ -187,6 +200,7 @@ x_real_positions (struct frame *f, int *xptr, int *yptr) | |||
| 187 | Display *dpy = FRAME_X_DISPLAY (f); | 200 | Display *dpy = FRAME_X_DISPLAY (f); |
| 188 | unsigned char *tmp_data = NULL; | 201 | unsigned char *tmp_data = NULL; |
| 189 | Atom target_type = XA_CARDINAL; | 202 | Atom target_type = XA_CARDINAL; |
| 203 | unsigned int ow IF_LINT (= 0), oh IF_LINT (= 0); | ||
| 190 | 204 | ||
| 191 | block_input (); | 205 | block_input (); |
| 192 | 206 | ||
| @@ -230,7 +244,7 @@ x_real_positions (struct frame *f, int *xptr, int *yptr) | |||
| 230 | 244 | ||
| 231 | /* Get the real coordinates for the WM window upper left corner */ | 245 | /* Get the real coordinates for the WM window upper left corner */ |
| 232 | XGetGeometry (FRAME_X_DISPLAY (f), win, | 246 | XGetGeometry (FRAME_X_DISPLAY (f), win, |
| 233 | &rootw, &real_x, &real_y, &ign, &ign, &ign, &ign); | 247 | &rootw, &real_x, &real_y, &ow, &oh, &ign, &ign); |
| 234 | 248 | ||
| 235 | /* Translate real coordinates to coordinates relative to our | 249 | /* Translate real coordinates to coordinates relative to our |
| 236 | window. For our window, the upper left corner is 0, 0. | 250 | window. For our window, the upper left corner is 0, 0. |
| @@ -310,16 +324,38 @@ x_real_positions (struct frame *f, int *xptr, int *yptr) | |||
| 310 | 324 | ||
| 311 | if (had_errors) return; | 325 | if (had_errors) return; |
| 312 | 326 | ||
| 313 | f->x_pixels_diff = -win_x; | 327 | if (x_pixels_diff) *x_pixels_diff = -win_x; |
| 314 | f->y_pixels_diff = -win_y; | 328 | if (y_pixels_diff) *y_pixels_diff = -win_y; |
| 329 | |||
| 330 | if (left_offset_x) *left_offset_x = -outer_x; | ||
| 331 | if (top_offset_y) *top_offset_y = -outer_x; | ||
| 315 | 332 | ||
| 316 | FRAME_X_OUTPUT (f)->x_pixels_outer_diff = -outer_x; | 333 | if (xptr) *xptr = real_x; |
| 317 | FRAME_X_OUTPUT (f)->y_pixels_outer_diff = -outer_y; | 334 | if (yptr) *yptr = real_y; |
| 318 | 335 | ||
| 319 | *xptr = real_x; | 336 | if (right_offset_x || bottom_offset_y) |
| 320 | *yptr = real_y; | 337 | { |
| 338 | unsigned int ign, fw, fh; | ||
| 339 | Window rootw; | ||
| 340 | |||
| 341 | XGetGeometry (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), | ||
| 342 | &rootw, &ign, &ign, &fw, &fh, &ign, &ign); | ||
| 343 | if (right_offset_x) *right_offset_x = ow - fw + outer_x; | ||
| 344 | if (bottom_offset_y) *bottom_offset_y = oh - fh + outer_y; | ||
| 345 | } | ||
| 321 | } | 346 | } |
| 322 | 347 | ||
| 348 | /* Store the screen positions of frame F into XPTR and YPTR. | ||
| 349 | These are the positions of the containing window manager window, | ||
| 350 | not Emacs's own window. */ | ||
| 351 | |||
| 352 | void | ||
| 353 | x_real_positions (struct frame *f, int *xptr, int *yptr) | ||
| 354 | { | ||
| 355 | x_real_pos_and_offsets (f, NULL, NULL, NULL, NULL, NULL, NULL, xptr, yptr); | ||
| 356 | } | ||
| 357 | |||
| 358 | |||
| 323 | /* Get the mouse position in frame relative coordinates. */ | 359 | /* Get the mouse position in frame relative coordinates. */ |
| 324 | 360 | ||
| 325 | void | 361 | void |
| @@ -351,11 +387,19 @@ x_relative_mouse_position (struct frame *f, int *x, int *y) | |||
| 351 | we don't care. */ | 387 | we don't care. */ |
| 352 | (unsigned int *) &dummy); | 388 | (unsigned int *) &dummy); |
| 353 | 389 | ||
| 354 | unblock_input (); | 390 | XTranslateCoordinates (FRAME_X_DISPLAY (f), |
| 391 | |||
| 392 | /* From-window, to-window. */ | ||
| 393 | FRAME_DISPLAY_INFO (f)->root_window, | ||
| 394 | FRAME_X_WINDOW (f), | ||
| 355 | 395 | ||
| 356 | /* Translate root window coordinates to window coordinates. */ | 396 | /* From-position, to-position. */ |
| 357 | *x -= f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); | 397 | *x, *y, x, y, |
| 358 | *y -= f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); | 398 | |
| 399 | /* Child of win. */ | ||
| 400 | &dummy_window); | ||
| 401 | |||
| 402 | unblock_input (); | ||
| 359 | } | 403 | } |
| 360 | 404 | ||
| 361 | /* Gamma-correct COLOR on frame F. */ | 405 | /* Gamma-correct COLOR on frame F. */ |
| @@ -4279,13 +4323,23 @@ elements (all size values are in pixels). | |||
| 4279 | Lisp_Object fullscreen = Fframe_parameter (frame, Qfullscreen); | 4323 | Lisp_Object fullscreen = Fframe_parameter (frame, Qfullscreen); |
| 4280 | int menu_bar_height, menu_bar_width, tool_bar_height, tool_bar_width; | 4324 | int menu_bar_height, menu_bar_width, tool_bar_height, tool_bar_width; |
| 4281 | 4325 | ||
| 4282 | border = FRAME_OUTER_TO_INNER_DIFF_X (f); | 4326 | int left_off, right_off, top_off, bottom_off; |
| 4283 | title = FRAME_X_OUTPUT (f)->y_pixels_outer_diff - border; | 4327 | XWindowAttributes atts; |
| 4328 | |||
| 4329 | block_input (); | ||
| 4330 | |||
| 4331 | XGetWindowAttributes (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &atts); | ||
| 4332 | |||
| 4333 | x_real_pos_and_offsets (f, &left_off, &right_off, &top_off, &bottom_off, | ||
| 4334 | NULL, NULL, NULL, NULL); | ||
| 4335 | |||
| 4336 | unblock_input (); | ||
| 4337 | |||
| 4338 | border = atts.border_width; | ||
| 4339 | title = top_off; | ||
| 4284 | 4340 | ||
| 4285 | outer_width = FRAME_PIXEL_WIDTH (f) + 2 * border; | 4341 | outer_width = FRAME_PIXEL_WIDTH (f) + 2 * border + right_off + left_off; |
| 4286 | outer_height = (FRAME_PIXEL_HEIGHT (f) | 4342 | outer_height = FRAME_PIXEL_HEIGHT (f) + 2 * border + top_off + bottom_off; |
| 4287 | + FRAME_OUTER_TO_INNER_DIFF_Y (f) | ||
| 4288 | + FRAME_OUTER_TO_INNER_DIFF_X (f)); | ||
| 4289 | 4343 | ||
| 4290 | #if defined (USE_GTK) | 4344 | #if defined (USE_GTK) |
| 4291 | { | 4345 | { |
| @@ -4298,16 +4352,10 @@ elements (all size values are in pixels). | |||
| 4298 | tool_bar_height = (tool_bar_left_right | 4352 | tool_bar_height = (tool_bar_left_right |
| 4299 | ? FRAME_PIXEL_HEIGHT (f) | 4353 | ? FRAME_PIXEL_HEIGHT (f) |
| 4300 | : FRAME_TOOLBAR_HEIGHT (f)); | 4354 | : FRAME_TOOLBAR_HEIGHT (f)); |
| 4301 | if (tool_bar_left_right) | ||
| 4302 | /* For some reason FRAME_OUTER_TO_INNER_DIFF_X does not count the | ||
| 4303 | width of a tool bar. */ | ||
| 4304 | outer_width += FRAME_TOOLBAR_WIDTH (f); | ||
| 4305 | } | 4355 | } |
| 4306 | #else | 4356 | #else |
| 4307 | tool_bar_height = FRAME_TOOL_BAR_HEIGHT (f); | 4357 | tool_bar_height = FRAME_TOOL_BAR_HEIGHT (f); |
| 4308 | tool_bar_width = ((tool_bar_height > 0) | 4358 | tool_bar_width = tool_bar_height > 0 ? FRAME_PIXEL_WIDTH (f) : 0; |
| 4309 | ? outer_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f) | ||
| 4310 | : 0); | ||
| 4311 | #endif | 4359 | #endif |
| 4312 | 4360 | ||
| 4313 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) | 4361 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) |
| @@ -4316,9 +4364,7 @@ elements (all size values are in pixels). | |||
| 4316 | menu_bar_height = FRAME_MENU_BAR_HEIGHT (f); | 4364 | menu_bar_height = FRAME_MENU_BAR_HEIGHT (f); |
| 4317 | #endif | 4365 | #endif |
| 4318 | 4366 | ||
| 4319 | menu_bar_width = ((menu_bar_height > 0) | 4367 | menu_bar_width = menu_bar_height > 0 ? FRAME_PIXEL_WIDTH (f) : 0; |
| 4320 | ? outer_width - 2 * border | ||
| 4321 | : 0); | ||
| 4322 | 4368 | ||
| 4323 | if (!FRAME_EXTERNAL_MENU_BAR (f)) | 4369 | if (!FRAME_EXTERNAL_MENU_BAR (f)) |
| 4324 | inner_height -= menu_bar_height; | 4370 | inner_height -= menu_bar_height; |
diff --git a/src/xmenu.c b/src/xmenu.c index fdf1f6f4d84..c9f150f67f3 100644 --- a/src/xmenu.c +++ b/src/xmenu.c | |||
| @@ -1211,13 +1211,25 @@ create_and_show_popup_menu (struct frame *f, widget_value *first_wv, | |||
| 1211 | 1211 | ||
| 1212 | if (use_pos_func) | 1212 | if (use_pos_func) |
| 1213 | { | 1213 | { |
| 1214 | Window dummy_window; | ||
| 1215 | |||
| 1214 | /* Not invoked by a click. pop up at x/y. */ | 1216 | /* Not invoked by a click. pop up at x/y. */ |
| 1215 | pos_func = menu_position_func; | 1217 | pos_func = menu_position_func; |
| 1216 | 1218 | ||
| 1217 | /* Adjust coordinates to be root-window-relative. */ | 1219 | /* Adjust coordinates to be root-window-relative. */ |
| 1218 | x += f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); | 1220 | block_input (); |
| 1219 | y += f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); | 1221 | XTranslateCoordinates (FRAME_X_DISPLAY (f), |
| 1222 | |||
| 1223 | /* From-window, to-window. */ | ||
| 1224 | FRAME_X_WINDOW (f), | ||
| 1225 | FRAME_DISPLAY_INFO (f)->root_window, | ||
| 1220 | 1226 | ||
| 1227 | /* From-position, to-position. */ | ||
| 1228 | x, y, &x, &y, | ||
| 1229 | |||
| 1230 | /* Child of win. */ | ||
| 1231 | &dummy_window); | ||
| 1232 | unblock_input (); | ||
| 1221 | popup_x_y.x = x; | 1233 | popup_x_y.x = x; |
| 1222 | popup_x_y.y = y; | 1234 | popup_x_y.y = y; |
| 1223 | popup_x_y.f = f; | 1235 | popup_x_y.f = f; |
diff --git a/src/xterm.h b/src/xterm.h index e597227c81c..16868f114e8 100644 --- a/src/xterm.h +++ b/src/xterm.h | |||
| @@ -628,15 +628,6 @@ struct x_output | |||
| 628 | They are changed only when a different background is involved. */ | 628 | They are changed only when a different background is involved. */ |
| 629 | unsigned long relief_background; | 629 | unsigned long relief_background; |
| 630 | 630 | ||
| 631 | /* As x_pixels_diff, but to FRAME_OUTER_WINDOW. For some reason the | ||
| 632 | two might differ by a pixel, depending on WM */ | ||
| 633 | int x_pixels_outer_diff; | ||
| 634 | |||
| 635 | /* As y_pixels_diff, but to FRAME_OUTER_WINDOW. In the toolkit version, | ||
| 636 | these may differ because this does not take into account possible | ||
| 637 | menubar. y_pixels_diff is with menubar height included */ | ||
| 638 | int y_pixels_outer_diff; | ||
| 639 | |||
| 640 | /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this | 631 | /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this |
| 641 | frame, or IMPLICIT if we received an EnterNotify. | 632 | frame, or IMPLICIT if we received an EnterNotify. |
| 642 | FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */ | 633 | FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */ |
| @@ -759,16 +750,6 @@ enum | |||
| 759 | /* This is the Colormap which frame F uses. */ | 750 | /* This is the Colormap which frame F uses. */ |
| 760 | #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap | 751 | #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap |
| 761 | 752 | ||
| 762 | /* The difference in pixels between the top left corner of the | ||
| 763 | Emacs window (including possible window manager decorations) | ||
| 764 | and FRAME_X_WINDOW (f). */ | ||
| 765 | #define FRAME_OUTER_TO_INNER_DIFF_X(f) \ | ||
| 766 | ((f)->output_data.x->x_pixels_outer_diff) | ||
| 767 | #define FRAME_OUTER_TO_INNER_DIFF_Y(f) \ | ||
| 768 | ((f)->output_data.x->y_pixels_outer_diff \ | ||
| 769 | + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f)) | ||
| 770 | |||
| 771 | |||
| 772 | #define FRAME_XIC(f) ((f)->output_data.x->xic) | 753 | #define FRAME_XIC(f) ((f)->output_data.x->xic) |
| 773 | #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim) | 754 | #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim) |
| 774 | #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles) | 755 | #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles) |
| @@ -971,6 +952,15 @@ SELECTION_EVENT_DISPLAY (struct input_event *ev) | |||
| 971 | 952 | ||
| 972 | extern void x_free_gcs (struct frame *); | 953 | extern void x_free_gcs (struct frame *); |
| 973 | extern void x_relative_mouse_position (struct frame *, int *, int *); | 954 | extern void x_relative_mouse_position (struct frame *, int *, int *); |
| 955 | extern void x_real_pos_and_offsets (struct frame *f, | ||
| 956 | int *left_offset_x, | ||
| 957 | int *right_offset_x, | ||
| 958 | int *top_offset_y, | ||
| 959 | int *bottom_offset_y, | ||
| 960 | int *x_pixels_diff, | ||
| 961 | int *y_pixels_diff, | ||
| 962 | int *xptr, | ||
| 963 | int *yptr); | ||
| 974 | 964 | ||
| 975 | /* From xrdb.c. */ | 965 | /* From xrdb.c. */ |
| 976 | 966 | ||