Skip to content

Commit 3ca7e2f

Browse files
authored
Remove byteorder dependency (#172)
Signed-off-by: Uli Schlachter <psychon@znc.in>
1 parent 4e7466c commit 3ca7e2f

File tree

11 files changed

+25
-37
lines changed

11 files changed

+25
-37
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
#### Changes
6+
7+
- Dependency on `byteorder` was replaced with `u32::from_ne_bytes()`
8+
59
## 0.12.1 -- 2020-12-08
610

711
#### Changes

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ wayland-client = "0.28"
2323
wayland-protocols = { version = "0.28" , features = ["client", "unstable_protocols"] }
2424
wayland-cursor = "0.28"
2525
calloop = { version = "0.6.1", optional = true }
26-
byteorder = "1.0"
2726

2827
[features]
2928
default = ["frames", "calloop"]

examples/image_viewer.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
extern crate byteorder;
21
extern crate image;
32
extern crate smithay_client_toolkit as sctk;
43

54
use std::env;
65
use std::io::{BufWriter, Seek, SeekFrom, Write};
76

8-
use byteorder::{NativeEndian, WriteBytesExt};
9-
107
use sctk::reexports::client::protocol::{wl_shm, wl_surface};
118
use sctk::shm::MemPool;
129
use sctk::window::{ConceptFrame, Event as WEvent, State};
@@ -288,14 +285,15 @@ fn redraw(
288285
let g = ::std::cmp::min(0xFF, (0xFF * (0xFF - a) + a * g) / 0xFF);
289286
let b = ::std::cmp::min(0xFF, (0xFF * (0xFF - a) + a * b) / 0xFF);
290287
// write the pixel
291-
// We use byteorder, as the wayland protocol explicitly specifies
288+
// The wayland protocol explicitly specifies
292289
// that the pixels must be written in native endianness
293-
writer.write_u32::<NativeEndian>((0xFF << 24) + (r << 16) + (g << 8) + b)?;
290+
let pixel: u32 = (0xFF << 24) + (r << 16) + (g << 8) + b;
291+
writer.write_all(&pixel.to_ne_bytes())?;
294292
}
295293
} else {
296294
// We do not have any image to draw, so we draw black contents
297295
for _ in 0..(buf_x * buf_y) {
298-
writer.write_u32::<NativeEndian>(0xFF000000)?;
296+
writer.write_all(&0xFF000000u32.to_ne_bytes())?;
299297
}
300298
}
301299
// Don't forget to flush the writer, to make sure all the contents are

examples/kbd_input.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
extern crate byteorder;
21
extern crate smithay_client_toolkit as sctk;
32

43
use std::cmp::min;
54
use std::io::{BufWriter, Seek, SeekFrom, Write};
65

7-
use byteorder::{NativeEndian, WriteBytesExt};
8-
96
use sctk::reexports::calloop;
107
use sctk::reexports::client::protocol::{wl_keyboard, wl_shm, wl_surface};
118
use sctk::seat::keyboard::{map_keyboard_repeat, Event as KbEvent, RepeatKind};
@@ -223,7 +220,8 @@ fn redraw(
223220
let r: u32 = min(((buf_x - x) * 0xFF) / buf_x, ((buf_y - y) * 0xFF) / buf_y);
224221
let g: u32 = min((x * 0xFF) / buf_x, ((buf_y - y) * 0xFF) / buf_y);
225222
let b: u32 = min(((buf_x - x) * 0xFF) / buf_x, (y * 0xFF) / buf_y);
226-
writer.write_u32::<NativeEndian>((0xFF << 24) + (r << 16) + (g << 8) + b)?;
223+
let pixel: u32 = (0xFF << 24) + (r << 16) + (g << 8) + b;
224+
writer.write_all(&pixel.to_ne_bytes())?;
227225
}
228226
writer.flush()?;
229227
}

examples/layer_shell.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use smithay_client_toolkit::{
1515
WaylandSource,
1616
};
1717

18-
use byteorder::{NativeEndian, WriteBytesExt};
19-
2018
use std::cell::{Cell, RefCell};
2119
use std::io::{BufWriter, Seek, SeekFrom, Write};
2220
use std::rc::Rc;
@@ -121,7 +119,7 @@ impl Surface {
121119
{
122120
let mut writer = BufWriter::new(&mut *pool);
123121
for _ in 0..(width * height) {
124-
writer.write_u32::<NativeEndian>(0xff00ff00).unwrap();
122+
writer.write_all(&0xff00ff00u32.to_ne_bytes()).unwrap();
125123
}
126124
writer.flush().unwrap();
127125
}

examples/pointer_input.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
extern crate byteorder;
21
extern crate smithay_client_toolkit as sctk;
32

43
use std::cmp::min;
54
use std::io::{BufWriter, Seek, SeekFrom, Write};
65

7-
use byteorder::{NativeEndian, WriteBytesExt};
8-
96
use sctk::reexports::client::protocol::{wl_pointer, wl_shm, wl_surface};
107
use sctk::shm::MemPool;
118
use sctk::window::{ConceptFrame, Event as WEvent};
@@ -211,7 +208,8 @@ fn redraw(
211208
let r: u32 = min(((buf_x - x) * 0xFF) / buf_x, ((buf_y - y) * 0xFF) / buf_y);
212209
let g: u32 = min((x * 0xFF) / buf_x, ((buf_y - y) * 0xFF) / buf_y);
213210
let b: u32 = min(((buf_x - x) * 0xFF) / buf_x, (y * 0xFF) / buf_y);
214-
writer.write_u32::<NativeEndian>((0xFF << 24) + (r << 16) + (g << 8) + b)?;
211+
let pixel = (0xFF << 24) + (r << 16) + (g << 8) + b;
212+
writer.write_all(&pixel.to_ne_bytes())?;
215213
}
216214
writer.flush()?;
217215
}

examples/selection.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
extern crate byteorder;
21
extern crate smithay_client_toolkit as sctk;
32

43
use std::io::{BufWriter, Read, Seek, SeekFrom, Write};
54

6-
use byteorder::{NativeEndian, WriteBytesExt};
7-
85
use sctk::{
96
data_device::{DataSourceEvent, ReadPipe},
107
environment::Environment,
@@ -344,7 +341,7 @@ fn redraw(
344341
{
345342
let mut writer = BufWriter::new(&mut *pool);
346343
for _ in 0..(buf_x * buf_y) {
347-
writer.write_u32::<NativeEndian>(0xFF000000)?;
344+
writer.write(&0xFF000000u32.to_ne_bytes())?;
348345
}
349346
writer.flush()?;
350347
}

examples/themed_frame.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
extern crate byteorder;
21
extern crate smithay_client_toolkit as sctk;
32

43
use std::cmp::min;
54
use std::io::{BufWriter, Seek, SeekFrom, Write};
65

7-
use byteorder::{NativeEndian, WriteBytesExt};
8-
96
use sctk::reexports::client::protocol::{wl_shm, wl_surface};
107
use sctk::shm::MemPool;
118
use sctk::window::{ButtonColorSpec, ColorSpec, ConceptConfig, ConceptFrame, Event as WEvent};
@@ -169,7 +166,8 @@ fn redraw(
169166
let r: u32 = min(((buf_x - x) * 0xFF) / buf_x, ((buf_y - y) * 0xFF) / buf_y);
170167
let g: u32 = min((x * 0xFF) / buf_x, ((buf_y - y) * 0xFF) / buf_y);
171168
let b: u32 = min(((buf_x - x) * 0xFF) / buf_x, (y * 0xFF) / buf_y);
172-
writer.write_u32::<NativeEndian>((0xFF << 24) + (r << 16) + (g << 8) + b)?;
169+
let pixel: u32 = (0xFF << 24) + (r << 16) + (g << 8) + b;
170+
writer.write_all(&pixel.to_ne_bytes())?;
173171
}
174172
writer.flush()?;
175173
}

src/seat/keyboard/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ use std::num::NonZeroU32;
1818
use std::time::Duration;
1919
use std::{
2020
cell::RefCell,
21+
convert::TryInto,
2122
fs::File,
2223
os::unix::io::{FromRawFd, RawFd},
2324
rc::Rc,
2425
};
2526

26-
use byteorder::{ByteOrder, NativeEndian};
27-
2827
pub use wayland_client::protocol::wl_keyboard::KeyState;
2928
use wayland_client::{
3029
protocol::{wl_keyboard, wl_seat, wl_surface},
@@ -393,7 +392,10 @@ impl KbdHandler {
393392
dispatch_data: wayland_client::DispatchData,
394393
) {
395394
let mut state = self.state.borrow_mut();
396-
let rawkeys = keys.chunks_exact(4).map(NativeEndian::read_u32).collect::<Vec<_>>();
395+
let rawkeys = keys
396+
.chunks_exact(4)
397+
.map(|c| u32::from_ne_bytes(c.try_into().unwrap()))
398+
.collect::<Vec<_>>();
397399
let keys: Vec<u32> = rawkeys.iter().map(|k| state.get_one_sym_raw(*k)).collect();
398400
(&mut *self.callback.borrow_mut())(
399401
Event::Enter { serial, surface, rawkeys: &rawkeys, keysyms: &keys },

src/shell/xdg.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use std::{cell::RefCell, rc::Rc};
2-
3-
use byteorder::{ByteOrder, NativeEndian};
1+
use std::{cell::RefCell, convert::TryInto, rc::Rc};
42

53
use wayland_client::{
64
protocol::{wl_output, wl_seat, wl_surface},
@@ -59,7 +57,7 @@ impl Xdg {
5957
};
6058
let translated_states = states
6159
.chunks_exact(4)
62-
.map(NativeEndian::read_u32)
60+
.map(|c| u32::from_ne_bytes(c.try_into().unwrap()))
6361
.flat_map(xdg_toplevel::State::from_raw)
6462
.collect::<Vec<_>>();
6563

0 commit comments

Comments
 (0)