comparison src/frame-x.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 6719134a07c2
children 2f8bb876ab1d
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
101 /* Like x_window_to_frame but also compares the window with the widget's 101 /* Like x_window_to_frame but also compares the window with the widget's
102 windows */ 102 windows */
103 struct frame * 103 struct frame *
104 x_any_window_to_frame (struct device *d, Window wdesc) 104 x_any_window_to_frame (struct device *d, Window wdesc)
105 { 105 {
106 Widget w;
107 assert (DEVICE_X_P (d));
108
109 w = XtWindowToWidget (DEVICE_X_DISPLAY (d), wdesc);
110
111 if (!w)
112 return 0;
113
114 /* We used to map over all frames here and then map over all widgets
115 belonging to that frame. However it turns out that this was very fragile
116 as it requires our display stuctures to be in sync _and_ that the
117 loop is told about every new widget somebody adds. Therefore we
118 now let Xt find it for us (which does a bottom-up search which
119 could even be faster) */
120 return x_any_widget_or_parent_to_frame (d, w);
121 }
122
123 static struct frame *
124 x_find_frame_for_window (struct device *d, Window wdesc)
125 {
106 Lisp_Object tail, frame; 126 Lisp_Object tail, frame;
107 struct frame *f; 127 struct frame *f;
108
109 assert (DEVICE_X_P (d));
110
111 /* This function was previously written to accept only a window argument 128 /* This function was previously written to accept only a window argument
112 (and to loop over all devices looking for a matching window), but 129 (and to loop over all devices looking for a matching window), but
113 that is incorrect because window ID's are not unique across displays. */ 130 that is incorrect because window ID's are not unique across displays. */
114 131
115 for (tail = DEVICE_FRAME_LIST (d); CONSP (tail); tail = XCDR (tail)) 132 for (tail = DEVICE_FRAME_LIST (d); CONSP (tail); tail = XCDR (tail))
116 { 133 {
117 int i;
118
119 frame = XCAR (tail); 134 frame = XCAR (tail);
120 f = XFRAME (frame); 135 f = XFRAME (frame);
121 /* This frame matches if the window is any of its widgets. */ 136 /* This frame matches if the window is any of its widgets. */
122 if (wdesc == XtWindow (FRAME_X_SHELL_WIDGET (f)) || 137 if (wdesc == XtWindow (FRAME_X_SHELL_WIDGET (f)) ||
123 wdesc == XtWindow (FRAME_X_CONTAINER_WIDGET (f)) || 138 wdesc == XtWindow (FRAME_X_CONTAINER_WIDGET (f)) ||
136 for this statement is that, in the old (broken) event loop, where 151 for this statement is that, in the old (broken) event loop, where
137 not all events went through XtDispatchEvent(), psheet events 152 not all events went through XtDispatchEvent(), psheet events
138 would incorrectly get sucked away by Emacs if this function matched 153 would incorrectly get sucked away by Emacs if this function matched
139 on psheet widgets. */ 154 on psheet widgets. */
140 155
141 for (i = 0; i < FRAME_X_NUM_TOP_WIDGETS (f); i++) 156 /* Note: that this called only from
142 { 157 x_any_widget_or_parent_to_frame it is unnecessary to iterate
143 Widget wid = FRAME_X_TOP_WIDGETS (f)[i]; 158 over the top level widgets. */
144 if (wid && XtIsManaged (wid) && wdesc == XtWindow (wid)) 159
145 return f; 160 /* Note: we use to special case scrollbars but this turns out to be a bad idea
146 } 161 because
147 162 1. We sometimes get events for _unmapped_ scrollbars and our
148 #ifdef HAVE_SCROLLBARS 163 callers don't want us to fail.
149 /* Match if the window is one of this frame's scrollbars. */ 164 2. Starting with the 21.2 widget stuff there are now loads of
150 if (x_window_is_scrollbar (f, wdesc)) 165 widgets to check and it is easy to forget adding them in a loop here.
151 return f; 166 See x_any_window_to_frame
152 #endif 167 3. We pick up all widgets now anyway. */
153 } 168 }
154 169
155 return 0; 170 return 0;
156 } 171 }
157 172
158 struct frame * 173 struct frame *
159 x_any_widget_or_parent_to_frame (struct device *d, Widget widget) 174 x_any_widget_or_parent_to_frame (struct device *d, Widget widget)
160 { 175 {
161 while (widget) 176 while (widget)
162 { 177 {
163 struct frame *f = x_any_window_to_frame (d, XtWindow (widget)); 178 struct frame *f = x_find_frame_for_window (d, XtWindow (widget));
164 if (f) 179 if (f)
165 return f; 180 return f;
166 widget = XtParent (widget); 181 widget = XtParent (widget);
167 } 182 }
168 183
326 classhint.res_name = frame_name; 341 classhint.res_name = frame_name;
327 classhint.res_class = app_class; 342 classhint.res_class = app_class;
328 XSetClassHint (dpy, XtWindow (shell), &classhint); 343 XSetClassHint (dpy, XtWindow (shell), &classhint);
329 } 344 }
330 345
331 #ifndef HAVE_SESSION 346 #ifndef HAVE_WMCOMMAND
332 static void 347 static void
333 x_wm_maybe_store_wm_command (struct frame *f) 348 x_wm_maybe_store_wm_command (struct frame *f)
334 { 349 {
335 Widget w = FRAME_X_SHELL_WIDGET (f); 350 Widget w = FRAME_X_SHELL_WIDGET (f);
336 struct device *d = XDEVICE (FRAME_DEVICE (f)); 351 struct device *d = XDEVICE (FRAME_DEVICE (f));
377 392
378 x_wm_maybe_store_wm_command (f); 393 x_wm_maybe_store_wm_command (f);
379 394
380 } 395 }
381 } 396 }
382 #endif /* !HAVE_SESSION */ 397 #endif /* !HAVE_WMCOMMAND */
383 398
384 static int 399 static int
385 x_frame_iconified_p (struct frame *f) 400 x_frame_iconified_p (struct frame *f)
386 { 401 {
387 Atom actual_type; 402 Atom actual_type;
419 434
420 static void 435 static void
421 init_x_prop_symbols (void) 436 init_x_prop_symbols (void)
422 { 437 {
423 #define def(sym, rsrc) \ 438 #define def(sym, rsrc) \
424 pure_put (sym, Qx_resource_name, build_string (rsrc)) 439 Fput (sym, Qx_resource_name, build_string (rsrc))
425 #define defi(sym,rsrc) \ 440 #define defi(sym,rsrc) \
426 def (sym, rsrc); pure_put (sym, Qintegerp, Qt) 441 def (sym, rsrc); Fput (sym, Qintegerp, Qt)
427 442
428 #if 0 /* this interferes with things. #### fix this right */ 443 #if 0 /* this interferes with things. #### fix this right */
429 def (Qminibuffer, XtNminibuffer); 444 def (Qminibuffer, XtNminibuffer);
430 def (Qunsplittable, XtNunsplittable); 445 def (Qunsplittable, XtNunsplittable);
431 #endif 446 #endif
642 Bufbyte *ptr; 657 Bufbyte *ptr;
643 /* Optimize for common ASCII case */ 658 /* Optimize for common ASCII case */
644 for (ptr = value; *ptr; ptr++) 659 for (ptr = value; *ptr; ptr++)
645 if (!BYTE_ASCII_P (*ptr)) 660 if (!BYTE_ASCII_P (*ptr))
646 { 661 {
647 CONST char * tmp; 662 const char * tmp;
648 encoding = DEVICE_XATOM_COMPOUND_TEXT (XDEVICE (FRAME_DEVICE (f))); 663 encoding = DEVICE_XATOM_COMPOUND_TEXT (XDEVICE (FRAME_DEVICE (f)));
649 GET_C_CHARPTR_EXT_CTEXT_DATA_ALLOCA ((CONST char *) value, tmp); 664 TO_EXTERNAL_FORMAT (C_STRING, value,
665 C_STRING_ALLOCA, tmp,
666 Qctext);
650 new_XtValue = (String) tmp; 667 new_XtValue = (String) tmp;
651 break; 668 break;
652 } 669 }
653 #endif /* MULE */ 670 #endif /* MULE */
654 671
655 /* ### Caching is device-independent - belongs in update_frame_title. */ 672 /* #### Caching is device-independent - belongs in update_frame_title. */
656 Xt_GET_VALUE (FRAME_X_SHELL_WIDGET (f), Xt_resource_name, &old_XtValue); 673 Xt_GET_VALUE (FRAME_X_SHELL_WIDGET (f), Xt_resource_name, &old_XtValue);
657 if (!old_XtValue || strcmp (new_XtValue, old_XtValue)) 674 if (!old_XtValue || strcmp (new_XtValue, old_XtValue))
658 { 675 {
659 Arg al[2]; 676 Arg al[2];
660 XtSetArg (al[0], Xt_resource_name, new_XtValue); 677 XtSetArg (al[0], Xt_resource_name, new_XtValue);
741 Lisp_Object prop = Fcar (tail); 758 Lisp_Object prop = Fcar (tail);
742 Lisp_Object val = Fcar (Fcdr (tail)); 759 Lisp_Object val = Fcar (Fcdr (tail));
743 760
744 if (STRINGP (prop)) 761 if (STRINGP (prop))
745 { 762 {
746 CONST char *extprop; 763 const char *extprop;
747 764
748 if (XSTRING_LENGTH (prop) == 0) 765 if (XSTRING_LENGTH (prop) == 0)
749 continue; 766 continue;
750 767
751 GET_C_STRING_CTEXT_DATA_ALLOCA (prop, extprop); 768 TO_EXTERNAL_FORMAT (LISP_STRING, prop,
769 C_STRING_ALLOCA, extprop,
770 Qctext);
752 if (STRINGP (val)) 771 if (STRINGP (val))
753 { 772 {
754 CONST Extbyte *extval; 773 const Extbyte *extval;
755 Extcount extvallen; 774 Extcount extvallen;
756 775
757 GET_STRING_CTEXT_DATA_ALLOCA (val, extval, extvallen); 776 TO_EXTERNAL_FORMAT (LISP_STRING, val,
777 ALLOCA, (extval, extvallen),
778 Qctext);
758 XtVaSetValues (w, XtVaTypedArg, extprop, 779 XtVaSetValues (w, XtVaTypedArg, extprop,
759 XtRString, extval, extvallen + 1, 780 XtRString, extval, extvallen + 1,
760 (XtArgVal) NULL); 781 (XtArgVal) NULL);
761 } 782 }
762 else 783 else
1086 struct x_device *xd = DEVICE_X_DATA (d); 1107 struct x_device *xd = DEVICE_X_DATA (d);
1087 XWindowAttributes win_attrib; 1108 XWindowAttributes win_attrib;
1088 unsigned int modifier = 0, state = 0; 1109 unsigned int modifier = 0, state = 0;
1089 char *Ctext; 1110 char *Ctext;
1090 int numItems = 0, textlen = 0, pos = 0; 1111 int numItems = 0, textlen = 0, pos = 0;
1091 struct Lisp_Event *lisp_event = XEVENT(event); 1112 Lisp_Event *lisp_event = XEVENT (event);
1092 Lisp_Object item = Qnil; 1113 Lisp_Object item = Qnil;
1093 struct gcpro gcpro1; 1114 struct gcpro gcpro1;
1094 1115
1095 /* only drag if this is really a press */ 1116 /* only drag if this is really a press */
1096 if (EVENT_TYPE(lisp_event) != button_press_event 1117 if (EVENT_TYPE(lisp_event) != button_press_event
1168 numItems=0; 1189 numItems=0;
1169 xfree(Ctext); 1190 xfree(Ctext);
1170 Ctext=NULL; 1191 Ctext=NULL;
1171 break; 1192 break;
1172 } 1193 }
1173 strcpy (Ctext+pos, (CONST char *)XSTRING_DATA (XCAR (item))); 1194 strcpy (Ctext+pos, (const char *)XSTRING_DATA (XCAR (item)));
1174 pos += XSTRING_LENGTH (XCAR (item)) + 1; 1195 pos += XSTRING_LENGTH (XCAR (item)) + 1;
1175 item = XCDR (item); 1196 item = XCDR (item);
1176 } 1197 }
1177 Ctext[pos] = 0; 1198 Ctext[pos] = 0;
1178 1199
1238 1259
1239 for (ii = 0; ii < transferInfo->dropData->numItems; ii++) 1260 for (ii = 0; ii < transferInfo->dropData->numItems; ii++)
1240 { 1261 {
1241 filePath = transferInfo->dropData->data.files[ii]; 1262 filePath = transferInfo->dropData->data.files[ii];
1242 hurl = dnd_url_hexify_string ((char *)filePath, "file:"); 1263 hurl = dnd_url_hexify_string ((char *)filePath, "file:");
1243 /* ### Mule-izing required */ 1264 /* #### Mule-izing required */
1244 l_data = Fcons (make_string ((Bufbyte* )hurl, 1265 l_data = Fcons (make_string ((Bufbyte* )hurl,
1245 strlen (hurl)), 1266 strlen (hurl)),
1246 l_data); 1267 l_data);
1247 xfree (hurl); 1268 xfree (hurl);
1248 } 1269 }
1313 XWindowAttributes win_attrib; 1334 XWindowAttributes win_attrib;
1314 unsigned int modifier = 0, state = 0; 1335 unsigned int modifier = 0, state = 0;
1315 char *dnd_data = NULL; 1336 char *dnd_data = NULL;
1316 unsigned long dnd_len = 0; 1337 unsigned long dnd_len = 0;
1317 int dnd_typ = DndText, dnd_dealloc = 0; 1338 int dnd_typ = DndText, dnd_dealloc = 0;
1318 struct Lisp_Event *lisp_event = XEVENT(event); 1339 Lisp_Event *lisp_event = XEVENT (event);
1319 1340
1320 /* only drag if this is really a press */ 1341 /* only drag if this is really a press */
1321 if (EVENT_TYPE(lisp_event) != button_press_event) 1342 if (EVENT_TYPE(lisp_event) != button_press_event)
1322 return Qnil; 1343 return Qnil;
1323 1344
1344 xfree (dnd_data); 1365 xfree (dnd_data);
1345 return Qnil; 1366 return Qnil;
1346 } 1367 }
1347 len = XSTRING_LENGTH (XCAR (run)) + 1; 1368 len = XSTRING_LENGTH (XCAR (run)) + 1;
1348 dnd_data = (char *) xrealloc (dnd_data, dnd_len + len); 1369 dnd_data = (char *) xrealloc (dnd_data, dnd_len + len);
1349 strcpy (dnd_data + dnd_len - 1, (CONST char *)XSTRING_DATA (XCAR (run))); 1370 strcpy (dnd_data + dnd_len - 1, (const char *)XSTRING_DATA (XCAR (run)));
1350 dnd_len += len; 1371 dnd_len += len;
1351 run = XCDR (run); 1372 run = XCDR (run);
1352 } 1373 }
1353 1374
1354 dnd_data[dnd_len - 1] = 0; /* the list-ending zero */ 1375 dnd_data[dnd_len - 1] = 0; /* the list-ending zero */
1838 int depth = DEVICE_X_DEPTH (d); 1859 int depth = DEVICE_X_DEPTH (d);
1839 Colormap cmap = DEVICE_X_COLORMAP (d); 1860 Colormap cmap = DEVICE_X_COLORMAP (d);
1840 #ifdef EXTERNAL_WIDGET 1861 #ifdef EXTERNAL_WIDGET
1841 Window window_id = 0; 1862 Window window_id = 0;
1842 #endif 1863 #endif
1843 CONST char *name; 1864 const char *name;
1844 Arg al [25]; 1865 Arg al [25];
1845 int ac = 0; 1866 int ac = 0;
1846 Widget text, container, shell; 1867 Widget text, container, shell;
1847 Widget parentwid = 0; 1868 Widget parentwid = 0;
1848 #ifdef HAVE_MENUBARS 1869 #ifdef HAVE_MENUBARS
1849 int menubar_visible; 1870 int menubar_visible;
1850 Widget menubar; 1871 Widget menubar;
1851 #endif 1872 #endif
1852 1873
1853 if (STRINGP (f->name)) 1874 if (STRINGP (f->name))
1854 GET_C_STRING_CTEXT_DATA_ALLOCA (f->name, name); 1875 TO_EXTERNAL_FORMAT (LISP_STRING, f->name,
1876 C_STRING_ALLOCA, name,
1877 Qctext);
1855 else 1878 else
1856 name = "emacs"; 1879 name = "emacs";
1857 1880
1858 /* The widget hierarchy is 1881 /* The widget hierarchy is
1859 1882
1878 if (!NILP (lisp_window_id)) 1901 if (!NILP (lisp_window_id))
1879 { 1902 {
1880 char *string; 1903 char *string;
1881 1904
1882 CHECK_STRING (lisp_window_id); 1905 CHECK_STRING (lisp_window_id);
1883 string = (char *) (XSTRING_DATA (lisp_window_id)); 1906 string = (char *) XSTRING_DATA (lisp_window_id);
1884 if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X')) 1907 if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X'))
1885 sscanf (string+2, "%lxu", &window_id); 1908 sscanf (string+2, "%lxu", &window_id);
1886 #if 0 1909 #if 0
1887 else if (string[0] == 'w') 1910 else if (string[0] == 'w')
1888 { 1911 {
2057 if (FRAME_X_TOP_LEVEL_FRAME_P (f)) 2080 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
2058 { 2081 {
2059 /* tell the window manager about us. */ 2082 /* tell the window manager about us. */
2060 x_wm_store_class_hints (shell_widget, XtName (frame_widget)); 2083 x_wm_store_class_hints (shell_widget, XtName (frame_widget));
2061 2084
2062 #ifndef HAVE_SESSION 2085 #ifndef HAVE_WMCOMMAND
2063 x_wm_maybe_store_wm_command (f); 2086 x_wm_maybe_store_wm_command (f);
2064 #endif /* HAVE_SESSION */ 2087 #endif /* HAVE_WMCOMMAND */
2065 2088
2066 x_wm_hack_wm_protocols (shell_widget); 2089 x_wm_hack_wm_protocols (shell_widget);
2067 } 2090 }
2068 2091
2069 #ifdef HAVE_XIM 2092 #ifdef HAVE_XIM
2188 2211
2189 x_popup_frame (f); 2212 x_popup_frame (f);
2190 } 2213 }
2191 2214
2192 static void 2215 static void
2193 x_mark_frame (struct frame *f, void (*markobj) (Lisp_Object)) 2216 x_mark_frame (struct frame *f)
2194 { 2217 {
2195 markobj (FRAME_X_ICON_PIXMAP (f)); 2218 mark_object (FRAME_X_ICON_PIXMAP (f));
2196 markobj (FRAME_X_ICON_PIXMAP_MASK (f)); 2219 mark_object (FRAME_X_ICON_PIXMAP_MASK (f));
2197 } 2220 }
2198 2221
2199 static void 2222 static void
2200 x_set_frame_icon (struct frame *f) 2223 x_set_frame_icon (struct frame *f)
2201 { 2224 {
2623 static void 2646 static void
2624 x_delete_frame (struct frame *f) 2647 x_delete_frame (struct frame *f)
2625 { 2648 {
2626 Display *dpy; 2649 Display *dpy;
2627 2650
2628 #ifndef HAVE_SESSION 2651 #ifndef HAVE_WMCOMMAND
2629 if (FRAME_X_TOP_LEVEL_FRAME_P (f)) 2652 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
2630 x_wm_maybe_move_wm_command (f); 2653 x_wm_maybe_move_wm_command (f);
2631 #endif /* HAVE_SESSION */ 2654 #endif /* HAVE_WMCOMMAND */
2632 2655
2633 #ifdef HAVE_CDE 2656 #ifdef HAVE_CDE
2634 DtDndDropUnregister (FRAME_X_TEXT_WIDGET (f)); 2657 DtDndDropUnregister (FRAME_X_TEXT_WIDGET (f));
2635 #endif /* HAVE_CDE */ 2658 #endif /* HAVE_CDE */
2636 2659
2647 XtDestroyWidget (FRAME_X_SHELL_WIDGET (f)); 2670 XtDestroyWidget (FRAME_X_SHELL_WIDGET (f));
2648 x_error_occurred_p (XtDisplay (FRAME_X_SHELL_WIDGET (f))); 2671 x_error_occurred_p (XtDisplay (FRAME_X_SHELL_WIDGET (f)));
2649 #else 2672 #else
2650 XtDestroyWidget (FRAME_X_SHELL_WIDGET (f)); 2673 XtDestroyWidget (FRAME_X_SHELL_WIDGET (f));
2651 /* make sure the windows are really gone! */ 2674 /* make sure the windows are really gone! */
2652 /* ### Is this REALLY necessary? */ 2675 /* #### Is this REALLY necessary? */
2653 XFlush (dpy); 2676 XFlush (dpy);
2654 #endif /* EXTERNAL_WIDGET */ 2677 #endif /* EXTERNAL_WIDGET */
2655 2678
2656 FRAME_X_SHELL_WIDGET (f) = 0; 2679 FRAME_X_SHELL_WIDGET (f) = 0;
2657 2680