Skip to content
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ Notable changes are recorded here. The format follows

### Added

- "Highlight mouse clicks" in the menu: a spot under the cursor at every click, yellow for
the left button and blue for the right. It follows a drag, fades where the button was let
go, is sized by each monitor's display scaling, and shows in screen captures.
- "Find cursor" in the menu: pressing Ctrl twice (or Shift or Alt, as chosen there) puts a dark halo with a bright ring around
the cursor, on whichever monitor it is. A click, a key or three seconds' rest dismisses it.
- Rust port of the C# Windows original, running on Windows, macOS and Linux.
- Settings menu and dialogs drawn by the program.
- Automated builds and releases for all supported platforms.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ cargo build --release
lock the screen, turn the monitor off, and more.
- 🔆 **Brightness panel.** Adjust every monitor from the tray, including **external monitors over
DDC/CI**, and use the mouse wheel to fine-tune.
- 🟡 **Click highlight.** Tick *Highlight mouse clicks* and every click shows a spot under the
cursor, yellow for the left button and blue for the right, on whichever monitor you click.
Unlike the walkers it shows in recordings and screen shares, which is what it is for.
- 🔦 **Find cursor.** Tick *Find cursor* and press Ctrl twice: a dark halo closes in on the
cursor, wherever it is on your monitors. A click, a key or a few seconds' rest sends it away.
The key is yours to pick in the menu: Ctrl, Shift or Alt (Option on a Mac).
- 💻 **Terminal prompt.** A window that sets up [Oh My Posh](https://ohmyposh.dev) for you:
installs or updates it, fetches its themes, puts the one you pick into every shell you have
(PowerShell, Windows PowerShell, bash, zsh, fish, Command Prompt through Clink, nu), installs
Expand Down
4 changes: 2 additions & 2 deletions crates/application/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub mod updates;

pub use brains::Brains;
pub use ports::{
BrainStore, BrightnessInfo, Desktop, Displays, Journal, Os, PreferenceStore, ReleaseFeed,
RunResult, Screen, Workstation,
BrainStore, BrightnessInfo, Desktop, Displays, Journal, Modifier, MouseButtons, Os,
PreferenceStore, ReleaseFeed, RunResult, Screen, Workstation,
};
pub use posh::Posh;
pub use preferences::Preferences;
Expand Down
38 changes: 38 additions & 0 deletions crates/application/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ pub struct BrightnessInfo {
pub key: String,
}

/// The two main mouse buttons, as the person's settings name them: on a left-handed
/// mouse `left` is still the primary button.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct MouseButtons {
pub left: bool,
pub right: bool,
}

/// A modifier key, on either side of the keyboard.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Modifier {
#[default]
Ctrl,
Shift,
/// Option on a Mac.
Alt,
}

impl Modifier {
pub const ALL: [Modifier; 3] = [Modifier::Ctrl, Modifier::Shift, Modifier::Alt];

/// From its saved number; `None` for one that was never a choice.
pub fn from_i32(v: i32) -> Option<Modifier> {
Modifier::ALL.into_iter().find(|m| *m as i32 == v)
}
}

// ---- The desktop -------------------------------------------------------------------------

/// The OS services the program uses. Every method is cheap unless it says otherwise,
Expand All @@ -43,6 +70,17 @@ pub trait Desktop: Send + Sync {
/// Where the cursor is, in world pixels; `None` when the OS will not say.
fn cursor_pos(&self) -> Option<Point>;
fn mouse_button_down(&self) -> bool;
/// Which main buttons are held, or were pressed since the last call: where the OS
/// can say, a click shorter than the caller's poll is still reported once. For one
/// caller only (the click highlight), since asking forgets the presses.
fn mouse_buttons(&self) -> MouseButtons;
/// The modifier is held, or where the OS can say was pressed since the last call.
fn modifier_down(&self, key: Modifier) -> bool;
/// Any key besides that modifier is held, the other modifiers included. Dearer than
/// the rest: asked only while a press of the modifier is being followed.
fn other_key_down(&self, key: Modifier) -> bool;
/// What this OS's keyboards call the modifier.
fn modifier_name(&self, key: Modifier) -> &'static str;
/// Seconds since the last input the OS counted, from anyone.
fn system_idle_seconds(&self) -> f64;
/// A harmless input that resets the OS idle clock.
Expand Down
18 changes: 17 additions & 1 deletion crates/application/src/preferences.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The menu choices that survive between runs: their names, defaults and the checks
//! that keep a damaged or older value from doing harm. Where they are kept is the
//! `PreferenceStore` port's business.
use crate::ports::PreferenceStore;
use crate::ports::{Modifier, PreferenceStore};
use idlewalker_domain::prelude::*;
use std::sync::Arc;

Expand Down Expand Up @@ -75,6 +75,22 @@ impl Preferences {
"KeepAwake",
Settings::KEEP_AWAKE_BY_DEFAULT
);
// Off until asked for: it draws over whatever the person is working on.
switch!(
load_click_highlight,
save_click_highlight,
"ClickHighlight",
false
);
switch!(load_find_cursor, save_find_cursor, "FindCursor", false);

/// The key that, pressed twice, finds the cursor.
pub fn load_find_key(&self) -> Modifier {
Modifier::from_i32(self.load("FindCursorKey", 0)).unwrap_or_default()
}
pub fn save_find_key(&self, key: Modifier) {
self.0.save("FindCursorKey", key as i32)
}

/// True once "start at sign-in" has been set up, so the default applies only once.
pub fn startup_decided(&self) -> bool {
Expand Down
24 changes: 23 additions & 1 deletion crates/application/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! per frame, saves what it learned, and applies the menu's choices. The presentation
//! layer calls `tick` once per frame and shows the result.
use crate::brains::Brains;
use crate::ports::{Desktop, Displays, Journal};
use crate::ports::{Desktop, Displays, Journal, Modifier};
use crate::preferences::Preferences;
use idlewalker_domain::prelude::*;
use std::sync::Arc;
Expand All @@ -17,6 +17,11 @@ pub struct Choices {
pub hide_on_move: bool,
pub corners: bool,
pub keep_awake: bool,
/// A coloured spot under the cursor at every click.
pub click_highlight: bool,
/// Pressing `find_key` twice shows where the cursor is.
pub find_cursor: bool,
pub find_key: Modifier,
pub startup: bool,
pub minion_mask: i32,
pub bird_mask: i32,
Expand Down Expand Up @@ -157,6 +162,9 @@ impl Session {
hide_on_move: prefs.load_hide_on_move(),
corners: prefs.load_hot_corners_enabled(),
keep_awake: prefs.load_keep_awake(),
click_highlight: prefs.load_click_highlight(),
find_cursor: prefs.load_find_cursor(),
find_key: prefs.load_find_key(),
startup: desktop.startup_is_enabled(),
minion_mask: troupe.minion_mask(),
bird_mask: troupe.bird_mask(),
Expand Down Expand Up @@ -409,6 +417,20 @@ impl Session {
prefs.save_keep_awake(self.choices.keep_awake);
self.desktop.keep_awake(self.choices.keep_awake);
}
"click-highlight" => {
self.choices.click_highlight = !self.choices.click_highlight;
prefs.save_click_highlight(self.choices.click_highlight);
}
"find-cursor" => {
self.choices.find_cursor = !self.choices.find_cursor;
prefs.save_find_cursor(self.choices.find_cursor);
}
"find-key" => {
if let Some(key) = Modifier::from_i32(value) {
self.choices.find_key = key;
prefs.save_find_key(key);
}
}
"startup" => {
let enable = !self.choices.startup;
match self.desktop.startup_set(enable) {
Expand Down
26 changes: 25 additions & 1 deletion crates/platform/src/adapters.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The OS backends behind the ports. Each implementation only forwards to the backend
//! compiled for this OS, so the ports stay the one place a capability is described.
use crate::prelude::*;
use crate::{backend, BrightnessInfo, MonitorWorld, Screen, SpriteWindow};
use crate::{backend, BrightnessInfo, Modifier, MonitorWorld, MouseButtons, Screen, SpriteWindow};
use idlewalker_application::{
Desktop, Displays, Journal, Os, ReleaseFeed, RunResult, Updates, Workstation,
};
Expand All @@ -21,6 +21,24 @@ impl Desktop for NativeDesktop {
fn mouse_button_down(&self) -> bool {
backend::mouse_button_down()
}
fn mouse_buttons(&self) -> MouseButtons {
backend::mouse_buttons()
}
fn modifier_down(&self, key: Modifier) -> bool {
backend::modifier_down(key)
}
fn other_key_down(&self, key: Modifier) -> bool {
backend::other_key_down(key)
}
fn modifier_name(&self, key: Modifier) -> &'static str {
match key {
Modifier::Ctrl if cfg!(target_os = "macos") => "Control",
Modifier::Ctrl => "Ctrl",
Modifier::Shift => "Shift",
Modifier::Alt if cfg!(target_os = "macos") => "Option",
Modifier::Alt => "Alt",
}
}
fn system_idle_seconds(&self) -> f64 {
backend::system_idle_seconds()
}
Expand Down Expand Up @@ -124,6 +142,12 @@ pub fn sprite_factory() -> SpriteFactory {
Arc::new(|| Box::new(SpriteWindow::new()) as Box<dyn SpriteSink>)
}

/// Makes sprite windows that screenshots, recordings and screen sharing include: the
/// click highlight is there to be seen by whoever is watching.
pub fn capturable_sprite_factory() -> SpriteFactory {
Arc::new(|| Box::new(SpriteWindow::capturable()) as Box<dyn SpriteSink>)
}

// ---- The local clock ---------------------------------------------------------------------

/// Local time as the OS keeps it.
Expand Down
5 changes: 3 additions & 2 deletions crates/platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
mod adapters;
mod files;
pub use adapters::{
sprite_factory, CurlReleaseFeed, NativeDesktop, NativeWorkstation, SystemClock, TempFileJournal,
capturable_sprite_factory, sprite_factory, CurlReleaseFeed, NativeDesktop, NativeWorkstation,
SystemClock, TempFileJournal,
};
pub use files::{FileBrainStore, FilePreferences};
pub use idlewalker_application::{BrightnessInfo, Screen};
pub use idlewalker_application::{BrightnessInfo, Modifier, MouseButtons, Screen};

pub(crate) use idlewalker_domain::rt;
pub(crate) mod prelude {
Expand Down
55 changes: 45 additions & 10 deletions crates/platform/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! XWayland: walkers and the brightness panel work, but Wayland does not let any
//! program read the global cursor, so the position only updates while the pointer is
//! over an X11 window. See "Platform differences" in the README.
use super::{BrightnessInfo, Screen};
use super::{BrightnessInfo, Modifier, MouseButtons, Screen};
use crate::prelude::*;
use crate::rt::{Point, Rectangle};
use std::ffi::CString;
Expand Down Expand Up @@ -203,19 +203,49 @@ pub fn cursor_pos() -> Option<Point> {
Some(Point::new(r.root_x as i32, r.root_y as i32))
}

/// The pointer's button and modifier bits; 0 when the server will not say.
fn pointer_mask() -> u16 {
x().and_then(|x| x.conn.query_pointer(x.root).ok()?.reply().ok())
.map_or(0, |r| u16::from(r.mask))
}

pub fn mouse_button_down() -> bool {
pointer_mask()
& (u16::from(KeyButMask::BUTTON1)
| u16::from(KeyButMask::BUTTON2)
| u16::from(KeyButMask::BUTTON3))
!= 0
}

/// Held right now, after the person's button mapping. The server keeps no record of
/// presses, so a click shorter than the caller's poll is not seen.
pub fn mouse_buttons() -> MouseButtons {
let mask = pointer_mask();
MouseButtons {
left: mask & u16::from(KeyButMask::BUTTON1) != 0,
right: mask & u16::from(KeyButMask::BUTTON3) != 0,
}
}

pub fn modifier_down(key: Modifier) -> bool {
let bit = match key {
Modifier::Shift => KeyButMask::SHIFT,
Modifier::Ctrl => KeyButMask::CONTROL,
Modifier::Alt => KeyButMask::MOD1,
};
pointer_mask() & u16::from(bit) != 0
}

/// More keys are held than the one the modifier accounts for.
pub fn other_key_down(key: Modifier) -> bool {
let Some(x) = x() else { return false };
x.conn
.query_pointer(x.root)
let held: u32 = x
.conn
.query_keymap()
.ok()
.and_then(|r| r.reply().ok())
.is_some_and(|r| {
u16::from(r.mask)
& (u16::from(KeyButMask::BUTTON1)
| u16::from(KeyButMask::BUTTON2)
| u16::from(KeyButMask::BUTTON3))
!= 0
})
.map_or(0, |r| r.keys.iter().map(|b| b.count_ones()).sum());
held > modifier_down(key) as u32
}

// ---- Pacing and power ---------------------------------------------------------------------
Expand Down Expand Up @@ -604,6 +634,11 @@ pub struct SpriteWindow {
}

impl SpriteWindow {
/// Nothing hides an X11 window from a capture, so this is the same window.
pub fn capturable() -> Self {
Self::new()
}

pub fn new() -> Self {
let mut s = SpriteWindow {
win: None,
Expand Down
Loading
Loading