|
|
@ -15,12 +15,15 @@ |
|
|
|
|
|
|
|
|
|
|
|
//! Utility functions including selection between choices using a menu program.
|
|
|
|
//! Utility functions including selection between choices using a menu program.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use once_cell::sync::Lazy; |
|
|
|
|
|
|
|
use regex::Regex; |
|
|
|
|
|
|
|
|
|
|
|
use crate::config as cfg; |
|
|
|
use crate::config as cfg; |
|
|
|
use lazy_static::lazy_static; |
|
|
|
|
|
|
|
use std::collections::HashMap; |
|
|
|
use std::collections::HashMap; |
|
|
|
use std::io::{BufRead, Write}; |
|
|
|
use std::io::{BufRead, Write}; |
|
|
|
use std::path as p; |
|
|
|
use std::path as p; |
|
|
|
use std::process as proc; |
|
|
|
use std::process as proc; |
|
|
|
|
|
|
|
use std::sync::Mutex; |
|
|
|
|
|
|
|
|
|
|
|
pub fn get_swayr_socket_path() -> String { |
|
|
|
pub fn get_swayr_socket_path() -> String { |
|
|
|
// We prefer checking the env variable instead of
|
|
|
|
// We prefer checking the env variable instead of
|
|
|
@ -120,12 +123,10 @@ fn find_icon(icon_name: &str, icon_dirs: &[String]) -> Option<Box<p::Path>> { |
|
|
|
None |
|
|
|
None |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lazy_static! { |
|
|
|
static WM_CLASS_OR_ICON_RX: Lazy<Regex> = |
|
|
|
static ref WM_CLASS_OR_ICON_RX: regex::Regex = |
|
|
|
Lazy::new(|| Regex::new(r"(StartupWMClass|Icon)=(.+)").unwrap()); |
|
|
|
regex::Regex::new(r"(StartupWMClass|Icon)=(.+)").unwrap(); |
|
|
|
static REV_DOMAIN_NAME_RX: Lazy<Regex> = |
|
|
|
static ref REV_DOMAIN_NAME_RX: regex::Regex = |
|
|
|
Lazy::new(|| Regex::new(r"^(?:[a-zA-Z0-9-]+\.)+([a-zA-Z0-9-]+)$").unwrap()); |
|
|
|
regex::Regex::new(r"^(?:[a-zA-Z0-9-]+\.)+([a-zA-Z0-9-]+)$").unwrap(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_app_id_to_icon_map( |
|
|
|
fn get_app_id_to_icon_map( |
|
|
|
icon_dirs: &[String], |
|
|
|
icon_dirs: &[String], |
|
|
@ -195,10 +196,10 @@ fn get_app_id_to_icon_map( |
|
|
|
map |
|
|
|
map |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lazy_static! { |
|
|
|
// Well, this type definition is pretty useless since it's only used in
|
|
|
|
static ref APP_ID_TO_ICON_MAP: std::sync::Mutex<Option<HashMap<String, Box<p::Path>>>> = |
|
|
|
// get_icon anyway but clippy suggested it...
|
|
|
|
std::sync::Mutex::new(None); |
|
|
|
type AppIdToIconMap = Lazy<Mutex<Option<HashMap<String, Box<p::Path>>>>>; |
|
|
|
} |
|
|
|
static APP_ID_TO_ICON_MAP: AppIdToIconMap = Lazy::new(|| Mutex::new(None)); |
|
|
|
|
|
|
|
|
|
|
|
pub fn get_icon(app_id: &str, icon_dirs: &[String]) -> Option<Box<p::Path>> { |
|
|
|
pub fn get_icon(app_id: &str, icon_dirs: &[String]) -> Option<Box<p::Path>> { |
|
|
|
let mut opt = APP_ID_TO_ICON_MAP.lock().unwrap(); |
|
|
|
let mut opt = APP_ID_TO_ICON_MAP.lock().unwrap(); |
|
|
|