Skip to content
Open
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
14 changes: 7 additions & 7 deletions src/ewmh/proto/application_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct GetWmNameReply {
impl From<xcb::x::GetPropertyReply> for GetWmNameReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetWmNameReply {
name: x_buffer_to_strings(reply.value::<u8>())[0].to_owned(),
name: x_buffer_string_or_default!(reply),
}
}
}
Expand All @@ -44,7 +44,7 @@ pub struct SetWmName {
impl SetWmName {
pub fn new(window: xcb::x::Window, name: &str) -> SetWmName {
SetWmName {
window: window,
window,
data: strings_to_x_buffer(vec![name]),
}
}
Expand All @@ -70,7 +70,7 @@ pub struct GetWmVisibleNameReply {
impl From<xcb::x::GetPropertyReply> for GetWmVisibleNameReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetWmVisibleNameReply {
name: x_buffer_to_strings(reply.value::<u8>())[0].to_owned(),
name: x_buffer_string_or_default!(reply),
}
}
}
Expand All @@ -95,7 +95,7 @@ pub struct GetWmIconNameReply {
impl From<xcb::x::GetPropertyReply> for GetWmIconNameReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetWmIconNameReply {
name: x_buffer_to_strings(reply.value::<u8>())[0].to_owned(),
name: x_buffer_string_or_default!(reply),
}
}
}
Expand All @@ -120,7 +120,7 @@ pub struct GetWmVisibleIconNameReply {
impl From<xcb::x::GetPropertyReply> for GetWmVisibleIconNameReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetWmVisibleIconNameReply {
name: x_buffer_to_strings(reply.value::<u8>())[0].to_owned(),
name: x_buffer_string_or_default!(reply),
}
}
}
Expand All @@ -145,7 +145,7 @@ pub struct GetWmDesktopReply {
impl From<xcb::x::GetPropertyReply> for GetWmDesktopReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetWmDesktopReply {
desktop: reply.value::<u32>()[0],
desktop: nth_u32_value_or_default!(reply, 0),
}
}
}
Expand All @@ -167,7 +167,7 @@ pub struct SetWmDesktop {
impl SetWmDesktop {
pub fn new(window: xcb::x::Window, desktop: u32) -> SetWmDesktop {
SetWmDesktop {
window: window,
window,
data: vec![desktop],
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/ewmh/proto/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,20 @@ mod set_property;

#[macro_use]
mod client_message;

macro_rules! x_buffer_string_or_default {
($reply:expr) => {{
x_buffer_to_strings($reply.value::<u8>())
.first()
.map_or_else(Default::default, ToOwned::to_owned)
}};
}

macro_rules! nth_u32_value_or_default {
($reply:expr, $index:expr) => {{
$reply
.value::<u32>()
.get($index)
.map_or_else(Default::default, ToOwned::to_owned)
}};
}
36 changes: 18 additions & 18 deletions src/ewmh/proto/root_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub struct GetNumberOfDesktopsReply {
impl From<xcb::x::GetPropertyReply> for GetNumberOfDesktopsReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetNumberOfDesktopsReply {
desktops: reply.value::<u32>()[0],
desktops: nth_u32_value_or_default!(reply, 0),
}
}
}
Expand Down Expand Up @@ -141,8 +141,8 @@ pub struct GetDesktopGeometryReply {
impl From<xcb::x::GetPropertyReply> for GetDesktopGeometryReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetDesktopGeometryReply {
width: reply.value::<u32>()[0],
height: reply.value::<u32>()[1],
width: nth_u32_value_or_default!(reply, 0),
height: nth_u32_value_or_default!(reply, 1),
}
}
}
Expand Down Expand Up @@ -188,8 +188,8 @@ pub struct GetDesktopViewportReply {
impl From<xcb::x::GetPropertyReply> for GetDesktopViewportReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetDesktopViewportReply {
x: reply.value::<u32>()[0],
y: reply.value::<u32>()[1],
x: nth_u32_value_or_default!(reply, 0),
y: nth_u32_value_or_default!(reply, 1),
}
}
}
Expand Down Expand Up @@ -234,7 +234,7 @@ pub struct GetCurrentDesktopReply {
impl From<xcb::x::GetPropertyReply> for GetCurrentDesktopReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetCurrentDesktopReply {
desktop: reply.value::<u32>()[0],
desktop: nth_u32_value_or_default!(reply, 0),
}
}
}
Expand Down Expand Up @@ -324,7 +324,7 @@ pub struct GetActiveWindowReply {
impl From<xcb::x::GetPropertyReply> for GetActiveWindowReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetActiveWindowReply {
window: unsafe { xcb::x::Window::new(reply.value::<u32>()[0]) },
window: unsafe { xcb::x::Window::new(nth_u32_value_or_default!(reply, 0)) },
}
}
}
Expand Down Expand Up @@ -384,10 +384,10 @@ pub struct GetWorkareaReply {
impl From<xcb::x::GetPropertyReply> for GetWorkareaReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetWorkareaReply {
x: reply.value::<u32>()[0],
y: reply.value::<u32>()[1],
width: reply.value::<u32>()[2],
height: reply.value::<u32>()[3],
x: nth_u32_value_or_default!(reply, 0),
y: nth_u32_value_or_default!(reply, 1),
width: nth_u32_value_or_default!(reply, 2),
height: nth_u32_value_or_default!(reply, 3),
}
}
}
Expand All @@ -412,7 +412,7 @@ pub struct GetSupportingWmCheckReply {
impl From<xcb::x::GetPropertyReply> for GetSupportingWmCheckReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetSupportingWmCheckReply {
window: unsafe { xcb::x::Window::new(reply.value::<u32>()[0]) },
window: unsafe { xcb::x::Window::new(nth_u32_value_or_default!(reply, 0)) },
}
}
}
Expand All @@ -437,7 +437,7 @@ pub struct GetVirtualRootsReply {
impl From<xcb::x::GetPropertyReply> for GetVirtualRootsReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetVirtualRootsReply {
window: unsafe { xcb::x::Window::new(reply.value::<u32>()[0]) },
window: unsafe { xcb::x::Window::new(nth_u32_value_or_default!(reply, 0)) },
}
}
}
Expand Down Expand Up @@ -465,10 +465,10 @@ pub struct DesktopLayoutReply {
impl From<xcb::x::GetPropertyReply> for DesktopLayoutReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
DesktopLayoutReply {
orientation: reply.value::<u32>()[0],
columns: reply.value::<u32>()[1],
rows: reply.value::<u32>()[2],
starting_corner: reply.value::<u32>()[3],
orientation: nth_u32_value_or_default!(reply, 0),
columns: nth_u32_value_or_default!(reply, 1),
rows: nth_u32_value_or_default!(reply, 2),
starting_corner: nth_u32_value_or_default!(reply, 3),
}
}
}
Expand All @@ -493,7 +493,7 @@ pub struct GetShowingDesktopReply {
impl From<xcb::x::GetPropertyReply> for GetShowingDesktopReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetShowingDesktopReply {
is_showing_desktop: { reply.value::<u32>()[0] == 1 },
is_showing_desktop: { nth_u32_value_or_default!(reply, 0) == 1 },
}
}
}
Expand Down
52 changes: 27 additions & 25 deletions src/icccm/proto/client_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#![allow(dead_code)]

use bitflags::bitflags;
use std::convert::TryInto;
use std::io::BufRead;
use std::mem;
use xcb::{Xid, XidNew};

Expand All @@ -27,7 +25,7 @@ impl From<xcb::x::GetPropertyReply> for GetWmNameReply {
let x = reply.value::<u8>().into();
GetWmNameReply {
// TODO Compound string
name: String::from_utf8(x).unwrap(),
name: String::from_utf8(x).unwrap_or_default(),
}
}
}
Expand All @@ -50,8 +48,8 @@ pub struct SetWmName<T: xcb::x::PropEl> {
impl<T: xcb::x::PropEl> SetWmName<T> {
pub fn new(window: xcb::x::Window, encoding: xcb::x::Atom, name: Vec<T>) -> SetWmName<T> {
SetWmName {
window: window,
encoding: encoding,
window,
encoding,
data: name,
}
}
Expand All @@ -76,7 +74,7 @@ impl From<xcb::x::GetPropertyReply> for GetWmIconNameReply {
let x = reply.value::<u8>().into();
GetWmIconNameReply {
// TODO Compound string
name: String::from_utf8(x).unwrap(),
name: String::from_utf8(x).unwrap_or_default(),
}
}
}
Expand All @@ -99,8 +97,8 @@ pub struct SetWmIconName<T: xcb::x::PropEl> {
impl<T: xcb::x::PropEl> SetWmIconName<T> {
pub fn new(window: xcb::x::Window, encoding: xcb::x::Atom, name: Vec<T>) -> SetWmIconName<T> {
SetWmIconName {
window: window,
encoding: encoding,
window,
encoding,
data: name,
}
}
Expand Down Expand Up @@ -148,7 +146,7 @@ impl SetWmColorMapWindows {
colormap_windows: Vec<xcb::x::Window>,
) -> SetWmColorMapWindows {
SetWmColorMapWindows {
window: window,
window,
data: colormap_windows,
}
}
Expand All @@ -174,7 +172,7 @@ impl From<xcb::x::GetPropertyReply> for GetWmClientMachineReply {
let x = reply.value::<u8>().into();
GetWmClientMachineReply {
// TODO Compound string
name: String::from_utf8(x).unwrap(),
name: String::from_utf8(x).unwrap_or_default(),
}
}
}
Expand All @@ -201,8 +199,8 @@ impl<T: xcb::x::PropEl> SetWmClientMachine<T> {
name: Vec<T>,
) -> SetWmClientMachine<T> {
SetWmClientMachine {
window: window,
encoding: encoding,
window,
encoding,
data: name,
}
}
Expand All @@ -225,7 +223,7 @@ pub struct GetWmClassReply {

impl From<xcb::x::GetPropertyReply> for GetWmClassReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
let values: Vec<&[u8]> = reply.value::<u8>().split(|v| *v == 0x00 as u8).collect();
let values: Vec<&[u8]> = reply.value::<u8>().split(|v| *v == 0x00_u8).collect();

GetWmClassReply {
instance: String::from_utf8_lossy(values[0]).to_string(),
Expand Down Expand Up @@ -253,14 +251,11 @@ impl SetWmClass {
pub fn new(window: xcb::x::Window, instance: &str, class: &str) -> SetWmClass {
let mut data = vec![];
data.append(&mut instance.as_bytes().to_vec());
data.push(0x00 as u8);
data.push(0x00_u8);
data.append(&mut class.as_bytes().to_vec());
data.push(0x00 as u8);
data.push(0x00_u8);

SetWmClass {
window: window,
data: data,
}
SetWmClass { window, data }
}
}

Expand All @@ -282,7 +277,14 @@ pub struct GetWmTransientForReply {
impl From<xcb::x::GetPropertyReply> for GetWmTransientForReply {
fn from(reply: xcb::x::GetPropertyReply) -> Self {
GetWmTransientForReply {
window: unsafe { xcb::x::Window::new(reply.value::<u32>()[0]) },
window: unsafe {
xcb::x::Window::new(
reply
.value::<u32>()
.first()
.map_or_else(Default::default, ToOwned::to_owned),
)
},
}
}
}
Expand All @@ -305,7 +307,7 @@ impl SetWmTransientFor {
// TODO better name for second window
pub fn new(window: xcb::x::Window, window2: xcb::x::Window) -> SetWmTransientFor {
SetWmTransientFor {
window: window,
window,
data: vec![window2],
}
}
Expand Down Expand Up @@ -527,7 +529,7 @@ pub struct SetWmNormalHints {
impl SetWmNormalHints {
pub fn new(window: xcb::x::Window, size_hints: &mut WmSizeHints) -> SetWmNormalHints {
SetWmNormalHints {
window: window,
window,
data: size_hints.as_data(),
}
}
Expand Down Expand Up @@ -629,9 +631,9 @@ impl WmHints {
};

WmHints {
flags: flags,
flags,
input: packed_vals[1] != 0,
initial_state: initial_state,
initial_state,
icon_pixmap: unsafe { xcb::x::Pixmap::new(packed_vals[3]) },
icon_window: unsafe { xcb::x::Window::new(packed_vals[4]) },
icon_x: packed_vals[5],
Expand Down Expand Up @@ -717,7 +719,7 @@ pub struct SetWmHints {
impl SetWmHints {
pub fn new(window: xcb::x::Window, hints: &mut WmHints) -> SetWmHints {
SetWmHints {
window: window,
window,
data: hints.as_data(),
}
}
Expand Down