Move windows to their monitors
When we create Firefox windows for each monitor, we need to move them to their respective screens. The Marionette protocol provides a `SetWindowRect` command that *should* move the active window (it doesn't work for all window managers, notably *i3*).dev/ci
parent
311e73e097
commit
ebb5318390
|
@ -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<i32>,
|
||||
pub y: Option<i32>,
|
||||
pub height: Option<u32>,
|
||||
pub width: Option<u32>,
|
||||
}
|
||||
|
||||
#[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),
|
||||
}
|
||||
|
|
|
@ -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<i32>,
|
||||
y: Option<i32>,
|
||||
height: Option<u32>,
|
||||
width: Option<u32>,
|
||||
) -> Result<WindowRect, CommandError> {
|
||||
let res: WindowRect = self
|
||||
.conn
|
||||
.send_message(Command::SetWindowRect(WindowRect {
|
||||
x,
|
||||
y,
|
||||
height,
|
||||
width,
|
||||
}))
|
||||
.await?
|
||||
.unwrap();
|
||||
debug!("Received message: {:?}", res);
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,5 +3,6 @@ pub struct Monitor {
|
|||
pub name: String,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Monitor> {
|
|||
name: m.name().unwrap().to_string(),
|
||||
width: m.width(),
|
||||
height: m.height(),
|
||||
x: m.x(),
|
||||
y: m.y(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue