[comp.windows.x] xrdb

sean@hazel.eos.scg.hac.com (04/10/91)

xrdb is used to set resources in the resource manager so that you don't have
to have seperate default files for every machine that might use.  I'm not sure
how to go about doing this.

If I want to run a client on a Sun and a Mac, and be able to have seperate
width, height, and font resources for both machines, how do I go about
specifying this with xrdb?  Is it based on the current DISPLAY value?  What
if they specify the display value on the command line of an application?
How does xrdb know when to use resources speicified for the Mac and resources
speicified for the Sun?

Thanks.

--
================================================================================
Sean Cohan                        ||\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /
Hughes Aircraft Co.               || \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/
1768 Business Center Dr.          || /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\

mouse@lightning.mcrcim.mcgill.EDU (der Mouse) (04/11/91)

> xrdb is used to set resources in the resource manager so that you
> don't have to have seperate default files for every machine that
> might use.

Right.

> I'm not sure how to go about doing this.

Just run xrdb.  The resource database is actually stored as a property
of the root window of screen 0 of your server.

> If I want to run a client on a Sun and a Mac, and be able to have
> seperate width, height, and font resources for both machines, how do
> I go about specifying this with xrdb?

When you load the resource database for your Sun, you load it with
values appropriate for the Sun; on the Mac, use values appropriate for
the Mac.  Then clients will get the correct values for the display
they're connecting to.

> Is it based on the current DISPLAY value?

That is the effect, though technically it is not true: it is based on
the RESOURCE_MANAGER property of the root of screen 0 on the connection
in question.

> What if they specify the display value on the command line of an
> application?

Then the resource routines will pick up the resources from that
display, when the program connects....

> How does xrdb know when to use resources speicified for the Mac and
> resources speicified for the Sun?

If you mean, how does it know to load the Mac values into the Mac's
database and the Sun's into the Sun, you have to tell it.  When you run
xrdb -load, you have to ensure that the values it gets are the correct
ones for the display you're loading them into.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

aw@jello.bae.bellcore.com (Andrew Wason) (04/12/91)

In article <14315@hacgate.UUCP>, sean@hazel.eos.scg.hac.com writes:
>If I want to run a client on a Sun and a Mac, and be able to have seperate
>width, height, and font resources for both machines, how do I go about
>specifying this with xrdb?  Is it based on the current DISPLAY value?  What
>if they specify the display value on the command line of an application?

It is based on the server xrdb used when it was run.

>How does xrdb know when to use resources speicified for the Mac and resources
>speicified for the Sun?

xrdb runs its input through cpp.  It also defines some
symbols based on the server it was run on.  These are
HOST, WIDTH, HEIGHT, X_RESOLUTION, Y_RESOLUTION, PLANES, BITS_PER_RGB,
CLASS and COLOR (see xrdb(1) for explanations of these).

So you can have one file which you can set up to work
correctly for certain types of servers by #ifdefing
chunks of resources.

For example, in the resources I feed to xrdb, I put
an '#ifdef COLOR' around all color resources.  So when I
run xrdb on my color server, I get all my color resources.
But when I run xrdb on my monochrome server, no color resources
are loaded and so everything defaults correctly.
e.g.

  #ifdef COLOR
  XBiff*background:       gray
  XBiff*foreground:       yellow
  #endif
  XBiff*update:           5
  XBiff*volume:           15

You could also use the WIDTH and HEIGHT symbols
to conditionally include geometry resources depending
on the size of your screen e.g.:

  #if WIDTH > 1000
  XBiff.width:    512
  #else
  XBiff.width:    256
  #endif

Type 'xrdb -symbols' to see the symbols defined for a particular server.
Type 'xrdb -query' to see the resources xrdb actually loaded.

Andrew

_______________________________________________________________________________

Andrew Wason                                       Bell Communications Research
aw@bae.bellcore.com                                Piscataway, NJ
bellcore!bae!aw

guy@auspex.auspex.com (Guy Harris) (04/13/91)

>Just run xrdb.  The resource database is actually stored as a property
>of the root window of screen 0 of your server.

Has anybody ever run an application with *so* many resources (perhaps
based on a "you can configure the shape, text, and color of every single
button" toolkit), and with those resources all set, so that when they
try to set said property, it's so big that their X terminal explodes (or
just runs out of memory :-))?

Or does nothing have that many resources, or are they never all set by
users, or do X terminals just have enough memory that this isn't a
problem?

jordan@tcs.COM (Jordan Hayes) (04/13/91)

Well, resources or not, this little ditty makes my Sparc2 go out to lunch.

/jordan

=====

/* explode.c ... make a "bunch" of labels (how could anyone even
 *	think of writing a spreadsheet where each cell was a widget?
 */

#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/Xaw/Label.h>

/* this is "big" ??? */
#define	NUM_LABELS	1000

main(argc, argv)
	int	argc;
	char	**argv;
{
	int		i;
	char		name[50];
	XtAppContext	app;
	Display		*display;
	Widget		shell, label[NUM_LABELS];

	XtToolkitInitialize();
	app = XtCreateApplicationContext();

        display = XtOpenDisplay(app, (String)NULL,
	    (String)NULL, "Explode", (XrmOptionDescRec *)NULL, 0,
	    &argc, argv);

	shell = XtAppCreateShell(NULL, "Explode", applicationShellWidgetClass,
	    display, (ArgList)NULL, (Cardinal)0);

	for (i = 0; i < NUM_LABELS; i++) {
		(void)sprintf(name, "label_%d", i);
		label[i] = XtCreateWidget(name, labelWidgetClass, shell,
		    (ArgList)NULL, (Cardinal)0);
	}
	XtManageChildren(label, NUM_LABELS);

	XtRealizeWidget(shell);

	XtAppMainLoop(app);
}

klee@wsl.dec.com (Ken Lee) (04/13/91)

In article <7150@auspex.auspex.com>, guy@auspex.auspex.com (Guy Harris) writes:
|> Has anybody ever run an application with *so* many resources (perhaps
|> based on a "you can configure the shape, text, and color of every single
|> button" toolkit), and with those resources all set, so that when they
|> try to set said property, it's so big that their X terminal explodes (or
|> just runs out of memory :-))?

I doubt that many Xnerds have more than a few 10KB in their
.Xdefaults.  If someone starts getting into memory trouble (i.e., many
100KB), they could put the resources into app-defaults files that are
only read in when applications start up.

-- 
Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee

george@ucs.adelaide.edu.au (George Travan) (05/16/91)

while adding resources to .Xrdb i have noticed that i get the following
error when i run xrdb
> xrdb .Xrdb
X Error of failed request:  BadLength (poly request too large or internal Xlib l
ength error)
  Major opcode of failed request:  18 (X_ChangeProperty)
  Minor opcode of failed request:  0
  Resource id in failed request:  0x8006e
  Serial number of failed request:  4
  Current serial number in output stream:  7

Could someone show me what's going on here? How to fix?...


George Travan
University of Adelaide
Box 498 G.P.O
Adelaide, AUSTRALIA           george@frodo.ua.oz.au