Skip to content

Commit

Permalink
hdrop: 0.5.0 -> 0.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Schweber committed Sep 1, 2024
1 parent 9d67858 commit ec1ac0b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 44 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

### 2024-09-01

hdrop:
- add class replacement for epiphany and godot
- refactor
- cleanup
- add recognition of `--app-id` for foot
- disable error notifications when closing foot

### 2024-08-02

grimblast: changed method to check if another instance is running
Expand Down
33 changes: 24 additions & 9 deletions hdrop/README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ This Bash script emulates the main features of [tdrop](https://github.com/noctui
> -c, --class
> Set classname of the program to be run. Use this if the classname is different from the name of the [COMMAND] and hdrop does not have a hardcoded replacement.
>
> -f, --floating
> -f, --floating
> Spawn as a floating window. Standard is top half, full width, no gap. Can be adjusted with -g, -h, -p and -w.
>
> -g, --gap
> -g, --gap
> If using --floating: specify gap to the screen edge in pixels.
>
> -h, --height
> -h, --height
> If using --floating: set the height of the window. Enter percentage value without % sign, e.g. '30'.
>
> -H, --help
Expand All @@ -38,7 +38,7 @@ This Bash script emulates the main features of [tdrop](https://github.com/noctui
> -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 (hardcoded or via `-c, --class`) is preferable.
>
> -p, --position
> -p, --position
> If using --floating: set the position of the window. One of: '[t]op' '[b]ottom' '[l]eft' '[r]ight'.
>
> -v, --verbose
Expand All @@ -47,7 +47,7 @@ This Bash script emulates the main features of [tdrop](https://github.com/noctui
> -V, --version
> Print version
>
> -w, --width
> -w, --width
> If using --floating: set the width of the window. Enter percentage value without % sign, e.g. '30'.
#### Multiple instances:
Expand Down Expand Up @@ -75,7 +75,7 @@ If you want to run a program on boot and have it wait in the background until ca

### Cursor jumps to newly focused windows

Set `no_cursor_warps = true` in `hyprland.conf` section [general](https://wiki.hyprland.org/Configuring/Variables/#general)
Set `no_warps = true` in `hyprland.conf` section [cursor](https://wiki.hyprland.org/Configuring/Variables/#cursor).

### Further instances of programs are started instead of hiding/unhiding a running instance

Expand All @@ -85,10 +85,24 @@ Run `hdrop -v [COMMAND]` _in the terminal_ to see maximum output for troubleshoo

Please report instances of programs with differing class names, so that they can be added to `hdrop`.

### Floating windows don't react to changed arguments
### Windows freeze when being called up from another workspace

This happens sometimes and will apparently be fixed in hyprland 0.43

### `--floating` windows don't react to changed arguments in hdrop

Close the program (don't just hide it with hdrop). The changed arguments are only applied when the program is restarted.

### `--floating` windows animation is only shown when the window is opened for the first time

This is a known issue and no workaround is known to me.

### `hdrop -b` is not working when used for autostart

If hdrop isn't installed but just added to PATH, then you might have to use this instead:

> exec-once = [workspace special:hdrop silent] hdrop [OPITONS] [COMMAND]
## Installation

### Repositories
Expand All @@ -97,11 +111,12 @@ Close the program (don't just hide it with hdrop). The changed arguments are onl

### Manual

Make sure that `bash` and `jq` are in your PATH.
Make sure that `bash`, `jq` and `awk` (for using the `--floating` option) are in your PATH.

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

Note: `hdrop` will only work in a `Hyprland` session. `exec-once = hdrop -b` might not work with this installation method.
Note: `hdrop` will only work in a `Hyprland` session.
`exec-once = hdrop -b` might not work with this installation method.

### Makefile

Expand Down
38 changes: 21 additions & 17 deletions hdrop/default.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
coreutils,
gawk,
hyprland,
jq,
lib,
stdenvNoCC,
libnotify,
makeWrapper,
scdoc,
coreutils,
stdenvNoCC,
util-linux,
jq,
libnotify,
withHyprland ? true,
hyprland,
gawk,
}:
stdenvNoCC.mkDerivation {
pname = "hdrop";
version = "0.5.0";
version = "0.5.2";

src = ./.;

Expand All @@ -22,18 +22,22 @@ stdenvNoCC.mkDerivation {
scdoc
];

makeFlags = ["PREFIX=$(out)"];
makeFlags = [ "PREFIX=$(out)" ];

postInstall = ''
wrapProgram $out/bin/hdrop --prefix PATH ':' \
"${lib.makeBinPath ([
coreutils
util-linux
jq
libnotify
gawk
]
++ lib.optional withHyprland hyprland)}"
"${
lib.makeBinPath (
[
coreutils
util-linux
jq
libnotify
gawk
]
++ lib.optional withHyprland hyprland
)
}"
'';

meta = with lib; {
Expand All @@ -42,7 +46,7 @@ stdenvNoCC.mkDerivation {
changelog = "https://github.com/Schweber/hdrop/releases/tag/v${version}";
license = licenses.agpl3Only;
platforms = platforms.linux;
maintainers = with maintainers; [Schweber];
maintainers = with maintainers; [ Schweber ];
mainProgram = "hdrop";
};
}
43 changes: 30 additions & 13 deletions hdrop/hdrop
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ print_help() {
}

print_version() {
echo "hdrop version: 0.5.0"
echo "hdrop version: 0.5.3"
}

notify() {
Expand All @@ -81,12 +81,9 @@ notify_low() {
echo "$@"
}

BACKGROUND=""
GAP=0
INSENSITIVE=false
FLOATING=false
POSITION="top"
VERBOSE=false
partial_match() {
CLASS=$(hyprctl clients -j | jq -r ".[] | select((.class |match(\"$1\";\"i\"))) | .class" | head -1)
}

hdrop_flags() {
while true; do
Expand Down Expand Up @@ -137,6 +134,12 @@ hdrop_flags() {
done
}

BACKGROUND=""
GAP=0
INSENSITIVE=false
FLOATING=false
POSITION="top"
VERBOSE=false
HDROP_FLAGS=()

while true; do
Expand Down Expand Up @@ -165,12 +168,19 @@ if [[ -n $HDROP_FLAGS ]]; then
fi

CLASS="$1"
COMMAND="$1"
COMMANDLINE="${*:1}"
ACTIVE_WORKSPACE="$(hyprctl activeworkspace -j | jq -r .id)" || notify "hdrop: Error executing dependencies 'hyprctl' or 'jq'" "Check terminal output of 'hdrop $COMMANDLINE'"

case "$1" in
epiphany)
CLASS="org.gnome.Epiphany"
;;
foot)
OPT=$(getopt --options a: -n hdrop -- "$@")
OPT=$(getopt --options a: --longoptions app-id: -n hdrop -- "$@")
;;
godot4)
partial_match "org.godotengine."
;;
logseq)
CLASS="Logseq"
Expand All @@ -182,7 +192,7 @@ tor-browser)
CLASS="Tor Browser"
;;
*)
OPT=$(getopt --longoptions class: -n hdrop -- "$@")
OPT=$(getopt --options "" --longoptions class: -n hdrop -- "$@")
;;
esac

Expand All @@ -191,7 +201,7 @@ if $VERBOSE && [[ $1 -ne $CLASS ]]; then notify_low "hdrop: Using '$CLASS' as ha
if [[ -n $OPT ]]; then
eval set -- "$OPT" # remove leading whitespace
case "$1" in
-a | --class)
-a | --app-id | --class)
CLASS="$2"
if $VERBOSE; then notify_low "hdrop: Extracted '$CLASS' from [COMMAND] for matching"; fi
;;
Expand All @@ -200,7 +210,7 @@ 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"
partial_match "$CLASS" || 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

Expand All @@ -214,6 +224,7 @@ if $FLOATING; then
ACTIVE_MONITOR_WIDTH=$(($(hyprctl monitors -j | jq -r ".[] | select(.focused==true) | .width") * 100))
ACTIVE_MONITOR_HEIGHT=$(($(hyprctl monitors -j | jq -r ".[] | select(.focused==true) | .height") * 100))
ACTIVE_MONITOR_SCALE=$(awk "BEGIN {printf $(hyprctl monitors -j | jq -r ".[] | select(.focused==true) | .scale") * 100}")

ACTIVE_MONITOR_WIDTH_SCALED=$(($ACTIVE_MONITOR_WIDTH / $ACTIVE_MONITOR_SCALE))
ACTIVE_MONITOR_HEIGHT_SCALED=$(($ACTIVE_MONITOR_HEIGHT / $ACTIVE_MONITOR_SCALE))
fi
Expand Down Expand Up @@ -260,7 +271,13 @@ elif [[ $(hyprctl clients -j | jq -r ".[] | select(.class==\"$CLASS\" and .works
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
# shellcheck disable=SC2086 # quoting COMMANDLINE=foot -a foot_1 doesn't work
$BACKGROUND $COMMANDLINE || notify "hdrop: Error executing given command" "$COMMANDLINE"
# 'foot' always throws an error when its window is closed. Thus we disable the notification.
if [[ $COMMAND == "foot" ]]; then
# shellcheck disable=SC2086 # when quoting COMMANDLINE the execution of the command fails
$BACKGROUND $COMMANDLINE
else
# shellcheck disable=SC2086 # when quoting COMMANDLINE the execution of the command fails
$BACKGROUND $COMMANDLINE || notify "hdrop: Error executing given command" "$COMMANDLINE"
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
10 changes: 5 additions & 5 deletions hdrop/hdrop.1.scd
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ Multiple instances of the same program can be run concurrently, if different cla
# 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.
Expand Down

0 comments on commit ec1ac0b

Please sign in to comment.