Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes to get miniquad programs run on KDE Wayland #409

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 71 additions & 2 deletions 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 @@ -397,7 +397,8 @@ unsafe extern "C" fn registry_add_object(
1,
) as _;
}
"zxdg_decoration_manager" => {
"zxdg_decoration_manager" |
"zxdg_decoration_manager_v1" => {
hch12907 marked this conversation as resolved.
Show resolved Hide resolved
display.decoration_manager = display.client.wl_registry_bind(
registry,
name,
Expand Down Expand Up @@ -510,6 +511,22 @@ unsafe extern "C" fn xdg_toplevel_handle_configure(
}
}

unsafe extern "C" fn xdg_wm_base_handle_ping(
data: *mut std::ffi::c_void,
toplevel: *mut extensions::xdg_shell::xdg_wm_base,
serial: u32,
) -> () {
assert!(!data.is_null());
let payload: &mut WaylandPayload = &mut *(data as *mut _);

wl_request!(
payload.client,
toplevel,
extensions::xdg_shell::xdg_wm_base::pong,
serial
);
}

struct WaylandClipboard;
impl crate::native::Clipboard for WaylandClipboard {
fn get(&mut self) -> Option<String> {
Expand Down Expand Up @@ -593,6 +610,16 @@ where
//assert!(display.keymap.is_null() == false);
//assert!(display.xkb_state.is_null() == false);

let xdg_wm_base_listener = extensions::xdg_shell::xdg_wm_base_listener {
ping: Some(xdg_wm_base_handle_ping),
};

(display.client.wl_proxy_add_listener)(
display.xdg_wm_base as _,
&xdg_wm_base_listener as *const _ as _,
&mut display as *mut _ as _,
);

if display.decoration_manager.is_null() && conf.platform.wayland_use_fallback_decorations {
eprintln!("Decoration manager not found, will draw fallback decorations");
}
Expand Down Expand Up @@ -651,6 +678,15 @@ where
&mut display as *mut _ as _,
);

let title = std::ffi::CString::new(conf.window_title.as_str()).unwrap();

wl_request!(
display.client,
display.xdg_toplevel,
extensions::xdg_shell::xdg_toplevel::set_title,
title.as_ptr()
);

wl_request!(display.client, display.surface, WL_SURFACE_COMMIT);
(display.client.wl_display_roundtrip)(wdisplay);

Expand All @@ -674,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 @@ -723,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
Loading