pub struct FrameConfig {
pub theme: ColorTheme,
pub hide_titlebar: bool,
}Expand description
The configuration for the AdwaitaFrame frame.
Fields§
§theme: ColorTheme§hide_titlebar: boolDraw decorations but without the titlebar
Implementations§
Source§impl FrameConfig
impl FrameConfig
Sourcepub fn new(theme: ColorTheme) -> Self
pub fn new(theme: ColorTheme) -> Self
Create the new configuration with the given theme.
Sourcepub fn auto() -> Self
pub fn auto() -> Self
This is equivalent of calling FrameConfig::new(ColorTheme::auto()).
For details see ColorTheme::auto.
Examples found in repository?
examples/window.rs (line 256)
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 }
325}
326
327impl SeatHandler for SimpleWindow {
328 fn seat_state(&mut self) -> &mut SeatState {
329 &mut self.seat_state
330 }
331
332 fn new_seat(&mut self, _: &Connection, _: &QueueHandle<Self>, _: wl_seat::WlSeat) {}
333
334 fn new_capability(
335 &mut self,
336 _conn: &Connection,
337 qh: &QueueHandle<Self>,
338 seat: wl_seat::WlSeat,
339 capability: Capability,
340 ) {
341 if capability == Capability::Pointer && self.themed_pointer.is_none() {
342 println!("Set pointer capability");
343 println!("Creating pointer theme");
344 let surface = self.compositor_state.create_surface(qh);
345 let themed_pointer = self
346 .seat_state
347 .get_pointer_with_theme(
348 qh,
349 &seat,
350 self.shm_state.wl_shm(),
351 surface,
352 ThemeSpec::default(),
353 )
354 .expect("Failed to create pointer");
355 self.themed_pointer.replace(themed_pointer);
356 }
357 }
358
359 fn remove_capability(
360 &mut self,
361 _conn: &Connection,
362 _: &QueueHandle<Self>,
363 _: wl_seat::WlSeat,
364 capability: Capability,
365 ) {
366 if capability == Capability::Pointer && self.themed_pointer.is_some() {
367 println!("Unset pointer capability");
368 self.themed_pointer.take().unwrap().pointer().release();
369 }
370 }
371
372 fn remove_seat(&mut self, _: &Connection, _: &QueueHandle<Self>, _: wl_seat::WlSeat) {}
373}
374
375impl PointerHandler for SimpleWindow {
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 }Sourcepub fn light() -> Self
pub fn light() -> Self
This is equivalent of calling FrameConfig::new(ColorTheme::light()).
For details see ColorTheme::light.
Sourcepub fn dark() -> Self
pub fn dark() -> Self
This is equivalent of calling FrameConfig::new(ColorTheme::dark()).
For details see ColorTheme::dark.
Sourcepub fn hide_titlebar(self, hide: bool) -> Self
pub fn hide_titlebar(self, hide: bool) -> Self
Draw decorations but without the titlebar
Examples found in repository?
examples/window.rs (line 256)
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 }
325}
326
327impl SeatHandler for SimpleWindow {
328 fn seat_state(&mut self) -> &mut SeatState {
329 &mut self.seat_state
330 }
331
332 fn new_seat(&mut self, _: &Connection, _: &QueueHandle<Self>, _: wl_seat::WlSeat) {}
333
334 fn new_capability(
335 &mut self,
336 _conn: &Connection,
337 qh: &QueueHandle<Self>,
338 seat: wl_seat::WlSeat,
339 capability: Capability,
340 ) {
341 if capability == Capability::Pointer && self.themed_pointer.is_none() {
342 println!("Set pointer capability");
343 println!("Creating pointer theme");
344 let surface = self.compositor_state.create_surface(qh);
345 let themed_pointer = self
346 .seat_state
347 .get_pointer_with_theme(
348 qh,
349 &seat,
350 self.shm_state.wl_shm(),
351 surface,
352 ThemeSpec::default(),
353 )
354 .expect("Failed to create pointer");
355 self.themed_pointer.replace(themed_pointer);
356 }
357 }
358
359 fn remove_capability(
360 &mut self,
361 _conn: &Connection,
362 _: &QueueHandle<Self>,
363 _: wl_seat::WlSeat,
364 capability: Capability,
365 ) {
366 if capability == Capability::Pointer && self.themed_pointer.is_some() {
367 println!("Unset pointer capability");
368 self.themed_pointer.take().unwrap().pointer().release();
369 }
370 }
371
372 fn remove_seat(&mut self, _: &Connection, _: &QueueHandle<Self>, _: wl_seat::WlSeat) {}
373}
374
375impl PointerHandler for SimpleWindow {
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 Clone for FrameConfig
impl Clone for FrameConfig
Source§fn clone(&self) -> FrameConfig
fn clone(&self) -> FrameConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FrameConfig
impl RefUnwindSafe for FrameConfig
impl Send for FrameConfig
impl Sync for FrameConfig
impl Unpin for FrameConfig
impl UnwindSafe for FrameConfig
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.