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

General fixes with Clippy lints #315

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Context {
unsafe { &*self.display.unwrap() }
}

pub fn display_mut(&self) -> &mut dyn NativeDisplay {
pub fn display_mut(&mut self) -> &mut dyn NativeDisplay {
unsafe { &mut *self.display.unwrap() }
}

Expand Down
58 changes: 30 additions & 28 deletions src/native/linux_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,34 +273,36 @@ unsafe extern "C" fn xdg_toplevel_handle_configure(
width: i32,
height: i32,
_states: *mut wl_array,
) -> () {
) {
assert!(!data.is_null());
let payload: &mut WaylandPayload = &mut *(data as *mut _);
let display = &mut payload.display;

if width != 0 && height != 0 {
let (egl_w, egl_h) = if display.decorations.is_some() {
// Otherwise window will resize iteself on sway
// I have no idea why
(
width - decorations::Decorations::WIDTH * 2,
height - decorations::Decorations::BAR_HEIGHT - decorations::Decorations::WIDTH,
)
} else {
(width, height)
};
(display.egl.wl_egl_window_resize)(display.egl_window, egl_w, egl_h, 0, 0);

display.data.screen_width = width;
display.data.screen_height = height;

if let Some(ref decorations) = display.decorations {
decorations.resize(&mut display.client, width, height);
let payload: &mut WaylandPayload = &mut *(data as *mut _);

{
let display = &mut payload.display;

let (egl_w, egl_h) = if display.decorations.is_some() {
// Otherwise window will resize iteself on sway
// I have no idea why
(
width - decorations::Decorations::WIDTH * 2,
height - decorations::Decorations::BAR_HEIGHT - decorations::Decorations::WIDTH,
)
} else {
(width, height)
};
(display.egl.wl_egl_window_resize)(display.egl_window, egl_w, egl_h, 0, 0);

display.data.screen_width = width;
display.data.screen_height = height;

if let Some(ref decorations) = display.decorations {
decorations.resize(&mut display.client, width, height);
}
}

drop(display);
if let (mut context, Some(event_handler)) = payload.context() {
event_handler.resize_event(&mut context, width as _, height as _);
if let (context, Some(event_handler)) = payload.context() {
event_handler.resize_event(context, width as _, height as _);
}
}
}
Expand Down Expand Up @@ -489,15 +491,15 @@ where
payload.display.data.screen_width = conf.window_width;
payload.display.data.screen_height = conf.window_height;

let event_handler = (f.take().unwrap())(&mut payload.context().0);
let event_handler = (f.take().unwrap())(payload.context().0);
payload.event_handler = Some(event_handler);

while payload.display.closed == false {
(payload.display.client.wl_display_dispatch_pending)(wdisplay);

let (mut context, event_handler) = payload.context();
event_handler.as_mut().unwrap().update(&mut context);
event_handler.as_mut().unwrap().draw(&mut context);
let (context, event_handler) = payload.context();
event_handler.as_mut().unwrap().update(context);
event_handler.as_mut().unwrap().draw(context);

(libegl.eglSwapBuffers.unwrap())(egl_display, egl_surface);
}
Expand Down
8 changes: 4 additions & 4 deletions src/native/linux_x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl X11Display {
if !db.is_null() {
let mut value = XrmValue {
size: 0,
addr: 0 as *mut libc::c_char,
addr: std::ptr::null_mut::<libc::c_char>(),
};
let mut type_ = std::ptr::null_mut();
if (self.libx11.XrmGetResource)(
Expand All @@ -177,10 +177,10 @@ impl X11Display {
&mut type_,
&mut value,
) != 0
&& !type_.is_null()
&& libc::strcmp(type_, b"String\x00".as_ptr() as _) == 0
{
if !type_.is_null() && libc::strcmp(type_, b"String\x00".as_ptr() as _) == 0 {
self.dpi_scale = libc::atof(value.addr as *const _) as f32 / 96.0;
}
self.dpi_scale = libc::atof(value.addr as *const _) as f32 / 96.0;
}
(self.libx11.XrmDestroyDatabase)(db);
}
Expand Down