Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ The repository also comes with a script to automatically override Steam's deskto
```sh
./override_steam_desktop_file.sh
```

Optionally for exposing the wayland socket to specifically extest, without overriding the internal wayland session for steam (ex: using gamescope), you can use the following command:

```sh
env EXTEST_DISPLAY=$WAYLAND_DISPLAY LD_PRELOAD=/path/to/libextest.so steam
```
42 changes: 38 additions & 4 deletions src/wayland.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{env, os::unix::net::UnixStream, path::PathBuf};

use wayland_client::{
backend::Backend,
delegate_noop,
protocol::{wl_output, wl_registry},
Connection, Dispatch, Proxy, QueueHandle,
Expand All @@ -7,24 +10,55 @@ use wayland_protocols::xdg::xdg_output::zv1::client::{
zxdg_output_manager_v1::ZxdgOutputManagerV1, zxdg_output_v1,
};


#[derive(Copy, Clone, Default)]
pub struct DisplaySize {
pub width: i32,
pub height: i32
pub height: i32,
}

#[derive(Default)]
struct OutputData {
wl_outputs: Vec<wl_output::WlOutput>,
output_man: Option<ZxdgOutputManagerV1>,
max_size: DisplaySize
max_size: DisplaySize,
}

fn connect_to_wayland() -> Connection {
if let Some(socket_name) = env::var_os("EXTEST_DISPLAY").map(Into::<PathBuf>::into) {
let socket_path = if socket_name.is_absolute() {
socket_name.clone()
} else {
let mut socket_path = env::var_os("XDG_RUNTIME_DIR")
.map(Into::<PathBuf>::into)
.unwrap();
if !socket_path.is_absolute() {
panic!("XDG_RUNTIME_DIR is not absolute");
}
socket_path.push(&socket_name);
socket_path
};
let stream = UnixStream::connect(socket_path)
.map_err(|_| {
panic!(
"Failed to connect to Wayland socket: {}",
socket_name.display()
)
})
.unwrap();
let backend = Backend::connect(stream)
.map_err(|_| panic!("Failed to connect to Wayland backend"))
.unwrap();
Connection::from_backend(backend)
} else {
// Default to standard Wayland connection if EXTEST_DISPLAY is not set
Connection::connect_to_env().unwrap()
}
}

/// Returns the largest dimensions of the detected monitors
#[must_use]
pub fn get_axes_range() -> DisplaySize {
let conn = Connection::connect_to_env().unwrap();
let conn = connect_to_wayland();
let display = conn.display();
let mut queue = conn.new_event_queue();
let handle = queue.handle();
Expand Down