Skip to content

Commit

Permalink
Update/Destroy outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhbooth committed May 29, 2024
1 parent 2412a38 commit 4953878
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 182 deletions.
27 changes: 21 additions & 6 deletions src/client/smithay_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ use crate::serialization::wayland::KeyInner;
use crate::serialization::wayland::KeyState;
use crate::serialization::wayland::KeyboardEvent;
use crate::serialization::wayland::Output;
use crate::serialization::wayland::OutputEvent;
use crate::serialization::wayland::SourceMetadata;
use crate::serialization::wayland::SurfaceEvent;
use crate::serialization::wayland::SurfaceEventPayload::OutputsChanged;
Expand Down Expand Up @@ -181,20 +182,34 @@ impl OutputHandler for WprsClientState {
&mut self.output_state
}

#[instrument(skip(self, _conn, _qh), level = "debug")]
fn new_output(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, output: WlOutput) {
let output_info = self.output_state().info(&output).unwrap();
debug!("NEW OUTPUT {:?}", &output_info);
self.serializer
.writer()
.send(SendType::Object(Event::Output(output_info.into())));
.send(SendType::Object(Event::Output(OutputEvent::New(
output_info.into(),
))));
}

fn update_output(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _output: WlOutput) {
// TODO
#[instrument(skip(self, _conn, _qh), level = "debug")]
fn update_output(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, output: WlOutput) {
let output_info = self.output_state().info(&output).unwrap();
self.serializer
.writer()
.send(SendType::Object(Event::Output(OutputEvent::Update(
output_info.into(),
))));
}

fn output_destroyed(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _output: WlOutput) {
// TODO
#[instrument(skip(self, _conn, _qh), level = "debug")]
fn output_destroyed(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, output: WlOutput) {
let output_info = self.output_state().info(&output).unwrap();
self.serializer
.writer()
.send(SendType::Object(Event::Output(OutputEvent::Destroy(
output_info.into(),
))));
}
}

Expand Down
57 changes: 57 additions & 0 deletions src/compositor_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashSet;
use std::sync::Mutex;
use std::time::Duration;

use smithay::output::Mode;
use smithay::output::Output;
use smithay::output::Scale;
use smithay::reexports::wayland_server::protocol::wl_buffer::WlBuffer;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::reexports::wayland_server::Resource;
Expand All @@ -26,6 +30,7 @@ use smithay::wayland::shm::BufferData;

use crate::buffer_pointer::BufferPointer;
use crate::prelude::*;
use crate::serialization::wayland::OutputInfo;

/// # Panics
/// If smithay has a bug and with_buffer_contents gives us an invalid pointer.
Expand Down Expand Up @@ -94,3 +99,55 @@ pub fn send_frames(
}
Ok(())
}

pub fn update_output(local_output: &mut Output, output: OutputInfo) {
let current_mode = local_output.current_mode().unwrap_or(Mode {
size: (0, 0).into(),
refresh: 0,
});
let received_mode = Mode {
size: output.mode.dimensions.into(),
refresh: output.mode.refresh_rate,
};
if current_mode != received_mode {
local_output.delete_mode(current_mode);
}

local_output.change_current_state(
Some(received_mode),
Some(output.transform.into()),
Some(Scale::Integer(output.scale_factor)),
Some(output.location.into()),
);

if output.mode.preferred {
local_output.set_preferred(received_mode);
}
}

pub fn update_surface_outputs<'a, F>(
surface: &WlSurface,
new_ids: &HashSet<u32>,
old_ids: &HashSet<u32>,
output_accessor: F,
) where
F: Fn(&u32) -> Option<&'a Output>,
{
let entered_ids = new_ids.difference(old_ids);
let left_ids = old_ids.difference(new_ids);

// careful, a surface can be on multiple outputs, and the surface scale is the largest scale among them
for id in entered_ids {
let output = output_accessor(id);
if let Some(output) = output {
output.enter(surface);
}
}

for id in left_ids {
let output = output_accessor(id);
if let Some(output) = output {
output.leave(surface);
}
}
}
2 changes: 1 addition & 1 deletion src/serialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub enum Request {
#[archive_attr(derive(bytecheck::CheckBytes, Debug))]
pub enum Event {
WprsClientConnect,
Output(wayland::OutputInfo),
Output(wayland::OutputEvent),
PointerFrame(Vec<wayland::PointerEvent>),
KeyboardEvent(wayland::KeyboardEvent),
Toplevel(xdg_shell::ToplevelEvent),
Expand Down
9 changes: 9 additions & 0 deletions src/serialization/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ pub struct SurfaceState {
pub opaque_region: Option<Region>,
pub input_region: Option<Region>,
pub z_ordered_children: Vec<SubsurfacePosition>,
// server-side only
pub output_ids: Vec<u32>,

// Interfaces
Expand Down Expand Up @@ -1018,6 +1019,14 @@ pub enum DataEvent {
TransferData(DataSource, DataToTransfer),
}

#[derive(Debug, Clone, PartialEq, Eq, Archive, Deserialize, Serialize)]
#[archive_attr(derive(bytecheck::CheckBytes, Debug))]
pub enum OutputEvent {
New(OutputInfo),
Update(OutputInfo),
Destroy(OutputInfo),
}

#[derive(Debug, Clone, PartialEq, Eq, Archive, Deserialize, Serialize)]
#[archive_attr(derive(bytecheck::CheckBytes, Debug))]
pub struct Output {
Expand Down
Loading

0 comments on commit 4953878

Please sign in to comment.