aboutsummaryrefslogtreecommitdiffstats
path: root/src/xterm.c
diff options
context:
space:
mode:
authorPaul Eggert2011-09-03 16:03:38 -0700
committerPaul Eggert2011-09-03 16:03:38 -0700
commitb49e353d9d01adbe60bc5d0b1658b4ef978b0b06 (patch)
tree9f2ffa6f7a6562abf661a4951012b488ad8b1ae7 /src/xterm.c
parent74b880cbc18bd0194c7b1fc44c4a983ee05adae2 (diff)
parentbc3200871917d5c54c8c4299a06bf8f8ba2ea02d (diff)
downloademacs-b49e353d9d01adbe60bc5d0b1658b4ef978b0b06.tar.gz
emacs-b49e353d9d01adbe60bc5d0b1658b4ef978b0b06.zip
Merge from trunk.
Diffstat (limited to 'src/xterm.c')
-rw-r--r--src/xterm.c93
1 files changed, 66 insertions, 27 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 20516ee9d6f..c07caec6c78 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -442,6 +442,27 @@ x_display_info_for_display (Display *dpy)
442 return 0; 442 return 0;
443} 443}
444 444
445static Window
446x_find_topmost_parent (struct frame *f)
447{
448 struct x_output *x = f->output_data.x;
449 Window win = None, wi = x->parent_desc;
450 Display *dpy = FRAME_X_DISPLAY (f);
451
452 while (wi != FRAME_X_DISPLAY_INFO (f)->root_window)
453 {
454 Window root;
455 Window *children;
456 unsigned int nchildren;
457
458 win = wi;
459 XQueryTree (dpy, win, &root, &wi, &children, &nchildren);
460 XFree (children);
461 }
462
463 return win;
464}
465
445#define OPAQUE 0xffffffff 466#define OPAQUE 0xffffffff
446 467
447void 468void
@@ -453,6 +474,7 @@ x_set_frame_alpha (struct frame *f)
453 double alpha = 1.0; 474 double alpha = 1.0;
454 double alpha_min = 1.0; 475 double alpha_min = 1.0;
455 unsigned long opac; 476 unsigned long opac;
477 Window parent;
456 478
457 if (dpyinfo->x_highlight_frame == f) 479 if (dpyinfo->x_highlight_frame == f)
458 alpha = f->alpha[0]; 480 alpha = f->alpha[0];
@@ -473,6 +495,19 @@ x_set_frame_alpha (struct frame *f)
473 495
474 opac = alpha * OPAQUE; 496 opac = alpha * OPAQUE;
475 497
498 x_catch_errors (dpy);
499
500 /* If there is a parent from the window manager, put the property there
501 also, to work around broken window managers that fail to do that.
502 Do this unconditionally as this function is called on reparent when
503 alpha has not changed on the frame. */
504
505 parent = x_find_topmost_parent (f);
506 if (parent != None)
507 XChangeProperty (dpy, parent, dpyinfo->Xatom_net_wm_window_opacity,
508 XA_CARDINAL, 32, PropModeReplace,
509 (unsigned char *) &opac, 1L);
510
476 /* return unless necessary */ 511 /* return unless necessary */
477 { 512 {
478 unsigned char *data; 513 unsigned char *data;
@@ -480,7 +515,6 @@ x_set_frame_alpha (struct frame *f)
480 int rc, format; 515 int rc, format;
481 unsigned long n, left; 516 unsigned long n, left;
482 517
483 x_catch_errors (dpy);
484 rc = XGetWindowProperty (dpy, win, dpyinfo->Xatom_net_wm_window_opacity, 518 rc = XGetWindowProperty (dpy, win, dpyinfo->Xatom_net_wm_window_opacity,
485 0L, 1L, False, XA_CARDINAL, 519 0L, 1L, False, XA_CARDINAL,
486 &actual, &format, &n, &left, 520 &actual, &format, &n, &left,
@@ -1625,19 +1659,18 @@ x_color_cells (Display *dpy, int *ncells)
1625 if (dpyinfo->color_cells == NULL) 1659 if (dpyinfo->color_cells == NULL)
1626 { 1660 {
1627 Screen *screen = dpyinfo->screen; 1661 Screen *screen = dpyinfo->screen;
1662 int ncolor_cells = XDisplayCells (dpy, XScreenNumberOfScreen (screen));
1628 int i; 1663 int i;
1629 1664
1630 dpyinfo->ncolor_cells 1665 dpyinfo->color_cells = xnmalloc (ncolor_cells,
1631 = XDisplayCells (dpy, XScreenNumberOfScreen (screen)); 1666 sizeof *dpyinfo->color_cells);
1632 dpyinfo->color_cells 1667 dpyinfo->ncolor_cells = ncolor_cells;
1633 = (XColor *) xmalloc (dpyinfo->ncolor_cells
1634 * sizeof *dpyinfo->color_cells);
1635 1668
1636 for (i = 0; i < dpyinfo->ncolor_cells; ++i) 1669 for (i = 0; i < ncolor_cells; ++i)
1637 dpyinfo->color_cells[i].pixel = i; 1670 dpyinfo->color_cells[i].pixel = i;
1638 1671
1639 XQueryColors (dpy, dpyinfo->cmap, 1672 XQueryColors (dpy, dpyinfo->cmap,
1640 dpyinfo->color_cells, dpyinfo->ncolor_cells); 1673 dpyinfo->color_cells, ncolor_cells);
1641 } 1674 }
1642 1675
1643 *ncells = dpyinfo->ncolor_cells; 1676 *ncells = dpyinfo->ncolor_cells;
@@ -4190,7 +4223,7 @@ xt_action_hook (Widget widget, XtPointer client_data, String action_name,
4190 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */ 4223 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4191 4224
4192static struct window **scroll_bar_windows; 4225static struct window **scroll_bar_windows;
4193static size_t scroll_bar_windows_size; 4226static ptrdiff_t scroll_bar_windows_size;
4194 4227
4195 4228
4196/* Send a client message with message type Xatom_Scrollbar for a 4229/* Send a client message with message type Xatom_Scrollbar for a
@@ -4205,7 +4238,7 @@ x_send_scroll_bar_event (Lisp_Object window, int part, int portion, int whole)
4205 XClientMessageEvent *ev = (XClientMessageEvent *) &event; 4238 XClientMessageEvent *ev = (XClientMessageEvent *) &event;
4206 struct window *w = XWINDOW (window); 4239 struct window *w = XWINDOW (window);
4207 struct frame *f = XFRAME (w->frame); 4240 struct frame *f = XFRAME (w->frame);
4208 size_t i; 4241 ptrdiff_t i;
4209 4242
4210 BLOCK_INPUT; 4243 BLOCK_INPUT;
4211 4244
@@ -4226,16 +4259,15 @@ x_send_scroll_bar_event (Lisp_Object window, int part, int portion, int whole)
4226 4259
4227 if (i == scroll_bar_windows_size) 4260 if (i == scroll_bar_windows_size)
4228 { 4261 {
4229 size_t new_size = max (10, 2 * scroll_bar_windows_size); 4262 ptrdiff_t old_nbytes =
4230 size_t nbytes = new_size * sizeof *scroll_bar_windows; 4263 scroll_bar_windows_size * sizeof *scroll_bar_windows;
4231 size_t old_nbytes = scroll_bar_windows_size * sizeof *scroll_bar_windows; 4264 ptrdiff_t nbytes;
4232 4265 enum { XClientMessageEvent_MAX = 0x7fffffff };
4233 if ((size_t) -1 / sizeof *scroll_bar_windows < new_size) 4266 scroll_bar_windows =
4234 memory_full (SIZE_MAX); 4267 xpalloc (scroll_bar_windows, &scroll_bar_windows_size, 1,
4235 scroll_bar_windows = (struct window **) xrealloc (scroll_bar_windows, 4268 XClientMessageEvent_MAX, sizeof *scroll_bar_windows);
4236 nbytes); 4269 nbytes = scroll_bar_windows_size * sizeof *scroll_bar_windows;
4237 memset (&scroll_bar_windows[i], 0, nbytes - old_nbytes); 4270 memset (&scroll_bar_windows[i], 0, nbytes - old_nbytes);
4238 scroll_bar_windows_size = new_size;
4239 } 4271 }
4240 4272
4241 scroll_bar_windows[i] = w; 4273 scroll_bar_windows[i] = w;
@@ -5813,11 +5845,12 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
5813 } inev; 5845 } inev;
5814 int count = 0; 5846 int count = 0;
5815 int do_help = 0; 5847 int do_help = 0;
5816 int nbytes = 0; 5848 ptrdiff_t nbytes = 0;
5817 struct frame *f = NULL; 5849 struct frame *f = NULL;
5818 struct coding_system coding; 5850 struct coding_system coding;
5819 XEvent event = *eventptr; 5851 XEvent event = *eventptr;
5820 Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight; 5852 Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight;
5853 USE_SAFE_ALLOCA;
5821 5854
5822 *finish = X_EVENT_NORMAL; 5855 *finish = X_EVENT_NORMAL;
5823 5856
@@ -6088,6 +6121,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6088 /* Perhaps reparented due to a WM restart. Reset this. */ 6121 /* Perhaps reparented due to a WM restart. Reset this. */
6089 FRAME_X_DISPLAY_INFO (f)->wm_type = X_WMTYPE_UNKNOWN; 6122 FRAME_X_DISPLAY_INFO (f)->wm_type = X_WMTYPE_UNKNOWN;
6090 FRAME_X_DISPLAY_INFO (f)->net_supported_window = 0; 6123 FRAME_X_DISPLAY_INFO (f)->net_supported_window = 0;
6124
6125 x_set_frame_alpha (f);
6091 } 6126 }
6092 goto OTHER; 6127 goto OTHER;
6093 6128
@@ -6511,7 +6546,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6511 } 6546 }
6512 6547
6513 { /* Raw bytes, not keysym. */ 6548 { /* Raw bytes, not keysym. */
6514 register int i; 6549 ptrdiff_t i;
6515 int nchars, len; 6550 int nchars, len;
6516 6551
6517 for (i = 0, nchars = 0; i < nbytes; i++) 6552 for (i = 0, nchars = 0; i < nbytes; i++)
@@ -6524,7 +6559,6 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6524 if (nchars < nbytes) 6559 if (nchars < nbytes)
6525 { 6560 {
6526 /* Decode the input data. */ 6561 /* Decode the input data. */
6527 int require;
6528 6562
6529 /* The input should be decoded with `coding_system' 6563 /* The input should be decoded with `coding_system'
6530 which depends on which X*LookupString function 6564 which depends on which X*LookupString function
@@ -6537,9 +6571,9 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6537 gives us composition information. */ 6571 gives us composition information. */
6538 coding.common_flags &= ~CODING_ANNOTATION_MASK; 6572 coding.common_flags &= ~CODING_ANNOTATION_MASK;
6539 6573
6540 require = MAX_MULTIBYTE_LENGTH * nbytes; 6574 SAFE_NALLOCA (coding.destination, MAX_MULTIBYTE_LENGTH,
6541 coding.destination = alloca (require); 6575 nbytes);
6542 coding.dst_bytes = require; 6576 coding.dst_bytes = MAX_MULTIBYTE_LENGTH * nbytes;
6543 coding.mode |= CODING_MODE_LAST_BLOCK; 6577 coding.mode |= CODING_MODE_LAST_BLOCK;
6544 decode_coding_c_string (&coding, copy_bufptr, nbytes, Qnil); 6578 decode_coding_c_string (&coding, copy_bufptr, nbytes, Qnil);
6545 nbytes = coding.produced; 6579 nbytes = coding.produced;
@@ -6998,6 +7032,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6998 count++; 7032 count++;
6999 } 7033 }
7000 7034
7035 SAFE_FREE ();
7001 *eventptr = event; 7036 *eventptr = event;
7002 return count; 7037 return count;
7003} 7038}
@@ -9822,6 +9857,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
9822 struct x_display_info *dpyinfo; 9857 struct x_display_info *dpyinfo;
9823 XrmDatabase xrdb; 9858 XrmDatabase xrdb;
9824 Mouse_HLInfo *hlinfo; 9859 Mouse_HLInfo *hlinfo;
9860 ptrdiff_t lim;
9825 9861
9826 BLOCK_INPUT; 9862 BLOCK_INPUT;
9827 9863
@@ -10040,12 +10076,15 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10040 XSetAfterFunction (x_current_display, x_trace_wire); 10076 XSetAfterFunction (x_current_display, x_trace_wire);
10041#endif /* ! 0 */ 10077#endif /* ! 0 */
10042 10078
10079 lim = min (PTRDIFF_MAX, SIZE_MAX) - sizeof "@";
10080 if (lim - SBYTES (Vinvocation_name) < SBYTES (Vsystem_name))
10081 memory_full (SIZE_MAX);
10043 dpyinfo->x_id_name 10082 dpyinfo->x_id_name
10044 = (char *) xmalloc (SBYTES (Vinvocation_name) 10083 = (char *) xmalloc (SBYTES (Vinvocation_name)
10045 + SBYTES (Vsystem_name) 10084 + SBYTES (Vsystem_name)
10046 + 2); 10085 + 2);
10047 sprintf (dpyinfo->x_id_name, "%s@%s", 10086 strcat (strcat (strcpy (dpyinfo->x_id_name, SSDATA (Vinvocation_name)), "@"),
10048 SSDATA (Vinvocation_name), SSDATA (Vsystem_name)); 10087 SSDATA (Vsystem_name));
10049 10088
10050 /* Figure out which modifier bits mean what. */ 10089 /* Figure out which modifier bits mean what. */
10051 x_find_modifier_meanings (dpyinfo); 10090 x_find_modifier_meanings (dpyinfo);