move-window-to-current-workspace.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env -S bash -e
  2. # Klimbim Software collection, A bag full of things
  3. # Copyright (C) 2011-2023 Johannes 'Banana' Keßler
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. # 2023 https://www.bananas-playground.net
  18. # Get a window of a workspace indentified by a name
  19. # Not very safe in case of errors. Use at onw risk
  20. # needs xdotool, wmctrl, xprop, wmctrl
  21. if [ -z "$1" ]
  22. then
  23. echo "Missing string to search for"
  24. exit 1;
  25. fi
  26. WINDOWNAME_TO_SEARCH=$1
  27. CURRENT_WORKSPACE=$(xdotool get_desktop)
  28. HEX_ID=$(wmctrl -lx | grep -i ${WINDOWNAME_TO_SEARCH} | awk '{print $1}')
  29. WINDOW_ID=$(printf "%d" ${HEX_ID})
  30. # remember if it was maximized
  31. WINDOW_STAGE=$(xprop -id ${WINDOW_ID=} _NET_WM_STATE | awk '{ print $3 }')
  32. # Un-maximize current window so that it can be moved
  33. wmctrl -ir ${WINDOW_ID=} -b remove,maximized_vert,maximized_horz
  34. xdotool set_desktop_for_window ${WINDOW_ID} ${CURRENT_WORKSPACE} && xdotool windowactivate ${WINDOW_ID}
  35. # Maximize if it was before the move
  36. if [ "${WINDOW_STAGE=}" = "_NET_WM_STATE_MAXIMIZED_HORZ," ]; then
  37. wmctrl -ir ${WINDOW_ID=} -b add,maximized_vert,maximized_horz
  38. fi