Mercurial > emacs
view src/xrdb.c @ 1720:4f5e3ac5d822
* frame.h (struct frame): New fields `can_have_scrollbars' and
`has_vertical_scrollbars'.
(FRAME_CAN_HAVE_SCROLLBARS, FRAME_HAS_VERTICAL_SCROLLBARS): New
accessors, for both the MULTI_FRAME and non-MULTI_FRAME.
(VERTICAL_SCROLLBAR_WIDTH, WINDOW_VERTICAL_SCROLLBAR,
WINDOW_VERTICAL_SCROLLBAR_COLUMN,
WINDOW_VERTICAL_SCROLLBAR_HEIGHT): New macros.
* window.h (struct window): New field `vertical_scrollbar'.
* xterm.h (struct x_display): vertical_scrollbars,
judge_timestamp, vertical_scrollbar_extra: New fields.
(struct scrollbar): New struct.
(VERTICAL_SCROLLBAR_PIXEL_WIDTH, VERTICAL_SCROLLBAR_PIXEL_HEIGHT,
VERTICAL_SCROLLBAR_LEFT_BORDER, VERTICAL_SCROLLBAR_RIGHT_BORDER,
VERTICAL_SCROLLBAR_TOP_BORDER, VERTICAL_SCROLLBAR_BOTTOM_BORDER,
CHAR_TO_PIXEL_WIDTH, CHAR_TO_PIXEL_HEIGHT, PIXEL_TO_CHAR_WIDTH,
PIXEL_TO_CHAR_HEIGHT): New accessors and macros.
* frame.c (make_frame): Initialize the `can_have_scrollbars' and
`has_vertical_scrollbars' fields of the frame.
* term.c (term_init): Note that TERMCAP terminals don't support
scrollbars.
(mouse_position_hook): Document new args.
(set_vertical_scrollbar_hook, condemn_scrollbars_hook,
redeem_scrollbar_hook, judge_scrollbars_hook): New hooks.
* termhooks.h: Declare and document them.
(enum scrollbar_part): New type.
(struct input_event): Describe the new form of the scrollbar_click
event type. Change `part' from a Lisp_Object to an enum
scrollbar_part. Add a new field `scrollbar'.
* keyboard.c (kbd_buffer_get_event): Pass appropriate new
parameters to *mouse_position_hook, and make_lispy_movement.
* xfns.c (x_set_vertical_scrollbar): New function.
(x_figure_window_size): Use new macros to calculate frame size.
(Fx_create_frame): Note that X Windows frames do support scroll
bars. Default to "yes".
* xterm.c: #include <X11/cursorfont.h> and "window.h".
(x_vertical_scrollbar_cursor): New variable.
(x_term_init): Initialize it.
(last_mouse_bar, last_mouse_bar_frame, last_mouse_part,
last_mouse_scroll_range_start, last_mouse_scroll_range_end): New
variables.
(XTmouse_position): Use them to return scrollbar movement events.
Take new arguments, for that purpose.
(x_window_to_scrollbar, x_scrollbar_create,
x_scrollbar_set_handle, x_scrollbar_remove, x_scrollbar_move,
XTset_scrollbar, XTcondemn_scrollbars, XTredeem_scrollbar,
XTjudge_scrollbars, x_scrollbar_expose,
x_scrollbar_background_expose, x_scrollbar_handle_click,
x_scrollbar_handle_motion): New functions to implement scrollbars.
(x_term_init): Set the termhooks.h hooks to point to them.
(x_set_window_size): Use new macros to calculate frame size. Set
vertical_scrollbar_extra field.
(x_make_frame_visible): Use the frame accessor
FRAME_HAS_VERTICAL_SCROLLBARS to decide if we need to map the
frame's subwindows as well.
(XTread_socket): Use new size-calculation macros from xterm.h when
processing ConfigureNotify events.
(x_wm_set_size_hint): Use PIXEL_TO_CHAR_WIDTH and
PIXEL_TO_CHAR_HEIGHT macros.
* ymakefile (xdisp.o): This now depends on termhooks.h.
(xterm.o): This now depends on window.h.
* xterm.h (struct x_display): Delete v_scrollbar, v_thumbup,
v_thumbdown, v_slider, h_scrollbar, h_thumbup,
h_thumbdown, h_slider, v_scrollbar_width, h_scrollbar_height
fields.
* keyboard.c (Qvscrollbar_part, Qvslider_part, Qvthumbup_part,
Qvthumbdown_part, Qhscrollbar_part, Qhslider_part, Qhthumbup_part,
Qhthumbdown_part, Qscrollbar_click): Deleted; part of an obsolete
interface.
(head_table): Removed from here as well.
(syms_of_keyboard): And here.
* keyboard.h: And here.
(POSN_SCROLLBAR_BUTTON): Removed.
* xscrollbar.h: File removed - no longer necessary.
* xfns.c: Don't #include it any more.
(Qhorizontal_scroll_bar, Qvertical_scroll_bar): Deleted.
(syms_of_xfns): Don't initialize or staticpro them.
(gray_bits): Salvaged from xscrollbar.h.
(x_window_to_scrollbar): Deleted.
(x_set_horizontal_scrollbar): Deleted.
(enum x_frame_parm, x_frame_parms): Remove references to
x_set_horizontal_scrollbar.
(x_set_foreground_color, x_set_background_color,
x_set_border_pixel): Remove special code to support scrollbars.
(Fx_create_frame): Remove old scrollbar setup code.
(install_vertical_scrollbar, install_horizontal_scrollbar,
adjust_scrollbars, x_resize_scrollbars): Deleted.
* xterm.c (construct_mouse_click): This doesn't need to take care of
scrollbar clicks anymore.
(XTread_socket): Remove old code to support scrollbars. Call new
functions instead for events which occur in scrollbar windows.
(XTupdate_end): Remove call to adjust_scrollbars; the main
redisplay code takes care of that now.
(enum window_type): Deleted.
* ymakefile: Note that xfns.o no longer depends on xscrollbar.h.
* xterm.c (x_set_mouse_position): Clip mouse position to be within
frame.
* xterm.c: Adjust the first line of each page to have a reasonable
description. This makes pages-directory more useful.
* xterm.c (x_do_pending_expose): Declare this routine only if
HAVE_X11 is not #defined; X11 doesn't need it.
(XTread_socket): Protect call to x_do_pending_expose with `#ifdef
HAVE_X11'.
* xterm.c (notice_mouse_movement): Deleted; obsolete and unused.
Properly handle focus shift events, so the cursor is filled and
hollow at the appropriate times, even in titleless windows.
* xterm.c (x_focus_event_frame): New variable.
(XTread_socket): When we receive a FocusIn event that's not
NotifyPointer, record the frame in x_focus_event_frame. When we
receive a FocusOut event that's not NotifyPointer, clear it. When
we get a LeaveNotify event, don't take it seriously if we still
have focus.
* xterm.c (XTread_socket): Remove special code in EnterNotify case
to handle scrollbars and fake mouse motion events.
Change the meaning of focus redirection to make switching windows
work properly. Fredirect_frame_focus has the details.
* frame.h (focus_frame): Doc fix.
[not MULTI_FRAME] (FRAME_FOCUS_FRAME): Make this Qnil, which
indicates no focus redirection, instead of zero, which is
selected_frame.
* frame.c (make_frame): Initialize f->focus_frame to Qnil, rather
than making it point to frame itself.
(Fselect_frame): If changing the selected frame from FOO to BAR,
make all redirections to FOO shift to BAR as well. Doc fix.
(Fredirect_frame_focus): Doc fix. Accept nil as a valid
redirection, not just as a default for FRAME.
(Fframe_focus): Doc fix.
* keyboard.c (kbd_buffer_store_event, kbd_buffer_get_event): Deal
with focus redirections being nil.
* xterm.c (XTframe_rehighlight): Doc fix. Deal with focus
redirections being nil.
* xterm.c (x_error_quitter): Just abort, so we can look at the
core to see what happened.
It's a pain to remember that you can't assign to FRAME->visible.
Let's change all references to the `visible' member of struct
frame to use the accessor macros, and then write a setter for the
`visible' field that does the right thing.
* frame.h (FRAME_VISIBLE_P): Make this not an l-value.
(FRAME_SET_VISIBLE): New macro.
* frame.c (make_terminal_frame, Fdelete_frame): Use FRAME_SET_VISIBLE.
(Fframe_visible_p, Fvisible_frame_list): Use FRAME_VISIBLE_P and
FRAME_ICONIFIED_P.
* dispnew.c (Fredraw_display): Use the FRAME_VISIBLE_P and
FRAME_GARBAGED_P accessors.
* xdisp.c (redisplay): Use the FRAME_VISIBLE_P accessor.
* xfns.c (x_set_foreground_color, x_set_background_color,
x_set_cursor_color, x_set_border_pixel, x_set_icon_type): Use the
FRAME_VISIBLE_P accessor.
(Fx_create_frame): Use FRAME_SET_VISIBILITY.
* xterm.c (clear_cursor, x_display_bar_cursor,
x_display_box_cursor): Use FRAME_SET_VISIBILITY.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Thu, 24 Dec 1992 06:21:14 +0000 |
parents | 517c3893ec5b |
children | 458a1fceb462 |
line wrap: on
line source
/* Deal with the X Resource Manager. Copyright (C) 1990, 1992 Free Software Foundation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Written by jla, 4/90 */ #ifdef emacs #include "config.h" #endif #if 1 /* I'd really appreciate it if this code could go away... -JimB */ /* this avoids lossage in the `dual-universe' headers on AT&T SysV X11 */ #ifdef USG5 #define SYSV #include <unistd.h> #endif /* USG5 */ #endif /* 1 */ /* This should be included before the X include files; otherwise, we get warnings about redefining NULL under BSD 4.3. */ #include <sys/param.h> #include <X11/Xlib.h> #include <X11/Xatom.h> #if 0 #include <X11/Xos.h> #endif #include <X11/X.h> #include <X11/Xutil.h> #include <X11/Xresource.h> #ifdef VMS #include "vms-pwd.h" #else #include <pwd.h> #endif #include <sys/stat.h> #ifndef MAXPATHLEN #define MAXPATHLEN 256 #endif extern char *getenv (); extern short getuid (); /* If this causes portability problems, I think we should just delete it; it'll default to `int' anyway. */ extern struct passwd *getpwuid (); extern struct passwd *getpwnam (); static char * gethomedir (dirname) char *dirname; { int uid; struct passwd *pw; char *ptr; if ((ptr = getenv ("HOME")) == NULL) { if ((ptr = getenv ("USER")) != NULL) pw = getpwnam (ptr); else { uid = getuid (); pw = getpwuid (uid); } if (pw) ptr = pw->pw_dir; else { ptr = NULL; *dirname = '\0'; } } if (ptr != NULL) strcpy (dirname, ptr); dirname += strlen (dirname); *dirname = '/'; dirname++; *dirname = '\0'; return dirname; } static int file_p (path) char *path; { struct stat status; return (access (path, 4) == 0 /* exists and is readable */ && stat (path, &status) == 0 /* get the status */ && (status.st_mode & S_IFDIR) == 0); /* not a directory */ } #if 0 #define X_DEFAULT_SEARCH_PATH "/usr/lib/X11/" #endif /* Isn't this just disgusting? */ #define X_DEFAULT_SEARCH_PATH "/usr/lib/X11/%L/%T/%N%S:/usr/lib/X11/%l/%T/%N%S:/usr/lib/X11/%T/%N%S" static int decode_magic (string, file, return_path) char *string, *file, *return_path; { char *p = string; char *t = return_path; while (*p) { if (*p == '%') switch (*++p) { case '%': *t++ = '%'; p++; break; case 'N': case 'T': case 'S': case 'L': case 'l': case 't': case 'c': default: p++; if (*t == '/' && *p == '/') p++; break; } else *t++ = *p++; } *t = '\0'; strcat (return_path, file); if (file_p (return_path)) return 1; return_path[0] = '\0'; return 0; } static int magic_searchpath_decoder (incantation_string, file, return_path) char *incantation_string, *return_path, *file; { register char *s = incantation_string; register char *p; /* Must be big enough for "%N%S". */ register int string_size = MAXPATHLEN; register char *string = (char *) alloca (string_size * sizeof (*string)); while (*s) { p = s; while (*p && *p != ':') p++; if (*p == ':' && *(p + 1) == ':') { /* We know string is big enough for this. */ bcopy ("%N%S", string, 5); if (decode_magic (string, file, return_path)) return 1; s = p + 1; continue; } if (p > s) { int len = p - s; if (string_size < len+1) { string_size = 2 * len; string = (char *) alloca (string_size * sizeof (*string)); } bcopy (s, string, len); string[len + 1] = '\0'; if (decode_magic (string, file, return_path)) return 1; } if (p) s = p + 1; else return 0; } return 0; } static XrmDatabase get_system_app (class) char *class; { XrmDatabase db; char path[MAXPATHLEN]; char *p; if ((p = getenv ("XFILESEARCHPATH")) == NULL) p = X_DEFAULT_SEARCH_PATH; if (! magic_searchpath_decoder (p, class, path)) return NULL; db = XrmGetFileDatabase (path); return db; } static XrmDatabase get_fallback (display) Display *display; { XrmDatabase db; return NULL; } static XrmDatabase get_user_app (class) char *class; { XrmDatabase db; char *magic_path; char path[MAXPATHLEN]; if ((magic_path = getenv ("XUSERFILESEARCHPATH")) == NULL) { char homedir[MAXPATHLEN]; char *default_magic; char *p; gethomedir (homedir); if ((p = getenv ("XAPPLRESDIR")) == NULL) { default_magic = "%s/%%L/%%N:%s/%%l/%%N:%s/%%N"; magic_path = (char *) alloca ((3 * strlen (homedir)) + strlen (default_magic)); sprintf (magic_path, default_magic, homedir, homedir, homedir); } else { default_magic = "%s/%%L/%%N:%s/%%l/%%N:%s/%%N:%s/%%N"; magic_path = (char *) alloca ((3 * strlen (p)) + strlen (default_magic) + strlen (homedir)); sprintf (magic_path, default_magic, p, p, p, homedir); } } if (! magic_searchpath_decoder (magic_path, class, path)) return NULL; db = XrmGetFileDatabase (path); return db; } static XrmDatabase get_user_db (display) Display *display; { XrmDatabase db; char *xdefs; #ifdef HAVE_X11R4 xdefs = XResourceManagerString (display); #else xdefs = display->xdefaults; #endif if (xdefs != NULL) db = XrmGetStringDatabase (xdefs); else { char xdefault[MAXPATHLEN]; gethomedir (xdefault); strcat (xdefault, ".Xdefaults"); db = XrmGetFileDatabase (xdefault); } return db; } static XrmDatabase get_environ_db () { XrmDatabase db; char *p; char path[MAXPATHLEN]; if ((p = getenv ("XENVIRONMENT")) == NULL) { gethomedir (path); strcat (path, ".Xdefaults-"); gethostname (path + strlen (path), MAXPATHLEN - strlen (path)); p = path; } db = XrmGetFileDatabase (p); return db; } /* Types of values that we can find in a database */ #define XrmStringType "String" /* String representation */ XrmRepresentation x_rm_string; /* Quark representation */ /* Load X resources based on the display and a possible -xrm option. */ XrmDatabase x_load_resources (display, xrm_string, myclass) Display *display; char *xrm_string, *myclass; { char *xdefs; XrmDatabase rdb; XrmDatabase db; x_rm_string = XrmStringToQuark (XrmStringType); XrmInitialize (); rdb = XrmGetStringDatabase (""); /* Get application system defaults */ db = get_system_app (myclass); if (db != NULL) XrmMergeDatabases (db, &rdb); /* Get Fallback resources */ db = get_fallback (display); if (db != NULL) XrmMergeDatabases (db, &rdb); /* Get application user defaults */ db = get_user_app (myclass); if (db != NULL) XrmMergeDatabases (db, &rdb); /* get User defaults */ db = get_user_db (display); if (db != NULL) XrmMergeDatabases (db, &rdb); /* Get Environment defaults. */ db = get_environ_db (); if (db != NULL) XrmMergeDatabases (db, &rdb); /* Last, merge in any specification from the command line. */ if (xrm_string != NULL) { db = XrmGetStringDatabase (xrm_string); if (db != NULL) XrmMergeDatabases (db, &rdb); } return rdb; } /* Retrieve the value of the resource specified by NAME with class CLASS and of type TYPE from database RDB. The value is returned in RET_VALUE. */ int x_get_resource (rdb, name, class, expected_type, ret_value) XrmDatabase rdb; char *name, *class; XrmRepresentation expected_type; XrmValue *ret_value; { XrmValue value; XrmName namelist[100]; XrmClass classlist[100]; XrmRepresentation type; XrmStringToNameList(name, namelist); XrmStringToClassList(class, classlist); if (XrmQGetResource (rdb, namelist, classlist, &type, &value) == True && (type == expected_type)) { if (type == x_rm_string) ret_value->addr = (char *) value.addr; else bcopy (value.addr, ret_value->addr, ret_value->size); return value.size; } return 0; } /* Retrieve the string resource specified by NAME with CLASS from database RDB. */ char * x_get_string_resource (rdb, name, class) XrmDatabase rdb; char *name, *class; { XrmValue value; if (x_get_resource (rdb, name, class, x_rm_string, &value)) return (char *) value.addr; return (char *) 0; } #ifdef TESTRM #include <stdio.h> #include "arg-list.h" static void fatal (msg, prog, x1, x2, x3, x4, x5) char *msg, *prog; int x1, x2, x3, x4, x5; { extern int errno; if (errno) perror (prog); (void) fprintf (stderr, msg, prog, x1, x2, x3, x4, x5); exit (1); } main (argc, argv) int argc; char **argv; { Display *display; char *displayname, *resource_string, *class; XrmDatabase xdb; List *arg_list, *lp; arg_list = arg_listify (argc, argv); lp = member ("-d", arg_list); if (!NIL (lp)) displayname = car (cdr (lp)); else displayname = "localhost:0.0"; lp = member ("-xrm", arg_list); if (! NIL (lp)) resource_string = car (cdr (lp)); else resource_string = (char *) 0; lp = member ("-c", arg_list); if (! NIL (lp)) class = car (cdr (lp)); else class = "Emacs"; free_arglist (arg_list); if (!(display = XOpenDisplay (displayname))) fatal ("Can't open display '%s'\n", XDisplayName (displayname)); xdb = x_load_resources (display, resource_string, class); #if 0 /* In a real program, you'd want to also do this: */ display->db = xdb; #endif while (1) { char line[90]; printf ("String: "); gets (line); if (strlen (line)) { char *value = x_get_string_resource (xdb, line, class); if (value != NULL) printf ("\t%s: %s\n\n", line, value); else printf ("\tNo Value.\n\n"); } else break; } printf ("\tExit.\n\n"); XCloseDisplay (display); } #endif /* TESTRM */