diff --git a/Cargo.lock b/Cargo.lock index a7f1909c..5924e490 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 4 [[package]] name = "anstream" -version = "0.6.18" +version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" dependencies = [ "anstyle", "anstyle-parse", @@ -19,44 +19,44 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.10" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" [[package]] name = "anstyle-parse" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.2" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "3.0.7" +version = "3.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", - "once_cell", + "once_cell_polyfill", "windows-sys", ] [[package]] name = "clap" -version = "4.5.37" +version = "4.5.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071" +checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" dependencies = [ "clap_builder", "clap_derive", @@ -64,9 +64,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.37" +version = "4.5.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2" +checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" dependencies = [ "anstream", "anstyle", @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.32" +version = "4.5.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" +checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" dependencies = [ "heck", "proc-macro2", @@ -88,15 +88,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "colorchoice" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" [[package]] name = "equivalent" @@ -106,9 +106,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "hashbrown" -version = "0.15.3" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" [[package]] name = "heck" @@ -118,9 +118,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "indexmap" -version = "2.9.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" dependencies = [ "equivalent", "hashbrown", @@ -128,9 +128,9 @@ dependencies = [ [[package]] name = "is_terminal_polyfill" -version = "1.70.1" +version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] name = "itoa" @@ -140,9 +140,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "libc" -version = "0.2.172" +version = "0.2.178" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" [[package]] name = "libmars" @@ -184,10 +184,10 @@ dependencies = [ ] [[package]] -name = "once_cell" -version = "1.21.3" +name = "once_cell_polyfill" +version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "pkg-config" @@ -197,18 +197,18 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.40" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" dependencies = [ "proc-macro2", ] @@ -221,18 +221,28 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -260,9 +270,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.101" +version = "2.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" dependencies = [ "proc-macro2", "quote", @@ -271,9 +281,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "unsafe-libyaml-norway" @@ -288,78 +298,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] -name = "windows-sys" -version = "0.59.0" +name = "windows-link" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] -name = "windows-targets" -version = "0.52.6" +name = "windows-sys" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-link", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - [[package]] name = "x11" version = "2.21.0" diff --git a/Cargo.toml b/Cargo.toml index 6ddfa15f..d4a0872d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,10 @@ license-file = "LICENSE" readme = "README.md" [workspace.dependencies] -clap = { version = "4.5.23", features = ["derive"] } +clap = { version = "4.5.53", features = ["derive"] } libmars = { path = "./libmars", version = "0.6.1" } -serde = { version = "1.0.216", features = ["derive"] } -serde_norway = { version = "0.9.41" } +serde = { version = "1.0.228", features = ["derive"] } +serde_norway = { version = "0.9.42" } x11 = { version = "2.21.0", features = ["xlib"] } diff --git a/libmars/src/interfaces/wm.rs b/libmars/src/interfaces/wm.rs index 142eef71..3224db4f 100644 --- a/libmars/src/interfaces/wm.rs +++ b/libmars/src/interfaces/wm.rs @@ -116,7 +116,7 @@ pub trait Backend { fn pointer_pos(&self) -> (i32, i32); /// Run window manager event loop - fn run(self, wm: &mut (dyn WindowManager)); + fn run(self, wm: &mut dyn WindowManager); /// Set client that receives mouse and keyboard inputs fn set_input_focus(&self, client_rc: Rc>); diff --git a/libmars/src/platforms/x11/misc/window.rs b/libmars/src/platforms/x11/misc/window.rs index c1b75285..7da10b91 100644 --- a/libmars/src/platforms/x11/misc/window.rs +++ b/libmars/src/platforms/x11/misc/window.rs @@ -10,34 +10,74 @@ use x11::xlib; use crate::common::error::*; use crate::platforms::x11::misc::*; - pub trait X11Window { fn x11_attributes(&self, display: *mut xlib::Display) -> Result; fn x11_class_hint(&self, display: *mut xlib::Display) -> Result<(String, String)>; - fn x11_close(&self, display: *mut xlib::Display, - error_handler: Option c_int>); + fn x11_close( + &self, + display: *mut xlib::Display, + error_handler: Option< + unsafe extern "C" fn(_: *mut xlib::Display, _: *mut xlib::XErrorEvent) -> c_int, + >, + ); fn x11_destroy(&self, display: *mut xlib::Display); fn x11_get_state(&self, display: *mut xlib::Display) -> Result; - fn x11_get_text_list_property(&self, display: *mut xlib::Display, property: X11Atom) -> Result>; + fn x11_get_text_list_property( + &self, + display: *mut xlib::Display, + property: X11Atom, + ) -> Result>; fn x11_net_wm_state(&self, display: *mut xlib::Display) -> Result>; fn x11_net_wm_state_add(&self, display: *mut xlib::Display, state: X11Atom); fn x11_net_wm_state_remove(&self, display: *mut xlib::Display, state: X11Atom); - fn x11_read_property_long(&self, display: *mut xlib::Display, property: X11Atom, prop_type: c_ulong) -> Result>; - fn x11_read_property_string(&self, display: *mut xlib::Display, property: X11Atom) -> Result; - fn x11_replace_property_long(&self, display: *mut xlib::Display, property: X11Atom, prop_type: c_ulong, data: &[c_ulong]); + fn x11_read_property_long( + &self, + display: *mut xlib::Display, + property: X11Atom, + prop_type: c_ulong, + ) -> Result>; + fn x11_read_property_string( + &self, + display: *mut xlib::Display, + property: X11Atom, + ) -> Result; + fn x11_replace_property_long( + &self, + display: *mut xlib::Display, + property: X11Atom, + prop_type: c_ulong, + data: &[c_ulong], + ); fn x11_set_state(&self, display: *mut xlib::Display, state: i32); - fn x11_set_text_list_property(&self, display: *mut xlib::Display, property: X11Atom, list: &[String]); + fn x11_set_text_list_property( + &self, + display: *mut xlib::Display, + property: X11Atom, + list: &[String], + ); fn x11_supports_protocol(&self, display: *mut xlib::Display, protocol: X11Atom) -> bool; fn x11_dimensions(&self, display: *mut xlib::Display) -> Result; - fn x11_geometry(&self, display: *mut xlib::Display) -> Result<(u64, i32, i32, u32, u32, u32, u32)>; + fn x11_geometry( + &self, + display: *mut xlib::Display, + ) -> Result<(u64, i32, i32, u32, u32, u32, u32)>; fn x11_get_window_types(&self, display: *mut xlib::Display) -> Vec; fn x11_is_transient_for(&self, display: *mut xlib::Display) -> Option; fn x11_map(&self, display: *mut xlib::Display); - fn x11_message(&self, display: *mut xlib::Display, msg_type: atoms::X11Atom, msg_format: c_int, msg_data: xlib::ClientMessageData); + fn x11_message( + &self, + display: *mut xlib::Display, + msg_type: atoms::X11Atom, + msg_format: c_int, + msg_data: xlib::ClientMessageData, + ); fn x11_unmap(&self, display: *mut xlib::Display); fn x11_wm_protocols(&self, display: *mut xlib::Display) -> Vec; fn x11_wm_name(&self, display: *mut xlib::Display) -> Result; - fn x11_wm_normal_hints(&self, display: *mut xlib::Display) -> Result<(xlib::XSizeHints, c_long)>; + fn x11_wm_normal_hints( + &self, + display: *mut xlib::Display, + ) -> Result<(xlib::XSizeHints, c_long)>; } impl X11Window for xlib::Window { @@ -47,7 +87,9 @@ impl X11Window for xlib::Window { if xlib::XGetWindowAttributes(display, *self, attributes.as_mut_ptr()) != 0 { Ok(attributes.assume_init()) } else { - Err(MarsError::failed_request(stringify!(xlib::XGetWindowAttributes))) + Err(MarsError::failed_request(stringify!( + xlib::XGetWindowAttributes + ))) } } } @@ -60,9 +102,13 @@ impl X11Window for xlib::Window { let class_hints = class_hints.assume_init(); if !class_hints.res_name.is_null() && !class_hints.res_class.is_null() { let res_name = CStr::from_ptr(class_hints.res_name) - .to_str().unwrap().to_owned(); + .to_str() + .unwrap() + .to_owned(); let res_class = CStr::from_ptr(class_hints.res_class) - .to_str().unwrap().to_owned(); + .to_str() + .unwrap() + .to_owned(); let ret_val = Ok((res_name, res_class)); xlib::XFree(class_hints.res_name as *mut c_void); xlib::XFree(class_hints.res_class as *mut c_void); @@ -76,8 +122,13 @@ impl X11Window for xlib::Window { } } - fn x11_close(&self, display: *mut xlib::Display, - error_handler: Option c_int>) { + fn x11_close( + &self, + display: *mut xlib::Display, + error_handler: Option< + unsafe extern "C" fn(_: *mut xlib::Display, _: *mut xlib::XErrorEvent) -> c_int, + >, + ) { if self.x11_supports_protocol(display, X11Atom::WMDeleteWindow) { let msg_type = X11Atom::WMProtocols; let mut msg_data = xlib::ClientMessageData::new(); @@ -103,20 +154,41 @@ impl X11Window for xlib::Window { } fn x11_get_state(&self, display: *mut xlib::Display) -> Result { - let result = self.x11_read_property_long(display, WMState, WMState.to_xlib_atom(display))?; + let result = + self.x11_read_property_long(display, WMState, WMState.to_xlib_atom(display))?; Ok(result[0]) } - fn x11_get_text_list_property(&self, display: *mut xlib::Display, property: X11Atom) -> Result> { + fn x11_get_text_list_property( + &self, + display: *mut xlib::Display, + property: X11Atom, + ) -> Result> { let mut text: MaybeUninit = MaybeUninit::uninit(); let mut nitems = 0; let mut data_ptr: *mut *mut c_char = ptr::null_mut(); let mut data = Vec::new(); unsafe { - if xlib::XGetTextProperty(display, *self, text.as_mut_ptr(), property.to_xlib_atom(display)) == 0 { + if xlib::XGetTextProperty( + display, + *self, + text.as_mut_ptr(), + property.to_xlib_atom(display), + ) == 0 + { Err(MarsError::property_unavailable(property)) - } else if xlib::Xutf8TextPropertyToTextList(display, text.as_ptr(), &mut data_ptr, &mut nitems) != 0 { - return Err(MarsError::failed_conversion(text.as_ptr(), stringify!(*mut *mut i8), stringify!(xlib::TextProperty))); + } else if xlib::Xutf8TextPropertyToTextList( + display, + text.as_ptr(), + &mut data_ptr, + &mut nitems, + ) != 0 + { + Err(MarsError::failed_conversion( + text.as_ptr(), + stringify!(*mut *mut i8), + stringify!(xlib::TextProperty), + )) } else if data_ptr.is_null() { Err(MarsError::property_unavailable(property)) } else { @@ -126,20 +198,27 @@ impl X11Window for xlib::Window { Ok(s) => s, Err(_) => { xlib::XFreeStringList(data_ptr); - return Err(MarsError::failed_conversion(cstr, stringify!(CStr), stringify!(String))); - }, + return Err(MarsError::failed_conversion( + cstr, + stringify!(CStr), + stringify!(String), + )); + } }; data.push(s.to_owned()); } xlib::XFreeStringList(data_ptr); - return Ok(data); + Ok(data) } } } fn x11_net_wm_state(&self, display: *mut xlib::Display) -> Result> { - let atoms = self.x11_read_property_long(display, NetWMState, xlib::XA_ATOM)? - .iter().filter_map(|a| X11Atom::from_xlib_atom(display, *a)).collect(); + let atoms = self + .x11_read_property_long(display, NetWMState, xlib::XA_ATOM)? + .iter() + .filter_map(|a| X11Atom::from_xlib_atom(display, *a)) + .collect(); Ok(atoms) } @@ -166,7 +245,12 @@ impl X11Window for xlib::Window { self.x11_replace_property_long(display, NetWMState, xlib::XA_ATOM, &states); } - fn x11_read_property_long(&self, display: *mut xlib::Display, property: X11Atom, prop_type: c_ulong) -> Result> { + fn x11_read_property_long( + &self, + display: *mut xlib::Display, + property: X11Atom, + prop_type: c_ulong, + ) -> Result> { let mut actual_type = 0; let mut actual_format = 0; let mut nitems = 0; @@ -177,22 +261,35 @@ impl X11Window for xlib::Window { unsafe { let mut data_ptr: *mut u8 = ptr::null_mut(); first_run = false; - let status = xlib::XGetWindowProperty(display, *self, property.to_xlib_atom(display), - data.len() as i64 / 2, 8, xlib::False, - prop_type, &mut actual_type, + let status = xlib::XGetWindowProperty( + display, + *self, + property.to_xlib_atom(display), + data.len() as i64 / 2, + 8, + xlib::False, + prop_type, + &mut actual_type, &mut actual_format, - &mut nitems, &mut remaining_bytes, - &mut data_ptr); + &mut nitems, + &mut remaining_bytes, + &mut data_ptr, + ); if status != 0 { - return Err(MarsError::failed_request(stringify!(xlib::XGetWindowProperty))); - } else if actual_type == XLIB_NONE - && actual_format == 0 - && remaining_bytes == 0 { + return Err(MarsError::failed_request(stringify!( + xlib::XGetWindowProperty + ))); + } else if actual_type == XLIB_NONE && actual_format == 0 && remaining_bytes == 0 { return Err(MarsError::property_unavailable(property)); } else if actual_type != prop_type || actual_format != 32 { - return Err(MarsError::invalid_response(stringify!(xlib::XGetWindowProperty))); + return Err(MarsError::invalid_response(stringify!( + xlib::XGetWindowProperty + ))); } else { - data.extend_from_slice(slice::from_raw_parts(data_ptr as *mut u64, nitems.try_into().unwrap())); + data.extend_from_slice(slice::from_raw_parts( + data_ptr as *mut u64, + nitems.try_into().unwrap(), + )); xlib::XFree(data_ptr as *mut c_void); } } @@ -200,7 +297,11 @@ impl X11Window for xlib::Window { Ok(data) } - fn x11_read_property_string(&self, display: *mut xlib::Display, property: X11Atom) -> Result { + fn x11_read_property_string( + &self, + display: *mut xlib::Display, + property: X11Atom, + ) -> Result { let v = self.x11_get_text_list_property(display, property)?; match v.first() { Some(string) => Ok(string.to_owned()), @@ -208,16 +309,24 @@ impl X11Window for xlib::Window { } } - fn x11_replace_property_long(&self, display: *mut xlib::Display, property: X11Atom, prop_type: c_ulong, data: &[c_ulong]) { + fn x11_replace_property_long( + &self, + display: *mut xlib::Display, + property: X11Atom, + prop_type: c_ulong, + data: &[c_ulong], + ) { unsafe { - xlib::XChangeProperty(display, - *self, - property.to_xlib_atom(display), - prop_type, - 32, - xlib::PropModeReplace, - data.as_ptr().cast::(), - data.len() as i32); + xlib::XChangeProperty( + display, + *self, + property.to_xlib_atom(display), + prop_type, + 32, + xlib::PropModeReplace, + data.as_ptr().cast::(), + data.len() as i32, + ); } } @@ -226,21 +335,47 @@ impl X11Window for xlib::Window { let state_atom = WMState.to_xlib_atom(display); unsafe { - xlib::XChangeProperty(display, *self, state_atom, state_atom, - 32, xlib::PropModeReplace, &data as *const i32 as *const u8, 1); + xlib::XChangeProperty( + display, + *self, + state_atom, + state_atom, + 32, + xlib::PropModeReplace, + &data as *const i32 as *const u8, + 1, + ); } } - - fn x11_set_text_list_property(&self, display: *mut xlib::Display, property: X11Atom, list: &[String]) { - let mut pointers: Vec<*mut c_char> = list.iter().flat_map(|s| CString::new(s.clone())) - .map(|s| s.into_raw()).collect(); + fn x11_set_text_list_property( + &self, + display: *mut xlib::Display, + property: X11Atom, + list: &[String], + ) { + let mut pointers: Vec<*mut c_char> = list + .iter() + .flat_map(|s| CString::new(s.clone())) + .map(|s| s.into_raw()) + .collect(); let slice = &mut pointers; let mut text: MaybeUninit = MaybeUninit::uninit(); let size = slice.len().try_into().unwrap(); unsafe { - xlib::Xutf8TextListToTextProperty(display, slice.as_mut_ptr(), size, xlib::XUTF8StringStyle, text.as_mut_ptr()); - xlib::XSetTextProperty(display, *self, &mut text.assume_init(), property.to_xlib_atom(display)); + xlib::Xutf8TextListToTextProperty( + display, + slice.as_mut_ptr(), + size, + xlib::XUTF8StringStyle, + text.as_mut_ptr(), + ); + xlib::XSetTextProperty( + display, + *self, + &mut text.assume_init(), + property.to_xlib_atom(display), + ); } } @@ -249,7 +384,10 @@ impl X11Window for xlib::Window { .map(|(_root, x, y, w, h, _bw, _depth)| Dimensions::new(x, y, w, h)) } - fn x11_geometry(&self, display: *mut xlib::Display) -> Result<(u64, i32, i32, u32, u32, u32, u32)> { + fn x11_geometry( + &self, + display: *mut xlib::Display, + ) -> Result<(u64, i32, i32, u32, u32, u32, u32)> { unsafe { let mut root: u64 = 0; let mut x: i32 = 0; @@ -258,7 +396,10 @@ impl X11Window for xlib::Window { let mut h: u32 = 0; let mut bw: u32 = 0; let mut depth: u32 = 0; - if xlib::XGetGeometry(display, *self, &mut root, &mut x, &mut y, &mut w, &mut h, &mut bw, &mut depth) != 0 { + if xlib::XGetGeometry( + display, *self, &mut root, &mut x, &mut y, &mut w, &mut h, &mut bw, &mut depth, + ) != 0 + { Ok((root, x, y, w, h, bw, depth)) } else { Err(MarsError::failed_request(stringify!(xlib::XGetGeometry))) @@ -276,15 +417,32 @@ impl X11Window for xlib::Window { unsafe { let mut win_types_ptr: *mut u8 = ptr::null_mut(); // TODO use x11_read_property_long - let result = xlib::XGetWindowProperty(display, *self, NetWMWindowType.to_xlib_atom(display), - 0, 8, xlib::False, xlib::XA_ATOM, - &mut da, &mut di, &mut nitems, &mut dl, &mut win_types_ptr); + let result = xlib::XGetWindowProperty( + display, + *self, + NetWMWindowType.to_xlib_atom(display), + 0, + 8, + xlib::False, + xlib::XA_ATOM, + &mut da, + &mut di, + &mut nitems, + &mut dl, + &mut win_types_ptr, + ); if result == xlib::Success.into() && !win_types_ptr.is_null() { - let temp = slice::from_raw_parts(win_types_ptr as *mut xlib::Atom, nitems.try_into().unwrap()); + let temp = slice::from_raw_parts( + win_types_ptr as *mut xlib::Atom, + nitems.try_into().unwrap(), + ); types = temp.to_vec(); } } - types.iter().filter_map(|xa| X11Atom::from_xlib_atom(display, *xa)).collect() + types + .iter() + .filter_map(|xa| X11Atom::from_xlib_atom(display, *xa)) + .collect() } fn x11_is_transient_for(&self, display: *mut xlib::Display) -> Option { @@ -303,7 +461,13 @@ impl X11Window for xlib::Window { } } - fn x11_message(&self, display: *mut xlib::Display, msg_type: atoms::X11Atom, msg_format: c_int, msg_data: xlib::ClientMessageData) { + fn x11_message( + &self, + display: *mut xlib::Display, + msg_type: atoms::X11Atom, + msg_format: c_int, + msg_data: xlib::ClientMessageData, + ) { unsafe { let msg_type_x11 = msg_type.to_xlib_atom(display); let msg_event = xlib::XClientMessageEvent { @@ -317,7 +481,9 @@ impl X11Window for xlib::Window { data: msg_data, }; - let mut event = xlib::XEvent { client_message: msg_event }; + let mut event = xlib::XEvent { + client_message: msg_event, + }; xlib::XSendEvent(display, *self, xlib::False, 0, &mut event); } @@ -343,18 +509,26 @@ impl X11Window for xlib::Window { supported_atoms.push(*n); } } - supported_atoms.iter().filter_map(|xa| X11Atom::from_xlib_atom(display, *xa)).collect() + supported_atoms + .iter() + .filter_map(|xa| X11Atom::from_xlib_atom(display, *xa)) + .collect() } fn x11_wm_name(&self, display: *mut xlib::Display) -> Result { self.x11_read_property_string(display, WMName) } - fn x11_wm_normal_hints(&self, display: *mut xlib::Display) -> Result<(xlib::XSizeHints, c_long)> { + fn x11_wm_normal_hints( + &self, + display: *mut xlib::Display, + ) -> Result<(xlib::XSizeHints, c_long)> { unsafe { let mut size_hints: MaybeUninit = MaybeUninit::uninit(); let mut supplied_hints: c_long = 0; - if xlib::XGetWMNormalHints(display, *self, size_hints.as_mut_ptr(), &mut supplied_hints) != 0 { + if xlib::XGetWMNormalHints(display, *self, size_hints.as_mut_ptr(), &mut supplied_hints) + != 0 + { Ok((size_hints.assume_init(), supplied_hints)) } else { Err(MarsError::property_unavailable(WMNormalHints)) diff --git a/marswm/src/bindings.rs b/marswm/src/bindings.rs index 0d272724..b717d813 100644 --- a/marswm/src/bindings.rs +++ b/marswm/src/bindings.rs @@ -266,7 +266,7 @@ impl ButtonBinding { } pub fn matches(&self, modifiers: u32, button: u32, target: ButtonTarget) -> bool { - modifiers == self.modifiers() && button == self.button && self.targets.iter().any(|t| *t == target) + modifiers == self.modifiers() && button == self.button && self.targets.contains(&target) } pub fn modifiers(&self) -> u32 { diff --git a/marswm/src/config.rs b/marswm/src/config.rs index ba7d7b8f..17b30c2a 100644 --- a/marswm/src/config.rs +++ b/marswm/src/config.rs @@ -122,7 +122,9 @@ pub struct NoDecorThemingConfiguration { #[derive(Serialize,Deserialize,Clone,Copy,Debug,PartialEq,Eq)] #[serde(rename_all = "kebab-case")] +#[derive(Default)] pub enum WindowPlacement { + #[default] Centered, Pointer, Wherever, @@ -177,11 +179,6 @@ impl Default for ThemingConfiguration { -impl Default for WindowPlacement { - fn default() -> Self { - Self::Centered - } -} impl WindowPlacement { diff --git a/marswm/src/monitor.rs b/marswm/src/monitor.rs index a6cb4c6c..8558aafc 100644 --- a/marswm/src/monitor.rs +++ b/marswm/src/monitor.rs @@ -3,9 +3,9 @@ use libmars::interfaces::wm::Client; use std::cell::RefCell; use std::rc::Rc; -use crate::*; use crate::config::Configuration; use crate::workspace::*; +use crate::*; pub struct Monitor> { config: MonitorConfig, @@ -16,12 +16,22 @@ pub struct Monitor> { } impl> Monitor { - pub fn new(monitor_config: MonitorConfig, config: &Configuration, primary: bool, workspace_offset: u32) - -> Monitor { - + pub fn new( + monitor_config: MonitorConfig, + config: &Configuration, + primary: bool, + workspace_offset: u32, + ) -> Monitor { let workspaces: Vec> = if primary { (0..config.primary_workspaces) - .map(|i| Workspace::new((i + 1).to_string(), workspace_offset + i, monitor_config.window_area(), config.layout)) + .map(|i| { + Workspace::new( + (i + 1).to_string(), + workspace_offset + i, + monitor_config.window_area(), + config.layout, + ) + }) .collect() } else { (0..config.secondary_workspaces) @@ -31,7 +41,12 @@ impl> Monitor { } else { format!("{}:{}", monitor_config.name(), i + 1) }; - Workspace::new(name, workspace_offset + i, monitor_config.window_area(), config.layout) + Workspace::new( + name, + workspace_offset + i, + monitor_config.window_area(), + config.layout, + ) }) .collect() }; @@ -70,10 +85,7 @@ impl> Monitor { } pub fn set_cur_workspace(&mut self, workspace_idx: u32) { - if workspace_idx == self.cur_workspace { - } else if workspace_idx >= self.workspace_count() { - return; - } else { + if workspace_idx != self.cur_workspace && workspace_idx < self.workspace_count() { self.prev_workspace = self.cur_workspace; self.cur_workspace = workspace_idx; } @@ -105,11 +117,11 @@ impl> Monitor { self.workspace_offset } - pub fn workspaces(&self) -> Box> + '_>{ + pub fn workspaces(&self) -> Box> + '_> { Box::new(self.workspaces.iter()) } - pub fn workspaces_mut(&mut self) -> Box> + '_>{ + pub fn workspaces_mut(&mut self) -> Box> + '_> { Box::new(self.workspaces.iter_mut()) } }