Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Schweber committed Jan 14, 2024
1 parent d0c5cda commit 528e8b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This Bash script emulates the main features of [tdrop](https://github.com/noctui
> Set classname of the program to be run. Use this if the classname is different from the name of the [COMMAND] and hdrop has not yet a hardcoded replacement.
>
> -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.
> 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 (hardcoded or via `-c, --class`) is preferable.
>
> -v, --verbose
> Show notifications regarding the matching process. Try this to figure out why running programs are not matched.
Expand Down
20 changes: 9 additions & 11 deletions hdrop
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ print_help() {
}

print_version() {
echo "hdrop version: 0.3.1"
echo "hdrop version: 0.4.0"
}

notify() {
Expand All @@ -72,22 +72,20 @@ hdrop_flags() {
;;
-b | --background)
BACKGROUND="hyprctl dispatch -- exec [workspace special:hdrop silent] "
shift
;;
-c | --class)
CLASS_OVERRIDE="$2"
shift 2
shift
CLASS_OVERRIDE="$1"
;;
-i | --insensitive)
INSENSITIVE=true
shift
;;
-v | --verbose)
VERBOSE=true
shift
;;
*) break ;;
esac
shift
done
}

Expand All @@ -102,14 +100,14 @@ while true; do
;;
-c | --class)
HDROP_FLAGS+=("$1" "$2")
shift 2
shift
;;
-*)
HDROP_FLAGS+=("$1")
shift
;;
*) break ;;
esac
shift
done

BACKGROUND=""
Expand All @@ -118,7 +116,7 @@ VERBOSE=false

# shellcheck disable=SC2128
if [[ -n $HDROP_FLAGS ]]; then
# shellcheck disable=SC2046
# shellcheck disable=SC2046 # avoids having to run 'eval set -- "$HDROP_FLAGS"' to remove leading whitespace
hdrop_flags $(getopt --options bc:ivVh --longoptions background,class:,insensitive,verbose,version,help -n hdrop -- "${HDROP_FLAGS[@]}")
fi

Expand All @@ -144,7 +142,7 @@ telegram-desktop)
esac

if [[ -n $OPT ]]; then
eval set -- "$OPT"
eval set -- "$OPT" # remove leading whitespace
case "$1" in
-a | --class)
CLASS="$2"
Expand Down Expand Up @@ -173,5 +171,5 @@ elif [[ $(hyprctl clients -j | jq -r ".[] | select(.class==\"$CLASS\" and .works
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 '$COMMANDLINE' in case it was not running already."; fi
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 '$COMMANDLINE' in case it was not running already."; fi
fi
16 changes: 8 additions & 8 deletions hdrop.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hdrop - run, show and hide programs on Hyprland
Set classname of the program to be run. Use this if the classname is different from the name of the [COMMAND] and hdrop has not yet a hardcoded replacement.

*-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.
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* (hardcoded or via *-c, --class*) is preferable.

*-v, --verbose*
Show notifications regarding the matching process. Try this to figure out why running programs are not matched."
Expand All @@ -43,36 +43,36 @@ This script emulates the main features of [tdrop](https://github.com/noctuid/tdr

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).
```
*

# 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'
```
*

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
```
*

# 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 find out the actual class name. Then use *hdrop -c CLASSNAME* to make it work. *hdrop -i [COMMAND]* might be sufficient, as long as a case insensitive (partial) match is sufficient.

Please report instances of programs with differing class names, so that i can add them to `hdrop`.
Please report instances of programs with differing class names, so that i can add them to *hdrop*.

# License

Expand Down

0 comments on commit 528e8b4

Please sign in to comment.