pub struct AdwaitaFrame<State> { /* private fields */ }Expand description
A simple set of decorations
Implementations§
Source§impl<State> AdwaitaFrame<State>
impl<State> AdwaitaFrame<State>
Sourcepub fn new(
base_surface: &impl WaylandSurface,
shm: &Shm,
compositor: Arc<CompositorState>,
subcompositor: Arc<SubcompositorState>,
queue_handle: QueueHandle<State>,
frame_config: FrameConfig,
) -> Result<Self, Box<dyn Error>>
pub fn new( base_surface: &impl WaylandSurface, shm: &Shm, compositor: Arc<CompositorState>, subcompositor: Arc<SubcompositorState>, queue_handle: QueueHandle<State>, frame_config: FrameConfig, ) -> Result<Self, Box<dyn Error>>
Examples found in repository?
examples/window.rs (lines 250-257)
233 fn configure(
234 &mut self,
235 conn: &Connection,
236 qh: &QueueHandle<Self>,
237 window: &Window,
238 configure: WindowConfigure,
239 _serial: u32,
240 ) {
241 self.buffer = None;
242
243 println!(
244 "Configure size {:?}, decorations: {:?}",
245 configure.new_size, configure.decoration_mode
246 );
247
248 let (width, height) = if configure.decoration_mode == DecorationMode::Client {
249 let window_frame = self.window_frame.get_or_insert_with(|| {
250 let mut frame = AdwaitaFrame::new(
251 &self.window,
252 &self.shm_state,
253 self.compositor_state.clone(),
254 self.subcompositor_state.clone(),
255 qh.clone(),
256 FrameConfig::auto().hide_titlebar(self.hide_titlebar),
257 )
258 .expect("failed to create client side decorations frame.");
259 frame.set_title(self.title.clone());
260 frame
261 });
262
263 // Un-hide the frame.
264 window_frame.set_hidden(false);
265
266 // Configure state before touching any resizing.
267 window_frame.update_state(configure.state);
268
269 // Configure the button state.
270 window_frame.update_wm_capabilities(configure.capabilities);
271
272 let (width, height) = match configure.new_size {
273 (Some(width), Some(height)) => {
274 // The size could be 0.
275 window_frame.subtract_borders(width, height)
276 }
277 _ => {
278 // You might want to consider checking for configure bounds.
279 (Some(self.width), Some(self.height))
280 }
281 };
282
283 // Clamp the size to at least one pixel.
284 let width = width.unwrap_or(NonZeroU32::new(1).unwrap());
285 let height = height.unwrap_or(NonZeroU32::new(1).unwrap());
286
287 window_frame.resize(width, height);
288
289 let (x, y) = window_frame.location();
290 let outer_size = window_frame.add_borders(width.get(), height.get());
291 window.xdg_surface().set_window_geometry(
292 x,
293 y,
294 outer_size.0 as i32,
295 outer_size.1 as i32,
296 );
297
298 (width, height)
299 } else {
300 // Hide the frame, if any.
301 if let Some(frame) = self.window_frame.as_mut() {
302 frame.set_hidden(true)
303 }
304 let width = configure.new_size.0.unwrap_or(self.width);
305 let height = configure.new_size.1.unwrap_or(self.height);
306 self.window.xdg_surface().set_window_geometry(
307 0,
308 0,
309 width.get() as i32,
310 height.get() as i32,
311 );
312 (width, height)
313 };
314
315 // Update new width and height;
316 self.width = width;
317 self.height = height;
318
319 // Initiate the first draw.
320 if self.first_configure {
321 self.first_configure = false;
322 self.draw(conn, qh);
323 }
324 }Sourcepub fn set_config(&mut self, config: FrameConfig)
pub fn set_config(&mut self, config: FrameConfig)
Update the current frame config.
Examples found in repository?
examples/window.rs (line 462)
376 fn pointer_frame(
377 &mut self,
378 _conn: &Connection,
379 _qh: &QueueHandle<Self>,
380 pointer: &wl_pointer::WlPointer,
381 events: &[PointerEvent],
382 ) {
383 use PointerEventKind::*;
384 for event in events {
385 let (x, y) = event.position;
386 match event.kind {
387 Enter { .. } => {
388 self.set_cursor = true;
389 self.cursor_icon = self
390 .window_frame
391 .as_mut()
392 .and_then(|frame| {
393 frame.click_point_moved(Duration::ZERO, &event.surface.id(), x, y)
394 })
395 .unwrap_or(CursorIcon::Crosshair)
396 .to_owned();
397
398 if &event.surface == self.window.wl_surface() {
399 println!("Pointer entered @{:?}", event.position);
400 }
401 }
402 Leave { .. } => {
403 if &event.surface != self.window.wl_surface() {
404 if let Some(window_frame) = self.window_frame.as_mut() {
405 window_frame.click_point_left();
406 }
407 }
408 println!("Pointer left");
409 }
410 Motion { time } => {
411 if let Some(new_cursor) = self.window_frame.as_mut().and_then(|frame| {
412 frame.click_point_moved(
413 Duration::from_millis(time as u64),
414 &event.surface.id(),
415 x,
416 y,
417 )
418 }) {
419 self.set_cursor = true;
420 self.cursor_icon = new_cursor.to_owned();
421 }
422 }
423 Press {
424 button,
425 serial,
426 time,
427 }
428 | Release {
429 button,
430 serial,
431 time,
432 } => {
433 let pressed = if matches!(event.kind, Press { .. }) {
434 true
435 } else {
436 false
437 };
438 if &event.surface != self.window.wl_surface() {
439 let click = match button {
440 0x110 => FrameClick::Normal,
441 0x111 => FrameClick::Alternate,
442 _ => continue,
443 };
444
445 if let Some(action) = self.window_frame.as_mut().and_then(|frame| {
446 frame.on_click(Duration::from_millis(time as u64), click, pressed)
447 }) {
448 self.frame_action(pointer, serial, action);
449 }
450 } else if pressed {
451 println!("Press {:x} @ {:?}", button, event.position);
452
453 // Hide/Show titlebar on right click
454 if button == 0x111 {
455 self.hide_titlebar = !self.hide_titlebar;
456
457 if let Some(frame) = self.window_frame.as_mut() {
458 // FrameConfig::auto() is not free, this shouldn't be called here
459 let config = FrameConfig::auto();
460
461 if self.hide_titlebar {
462 frame.set_config(config.hide_titlebar(true));
463 self.window.xdg_surface().set_window_geometry(
464 0,
465 0,
466 self.width.get() as i32,
467 self.height.get() as i32,
468 );
469 } else {
470 let (width, height) = (self.width, self.height);
471
472 frame.set_config(config.hide_titlebar(false));
473 frame.resize(width, height);
474
475 let (x, y) = frame.location();
476 let outer_size = frame.add_borders(width.get(), height.get());
477 self.window.xdg_surface().set_window_geometry(
478 x,
479 y,
480 outer_size.0 as i32,
481 outer_size.1 as i32,
482 );
483
484 // Update new width and height;
485 self.width = width;
486 self.height = height;
487 }
488 }
489 } else {
490 self.shift = self.shift.xor(Some(0));
491 }
492 }
493 }
494 Axis {
495 horizontal,
496 vertical,
497 ..
498 } => {
499 if &event.surface == self.window.wl_surface() {
500 println!("Scroll H:{horizontal:?}, V:{vertical:?}");
501 }
502 }
503 }
504 }
505 }Trait Implementations§
Source§impl<State: Debug> Debug for AdwaitaFrame<State>
impl<State: Debug> Debug for AdwaitaFrame<State>
Source§impl<State> DecorationsFrame for AdwaitaFrame<State>
impl<State> DecorationsFrame for AdwaitaFrame<State>
Source§fn update_state(&mut self, state: WindowState)
fn update_state(&mut self, state: WindowState)
Update the state of the frame. Read more
Source§fn update_wm_capabilities(&mut self, wm_capabilities: WindowManagerCapabilities)
fn update_wm_capabilities(&mut self, wm_capabilities: WindowManagerCapabilities)
Update the window manager capabilites. Read more
Set the frame as hidden. Read more
Source§fn set_resizable(&mut self, resizable: bool)
fn set_resizable(&mut self, resizable: bool)
Mark the frame as resizable. Read more
Source§fn resize(&mut self, width: NonZeroU32, height: NonZeroU32)
fn resize(&mut self, width: NonZeroU32, height: NonZeroU32)
Resize the window to the new size. Read more
Source§fn subtract_borders(
&self,
width: NonZeroU32,
height: NonZeroU32,
) -> (Option<NonZeroU32>, Option<NonZeroU32>)
fn subtract_borders( &self, width: NonZeroU32, height: NonZeroU32, ) -> (Option<NonZeroU32>, Option<NonZeroU32>)
Source§fn location(&self) -> (i32, i32)
fn location(&self) -> (i32, i32)
Return the coordinates of the top-left corner of the borders relative to
the content. Read more
Source§fn on_click(
&mut self,
timestamp: Duration,
click: FrameClick,
pressed: bool,
) -> Option<FrameAction>
fn on_click( &mut self, timestamp: Duration, click: FrameClick, pressed: bool, ) -> Option<FrameAction>
Emulate click on the decorations. Read more
Source§fn set_scaling_factor(&mut self, scale_factor: f64)
fn set_scaling_factor(&mut self, scale_factor: f64)
Set the scaling of the decorations frame. Read more
Source§fn click_point_moved(
&mut self,
_timestamp: Duration,
surface: &ObjectId,
x: f64,
y: f64,
) -> Option<CursorIcon>
fn click_point_moved( &mut self, _timestamp: Duration, surface: &ObjectId, x: f64, y: f64, ) -> Option<CursorIcon>
Emulate pointer moved event on the decorations frame. Read more
Source§fn click_point_left(&mut self)
fn click_point_left(&mut self)
All clicks left the decorations. Read more
Get the frame hidden state. Read more
Auto Trait Implementations§
impl<State> Freeze for AdwaitaFrame<State>
impl<State> !RefUnwindSafe for AdwaitaFrame<State>
impl<State> Send for AdwaitaFrame<State>
impl<State> Sync for AdwaitaFrame<State>
impl<State> Unpin for AdwaitaFrame<State>
impl<State> !UnwindSafe for AdwaitaFrame<State>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.