Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimize window if already focused #41

Merged
merged 3 commits into from
Apr 7, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

-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
xdotool getactivewindow windowminimize
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be able to unit test this, instead of directly calling:

xdotool getactivewindow windowminimize

You could declare a new function near the bottom of the file:

minimize_active_window() {
  xdotool getactivewindow windowminimize
}

Then call it from here. That would make it easy to unit test this.

elif (( ${#windowids[@]} )) && ! needs_passthrough "$@"; then
local window=$(get_subsequent_window "${windowids[@]}")
if [[ -n "$keep_workspace" ]]; then
Expand Down