mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 20:09:59 +03:00
Compare commits
18 Commits
remove-git
...
gtk-fronte
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93f5172daa | ||
|
|
f849135c61 | ||
|
|
77cddacc4a | ||
|
|
7ccf9188fe | ||
|
|
6f8d7e3c1d | ||
|
|
7e9ad6f1a2 | ||
|
|
f6c526b596 | ||
|
|
639e86d95e | ||
|
|
f247300f8c | ||
|
|
5d1745a60c | ||
|
|
615c75817a | ||
|
|
03407b9826 | ||
|
|
89684e1481 | ||
|
|
a1d4effcf9 | ||
|
|
da054b7a9a | ||
|
|
508d066700 | ||
|
|
21c24f7fa1 | ||
|
|
3e1c3e95b7 |
34
.github/workflows/pre-release.yml
vendored
34
.github/workflows/pre-release.yml
vendored
@@ -84,36 +84,56 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install dependencies
|
||||
run: brew install gtk4 libadwaita
|
||||
run: brew install gtk4 libadwaita imagemagick
|
||||
- name: Release Build
|
||||
run: |
|
||||
cargo build --release
|
||||
cp target/release/lan-mouse lan-mouse-macos-intel
|
||||
- name: Make icns
|
||||
run: scripts/makeicns.sh
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle --release
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/release/bundle/osx
|
||||
zip -r "lan-mouse-macos-intel.zip" "Lan Mouse.app"
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: lan-mouse-macos-intel
|
||||
path: lan-mouse-macos-intel
|
||||
path: target/release/bundle/osx/lan-mouse-macos-intel.zip
|
||||
|
||||
macos-aarch64-release-build:
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install dependencies
|
||||
run: brew install gtk4 libadwaita
|
||||
run: brew install gtk4 libadwaita imagemagick
|
||||
- name: Release Build
|
||||
run: |
|
||||
cargo build --release
|
||||
cp target/release/lan-mouse lan-mouse-macos-aarch64
|
||||
- name: Make icns
|
||||
run: scripts/makeicns.sh
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle --release
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/release/bundle/osx
|
||||
zip -r "lan-mouse-macos-aarch64.zip" "Lan Mouse.app"
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: lan-mouse-macos-aarch64
|
||||
path: lan-mouse-macos-aarch64
|
||||
path: target/release/bundle/osx/lan-mouse-macos-aarch64.zip
|
||||
|
||||
pre-release:
|
||||
name: "Pre Release"
|
||||
needs: [windows-release-build, linux-release-build, macos-release-build]
|
||||
needs: [windows-release-build, linux-release-build, macos-release-build, macos-aarch64-release-build]
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- name: Download build artifacts
|
||||
@@ -127,6 +147,6 @@ jobs:
|
||||
title: "Development Build"
|
||||
files: |
|
||||
lan-mouse-linux/lan-mouse
|
||||
lan-mouse-macos-intel/lan-mouse-macos-intel
|
||||
lan-mouse-macos-aarch64/lan-mouse-macos-aarch64
|
||||
lan-mouse-macos-intel/lan-mouse-macos-intel.zip
|
||||
lan-mouse-macos-aarch64/lan-mouse-macos-aarch64.zip
|
||||
lan-mouse-windows/lan-mouse-windows.zip
|
||||
|
||||
32
.github/workflows/rust.yml
vendored
32
.github/workflows/rust.yml
vendored
@@ -98,7 +98,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install dependencies
|
||||
run: brew install gtk4 libadwaita
|
||||
run: brew install gtk4 libadwaita imagemagick
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
@@ -107,18 +107,28 @@ jobs:
|
||||
run: cargo fmt --check
|
||||
- name: Clippy
|
||||
run: cargo clippy --all-features --all-targets -- --deny warnings
|
||||
- name: Make icns
|
||||
run: scripts/makeicns.sh
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/debug/bundle/osx
|
||||
zip -r "Lan Mouse macOS (Intel).zip" "Lan Mouse.app"
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: lan-mouse-macos
|
||||
path: target/debug/lan-mouse
|
||||
name: Lan Mouse macOS (Intel)
|
||||
path: target/debug/bundle/osx/Lan Mouse macOS (Intel).zip
|
||||
|
||||
build-macos-aarch64:
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install dependencies
|
||||
run: brew install gtk4 libadwaita
|
||||
run: brew install gtk4 libadwaita imagemagick
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
@@ -127,8 +137,18 @@ jobs:
|
||||
run: cargo fmt --check
|
||||
- name: Clippy
|
||||
run: cargo clippy --all-features --all-targets -- --deny warnings
|
||||
- name: Make icns
|
||||
run: scripts/makeicns.sh
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/debug/bundle/osx
|
||||
zip -r "Lan Mouse macOS (ARM).zip" "Lan Mouse.app"
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: lan-mouse-macos-aarch64
|
||||
path: target/debug/lan-mouse
|
||||
name: Lan Mouse macOS (ARM)
|
||||
path: target/debug/bundle/osx/Lan Mouse macOS (ARM).zip
|
||||
|
||||
38
.github/workflows/tagged-release.yml
vendored
38
.github/workflows/tagged-release.yml
vendored
@@ -80,36 +80,56 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install dependencies
|
||||
run: brew install gtk4 libadwaita
|
||||
run: brew install gtk4 libadwaita imagemagick
|
||||
- name: Release Build
|
||||
run: |
|
||||
cargo build --release
|
||||
cp target/release/lan-mouse lan-mouse-macos-intel
|
||||
- name: Make icns
|
||||
run: scripts/makeicns.sh
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle --release
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/release/bundle/osx
|
||||
zip -r "lan-mouse-macos-intel.zip" "Lan Mouse.app"
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: lan-mouse-macos-intel
|
||||
path: lan-mouse-macos-intel
|
||||
name: lan-mouse-macos-intel.zip
|
||||
path: target/release/bundle/osx/lan-mouse-macos-intel.zip
|
||||
|
||||
macos-aarch64-release-build:
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install dependencies
|
||||
run: brew install gtk4 libadwaita
|
||||
run: brew install gtk4 libadwaita imagemagick
|
||||
- name: Release Build
|
||||
run: |
|
||||
cargo build --release
|
||||
cp target/release/lan-mouse lan-mouse-macos-aarch64
|
||||
- name: Make icns
|
||||
run: scripts/makeicns.sh
|
||||
- name: Install cargo bundle
|
||||
run: cargo install cargo-bundle
|
||||
- name: Bundle
|
||||
run: cargo bundle --release
|
||||
- name: Zip bundle
|
||||
run: |
|
||||
cd target/release/bundle/osx
|
||||
zip -r "lan-mouse-macos-aarch64.zip" "Lan Mouse.app"
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: lan-mouse-macos-aarch64
|
||||
path: lan-mouse-macos-aarch64
|
||||
name: lan-mouse-macos-aarch64.zip
|
||||
path: target/release/bundle/osx/lan-mouse-macos-aarch64.zip
|
||||
|
||||
tagged-release:
|
||||
name: "Tagged Release"
|
||||
needs: [windows-release-build, linux-release-build, macos-release-build]
|
||||
needs: [windows-release-build, linux-release-build, macos-release-build, macos-aarch64-release-build]
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- name: Download build artifacts
|
||||
@@ -121,6 +141,6 @@ jobs:
|
||||
prerelease: false
|
||||
files: |
|
||||
lan-mouse-linux/lan-mouse
|
||||
lan-mouse-macos-intel/lan-mouse-macos-intel
|
||||
lan-mouse-macos-aarch64/lan-mouse-macos-aarch64
|
||||
lan-mouse-macos-intel/lan-mouse-macos-intel.zip
|
||||
lan-mouse-macos-aarch64/lan-mouse-macos-aarch64.zip
|
||||
lan-mouse-windows/lan-mouse-windows.zip
|
||||
|
||||
@@ -89,3 +89,8 @@ libei_emulation = ["input-event/libei", "input-emulation/libei"]
|
||||
wlroots_emulation = ["input-emulation/wlroots"]
|
||||
x11_emulation = ["input-emulation/x11"]
|
||||
rdp_emulation = ["input-emulation/remote_desktop_portal"]
|
||||
|
||||
[package.metadata.bundle]
|
||||
name = "Lan Mouse"
|
||||
icon = ["target/icon.icns"]
|
||||
identifier = "de.feschber.LanMouse"
|
||||
|
||||
12
flake.lock
generated
12
flake.lock
generated
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1728018373,
|
||||
"narHash": "sha256-NOiTvBbRLIOe5F6RbHaAh6++BNjsb149fGZd1T4+KBg=",
|
||||
"lastModified": 1740560979,
|
||||
"narHash": "sha256-Vr3Qi346M+8CjedtbyUevIGDZW8LcA1fTG0ugPY/Hic=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "bc947f541ae55e999ffdb4013441347d83b00feb",
|
||||
"rev": "5135c59491985879812717f4c9fea69604e7f26f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -29,11 +29,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1728181869,
|
||||
"narHash": "sha256-sQXHXsjIcGEoIHkB+RO6BZdrPfB+43V1TEpyoWRI3ww=",
|
||||
"lastModified": 1740623427,
|
||||
"narHash": "sha256-3SdPQrZoa4odlScFDUHd4CUPQ/R1gtH4Mq9u8CBiK8M=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "cd46aa3906c14790ef5cbe278d9e54f2c38f95c0",
|
||||
"rev": "d342e8b5fd88421ff982f383c853f0fc78a847ab",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use async_trait::async_trait;
|
||||
use futures_core::Stream;
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
collections::{HashSet, VecDeque},
|
||||
env,
|
||||
fmt::{self, Display},
|
||||
io::{self, ErrorKind},
|
||||
os::fd::{AsFd, RawFd},
|
||||
pin::Pin,
|
||||
@@ -46,13 +47,15 @@ use wayland_protocols_wlr::layer_shell::v1::client::{
|
||||
use wayland_client::{
|
||||
backend::{ReadEventsGuard, WaylandError},
|
||||
delegate_noop,
|
||||
globals::{registry_queue_init, GlobalListContents},
|
||||
globals::{registry_queue_init, Global, GlobalList, GlobalListContents},
|
||||
protocol::{
|
||||
wl_buffer, wl_compositor,
|
||||
wl_keyboard::{self, WlKeyboard},
|
||||
wl_output::{self, WlOutput},
|
||||
wl_pointer::{self, WlPointer},
|
||||
wl_region, wl_registry, wl_seat, wl_shm, wl_shm_pool,
|
||||
wl_region,
|
||||
wl_registry::{self, WlRegistry},
|
||||
wl_seat, wl_shm, wl_shm_pool,
|
||||
wl_surface::WlSurface,
|
||||
},
|
||||
Connection, Dispatch, DispatchError, EventQueue, QueueHandle, WEnum,
|
||||
@@ -75,28 +78,42 @@ struct Globals {
|
||||
seat: wl_seat::WlSeat,
|
||||
shm: wl_shm::WlShm,
|
||||
layer_shell: ZwlrLayerShellV1,
|
||||
outputs: Vec<WlOutput>,
|
||||
xdg_output_manager: ZxdgOutputManagerV1,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
struct Output {
|
||||
wl_output: WlOutput,
|
||||
global: Global,
|
||||
info: Option<OutputInfo>,
|
||||
pending_info: OutputInfo,
|
||||
has_xdg_info: bool,
|
||||
}
|
||||
|
||||
impl Display for Output {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if let Some(info) = &self.info {
|
||||
write!(
|
||||
f,
|
||||
"{} {}x{} @pos {:?} ({})",
|
||||
info.name, info.size.0, info.size.1, info.position, info.description
|
||||
)
|
||||
} else {
|
||||
write!(f, "unknown output")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct OutputInfo {
|
||||
description: String,
|
||||
name: String,
|
||||
position: (i32, i32),
|
||||
size: (i32, i32),
|
||||
}
|
||||
|
||||
impl OutputInfo {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
name: "".to_string(),
|
||||
position: (0, 0),
|
||||
size: (0, 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct State {
|
||||
active_positions: HashSet<Position>,
|
||||
pointer: Option<WlPointer>,
|
||||
keyboard: Option<WlKeyboard>,
|
||||
pointer_lock: Option<ZwpLockedPointerV1>,
|
||||
@@ -104,12 +121,13 @@ struct State {
|
||||
shortcut_inhibitor: Option<ZwpKeyboardShortcutsInhibitorV1>,
|
||||
active_windows: Vec<Arc<Window>>,
|
||||
focused: Option<Arc<Window>>,
|
||||
g: Globals,
|
||||
global_list: GlobalList,
|
||||
globals: Globals,
|
||||
wayland_fd: RawFd,
|
||||
read_guard: Option<ReadEventsGuard>,
|
||||
qh: QueueHandle<Self>,
|
||||
pending_events: VecDeque<(Position, CaptureEvent)>,
|
||||
output_info: Vec<(WlOutput, OutputInfo)>,
|
||||
outputs: Vec<Output>,
|
||||
scroll_discrete_pending: bool,
|
||||
}
|
||||
|
||||
@@ -142,7 +160,7 @@ impl Window {
|
||||
size: (i32, i32),
|
||||
) -> Window {
|
||||
log::debug!("creating window output: {output:?}, size: {size:?}");
|
||||
let g = &state.g;
|
||||
let g = &state.globals;
|
||||
|
||||
let (width, height) = match pos {
|
||||
Position::Left | Position::Right => (1, size.1 as u32),
|
||||
@@ -203,41 +221,36 @@ impl Drop for Window {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_edges(outputs: &[(WlOutput, OutputInfo)], pos: Position) -> Vec<(WlOutput, i32)> {
|
||||
fn get_edges(outputs: &[Output], pos: Position) -> Vec<(Output, i32)> {
|
||||
outputs
|
||||
.iter()
|
||||
.map(|(o, i)| {
|
||||
(
|
||||
o.clone(),
|
||||
match pos {
|
||||
Position::Left => i.position.0,
|
||||
Position::Right => i.position.0 + i.size.0,
|
||||
Position::Top => i.position.1,
|
||||
Position::Bottom => i.position.1 + i.size.1,
|
||||
},
|
||||
)
|
||||
.filter_map(|output| {
|
||||
output.info.as_ref().map(|info| {
|
||||
(
|
||||
output.clone(),
|
||||
match pos {
|
||||
Position::Left => info.position.0,
|
||||
Position::Right => info.position.0 + info.size.0,
|
||||
Position::Top => info.position.1,
|
||||
Position::Bottom => info.position.1 + info.size.1,
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_output_configuration(state: &State, pos: Position) -> Vec<(WlOutput, OutputInfo)> {
|
||||
fn get_output_configuration(state: &State, pos: Position) -> Vec<Output> {
|
||||
// get all output edges corresponding to the position
|
||||
let edges = get_edges(&state.output_info, pos);
|
||||
log::debug!("edges: {edges:?}");
|
||||
let opposite_edges = get_edges(&state.output_info, pos.opposite());
|
||||
let edges = get_edges(&state.outputs, pos);
|
||||
let opposite_edges = get_edges(&state.outputs, pos.opposite());
|
||||
|
||||
// remove those edges that are at the same position
|
||||
// as an opposite edge of a different output
|
||||
let outputs: Vec<WlOutput> = edges
|
||||
edges
|
||||
.iter()
|
||||
.filter(|(_, edge)| !opposite_edges.iter().map(|(_, e)| *e).any(|e| &e == edge))
|
||||
.map(|(o, _)| o.clone())
|
||||
.collect();
|
||||
state
|
||||
.output_info
|
||||
.iter()
|
||||
.filter(|(o, _)| outputs.contains(o))
|
||||
.map(|(o, i)| (o.clone(), i.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -259,36 +272,36 @@ fn draw(f: &mut File, (width, height): (u32, u32)) {
|
||||
impl LayerShellInputCapture {
|
||||
pub fn new() -> std::result::Result<Self, LayerShellCaptureCreationError> {
|
||||
let conn = Connection::connect_to_env()?;
|
||||
let (g, mut queue) = registry_queue_init::<State>(&conn)?;
|
||||
let (global_list, mut queue) = registry_queue_init::<State>(&conn)?;
|
||||
|
||||
let qh = queue.handle();
|
||||
|
||||
let compositor: wl_compositor::WlCompositor = g
|
||||
let compositor: wl_compositor::WlCompositor = global_list
|
||||
.bind(&qh, 4..=5, ())
|
||||
.map_err(|e| WaylandBindError::new(e, "wl_compositor 4..=5"))?;
|
||||
let xdg_output_manager: ZxdgOutputManagerV1 = g
|
||||
let xdg_output_manager: ZxdgOutputManagerV1 = global_list
|
||||
.bind(&qh, 1..=3, ())
|
||||
.map_err(|e| WaylandBindError::new(e, "xdg_output_manager 1..=3"))?;
|
||||
let shm: wl_shm::WlShm = g
|
||||
let shm: wl_shm::WlShm = global_list
|
||||
.bind(&qh, 1..=1, ())
|
||||
.map_err(|e| WaylandBindError::new(e, "wl_shm"))?;
|
||||
let layer_shell: ZwlrLayerShellV1 = g
|
||||
let layer_shell: ZwlrLayerShellV1 = global_list
|
||||
.bind(&qh, 3..=4, ())
|
||||
.map_err(|e| WaylandBindError::new(e, "wlr_layer_shell 3..=4"))?;
|
||||
let seat: wl_seat::WlSeat = g
|
||||
let seat: wl_seat::WlSeat = global_list
|
||||
.bind(&qh, 7..=8, ())
|
||||
.map_err(|e| WaylandBindError::new(e, "wl_seat 7..=8"))?;
|
||||
|
||||
let pointer_constraints: ZwpPointerConstraintsV1 = g
|
||||
let pointer_constraints: ZwpPointerConstraintsV1 = global_list
|
||||
.bind(&qh, 1..=1, ())
|
||||
.map_err(|e| WaylandBindError::new(e, "zwp_pointer_constraints_v1"))?;
|
||||
let relative_pointer_manager: ZwpRelativePointerManagerV1 = g
|
||||
let relative_pointer_manager: ZwpRelativePointerManagerV1 = global_list
|
||||
.bind(&qh, 1..=1, ())
|
||||
.map_err(|e| WaylandBindError::new(e, "zwp_relative_pointer_manager_v1"))?;
|
||||
let shortcut_inhibit_manager: Result<
|
||||
ZwpKeyboardShortcutsInhibitManagerV1,
|
||||
WaylandBindError,
|
||||
> = g
|
||||
> = global_list
|
||||
.bind(&qh, 1..=1, ())
|
||||
.map_err(|e| WaylandBindError::new(e, "zwp_keyboard_shortcuts_inhibit_manager_v1"));
|
||||
// layer-shell backend still works without this protocol so we make it an optional dependency
|
||||
@@ -297,65 +310,41 @@ impl LayerShellInputCapture {
|
||||
to the client");
|
||||
}
|
||||
let shortcut_inhibit_manager = shortcut_inhibit_manager.ok();
|
||||
let outputs = vec![];
|
||||
|
||||
let g = Globals {
|
||||
compositor,
|
||||
shm,
|
||||
layer_shell,
|
||||
seat,
|
||||
pointer_constraints,
|
||||
relative_pointer_manager,
|
||||
shortcut_inhibit_manager,
|
||||
outputs,
|
||||
xdg_output_manager,
|
||||
};
|
||||
|
||||
// flush outgoing events
|
||||
queue.flush()?;
|
||||
|
||||
let wayland_fd = queue.as_fd().as_raw_fd();
|
||||
|
||||
let mut state = State {
|
||||
active_positions: Default::default(),
|
||||
pointer: None,
|
||||
keyboard: None,
|
||||
g,
|
||||
global_list,
|
||||
globals: Globals {
|
||||
compositor,
|
||||
shm,
|
||||
layer_shell,
|
||||
seat,
|
||||
pointer_constraints,
|
||||
relative_pointer_manager,
|
||||
shortcut_inhibit_manager,
|
||||
xdg_output_manager,
|
||||
},
|
||||
pointer_lock: None,
|
||||
rel_pointer: None,
|
||||
shortcut_inhibitor: None,
|
||||
active_windows: Vec::new(),
|
||||
focused: None,
|
||||
qh,
|
||||
wayland_fd,
|
||||
wayland_fd: queue.as_fd().as_raw_fd(),
|
||||
read_guard: None,
|
||||
pending_events: VecDeque::new(),
|
||||
output_info: vec![],
|
||||
outputs: vec![],
|
||||
scroll_discrete_pending: false,
|
||||
};
|
||||
|
||||
// dispatch registry to () again, in order to read all wl_outputs
|
||||
conn.display().get_registry(&state.qh, ());
|
||||
log::debug!("==============> requested registry");
|
||||
|
||||
// roundtrip to read wl_output globals
|
||||
queue.roundtrip(&mut state)?;
|
||||
log::debug!("==============> roundtrip 1 done");
|
||||
|
||||
// read outputs
|
||||
for output in state.g.outputs.iter() {
|
||||
state
|
||||
.g
|
||||
.xdg_output_manager
|
||||
.get_xdg_output(output, &state.qh, output.clone());
|
||||
for global in state.global_list.contents().clone_list() {
|
||||
state.register_global(global);
|
||||
}
|
||||
|
||||
// roundtrip to read xdg_output events
|
||||
queue.roundtrip(&mut state)?;
|
||||
|
||||
log::debug!("==============> roundtrip 2 done");
|
||||
for i in &state.output_info {
|
||||
log::debug!("{:#?}", i.1);
|
||||
}
|
||||
// flush outgoing events
|
||||
queue.flush()?;
|
||||
|
||||
let read_guard = loop {
|
||||
match queue.prepare_read() {
|
||||
@@ -379,6 +368,7 @@ impl LayerShellInputCapture {
|
||||
|
||||
fn delete_client(&mut self, pos: Position) {
|
||||
let inner = self.0.get_mut();
|
||||
inner.state.active_positions.remove(&pos);
|
||||
// remove all windows corresponding to this client
|
||||
while let Some(i) = inner.state.active_windows.iter().position(|w| w.pos == pos) {
|
||||
inner.state.active_windows.remove(i);
|
||||
@@ -388,6 +378,52 @@ impl LayerShellInputCapture {
|
||||
}
|
||||
|
||||
impl State {
|
||||
fn update_output_info(&mut self, name: u32) {
|
||||
let output = self
|
||||
.outputs
|
||||
.iter_mut()
|
||||
.find(|o| o.global.name == name)
|
||||
.expect("output not found");
|
||||
if output.has_xdg_info {
|
||||
output.info.replace(output.pending_info.clone());
|
||||
self.update_windows();
|
||||
}
|
||||
}
|
||||
|
||||
fn register_global(&mut self, global: Global) {
|
||||
if global.interface.as_str() == "wl_output" {
|
||||
log::debug!("new output global: wl_output {}", global.name);
|
||||
let wl_output = self.global_list.registry().bind::<WlOutput, _, _>(
|
||||
global.name,
|
||||
4,
|
||||
&self.qh,
|
||||
global.name,
|
||||
);
|
||||
self.globals
|
||||
.xdg_output_manager
|
||||
.get_xdg_output(&wl_output, &self.qh, global.name);
|
||||
self.outputs.push(Output {
|
||||
wl_output,
|
||||
global,
|
||||
info: None,
|
||||
has_xdg_info: false,
|
||||
pending_info: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn deregister_global(&mut self, name: u32) {
|
||||
self.outputs.retain(|o| {
|
||||
if o.global.name == name {
|
||||
log::debug!("{o} (global {:?}) removed", o.global);
|
||||
o.wl_output.release();
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn grab(
|
||||
&mut self,
|
||||
surface: &WlSurface,
|
||||
@@ -408,7 +444,7 @@ impl State {
|
||||
|
||||
// lock pointer
|
||||
if self.pointer_lock.is_none() {
|
||||
self.pointer_lock = Some(self.g.pointer_constraints.lock_pointer(
|
||||
self.pointer_lock = Some(self.globals.pointer_constraints.lock_pointer(
|
||||
surface,
|
||||
pointer,
|
||||
None,
|
||||
@@ -420,7 +456,7 @@ impl State {
|
||||
|
||||
// request relative input
|
||||
if self.rel_pointer.is_none() {
|
||||
self.rel_pointer = Some(self.g.relative_pointer_manager.get_relative_pointer(
|
||||
self.rel_pointer = Some(self.globals.relative_pointer_manager.get_relative_pointer(
|
||||
pointer,
|
||||
qh,
|
||||
(),
|
||||
@@ -428,10 +464,14 @@ impl State {
|
||||
}
|
||||
|
||||
// capture modifier keys
|
||||
if let Some(shortcut_inhibit_manager) = &self.g.shortcut_inhibit_manager {
|
||||
if let Some(shortcut_inhibit_manager) = &self.globals.shortcut_inhibit_manager {
|
||||
if self.shortcut_inhibitor.is_none() {
|
||||
self.shortcut_inhibitor =
|
||||
Some(shortcut_inhibit_manager.inhibit_shortcuts(surface, &self.g.seat, qh, ()));
|
||||
self.shortcut_inhibitor = Some(shortcut_inhibit_manager.inhibit_shortcuts(
|
||||
surface,
|
||||
&self.globals.seat,
|
||||
qh,
|
||||
(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -469,21 +509,39 @@ impl State {
|
||||
}
|
||||
|
||||
fn add_client(&mut self, pos: Position) {
|
||||
self.active_positions.insert(pos);
|
||||
let outputs = get_output_configuration(self, pos);
|
||||
|
||||
log::debug!("outputs: {outputs:?}");
|
||||
outputs.iter().for_each(|(o, i)| {
|
||||
let window = Window::new(self, &self.qh, o, pos, i.size);
|
||||
let window = Arc::new(window);
|
||||
self.active_windows.push(window);
|
||||
log::info!(
|
||||
"adding capture for position {pos} - using outputs: {:?}",
|
||||
outputs
|
||||
.iter()
|
||||
.map(|o| o
|
||||
.info
|
||||
.as_ref()
|
||||
.map(|i| i.name.to_owned())
|
||||
.unwrap_or("unknown output".to_owned()))
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
outputs.iter().for_each(|o| {
|
||||
if let Some(info) = o.info.as_ref() {
|
||||
let window = Window::new(self, &self.qh, &o.wl_output, pos, info.size);
|
||||
let window = Arc::new(window);
|
||||
self.active_windows.push(window);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn update_windows(&mut self) {
|
||||
log::debug!("updating windows");
|
||||
log::debug!("output info: {:?}", self.output_info);
|
||||
let clients: Vec<_> = self.active_windows.drain(..).map(|w| w.pos).collect();
|
||||
for pos in clients {
|
||||
log::info!("active outputs: ");
|
||||
for output in self.outputs.iter().filter(|o| o.info.is_some()) {
|
||||
log::info!(" * {}", output);
|
||||
}
|
||||
|
||||
self.active_windows.clear();
|
||||
|
||||
let active_positions = self.active_positions.iter().cloned().collect::<Vec<_>>();
|
||||
for pos in active_positions {
|
||||
self.add_client(pos);
|
||||
}
|
||||
}
|
||||
@@ -835,7 +893,7 @@ impl Dispatch<ZwpRelativePointerV1, ()> for State {
|
||||
} = event
|
||||
{
|
||||
if let Some(window) = &app.focused {
|
||||
let time = (((utime_hi as u64) << 32 | utime_lo as u64) / 1000) as u32;
|
||||
let time = ((((utime_hi as u64) << 32) | utime_lo as u64) / 1000) as u32;
|
||||
app.pending_events.push_back((
|
||||
window.pos,
|
||||
CaptureEvent::Input(Event::Pointer(PointerEvent::Motion { time, dx, dy })),
|
||||
@@ -872,94 +930,89 @@ impl Dispatch<ZwlrLayerSurfaceV1, ()> for State {
|
||||
}
|
||||
|
||||
// delegate wl_registry events to App itself
|
||||
impl Dispatch<wl_registry::WlRegistry, GlobalListContents> for State {
|
||||
fn event(
|
||||
_state: &mut Self,
|
||||
_proxy: &wl_registry::WlRegistry,
|
||||
_event: <wl_registry::WlRegistry as wayland_client::Proxy>::Event,
|
||||
_data: &GlobalListContents,
|
||||
_conn: &Connection,
|
||||
_qhandle: &QueueHandle<Self>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<wl_registry::WlRegistry, ()> for State {
|
||||
impl Dispatch<WlRegistry, GlobalListContents> for State {
|
||||
fn event(
|
||||
state: &mut Self,
|
||||
registry: &wl_registry::WlRegistry,
|
||||
event: <wl_registry::WlRegistry as wayland_client::Proxy>::Event,
|
||||
_: &(),
|
||||
_: &Connection,
|
||||
qh: &QueueHandle<Self>,
|
||||
_registry: &WlRegistry,
|
||||
event: <WlRegistry as wayland_client::Proxy>::Event,
|
||||
_data: &GlobalListContents,
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
) {
|
||||
match event {
|
||||
wl_registry::Event::Global {
|
||||
name,
|
||||
interface,
|
||||
version: _,
|
||||
version,
|
||||
} => {
|
||||
if interface.as_str() == "wl_output" {
|
||||
log::debug!("wl_output global");
|
||||
state
|
||||
.g
|
||||
.outputs
|
||||
.push(registry.bind::<WlOutput, _, _>(name, 4, qh, ()))
|
||||
}
|
||||
state.register_global(Global {
|
||||
name,
|
||||
interface,
|
||||
version,
|
||||
});
|
||||
}
|
||||
wl_registry::Event::GlobalRemove { name } => {
|
||||
state.deregister_global(name);
|
||||
}
|
||||
wl_registry::Event::GlobalRemove { .. } => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ZxdgOutputV1, WlOutput> for State {
|
||||
impl Dispatch<ZxdgOutputV1, u32> for State {
|
||||
fn event(
|
||||
state: &mut Self,
|
||||
_: &ZxdgOutputV1,
|
||||
event: <ZxdgOutputV1 as wayland_client::Proxy>::Event,
|
||||
wl_output: &WlOutput,
|
||||
name: &u32,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
) {
|
||||
log::debug!("xdg-output - {event:?}");
|
||||
let output_info = match state.output_info.iter_mut().find(|(o, _)| o == wl_output) {
|
||||
Some((_, c)) => c,
|
||||
None => {
|
||||
let output_info = OutputInfo::new();
|
||||
state.output_info.push((wl_output.clone(), output_info));
|
||||
&mut state.output_info.last_mut().unwrap().1
|
||||
}
|
||||
};
|
||||
let output = state
|
||||
.outputs
|
||||
.iter_mut()
|
||||
.find(|o| o.global.name == *name)
|
||||
.expect("output");
|
||||
|
||||
log::debug!("xdg_output {name} - {:?}", event);
|
||||
match event {
|
||||
zxdg_output_v1::Event::LogicalPosition { x, y } => {
|
||||
output_info.position = (x, y);
|
||||
output.pending_info.position = (x, y);
|
||||
output.has_xdg_info = true;
|
||||
}
|
||||
zxdg_output_v1::Event::LogicalSize { width, height } => {
|
||||
output_info.size = (width, height);
|
||||
output.pending_info.size = (width, height);
|
||||
output.has_xdg_info = true;
|
||||
}
|
||||
zxdg_output_v1::Event::Done => {
|
||||
log::warn!("Use of deprecated xdg-output event \"done\"");
|
||||
state.update_output_info(*name);
|
||||
}
|
||||
zxdg_output_v1::Event::Done => {}
|
||||
zxdg_output_v1::Event::Name { name } => {
|
||||
output_info.name = name;
|
||||
output.pending_info.name = name;
|
||||
output.has_xdg_info = true;
|
||||
}
|
||||
zxdg_output_v1::Event::Description { .. } => {}
|
||||
_ => {}
|
||||
zxdg_output_v1::Event::Description { description } => {
|
||||
output.pending_info.description = description;
|
||||
output.has_xdg_info = true;
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<WlOutput, ()> for State {
|
||||
impl Dispatch<WlOutput, u32> for State {
|
||||
fn event(
|
||||
state: &mut Self,
|
||||
_proxy: &WlOutput,
|
||||
_wl_output: &WlOutput,
|
||||
event: <WlOutput as wayland_client::Proxy>::Event,
|
||||
_data: &(),
|
||||
name: &u32,
|
||||
_conn: &Connection,
|
||||
_qhandle: &QueueHandle<Self>,
|
||||
) {
|
||||
log::debug!("wl_output {name} - {:?}", event);
|
||||
if let wl_output::Event::Done = event {
|
||||
state.update_windows();
|
||||
state.update_output_info(*name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ pub fn run() -> Result<(), IpcError> {
|
||||
|
||||
struct Cli {
|
||||
clients: Vec<(ClientHandle, ClientConfig, ClientState)>,
|
||||
changed: Option<ClientHandle>,
|
||||
rx: AsyncFrontendEventReader,
|
||||
tx: AsyncFrontendRequestWriter,
|
||||
}
|
||||
@@ -39,7 +38,6 @@ impl Cli {
|
||||
fn new(rx: AsyncFrontendEventReader, tx: AsyncFrontendRequestWriter) -> Cli {
|
||||
Self {
|
||||
clients: vec![],
|
||||
changed: None,
|
||||
rx,
|
||||
tx,
|
||||
}
|
||||
@@ -87,23 +85,9 @@ impl Cli {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(handle) = self.changed.take() {
|
||||
self.update_client(handle).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn update_client(&mut self, handle: ClientHandle) -> Result<(), IpcError> {
|
||||
self.tx.request(FrontendRequest::GetState(handle)).await?;
|
||||
while let Some(Ok(event)) = self.rx.next().await {
|
||||
self.handle_event(event.clone());
|
||||
if let FrontendEvent::State(_, _, _) | FrontendEvent::NoSuchClient(_) = event {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn execute(&mut self, cmd: Command) -> Result<(), IpcError> {
|
||||
match cmd {
|
||||
Command::None => {}
|
||||
@@ -131,7 +115,6 @@ impl Cli {
|
||||
] {
|
||||
self.tx.request(request).await?;
|
||||
}
|
||||
self.update_client(handle).await?;
|
||||
}
|
||||
Command::Disconnect(id) => {
|
||||
self.tx.request(FrontendRequest::Delete(id)).await?;
|
||||
@@ -147,13 +130,11 @@ impl Cli {
|
||||
}
|
||||
Command::Activate(id) => {
|
||||
self.tx.request(FrontendRequest::Activate(id, true)).await?;
|
||||
self.update_client(id).await?;
|
||||
}
|
||||
Command::Deactivate(id) => {
|
||||
self.tx
|
||||
.request(FrontendRequest::Activate(id, false))
|
||||
.await?;
|
||||
self.update_client(id).await?;
|
||||
}
|
||||
Command::List => {
|
||||
self.tx.request(FrontendRequest::Enumerate()).await?;
|
||||
@@ -168,12 +149,10 @@ impl Cli {
|
||||
Command::SetHost(handle, host) => {
|
||||
let request = FrontendRequest::UpdateHostname(handle, Some(host.clone()));
|
||||
self.tx.request(request).await?;
|
||||
self.update_client(handle).await?;
|
||||
}
|
||||
Command::SetPort(handle, port) => {
|
||||
let request = FrontendRequest::UpdatePort(handle, port.unwrap_or(DEFAULT_PORT));
|
||||
self.tx.request(request).await?;
|
||||
self.update_client(handle).await?;
|
||||
}
|
||||
Command::Help => {
|
||||
for cmd_type in [
|
||||
@@ -209,7 +188,6 @@ impl Cli {
|
||||
|
||||
fn handle_event(&mut self, event: FrontendEvent) {
|
||||
match event {
|
||||
FrontendEvent::Changed(h) => self.changed = Some(h),
|
||||
FrontendEvent::Created(h, c, s) => {
|
||||
eprint!("client added ({h}): ");
|
||||
print_config(&c);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<!-- enabled -->
|
||||
<child type="prefix">
|
||||
<object class="GtkSwitch" id="enable_switch">
|
||||
<signal name="state_set" handler="handle_client_set_state" swapped="true"/>
|
||||
<property name="valign">center</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="tooltip-text" translatable="yes">enable</property>
|
||||
|
||||
@@ -13,7 +13,7 @@ use super::ClientData;
|
||||
#[properties(wrapper_type = super::ClientObject)]
|
||||
pub struct ClientObject {
|
||||
#[property(name = "handle", get, set, type = ClientHandle, member = handle)]
|
||||
#[property(name = "hostname", get, set, type = String, member = hostname)]
|
||||
#[property(name = "hostname", get, set, type = Option<String>, member = hostname)]
|
||||
#[property(name = "port", get, set, type = u32, member = port, maximum = u16::MAX as u32)]
|
||||
#[property(name = "active", get, set, type = bool, member = active)]
|
||||
#[property(name = "position", get, set, type = String, member = position)]
|
||||
|
||||
@@ -4,7 +4,7 @@ use adw::prelude::*;
|
||||
use adw::subclass::prelude::*;
|
||||
use gtk::glib::{self, Object};
|
||||
|
||||
use lan_mouse_ipc::DEFAULT_PORT;
|
||||
use lan_mouse_ipc::{Position, DEFAULT_PORT};
|
||||
|
||||
use super::ClientObject;
|
||||
|
||||
@@ -15,25 +15,32 @@ glib::wrapper! {
|
||||
}
|
||||
|
||||
impl ClientRow {
|
||||
pub fn new(_client_object: &ClientObject) -> Self {
|
||||
Object::builder().build()
|
||||
pub fn new(client_object: &ClientObject) -> Self {
|
||||
let client_row: Self = Object::builder().build();
|
||||
client_row
|
||||
.imp()
|
||||
.client_object
|
||||
.borrow_mut()
|
||||
.replace(client_object.clone());
|
||||
client_row
|
||||
}
|
||||
|
||||
pub fn bind(&self, client_object: &ClientObject) {
|
||||
let mut bindings = self.imp().bindings.borrow_mut();
|
||||
|
||||
// bind client active to switch state
|
||||
let active_binding = client_object
|
||||
.bind_property("active", &self.imp().enable_switch.get(), "state")
|
||||
.bidirectional()
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
// bind client active to switch position
|
||||
let switch_position_binding = client_object
|
||||
.bind_property("active", &self.imp().enable_switch.get(), "active")
|
||||
.bidirectional()
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
// bind hostname to hostname edit field
|
||||
let hostname_binding = client_object
|
||||
.bind_property("hostname", &self.imp().hostname.get(), "text")
|
||||
.transform_to(|_, v: Option<String>| {
|
||||
@@ -43,72 +50,48 @@ impl ClientRow {
|
||||
Some("".to_string())
|
||||
}
|
||||
})
|
||||
.transform_from(|_, v: String| {
|
||||
if v.as_str().trim() == "" {
|
||||
Some(None)
|
||||
} else {
|
||||
Some(Some(v))
|
||||
}
|
||||
})
|
||||
.bidirectional()
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
// bind hostname to title
|
||||
let title_binding = client_object
|
||||
.bind_property("hostname", self, "title")
|
||||
.transform_to(|_, v: Option<String>| {
|
||||
if let Some(hostname) = v {
|
||||
Some(hostname)
|
||||
} else {
|
||||
Some("<span font_style=\"italic\" font_weight=\"light\" foreground=\"darkgrey\">no hostname!</span>".to_string())
|
||||
}
|
||||
})
|
||||
.transform_to(|_, v: Option<String>| v.or(Some("<span font_style=\"italic\" font_weight=\"light\" foreground=\"darkgrey\">no hostname!</span>".to_string())))
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
// bind port to port edit field
|
||||
let port_binding = client_object
|
||||
.bind_property("port", &self.imp().port.get(), "text")
|
||||
.transform_from(|_, v: String| {
|
||||
if v.is_empty() {
|
||||
Some(DEFAULT_PORT as u32)
|
||||
} else {
|
||||
Some(v.parse::<u16>().unwrap_or(DEFAULT_PORT) as u32)
|
||||
}
|
||||
})
|
||||
.transform_to(|_, v: u32| {
|
||||
if v == 4242 {
|
||||
if v == DEFAULT_PORT as u32 {
|
||||
Some("".to_string())
|
||||
} else {
|
||||
Some(v.to_string())
|
||||
}
|
||||
})
|
||||
.bidirectional()
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
// bind port to subtitle
|
||||
let subtitle_binding = client_object
|
||||
.bind_property("port", self, "subtitle")
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
// bind position to selected position
|
||||
let position_binding = client_object
|
||||
.bind_property("position", &self.imp().position.get(), "selected")
|
||||
.transform_from(|_, v: u32| match v {
|
||||
1 => Some("right"),
|
||||
2 => Some("top"),
|
||||
3 => Some("bottom"),
|
||||
_ => Some("left"),
|
||||
})
|
||||
.transform_to(|_, v: String| match v.as_str() {
|
||||
"right" => Some(1),
|
||||
"right" => Some(1u32),
|
||||
"top" => Some(2u32),
|
||||
"bottom" => Some(3u32),
|
||||
_ => Some(0u32),
|
||||
})
|
||||
.bidirectional()
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
// bind resolving status to spinner visibility
|
||||
let resolve_binding = client_object
|
||||
.bind_property(
|
||||
"resolving",
|
||||
@@ -118,6 +101,7 @@ impl ClientRow {
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
// bind ips to tooltip-text
|
||||
let ip_binding = client_object
|
||||
.bind_property("ips", &self.imp().dns_button.get(), "tooltip-text")
|
||||
.transform_to(|_, ips: Vec<String>| {
|
||||
@@ -146,4 +130,24 @@ impl ClientRow {
|
||||
binding.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_active(&self, active: bool) {
|
||||
self.imp().set_active(active);
|
||||
}
|
||||
|
||||
pub fn set_hostname(&self, hostname: Option<String>) {
|
||||
self.imp().set_hostname(hostname);
|
||||
}
|
||||
|
||||
pub fn set_port(&self, port: u16) {
|
||||
self.imp().set_port(port);
|
||||
}
|
||||
|
||||
pub fn set_position(&self, pos: Position) {
|
||||
self.imp().set_pos(pos);
|
||||
}
|
||||
|
||||
pub fn set_dns_state(&self, resolved: bool) {
|
||||
self.imp().set_dns_state(resolved);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@ use std::cell::RefCell;
|
||||
use adw::subclass::prelude::*;
|
||||
use adw::{prelude::*, ActionRow, ComboRow};
|
||||
use glib::{subclass::InitializingObject, Binding};
|
||||
use gtk::glib::clone;
|
||||
use gtk::glib::subclass::Signal;
|
||||
use gtk::{glib, Button, CompositeTemplate, Switch};
|
||||
use gtk::glib::{clone, SignalHandlerId};
|
||||
use gtk::{glib, Button, CompositeTemplate, Entry, Switch};
|
||||
use lan_mouse_ipc::Position;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use crate::client_object::ClientObject;
|
||||
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
#[template(resource = "/de/feschber/LanMouse/client_row.ui")]
|
||||
pub struct ClientRow {
|
||||
@@ -28,6 +31,11 @@ pub struct ClientRow {
|
||||
#[template_child]
|
||||
pub dns_loading_indicator: TemplateChild<gtk::Spinner>,
|
||||
pub bindings: RefCell<Vec<Binding>>,
|
||||
hostname_change_handler: RefCell<Option<SignalHandlerId>>,
|
||||
port_change_handler: RefCell<Option<SignalHandlerId>>,
|
||||
position_change_handler: RefCell<Option<SignalHandlerId>>,
|
||||
set_state_handler: RefCell<Option<SignalHandlerId>>,
|
||||
pub client_object: RefCell<Option<ClientObject>>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
@@ -59,17 +67,61 @@ impl ObjectImpl for ClientRow {
|
||||
row.handle_client_delete(button);
|
||||
}
|
||||
));
|
||||
let handler = self.hostname.connect_changed(clone!(
|
||||
#[weak(rename_to = row)]
|
||||
self,
|
||||
move |entry| {
|
||||
row.handle_hostname_changed(entry);
|
||||
}
|
||||
));
|
||||
self.hostname_change_handler.replace(Some(handler));
|
||||
let handler = self.port.connect_changed(clone!(
|
||||
#[weak(rename_to = row)]
|
||||
self,
|
||||
move |entry| {
|
||||
row.handle_port_changed(entry);
|
||||
}
|
||||
));
|
||||
self.port_change_handler.replace(Some(handler));
|
||||
let handler = self.position.connect_selected_notify(clone!(
|
||||
#[weak(rename_to = row)]
|
||||
self,
|
||||
move |position| {
|
||||
row.handle_position_changed(position);
|
||||
}
|
||||
));
|
||||
self.position_change_handler.replace(Some(handler));
|
||||
let handler = self.enable_switch.connect_state_set(clone!(
|
||||
#[weak(rename_to = row)]
|
||||
self,
|
||||
#[upgrade_or]
|
||||
glib::Propagation::Proceed,
|
||||
move |switch, state| {
|
||||
row.handle_activate_switch(state, switch);
|
||||
glib::Propagation::Proceed
|
||||
}
|
||||
));
|
||||
self.set_state_handler.replace(Some(handler));
|
||||
}
|
||||
|
||||
fn signals() -> &'static [glib::subclass::Signal] {
|
||||
static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new();
|
||||
SIGNALS.get_or_init(|| {
|
||||
vec![
|
||||
Signal::builder("request-dns").build(),
|
||||
Signal::builder("request-update")
|
||||
Signal::builder("request-activate")
|
||||
.param_types([bool::static_type()])
|
||||
.build(),
|
||||
Signal::builder("request-delete").build(),
|
||||
Signal::builder("request-dns").build(),
|
||||
Signal::builder("request-hostname-change")
|
||||
.param_types([String::static_type()])
|
||||
.build(),
|
||||
Signal::builder("request-port-change")
|
||||
.param_types([u32::static_type()])
|
||||
.build(),
|
||||
Signal::builder("request-position-change")
|
||||
.param_types([u32::static_type()])
|
||||
.build(),
|
||||
]
|
||||
})
|
||||
}
|
||||
@@ -78,22 +130,97 @@ impl ObjectImpl for ClientRow {
|
||||
#[gtk::template_callbacks]
|
||||
impl ClientRow {
|
||||
#[template_callback]
|
||||
fn handle_client_set_state(&self, state: bool, _switch: &Switch) -> bool {
|
||||
log::debug!("state change -> requesting update");
|
||||
self.obj().emit_by_name::<()>("request-update", &[&state]);
|
||||
fn handle_activate_switch(&self, state: bool, _switch: &Switch) -> bool {
|
||||
self.obj().emit_by_name::<()>("request-activate", &[&state]);
|
||||
true // dont run default handler
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn handle_request_dns(&self, _: Button) {
|
||||
fn handle_request_dns(&self, _: &Button) {
|
||||
self.obj().emit_by_name::<()>("request-dns", &[]);
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn handle_client_delete(&self, _button: &Button) {
|
||||
log::debug!("delete button pressed -> requesting delete");
|
||||
self.obj().emit_by_name::<()>("request-delete", &[]);
|
||||
}
|
||||
|
||||
fn handle_port_changed(&self, port_entry: &Entry) {
|
||||
if let Ok(port) = port_entry.text().parse::<u16>() {
|
||||
self.obj()
|
||||
.emit_by_name::<()>("request-port-change", &[&(port as u32)]);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_hostname_changed(&self, hostname_entry: &Entry) {
|
||||
self.obj()
|
||||
.emit_by_name::<()>("request-hostname-change", &[&hostname_entry.text()]);
|
||||
}
|
||||
|
||||
fn handle_position_changed(&self, position: &ComboRow) {
|
||||
self.obj()
|
||||
.emit_by_name("request-position-change", &[&position.selected()])
|
||||
}
|
||||
|
||||
pub(super) fn set_hostname(&self, hostname: Option<String>) {
|
||||
let position = self.hostname.position();
|
||||
let handler = self.hostname_change_handler.borrow();
|
||||
let handler = handler.as_ref().expect("signal handler");
|
||||
self.hostname.block_signal(handler);
|
||||
self.client_object
|
||||
.borrow_mut()
|
||||
.as_mut()
|
||||
.expect("client object")
|
||||
.set_property("hostname", hostname);
|
||||
self.hostname.unblock_signal(handler);
|
||||
self.hostname.set_position(position);
|
||||
}
|
||||
|
||||
pub(super) fn set_port(&self, port: u16) {
|
||||
let position = self.port.position();
|
||||
let handler = self.port_change_handler.borrow();
|
||||
let handler = handler.as_ref().expect("signal handler");
|
||||
self.port.block_signal(handler);
|
||||
self.client_object
|
||||
.borrow_mut()
|
||||
.as_mut()
|
||||
.expect("client object")
|
||||
.set_port(port as u32);
|
||||
self.port.unblock_signal(handler);
|
||||
self.port.set_position(position);
|
||||
}
|
||||
|
||||
pub(super) fn set_pos(&self, pos: Position) {
|
||||
let handler = self.position_change_handler.borrow();
|
||||
let handler = handler.as_ref().expect("signal handler");
|
||||
self.position.block_signal(handler);
|
||||
self.client_object
|
||||
.borrow_mut()
|
||||
.as_mut()
|
||||
.expect("client object")
|
||||
.set_position(pos.to_string());
|
||||
self.position.unblock_signal(handler);
|
||||
}
|
||||
|
||||
pub(super) fn set_active(&self, active: bool) {
|
||||
let handler = self.set_state_handler.borrow();
|
||||
let handler = handler.as_ref().expect("signal handler");
|
||||
self.enable_switch.block_signal(handler);
|
||||
self.client_object
|
||||
.borrow_mut()
|
||||
.as_mut()
|
||||
.expect("client object")
|
||||
.set_active(active);
|
||||
self.enable_switch.unblock_signal(handler);
|
||||
}
|
||||
|
||||
pub(super) fn set_dns_state(&self, resolved: bool) {
|
||||
if resolved {
|
||||
self.dns_button.set_css_classes(&["success"])
|
||||
} else {
|
||||
self.dns_button.set_css_classes(&["warning"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for ClientRow {}
|
||||
|
||||
@@ -9,12 +9,10 @@ use std::{env, process, str};
|
||||
|
||||
use window::Window;
|
||||
|
||||
use lan_mouse_ipc::{FrontendEvent, FrontendRequest};
|
||||
use lan_mouse_ipc::FrontendEvent;
|
||||
|
||||
use adw::Application;
|
||||
use gtk::{
|
||||
gdk::Display, glib::clone, prelude::*, subclass::prelude::ObjectSubclassIsExt, IconTheme,
|
||||
};
|
||||
use gtk::{gdk::Display, glib::clone, prelude::*, IconTheme};
|
||||
use gtk::{gio, glib, prelude::ApplicationExt};
|
||||
|
||||
use self::client_object::ClientObject;
|
||||
@@ -49,7 +47,11 @@ fn gtk_main() -> glib::ExitCode {
|
||||
.application_id("de.feschber.LanMouse")
|
||||
.build();
|
||||
|
||||
app.connect_startup(|_| load_icons());
|
||||
app.connect_startup(|app| {
|
||||
load_icons();
|
||||
setup_actions(app);
|
||||
setup_menu(app);
|
||||
});
|
||||
app.connect_activate(build_ui);
|
||||
|
||||
let args: Vec<&'static str> = vec![];
|
||||
@@ -62,6 +64,33 @@ fn load_icons() {
|
||||
icon_theme.add_resource_path("/de/feschber/LanMouse/icons");
|
||||
}
|
||||
|
||||
// Add application actions
|
||||
fn setup_actions(app: &adw::Application) {
|
||||
// Quit action
|
||||
// This is important on macOS, where users expect a File->Quit action with a Cmd+Q shortcut.
|
||||
let quit_action = gio::SimpleAction::new("quit", None);
|
||||
quit_action.connect_activate({
|
||||
let app = app.clone();
|
||||
move |_, _| {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
app.add_action(&quit_action);
|
||||
}
|
||||
|
||||
// Set up a global menu
|
||||
//
|
||||
// Currently this is used only on macOS
|
||||
fn setup_menu(app: &adw::Application) {
|
||||
let menu = gio::Menu::new();
|
||||
|
||||
let file_menu = gio::Menu::new();
|
||||
file_menu.append(Some("Quit"), Some("app.quit"));
|
||||
menu.append_submenu(Some("_File"), &file_menu);
|
||||
|
||||
app.set_menubar(Some(&menu))
|
||||
}
|
||||
|
||||
fn build_ui(app: &Application) {
|
||||
log::debug!("connecting to lan-mouse-socket");
|
||||
let (mut frontend_rx, frontend_tx) = match lan_mouse_ipc::connect() {
|
||||
@@ -96,54 +125,28 @@ fn build_ui(app: &Application) {
|
||||
loop {
|
||||
let notify = receiver.recv().await.unwrap_or_else(|_| process::exit(1));
|
||||
match notify {
|
||||
FrontendEvent::Changed(handle) => {
|
||||
window.request(FrontendRequest::GetState(handle));
|
||||
}
|
||||
FrontendEvent::Created(handle, client, state) => {
|
||||
window.new_client(handle, client, state);
|
||||
}
|
||||
FrontendEvent::Deleted(client) => {
|
||||
window.delete_client(client);
|
||||
window.new_client(handle, client, state)
|
||||
}
|
||||
FrontendEvent::Deleted(client) => window.delete_client(client),
|
||||
FrontendEvent::State(handle, config, state) => {
|
||||
window.update_client_config(handle, config);
|
||||
window.update_client_state(handle, state);
|
||||
}
|
||||
FrontendEvent::NoSuchClient(_) => {}
|
||||
FrontendEvent::Error(e) => {
|
||||
window.show_toast(e.as_str());
|
||||
FrontendEvent::Error(e) => window.show_toast(e.as_str()),
|
||||
FrontendEvent::Enumerate(clients) => window.update_client_list(clients),
|
||||
FrontendEvent::PortChanged(port, msg) => window.update_port(port, msg),
|
||||
FrontendEvent::CaptureStatus(s) => window.set_capture(s.into()),
|
||||
FrontendEvent::EmulationStatus(s) => window.set_emulation(s.into()),
|
||||
FrontendEvent::AuthorizedUpdated(keys) => window.set_authorized_keys(keys),
|
||||
FrontendEvent::PublicKeyFingerprint(fp) => window.set_pk_fp(&fp),
|
||||
FrontendEvent::IncomingConnected(_fingerprint, addr, pos) => {
|
||||
window.show_toast(format!("device connected: {addr} ({pos})").as_str());
|
||||
}
|
||||
FrontendEvent::Enumerate(clients) => {
|
||||
for (handle, client, state) in clients {
|
||||
if window.client_idx(handle).is_some() {
|
||||
window.update_client_config(handle, client);
|
||||
window.update_client_state(handle, state);
|
||||
} else {
|
||||
window.new_client(handle, client, state);
|
||||
}
|
||||
}
|
||||
FrontendEvent::IncomingDisconnected(addr) => {
|
||||
window.show_toast(format!("{addr} disconnected").as_str());
|
||||
}
|
||||
FrontendEvent::PortChanged(port, msg) => {
|
||||
match msg {
|
||||
None => window.show_toast(format!("port changed: {port}").as_str()),
|
||||
Some(msg) => window.show_toast(msg.as_str()),
|
||||
}
|
||||
window.imp().set_port(port);
|
||||
}
|
||||
FrontendEvent::CaptureStatus(s) => {
|
||||
window.set_capture(s.into());
|
||||
}
|
||||
FrontendEvent::EmulationStatus(s) => {
|
||||
window.set_emulation(s.into());
|
||||
}
|
||||
FrontendEvent::AuthorizedUpdated(keys) => {
|
||||
window.set_authorized_keys(keys);
|
||||
}
|
||||
FrontendEvent::PublicKeyFingerprint(fp) => {
|
||||
window.set_pk_fp(&fp);
|
||||
}
|
||||
FrontendEvent::IncomingConnected(..) => {}
|
||||
FrontendEvent::IncomingDisconnected(..) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use glib::{clone, Object};
|
||||
use gtk::{
|
||||
gio,
|
||||
glib::{self, closure_local},
|
||||
ListBox, NoSelection,
|
||||
NoSelection,
|
||||
};
|
||||
|
||||
use lan_mouse_ipc::{
|
||||
@@ -28,7 +28,7 @@ glib::wrapper! {
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub(crate) fn new(app: &adw::Application, conn: FrontendRequestWriter) -> Self {
|
||||
pub(super) fn new(app: &adw::Application, conn: FrontendRequestWriter) -> Self {
|
||||
let window: Self = Object::builder().property("application", app).build();
|
||||
window
|
||||
.imp()
|
||||
@@ -38,7 +38,7 @@ impl Window {
|
||||
window
|
||||
}
|
||||
|
||||
pub fn clients(&self) -> gio::ListStore {
|
||||
fn clients(&self) -> gio::ListStore {
|
||||
self.imp()
|
||||
.clients
|
||||
.borrow()
|
||||
@@ -46,7 +46,7 @@ impl Window {
|
||||
.expect("Could not get clients")
|
||||
}
|
||||
|
||||
pub fn authorized(&self) -> gio::ListStore {
|
||||
fn authorized(&self) -> gio::ListStore {
|
||||
self.imp()
|
||||
.authorized
|
||||
.borrow()
|
||||
@@ -62,6 +62,14 @@ impl Window {
|
||||
self.authorized().item(idx).map(|o| o.downcast().unwrap())
|
||||
}
|
||||
|
||||
fn row_by_idx(&self, idx: i32) -> Option<ClientRow> {
|
||||
self.imp()
|
||||
.client_list
|
||||
.get()
|
||||
.row_at_index(idx)
|
||||
.map(|o| o.downcast().expect("expected ClientRow"))
|
||||
}
|
||||
|
||||
fn setup_authorized(&self) {
|
||||
let store = gio::ListStore::new::<KeyObject>();
|
||||
self.imp().authorized.replace(Some(store));
|
||||
@@ -112,16 +120,57 @@ impl Window {
|
||||
.expect("Expected object of type `ClientObject`.");
|
||||
let row = window.create_client_row(client_object);
|
||||
row.connect_closure(
|
||||
"request-update",
|
||||
"request-hostname-change",
|
||||
false,
|
||||
closure_local!(
|
||||
#[strong]
|
||||
window,
|
||||
move |row: ClientRow, hostname: String| {
|
||||
log::info!("request-hostname-change");
|
||||
if let Some(client) = window.client_by_idx(row.index() as u32) {
|
||||
let hostname = Some(hostname).filter(|s| !s.is_empty());
|
||||
/* changed in response to FrontendEvent
|
||||
* -> do not request additional update */
|
||||
window.request(FrontendRequest::UpdateHostname(
|
||||
client.handle(),
|
||||
hostname,
|
||||
));
|
||||
}
|
||||
}
|
||||
),
|
||||
);
|
||||
row.connect_closure(
|
||||
"request-port-change",
|
||||
false,
|
||||
closure_local!(
|
||||
#[strong]
|
||||
window,
|
||||
move |row: ClientRow, port: u32| {
|
||||
if let Some(client) = window.client_by_idx(row.index() as u32) {
|
||||
window.request(FrontendRequest::UpdatePort(
|
||||
client.handle(),
|
||||
port as u16,
|
||||
));
|
||||
}
|
||||
}
|
||||
),
|
||||
);
|
||||
row.connect_closure(
|
||||
"request-activate",
|
||||
false,
|
||||
closure_local!(
|
||||
#[strong]
|
||||
window,
|
||||
move |row: ClientRow, active: bool| {
|
||||
if let Some(client) = window.client_by_idx(row.index() as u32) {
|
||||
window.request_client_activate(&client, active);
|
||||
window.request_client_update(&client);
|
||||
window.request_client_state(&client);
|
||||
log::info!(
|
||||
"request: {} client",
|
||||
if active { "activating" } else { "deactivating" }
|
||||
);
|
||||
window.request(FrontendRequest::Activate(
|
||||
client.handle(),
|
||||
active,
|
||||
));
|
||||
}
|
||||
}
|
||||
),
|
||||
@@ -134,7 +183,7 @@ impl Window {
|
||||
window,
|
||||
move |row: ClientRow| {
|
||||
if let Some(client) = window.client_by_idx(row.index() as u32) {
|
||||
window.request_client_delete(&client);
|
||||
window.request(FrontendRequest::Delete(client.handle()));
|
||||
}
|
||||
}
|
||||
),
|
||||
@@ -147,9 +196,31 @@ impl Window {
|
||||
window,
|
||||
move |row: ClientRow| {
|
||||
if let Some(client) = window.client_by_idx(row.index() as u32) {
|
||||
window.request_client_update(&client);
|
||||
window.request_dns(&client);
|
||||
window.request_client_state(&client);
|
||||
window.request(FrontendRequest::ResolveDns(
|
||||
client.get_data().handle,
|
||||
));
|
||||
}
|
||||
}
|
||||
),
|
||||
);
|
||||
row.connect_closure(
|
||||
"request-position-change",
|
||||
false,
|
||||
closure_local!(
|
||||
#[strong]
|
||||
window,
|
||||
move |row: ClientRow, pos_idx: u32| {
|
||||
if let Some(client) = window.client_by_idx(row.index() as u32) {
|
||||
let position = match pos_idx {
|
||||
0 => Position::Left,
|
||||
1 => Position::Right,
|
||||
2 => Position::Top,
|
||||
_ => Position::Bottom,
|
||||
};
|
||||
window.request(FrontendRequest::UpdatePosition(
|
||||
client.handle(),
|
||||
position,
|
||||
));
|
||||
}
|
||||
}
|
||||
),
|
||||
@@ -160,10 +231,14 @@ impl Window {
|
||||
);
|
||||
}
|
||||
|
||||
fn setup_icon(&self) {
|
||||
self.set_icon_name(Some("de.feschber.LanMouse"));
|
||||
}
|
||||
|
||||
/// workaround for a bug in libadwaita that shows an ugly line beneath
|
||||
/// the last element if a placeholder is set.
|
||||
/// https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/6308
|
||||
pub fn update_placeholder_visibility(&self) {
|
||||
fn update_placeholder_visibility(&self) {
|
||||
let visible = self.clients().n_items() == 0;
|
||||
let placeholder = self.imp().client_placeholder.get();
|
||||
self.imp().client_list.set_placeholder(match visible {
|
||||
@@ -172,7 +247,7 @@ impl Window {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn update_auth_placeholder_visibility(&self) {
|
||||
fn update_auth_placeholder_visibility(&self) {
|
||||
let visible = self.authorized().n_items() == 0;
|
||||
let placeholder = self.imp().authorized_placeholder.get();
|
||||
self.imp().authorized_list.set_placeholder(match visible {
|
||||
@@ -181,10 +256,6 @@ impl Window {
|
||||
});
|
||||
}
|
||||
|
||||
fn setup_icon(&self) {
|
||||
self.set_icon_name(Some("de.feschber.LanMouse"));
|
||||
}
|
||||
|
||||
fn create_client_row(&self, client_object: &ClientObject) -> ClientRow {
|
||||
let row = ClientRow::new(client_object);
|
||||
row.bind(client_object);
|
||||
@@ -197,24 +268,46 @@ impl Window {
|
||||
row
|
||||
}
|
||||
|
||||
pub fn new_client(&self, handle: ClientHandle, client: ClientConfig, state: ClientState) {
|
||||
pub(super) fn new_client(
|
||||
&self,
|
||||
handle: ClientHandle,
|
||||
client: ClientConfig,
|
||||
state: ClientState,
|
||||
) {
|
||||
let client = ClientObject::new(handle, client, state.clone());
|
||||
self.clients().append(&client);
|
||||
self.update_placeholder_visibility();
|
||||
self.update_dns_state(handle, !state.ips.is_empty());
|
||||
}
|
||||
|
||||
pub fn client_idx(&self, handle: ClientHandle) -> Option<usize> {
|
||||
self.clients().iter::<ClientObject>().position(|c| {
|
||||
if let Ok(c) = c {
|
||||
c.handle() == handle
|
||||
pub(super) fn update_client_list(
|
||||
&self,
|
||||
clients: Vec<(ClientHandle, ClientConfig, ClientState)>,
|
||||
) {
|
||||
for (handle, client, state) in clients {
|
||||
if self.client_idx(handle).is_some() {
|
||||
self.update_client_config(handle, client);
|
||||
self.update_client_state(handle, state);
|
||||
} else {
|
||||
false
|
||||
self.new_client(handle, client, state);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete_client(&self, handle: ClientHandle) {
|
||||
pub(super) fn update_port(&self, port: u16, msg: Option<String>) {
|
||||
if let Some(msg) = msg {
|
||||
self.show_toast(msg.as_str());
|
||||
}
|
||||
self.imp().set_port(port);
|
||||
}
|
||||
|
||||
fn client_idx(&self, handle: ClientHandle) -> Option<usize> {
|
||||
self.clients()
|
||||
.iter::<ClientObject>()
|
||||
.position(|c| c.ok().map(|c| c.handle() == handle).unwrap_or_default())
|
||||
}
|
||||
|
||||
pub(super) fn delete_client(&self, handle: ClientHandle) {
|
||||
let Some(idx) = self.client_idx(handle) else {
|
||||
log::warn!("could not find client with handle {handle}");
|
||||
return;
|
||||
@@ -226,46 +319,31 @@ impl Window {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_client_config(&self, handle: ClientHandle, client: ClientConfig) {
|
||||
let Some(idx) = self.client_idx(handle) else {
|
||||
log::warn!("could not find client with handle {}", handle);
|
||||
pub(super) fn update_client_config(&self, handle: ClientHandle, client: ClientConfig) {
|
||||
let Some(row) = self.row_for_handle(handle) else {
|
||||
log::warn!("could not find row for handle {}", handle);
|
||||
return;
|
||||
};
|
||||
let client_object = self.clients().item(idx as u32).unwrap();
|
||||
let client_object: &ClientObject = client_object.downcast_ref().unwrap();
|
||||
let data = client_object.get_data();
|
||||
|
||||
/* only change if it actually has changed, otherwise
|
||||
* the update signal is triggered */
|
||||
if data.hostname != client.hostname {
|
||||
client_object.set_hostname(client.hostname.unwrap_or("".into()));
|
||||
}
|
||||
if data.port != client.port as u32 {
|
||||
client_object.set_port(client.port as u32);
|
||||
}
|
||||
if data.position != client.pos.to_string() {
|
||||
client_object.set_position(client.pos.to_string());
|
||||
}
|
||||
row.set_hostname(client.hostname);
|
||||
row.set_port(client.port);
|
||||
row.set_position(client.pos);
|
||||
}
|
||||
|
||||
pub fn update_client_state(&self, handle: ClientHandle, state: ClientState) {
|
||||
let Some(idx) = self.client_idx(handle) else {
|
||||
log::warn!("could not find client with handle {}", handle);
|
||||
pub(super) fn update_client_state(&self, handle: ClientHandle, state: ClientState) {
|
||||
let Some(row) = self.row_for_handle(handle) else {
|
||||
log::warn!("could not find row for handle {}", handle);
|
||||
return;
|
||||
};
|
||||
let Some(client_object) = self.client_object_for_handle(handle) else {
|
||||
log::warn!("could not find row for handle {}", handle);
|
||||
return;
|
||||
};
|
||||
let client_object = self.clients().item(idx as u32).unwrap();
|
||||
let client_object: &ClientObject = client_object.downcast_ref().unwrap();
|
||||
let data = client_object.get_data();
|
||||
|
||||
if state.active != data.active {
|
||||
client_object.set_active(state.active);
|
||||
log::debug!("set active to {}", state.active);
|
||||
}
|
||||
/* activation state */
|
||||
row.set_active(state.active);
|
||||
|
||||
if state.resolving != data.resolving {
|
||||
client_object.set_resolving(state.resolving);
|
||||
log::debug!("resolving {}: {}", data.handle, state.resolving);
|
||||
}
|
||||
/* dns state */
|
||||
client_object.set_resolving(state.resolving);
|
||||
|
||||
self.update_dns_state(handle, !state.ips.is_empty());
|
||||
let ips = state
|
||||
@@ -276,22 +354,23 @@ impl Window {
|
||||
client_object.set_ips(ips);
|
||||
}
|
||||
|
||||
pub fn update_dns_state(&self, handle: ClientHandle, resolved: bool) {
|
||||
let Some(idx) = self.client_idx(handle) else {
|
||||
log::warn!("could not find client with handle {}", handle);
|
||||
return;
|
||||
};
|
||||
let list_box: ListBox = self.imp().client_list.get();
|
||||
let row = list_box.row_at_index(idx as i32).unwrap();
|
||||
let client_row: ClientRow = row.downcast().expect("expected ClientRow Object");
|
||||
if resolved {
|
||||
client_row.imp().dns_button.set_css_classes(&["success"])
|
||||
} else {
|
||||
client_row.imp().dns_button.set_css_classes(&["warning"])
|
||||
fn client_object_for_handle(&self, handle: ClientHandle) -> Option<ClientObject> {
|
||||
self.client_idx(handle)
|
||||
.and_then(|i| self.client_by_idx(i as u32))
|
||||
}
|
||||
|
||||
fn row_for_handle(&self, handle: ClientHandle) -> Option<ClientRow> {
|
||||
self.client_idx(handle)
|
||||
.and_then(|i| self.row_by_idx(i as i32))
|
||||
}
|
||||
|
||||
fn update_dns_state(&self, handle: ClientHandle, resolved: bool) {
|
||||
if let Some(client_row) = self.row_for_handle(handle) {
|
||||
client_row.set_dns_state(resolved);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request_port_change(&self) {
|
||||
fn request_port_change(&self) {
|
||||
let port = self
|
||||
.imp()
|
||||
.port_entry
|
||||
@@ -303,55 +382,19 @@ impl Window {
|
||||
self.request(FrontendRequest::ChangePort(port));
|
||||
}
|
||||
|
||||
pub fn request_capture(&self) {
|
||||
fn request_capture(&self) {
|
||||
self.request(FrontendRequest::EnableCapture);
|
||||
}
|
||||
|
||||
pub fn request_emulation(&self) {
|
||||
fn request_emulation(&self) {
|
||||
self.request(FrontendRequest::EnableEmulation);
|
||||
}
|
||||
|
||||
pub fn request_client_state(&self, client: &ClientObject) {
|
||||
self.request_client_state_for(client.handle());
|
||||
}
|
||||
|
||||
pub fn request_client_state_for(&self, handle: ClientHandle) {
|
||||
self.request(FrontendRequest::GetState(handle));
|
||||
}
|
||||
|
||||
pub fn request_client_create(&self) {
|
||||
fn request_client_create(&self) {
|
||||
self.request(FrontendRequest::Create);
|
||||
}
|
||||
|
||||
pub fn request_dns(&self, client: &ClientObject) {
|
||||
self.request(FrontendRequest::ResolveDns(client.get_data().handle));
|
||||
}
|
||||
|
||||
pub fn request_client_update(&self, client: &ClientObject) {
|
||||
let handle = client.handle();
|
||||
let data = client.get_data();
|
||||
let position = Position::try_from(data.position.as_str()).expect("invalid position");
|
||||
let hostname = data.hostname;
|
||||
let port = data.port as u16;
|
||||
|
||||
for event in [
|
||||
FrontendRequest::UpdateHostname(handle, hostname),
|
||||
FrontendRequest::UpdatePosition(handle, position),
|
||||
FrontendRequest::UpdatePort(handle, port),
|
||||
] {
|
||||
self.request(event);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request_client_activate(&self, client: &ClientObject, active: bool) {
|
||||
self.request(FrontendRequest::Activate(client.handle(), active));
|
||||
}
|
||||
|
||||
pub fn request_client_delete(&self, client: &ClientObject) {
|
||||
self.request(FrontendRequest::Delete(client.handle()));
|
||||
}
|
||||
|
||||
pub fn open_fingerprint_dialog(&self) {
|
||||
fn open_fingerprint_dialog(&self) {
|
||||
let window = FingerprintWindow::new();
|
||||
window.set_transient_for(Some(self));
|
||||
window.connect_closure(
|
||||
@@ -369,15 +412,15 @@ impl Window {
|
||||
window.present();
|
||||
}
|
||||
|
||||
pub fn request_fingerprint_add(&self, desc: String, fp: String) {
|
||||
fn request_fingerprint_add(&self, desc: String, fp: String) {
|
||||
self.request(FrontendRequest::AuthorizeKey(desc, fp));
|
||||
}
|
||||
|
||||
pub fn request_fingerprint_remove(&self, fp: String) {
|
||||
fn request_fingerprint_remove(&self, fp: String) {
|
||||
self.request(FrontendRequest::RemoveAuthorizedKey(fp));
|
||||
}
|
||||
|
||||
pub fn request(&self, request: FrontendRequest) {
|
||||
fn request(&self, request: FrontendRequest) {
|
||||
let mut requester = self.imp().frontend_request_writer.borrow_mut();
|
||||
let requester = requester.as_mut().unwrap();
|
||||
if let Err(e) = requester.request(request) {
|
||||
@@ -385,18 +428,18 @@ impl Window {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn show_toast(&self, msg: &str) {
|
||||
pub(super) fn show_toast(&self, msg: &str) {
|
||||
let toast = adw::Toast::new(msg);
|
||||
let toast_overlay = &self.imp().toast_overlay;
|
||||
toast_overlay.add_toast(toast);
|
||||
}
|
||||
|
||||
pub fn set_capture(&self, active: bool) {
|
||||
pub(super) fn set_capture(&self, active: bool) {
|
||||
self.imp().capture_active.replace(active);
|
||||
self.update_capture_emulation_status();
|
||||
}
|
||||
|
||||
pub fn set_emulation(&self, active: bool) {
|
||||
pub(super) fn set_emulation(&self, active: bool) {
|
||||
self.imp().emulation_active.replace(active);
|
||||
self.update_capture_emulation_status();
|
||||
}
|
||||
@@ -411,7 +454,7 @@ impl Window {
|
||||
.set_visible(!capture || !emulation);
|
||||
}
|
||||
|
||||
pub(crate) fn set_authorized_keys(&self, fingerprints: HashMap<String, String>) {
|
||||
pub(super) fn set_authorized_keys(&self, fingerprints: HashMap<String, String>) {
|
||||
let authorized = self.authorized();
|
||||
// clear list
|
||||
authorized.remove_all();
|
||||
@@ -423,7 +466,7 @@ impl Window {
|
||||
self.update_auth_placeholder_visibility();
|
||||
}
|
||||
|
||||
pub(crate) fn set_pk_fp(&self, fingerprint: &str) {
|
||||
pub(super) fn set_pk_fp(&self, fingerprint: &str) {
|
||||
self.imp().fingerprint_row.set_subtitle(fingerprint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,8 +177,6 @@ pub struct ClientState {
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum FrontendEvent {
|
||||
/// client state has changed, new state must be requested via [`FrontendRequest::GetState`]
|
||||
Changed(ClientHandle),
|
||||
/// a client was created
|
||||
Created(ClientHandle, ClientConfig, ClientState),
|
||||
/// no such client
|
||||
@@ -229,8 +227,6 @@ pub enum FrontendRequest {
|
||||
UpdatePosition(ClientHandle, Position),
|
||||
/// update fix-ips
|
||||
UpdateFixIps(ClientHandle, Vec<IpAddr>),
|
||||
/// request the state of the given client
|
||||
GetState(ClientHandle),
|
||||
/// request reenabling input capture
|
||||
EnableCapture,
|
||||
/// request reenabling input emulation
|
||||
|
||||
42
scripts/makeicns.sh
Executable file
42
scripts/makeicns.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
$0: Make a macOS icns file from an SVG with ImageMagick and iconutil.
|
||||
usage: $0 [SVG [ICNS [ICONSET]]
|
||||
|
||||
ARGUMENTS
|
||||
SVG The SVG file to convert
|
||||
Defaults to ./lan-mouse-gtk/resources/de.feschber.LanMouse.svg
|
||||
ICNS The icns file to create
|
||||
Defaults to ./target/icon.icns
|
||||
ICONSET The iconset directory to create
|
||||
Defaults to ./target/icon.iconset
|
||||
This is just a temporary directory
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
svg="${1:-./lan-mouse-gtk/resources/de.feschber.LanMouse.svg}"
|
||||
icns="${2:-./target/icon.icns}"
|
||||
iconset="${3:-./target/icon.iconset}"
|
||||
|
||||
set -u
|
||||
|
||||
mkdir -p "$iconset"
|
||||
magick convert -background none -resize 1024x1024 "$svg" "$iconset"/icon_512x512@2x.png
|
||||
magick convert -background none -resize 512x512 "$svg" "$iconset"/icon_512x512.png
|
||||
magick convert -background none -resize 256x256 "$svg" "$iconset"/icon_256x256.png
|
||||
magick convert -background none -resize 128x128 "$svg" "$iconset"/icon_128x128.png
|
||||
magick convert -background none -resize 64x64 "$svg" "$iconset"/icon_32x32@2x.png
|
||||
magick convert -background none -resize 32x32 "$svg" "$iconset"/icon_32x32.png
|
||||
magick convert -background none -resize 16x16 "$svg" "$iconset"/icon_16x16.png
|
||||
cp "$iconset"/icon_512x512.png "$iconset"/icon_256x256@2x.png
|
||||
cp "$iconset"/icon_256x256.png "$iconset"/icon_128x128@2x.png
|
||||
cp "$iconset"/icon_32x32.png "$iconset"/icon_16x16@2x.png
|
||||
iconutil -c icns "$iconset" -o "$icns"
|
||||
@@ -38,7 +38,6 @@ pub struct ConfigToml {
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||
pub struct TomlClient {
|
||||
pub capture_backend: Option<CaptureBackend>,
|
||||
pub hostname: Option<String>,
|
||||
pub host_name: Option<String>,
|
||||
pub ips: Option<Vec<IpAddr>>,
|
||||
|
||||
15
src/dns.rs
15
src/dns.rs
@@ -1,4 +1,4 @@
|
||||
use std::net::IpAddr;
|
||||
use std::{collections::HashMap, net::IpAddr};
|
||||
|
||||
use local_channel::mpsc::{channel, Receiver, Sender};
|
||||
use tokio::task::{spawn_local, JoinHandle};
|
||||
@@ -30,6 +30,7 @@ struct DnsTask {
|
||||
request_rx: Receiver<DnsRequest>,
|
||||
event_tx: Sender<DnsEvent>,
|
||||
cancellation_token: CancellationToken,
|
||||
active_tasks: HashMap<ClientHandle, JoinHandle<()>>,
|
||||
}
|
||||
|
||||
impl DnsResolver {
|
||||
@@ -39,6 +40,7 @@ impl DnsResolver {
|
||||
let (event_tx, event_rx) = channel();
|
||||
let cancellation_token = CancellationToken::new();
|
||||
let dns_task = DnsTask {
|
||||
active_tasks: Default::default(),
|
||||
resolver,
|
||||
request_rx,
|
||||
event_tx,
|
||||
@@ -81,6 +83,14 @@ impl DnsTask {
|
||||
while let Some(dns_request) = self.request_rx.recv().await {
|
||||
let DnsRequest { handle, hostname } = dns_request;
|
||||
|
||||
/* abort previous dns task */
|
||||
let previous_task = self.active_tasks.remove(&handle);
|
||||
if let Some(task) = previous_task {
|
||||
if !task.is_finished() {
|
||||
task.abort();
|
||||
}
|
||||
}
|
||||
|
||||
self.event_tx
|
||||
.send(DnsEvent::Resolving(handle))
|
||||
.expect("channel closed");
|
||||
@@ -90,7 +100,7 @@ impl DnsTask {
|
||||
let resolver = self.resolver.clone();
|
||||
let cancellation_token = self.cancellation_token.clone();
|
||||
|
||||
tokio::task::spawn_local(async move {
|
||||
let task = tokio::task::spawn_local(async move {
|
||||
tokio::select! {
|
||||
ips = resolver.lookup_ip(&hostname) => {
|
||||
let ips = ips.map(|ips| ips.iter().collect::<Vec<_>>());
|
||||
@@ -101,6 +111,7 @@ impl DnsTask {
|
||||
_ = cancellation_token.cancelled() => {},
|
||||
}
|
||||
});
|
||||
self.active_tasks.insert(handle, task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,6 @@ impl Service {
|
||||
FrontendRequest::EnableCapture => self.capture.reenable(),
|
||||
FrontendRequest::EnableEmulation => self.emulation.reenable(),
|
||||
FrontendRequest::Enumerate() => self.enumerate(),
|
||||
FrontendRequest::GetState(handle) => self.broadcast_client(handle),
|
||||
FrontendRequest::UpdateFixIps(handle, fix_ips) => self.update_fix_ips(handle, fix_ips),
|
||||
FrontendRequest::UpdateHostname(handle, host) => self.update_hostname(handle, host),
|
||||
FrontendRequest::UpdatePort(handle, port) => self.update_port(handle, port),
|
||||
@@ -283,7 +282,7 @@ impl Service {
|
||||
handle
|
||||
}
|
||||
};
|
||||
self.notify_frontend(FrontendEvent::Changed(handle));
|
||||
self.broadcast_client(handle);
|
||||
}
|
||||
|
||||
fn resolve(&self, handle: ClientHandle) {
|
||||
@@ -399,7 +398,7 @@ impl Service {
|
||||
log::debug!("deactivating client {handle}");
|
||||
if self.client_manager.deactivate_client(handle) {
|
||||
self.capture.destroy(handle);
|
||||
self.notify_frontend(FrontendEvent::Changed(handle));
|
||||
self.broadcast_client(handle);
|
||||
log::info!("deactivated client {handle}");
|
||||
}
|
||||
}
|
||||
@@ -425,7 +424,7 @@ impl Service {
|
||||
if self.client_manager.activate_client(handle) {
|
||||
/* notify capture and frontends */
|
||||
self.capture.create(handle, pos, CaptureType::Default);
|
||||
self.notify_frontend(FrontendEvent::Changed(handle));
|
||||
self.broadcast_client(handle);
|
||||
log::info!("activated client {handle} ({pos})");
|
||||
}
|
||||
}
|
||||
@@ -452,19 +451,20 @@ impl Service {
|
||||
|
||||
fn update_fix_ips(&mut self, handle: ClientHandle, fix_ips: Vec<IpAddr>) {
|
||||
self.client_manager.set_fix_ips(handle, fix_ips);
|
||||
self.notify_frontend(FrontendEvent::Changed(handle));
|
||||
self.broadcast_client(handle);
|
||||
}
|
||||
|
||||
fn update_hostname(&mut self, handle: ClientHandle, hostname: Option<String>) {
|
||||
log::info!("hostname changed: {hostname:?}");
|
||||
if self.client_manager.set_hostname(handle, hostname.clone()) {
|
||||
self.resolve(handle);
|
||||
}
|
||||
self.notify_frontend(FrontendEvent::Changed(handle));
|
||||
self.broadcast_client(handle);
|
||||
}
|
||||
|
||||
fn update_port(&mut self, handle: ClientHandle, port: u16) {
|
||||
self.client_manager.set_port(handle, port);
|
||||
self.notify_frontend(FrontendEvent::Changed(handle));
|
||||
self.broadcast_client(handle);
|
||||
}
|
||||
|
||||
fn update_pos(&mut self, handle: ClientHandle, pos: Position) {
|
||||
@@ -473,7 +473,7 @@ impl Service {
|
||||
self.deactivate_client(handle);
|
||||
self.activate_client(handle);
|
||||
}
|
||||
self.notify_frontend(FrontendEvent::Changed(handle));
|
||||
self.broadcast_client(handle);
|
||||
}
|
||||
|
||||
fn broadcast_client(&mut self, handle: ClientHandle) {
|
||||
|
||||
Reference in New Issue
Block a user