[comp.windows.x] Visuals, colors, resource db

ado@hutcs.hut.fi (Andre Dolenc) (08/23/89)

[ It is the first I post a message so I apologies in advance for
  any mistakes. ]

------
Xt question: Between a call to root=XtInitialize (or equivalent) and the
XtRealizeWidget(root), how can one select the appropriate Visual? Can one
let the Intrinsics use the default and then change it?
------
Resource database question: I have an application-dependent resource
db which I would like to merge with the one returned by XtDatabase.
Fine, so I load it with XrmGetDatabase and merge them with XrmMergeDatabases.
However, since I want Xt to use this merged result when XtRealizeWidget is
called I must change the default db associated to the display and the only
way I have figured to do this is make a direct assignment:
	display->db = merged_db
I don't like it; looks like a hack... Have I missed something?
------
Problem
(Environments: (1) Sun 3, SunOs 4.0, X11.3; (2) Tektronics 4319, X11.3)

XGetWindowAttributes and XAllocNamedColor return BadRequest. These Xlib
routines where used between the calls to XtRealizeWidget and XtMainLoop.

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (08/25/89)

> Xt question: Between a call to root=XtInitialize (or equivalent) and the
> XtRealizeWidget(root), how can one select the appropriate Visual? Can one
> let the Intrinsics use the default and then change it?

A visual field will be added to the Shell widget in Release 4.  Until then
there is little you can do, short of writing your own widget that has a
visual field.

> Resource database question: I have an application-dependent resource
> db which I would like to merge with the one returned by XtDatabase.

How about using an app-defaults file instead?  This way the toolkit
will merge your resources in for you.

> XGetWindowAttributes and XAllocNamedColor return BadRequest. These Xlib
> routines where used between the calls to XtRealizeWidget and XtMainLoop.

You need to flush the event queue.  Take a look at XFlush().


						Chris D. Peterson     
						MIT X Consortium 

Net:	 kit@expo.lcs.mit.edu
Phone:   (617) 253 - 9608	
Address: MIT - Room NE43-213

ado@hutcs.hut.fi (Andre Dolenc) (08/25/89)

>> Xt question: Between a call to root=XtInitialize (or equivalent) and the
>> XtRealizeWidget(root), how can one select the appropriate Visual?....

>A visual field will be added to the Shell widget in Release 4.  Until then
>there is little you can do, short of writing your own widget that has a
>visual field.

>> XGetWindowAttributes and XAllocNamedColor return BadRequest. These Xlib
>> routines where used between the calls to XtRealizeWidget and XtMainLoop.

>You need to flush the event queue.  Take a look at XFlush().

1. I tried XFlush and XSync to no avail... It seems to me that I must
   force the root window to be displayed before I can use these calls.
   What is there in XtMainLoop that does this? XtNextEvent?
2. On the other hand, I need the window attr's in order to know which
   Visual and Colormap where assigned to it. Thus, these 2 prblms are
   related. I will try to write my own realize proc for the root widget.
   Any other suggestions?

>> Resource database question: I have an application-dependent resource
>> db which I would like to merge with the one returned by XtDatabase.

>How about using an app-defaults file instead?  This way the toolkit
>will merge your resources in for you.

Yes, I thought of that. But I have at least 2 resource files which
must be loaded; one of them is (human) language dependent.

Thanx a lot for your reply.
-----

staatsvr@asdcds.cds.wpafb.af.mil (Vern Staats; ASD/SCED;) (08/26/89)

In article <ADO.89Aug25115032@hutcs.hut.fi> ado@hutcs.hut.fi (Andre Dolenc) writes:
>>>   Resource database question: I have an application-dependent resource
>>>   db which I would like to merge with the one returned by XtDatabase.
>>  How about using an app-defaults file instead?  This way the toolkit
>>  will merge your resources in for you.
> Yes, I thought of that. But I have at least 2 resource files which
> must be loaded; one of them is (human) language dependent.

I have a similar question on X Philosophy and resource databases:
Should program-specific defaults for resources be rigorously avoided,
or are they OK provided they have the absolute rock-bottom precedence?  
I get the feeling that requiring an app-defaults file is the 
"philisophically correct" thing to do, but I'd really prefer 
to have my applications stay somewhat sane in its absence.

Here's what I'm doing.  I think its OK, please zap me if its wrong.

------------------------------------------------------------------------
main() {  ...
    XtToolkitInitialize();
    dpy = XtOpenDisplay((XtAppContext) NULL,displayname,app_name,app_class,
                        opTable,opTableEntries,&argc,argv);
    toplevel = XtAppCreateShell(app_name,app_class,topLevelShellWidgetClass,
                                dpy,top_args,XtNumber(top_args));
    merge_default_prefs();
    ...
}

/*  Adds application-specific hardcoded defaults to current database,
**  at a lower precedence than the existing database.
*/
merge_default_prefs()
{
    int                 i;
    static XrmDatabase  finalDB = NULL;
    XrmDatabase         currentDB;
    static char         *pgmdefaults[] = {
        "*button.background:        gray50\n",
        "*button.foreground:        cyan\n",
        /* and etc  */
        };

    for (i=0; i < sizeof(pgmdefaults) / sizeof(char *); i++)  {
        XrmPutLineResource(&finalDB,pgmdefaults[i]);
        }

    currentDB = XtDatabase(dpy);
    XrmMergeDatabases(currentDB,&finalDB);
    /* so now the currentDB (from .Xdefaults, etc) has overwritten my
       pgmdefaults in finalDB.  Now all we have to do is install finalDB.
    */

    /*  Which of these is better form?  Peeking at Xlib.h and Xresource.h:
    */
        dpy->db = finalDB;

    /*  or this?:
        currentDB = XtDatabase(dpy);
        XrmMergeDatabases(finalDB,&currentDB);
    */
}

----
INET:  staatsvr@asd.wpafb.af.mil   Vern Staats  (513) 255-2714        /// Save
UUCP:  nap1!asd!staatsvr           ASD/SCED                       \\\/// The
Opinions:  my!own!                 WPAFB OH 45433                  \XX/ Guru

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (08/28/89)

> 1. I tried XFlush and XSync to no avail... It seems to me that I must
>    force the root window to be displayed before I can use these calls.
>   What is there in XtMainLoop that does this? XtNextEvent?

XtRealizeWidget(widget);
XFlush(XtDisplay(widget));
[stuff]
XtMainLoop();

This type of thing doesn't work?

> 2. On the other hand, I need the window attr's in order to know which
>    Visual and Colormap where assigned to it. Thus, these 2 prblms are
>    related. I will try to write my own realize proc for the root widget.
>   Any other suggestions?

In R3 the visual is always the default visual of the screen, and unless you
explicitly change the colormap it is also the default colormap of screen.

Also, once you have realized a widget the window ID should be valid, and you
can get the attributes of it.  Whether or not it is visable on the screen
yet.

> >How about using an app-defaults file instead?  This way the toolkit
> >will merge your resources in for you.

> Yes, I thought of that. But I have at least 2 resource files which
> must be loaded; one of them is (human) language dependent.

Don't spend too long on this one, as we are come up with a solution to
the human language problem for R4.


						Chris D. Peterson     
						MIT X Consortium 

Net:	 kit@expo.lcs.mit.edu
Phone:   (617) 253 - 9608	
Address: MIT - Room NE43-213