mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-16 22:31:03 +02:00
Merge pull request #1060 from Username404-59/master
Add a launch_command setting
This commit is contained in:
commit
bb7e927309
8 changed files with 91 additions and 66 deletions
|
@ -13,23 +13,24 @@ Optionally displays a launchable set of favourites.
|
||||||
|
|
||||||
> Type: `launcher`
|
> Type: `launcher`
|
||||||
|
|
||||||
| | Type | Default | Description |
|
| | Type | Default | Description |
|
||||||
|-----------------------------|---------------------------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-----------------------------|---------------------------------------------|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `favorites` | `string[]` | `[]` | List of app IDs (or classes) to always show at the start of the launcher. |
|
| `favorites` | `string[]` | `[]` | List of app IDs (or classes) to always show at the start of the launcher. |
|
||||||
| `show_names` | `boolean` | `false` | Whether to show app names on the button label. Names will still show on tooltips when set to false. |
|
| `show_names` | `boolean` | `false` | Whether to show app names on the button label. Names will still show on tooltips when set to false. |
|
||||||
| `show_icons` | `boolean` | `true` | Whether to show app icons on the button. |
|
| `show_icons` | `boolean` | `true` | Whether to show app icons on the button. |
|
||||||
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
|
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
|
||||||
| `reversed` | `boolean` | `false` | Whether to reverse the order of favorites/items |
|
| `launch_command` | `string` | `gtk-launch {app_name}` | Command used to launch applications. |
|
||||||
| `minimize_focused` | `boolean` | `true` | Whether to minimize a focused window when its icon is clicked. Only minimizes single windows. |
|
| `reversed` | `boolean` | `false` | Whether to reverse the order of favorites/items |
|
||||||
| `truncate.mode` | `'start'` or `'middle'` or `'end'` or `off` | `end` | Location of the ellipses and where to truncate text from. Applies to application names when `show_names` is enabled. |
|
| `minimize_focused` | `boolean` | `true` | Whether to minimize a focused window when its icon is clicked. Only minimizes single windows. |
|
||||||
| `truncate.length` | `integer` | `null` | Fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
|
| `truncate.mode` | `'start'` or `'middle'` or `'end'` or `off` | `end` | Location of the ellipses and where to truncate text from. Applies to application names when `show_names` is enabled. |
|
||||||
| `truncate.max_length` | `integer` | `null` | Maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
|
| `truncate.length` | `integer` | `null` | Fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
|
||||||
| `truncate_popup.mode` | `'start'` or `'middle'` or `'end'` or `off` | `middle` | Location of the ellipses and where to truncate text from. Applies to window names within a group popup. |
|
| `truncate.max_length` | `integer` | `null` | Maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
|
||||||
| `truncate_popup.length` | `integer` | `null` | Fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
|
| `truncate_popup.mode` | `'start'` or `'middle'` or `'end'` or `off` | `middle` | Location of the ellipses and where to truncate text from. Applies to window names within a group popup. |
|
||||||
| `truncate_popup.max_length` | `integer` | `25` | Maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
|
| `truncate_popup.length` | `integer` | `null` | Fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
|
||||||
| `page_size` | `integer` | `1000` | Number of items to show on a page. When the number of items is reached, controls appear which can be used to move forward/back through the list of items. |
|
| `truncate_popup.max_length` | `integer` | `25` | Maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
|
||||||
| `icons.page_back` | `string` or [image](images) | `` | Icon to show for page back button. |
|
| `page_size` | `integer` | `1000` | Number of items to show on a page. When the number of items is reached, controls appear which can be used to move forward/back through the list of items. |
|
||||||
| `icons.page_forward` | `string` or [image](images) | `` | Icon to show for page forward button. |
|
| `icons.page_back` | `string` or [image](images) | `` | Icon to show for page back button. |
|
||||||
|
| `icons.page_forward` | `string` or [image](images) | `` | Icon to show for page forward button. |
|
||||||
<details>
|
<details>
|
||||||
<summary>JSON</summary>
|
<summary>JSON</summary>
|
||||||
|
|
||||||
|
|
|
@ -10,20 +10,21 @@ It is also possible to add custom categories and actions into the menu.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
| | Type | Default | Description |
|
| | Type | Default | Description |
|
||||||
|-----------------------|------------------------------------------------------|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-----------------------|------------------------------------------------------|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `start` | `MenuEntry[]` | `[]` | Items to add to the start of the main menu. |
|
| `start` | `MenuEntry[]` | `[]` | Items to add to the start of the main menu. |
|
||||||
| `center` | `MenuEntry[]` | Default XDG menu | Items to add to the centre of the main menu. By default this shows a number of XDG entries that should cover all common applications. |
|
| `center` | `MenuEntry[]` | Default XDG menu | Items to add to the centre of the main menu. By default this shows a number of XDG entries that should cover all common applications. |
|
||||||
| `end` | `MenuEntry[]` | `[]` | Items to add to the end of the main menu. |
|
| `end` | `MenuEntry[]` | `[]` | Items to add to the end of the main menu. |
|
||||||
| `height` | `integer` | `null` | Height of the menu. Leave null to resize dynamically. |
|
| `height` | `integer` | `null` | Height of the menu. Leave null to resize dynamically. |
|
||||||
| `width` | `integer` | `null` | Width of the menu. Leave null to resize dynamically. |
|
| `width` | `integer` | `null` | Width of the menu. Leave null to resize dynamically. |
|
||||||
| `label` | `string` | `≡` | Label to show on the menu button on the bar. |
|
| `label` | `string` | `≡` | Label to show on the menu button on the bar. |
|
||||||
| `label_icon` | `string` | `null` | Icon to show on the menu button on the bar. |
|
| `label_icon` | `string` | `null` | Icon to show on the menu button on the bar. |
|
||||||
| `label_icon_size` | `integer` | `16` | Size of the label_icon image. |
|
| `label_icon_size` | `integer` | `16` | Size of the label_icon image. |
|
||||||
| `truncate` | `'start'` or `'middle'` or `'end'` or `off` or `Map` | `off` | Applies to popup. The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. |
|
| `launch_command` | `string` | `gtk-launch {app_name}` | Command used to launch applications. |
|
||||||
| `truncate.mode` | `'start'` or `'middle'` or `'end'` or `off` | `off` | Applies to popup. The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
|
| `truncate` | `'start'` or `'middle'` or `'end'` or `off` or `Map` | `off` | Applies to popup. The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. |
|
||||||
| `truncate.length` | `integer` | `null` | Applies to popup. The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
|
| `truncate.mode` | `'start'` or `'middle'` or `'end'` or `off` | `off` | Applies to popup. The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
|
||||||
| `truncate.max_length` | `integer` | `null` | Applies to popup. The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
|
| `truncate.length` | `integer` | `null` | Applies to popup. The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
|
||||||
|
| `truncate.max_length` | `integer` | `null` | Applies to popup. The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
|
||||||
|
|
||||||
|
|
||||||
### `MenuEntry`
|
### `MenuEntry`
|
||||||
|
|
|
@ -481,3 +481,7 @@ pub const fn default_false() -> bool {
|
||||||
pub const fn default_true() -> bool {
|
pub const fn default_true() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn default_launch_command() -> String {
|
||||||
|
String::from("gtk-launch {app_name}")
|
||||||
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use crate::spawn;
|
use crate::spawn;
|
||||||
use color_eyre::Result;
|
use color_eyre::{Help, Report, Result};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::io::{AsyncBufReadExt, BufReader};
|
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tracing::debug;
|
use tracing::{debug, error};
|
||||||
use walkdir::{DirEntry, WalkDir};
|
use walkdir::{DirEntry, WalkDir};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -323,6 +324,25 @@ fn files(dir: &Path) -> Vec<PathBuf> {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Starts a `.desktop` file with the provided formatted command.
|
||||||
|
pub fn open_program(file_name: &str, str: &str) {
|
||||||
|
let expanded = str.replace("{app_name}", file_name);
|
||||||
|
let launch_command_parts: Vec<&str> = expanded.split_whitespace().collect();
|
||||||
|
if let Err(err) = Command::new(&launch_command_parts[0])
|
||||||
|
.args(&launch_command_parts[1..])
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
|
.spawn()
|
||||||
|
{
|
||||||
|
error!(
|
||||||
|
"{:?}",
|
||||||
|
Report::new(err)
|
||||||
|
.wrap_err("Failed to run launch command.")
|
||||||
|
.suggestion("Perhaps the applications file is invalid?")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -7,17 +7,19 @@ use self::open_state::OpenState;
|
||||||
use super::{Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, WidgetContext};
|
use super::{Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, WidgetContext};
|
||||||
use crate::channels::{AsyncSenderExt, BroadcastReceiverExt};
|
use crate::channels::{AsyncSenderExt, BroadcastReceiverExt};
|
||||||
use crate::clients::wayland::{self, ToplevelEvent};
|
use crate::clients::wayland::{self, ToplevelEvent};
|
||||||
use crate::config::{CommonConfig, EllipsizeMode, LayoutConfig, TruncateMode};
|
use crate::config::{
|
||||||
|
CommonConfig, EllipsizeMode, LayoutConfig, TruncateMode, default_launch_command,
|
||||||
|
};
|
||||||
|
use crate::desktop_file::open_program;
|
||||||
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
|
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
|
||||||
use crate::modules::launcher::item::ImageTextButton;
|
use crate::modules::launcher::item::ImageTextButton;
|
||||||
use crate::modules::launcher::pagination::{IconContext, Pagination};
|
use crate::modules::launcher::pagination::{IconContext, Pagination};
|
||||||
use crate::{arc_mut, lock, module_impl, spawn, write_lock};
|
use crate::{arc_mut, lock, module_impl, spawn, write_lock};
|
||||||
use color_eyre::{Help, Report};
|
use color_eyre::Report;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{Button, Orientation};
|
use gtk::{Button, Orientation};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::process::{Command, Stdio};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tracing::{debug, error, trace, warn};
|
use tracing::{debug, error, trace, warn};
|
||||||
|
@ -108,6 +110,12 @@ pub struct LauncherModule {
|
||||||
#[serde(default, flatten)]
|
#[serde(default, flatten)]
|
||||||
layout: LayoutConfig,
|
layout: LayoutConfig,
|
||||||
|
|
||||||
|
/// Command used to launch applications.
|
||||||
|
///
|
||||||
|
/// **Default**: `gtk-launch`
|
||||||
|
#[serde(default = "default_launch_command")]
|
||||||
|
launch_command: String,
|
||||||
|
|
||||||
/// See [common options](module-level-options#common-options).
|
/// See [common options](module-level-options#common-options).
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub common: Option<CommonConfig>,
|
pub common: Option<CommonConfig>,
|
||||||
|
@ -373,25 +381,14 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
let wl = context.client::<wayland::Client>();
|
let wl = context.client::<wayland::Client>();
|
||||||
|
|
||||||
let desktop_files = context.ironbar.desktop_files();
|
let desktop_files = context.ironbar.desktop_files();
|
||||||
|
let launch_command_str: String = self.launch_command.clone();
|
||||||
|
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
while let Some(event) = rx.recv().await {
|
while let Some(event) = rx.recv().await {
|
||||||
if let ItemEvent::OpenItem(app_id) = event {
|
if let ItemEvent::OpenItem(app_id) = event {
|
||||||
match desktop_files.find(&app_id).await {
|
match desktop_files.find(&app_id).await {
|
||||||
Ok(Some(file)) => {
|
Ok(Some(file)) => {
|
||||||
if let Err(err) = Command::new("gtk-launch")
|
open_program(&file.file_name, &launch_command_str);
|
||||||
.arg(file.file_name)
|
|
||||||
.stdout(Stdio::null())
|
|
||||||
.stderr(Stdio::null())
|
|
||||||
.spawn()
|
|
||||||
{
|
|
||||||
error!(
|
|
||||||
"{:?}",
|
|
||||||
Report::new(err)
|
|
||||||
.wrap_err("Failed to run gtk-launch command.")
|
|
||||||
.suggestion("Perhaps the applications file is invalid?")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(None) => warn!("Could not find applications file for {}", app_id),
|
Ok(None) => warn!("Could not find applications file for {}", app_id),
|
||||||
Err(err) => error!("Failed to find parse file for {}: {}", app_id, err),
|
Err(err) => error!("Failed to find parse file for {}: {}", app_id, err),
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::config::default_launch_command;
|
||||||
use crate::config::{CommonConfig, TruncateMode};
|
use crate::config::{CommonConfig, TruncateMode};
|
||||||
use crate::modules::menu::{MenuEntry, XdgSection};
|
use crate::modules::menu::{MenuEntry, XdgSection};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
@ -123,6 +124,12 @@ pub struct MenuModule {
|
||||||
/// See [common options](module-level-options#common-options).
|
/// See [common options](module-level-options#common-options).
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub common: Option<CommonConfig>,
|
pub common: Option<CommonConfig>,
|
||||||
|
|
||||||
|
/// Command used to launch applications.
|
||||||
|
///
|
||||||
|
/// **Default**: `gtk-launch`
|
||||||
|
#[serde(default = "default_launch_command")]
|
||||||
|
pub launch_command: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MenuModule {
|
impl Default for MenuModule {
|
||||||
|
@ -139,6 +146,7 @@ impl Default for MenuModule {
|
||||||
label_icon: None,
|
label_icon: None,
|
||||||
label_icon_size: default_menu_popup_icon_size(),
|
label_icon_size: default_menu_popup_icon_size(),
|
||||||
common: Some(CommonConfig::default()),
|
common: Some(CommonConfig::default()),
|
||||||
|
launch_command: default_launch_command(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,8 +262,13 @@ impl Module<Button> for MenuModule {
|
||||||
for entry in $entries.values() {
|
for entry in $entries.values() {
|
||||||
let container1 = container.clone();
|
let container1 = container.clone();
|
||||||
let tx = context.tx.clone();
|
let tx = context.tx.clone();
|
||||||
let (button, sub_menu) =
|
let (button, sub_menu) = ui::make_entry(
|
||||||
ui::make_entry(entry, tx, &image_provider, truncate_mode);
|
entry,
|
||||||
|
tx,
|
||||||
|
&image_provider,
|
||||||
|
truncate_mode,
|
||||||
|
&self.launch_command,
|
||||||
|
);
|
||||||
|
|
||||||
if let Some(sub_menu) = sub_menu.clone() {
|
if let Some(sub_menu) = sub_menu.clone() {
|
||||||
sub_menu.set_valign(alignment);
|
sub_menu.set_valign(alignment);
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
use super::MenuEntry;
|
use super::MenuEntry;
|
||||||
use crate::channels::AsyncSenderExt;
|
use crate::channels::AsyncSenderExt;
|
||||||
use crate::config::TruncateMode;
|
use crate::config::TruncateMode;
|
||||||
|
use crate::desktop_file::open_program;
|
||||||
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
|
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
|
||||||
use crate::modules::ModuleUpdateEvent;
|
use crate::modules::ModuleUpdateEvent;
|
||||||
use crate::script::Script;
|
use crate::script::Script;
|
||||||
use crate::{image, spawn};
|
use crate::{image, spawn};
|
||||||
use color_eyre::{Help, Report};
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{Align, Button, Label, Orientation};
|
use gtk::{Align, Button, Label, Orientation};
|
||||||
use std::process::{Command, Stdio};
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
|
@ -17,6 +16,7 @@ pub fn make_entry<R>(
|
||||||
tx: mpsc::Sender<ModuleUpdateEvent<R>>,
|
tx: mpsc::Sender<ModuleUpdateEvent<R>>,
|
||||||
image_provider: &image::Provider,
|
image_provider: &image::Provider,
|
||||||
truncate_mode: TruncateMode,
|
truncate_mode: TruncateMode,
|
||||||
|
launch_command_str: &str,
|
||||||
) -> (Button, Option<gtk::Box>)
|
) -> (Button, Option<gtk::Box>)
|
||||||
where
|
where
|
||||||
R: Send + Clone + 'static,
|
R: Send + Clone + 'static,
|
||||||
|
@ -96,22 +96,11 @@ where
|
||||||
{
|
{
|
||||||
let sub_menu = sub_menu.clone();
|
let sub_menu = sub_menu.clone();
|
||||||
let file_name = sub_entry.file_name.clone();
|
let file_name = sub_entry.file_name.clone();
|
||||||
|
let command = launch_command_str.to_string();
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
|
|
||||||
button.connect_clicked(move |_button| {
|
button.connect_clicked(move |_button| {
|
||||||
if let Err(err) = Command::new("gtk-launch")
|
open_program(&file_name, &command);
|
||||||
.arg(&file_name)
|
|
||||||
.stdout(Stdio::null())
|
|
||||||
.stderr(Stdio::null())
|
|
||||||
.spawn()
|
|
||||||
{
|
|
||||||
error!(
|
|
||||||
"{:?}",
|
|
||||||
Report::new(err)
|
|
||||||
.wrap_err("Failed to run gtk-launch command.")
|
|
||||||
.suggestion("Perhaps the applications file is invalid?")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub_menu.hide();
|
sub_menu.hide();
|
||||||
tx.send_spawn(ModuleUpdateEvent::ClosePopup);
|
tx.send_spawn(ModuleUpdateEvent::ClosePopup);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue