Struct Database
pub struct Database { /* private fields */ }
Expand description
A X11 resource database.
The recommended way to load a database is through Database::new_from_default
.
Implementations§
§impl Database
impl Database
pub const GET_RESOURCE_DATABASE: GetPropertyRequest = _
pub const GET_RESOURCE_DATABASE: GetPropertyRequest = _
The GetPropertyRequest to load the X11 resource database from the root window.
Copy this struct, set its window
field to the root window of the first screen send the
resulting request to the X11 server. The reply can be passed to
Self::new_from_default
.
pub fn new_from_default(
reply: &GetPropertyReply,
hostname: OsString,
) -> Database
pub fn new_from_default( reply: &GetPropertyReply, hostname: OsString, ) -> Database
Create a new X11 resource database from the default locations.
The reply
argument should come from Self::GET_RESOURCE_DATABASE
with its window
field set to the window ID of the first root window. The hostname
argument should be the
hostname of the running system.
The default location is a combination of two places. First, the following places are searched for data:
- The
RESOURCE_MANAGER
property of the first screen’s root window (SeeSelf::GET_RESOURCE_DATABASE
andSelf::new_from_get_property_reply
). - If not found, the file
$HOME/.Xresources
is loaded. - If not found, the file
$HOME/.Xdefaults
is loaded.
The result of the above search of the above search is combined with:
- The contents of the file
$XENVIRONMENT
, if this environment variable is set. - Otherwise, the contents of
$HOME/.Xdefaults-[hostname]
.
This function only returns an error if communication with the X11 server fails. All other errors are ignored. It might be that an empty database is returned.
The behaviour of this function is mostly equivalent to Xlib’s XGetDefault()
. The
exception is that XGetDefault()
does not load $HOME/.Xresources
.
The behaviour of this function is equivalent to xcb-util-xrm’s
xcb_xrm_database_from_default()
.
pub fn new_from_get_property_reply(reply: &GetPropertyReply) -> Option<Database>
pub fn new_from_get_property_reply(reply: &GetPropertyReply) -> Option<Database>
Construct a new X11 resource database from a GetPropertyReply
.
The reply should come from Self::GET_RESOURCE_DATABASE
with its window
field set to
the window ID of the first root window.
pub fn new_from_data(data: &[u8]) -> Database
pub fn new_from_data(data: &[u8]) -> Database
Construct a new X11 resource database from raw data.
This function parses data like Some.Entry: Value\n#include "some_file"\n
and returns the
resulting resource database. Parsing cannot fail since unparsable lines are simply ignored.
See Self::new_from_data_with_base_directory
for a version that allows to provide a path that
is used for resolving relative #include
statements.
pub fn new_from_data_with_base_directory(
data: &[u8],
base_path: impl AsRef<Path>,
) -> Database
pub fn new_from_data_with_base_directory( data: &[u8], base_path: impl AsRef<Path>, ) -> Database
Construct a new X11 resource database from raw data.
This function parses data like Some.Entry: Value\n#include "some_file"\n
and returns the
resulting resource database. Parsing cannot fail since unparsable lines are simply ignored.
When a relative #include
statement is encountered, the file to include is searched
relative to the given base_path
.
pub fn get_bytes(
&self,
resource_name: &str,
resource_class: &str,
) -> Option<&[u8]>
pub fn get_bytes( &self, resource_name: &str, resource_class: &str, ) -> Option<&[u8]>
Get a value from the resource database as a byte slice.
The given values describe a query to the resource database. resource_class
can be an
empty string, but otherwise must contain the same number of components as resource_name
.
Both strings may only contain alphanumeric characters or ‘-’, ‘_’, and ‘.’.
For example, this is how Xterm could query one of its settings if it where written in Rust
(see man xterm
):
use x11rb_protocol::resource_manager::Database;
fn get_pointer_shape(db: &Database) -> &[u8] {
db.get_bytes("XTerm.vt100.pointerShape", "XTerm.VT100.Cursor").unwrap_or(b"xterm")
}
pub fn get_string(
&self,
resource_name: &str,
resource_class: &str,
) -> Option<&str>
pub fn get_string( &self, resource_name: &str, resource_class: &str, ) -> Option<&str>
Get a value from the resource database as a byte slice.
The given values describe a query to the resource database. resource_class
can be an
empty string, but otherwise must contain the same number of components as resource_name
.
Both strings may only contain alphanumeric characters or ‘-’, ‘_’, and ‘.’.
If an entry is found that is not a valid utf8 str
, None
is returned.
For example, this is how Xterm could query one of its settings if it where written in Rust
(see man xterm
):
use x11rb_protocol::resource_manager::Database;
fn get_pointer_shape(db: &Database) -> &str {
db.get_string("XTerm.vt100.pointerShape", "XTerm.VT100.Cursor").unwrap_or("xterm")
}
pub fn get_bool(
&self,
resource_name: &str,
resource_class: &str,
) -> Option<bool>
pub fn get_bool( &self, resource_name: &str, resource_class: &str, ) -> Option<bool>
Get a value from the resource database as a byte slice.
The given values describe a query to the resource database. resource_class
can be an
empty string, but otherwise must contain the same number of components as resource_name
.
Both strings may only contain alphanumeric characters or ‘-’, ‘_’, and ‘.’.
This function interprets “true”, “on”, “yes” as true-ish and “false”, “off”, “no” als
false-ish. Numbers are parsed and are true if they are not zero. Unknown values are mapped
to None
.
For example, this is how Xterm could query one of its settings if it where written in Rust
(see man xterm
):
use x11rb_protocol::resource_manager::Database;
fn get_bell_is_urgent(db: &Database) -> bool {
db.get_bool("XTerm.vt100.bellIsUrgent", "XTerm.VT100.BellIsUrgent").unwrap_or(false)
}
pub fn get_value<T>(
&self,
resource_name: &str,
resource_class: &str,
) -> Result<Option<T>, <T as FromStr>::Err>where
T: FromStr,
pub fn get_value<T>(
&self,
resource_name: &str,
resource_class: &str,
) -> Result<Option<T>, <T as FromStr>::Err>where
T: FromStr,
Get a value from the resource database and parse it.
The given values describe a query to the resource database. resource_class
can be an
empty string, but otherwise must contain the same number of components as resource_name
.
Both strings may only contain alphanumeric characters or ‘-’, ‘_’, and ‘.’.
If no value is found, Ok(None)
is returned. Otherwise, the result from
[FromStr::from_str]
is returned with Ok(value)
replaced with Ok(Some(value))
.
For example, this is how Xterm could query one of its settings if it where written in Rust
(see man xterm
):
use x11rb_protocol::resource_manager::Database;
fn get_print_attributes(db: &Database) -> u8 {
db.get_value("XTerm.vt100.printAttributes", "XTerm.VT100.PrintAttributes")
.ok().flatten().unwrap_or(1)
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Database
impl RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnwindSafe for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)