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
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum Message {
KeyPressed(u32),
HideWindow(Id),
RunFunction(Function),
ReturnFocus,
ClearSearchResults,
WindowFocusChanged(Id, bool),
ClearSearchQuery,
Expand Down
8 changes: 4 additions & 4 deletions src/app/tile/elm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ pub fn new(keybind_id: u32, config: &Config) -> (Tile, Task<Message>) {

let store_icons = config.theme.show_icons;

let user_local_path = std::env::var("home").unwrap() + "/applications/";
let user_local_path = std::env::var("HOME").unwrap() + "/Applications/";

let paths = vec![
"/applications/",
"/Applications/",
user_local_path.as_str(),
"/system/applications/",
"/system/applications/utilities/",
"/System/Applications/",
"/System/Applications/Utilities/",
];

let mut options: Vec<App> = paths
Expand Down
16 changes: 15 additions & 1 deletion src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
} else {
Message::_Nothing
}),
Task::done(Message::ReturnFocus),
])
}
} else {
Expand All @@ -164,23 +165,36 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
Message::RunFunction(command) => {
command.execute(&tile.config, &tile.query);

let return_focus_task = match &command {
Function::OpenApp(_) | Function::OpenPrefPane | Function::GoogleSearch(_) => {
Task::none()
}
_ => Task::done(Message::ReturnFocus),
};

if tile.config.buffer_rules.clear_on_enter {
window::latest()
.map(|x| x.unwrap())
.map(Message::HideWindow)
.chain(Task::done(Message::ClearSearchQuery))
.chain(return_focus_task)
} else {
Task::none()
}
}

Message::HideWindow(a) => {
tile.restore_frontmost();
tile.visible = false;
tile.focused = false;
tile.page = Page::Main;
Task::batch([window::close(a), Task::done(Message::ClearSearchResults)])
}

Message::ReturnFocus => {
tile.restore_frontmost();
Task::none()
}

Message::ClearSearchResults => {
tile.results = vec![];
Task::none()
Expand Down
6 changes: 4 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! This is the config file type definitions for rustcast
use std::{path::Path, sync::Arc};

use global_hotkey::hotkey::Code;

use iced::{theme::Custom, widget::image::Handle};
use serde::{Deserialize, Serialize};

Expand All @@ -11,7 +13,7 @@ use crate::{app::apps::App, commands::Function, utils::handle_from_icns};
#[serde(default)]
pub struct Config {
pub toggle_mod: String,
pub toggle_key: String,
pub toggle_key: Code,
pub buffer_rules: Buffer,
pub theme: Theme,
pub placeholder: String,
Expand All @@ -24,7 +26,7 @@ impl Default for Config {
fn default() -> Self {
Self {
toggle_mod: "ALT".to_string(),
toggle_key: "Space".to_string(),
toggle_key: Code::Space,
buffer_rules: Buffer::default(),
theme: Theme::default(),
placeholder: String::from("Time to be productive!"),
Expand Down
11 changes: 7 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ mod utils;

use std::path::Path;

use crate::{app::tile::Tile, config::Config, utils::to_key_code};
use crate::{app::tile::Tile, config::Config};

use global_hotkey::{
GlobalHotKeyManager,
hotkey::{Code, HotKey, Modifiers},
hotkey::{HotKey, Modifiers},
};

fn main() -> iced::Result {
Expand Down Expand Up @@ -41,11 +41,14 @@ fn main() -> iced::Result {

let show_hide = HotKey::new(
Some(Modifiers::from_name(&config.toggle_mod).unwrap_or(Modifiers::ALT)),
to_key_code(&config.toggle_key).unwrap_or(Code::Space),
config.toggle_key,
);

// Hotkeys are stored as a vec so that hyperkey support can be added later
let hotkeys = vec![show_hide];

manager
.register_all(&[show_hide])
.register_all(&hotkeys)
.expect("Unable to register hotkey");

iced::daemon(
Expand Down
128 changes: 0 additions & 128 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{
process::exit,
};

use global_hotkey::hotkey::Code;
use iced::widget::image::Handle;
use icns::IconFamily;
use image::RgbaImage;
Expand Down Expand Up @@ -171,130 +170,3 @@ pub(crate) fn get_installed_apps(dir: impl AsRef<Path>, store_icons: bool) -> Ve
})
.collect()
}

/// This converts a string to a [`Code`] enum so that it can be used as a hotkey
pub fn to_key_code(key_str: &str) -> Option<Code> {
match key_str.to_lowercase().as_str() {
// Letters
"a" => Some(Code::KeyA),
"b" => Some(Code::KeyB),
"c" => Some(Code::KeyC),
"d" => Some(Code::KeyD),
"e" => Some(Code::KeyE),
"f" => Some(Code::KeyF),
"g" => Some(Code::KeyG),
"h" => Some(Code::KeyH),
"i" => Some(Code::KeyI),
"j" => Some(Code::KeyJ),
"k" => Some(Code::KeyK),
"l" => Some(Code::KeyL),
"m" => Some(Code::KeyM),
"n" => Some(Code::KeyN),
"o" => Some(Code::KeyO),
"p" => Some(Code::KeyP),
"q" => Some(Code::KeyQ),
"r" => Some(Code::KeyR),
"s" => Some(Code::KeyS),
"t" => Some(Code::KeyT),
"u" => Some(Code::KeyU),
"v" => Some(Code::KeyV),
"w" => Some(Code::KeyW),
"x" => Some(Code::KeyX),
"y" => Some(Code::KeyY),
"z" => Some(Code::KeyZ),

// Digits (main row)
"0" => Some(Code::Digit0),
"1" => Some(Code::Digit1),
"2" => Some(Code::Digit2),
"3" => Some(Code::Digit3),
"4" => Some(Code::Digit4),
"5" => Some(Code::Digit5),
"6" => Some(Code::Digit6),
"7" => Some(Code::Digit7),
"8" => Some(Code::Digit8),
"9" => Some(Code::Digit9),

// Function keys
"f1" => Some(Code::F1),
"f2" => Some(Code::F2),
"f3" => Some(Code::F3),
"f4" => Some(Code::F4),
"f5" => Some(Code::F5),
"f6" => Some(Code::F6),
"f7" => Some(Code::F7),
"f8" => Some(Code::F8),
"f9" => Some(Code::F9),
"f10" => Some(Code::F10),
"f11" => Some(Code::F11),
"f12" => Some(Code::F12),

// Arrows
"up" | "arrowup" => Some(Code::ArrowUp),
"down" | "arrowdown" => Some(Code::ArrowDown),
"left" | "arrowleft" => Some(Code::ArrowLeft),
"right" | "arrowright" => Some(Code::ArrowRight),

// Modifiers
"shift" | "lshift" => Some(Code::ShiftLeft),
"rshift" => Some(Code::ShiftRight),
"ctrl" | "control" | "lctrl" => Some(Code::ControlLeft),
"rctrl" => Some(Code::ControlRight),
"alt" | "lalt" => Some(Code::AltLeft),
"ralt" => Some(Code::AltRight),
"meta" | "super" | "win" | "lmeta" => Some(Code::MetaLeft),
"rmeta" => Some(Code::MetaRight),

// Whitespace / editing
"space" => Some(Code::Space),
"enter" => Some(Code::Enter),
"tab" => Some(Code::Tab),
"backspace" => Some(Code::Backspace),
"delete" => Some(Code::Delete),
"insert" => Some(Code::Insert),
"escape" | "esc" => Some(Code::Escape),

// Punctuation (US layout-style names)
"-" | "minus" => Some(Code::Minus),
"=" | "equal" => Some(Code::Equal),
"[" | "bracketleft" => Some(Code::BracketLeft),
"]" | "bracketright" => Some(Code::BracketRight),
"\\" | "backslash" => Some(Code::Backslash),
";" | "semicolon" => Some(Code::Semicolon),
"'" | "quote" => Some(Code::Quote),
"," | "comma" => Some(Code::Comma),
"." | "period" => Some(Code::Period),
"/" | "slash" => Some(Code::Slash),
"`" | "backquote" | "grave" => Some(Code::Backquote),

// Numpad
"numpad0" => Some(Code::Numpad0),
"numpad1" => Some(Code::Numpad1),
"numpad2" => Some(Code::Numpad2),
"numpad3" => Some(Code::Numpad3),
"numpad4" => Some(Code::Numpad4),
"numpad5" => Some(Code::Numpad5),
"numpad6" => Some(Code::Numpad6),
"numpad7" => Some(Code::Numpad7),
"numpad8" => Some(Code::Numpad8),
"numpad9" => Some(Code::Numpad9),
"numpadadd" | "numadd" | "kp+" => Some(Code::NumpadAdd),
"numpadsubtract" | "numsub" | "kp-" => Some(Code::NumpadSubtract),
"numpadmultiply" | "nummul" | "kp*" => Some(Code::NumpadMultiply),
"numpaddivide" | "numdiv" | "kp/" => Some(Code::NumpadDivide),
"numpaddecimal" | "numdecimal" | "kp." => Some(Code::NumpadDecimal),
"numpadenter" | "numenter" => Some(Code::NumpadEnter),

// Navigation / misc
"home" => Some(Code::Home),
"end" => Some(Code::End),
"pageup" => Some(Code::PageUp),
"pagedown" => Some(Code::PageDown),
"capslock" => Some(Code::CapsLock),
"scrolllock" => Some(Code::ScrollLock),
"numlock" => Some(Code::NumLock),
"pause" => Some(Code::Pause),

_ => None,
}
}