diff --git a/CHANGELOG.md b/CHANGELOG.md index 78465bb..0ff7166 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 2024-09-05 + +hdrop: add `--focus` option + ### 2024-09-01 hdrop: diff --git a/hdrop/README.md b/hdrop/README.md index b6181e5..0d5815e 100644 --- a/hdrop/README.md +++ b/hdrop/README.md @@ -26,6 +26,9 @@ This Bash script emulates the main features of [tdrop](https://github.com/noctui > -f, --floating > Spawn as a floating window. Standard is top half, full width, no gap. Can be adjusted with -g, -h, -p and -w. > +> -F, --focus +> Changes the default behaviour: focus the specified program's window and switch to its present workspace if necessary. Do not hide it, if it's already on the current workspace." +> > -g, --gap > If using --floating: specify gap to the screen edge in pixels. > @@ -54,7 +57,7 @@ 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](https://codeberg.org/dnkl/foot/) terminal emulator) +> `-a` | `--app-id` ([foot](https://codeberg.org/dnkl/foot/) terminal emulator) > `--class` (all other programs) #### Example bindings in Hyprland config: @@ -101,7 +104,7 @@ This is a known issue and no workaround is known to me. 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] +> exec-once = [workspace special:hdrop silent] hdrop [OPTIONS] [COMMAND] ## Installation diff --git a/hdrop/default.nix b/hdrop/default.nix index c8641e2..ff4a9b7 100644 --- a/hdrop/default.nix +++ b/hdrop/default.nix @@ -13,7 +13,7 @@ }: stdenvNoCC.mkDerivation { pname = "hdrop"; - version = "0.5.3"; + version = "0.6.0"; src = ./.; diff --git a/hdrop/hdrop b/hdrop/hdrop index 57976eb..e832b90 100755 --- a/hdrop/hdrop +++ b/hdrop/hdrop @@ -25,6 +25,11 @@ print_help() { echo " Standard is top half, full width, no gap." echo " Can be adjusted with -g, -h, -p and -w." echo "" + echo " -F, --focus" + echo " Changes the default behaviour: focus the specified program's" + echo " window and switch to its present workspace if necessary." + echo " Do not hide it, if it's already on the current workspace." + echo "" echo " -g, --gap" echo " If using --floating: specify gap to the screen edge in pixels." echo "" @@ -68,7 +73,7 @@ print_help() { } print_version() { - echo "hdrop version: 0.5.3" + echo "hdrop version: 0.6.0" } notify() { @@ -98,6 +103,9 @@ hdrop_flags() { -f | --floating) FLOATING=true ;; + -F | --focus) + FOCUS=true + ;; -g | --gap) shift GAP="$1" @@ -135,6 +143,7 @@ hdrop_flags() { } BACKGROUND="" +FOCUS=false GAP=0 INSENSITIVE=false FLOATING=false @@ -164,7 +173,7 @@ done # shellcheck disable=SC2128 # erroneous warning if [[ -n $HDROP_FLAGS ]]; then # shellcheck disable=SC2046 # avoids having to run 'eval set -- "$HDROP_FLAGS"' to remove leading whitespace - hdrop_flags $(getopt -u --options bc:fg:h:Hip:vVw: --longoptions background,class:,floating,gap:,height:,help,insensitive,position:,verbose,version,width: -n hdrop -- "${HDROP_FLAGS[@]}") + hdrop_flags $(getopt -u --options bc:fFg:h:Hip:vVw: --longoptions background,class:,floating,focus,gap:,height:,help,insensitive,position:,verbose,version,width: -n hdrop -- "${HDROP_FLAGS[@]}") fi CLASS="$1" @@ -263,13 +272,19 @@ if $FLOATING; then fi if [[ $(hyprctl clients -j | jq -r ".[] | select(.class==\"$CLASS\" and .workspace.id!=$ACTIVE_WORKSPACE)") ]]; then - # shellcheck disable=SC2140 # erroneous warning - hyprctl dispatch -- movetoworkspacesilent "$ACTIVE_WORKSPACE","^$CLASS$" || notify "hdrop: Error moving '$COMMANDLINE' to current workspace" + if [[ $FOCUS == false ]]; then + # shellcheck disable=SC2140 # erroneous warning + hyprctl dispatch -- movetoworkspacesilent "$ACTIVE_WORKSPACE","^$CLASS$" || notify "hdrop: Error moving '$COMMANDLINE' to current workspace" + if $VERBOSE; then notify_low "hdrop: Matched class '$CLASS' on another workspace and moved it to current workspace"; fi + fi 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 + if [[ $FOCUS == false ]]; 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 + hyprctl dispatch -- focuswindow "^$CLASS$" || notify "hdrop: Error focusing '$COMMANDLINE' on current workspace" + fi else # 'foot' always throws an error when its window is closed. Thus we disable the notification. if [[ $COMMAND == "foot" ]]; then diff --git a/hdrop/hdrop.1.scd b/hdrop/hdrop.1.scd index 07985be..e73acf5 100644 --- a/hdrop/hdrop.1.scd +++ b/hdrop/hdrop.1.scd @@ -22,6 +22,9 @@ hdrop - run, show and hide programs on Hyprland *-f, --floating* Spawn as a floating window. Standard is top half, full width, no gap. Can be adjusted with -g, -h, -p and -w. +*-F, --focus* + Changes the default behaviour: focus the specified program's window and switch to its present workspace if necessary. Do not hide it, if it's already on the current workspace." + *-g, --gap* If using --floating: specify gap to the screen edge in pixels.