diff --git a/CHANGES.md b/CHANGES.md index ca097809..ea60771d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -28,6 +28,7 @@ - All: You can now use a logger to investigate errors ## Fixed +- *BSD: Fix the build for BSDs - macOS: Add info how much a mouse was moved relative to the last position - macOS: A mouse drag with the right key is now possible too - win, linux: `key_sequence()` and `key_click(Key::Layout())` can properly enter new lines and tabs diff --git a/Cargo.toml b/Cargo.toml index 7a187cbd..9d5fc94b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ icrate = { version = "0.1", features = [ objc2 = { version = "0.5", features = ["relax-void-encoding"] } foreign-types-shared = "0.3" -[target.'cfg(target_os = "linux")'.dependencies] +[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies] libc = "0.2" wayland-protocols-misc = { version = "0.2", features = [ "client", diff --git a/examples/platform_specific.rs b/examples/platform_specific.rs index a3e87f92..9f3a687a 100644 --- a/examples/platform_specific.rs +++ b/examples/platform_specific.rs @@ -11,7 +11,7 @@ fn main() { #[cfg(target_os = "macos")] enigo.key(Key::Launchpad, Click).unwrap(); // macOS: Open launchpad - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] enigo.key(Key::Meta, Click).unwrap(); // linux: Open launcher #[cfg(target_os = "windows")] diff --git a/src/keycodes.rs b/src/keycodes.rs index ceaa7316..eb2a2054 100644 --- a/src/keycodes.rs +++ b/src/keycodes.rs @@ -1,4 +1,4 @@ -#[cfg(any(target_os = "linux", target_os = "windows"))] +#[cfg(any(all(unix, not(target_os = "macos")), target_os = "windows"))] use log::trace; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -100,9 +100,9 @@ pub enum Key { Attn, /// backspace key Backspace, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] Break, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] Begin, #[cfg(target_os = "macos")] BrightnessDown, @@ -122,11 +122,11 @@ pub enum Key { BrowserSearch, #[cfg(target_os = "windows")] BrowserStop, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Cancel, /// caps lock key CapsLock, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Clear, #[deprecated(since = "0.0.12", note = "now renamed to Meta")] /// command key on macOS (super key on Linux, windows key on Windows) @@ -185,7 +185,7 @@ pub enum Key { Ereof, /// escape key (esc) Escape, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Execute, #[cfg(target_os = "windows")] Exsel, @@ -229,45 +229,45 @@ pub enum Key { F19, /// F20 key F20, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] /// F21 key F21, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] /// F22 key F22, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] /// F23 key F23, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] /// F24 key F24, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F25, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F26, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F27, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F28, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F29, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F30, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F31, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F32, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F33, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F34, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] F35, #[cfg(target_os = "macos")] Function, #[cfg(target_os = "windows")] Final, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] Find, #[cfg(target_os = "windows")] GamepadA, @@ -319,9 +319,9 @@ pub enum Key { GamepadY, #[cfg(target_os = "windows")] Hangeul, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Hangul, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Hanja, Help, /// home key @@ -342,13 +342,13 @@ pub enum Key { IMEOff, #[cfg(target_os = "windows")] IMEOn, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Insert, #[cfg(target_os = "windows")] Junja, #[cfg(target_os = "windows")] Kana, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Kanji, #[cfg(target_os = "windows")] LaunchApp1, @@ -368,9 +368,9 @@ pub enum Key { LControl, /// left arrow key LeftArrow, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] Linefeed, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] LMenu, LShift, #[cfg(target_os = "windows")] @@ -384,14 +384,14 @@ pub enum Key { MediaPrevTrack, #[cfg(target_os = "macos")] MediaRewind, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] MediaStop, /// meta key (also known as "windows", "super", and "command") Meta, #[cfg(target_os = "macos")] /// Opens mission control MissionControl, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] ModeChange, #[cfg(target_os = "windows")] Multiply, @@ -417,7 +417,7 @@ pub enum Key { NonConvert, #[cfg(target_os = "windows")] None, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Numlock, #[cfg(target_os = "windows")] Numpad0, @@ -517,13 +517,13 @@ pub enum Key { PageDown, /// page up key PageUp, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Pause, #[cfg(target_os = "windows")] Play, #[cfg(target_os = "macos")] Power, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Print, #[cfg(target_os = "windows")] Processkey, @@ -532,7 +532,7 @@ pub enum Key { #[cfg(target_os = "macos")] RCommand, RControl, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] Redo, /// return key Return, @@ -547,17 +547,17 @@ pub enum Key { RWin, #[cfg(target_os = "windows")] Scroll, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] ScrollLock, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] Select, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] ScriptSwitch, #[cfg(target_os = "windows")] Separator, /// shift key Shift, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] /// Lock shift key ShiftLock, #[cfg(target_os = "windows")] @@ -571,11 +571,11 @@ pub enum Key { #[deprecated(since = "0.0.12", note = "now renamed to Meta")] /// super key on linux (command key on macOS, windows key on Windows) Super, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] SysReq, /// tab key (tabulator) Tab, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] Undo, /// up arrow key UpArrow, @@ -584,7 +584,7 @@ pub enum Key { VolumeDown, VolumeMute, VolumeUp, - #[cfg(target_os = "linux")] + #[cfg(all(unix, not(target_os = "macos")))] /// microphone mute toggle on linux MicMute, #[deprecated(since = "0.0.12", note = "now renamed to Meta")] @@ -608,7 +608,7 @@ pub enum Key { Other(u32), } -#[cfg(target_os = "linux")] +#[cfg(all(unix, not(target_os = "macos")))] /// Converts a Key to a Keysym impl From for xkeysym::Keysym { #[allow(clippy::too_many_lines)] @@ -1027,7 +1027,7 @@ impl TryFrom for windows::Win32::UI::Input::KeyboardAndMouse::VIRTUAL_KEY { } } -#[cfg(target_os = "linux")] +#[cfg(all(unix, not(target_os = "macos")))] #[cfg(any(feature = "wayland", feature = "x11rb"))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -1042,7 +1042,7 @@ pub(crate) enum Modifier { Mod5, } -#[cfg(target_os = "linux")] +#[cfg(all(unix, not(target_os = "macos")))] #[cfg(any(feature = "wayland", feature = "x11rb"))] impl Modifier { /// Returns the bitflag of the modifier that is usually associated with it @@ -1078,7 +1078,7 @@ impl Modifier { } } -#[cfg(target_os = "linux")] +#[cfg(all(unix, not(target_os = "macos")))] #[cfg(any(feature = "wayland", feature = "x11rb"))] /// Converts a Key to a modifier impl TryFrom for Modifier { @@ -1100,6 +1100,6 @@ impl TryFrom for Modifier { } } -#[cfg(target_os = "linux")] +#[cfg(all(unix, not(target_os = "macos")))] #[cfg(any(feature = "wayland", feature = "x11rb"))] pub(crate) type ModifierBitflag = u32; diff --git a/src/lib.rs b/src/lib.rs index dd940817..8160199c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,7 +64,7 @@ use serde::{Deserialize, Serialize}; /// works. pub mod agent; -#[cfg_attr(target_os = "linux", path = "linux/mod.rs")] +#[cfg_attr(all(unix, not(target_os = "macos")), path = "linux/mod.rs")] #[cfg_attr(target_os = "macos", path = "macos/mod.rs")] #[cfg_attr(target_os = "windows", path = "win/mod.rs")] mod platform; @@ -93,10 +93,10 @@ pub enum Button { Middle, /// Right mouse button Right, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] /// 4th mouse button. Typically performs the same function as `Browser_Back` Back, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", all(unix, not(target_os = "macos"))))] /// 5th mouse button. Typically performs the same function as /// `Browser_Forward` Forward,