1
0
Fork 0
forked from wry/wry

config: allow running commands privileged

This commit is contained in:
Julian Orth 2024-04-01 13:16:34 +02:00
parent 4558bdb7c1
commit affea49e49
11 changed files with 74 additions and 5 deletions

View file

@ -944,6 +944,12 @@ impl Client {
})
}
pub fn get_socket_path(&self) -> Option<String> {
let res = self.send_with_response(&ClientMessage::GetSocketPath);
get_response!(res, None, GetSocketPath { path });
Some(path)
}
pub fn create_pollable(&self, fd: i32) -> Result<PollableId, String> {
let res = self.send_with_response(&ClientMessage::AddPollable { fd });
get_response!(

View file

@ -431,6 +431,7 @@ pub enum ClientMessage<'a> {
SetExplicitSyncEnabled {
enabled: bool,
},
GetSocketPath,
}
#[derive(Serialize, Deserialize, Debug)]
@ -576,6 +577,9 @@ pub enum Response {
GetInputDeviceDevnode {
devnode: String,
},
GetSocketPath {
path: String,
},
}
#[derive(Serialize, Deserialize, Debug)]

View file

@ -82,6 +82,21 @@ impl Command {
self.fd(2, fd)
}
/// Runs the application with access to privileged wayland protocols.
///
/// The default is `false`.
pub fn privileged(&mut self) -> &mut Self {
match get!(self).get_socket_path() {
Some(path) => {
self.env("WAYLAND_DISPLAY", &format!("{path}.jay"));
}
_ => {
log::error!("Compositor did not send the socket path");
}
}
self
}
/// Executes the command.
///
/// This consumes all attached file descriptors.