Skip to content

Commit

Permalink
Merge pull request #41 from matklad/m-for-minimize
Browse files Browse the repository at this point in the history
minimize window if already focused
  • Loading branch information
mkropat authored Apr 7, 2019
2 parents 66c94d3 + e50ffa5 commit dba1062
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
13 changes: 11 additions & 2 deletions jumpapp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Otherwise, launch COMMAND (with opitonal ARGs) to start the application.
Options:
-r -- cycle through windows in reverse order
-f -- force COMMAND to launch if process found but no windows found
-m -- if a single window is already open and in focus - minimize it
-n -- do not fork into background when launching COMMAND
-p -- always launch COMMAND when ARGs passed
(see Argument Passthrough in man page)
Expand All @@ -25,16 +26,17 @@ Options:
}

main() {
local classid cmdid force fork=1 list passthrough in_reverse matching_title workspace_filter mouse_center
local classid cmdid force fork=1 list passthrough focusOrMinimize in_reverse matching_title workspace_filter mouse_center

local OPTIND
while getopts c:fhi:Lnprt:wRC opt; do
while getopts c:fhi:Lmnprt:wRC opt; do
case "$opt" in
c) classid="$OPTARG" ;;
f) force=1 ;;
h) show_usage; exit 0 ;;
i) cmdid="$OPTARG" ;;
L) list=1 ;;
m) focusOrMinimize=1 ;;
n) fork='' ;;
p) passthrough=1; force=1 ;; # passthrough implies force
r) in_reverse=1 ;;
Expand Down Expand Up @@ -85,6 +87,9 @@ jumpapp() {
if [[ -n "$list" ]]; then
printf 'Matched Windows [%d]\n' ${#windowids[@]}
list_matching_windows "$classid" "${pids[@]}" | print_windows
elif [[ -n "$focusOrMinimize" ]] && [[ ${#windowids[@]} -eq "1" ]] \
&& [[ "$(get_active_windowid)" -eq "${windowids[0]}" ]]; then
minimize_active_window
elif (( ${#windowids[@]} )) && ! needs_passthrough "$@"; then
local window=$(get_subsequent_window "${windowids[@]}")
if [[ -n "$keep_workspace" ]]; then
Expand Down Expand Up @@ -393,6 +398,10 @@ center_cursor() {
xdotool mousemove -w "$1" $(wmctrl -lG | grep "$1" | awk '{ print $5/2 " " $6/2 }')
}

minimize_active_window() {
xdotool getactivewindow windowminimize
}

has_command() {
hash "$1" 2>/dev/null
}
Expand Down
25 changes: 25 additions & 0 deletions t/test_jumpapp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ setUp() {
activate_window_arg=
center_cursor_called=
center_cursor_arg=
minimize_active_window_called=
die_called=
exec_command_called=
focus_window_by_class_called=
Expand Down Expand Up @@ -364,6 +365,26 @@ it_prints_matching_windows_when_called_with_-L() {
[[ "$output" == *"678 somehost 123 -1 someapp: SomeApp Window #2"* ]] || fail 'Output does not list Window #2'
}

it_calls_minimize_active_window_when_called_with_-m_and_window_is_active() {
active_windowid=456
list_windows_output='456 somehost 123 -1 someapp
567 somehost 234 -1 anotherapp AnotherApp Window'
main -m someapp

assertNotNull 'minimize_active_window() called' "$minimize_active_window_called"
}

it_calls_activate_window_when_called_with_-m_but_the_window_is_not_active() {
active_windowid=567
list_windows_output='456 somehost 123 -1 someapp
567 somehost 234 -1 anotherapp AnotherApp Window'
main -m someapp

assertNull 'minimize_active_window() not called' "$minimize_active_window_called"
assertNotNull 'i() called' "$activate_window_called"
assertEquals 456 "$activate_window_arg"
}

##### Test Doubles #####

source ./jumpapp # load app now, so we can override it
Expand Down Expand Up @@ -420,6 +441,10 @@ center_cursor() {
center_cursor_arg=$1
}

minimize_active_window() {
minimize_active_window_called=1
}

has_command() {
return "$has_command_val"
}
Expand Down

0 comments on commit dba1062

Please sign in to comment.