Skip to content

Commit 3aafa40

Browse files
committed
Merge branch 'inner-outer-pos-size' into 'main'
Add support for inner and outer position and size See merge request verso-browser/verso!323
2 parents d38636f + 28a182f commit 3aafa40

File tree

5 files changed

+77
-16
lines changed

5 files changed

+77
-16
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
members = ["verso", "versoview_messages", "versoview_build"]
33

44
[workspace.package]
5-
version = "0.0.2"
5+
version = "0.0.3"
66
edition = "2024"
77
license = "Apache-2.0 OR MIT"
88
homepage = "https://versotile.org/verso"

src/verso.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use script::{self, JSEngineSetup};
3333
use servo_config::{opts, pref};
3434
use servo_url::ServoUrl;
3535
use style;
36-
use versoview_messages::{ToControllerMessage, ToVersoMessage};
36+
use versoview_messages::{PositionType, SizeType, ToControllerMessage, ToVersoMessage};
3737
use webgpu;
3838
use webrender::{ShaderPrecacheFlags, WebRenderOptions, create_webrender_instance};
3939
use webrender_api::*;
@@ -697,21 +697,31 @@ impl Verso {
697697
let _ = window.window.drag_window();
698698
}
699699
}
700-
ToVersoMessage::GetSize(id) => {
700+
ToVersoMessage::GetSize(id, size_type) => {
701701
if let Some(window) = self.first_window() {
702702
if let Err(error) = self.to_controller_sender.as_ref().unwrap().send(
703-
ToControllerMessage::GetSizeResponse(id, window.window.inner_size()),
703+
ToControllerMessage::GetSizeResponse(
704+
id,
705+
match size_type {
706+
SizeType::Inner => window.window.inner_size(),
707+
SizeType::Outer => window.window.outer_size(),
708+
},
709+
),
704710
) {
705711
log::error!("Verso failed to send GetSizeReponse to controller: {error}")
706712
}
707713
}
708714
}
709-
ToVersoMessage::GetPosition(id) => {
715+
ToVersoMessage::GetPosition(id, position_type) => {
710716
if let Some(window) = self.first_window() {
711717
if let Err(error) = self.to_controller_sender.as_ref().unwrap().send(
712718
ToControllerMessage::GetPositionResponse(
713719
id,
714-
window.window.inner_position().ok(),
720+
match position_type {
721+
PositionType::Inner => window.window.inner_position(),
722+
PositionType::Outer => window.window.outer_position(),
723+
}
724+
.ok(),
715725
),
716726
) {
717727
log::error!(

verso/src/lib.rs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use std::{
1111
};
1212
pub use versoview_messages::{ConfigFromController as VersoviewSettings, ProfilerSettings};
1313
use versoview_messages::{
14-
ToControllerMessage, ToVersoMessage, WebResourceRequest, WebResourceRequestResponse,
14+
PositionType, SizeType, ToControllerMessage, ToVersoMessage, WebResourceRequest,
15+
WebResourceRequestResponse,
1516
};
1617

1718
use ipc_channel::{
@@ -298,15 +299,18 @@ impl VersoviewController {
298299
}
299300

300301
/// Get the window's size
301-
pub fn get_size(&self) -> Result<PhysicalSize<u32>, Box<ipc_channel::ErrorKind>> {
302+
fn get_size(
303+
&self,
304+
size_type: SizeType,
305+
) -> Result<PhysicalSize<u32>, Box<ipc_channel::ErrorKind>> {
302306
let id = uuid::Uuid::new_v4();
303307
let (sender, receiver) = std::sync::mpsc::channel();
304308
self.event_listeners
305309
.size_response
306310
.lock()
307311
.unwrap()
308312
.insert(id, sender);
309-
if let Err(error) = self.sender.send(ToVersoMessage::GetSize(id)) {
313+
if let Err(error) = self.sender.send(ToVersoMessage::GetSize(id, size_type)) {
310314
self.event_listeners
311315
.size_response
312316
.lock()
@@ -317,10 +321,26 @@ impl VersoviewController {
317321
Ok(receiver.recv().unwrap())
318322
}
319323

324+
/// Returns the physical size of the window's client area.
325+
///
326+
/// The client area is the content of the window, excluding the title bar and borders.
327+
pub fn get_inner_size(&self) -> Result<PhysicalSize<u32>, Box<ipc_channel::ErrorKind>> {
328+
self.get_size(SizeType::Inner)
329+
}
330+
331+
/// Returns the physical size of the entire window.
332+
///
333+
/// These dimensions include the title bar and borders.
334+
/// If you don't want that (and you usually don't), use [`Self::get_inner_size`] instead.
335+
pub fn get_outer_size(&self) -> Result<PhysicalSize<u32>, Box<ipc_channel::ErrorKind>> {
336+
self.get_size(SizeType::Outer)
337+
}
338+
320339
/// Get the window's position,
321340
/// returns [`None`] on unsupported platforms (currently only Wayland)
322-
pub fn get_position(
341+
fn get_position(
323342
&self,
343+
position_type: PositionType,
324344
) -> Result<Option<PhysicalPosition<i32>>, Box<ipc_channel::ErrorKind>> {
325345
let id = uuid::Uuid::new_v4();
326346
let (sender, receiver) = std::sync::mpsc::channel();
@@ -329,7 +349,10 @@ impl VersoviewController {
329349
.lock()
330350
.unwrap()
331351
.insert(id, sender);
332-
if let Err(error) = self.sender.send(ToVersoMessage::GetPosition(id)) {
352+
if let Err(error) = self
353+
.sender
354+
.send(ToVersoMessage::GetPosition(id, position_type))
355+
{
333356
self.event_listeners
334357
.position_response
335358
.lock()
@@ -340,6 +363,22 @@ impl VersoviewController {
340363
Ok(receiver.recv().unwrap())
341364
}
342365

366+
/// Get the window's inner position,
367+
/// returns [`None`] on unsupported platforms (currently only Wayland)
368+
pub fn get_inner_position(
369+
&self,
370+
) -> Result<Option<PhysicalPosition<i32>>, Box<ipc_channel::ErrorKind>> {
371+
self.get_position(PositionType::Inner)
372+
}
373+
374+
/// Get the window's outer position,
375+
/// returns [`None`] on unsupported platforms (currently only Wayland)
376+
pub fn get_outer_position(
377+
&self,
378+
) -> Result<Option<PhysicalPosition<i32>>, Box<ipc_channel::ErrorKind>> {
379+
self.get_position(PositionType::Outer)
380+
}
381+
343382
/// Get if the window is currently maximized or not
344383
pub fn is_maximized(&self) -> Result<bool, Box<ipc_channel::ErrorKind>> {
345384
let id = uuid::Uuid::new_v4();

versoview_messages/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ pub enum ToVersoMessage {
5151
/// Moves the window with the left mouse button until the button is released
5252
StartDragging,
5353
/// Get the window's size, need a response with [`ToControllerMessage::GetSizeResponse`]
54-
GetSize(uuid::Uuid),
54+
GetSize(uuid::Uuid, SizeType),
5555
/// Get the window's position, need a response with [`ToControllerMessage::GetPositionResponse`]
56-
GetPosition(uuid::Uuid),
56+
GetPosition(uuid::Uuid, PositionType),
5757
/// Get if the window is currently maximized or not, need a response with [`ToControllerMessage::GetMaximizedResponse`]
5858
GetMaximized(uuid::Uuid),
5959
/// Get if the window is currently minimized or not, need a response with [`ToControllerMessage::GetMinimizedResponse`]
@@ -68,6 +68,18 @@ pub enum ToVersoMessage {
6868
GetCurrentUrl(uuid::Uuid),
6969
}
7070

71+
#[derive(Debug, Serialize, Deserialize)]
72+
pub enum PositionType {
73+
Inner,
74+
Outer,
75+
}
76+
77+
#[derive(Debug, Serialize, Deserialize)]
78+
pub enum SizeType {
79+
Inner,
80+
Outer,
81+
}
82+
7183
/// Message sent from versoview to the controller
7284
#[derive(Debug, Serialize, Deserialize)]
7385
#[non_exhaustive]

0 commit comments

Comments
 (0)