Skip to content

Commit

Permalink
linux/wayland: implement fullscreen requests
Browse files Browse the repository at this point in the history
  • Loading branch information
hch12907 committed Sep 20, 2023
1 parent 76f1ce3 commit 9e989de
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion src/native/linux_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use libxkbcommon::*;

use crate::{
event::{EventHandler, KeyCode, KeyMods, MouseButton},
native::{egl, NativeDisplayData},
native::{egl, NativeDisplayData, Request},
};

use std::collections::HashSet;
Expand Down Expand Up @@ -710,6 +710,17 @@ where
panic!("eglMakeCurrent failed");
}

// For some reason, setting fullscreen before egl_window is created leads
// to segfault because wl_egl_window_create returns NULL.
if conf.fullscreen {
wl_request!(
display.client,
display.xdg_toplevel,
extensions::xdg_shell::xdg_toplevel::set_fullscreen,
std::ptr::null_mut::<*mut wl_output>()
)
}

crate::native::gl::load_gl_funcs(|proc| {
let name = std::ffi::CString::new(proc).unwrap();
libegl.eglGetProcAddress.expect("non-null function pointer")(name.as_ptr() as _)
Expand Down Expand Up @@ -759,6 +770,28 @@ where
event_handler.key_down_event(keycode.clone(), keymods, true);
}

while let Ok(request) = rx.try_recv() {
match request {
Request::SetFullscreen(full) => if full {
wl_request!(
display.client,
display.xdg_toplevel,
extensions::xdg_shell::xdg_toplevel::set_fullscreen,
std::ptr::null_mut::<*mut wl_output>()
);
} else {
wl_request!(
display.client,
display.xdg_toplevel,
extensions::xdg_shell::xdg_toplevel::unset_fullscreen
);
},

// TODO: implement the other events
_ => (),
}
}

for event in EVENTS.drain(..) {
match event {
WaylandEvent::KeyboardKey(keycode, state) => {
Expand Down
2 changes: 1 addition & 1 deletion src/native/linux_wayland/extensions/xdg_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ wayland_interface!(
(set_min_size, "ii", ()),
(set_maximized, "", ()),
(unset_maximized, "", ()),
(set_fullscreen, "", (wl_output_interface)),
(set_fullscreen, "?o", (wl_output_interface)),
(unset_fullscreen, "", ()),
(set_minimized, "", ())
],
Expand Down

0 comments on commit 9e989de

Please sign in to comment.