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
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ OS tested on:

- [ ] `cargo test --release --workspace --lib` passes
- [ ] `cargo test --release --test selftest` passes
- [ ] The README is updated if behaviour differs across OSes
- [ ] The platform table in `docs/DEVELOPMENT.md` is updated if behaviour differs across OSes
- [ ] `CHANGELOG.md` is updated if users will notice this change
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ jobs:
run: sh tools/release/stamp-version.sh "$TAG"

- name: Unit tests
run: cargo test --release --workspace --lib
run: cargo test --release --locked --workspace --lib

- name: Self-test
run: cargo test --release --test selftest
run: cargo test --release --locked --test selftest

- name: Build
if: runner.os != 'Linux'
run: cargo build --release --bin idlewalker
run: cargo build --release --locked --bin idlewalker

# Linked against an old glibc, because a binary only runs on a glibc at least as new as
# the one it was linked against, and the runner's is recent. A later step checks it.
Expand Down
11 changes: 4 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Notable changes are recorded here. The format follows
- The painter on macOS no longer drops to the efficiency cores on Apple Silicon.
- Painting runs on two threads where there are cores to spare, and the paint budget no
longer flips the frame rate back and forth when the demand hovers near it.
- On macOS with displays of different scaling, tray panels no longer open in the wrong place
or close when clicked.
- On macOS, each brightness slider now uses the same display number as the card on that monitor.

### Added

Expand All @@ -36,12 +39,6 @@ Notable changes are recorded here. The format follows

- Linux downloads are now a single executable that runs on glibc 2.28 and later, instead of a
tar archive that needed glibc 2.34.
- macOS downloads are now one disk image with a universal `IdleWalker.app`, instead of a tar
- macOS downloads are now one zip holding a universal `IdleWalker.app`, instead of a tar
archive per CPU type.
- On macOS, a click on the status bar icon now opens the brightness panel.

### Fixed

- On macOS with displays of different scaling, tray panels no longer open in the wrong place
or close when clicked.
- On macOS, each brightness slider now uses the same display number as the card on that monitor.
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cargo test --release --test selftest
```

Run the unit tests and the self-test before opening a pull request. CI runs them on Windows,
Linux and macOS. The [README](README.md#how-it-is-built) explains how the code is laid out.
Linux and macOS. [DEVELOPMENT.md](docs/DEVELOPMENT.md#how-it-is-built) explains how the code is laid out.

`IDLEWALKER_TEST=1` is useful while developing: it leaves your sign-in entry alone and skips the
single-instance check.
Expand All @@ -36,7 +36,8 @@ single-instance check.
## Pull requests

- Keep each pull request to one change, and say how you tested it and on which OS.
- If a feature behaves differently across OSes, update the table in the README.
- If a feature behaves differently across OSes, update the platform table in
[DEVELOPMENT.md](docs/DEVELOPMENT.md#platform-differences).
- Add a line to the `Unreleased` section of [CHANGELOG.md](CHANGELOG.md) for anything users notice.

By contributing, you agree that your contribution is licensed under the [MIT License](LICENSE).
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ license.workspace = true
repository.workspace = true
description = "A tiny desktop companion: characters stroll along the bottom of your screens while the mouse rests."
readme = "README.md"
# `cargo run` and `cargo install` mean the app, not the port-checking tools beside it.
default-run = "idlewalker"
keywords = ["desktop-pet", "desktop-companion", "tray", "animation"]
categories = ["games"]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ native Wayland windows, so idle detection and hot corners are less reliable ther
| OS | Needs |
| --- | --- |
| Windows | Windows 10 1703 or later. Nothing to install. |
| macOS | Nothing to install. Run it from Applications, not from the opened disk image, or *Start at login* will point at a path that goes away. Hot corners that send keys ask for the Accessibility permission. |
| macOS | Nothing to install. Run it from Applications, not from the unzipped folder, or *Start at login* will point at a path that may go away. Hot corners that send keys ask for the Accessibility permission. |
| Linux | glibc 2.28+ (Debian 10 / Ubuntu 20.04 and newer), X11 or XWayland with a compositing window manager. For the tray icon, StatusNotifierItem support (KDE, or GNOME with the AppIndicator extension). Optional: `ddcutil` for external monitor brightness and `brightnessctl` for the built-in panel. |
</details>

Expand Down
8 changes: 7 additions & 1 deletion crates/platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
//!
//! All coordinates are "world pixels": y grows downward from the top of the primary
//! display, and a monitor's `scale` says how big one cell is drawn there.
#![allow(warnings)]
// Style lints only: the FFI declarations keep the OS's own type names, and the adapters
// are built by the composition root, not by `Default`. Compiler warnings are not silenced.
#![allow(
clippy::upper_case_acronyms,
clippy::type_complexity,
clippy::new_without_default
)]
mod adapters;
mod files;
pub use adapters::{sprite_factory, CurlReleaseFeed, NativeDesktop, SystemClock, TempFileJournal};
Expand Down
4 changes: 1 addition & 3 deletions crates/platform/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use x11rb::protocol::shape::{self, ConnectionExt as _};
use x11rb::protocol::xproto::*;
use x11rb::protocol::xtest::ConnectionExt as _;
use x11rb::rust_connection::RustConnection;
use x11rb::wrapper::ConnectionExt as _;

struct X {
conn: RustConnection,
Expand Down Expand Up @@ -349,7 +348,6 @@ pub const CORNER_ACTION_NAMES: [&str; 10] = [
"Call the Minions",
];

const KEY_ESC: u8 = 9;
const KEY_LCTRL: u8 = 37;
const KEY_LALT: u8 = 64;
const KEY_LSUPER: u8 = 133;
Expand Down Expand Up @@ -669,7 +667,7 @@ impl SpriteWindow {

/// Shows the surface with its top-left corner at (x, y). Only the part that has
/// content is uploaded and shown; the window shrinks to fit it.
pub fn present(&mut self, mut surface: Surface, px: i32, py: i32) {
pub fn present(&mut self, surface: Surface, px: i32, py: i32) {
let (Some(win), Some(x)) = (self.win, x()) else {
return;
};
Expand Down
19 changes: 8 additions & 11 deletions crates/platform/src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#![allow(non_upper_case_globals)]
use super::{BrightnessInfo, Screen};
use crate::prelude::*;
use objc2::rc::Retained;
use objc2::runtime::{AnyClass, AnyObject, Bool};
use objc2::runtime::AnyObject;
use objc2::{class, msg_send};
use objc2_foundation::{NSPoint, NSRect, NSSize};
use std::ffi::{c_void, CString};
Expand All @@ -18,7 +17,6 @@ type Id = *mut AnyObject;
#[link(name = "CoreGraphics", kind = "framework")]
extern "C" {
fn CGColorSpaceCreateDeviceRGB() -> *mut c_void;
fn CGColorSpaceRelease(c: *mut c_void);
fn CGDataProviderCreateWithData(
info: *mut c_void,
data: *const c_void,
Expand Down Expand Up @@ -48,8 +46,12 @@ extern "C" {
#[link(name = "CoreFoundation", kind = "framework")]
extern "C" {
fn CFRelease(o: *const c_void);
fn CFStringGetCString(s: *const c_void, out: *mut std::ffi::c_char, size: isize, enc: u32)
-> u8;
fn CFStringGetCString(
s: *const c_void,
out: *mut std::ffi::c_char,
size: isize,
enc: u32,
) -> u8;
}
#[link(name = "IOKit", kind = "framework")]
extern "C" {
Expand Down Expand Up @@ -87,11 +89,6 @@ const kCGEventFlagMaskSecondaryFn: u64 = 0x800000;

pub(crate) fn hide_console(_c: &mut std::process::Command) {}

unsafe fn cls(name: &str) -> &'static AnyClass {
let c = CString::new(name).unwrap();
AnyClass::get(c.as_c_str()).expect("AppKit class")
}

// ---- The process -------------------------------------------------------------------

pub fn init_process() {}
Expand Down Expand Up @@ -1181,7 +1178,7 @@ impl SpriteWindow {

/// Shows the surface with its top-left corner at (x, y). Only the part that has
/// content is uploaded; it is placed where it belongs inside the canvas-sized window.
pub fn present(&mut self, mut surface: Surface, x: i32, y: i32) {
pub fn present(&mut self, surface: Surface, x: i32, y: i32) {
let mut b = surface.bounds();
if b.is_empty() {
b = Rectangle::new(0, 0, 1, 1);
Expand Down
57 changes: 45 additions & 12 deletions crates/platform/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#![allow(non_snake_case, non_camel_case_types)]
use super::{BrightnessInfo, Screen};
use crate::prelude::*;
use std::collections::HashMap;
use std::ffi::c_void;
use std::os::windows::process::CommandExt;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Mutex, OnceLock};

Expand Down Expand Up @@ -924,8 +924,14 @@ impl Wmi {
/// The first object a WQL query returns.
fn first(&self, wql: &str) -> Option<Com> {
unsafe {
type ExecQuery =
unsafe extern "system" fn(*mut c_void, *mut u16, *mut u16, i32, *mut c_void, Out) -> i32;
type ExecQuery = unsafe extern "system" fn(
*mut c_void,
*mut u16,
*mut u16,
i32,
*mut c_void,
Out,
) -> i32;
type Next = unsafe extern "system" fn(*mut c_void, i32, u32, Out, *mut u32) -> i32;
let (lang, q) = (Bstr::new("WQL"), Bstr::new(wql));
let mut e = NUL;
Expand All @@ -941,8 +947,14 @@ impl Wmi {
}

fn get(obj: &Com, name: &str) -> Option<VARIANT> {
type Get =
unsafe extern "system" fn(*mut c_void, *const u16, i32, *mut VARIANT, *mut i32, *mut i32) -> i32;
type Get = unsafe extern "system" fn(
*mut c_void,
*const u16,
i32,
*mut VARIANT,
*mut i32,
*mut i32,
) -> i32;
let mut v = VARIANT {
vt: 0,
_reserved: [0; 3],
Expand All @@ -954,7 +966,8 @@ impl Wmi {
}

fn put(obj: &Com, name: &str, vt: u16, value: usize) -> bool {
type Put = unsafe extern "system" fn(*mut c_void, *const u16, i32, *mut VARIANT, i32) -> i32;
type Put =
unsafe extern "system" fn(*mut c_void, *const u16, i32, *mut VARIANT, i32) -> i32;
let mut v = VARIANT {
vt,
_reserved: [0; 3],
Expand All @@ -974,17 +987,33 @@ impl Wmi {
let path = Bstr(p.data[0] as *mut u16); // ownership moves to the Bstr
type GetObject =
unsafe extern "system" fn(*mut c_void, *mut u16, i32, *mut c_void, Out, Out) -> i32;
type GetMethod = unsafe extern "system" fn(*mut c_void, *const u16, i32, Out, Out) -> i32;
type GetMethod =
unsafe extern "system" fn(*mut c_void, *const u16, i32, Out, Out) -> i32;
type SpawnInstance = unsafe extern "system" fn(*mut c_void, i32, Out) -> i32;
let name = Bstr::new("WmiMonitorBrightnessMethods");
let mut class = NUL;
if slot::<GetObject>(self.svc.0, 6)(self.svc.0, name.0, 0, NUL, &mut class, std::ptr::null_mut()) < 0 {
if slot::<GetObject>(self.svc.0, 6)(
self.svc.0,
name.0,
0,
NUL,
&mut class,
std::ptr::null_mut(),
) < 0
{
return None;
}
let class = Com(class);
let (mut in_def, mut out_def) = (NUL, NUL);
let method = w("WmiSetBrightness");
if slot::<GetMethod>(class.0, 19)(class.0, method.as_ptr(), 0, &mut in_def, &mut out_def) < 0 {
if slot::<GetMethod>(class.0, 19)(
class.0,
method.as_ptr(),
0,
&mut in_def,
&mut out_def,
) < 0
{
return None;
}
let (in_def, _out_def) = (Com(in_def), Com(out_def));
Expand All @@ -1002,7 +1031,8 @@ impl Wmi {
}

fn brightness(&self) -> Option<i32> {
let o = self.first("SELECT CurrentBrightness FROM WmiMonitorBrightness WHERE Active=TRUE")?;
let o =
self.first("SELECT CurrentBrightness FROM WmiMonitorBrightness WHERE Active=TRUE")?;
let mut v = Self::get(&o, "CurrentBrightness")?;
let r = match v.vt {
VT_UI1 => Some((v.data[0] & 0xFF) as i32),
Expand Down Expand Up @@ -1193,7 +1223,10 @@ pub fn brightness_write(key: &str, percent: i32) {
for (j, p) in physical_monitors(m).into_iter().enumerate() {
unsafe {
// The range learned at enumeration; only a monitor not seen then is read.
let known = ddc_ranges().lock().ok().and_then(|r| r.get(&(i, j)).copied());
let known = ddc_ranges()
.lock()
.ok()
.and_then(|r| r.get(&(i, j)).copied());
let (mut lo, mut cur, mut hi) = (0, 0, 0);
if let Some(r) = known {
(lo, hi) = r;
Expand Down Expand Up @@ -1334,7 +1367,7 @@ impl SpriteWindow {

/// Shows the surface with its top-left corner at (x, y). Only the part that has
/// content is uploaded and shown; the window shrinks to fit it.
pub fn present(&mut self, mut surface: Surface, x: i32, y: i32) {
pub fn present(&mut self, surface: Surface, x: i32, y: i32) {
let (sw, sh) = (surface.width(), surface.height());
self.ensure_bitmap(sw, sh);
if self.dib == 0 {
Expand Down
4 changes: 2 additions & 2 deletions crates/ui/src/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ pub struct BrainDialog {
confirm: bool,
}

fn row_of(mut w: Walker) -> Row {
fn row_of(w: Walker) -> Row {
let (t, fr, exp) = (w.learned_entries(), w.friendships(), w.experience());
let (avg, net) = (w.avg_reward(), w.mlp_weight_norm());
Row {
Expand Down Expand Up @@ -822,7 +822,7 @@ impl BrainDialog {
f: &mut Font,
m: &Mouse,
s: f64,
mut troupe: Troupe,
troupe: Troupe,
services: &Services,
) -> Outcome {
c.clear(gfx::BACK);
Expand Down
8 changes: 7 additions & 1 deletion crates/ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
//! the tray menu, the cards and the dialogs. What happens each frame is the
//! `Session`'s business; this crate shows it, and turns clicks into its commands. It
//! never names an OS service: they all arrive as ports from the composition root.
#![allow(warnings)]
// Style lints only: the painters take their geometry as plain arguments, and the index
// loops mirror the rows they draw. Compiler warnings are not silenced.
#![allow(
clippy::too_many_arguments,
clippy::new_without_default,
clippy::needless_range_loop
)]
pub mod dialogs;
pub mod gfx;
pub mod menu_panel;
Expand Down
15 changes: 8 additions & 7 deletions crates/ui/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,14 @@ pub fn logo_rgba(size: u32) -> Vec<u8> {
n += 1;
}
}
let i = (y * s + x) * 4;
if a > 0 {
out[i] = (r / a) as u8;
out[i + 1] = (g / a) as u8;
out[i + 2] = (b / a) as u8;
out[i + 3] = (a / n) as u8;
if a == 0 {
continue; // fully transparent: leave the zeroed pixel
}
let i = (y * s + x) * 4;
out[i] = (r / a) as u8;
out[i + 1] = (g / a) as u8;
out[i + 2] = (b / a) as u8;
out[i + 3] = (a / n) as u8;
}
}
out
Expand Down Expand Up @@ -369,7 +370,7 @@ mod backend {
let size = 32;
// The protocol wants ARGB, network byte order.
let mut data = logo_rgba(size as u32);
for p in data.chunks_exact_mut(4) {
for p in data.as_chunks_mut::<4>().0 {
p.rotate_right(1);
}
vec![ksni::Icon {
Expand Down
4 changes: 2 additions & 2 deletions tools/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ fn main() {
let scale = 3;
let (width, height) = (40 * scale, anatomies[l].canvas_rows * scale);
for yi in 0..yaws.len() {
for pi in 0..phases.len() {
for (pi, &phase) in phases.iter().enumerate() {
for fi in 0..faces.len() {
let mut pose = Pose::standing();
pose.face = faces[fi];
pose.yaw = yaws[yi];
pose.walking = pi > 0;
pose.walk_phase = phases[pi];
pose.walk_phase = phase;
pose.gaze_x = 0.25 * yi as f64 - 0.5;
pose.gaze_y = 0.1 * fi as f64;
pose.lean = 0.1 * pi as f64;
Expand Down
Loading