1
0
Fork 0
forked from wry/wry

config: add various new functions

This commit is contained in:
Julian Orth 2024-03-13 19:29:33 +01:00
parent f1a3705699
commit e24a61bc62
12 changed files with 435 additions and 28 deletions

View file

@ -506,6 +506,14 @@ impl Client {
self.send(&ClientMessage::SetEnv { key, val });
}
pub fn set_log_level(&self, level: LogLevel) {
self.send(&ClientMessage::SetLogLevel { level })
}
pub fn unset_env(&self, key: &str) {
self.send(&ClientMessage::UnsetEnv { key });
}
pub fn set_status(&self, status: &str) {
self.send(&ClientMessage::SetStatus { status });
}
@ -580,6 +588,12 @@ impl Client {
self.send(&ClientMessage::DisableDefaultSeat);
}
pub fn connector_get_position(&self, connector: Connector) -> (i32, i32) {
let res = self.send_with_response(&ClientMessage::ConnectorGetPosition { connector });
get_response!(res, (0, 0), ConnectorGetPosition { x, y });
(x, y)
}
pub fn connector_set_position(&self, connector: Connector, x: i32, y: i32) {
self.send(&ClientMessage::ConnectorSetPosition { connector, x, y });
}
@ -595,9 +609,49 @@ impl Client {
});
}
pub fn device_connectors(&self, device: DrmDevice) -> Vec<Connector> {
let res = self.send_with_response(&ClientMessage::GetDeviceConnectors { device });
get_response!(res, vec![], GetDeviceConnectors { connectors });
pub fn connector_get_name(&self, connector: Connector) -> String {
let res = self.send_with_response(&ClientMessage::GetConnectorName { connector });
get_response!(res, String::new(), GetConnectorName { name });
name
}
pub fn connector_get_model(&self, connector: Connector) -> String {
let res = self.send_with_response(&ClientMessage::GetConnectorModel { connector });
get_response!(res, String::new(), GetConnectorModel { model });
model
}
pub fn connector_get_manufacturer(&self, connector: Connector) -> String {
let res = self.send_with_response(&ClientMessage::GetConnectorManufacturer { connector });
get_response!(
res,
String::new(),
GetConnectorManufacturer { manufacturer }
);
manufacturer
}
pub fn connector_get_serial_number(&self, connector: Connector) -> String {
let res = self.send_with_response(&ClientMessage::GetConnectorSerialNumber { connector });
get_response!(
res,
String::new(),
GetConnectorSerialNumber { serial_number }
);
serial_number
}
pub fn connectors(&self, device: Option<DrmDevice>) -> Vec<Connector> {
if let Some(device) = device {
let res = self.send_with_response(&ClientMessage::GetDeviceConnectors { device });
get_response!(res, vec![], GetConnectors { connectors });
return connectors;
}
let res = self.send_with_response(&ClientMessage::GetConnectors {
device,
connected_only: false,
});
get_response!(res, vec![], GetConnectors { connectors });
connectors
}
@ -607,6 +661,12 @@ impl Client {
syspath
}
pub fn drm_device_devnode(&self, device: DrmDevice) -> String {
let res = self.send_with_response(&ClientMessage::GetDrmDeviceDevnode { device });
get_response!(res, String::new(), GetDrmDeviceDevnode { devnode });
devnode
}
pub fn drm_device_vendor(&self, device: DrmDevice) -> String {
let res = self.send_with_response(&ClientMessage::GetDrmDeviceVendor { device });
get_response!(res, String::new(), GetDrmDeviceVendor { vendor });
@ -727,6 +787,22 @@ impl Client {
self.on_devices_enumerated.set(Some(Box::new(f)));
}
pub fn config_dir(&self) -> String {
let res = self.send_with_response(&ClientMessage::GetConfigDir);
get_response!(res, String::new(), GetConfigDir { dir });
dir
}
pub fn workspaces(&self) -> Vec<Workspace> {
let res = self.send_with_response(&ClientMessage::GetWorkspaces);
get_response!(res, vec![], GetWorkspaces { workspaces });
workspaces
}
pub fn set_idle(&self, timeout: Duration) {
self.send(&ClientMessage::SetIdle { timeout })
}
pub fn set_seat(&self, device: InputDevice, seat: Seat) {
self.send(&ClientMessage::SetSeat { device, seat })
}
@ -776,6 +852,18 @@ impl Client {
name
}
pub fn input_device_syspath(&self, device: InputDevice) -> String {
let res = self.send_with_response(&ClientMessage::GetInputDeviceSyspath { device });
get_response!(res, String::new(), GetInputDeviceSyspath { syspath });
syspath
}
pub fn input_device_devnode(&self, device: InputDevice) -> String {
let res = self.send_with_response(&ClientMessage::GetInputDeviceDevnode { device });
get_response!(res, String::new(), GetInputDeviceDevnode { devnode });
devnode
}
pub fn has_capability(&self, device: InputDevice, cap: Capability) -> bool {
let res = self.send_with_response(&ClientMessage::HasCapability { device, cap });
get_response!(res, false, HasCapability { has });

View file

@ -385,6 +385,45 @@ pub enum ClientMessage<'a> {
DestroyKeymap {
keymap: Keymap,
},
GetConnectorName {
connector: Connector,
},
GetConnectorModel {
connector: Connector,
},
GetConnectorManufacturer {
connector: Connector,
},
GetConnectorSerialNumber {
connector: Connector,
},
GetConnectors {
device: Option<DrmDevice>,
connected_only: bool,
},
ConnectorGetPosition {
connector: Connector,
},
GetConfigDir,
GetWorkspaces,
UnsetEnv {
key: &'a str,
},
SetLogLevel {
level: LogLevel,
},
GetDrmDeviceDevnode {
device: DrmDevice,
},
GetInputDeviceSyspath {
device: InputDevice,
},
GetInputDeviceDevnode {
device: InputDevice,
},
SetIdle {
timeout: Duration,
},
}
#[derive(Serialize, Deserialize, Debug)]
@ -444,7 +483,7 @@ pub enum Response {
GetFullscreen {
fullscreen: bool,
},
GetDeviceConnectors {
GetConnectors {
connectors: Vec<Connector>,
},
GetDrmDeviceSyspath {
@ -493,6 +532,37 @@ pub enum Response {
AddPollable {
id: Result<PollableId, String>,
},
GetConnectorName {
name: String,
},
GetConnectorModel {
model: String,
},
GetConnectorManufacturer {
manufacturer: String,
},
GetConnectorSerialNumber {
serial_number: String,
},
ConnectorGetPosition {
x: i32,
y: i32,
},
GetConfigDir {
dir: String,
},
GetWorkspaces {
workspaces: Vec<Workspace>,
},
GetDrmDeviceDevnode {
devnode: String,
},
GetInputDeviceSyspath {
syspath: String,
},
GetInputDeviceDevnode {
devnode: String,
},
}
#[derive(Serialize, Deserialize, Debug)]

View file

@ -9,6 +9,13 @@ pub fn set_env(key: &str, val: &str) {
get!().set_env(key, val);
}
/// Unsets an environment variable.
///
/// This does not affect the compositor itself but only programs spawned by the compositor.
pub fn unset_env(key: &str) {
get!().unset_env(key);
}
/// A command to be spawned.
pub struct Command {
pub(crate) prog: String,

View file

@ -113,6 +113,20 @@ impl InputDevice {
pub fn set_natural_scrolling_enabled(self, enabled: bool) {
get!().set_input_natural_scrolling_enabled(self, enabled);
}
/// Returns the syspath of this device.
///
/// E.g. `/sys/devices/pci0000:00/0000:00:08.1/0000:14:00.4/usb5/5-1/5-1.1/5-1.1.3/5-1.1.3:1.0`.
pub fn syspath(self) -> String {
get!(String::new()).input_device_syspath(self)
}
/// Returns the devnode of this device.
///
/// E.g. `/dev/input/event7`.
pub fn devnode(self) -> String {
get!(String::new()).input_device_devnode(self)
}
}
/// A seat.

View file

@ -42,7 +42,10 @@
use {
crate::keyboard::ModifiedKeySym,
serde::{Deserialize, Serialize},
std::fmt::{Debug, Display, Formatter},
std::{
fmt::{Debug, Display, Formatter},
time::Duration,
},
};
#[macro_use]
@ -195,3 +198,20 @@ pub fn on_idle<F: FnMut() + 'static>(f: F) {
pub fn on_devices_enumerated<F: FnOnce() + 'static>(f: F) {
get!().on_devices_enumerated(f)
}
/// Returns the Jay config directory.
pub fn config_dir() -> String {
get!().config_dir()
}
/// Returns all visible workspaces.
pub fn workspaces() -> Vec<Workspace> {
get!().workspaces()
}
/// Configures the idle timeout.
///
/// `None` disables the timeout.
pub fn set_idle(timeout: Option<Duration>) {
get!().set_idle(timeout.unwrap_or_default())
}

View file

@ -14,3 +14,8 @@ pub enum LogLevel {
Debug,
Trace,
}
/// Sets the log level of the compositor.
pub fn set_log_level(level: LogLevel) {
get!().set_log_level(level);
}

View file

@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
///
/// When using hexadecimal notation, `#RRGGBBAA`, the RGB values are usually straight.
// values are stored premultiplied
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub struct Color {
r: f32,
g: f32,
@ -32,13 +32,13 @@ fn to_u8(c: f32) -> u8 {
}
fn validate_f32(f: f32) -> bool {
f.is_normal() && f >= 0.0 && f <= 1.0
f >= 0.0 && f <= 1.0
}
fn validate_f32_all(f: [f32; 4]) -> bool {
if !f.into_iter().all(validate_f32) {
log::warn!(
"f32 values {:?} are not in the valid color range. Using solid black instead",
"f32 values {:?} are not in the valid color range. Using solid black instead xyz",
f
);
return false;
@ -72,7 +72,7 @@ impl Color {
/// Creates a new color from premultiplied `f32` RGBA values.
pub fn new_f32_premultiplied(r: f32, g: f32, b: f32, a: f32) -> Self {
if validate_f32_all([r, g, b, a]) {
if !validate_f32_all([r, g, b, a]) {
Self::BLACK
} else if r > a || g > a || b > a {
log::warn!("f32 values {:?} are not valid valid for a premultiplied color. Using solid black instead.", [r, g, b, a]);
@ -84,7 +84,7 @@ impl Color {
/// Creates a new color from straight `f32` RGBA values.
pub fn new_f32_straight(r: f32, g: f32, b: f32, a: f32) -> Self {
if validate_f32_all([r, g, b, a]) {
if !validate_f32_all([r, g, b, a]) {
Self::BLACK
} else {
Self {

View file

@ -178,6 +178,14 @@ impl Connector {
self.mode().refresh_millihz
}
/// Retrieves the position of the output in the global compositor space.
pub fn position(self) -> (i32, i32) {
if !self.connected() {
return (0, 0);
}
get!().connector_get_position(self)
}
/// Sets the position of the connector in the global compositor space.
///
/// `x` and `y` must be non-negative and must not exceed a currently unspecified limit.
@ -212,6 +220,34 @@ impl Connector {
}
get!().connector_set_transform(self, transform);
}
pub fn name(self) -> String {
if !self.exists() {
return String::new();
}
get!(String::new()).connector_get_name(self)
}
pub fn model(self) -> String {
if !self.exists() {
return String::new();
}
get!(String::new()).connector_get_model(self)
}
pub fn manufacturer(self) -> String {
if !self.exists() {
return String::new();
}
get!(String::new()).connector_get_manufacturer(self)
}
pub fn serial_number(self) -> String {
if !self.exists() {
return String::new();
}
get!(String::new()).connector_get_serial_number(self)
}
}
/// Returns all available DRM devices.
@ -247,6 +283,10 @@ pub fn on_graphics_initialized<F: FnOnce() + 'static>(f: F) {
get!().on_graphics_initialized(f)
}
pub fn connectors() -> Vec<Connector> {
get!().connectors(None)
}
/// Returns the connector with the given id.
///
/// The linux kernel identifies connectors by a (type, idx) tuple, e.g., `DP-0`.
@ -381,7 +421,14 @@ pub struct DrmDevice(pub u64);
impl DrmDevice {
/// Returns the connectors of this device.
pub fn connectors(self) -> Vec<Connector> {
get!().device_connectors(self)
get!().connectors(Some(self))
}
/// Returns the devnode of this device.
///
/// E.g. `/dev/dri/card0`.
pub fn devnode(self) -> String {
get!().drm_device_devnode(self)
}
/// Returns the syspath of this device.