Skip to content

Commit

Permalink
Fix the build on *BSDs
Browse files Browse the repository at this point in the history
  • Loading branch information
pentamassiv committed Apr 11, 2024
1 parent 825ae66 commit 51a8d11
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/platform_specific.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
92 changes: 46 additions & 46 deletions src/keycodes.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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")]
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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")]
Expand All @@ -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,
Expand All @@ -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")]
Expand All @@ -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<Key> for xkeysym::Keysym {
#[allow(clippy::too_many_lines)]
Expand Down Expand Up @@ -1027,7 +1027,7 @@ impl TryFrom<Key> 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)]
Expand All @@ -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
Expand Down Expand Up @@ -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<Key> for Modifier {
Expand All @@ -1100,6 +1100,6 @@ impl TryFrom<Key> for Modifier {
}
}

#[cfg(target_os = "linux")]
#[cfg(all(unix, not(target_os = "macos")))]
#[cfg(any(feature = "wayland", feature = "x11rb"))]
pub(crate) type ModifierBitflag = u32;
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 51a8d11

Please sign in to comment.