aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@gmail.com>2020-06-22 20:33:24 -0300
committerMatias Linares <matiaslina@gmail.com>2020-06-22 20:33:24 -0300
commit71e220b5f94c8af1ddfbc8e57182d9a51c1f6136 (patch)
tree2de62131f562224f4377a81961fc3c27bd28070e
parent0763564eedc459a98e63a65f7ffee8ad37100fe7 (diff)
downloaddotwm-71e220b5f94c8af1ddfbc8e57182d9a51c1f6136.tar.gz
Use MaybeUninit::uninit() in favor of mem::uninitialized()HEADmaster
-rw-r--r--src/dotwm.rs10
-rw-r--r--src/event.rs4
-rw-r--r--src/main.rs4
-rw-r--r--src/safe_x11/mod.rs8
-rw-r--r--src/safe_x11/window.rs14
5 files changed, 20 insertions, 20 deletions
diff --git a/src/dotwm.rs b/src/dotwm.rs
index 248e969..88951b8 100644
--- a/src/dotwm.rs
+++ b/src/dotwm.rs
@@ -20,7 +20,7 @@ use desktop::Desktop;
use std::ptr;
use std::process::exit;
-use std::mem::uninitialized;
+use std::mem::MaybeUninit;
use std::collections::HashMap;
use libc::c_int;
use libc::c_char;
@@ -86,7 +86,7 @@ impl DotWM {
let root = unsafe { xlib::XDefaultRootWindow(d) };
unsafe {
- let mut attrs: xlib::XSetWindowAttributes = uninitialized();
+ let mut attrs: xlib::XSetWindowAttributes = MaybeUninit::uninit().assume_init();
attrs.event_mask = xlib::SubstructureNotifyMask;
xlib::XChangeWindowAttributes(d, root, xlib::CWEventMask, &mut attrs);
}
@@ -134,7 +134,7 @@ impl DotWM {
pub fn current_desktop(&self) -> &Desktop {
self.desktops.get(self.desktop_idx).unwrap()
}
-
+
/// Add a window to the current desktop
pub fn add_window(&mut self, w: xlib::Window) {
self.current_desktop_mut().add_window(w);
@@ -212,14 +212,14 @@ impl DotWM {
let old_desktop = &self.desktops[self.desktop_idx];
new_desktop.show_windows();
- // let mut do_not_propagate: xlib::XSetWindowAttributes = unsafe { uninitialized() };
+ // let mut do_not_propagate: xlib::XSetWindowAttributes = unsafe { MaybeUninit::uninit().assume_init() };
// let root = root_window(self.display);
// do_not_propagate.do_not_propagate_mask = xlib::SubstructureNotifyMask;
// change_window_attributes(self.display, root, xlib::CWEventMask,
// &mut do_not_propagate);
old_desktop.hide_windows();
- // let mut root_mask: xlib::XSetWindowAttributes = unsafe { uninitialized() };
+ // let mut root_mask: xlib::XSetWindowAttributes = unsafe { MaybeUninit::uninit().assume_init() };
// root_mask.event_mask = xlib::SubstructureRedirectMask|xlib::ButtonPressMask|xlib::SubstructureNotifyMask|xlib::PropertyChangeMask;
// change_window_attributes(self.display, root, xlib::CWEventMask,
// &mut root_mask);
diff --git a/src/event.rs b/src/event.rs
index 9e96146..761e22b 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -29,7 +29,7 @@ use libc::{
};
use std::fmt;
use std::ptr;
-use std::mem::uninitialized;
+use std::mem::MaybeUninit;
use std::cmp::max;
use std::os::unix::io::AsRawFd;
@@ -82,7 +82,7 @@ pub unsafe fn select_event(display: *mut Display, x11fd: c_int, listener: &UnixL
}
let socket_fd = listener.as_raw_fd();
- let mut read_fdset: fd_set = uninitialized();
+ let mut read_fdset: fd_set = MaybeUninit::uninit().assume_init();
FD_ZERO(&mut read_fdset);
FD_SET(x11fd, &mut read_fdset);
diff --git a/src/main.rs b/src/main.rs
index fab737a..1f56bf2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -18,7 +18,7 @@ pub mod socket;
pub mod desktop;
use std::collections::HashMap;
-use std::mem::uninitialized;
+use std::mem::MaybeUninit;
use std::fs;
use std::path::{PathBuf};
use std::io::{Read,Write};
@@ -106,7 +106,7 @@ fn main() {
Event::Drag(e) => {
// We can "compress" the drag notify here.
unsafe{
- let mut new_ev = uninitialized();
+ let mut new_ev = MaybeUninit::uninit().assume_init();
while xlib::XCheckTypedEvent(dotwm.display, xlib::MotionNotify, &mut new_ev) != 0 {};
};
exec_func(&mut dotwm, &mut bindings, 1, e.state, xlib::XEvent::from(e));
diff --git a/src/safe_x11/mod.rs b/src/safe_x11/mod.rs
index a65c132..7dcdce1 100644
--- a/src/safe_x11/mod.rs
+++ b/src/safe_x11/mod.rs
@@ -29,7 +29,7 @@ use std::ffi::CString;
use std::ffi::NulError;
use std::ptr;
use std::error;
-use std::mem::uninitialized;
+use std::mem::MaybeUninit;
use std::slice;
use std::fmt;
use libc::c_int;
@@ -81,7 +81,7 @@ pub fn x11_fd(display: *mut Display) -> c_int {
/// on the main thread.
pub fn next_xevent(display: *mut Display) -> XEvent {
unsafe {
- let mut last_event: XEvent = uninitialized();
+ let mut last_event: XEvent = MaybeUninit::uninit().assume_init();
XNextEvent(display, &mut last_event);
last_event
}
@@ -171,7 +171,7 @@ pub fn window_list(display: *mut Display) -> &'static [Window] {
let mut children_count: u32 = 0;
unsafe {
let root_window = XDefaultRootWindow(display);
- let mut children: *mut Window = uninitialized();
+ let mut children: *mut Window = MaybeUninit::uninit().assume_init();
XQueryTree(display, root_window,
&mut root, &mut parent,
&mut children, &mut children_count);
@@ -201,7 +201,7 @@ fn get_color<T: Into<Vec<u8>>>(display: *mut Display, color: T) -> u64{
let screen_num = unsafe { xlib::XDefaultScreen(display) };
let colormap = unsafe { xlib::XDefaultColormap(display, screen_num) };
unsafe {
- let mut xcolor: xlib::XColor = uninitialized();
+ let mut xcolor: xlib::XColor = MaybeUninit::uninit().assume_init();
let cstr = CString::new(color).unwrap();
xlib::XAllocNamedColor(display, colormap, cstr.as_ptr(),
&mut xcolor, &mut xcolor);
diff --git a/src/safe_x11/window.rs b/src/safe_x11/window.rs
index 6c483d9..78b3bcf 100644
--- a/src/safe_x11/window.rs
+++ b/src/safe_x11/window.rs
@@ -28,7 +28,7 @@ use x11::xlib::{
};
use std::ptr;
-use std::mem::uninitialized;
+use std::mem::MaybeUninit;
use std::mem::transmute;
use std::cmp::{max};
use std::ffi::CString;
@@ -54,7 +54,7 @@ fn fixed_with_ratio(x: i32, ratio: f32) -> i32 {
fn window_attribs(display: *mut xlib::Display, w: Window) -> XWindowAttributes {
unsafe {
- let mut attrptr: XWindowAttributes = uninitialized();
+ let mut attrptr: XWindowAttributes = MaybeUninit::uninit().assume_init();
XGetWindowAttributes(display, w, &mut attrptr);
attrptr
}
@@ -65,7 +65,7 @@ impl XWindow {
/// `None` if the window is the root window.
pub fn new(d: *mut xlib::Display, w: Window) -> Option<XWindow> {
if w != 0 {
- let attrs: XWindowAttributes = unsafe { uninitialized() };
+ let attrs: XWindowAttributes = unsafe { MaybeUninit::uninit().assume_init() };
Some(XWindow {
display: d,
inner: w,
@@ -88,7 +88,7 @@ impl XWindow {
/// also perform any confirmation dialog with the user.
pub fn delete(&self) {
// First delete the border window and then the main window.
- let mut ev: XClientMessageEvent = unsafe { uninitialized() };
+ let mut ev: XClientMessageEvent = unsafe { MaybeUninit::uninit().assume_init() };
ev.type_ = ClientMessage;
ev.window = self.inner;
ev.format = 32;
@@ -143,7 +143,7 @@ impl XWindow {
/// Moves the window given an offset from where it is.
pub fn move_offset(&self, xoffset: i32, yoffset: i32) {
unsafe {
- let mut attributes: XWindowAttributes = uninitialized();
+ let mut attributes: XWindowAttributes = MaybeUninit::uninit().assume_init();
XGetWindowAttributes(self.display, self.inner, &mut attributes);
XMoveWindow(self.display, self.inner,
attributes.x + xoffset,
@@ -158,7 +158,7 @@ impl XWindow {
ptr::read(s)
};
let attrs = self.attributes();
-
+
if x < -attrs.width && x <= screen.width || -attrs.height > y && y <= screen.height {
Err("Cannot move the window outside the screen!")
} else {
@@ -222,7 +222,7 @@ impl XWindow {
XMoveResizeWindow(self.display, self.inner, x, y, w, h as u32);
}
}
-
+
/// Resizes the window a fixed amount within the height and width.
pub fn resize(&self, w: i32, h: i32) {
let ratio = screen_ratio(self.display);