Skip to content

Commit

Permalink
hdrop: 0.2.4 -> 0.2.5
Browse files Browse the repository at this point in the history
hdrop: 0.2.4 -> 0.3.0

r

hdrop: change version
  • Loading branch information
Schweber committed Dec 28, 2023
1 parent 8a6c82c commit 5cb203a
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 53 deletions.
42 changes: 27 additions & 15 deletions hdrop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ This Bash script emulates the main features of [tdrop](https://github.com/noctui
#### Options:

> -b, --background
> changes the default behaviour: if the specified program is not running, launch it in the background instead of foreground. Thereafter 'hdrop -b' will work the same as without this flag.
> changes the default behaviour: if the specified program is not running, launch it in the background instead of in the foreground. Thereafter 'hdrop -b' will work the same as without this flag.
>
> -i, --insensitive
> Case insensitive partial matching of class names. Can work as a stopgap if a running program is not recognized and a new instance is launched instead. Note: incorrect matches may occur, adding a special handling of the program to hdrop is preferable.
>
> -v, --verbose
> Show notifications regarding the matching process. Try this to figure out why running programs are not matched.
>
> -h, --help
> Print this help message
> Print help message
>
> -V, --version
> Print version
Expand All @@ -30,28 +36,28 @@ This Bash script emulates the main features of [tdrop](https://github.com/noctui

Multiple instances of the same program can be run concurrently, if different class names are assigned to each instance. Presently there is support for the following flags in the [COMMAND] string:

> -a ('foot' terminal emulator)
> --class (all other programs).
> -a ([foot](https://codeberg.org/dnkl/foot/) terminal emulator)
> --class (all other programs)
#### Example bindings in Hyprland config:

> bind = $mainMod, b, exec, hdrop librewolf'
> bind = $mainMod, x, exec, hdrop kitty --class kitty_1'
> bind = $mainMod CTRL, x, exec, hdrop kitty --class kitty_2'
> bind = $mainMod, c, exec, hdrop foot -a foot_1'
> bind = $mainMod CTRL, c, exec, hdrop foot -a foot_2'
> bind = $mainMod, b, exec, hdrop librewolf
> bind = $mainMod, x, exec, hdrop kitty --class kitty_1
> bind = $mainMod CTRL, x, exec, hdrop kitty --class kitty_2
> bind = $mainMod, c, exec, hdrop foot -a foot_1
> bind = $mainMod CTRL, c, exec, hdrop foot -a foot_2
Note: defining a class name is only necessary when running several instances of the same program.

If you want to run a program on boot and have it wait in the background until called up by hdrop you can use this:

> exec-once = hdrop -b librewolf
Please feel free to report missing flags or peculiarities for other programs!
## Troubleshooting

If hdrop can't match an already running program and starts a new instance instead, then its class name is most likely different from its command name. For example, the class name of `telegram-desktop` is `org.telegram.desktop` and the class name of `logseq` is `Logseq`.

Dependencies: bash jq hyprland
Author: Schweber (https://github.com/Schweber/hdrop)
License: AGPL3
Run `hdrop -v [COMMAND]` _in the terminal_ to see maximum output for troubleshooting and please report such peculiarities so that i can add them to hdrop. Using `hdrop -i [COMMAND]` might make it work in the meantime.

## Installation

Expand All @@ -61,10 +67,16 @@ License: AGPL3

### Manual

Make sure that `bash`, `jq` and `hyprland` are in your PATH.
Make sure that `bash` and `jq` are in your PATH.

Download the script, make it executable and add it to your PATH.

### hyprwm/contrib
Note: `hdrop` will only work in a `Hyprland` session.

### Makefile

Use the provided Makefile.

## See also

`hdrop` is part of [hyprwm/contrib](https://github.com/hyprwm/contrib), which is a collection of useful scripts for `Hyprland`.
3 changes: 1 addition & 2 deletions hdrop/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}:
stdenvNoCC.mkDerivation {
pname = "hdrop";
version = "0.2.4";
version = "0.3.0";

src = ./.;

Expand All @@ -37,7 +37,6 @@ stdenvNoCC.mkDerivation {
description = "Emulate 'tdrop' in Hyprland (show and hide specific programs per keybind)";
license = licenses.agpl3;
platforms = platforms.unix;
# maintainers = with maintainers; [];
mainProgram = "hdrop";
};
}
107 changes: 76 additions & 31 deletions hdrop/hdrop
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ print_help() {
echo ""
echo "Options:"
echo " -b, --background"
echo " changes the default behaviour: if the specified program is"
echo " Changes the default behaviour: if the specified program is"
echo " not running, launch it in the background instead of foreground."
echo " Thereafter 'hdrop -b' will work the same as without this flag."
echo ""
echo " -i, --insensitive"
echo " Case insensitive partial matching of class names."
echo " Try this if a running program is not recognized and a new"
echo " instance is launched instead."
echo ""
echo " -v, --verbose"
echo " Show notifications regarding the matching process."
echo " Use this to figure out why running programs are not matched."
echo ""
echo " -h, --help"
echo " Print this help message"
echo ""
Expand All @@ -26,45 +35,76 @@ print_help() {
echo "support for the following flags in the [COMMAND] string:"
echo ""
echo " -a ('foot' terminal emulator)"
echo " --class (all other programs)."
echo " --class (all other programs)"
echo ""
echo "See man page for more information"
}

print_version() {
echo "hdrop version: 0.2.4"
echo "hdrop version: 0.3.0"
}

notify() {
notify-send "$@" || hyprctl notify 0 5000 0 "$@"
echo "$@"
}

notify_low() {
notify-send -u low "$@" || hyprctl notify 1 5000 0 "$@"
echo "$@"
}

BACKGROUND=""
INSENSITIVE=false
VERBOSE=false

case "$1" in
"")
notify "hdrop: missing Argument" "Run 'hdrop -h' for more information"
print_help
exit 1
;;
-h | --help)
print_help
exit
;;
-V | --version)
print_version
exit
;;
-b | --background)
BACKGROUND="hyprctl dispatch -- exec [workspace special:hdrop silent] "
shift
;;
-*)
notify "hdrop: unrecognized flag" "Run 'hdrop -h' for more information"
print_help
exit 1
;;
esac
# shopt -s extglob

while true; do
case "$1" in
"")
notify "hdrop: Missing Argument" "Run 'hdrop -h' for more information"
print_help
exit 1
;;
-h | --help)
print_help
exit
;;
-V | --version)
print_version
exit
;;
-b | --background)
BACKGROUND="hyprctl dispatch -- exec [workspace special:hdrop silent] "
shift
;;
-i | --insensitive)
INSENSITIVE=true
shift
;;
-v | --verbose)
VERBOSE=true
shift
;;
-bi | -ib)
BACKGROUND="hyprctl dispatch -- exec [workspace special:hdrop silent] "
INSENSITIVE=true
shift
;;
-vi | -iv)
INSENSITIVE=true
VERBOSE=true
shift
;;
-*)
notify "hdrop: Unrecognized flag '$1'" "Run 'hdrop -h' for more information"
print_help
exit 1
;;
*) break ;;
esac
done

CLASS="$1"
COMMANDLINE="${*:1}"
Expand All @@ -87,22 +127,27 @@ esac

if [[ -n $OPT ]]; then
eval set -- "$OPT"
# while true; do
case "$1" in
-a | --class)
CLASS="$2"
# shift 2
;;
# *) break ;;
esac
# done
fi

if $INSENSITIVE && [[ $(hyprctl clients -j | jq -r ".[] | select((.class |test(\"$CLASS\";\"i\")))") ]]; then
if $VERBOSE; then notify_low "hdrop: --insensitive -> Insensitive (partial) match of class '$CLASS' successful"; fi
CLASS=$(hyprctl clients -j | jq -r ".[] | select((.class |match(\"$CLASS\";\"i\"))) | .class" | head -1) || notify "hdrop: Error assigning case insensitive (partial) match to CLASS"
if $VERBOSE; then notify_low "hdrop: --insensitive -> Using class '$CLASS' after insensitive (partial) matching"; fi
fi

if [[ $(hyprctl clients -j | jq -r ".[] | select(.class==\"$CLASS\" and .workspace.id!=$ACTIVE_WORKSPACE)") ]]; then
hyprctl dispatch -- movetoworkspacesilent "$ACTIVE_WORKSPACE","$CLASS" || notify "hdrop: Error moving '$COMMANDLINE' to current workspace"
hyprctl dispatch -- focuswindow "$CLASS" || notify "hdrop: Error focusing '$COMMANDLINE' on current workspace"
if $VERBOSE; then notify_low "hdrop: Matched class '$CLASS' on another workspace and moved it to current workspace"; fi
elif [[ $(hyprctl clients -j | jq -r ".[] | select(.class==\"$CLASS\" and .workspace.id==$ACTIVE_WORKSPACE)") ]]; then
hyprctl dispatch -- movetoworkspacesilent special:hdrop,"$CLASS" || notify "hdrop: Error moving '$COMMANDLINE' to workspace 'special:hdrop'"
if $VERBOSE; then notify_low "hdrop: Matched class '$CLASS' on current workspace and moved it to workspace 'special:hdrop'"; fi
else
$BACKGROUND $COMMANDLINE || notify "hdrop: Error executing given command" "$COMMANDLINE"
if $VERBOSE; then notify_low "hdrop: No running program matches class '$CLASS'" "Currently active classes are '$(hyprctl clients -j | jq -r '.[] | select(.mapped==true) | .class' | sort | tr '\n' ' ')'. Executed '$CLASS' in case it was not running already."; fi
fi
22 changes: 17 additions & 5 deletions hdrop/hdrop.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ hdrop - run, show and hide programs on Hyprland

*hdrop* [OPTIONS] [COMMAND]

# OPTIONS

*[COMMAND]*
# COMMAND
The usual command you would run to start the desired program

# OPTIONS

*-b, --background*
changes the default behaviour: if the specified program is not running, launch it in the background instead of foreground. Thereafter 'hdrop -b' will work the same as without this flag.
Changes the default behaviour: if the specified program is not running, launch it in the background instead of foreground. Thereafter 'hdrop -b' will work the same as without this flag.

*-i, --insensitive*
Case insensitive partial matching of class names. Can work as a stopgap if a running program is not recognized and a new instance is launched instead. Note: incorrect matches may occur, adding a special handling of the program to `hdrop` is preferable.

*-v, --verbose*
Show notifications regarding the matching process. Try this to figure out why running programs are not matched."

*-h, --help*
Print help message
Expand Down Expand Up @@ -57,7 +63,13 @@ If you want to run a program on boot and have it wait in the background until ca
exec-once = hdrop -b librewolf
```

Please feel free to report missing flags or peculiarities for other programs!
# Troubleshooting

If hdrop can't match an already running program and starts a new instance instead, then its class name is most likely different from its command name. For example, the class name of *telegram-desktop* is *org.telegram.desktop* and the class name of *logseq* is *Logseq*.

Run *hdrop -v [COMMAND]* in the terminal to see maximum output for troubleshooting and please report such peculiarities so that i can add them to hdrop. Using *hdrop -i [COMMAND]* might make it work in the meantime.

# License

Dependencies: bash jq hyprland
Part of: https://github.com/hyprwm/contrib
Expand Down

0 comments on commit 5cb203a

Please sign in to comment.