OSDN Git Service

dswitch accept arguments
[instantos/instantOS.git] / dswitch
1 #!/bin/bash
2
3 ##############################################
4 ## dwm popup to choose between open windows ##
5 ## does not change to respective monitor    ##
6 ##############################################
7
8 if ! [ -n "$1" ]; then
9     # Date format, for use as the prompt.
10     date=$(date +"%a %d. %b %R")
11
12     # dmenu cannot display more than 30 lines, to avoid screen clutter. Only relevant if you have more than 30 windows open.
13     height=$(wmctrl -l | wc -l)
14     if [[ $height -gt 30 ]]; then
15         heightfit=30
16     else
17         heightfit=$height
18     fi
19
20     num=$(wmctrl -l | sed 's/  / /' | cut -d " " -f 4- | nl -w 3 -n rn | sed -r 's/^([ 0-9]+)[ \t]*(.*)$/\1 - \2/' | dmenu -b -i -p "$date" -l $heightfit | cut -d '-' -f -1)
21     [[ -z "$num" ]] && exit
22
23     WID=$(wmctrl -l | sed -n "$num p" | cut -c -10)
24 else
25     WID="$1"
26 fi
27
28 echo "focus target $WID"
29
30 focuswin() {
31     [[ $1 =~ "," ]] && echo "error focussing" && return 1
32     wmctrl -i -a "$1"
33 }
34
35 if ! [ -e ~/paperbenni/ismultimonitor ]; then
36     focuswin "$WID"
37     echo "exiting"
38     exit
39 fi
40
41 getmonitor() {
42     XPOS=$(xdotool getwindowfocus getwindowgeometry | grep -Eoi 'position.*,' | grep -o '[0-9]*')
43     if [ "$XPOS" -gt "1919" ]; then
44         echo "1"
45     else
46         echo "0"
47     fi
48 }
49
50 OLDWID=$(pfw)
51 focuswin "$WID"
52
53 if [ "$(pfw)" = "$WID" ]; then
54     exit
55 else
56     if ! [ "$(pfw)" = "$OLDWID" ]; then
57         if ! [ "$OLDWID" = "0x000001e1" ]; then
58             xdotool key "super+Tab"
59         fi
60     fi
61     xdotool key "super+comma"
62     focuswin "$WID"
63 fi