You are not logged in.
After a call to
XrmInitialize()
XrmGetDatabase(dpy);
Where is the created database (if the above lines do indeed create a new database) stored? How do we retrieve this database the next time the code is run?
Also, the manual claims that "Resources are stored in the database with only partially specified names and classes." What is the advantage of using loose bindings such as a "*" or "?"? Why can't the database just store the plain fully qualified names?
Last edited by Portal (2020-03-08 21:39:39)
Offline
Where is the created database (if the above lines do indeed create a new database) stored?
Those lines do not create a new database. They are used to access the current database stored by the xserver (in memory). There are other functions if you actually want to load or save these data to/from a file.
How do we retrieve this database the next time the code is run?
What do you mean by "retrieve this database"? The result of the second line should be stored, as that is the (handle to) the database.
What are you actually trying to do? It sounds like you may not actually want to use the xrmdb but rather you want some other static database storage for your program.
The xrmdb is not where you would store data from one run of your program that you'd want to retreive on the next run.
Last edited by Trilby (2019-12-28 13:13:17)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Hey sorry for the late follow-up... I forgot I had posted this thread...
The Xrm database stores user preferences, right? I was just wondering, if I store into the database returned by XrmGetDatabase something like App.rootwindow.font=red, will this entry persist after restarting the program? The official documentation says "Specifying all of these options on the command line is awkward because users may want to customize many aspects of the program and need a convenient way to establish these customizations as the default settings" Does the x server have one large database that it passes to all clients? I just don't see how the concept of "default settings" can be implemented.
Offline
The Xrm database stores user preferences, right?
It can store anything (well, kinda ... anything that can be represented as a short string). It is often used for preferences / configurations. But as already stated, if you want to store some data from within your program and have it available on the next run of that same program, this is the wrong tool.
Look at xterm, urxvt and the like. They read various settings from the xrdb for font, colors, etc. These data are loaded into the xrdb by a call to the xrdb program when X starts up (if the user has such a call in their xinitrc or equivalent). All data in this db is gone once the x server shuts down / restarts. It must be loaded again every time the server restarts (hence the need for ~/.Xresources or ~/.Xdefaults).
I was just wondering, if I store into the database returned by XrmGetDatabase something like App.rootwindow.font=red, will this entry persist after restarting the program?
If the second run of the program is within the same X session, then yes. But this is not very practical, so for all real purposes, the answer to this question is 'No'. Again, the xrdb is not for storing data between runs of your program.
Does the x server have one large database that it passes to all clients?
Yes. This is why key names include various elements including the window class or resource name, e.g.:
URxvt.background = "#202428"
This would allow urxvt to retrieve values for resource class "URxvt" and get a "background" value of "#202428", but not get background values for other programs or resource names.
I just don't see how the concept of "default settings" can be implemented.
If you want users to be able to edit a text file to specify settings for your program, then they can write those settings in ~/.Xdefaults. Your documentation should note that they should be merging these data with the xrdb when X starts (this step is part of the default Xinitrc boiler-plate). Then when your program runs, you retrieve the user's prefered settings from the database.
But again, if you want your program to set these values at run time, and be able to retrieve them the next time it runs, the xrdb is the wrong tool for the job (it can be contorted into use for this purpose, but you will most likely not be happy, and I'm sure your programs users would not be happy with this). And so I ask again:
What are you actually trying to do?
This is a classic X-Y problem. You have some goal X, and you think tool Y (xrdb) will accomplish it. Tell us about X, because so far most of your questions suggest that the xrdb is probably not the right tool.
If you want storage for your programs own data that it reads and writes as users change options within your program, then you'd be better servered by berkley db or sqlite (I prefer the latter). Or if there are very few values that need to be stored, and you don't need users to be able to modify the stored data outside your program, just use your own data file.
Last edited by Trilby (2020-03-08 13:37:49)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thank you so much for the detailed answer! It all makes sense now... I'm not currently working on a project, but I will be in the near future. I am currently studying the source code of dwm (trying to learn xlib), which seems to use a very poorly documented xft library...
Offline
Err, ok. Xft has nothing to do with Xrdb, and dwm does not use the Xrdb at all.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Xft has nothing to do with Xrdb
yea of course... I was just pointing out a side note.
dwm does not use the Xrdb at all.
DWM messes alot with this WM_CLASS property. According to the manual, the WM_CLASS property is
Set by application programs to allow window and session managers to obtain the application's resources from the resource database
The resource database refers to the xrdb, right? If dwm doesn't even use the xrdb, why does it bother changing the WM_CLASS property at all with calls such as
XClassHint ch={null,null};
...
...
XSetClassHint(dpy,c->win, &ch);
...
...
XSetClassHint(dpy,m->barwin,&ch);
?
What is it trying to accomplish here?
Offline
Which manual page is that excerpt from? While strictly true, I'd say that is very misleading. That is one of very many uses of the WM_CLASS property.
DWM allows users to configure rules for windows. For example if a window matches a specified WM_CLASS, it can be assigned to a specific tag every time it starts up. Or other rules can specify that certain windows should "float" rather than be tiled. This is how DWM users will have their web browser open on one tag and a terminal on another, etc. This has nothing to with the xrdb. Many tools use properties like WM_CLASS for different purposes.
In DWM, the primary use is to get the class from each window mapped and check if there are any rules set for that window. This is in the "applyrules" function on lines 278-312 of the current dwm-git code. The other use is to specify the bar window's own WM_CLASS to be "dwm", "dwm" which would only be of use to other program that wanted to find the dwm bar window to interact with it (system tray applications perhaps).
Last edited by Trilby (2020-03-11 02:11:32)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
For example if a window matches a specified WM_CLASS, it can be assigned to a specific tag every time it starts up.
But then it is not about WM_CLASS itself, right? I can create, say, an atom with name "tag_number", and associate that on windows and achieve the same goal, right? Is there anything special about WM_CLASS that differentiates it from any other properties or atoms?
Offline
Is there anything special about WM_CLASS that differentiates it from any other properties or atoms?
Any property could be used, but many programs provide a mechanism to set their class value. If you used your own custom property users would have to use yet another program to create/set that property or atom on each window.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline