diff --git a/src/marionette/message.rs b/src/marionette/message.rs index 476213e..af9f015 100644 --- a/src/marionette/message.rs +++ b/src/marionette/message.rs @@ -98,6 +98,16 @@ pub struct SwitchToWindowParams { pub focus: bool, } +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +#[allow(dead_code)] +pub struct WindowRect { + pub x: Option, + pub y: Option, + pub height: Option, + pub width: Option, +} + #[derive(Debug, Serialize)] #[serde(tag = "command", content = "params")] pub enum Command { @@ -119,4 +129,6 @@ pub enum Command { SwitchToWindow(SwitchToWindowParams), #[serde(rename = "WebDriver:FullscreenWindow")] FullscreenWindow, + #[serde(rename = "WebDriver:SetWindowRect")] + SetWindowRect(WindowRect), } diff --git a/src/marionette/mod.rs b/src/marionette/mod.rs index 15788d3..df0071e 100644 --- a/src/marionette/mod.rs +++ b/src/marionette/mod.rs @@ -20,7 +20,7 @@ pub use error::{CommandError, ConnectionError, ErrorResponse, MessageError}; use message::{ CloseWindowParams, Command, GetCurrentUrlResponse, GetTitleResponse, Hello, NavigateParams, NewSessionParams, NewSessionResponse, - SwitchToWindowParams, + SwitchToWindowParams, WindowRect, }; #[derive(Debug, Deserialize, Serialize)] @@ -251,6 +251,27 @@ impl Marionette { let res: String = self.conn.send_message(Command::NewWindow).await?.unwrap(); debug!("Received message: {:?}", res); + Ok(res.handle) + } + + pub async fn set_window_rect( + &mut self, + x: Option, + y: Option, + height: Option, + width: Option, + ) -> Result { + let res: WindowRect = self + .conn + .send_message(Command::SetWindowRect(WindowRect { + x, + y, + height, + width, + })) + .await? + .unwrap(); + debug!("Received message: {:?}", res); Ok(res) } diff --git a/src/monitor.rs b/src/monitor.rs index b077d6a..3a5a60e 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -3,5 +3,6 @@ pub struct Monitor { pub name: String, pub width: u32, pub height: u32, + pub x: i32, + pub y: i32, } - diff --git a/src/session.rs b/src/session.rs index 2b004d0..6ad340c 100644 --- a/src/session.rs +++ b/src/session.rs @@ -140,11 +140,22 @@ impl Session { let mut windowmap = HashMap::new(); let mut window = Some(handles.remove(handles.len() - 1)); for monitor in monitors { + debug!( + "Creating window for monitor {}: {}x{} ({}, {})", + monitor.name, + monitor.width, + monitor.height, + monitor.x, + monitor.y + ); if window.is_none() { window = Some(self.marionette.new_window().await?); } let w = window.take().unwrap(); self.marionette.switch_to_window(w.clone(), false).await?; + self.marionette + .set_window_rect(Some(monitor.x), Some(monitor.y), None, None) + .await?; self.marionette.fullscreen().await?; windowmap.insert(monitor.name, w); } @@ -218,6 +229,8 @@ fn get_monitors() -> Vec { name: m.name().unwrap().to_string(), width: m.width(), height: m.height(), + x: m.x(), + y: m.y(), }) .collect() } diff --git a/src/x11/xrandr.rs b/src/x11/xrandr.rs index f3043c1..f82bc55 100644 --- a/src/x11/xrandr.rs +++ b/src/x11/xrandr.rs @@ -29,6 +29,14 @@ impl XMonitor { pub fn name(&self) -> Option<&str> { Some(&self.name) } + + pub fn x(&self) -> i32 { + self.monitor.x as i32 + } + + pub fn y(&self) -> i32 { + self.monitor.y as i32 + } } /// Return information about the monitors attached to an X display