* Re: check_window_system
2013-04-05 15:21 ` check_window_system Stefan Monnier
@ 2013-04-06 10:13 ` Dmitry Antipov
2013-04-06 12:19 ` check_window_system Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Antipov @ 2013-04-06 10:13 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Eli Zaretskii, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 755 bytes --]
On 04/05/2013 07:21 PM, Stefan Monnier wrote:
>> Thus, after the changes above, we have 4 different implementations of
>> the same function check_window_system, which means it would be
> [...]
>> etc., you get the idea. IOW, there should be no assumption that X,
>> NS, and w32 are mutually exclusive.
>
> Right: 4 implementations of the same function is a problem in itself
> (we have this problem in several places in Emacs, but we should try to
> get rid of them, rather than add more).
OK. It looks like that we can also try to drop have_menus_p, check_x_frame,
check_ns_frame plus (x|w32)_in_use.
This looks good enough for X and TTY; I'm willing to add some comments,
commit and get my portion of blame for broken W32 and NS ports :-).
Dmitry
[-- Attachment #2: window_system_stuff.patch --]
[-- Type: text/plain, Size: 38607 bytes --]
=== modified file 'src/fileio.c'
--- src/fileio.c 2013-04-02 01:54:56 +0000
+++ src/fileio.c 2013-04-06 05:54:42 +0000
@@ -5816,7 +5816,7 @@
if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
&& use_dialog_box
&& use_file_dialog
- && have_menus_p ())
+ && window_system_available (SELECTED_FRAME ()))
return Qt;
#endif
return Qnil;
=== modified file 'src/fns.c'
--- src/fns.c 2013-04-02 01:54:56 +0000
+++ src/fns.c 2013-04-06 05:54:42 +0000
@@ -2443,10 +2443,9 @@
CHECK_STRING (prompt);
#ifdef HAVE_MENUS
- if (FRAME_WINDOW_P (SELECTED_FRAME ())
- && (NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
+ if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
&& use_dialog_box
- && have_menus_p ())
+ && window_system_available (SELECTED_FRAME ()))
{
Lisp_Object pane, menu, obj;
redisplay_preserve_echo_area (4);
=== modified file 'src/font.c'
--- src/font.c 2013-04-05 14:07:02 +0000
+++ src/font.c 2013-04-06 06:03:04 +0000
@@ -4844,11 +4844,9 @@
Lisp_Object info;
Lisp_Object font_object;
- check_window_system ();
-
if (! FONTP (name))
CHECK_STRING (name);
- f = decode_live_frame (frame);
+ f = decode_window_system_frame (frame);
if (STRINGP (name))
{
=== modified file 'src/fontset.c'
--- src/fontset.c 2013-04-05 14:07:02 +0000
+++ src/fontset.c 2013-04-06 09:57:45 +0000
@@ -1209,7 +1209,7 @@
Lisp_Object fontset;
int id;
- check_window_system ();
+ check_window_system (NULL);
CHECK_STRING (pattern);
@@ -1915,8 +1915,7 @@
Lisp_Object val, elt;
int c, i, j, k;
- check_window_system ();
-
+ check_window_system (NULL);
fontset = check_fontset_name (fontset, &frame);
/* Recode fontsets realized on FRAME from the base fontset FONTSET
=== modified file 'src/frame.c'
--- src/frame.c 2013-04-05 14:07:02 +0000
+++ src/frame.c 2013-04-06 05:54:42 +0000
@@ -149,6 +149,36 @@
return XFRAME (frame);
}
+bool
+window_system_available (struct frame *f)
+{
+ if (f)
+ return FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f);
+ else
+#ifdef HAVE_WINDOW_SYSTEM
+ return x_display_list != NULL;
+#else
+ return 0;
+#endif
+}
+
+struct frame *
+decode_window_system_frame (Lisp_Object frame)
+{
+ struct frame *f = decode_live_frame (frame);
+
+ if (!window_system_available (f))
+ error ("Window system frame should be used");
+ return f;
+}
+
+void
+check_window_system (struct frame *f)
+{
+ if (!window_system_available (f))
+ error ("Window system is not in use or not initialized");
+}
+
static void
set_menu_bar_lines_1 (Lisp_Object window, int n)
{
@@ -3493,7 +3523,7 @@
(Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
Lisp_Object subclass)
{
- check_window_system ();
+ check_window_system (NULL);
return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
attribute, class, component, subclass);
=== modified file 'src/frame.h'
--- src/frame.h 2013-03-31 05:45:54 +0000
+++ src/frame.h 2013-04-06 05:55:27 +0000
@@ -958,6 +958,7 @@
extern struct frame *last_nonminibuf_frame;
extern void set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
+extern struct frame *decode_window_system_frame (Lisp_Object);
extern struct frame *decode_live_frame (Lisp_Object);
extern struct frame *decode_any_frame (Lisp_Object);
extern struct frame *make_initial_frame (void);
@@ -968,6 +969,8 @@
struct kboard *,
Lisp_Object);
#endif /* HAVE_WINDOW_SYSTEM */
+extern bool window_system_available (struct frame *);
+extern void check_window_system (struct frame *);
extern void frame_make_pointer_invisible (void);
extern void frame_make_pointer_visible (void);
extern Lisp_Object delete_frame (Lisp_Object, Lisp_Object);
=== modified file 'src/image.c'
--- src/image.c 2013-03-28 06:40:01 +0000
+++ src/image.c 2013-04-06 05:54:43 +0000
@@ -889,7 +889,7 @@
size = Qnil;
if (valid_image_p (spec))
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
ptrdiff_t id = lookup_image (f, spec);
struct image *img = IMAGE_FROM_ID (f, id);
int width = img->width + 2 * img->hmargin;
@@ -919,7 +919,7 @@
mask = Qnil;
if (valid_image_p (spec))
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
ptrdiff_t id = lookup_image (f, spec);
struct image *img = IMAGE_FROM_ID (f, id);
if (img->mask)
@@ -942,7 +942,7 @@
ext = Qnil;
if (valid_image_p (spec))
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
ptrdiff_t id = lookup_image (f, spec);
struct image *img = IMAGE_FROM_ID (f, id);
ext = img->lisp_data;
@@ -1550,7 +1550,7 @@
if (!(EQ (filter, Qnil) || FRAMEP (filter)))
clear_image_caches (filter);
else
- clear_image_cache (check_x_frame (filter), Qt);
+ clear_image_cache (decode_window_system_frame (filter), Qt);
return Qnil;
}
@@ -1581,7 +1581,7 @@
}
}
else
- uncache_image (check_x_frame (frame), spec);
+ uncache_image (decode_window_system_frame (frame), spec);
return Qnil;
}
=== modified file 'src/lisp.h'
--- src/lisp.h 2013-04-05 14:07:02 +0000
+++ src/lisp.h 2013-04-06 05:12:17 +0000
@@ -3765,22 +3765,12 @@
extern char *x_get_keysym_name (int);
#endif /* HAVE_WINDOW_SYSTEM */
-#if defined(HAVE_WINDOW_SYSTEM) || defined (MSDOS)
-/* Defined in (x|w32)fns.c, nsfns.m, msdos.c. */
-extern void check_window_system (void);
-#endif
-
#ifdef HAVE_LIBXML2
/* Defined in xml.c. */
extern void syms_of_xml (void);
extern void xml_cleanup_parser (void);
#endif
-#ifdef HAVE_MENUS
-/* Defined in (x|w32)fns.c, nsfns.m, msdos.c. */
-extern int have_menus_p (void);
-#endif
-
#ifdef HAVE_DBUS
/* Defined in dbusbind.c. */
void syms_of_dbusbind (void);
=== modified file 'src/menu.c'
--- src/menu.c 2013-04-05 14:07:02 +0000
+++ src/menu.c 2013-04-06 05:54:43 +0000
@@ -1086,7 +1086,7 @@
{
bool get_current_pos_p = 0;
- check_window_system ();
+ check_window_system (SELECTED_FRAME ());
/* Decode the first argument: find the window and the coordinates. */
if (EQ (position, Qt)
=== modified file 'src/msdos.c'
--- src/msdos.c 2013-04-05 14:07:02 +0000
+++ src/msdos.c 2013-04-06 06:09:03 +0000
@@ -2983,11 +2983,6 @@
\f
/* --------------------------- X Menu emulation ---------------------- */
-/* Report availability of menus. */
-
-int
-have_menus_p (void) { return 1; }
-
/* Create a brand new menu structure. */
XMenu *
=== modified file 'src/nsfns.m'
--- src/nsfns.m 2013-04-05 14:07:02 +0000
+++ src/nsfns.m 2013-04-06 09:36:35 +0000
@@ -107,43 +107,6 @@
========================================================================== */
-
-void
-check_window_system (void)
-{
- if (NSApp == nil)
- error ("OpenStep is not in use or not initialized");
-}
-
-
-/* Nonzero if we can use mouse menus. */
-int
-have_menus_p (void)
-{
- return NSApp != nil;
-}
-
-
-/* Extract a frame as a FRAME_PTR, defaulting to the selected frame
- and checking validity for NS. */
-static FRAME_PTR
-check_ns_frame (Lisp_Object frame)
-{
- FRAME_PTR f;
-
- if (NILP (frame))
- f = SELECTED_FRAME ();
- else
- {
- CHECK_LIVE_FRAME (frame);
- f = XFRAME (frame);
- }
- if (! FRAME_NS_P (f))
- error ("non-Nextstep frame used");
- return f;
-}
-
-
/* Let the user specify an Nextstep display with a frame.
nil stands for the selected frame--or, if that is not an Nextstep frame,
the first Nextstep display on the list. */
@@ -1145,8 +1108,6 @@
Lisp_Object tfont, tfontsize;
static int desc_ctr = 1;
- check_window_system ();
-
/* x_get_arg modifies parms. */
parms = Fcopy_alist (parms);
@@ -1418,7 +1379,7 @@
FRAME nil means use the selected frame. */)
(Lisp_Object frame)
{
- struct frame *f = check_ns_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f);
if (dpyinfo->x_focus_frame != f)
@@ -1439,18 +1400,8 @@
doc: /* Pop up the font panel. */)
(Lisp_Object frame)
{
- id fm;
- struct frame *f;
-
- check_window_system ();
- fm = [NSFontManager sharedFontManager];
- if (NILP (frame))
- f = SELECTED_FRAME ();
- else
- {
- CHECK_FRAME (frame);
- f = XFRAME (frame);
- }
+ struct frame *f = decode_window_system_frame (frame);
+ id fm = [NSFontManager sharedFontManager];
[fm setSelectedFont: ((struct nsfont_info *)f->output_data.ns->font)->nsfont
isMultiple: NO];
@@ -1464,17 +1415,7 @@
doc: /* Pop up the color panel. */)
(Lisp_Object frame)
{
- struct frame *f;
-
- check_window_system ();
- if (NILP (frame))
- f = SELECTED_FRAME ();
- else
- {
- CHECK_FRAME (frame);
- f = XFRAME (frame);
- }
-
+ check_window_system (NULL);
[NSApp orderFrontColorPanel: NSApp];
return Qnil;
}
@@ -1503,7 +1444,7 @@
NSString *initS = NILP (init) || !STRINGP (init) ? nil :
[NSString stringWithUTF8String: SSDATA (init)];
- check_window_system ();
+ check_window_system (NULL);
if (fileDelegate == nil)
fileDelegate = [EmacsFileDelegate new];
@@ -1594,11 +1535,10 @@
{
const char *value;
- check_window_system ();
+ check_window_system (NULL);
if (NILP (owner))
owner = build_string([ns_app_name UTF8String]);
CHECK_STRING (name);
-/*fprintf (stderr, "ns-get-resource checking resource '%s'\n", SSDATA (name)); */
value = ns_get_defaults_value (SSDATA (name));
@@ -1614,7 +1554,7 @@
If VALUE is nil, the default is removed. */)
(Lisp_Object owner, Lisp_Object name, Lisp_Object value)
{
- check_window_system ();
+ check_window_system (NULL);
if (NILP (owner))
owner = build_string ([ns_app_name UTF8String]);
CHECK_STRING (name);
@@ -1642,7 +1582,7 @@
doc: /* This function is a no-op. It is only present for completeness. */)
(Lisp_Object display)
{
- check_window_system ();
+ check_ns_display_info (display);
/* This function has no real equivalent under NeXTstep. Return nil to
indicate this. */
return Qnil;
@@ -1692,7 +1632,7 @@
{
int num;
- check_window_system ();
+ check_ns_display_info (display);
num = [[NSScreen screens] count];
return (num != 0) ? make_number (num) : Qnil;
@@ -1706,7 +1646,7 @@
If omitted or nil, the selected frame's display is used. */)
(Lisp_Object display)
{
- check_window_system ();
+ check_ns_display_info (display);
return make_number ((int)
([ns_get_screen (display) frame].size.height/(92.0/25.4)));
}
@@ -1719,7 +1659,7 @@
If omitted or nil, the selected frame's display is used. */)
(Lisp_Object display)
{
- check_window_system ();
+ check_ns_display_info (display);
return make_number ((int)
([ns_get_screen (display) frame].size.width/(92.0/25.4)));
}
@@ -1733,7 +1673,7 @@
If omitted or nil, the selected frame's display is used. */)
(Lisp_Object display)
{
- check_window_system ();
+ check_ns_display_info (display);
switch ([ns_get_window (display) backingType])
{
case NSBackingStoreBuffered:
@@ -1759,7 +1699,8 @@
(Lisp_Object display)
{
NSWindowDepth depth;
- check_window_system ();
+
+ check_ns_display_info (display);
depth = [ns_get_screen (display) depth];
if ( depth == NSBestDepth (NSCalibratedWhiteColorSpace, 2, 2, YES, NULL))
@@ -1786,7 +1727,7 @@
If omitted or nil, the selected frame's display is used. */)
(Lisp_Object display)
{
- check_window_system ();
+ check_ns_display_info (display);
switch ([ns_get_window (display) backingType])
{
case NSBackingStoreBuffered:
@@ -1836,11 +1777,10 @@
DEFUN ("x-close-connection", Fx_close_connection, Sx_close_connection,
1, 1, 0,
doc: /* Close the connection to the current Nextstep display server.
-The argument DISPLAY is currently ignored. */)
+DISPLAY should be a frame, the display name as a string, or a terminal ID. */)
(Lisp_Object display)
{
- check_window_system ();
- /*ns_delete_terminal (dpyinfo->terminal); */
+ check_ns_display_info (display);
[NSApp terminate: NSApp];
return Qnil;
}
@@ -1865,7 +1805,7 @@
doc: /* Hides all applications other than Emacs. */)
(void)
{
- check_window_system ();
+ check_window_system (NULL);
[NSApp hideOtherApplications: NSApp];
return Qnil;
}
@@ -1878,7 +1818,7 @@
the active application. */)
(Lisp_Object on)
{
- check_window_system ();
+ check_window_system (NULL);
if (EQ (on, intern ("activate")))
{
[NSApp unhide: NSApp];
@@ -1897,7 +1837,7 @@
doc: /* Shows the 'Info' or 'About' panel for Emacs. */)
(void)
{
- check_window_system ();
+ check_window_system (NULL);
[NSApp orderFrontStandardAboutPanel: nil];
return Qnil;
}
@@ -1975,7 +1915,7 @@
NSMenu *svcs;
id delegate;
- check_window_system ();
+ check_window_system (NULL);
svcs = [[NSMenu alloc] initWithTitle: @"Services"];
[NSApp setServicesMenu: svcs];
[NSApp registerServicesMenuSendTypes: ns_send_types
@@ -2028,7 +1968,7 @@
char *utfStr;
CHECK_STRING (service);
- check_window_system ();
+ check_window_system (NULL);
utfStr = SSDATA (service);
svcName = [NSString stringWithUTF8String: utfStr];
@@ -2152,7 +2092,7 @@
NSEvent *nxev;
CHECK_STRING (script);
- check_window_system ();
+ check_window_system (NULL);
block_input ();
@@ -2201,15 +2141,6 @@
========================================================================== */
-
-/* called from image.c */
-FRAME_PTR
-check_x_frame (Lisp_Object frame)
-{
- return check_ns_frame (frame);
-}
-
-
/* called from frame.c */
struct ns_display_info *
check_x_display_info (Lisp_Object frame)
@@ -2235,7 +2166,7 @@
/* remove appname prefix; TODO: allow for !="Emacs" */
char *toCheck = class + (!strncmp (class, "Emacs.", 6) ? 6 : 0);
const char *res;
- check_window_system ();
+ check_window_system (NULL);
if (inhibit_x_resources)
/* --quick was passed, so this is a no-op. */
@@ -2305,7 +2236,7 @@
(Lisp_Object color, Lisp_Object frame)
{
NSColor * col;
- check_window_system ();
+ check_window_system (NULL);
return ns_lisp_to_color (color, &col) ? Qnil : Qt;
}
@@ -2317,7 +2248,7 @@
NSColor * col;
CGFloat red, green, blue, alpha;
- check_window_system ();
+ check_window_system (NULL);
CHECK_STRING (color);
if (ns_lisp_to_color (color, &col))
@@ -2336,7 +2267,8 @@
{
NSWindowDepth depth;
NSString *colorSpace;
- check_window_system ();
+
+ check_ns_display_info (display);
depth = [ns_get_screen (display) depth];
colorSpace = NSColorSpaceFromDepth (depth);
@@ -2356,7 +2288,8 @@
(Lisp_Object display)
{
NSWindowDepth depth;
- check_window_system ();
+
+ check_ns_display_info (display);
depth = [ns_get_screen (display) depth];
return NSBitsPerPixelFromDepth (depth) > 1 ? Qt : Qnil;
@@ -2371,7 +2304,7 @@
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object display)
{
- check_window_system ();
+ check_ns_display_info (display);
return make_number ((int) [ns_get_screen (display) frame].size.width);
}
@@ -2384,7 +2317,7 @@
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object display)
{
- check_window_system ();
+ check_ns_display_info (display);
return make_number ((int) [ns_get_screen (display) frame].size.height);
}
@@ -2404,7 +2337,7 @@
NSScreen *screen;
NSRect vScreen;
- check_window_system ();
+ check_ns_display_info (display);
screen = ns_get_screen (display);
if (!screen)
return Qnil;
@@ -2428,7 +2361,7 @@
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object display)
{
- check_window_system ();
+ check_ns_display_info (display);
return make_number
(NSBitsPerPixelFromDepth ([ns_get_screen (display) depth]));
}
@@ -2442,10 +2375,7 @@
If omitted or nil, that stands for the selected frame's display. */)
(Lisp_Object display)
{
- struct ns_display_info *dpyinfo;
- check_window_system ();
-
- dpyinfo = check_ns_display_info (display);
+ struct ns_display_info *dpyinfo = check_ns_display_info (display);
/* We force 24+ bit depths to 24-bit to prevent an overflow. */
return make_number (1 << min (dpyinfo->n_planes, 24));
}
@@ -2558,7 +2488,7 @@
CHECK_STRING (string);
str = SSDATA (string);
- f = check_x_frame (frame);
+ f = decode_window_system_frame (frame);
if (NILP (timeout))
timeout = make_number (5);
else
=== modified file 'src/nsmenu.m'
--- src/nsmenu.m 2013-04-05 14:07:02 +0000
+++ src/nsmenu.m 2013-04-06 09:36:51 +0000
@@ -1409,8 +1409,6 @@
NSTRACE (x-popup-dialog);
- check_window_system ();
-
isQ = NILP (header);
if (EQ (position, Qt)
@@ -1448,6 +1446,8 @@
else
CHECK_WINDOW (window);
+ check_window_system (f);
+
p.x = (int)f->left_pos + ((int)FRAME_COLUMN_WIDTH (f) * f->text_cols)/2;
p.y = (int)f->top_pos + (FRAME_LINE_HEIGHT (f) * f->text_lines)/2;
=== modified file 'src/nsselect.m'
--- src/nsselect.m 2013-04-05 14:07:02 +0000
+++ src/nsselect.m 2013-04-06 09:37:36 +0000
@@ -354,8 +354,7 @@
Lisp_Object successful_p = Qnil, rest;
Lisp_Object target_symbol, data;
-
- check_window_system ();
+ check_window_system (NULL);
CHECK_SYMBOL (selection);
if (NILP (value))
error ("selection value may not be nil.");
@@ -409,7 +408,7 @@
(Lisp_Object selection, Lisp_Object time_object, Lisp_Object terminal)
{
id pb;
- check_window_system ();
+ check_window_system (NULL);
CHECK_SYMBOL (selection);
if (NILP (assq_no_quit (selection, Vselection_alist))) return Qnil;
@@ -436,7 +435,7 @@
id pb;
NSArray *types;
- check_window_system ();
+ check_window_system (NULL);
CHECK_SYMBOL (selection);
if (EQ (selection, Qnil)) selection = QPRIMARY;
if (EQ (selection, Qt)) selection = QSECONDARY;
@@ -464,7 +463,7 @@
On Nextstep, TERMINAL is unused. */)
(Lisp_Object selection, Lisp_Object terminal)
{
- check_window_system ();
+ check_window_system (NULL);
CHECK_SYMBOL (selection);
if (EQ (selection, Qnil)) selection = QPRIMARY;
if (EQ (selection, Qt)) selection = QSECONDARY;
@@ -492,7 +491,7 @@
{
Lisp_Object val;
- check_window_system ();
+ check_window_system (NULL);
CHECK_SYMBOL (selection_name);
CHECK_SYMBOL (target_type);
val = ns_get_local_selection (selection_name, target_type);
@@ -516,7 +515,7 @@
(Lisp_Object selection)
{
id pb;
- check_window_system ();
+ check_window_system (NULL);
pb = ns_symbol_to_pb (selection);
return pb != nil ? ns_string_from_pasteboard (pb) : Qnil;
}
@@ -529,7 +528,7 @@
(Lisp_Object selection, Lisp_Object string)
{
id pb;
- check_window_system ();
+ check_window_system (NULL);
pb = ns_symbol_to_pb (selection);
if (pb != nil) ns_string_to_pasteboard (pb, string);
return Qnil;
=== modified file 'src/nsterm.h'
--- src/nsterm.h 2013-04-05 14:07:02 +0000
+++ src/nsterm.h 2013-04-06 09:26:15 +0000
@@ -577,8 +577,6 @@
extern struct ns_display_info *ns_display_info_for_name (Lisp_Object name);
struct ns_display_info *check_x_display_info (Lisp_Object frame);
-FRAME_PTR check_x_frame (Lisp_Object frame);
-
struct ns_output
{
=== modified file 'src/nsterm.m'
--- src/nsterm.m 2013-04-05 14:07:02 +0000
+++ src/nsterm.m 2013-04-06 09:40:38 +0000
@@ -1012,8 +1012,9 @@
Bring window to foreground and make it active
-------------------------------------------------------------------------- */
{
- NSView *view = FRAME_NS_VIEW (f);
- check_window_system ();
+ NSView *view;
+ check_window_system (f);
+ view = FRAME_NS_VIEW (f);
block_input ();
if (FRAME_VISIBLE_P (f))
[[view window] makeKeyAndOrderFront: NSApp];
@@ -1027,8 +1028,9 @@
Send window to back
-------------------------------------------------------------------------- */
{
- NSView *view = FRAME_NS_VIEW (f);
- check_window_system ();
+ NSView *view;
+ check_window_system (f);
+ view = FRAME_NS_VIEW (f);
block_input ();
[[view window] orderBack: NSApp];
unblock_input ();
@@ -1131,9 +1133,10 @@
External: Hide the window (X11 semantics)
-------------------------------------------------------------------------- */
{
- NSView * view = FRAME_NS_VIEW (f);
+ NSView *view;
NSTRACE (x_make_frame_invisible);
- check_window_system ();
+ check_window_system (f);
+ view = FRAME_NS_VIEW (f);
[[view window] orderOut: NSApp];
SET_FRAME_VISIBLE (f, 0);
SET_FRAME_ICONIFIED (f, 0);
@@ -1146,10 +1149,13 @@
External: Iconify window
-------------------------------------------------------------------------- */
{
- NSView * view = FRAME_NS_VIEW (f);
- struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f);
+ NSView *view;
+ struct ns_display_info *dpyinfo;
+
NSTRACE (x_iconify_frame);
- check_window_system ();
+ check_window_system (f);
+ view = FRAME_NS_VIEW (f);
+ dpyinfo = FRAME_NS_DISPLAY_INFO (f);
if (dpyinfo->x_highlight_frame == f)
dpyinfo->x_highlight_frame = 0;
@@ -1174,11 +1180,15 @@
void
x_free_frame_resources (struct frame *f)
{
- NSView *view = FRAME_NS_VIEW (f);
- struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f);
- Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
+ NSView *view;
+ struct ns_display_info *dpyinfo;
+ Mouse_HLInfo *hlinfo;
+
NSTRACE (x_free_frame_resources);
- check_window_system ();
+ check_window_system (f);
+ view = FRAME_NS_VIEW (f);
+ dpyinfo = FRAME_NS_DISPLAY_INFO (f);
+ hlinfo = MOUSE_HL_INFO (f);
[(EmacsView *)view setWindowClosing: YES]; /* may not have been informed */
@@ -1219,7 +1229,7 @@
-------------------------------------------------------------------------- */
{
NSTRACE (x_destroy_window);
- check_window_system ();
+ check_window_system (f);
x_free_frame_resources (f);
ns_window_num--;
}
=== modified file 'src/w32fns.c'
--- src/w32fns.c 2013-04-05 14:07:02 +0000
+++ src/w32fns.c 2013-04-06 06:27:17 +0000
@@ -95,10 +95,6 @@
#define IDC_HAND MAKEINTRESOURCE(32649)
#endif
-/* Nonzero if using Windows. */
-
-static int w32_in_use;
-
Lisp_Object Qsuppress_icon;
Lisp_Object Qundefined_color;
Lisp_Object Qcancel_timer;
@@ -239,37 +235,6 @@
static unsigned int sound_type = 0xFFFFFFFF;
#define MB_EMACS_SILENT (0xFFFFFFFF - 1)
-\f
-/* Error if we are not connected to MS-Windows. */
-void
-check_window_system (void)
-{
- if (! w32_in_use)
- error ("MS-Windows not in use or not initialized");
-}
-
-/* Nonzero if we can use mouse menus.
- You should not call this unless HAVE_MENUS is defined. */
-
-int
-have_menus_p (void)
-{
- return w32_in_use;
-}
-
-/* Extract a frame as a FRAME_PTR, defaulting to the selected frame
- and checking validity for W32. */
-
-FRAME_PTR
-check_x_frame (Lisp_Object frame)
-{
- struct frame *f = decode_live_frame (frame);
-
- if (! FRAME_W32_P (f))
- error ("Non-W32 frame used");
- return f;
-}
-
/* Let the user specify a display with a frame.
nil stands for the selected frame--or, if that is not a w32 frame,
the first display on the list. */
@@ -4567,7 +4532,7 @@
doc: /* Give FRAME input focus, raising to foreground if necessary. */)
(Lisp_Object frame)
{
- x_focus_on_frame (check_x_frame (frame));
+ x_focus_on_frame (decode_window_system_frame (frame));
return Qnil;
}
@@ -4578,7 +4543,7 @@
(Lisp_Object color, Lisp_Object frame)
{
XColor foo;
- FRAME_PTR f = check_x_frame (frame);
+ FRAME_PTR f = decode_window_system_frame (frame);
CHECK_STRING (color);
@@ -4593,7 +4558,7 @@
(Lisp_Object color, Lisp_Object frame)
{
XColor foo;
- FRAME_PTR f = check_x_frame (frame);
+ FRAME_PTR f = decode_window_system_frame (frame);
CHECK_STRING (color);
@@ -4911,7 +4876,6 @@
if (dpyinfo == 0)
error ("Cannot connect to server %s", SDATA (name));
- w32_in_use = 1;
XSETFASTINT (Vwindow_system_version, w32_major_version);
return dpyinfo;
@@ -4941,7 +4905,7 @@
/* If initialization has already been done, return now to avoid
overwriting critical parts of one_w32_display_info. */
- if (w32_in_use)
+ if (window_system_available (NULL))
return Qnil;
if (! NILP (xrm_string))
@@ -5010,8 +4974,6 @@
error ("Cannot connect to server %s", SDATA (display));
}
- w32_in_use = 1;
-
XSETFASTINT (Vwindow_system_version, w32_major_version);
return Qnil;
}
@@ -5095,7 +5057,7 @@
(Lisp_Object prop, Lisp_Object value, Lisp_Object frame,
Lisp_Object type, Lisp_Object format, Lisp_Object outer_p)
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
Atom prop_atom;
CHECK_STRING (prop);
@@ -5121,7 +5083,7 @@
FRAME nil or omitted means use the selected frame. Value is PROP. */)
(Lisp_Object prop, Lisp_Object frame)
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
Atom prop_atom;
CHECK_STRING (prop);
@@ -5157,7 +5119,7 @@
(Lisp_Object prop, Lisp_Object frame, Lisp_Object type,
Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p)
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
Atom prop_atom;
int rc;
Lisp_Object prop_value = Qnil;
@@ -5358,8 +5320,6 @@
Lisp_Object buffer;
struct buffer *old_buffer;
- check_window_system ();
-
/* Use this general default value to start with until we know if
this frame has a specified name. */
Vx_resource_name = Vinvocation_name;
@@ -5703,7 +5663,7 @@
GCPRO4 (string, parms, frame, timeout);
CHECK_STRING (string);
- f = check_x_frame (frame);
+ f = decode_window_system_frame (frame);
if (NILP (timeout))
timeout = make_number (5);
else
@@ -6354,7 +6314,7 @@
If optional parameter FRAME is not specified, use selected frame. */)
(Lisp_Object command, Lisp_Object frame)
{
- FRAME_PTR f = check_x_frame (frame);
+ FRAME_PTR f = decode_window_system_frame (frame);
CHECK_NUMBER (command);
@@ -7312,8 +7272,6 @@
syms_of_w32fns (void)
{
globals_of_w32fns ();
- /* This is zero if not using MS-Windows. */
- w32_in_use = 0;
track_mouse_window = NULL;
w32_visible_system_caret_hwnd = NULL;
=== modified file 'src/w32font.c'
--- src/w32font.c 2013-03-20 09:56:19 +0000
+++ src/w32font.c 2013-04-06 06:11:27 +0000
@@ -2467,7 +2467,7 @@
in the font selection dialog. */)
(Lisp_Object frame, Lisp_Object exclude_proportional)
{
- FRAME_PTR f = check_x_frame (frame);
+ FRAME_PTR f = decode_window_system_frame (frame);
CHOOSEFONT cf;
LOGFONT lf;
TEXTMETRIC tm;
=== modified file 'src/w32menu.c'
--- src/w32menu.c 2013-04-05 14:07:02 +0000
+++ src/w32menu.c 2013-04-06 06:28:10 +0000
@@ -140,8 +140,6 @@
FRAME_PTR f = NULL;
Lisp_Object window;
- check_window_system ();
-
/* Decode the first argument: find the window or frame to use. */
if (EQ (position, Qt)
|| (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
@@ -194,6 +192,8 @@
but I don't want to make one now. */
CHECK_WINDOW (window);
+ check_window_system (f);
+
#ifndef HAVE_DIALOGS
{
=== modified file 'src/w32term.h'
--- src/w32term.h 2013-04-05 14:07:02 +0000
+++ src/w32term.h 2013-04-06 06:11:10 +0000
@@ -739,7 +739,6 @@
struct face;
XGCValues *XCreateGC (void *, Window, unsigned long, XGCValues *);
-struct frame * check_x_frame (Lisp_Object);
typedef DWORD (WINAPI * ClipboardSequence_Proc) (void);
typedef BOOL (WINAPI * AppendMenuW_Proc) (
=== modified file 'src/xfaces.c'
--- src/xfaces.c 2013-04-05 14:07:02 +0000
+++ src/xfaces.c 2013-04-06 05:54:43 +0000
@@ -1634,7 +1634,6 @@
struct frame *f;
int size, avgwidth IF_LINT (= 0);
- check_window_system ();
CHECK_STRING (pattern);
if (! NILP (maximum))
@@ -1643,8 +1642,8 @@
if (!NILP (width))
CHECK_NUMBER (width);
- /* We can't simply call check_x_frame because this function may be
- called before any frame is created. */
+ /* We can't simply call decode_window_system_frame because
+ this function may be called before any frame is created. */
f = decode_live_frame (frame);
if (! FRAME_WINDOW_P (f))
{
@@ -3923,8 +3922,8 @@
struct frame *f;
Lisp_Object lface1, lface2;
- /* Don't use check_x_frame here because this function is called
- before X frames exist. At that time, if FRAME is nil,
+ /* Don't use decode_window_system_frame here because this function
+ is called before X frames exist. At that time, if FRAME is nil,
selected_frame will be used which is the frame dumped with
Emacs. That frame is not an X frame. */
f = EQ (frame, Qt) ? NULL : decode_live_frame (frame);
=== modified file 'src/xfns.c'
--- src/xfns.c 2013-04-05 14:07:02 +0000
+++ src/xfns.c 2013-04-06 05:54:43 +0000
@@ -123,10 +123,6 @@
#define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
-/* Nonzero if using X. */
-
-int x_in_use;
-
static Lisp_Object Qsuppress_icon;
static Lisp_Object Qundefined_color;
static Lisp_Object Qcompound_text, Qcancel_timer;
@@ -139,38 +135,6 @@
static struct x_display_info *x_display_info_for_name (Lisp_Object);
-\f
-/* Error if we are not connected to X. */
-
-void
-check_window_system (void)
-{
- if (! x_in_use)
- error ("X windows are not in use or not initialized");
-}
-
-/* Nonzero if we can use mouse menus.
- You should not call this unless HAVE_MENUS is defined. */
-
-int
-have_menus_p (void)
-{
- return x_in_use;
-}
-
-/* Extract a frame as a FRAME_PTR, defaulting to the selected frame
- and checking validity for X. */
-
-FRAME_PTR
-check_x_frame (Lisp_Object frame)
-{
- struct frame *f = decode_live_frame (frame);
-
- if (! FRAME_X_P (f))
- error ("Non-X frame used");
- return f;
-}
-
/* Let the user specify an X display with a Lisp object.
OBJECT may be nil, a frame or a terminal object.
nil stands for the selected frame--or, if that is not an X frame,
@@ -205,7 +169,7 @@
dpyinfo = x_display_info_for_name (object);
else
{
- FRAME_PTR f = check_x_frame (object);
+ FRAME_PTR f = decode_window_system_frame (object);
dpyinfo = FRAME_X_DISPLAY_INFO (f);
}
@@ -2992,7 +2956,7 @@
Signal error if FRAME is not an X frame. */)
(Lisp_Object frame)
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
block_input ();
x_wm_set_size_hint (f, 0, 0);
@@ -3483,7 +3447,7 @@
FRAME nil means use the selected frame. */)
(Lisp_Object frame)
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
Display *dpy = FRAME_X_DISPLAY (f);
block_input ();
@@ -3516,7 +3480,7 @@
(Lisp_Object color, Lisp_Object frame)
{
XColor foo;
- FRAME_PTR f = check_x_frame (frame);
+ FRAME_PTR f = decode_window_system_frame (frame);
CHECK_STRING (color);
@@ -3531,7 +3495,7 @@
(Lisp_Object color, Lisp_Object frame)
{
XColor foo;
- FRAME_PTR f = check_x_frame (frame);
+ FRAME_PTR f = decode_window_system_frame (frame);
CHECK_STRING (color);
@@ -3996,7 +3960,6 @@
if (dpyinfo == 0)
error ("Cannot connect to X server %s", SDATA (name));
- x_in_use = 1;
XSETFASTINT (Vwindow_system_version, 11);
return dpyinfo;
@@ -4050,8 +4013,6 @@
error ("Cannot connect to X server %s", SDATA (display));
}
- x_in_use = 1;
-
XSETFASTINT (Vwindow_system_version, 11);
return Qnil;
}
@@ -4143,7 +4104,7 @@
(Lisp_Object prop, Lisp_Object value, Lisp_Object frame,
Lisp_Object type, Lisp_Object format, Lisp_Object outer_p)
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
Atom prop_atom;
Atom target_type = XA_STRING;
int element_format = 8;
@@ -4221,7 +4182,7 @@
FRAME nil or omitted means use the selected frame. Value is PROP. */)
(Lisp_Object prop, Lisp_Object frame)
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
Atom prop_atom;
CHECK_STRING (prop);
@@ -4257,7 +4218,7 @@
(Lisp_Object prop, Lisp_Object frame, Lisp_Object type,
Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p)
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
Atom prop_atom;
int rc;
Lisp_Object prop_value = Qnil;
@@ -4525,8 +4486,6 @@
Lisp_Object buffer;
struct buffer *old_buffer;
- check_window_system ();
-
if (!dpyinfo->terminal->name)
error ("Terminal is not live, can't create new frames on it");
@@ -4923,7 +4882,7 @@
if (SCHARS (string) == 0)
string = make_unibyte_string (" ", 1);
- f = check_x_frame (frame);
+ f = decode_window_system_frame (frame);
if (NILP (timeout))
timeout = make_number (5);
else
@@ -5246,7 +5205,7 @@
#ifdef USE_GTK
if (use_dialog_box
&& use_file_dialog
- && have_menus_p ()
+ && window_system_available (SELECTED_FRAME ())
&& xg_uses_old_file_dialog ())
return Qt;
#endif
@@ -5316,7 +5275,7 @@
ptrdiff_t count = SPECPDL_INDEX ();
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
- check_window_system ();
+ check_window_system (f);
GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
@@ -5486,7 +5445,7 @@
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
char *cdef_file;
- check_window_system ();
+ check_window_system (f);
GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
@@ -5541,15 +5500,13 @@
nil, it defaults to the selected frame. */)
(Lisp_Object frame, Lisp_Object ignored)
{
- FRAME_PTR f = check_x_frame (frame);
+ FRAME_PTR f = decode_window_system_frame (frame);
Lisp_Object font;
Lisp_Object font_param;
char *default_name = NULL;
struct gcpro gcpro1, gcpro2;
ptrdiff_t count = SPECPDL_INDEX ();
- check_window_system ();
-
if (popup_activated ())
error ("Trying to use a menu from within a menu-entry");
@@ -5609,7 +5566,7 @@
return Qlambda;
#else
XkbDescPtr kb;
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
Display *dpy = FRAME_X_DISPLAY (f);
Lisp_Object have_keys;
int major, minor, op, event, error_code;
@@ -5737,9 +5694,6 @@
void
syms_of_xfns (void)
{
- /* This is zero if not using X windows. */
- x_in_use = 0;
-
/* The section below is built by the lisp expression at the top of the file,
just above where these variables are declared. */
/*&&& init symbols here &&&*/
=== modified file 'src/xgselect.c'
--- src/xgselect.c 2013-03-05 07:10:55 +0000
+++ src/xgselect.c 2013-04-06 05:54:43 +0000
@@ -26,6 +26,7 @@
#include <glib.h>
#include <errno.h>
#include "xterm.h"
+#include "frame.h"
int
xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
@@ -43,7 +44,7 @@
int i, nfds, tmo_in_millisec;
USE_SAFE_ALLOCA;
- if (! (x_in_use
+ if (! (window_system_available (NULL)
&& g_main_context_pending (context = g_main_context_default ())))
return pselect (fds_lim, rfds, wfds, efds, timeout, sigmask);
=== modified file 'src/xmenu.c'
--- src/xmenu.c 2013-04-05 14:07:02 +0000
+++ src/xmenu.c 2013-04-06 05:54:43 +0000
@@ -223,8 +223,6 @@
FRAME_PTR f = NULL;
Lisp_Object window;
- check_window_system ();
-
/* Decode the first argument: find the window or frame to use. */
if (EQ (position, Qt)
|| (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
@@ -277,8 +275,7 @@
but I don't want to make one now. */
CHECK_WINDOW (window);
- if (! FRAME_X_P (f) && ! FRAME_MSDOS_P (f))
- error ("Can not put X dialog on this terminal");
+ check_window_system (f);
/* Force a redisplay before showing the dialog. If a frame is created
just before showing the dialog, its contents may not have been fully
@@ -485,7 +482,7 @@
(Lisp_Object frame)
{
XEvent ev;
- FRAME_PTR f = check_x_frame (frame);
+ FRAME_PTR f = decode_window_system_frame (frame);
Widget menubar;
block_input ();
@@ -569,7 +566,7 @@
block_input (). */
block_input ();
- f = check_x_frame (frame);
+ f = decode_window_system_frame (frame);
if (FRAME_EXTERNAL_MENU_BAR (f))
set_frame_menubar (f, 0, 1);
=== modified file 'src/xselect.c'
--- src/xselect.c 2013-03-24 12:59:45 +0000
+++ src/xselect.c 2013-04-06 05:54:43 +0000
@@ -2450,7 +2450,7 @@
If the value is 0 or the atom is not known, return the empty string. */)
(Lisp_Object value, Lisp_Object frame)
{
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
char *name = 0;
char empty[] = "";
Lisp_Object ret = Qnil;
@@ -2485,7 +2485,7 @@
(Lisp_Object atom, Lisp_Object frame)
{
Atom x_atom;
- struct frame *f = check_x_frame (frame);
+ struct frame *f = decode_window_system_frame (frame);
ptrdiff_t i;
struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
@@ -2618,7 +2618,7 @@
struct x_display_info *dpyinfo = check_x_display_info (display);
Window wdest;
XEvent event;
- struct frame *f = check_x_frame (from);
+ struct frame *f = decode_window_system_frame (from);
int to_root;
CHECK_NUMBER (format);
@@ -2635,7 +2635,7 @@
if (FRAMEP (dest) || NILP (dest))
{
- struct frame *fdest = check_x_frame (dest);
+ struct frame *fdest = decode_window_system_frame (dest);
wdest = FRAME_OUTER_WINDOW (fdest);
}
else if (STRINGP (dest))
=== modified file 'src/xterm.h'
--- src/xterm.h 2013-04-05 14:07:02 +0000
+++ src/xterm.h 2013-04-06 05:53:32 +0000
@@ -923,7 +923,6 @@
/* From xfns.c. */
-struct frame *check_x_frame (Lisp_Object);
extern void x_free_gcs (struct frame *);
/* From xrdb.c. */
@@ -1008,7 +1007,6 @@
extern struct x_display_info * check_x_display_info (Lisp_Object);
extern Lisp_Object x_get_focus_frame (struct frame *);
-extern int x_in_use;
#ifdef USE_GTK
extern int xg_set_icon (struct frame *, Lisp_Object);
^ permalink raw reply [flat|nested] 5+ messages in thread