diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-04-15 10:26:52 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-04-15 10:26:52 +0200 |
| commit | 1697e03a03a3860633cf695139df77d37da4703e (patch) | |
| tree | fef579a6698c62fd7cb5e0fc2f8d6158a2398907 | |
| parent | 4ccdc231b3fb4cc3a9c9aad626de46a32bc9a628 (diff) | |
| download | dotfiles-1697e03a03a3860633cf695139df77d37da4703e.tar.gz dotfiles-1697e03a03a3860633cf695139df77d37da4703e.zip | |
sway: add present script, workspace and key bindings
| -rw-r--r-- | config/sway/config | 7 | ||||
| -rwxr-xr-x | scripts/present.sh | 13 | ||||
| -rwxr-xr-x | scripts/sway-toolwait | 134 |
3 files changed, 153 insertions, 1 deletions
diff --git a/config/sway/config b/config/sway/config index d2a9580..76135ca 100644 --- a/config/sway/config +++ b/config/sway/config @@ -114,7 +114,7 @@ input "1:1:AT_Translated_Set_2_keyboard" { bindsym $mod+Shift+b exec rofi-bibbrowser # start wofi-pass - bindsym $mod+p exec wofi-pass + bindsym $mod+$alt+p exec wofi-pass # start vocosma-wofi-pass bindsym $mod+$alt+v exec vocosma-wofi-pass -1 @@ -136,6 +136,9 @@ input "1:1:AT_Translated_Set_2_keyboard" { # open primary selection in browser bindsym $mod+Shift+o exec $DOTFILES_LOCATION/scripts/open_primary_in_browser.sh + # presentation related commands + bindsym $mod+Shift+m exec $DOTFILES_LOCATION/scripts/present.sh mirror + # # Moving around: # @@ -174,6 +177,7 @@ input "1:1:AT_Translated_Set_2_keyboard" { bindsym $mod+8 workspace 8:mail bindsym $mod+9 workspace 9:music bindsym $mod+0 workspace 10 + bindsym $mod+p workspace P # move focused container to workspace bindsym $mod+Shift+1 move container to workspace 1 bindsym $mod+Shift+2 move container to workspace 2:www @@ -202,6 +206,7 @@ input "1:1:AT_Translated_Set_2_keyboard" { workspace "7" output eDP-1 workspace "8:mail" output eDP-1 workspace "9:music" output eDP-1 + workspace P output HDMI-A-1 # # Layout stuff: diff --git a/scripts/present.sh b/scripts/present.sh new file mode 100755 index 0000000..045af6d --- /dev/null +++ b/scripts/present.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ "$1" = "mirror" ]; then + swaymsg "workspace P" + "${DOTFILES_LOCATION}"/scripts/sway-toolwait -w at.yrlf.wl_mirror wl-mirror eDP-1 + swaymsg "fullscreen" +elif [ -f "$1" ]; then + "${DOTFILES_LOCATION}"/scripts/sway-toolwait pdfpc "$1" + swaymsg "[title=\"pdfpc - presentation ()\"] focus" && \ + swaymsg "move window to workspace P" && \ + swaymsg "workspace P" && \ + swaymsg "[title=\"pdfpc - presenter ()\"] focus" +fi diff --git a/scripts/sway-toolwait b/scripts/sway-toolwait new file mode 100755 index 0000000..562cc49 --- /dev/null +++ b/scripts/sway-toolwait @@ -0,0 +1,134 @@ +#!/usr/bin/env -S python3 -B +# https://gitlab.com/wef/dotfiles/-/blob/master/bin/sway-toolwait +TIME_STAMP="20230321.220111" + +# dependencies: i3ipc: https://i3ipc-python.readthedocs.io/en/latest/ + +# Copyright (C) 2020-2022 Bob Hepple <bob dot hepple at gmail dot com> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from i3ipc import Connection +import argparse +import subprocess, sys +import time +from multiprocessing import Process + +sys.dont_write_bytecode = True + +global parser, i3, retval, args, start_time + +def verbose(msg): + if args.verbose: + elapsed_time = time.time() - start_time + print(f"{elapsed_time}s: {parser.prog}: {msg}") + +def sleep_and_run_command(): + "This runs in a separate process" + s = 0.1 # just enough to let i3ipc.main() loop start + verbose(f"Runner process sleeping for {s}s") + time.sleep(s) + verbose(f"Running: {args.command}") + # perhaps a simple fork/spawn here would suffice (and be quicker?) + subprocess.Popen(args.command) + +def on_window(i3, e): + "callback function from i3ipc.main() loop" + verbose(f"Got a {e.change} window event:") + if e.ipc_data['container']['app_id']: + verbose(f"app_id: {e.ipc_data['container']['app_id']}") + else: + verbose(f"Class: {e.ipc_data['container']['window_properties']['class']}, instance: {e.ipc_data['container']['window_properties']['instance']}") + + waitfor = args.command[0] + if args.waitfor: + waitfor = args.waitfor + + finished = False + if args.nocheck: + finished = True + else: + if e.ipc_data['container']['app_id']: + new_window = e.ipc_data['container']['app_id'] + else: + new_window = e.ipc_data['container']['window_properties']['instance'] + if new_window == waitfor: + verbose(f"a new window for '{waitfor}' appeared") + finished = True + else: + verbose(f"a new window appeared '{new_window}' but I'm waiting for '{waitfor}'") + + if finished: + i3.main_quit() # else continue to wait + +if __name__ == "__main__": + + parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, + description=""" +Run 'command', wait for a window to open, then exit. If no window +appears in 'timeout' seconds (eg by running a non-GUI program like +'date') then terminate. +""", + epilog="""eg. + + %(prog)s firefox # this gives time for the window to be created before: + swaymsg -q "floating disable; border none" + +To run more complex commands use "--". eg. + + %(prog)s -- bash -c "some complex bash commands" + +This may be similar to the ancient Sun OpenWindows command toolwait or +the X11 version at +http://www.ibiblio.org/pub/linux/X11/xutils/toolwait-0.9.tar.gz + """) + parser.add_argument('-n', '--nocheck', dest='nocheck', action='store_true', + help='don\'t check that the window that opens is for that command (default = %(default)s)') + parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='verbose operation') + parser.add_argument('-m', '--mark', dest='mark', type=str, help='mark to add to window', default='') + parser.add_argument('-t', '--timeout', dest='timeout', type=float, help='timeout (default = %(default)s secs)', default=30.0) + parser.add_argument('-w', '--waitfor', dest='waitfor', help='app_id (wayland) or instance string (xwayland) to wait for') + parser.add_argument('command', nargs='+', help='command to run') + args = parser.parse_args() + + i3 = Connection() + i3.on('window::new', on_window) + + retval = 1 + start_time = time.time() + # run the command without waiting ie in background: + Process(target=sleep_and_run_command).start() + i3.main(timeout=args.timeout) + + # i3ipc gives no indication that a timeout has occured, so check the clock: + elapsed_time = time.time() - start_time + if elapsed_time <= args.timeout: + verbose(f"'{args.command} took {elapsed_time}secs to create its first window") + retval = 0 + else: + verbose(f"timed out after {args.timeout} secs") + + if args.mark != '': + mark_cmd = f'swaymsg -q mark "{args.mark}"' + verbose(f"Running: {mark_cmd}") + subprocess.run([mark_cmd], shell=True) + + verbose(f"terminated, retval={retval}") + sys.exit(retval) + +# Local variables: +# mode: python +# time-stamp-pattern: "4/TIME_STAMP=\"%:y%02m%02d.%02H%02M%02S\"" +# eval: (add-hook 'before-save-hook 'time-stamp) +# End: |
