Package: i3-sway-switch-window
i3-sway-switch-windowIn i3wm, or sway, replace currently focused window with emacs buffer, file from emacs recentf, browser window showing URL from a browser tab, or another window.
Can also place selected buffer window, recentf window, browser tab, or another window, adjacent to currently focused window.
Emacs buffer and file from emacs recentf are displayed with emacsclient. Currently only tested under Ubuntu 23.04.Installationpipxinstall-Ui3-sway-switch-windowIt is necessary to install with 'pipx' rather than 'pip', as a number of command line entry points are included in the package.Then you can runbrowser_tab-h
emacs_buffers-h
emacs_recentf-h
wm_window_switch-hTo uninstall the package run:pipxuninstalli3-sway-switch-windowInstall requirements:To use commands emacs_buffers and emacs_recentf, emacs must be running in server (daemon) mode. emacsclient must be available.To use browser_tab, brotab must be installed. Seehttps://github.com/balta2ar/brotabfor how to install the command line application.
You must also have the brotab browser extensiom installed in your browser, and enabled.Note that the brotab command line application 'bt', is currently unable to communicate with browsers installed via flatpak and snap.
On Ubuntu I have had success with the vivaldi browser. It is still possible to open the URLs with for example chrome.
Note 2023-06-22: bt now works also with chrome on Ubuntu.The browser_tab command can be configured to display in for example chrome and vivaldi. It can also be configured to display in the nyxt browser, see the details in the config example below.Beside getting info from brotab, browser_tab can be configured to also get info from the nyxt browser, but that requires some extra configuration. See below.The i3-sway-switch-window applications expect to find a configuration file in "i3_sway_switch_window/config.ini" in your config directory.
The file can be empty.A sample config.ini is:[roficommand]# Default is "rofi -dmenu"roficommand=/usr/local/bin/rofi-dmenu[webbrowser]# Default is "vivaldi"webbrowser=google-chrome# commandlineoptions is default --new-window# urlprefix is default empty# urlsuffix is default empty# Config for displaying in the nyxt browser:# webbrowser = nyxt# commandlineoptions = -r -q -e# urlprefix = '(make-window (make-buffer :url "# urlsuffix = "))'## Besides this the following is needed in nyxt config# (define-configuration browser#   (#    ;; Whether code sent to the socket gets executed.  You must understand the#    ;; risks before enabling this: a privileged user with access to your system#    ;; can then take control of the browser and execute arbitrary code under your#    ;; user profile.#    (remote-execution-p t)))# Should we try to get a list of titles and URLs from nyxt webbrowser.# There are some requirements: See the project README.# default is noget_urls_from_nyxt=yes# Config for displaying in qutebrowser:# webbrowser = qutebrowser# commandlineoptions = --target window# Should we try to get a list of titles and URLs from qutebrowser.# There are some requirements: See the project README.# default is noget_urls_from_qutebrowser=yes[workspace]# i3, or sway, workspace to which focused window will be swapped# Default is "2"swap_workspace=9How to useThe commands can be run from the command line. They can also be part of the i3, or sway, configuration.
Here are some sample lines from my i3 configuration file:# get wm window names, select one, display at current desktop windowbindsym$mod+wexec~/.local/bin/wm_window_switchswap# get wm window names, select one, display next to current desktop windowbindsym$mod+Shift+wexec~/.local/bin/wm_window_switchadd# get web browser tab titles and URLs, select one, display at current desktop windowbindsym$mod+uexec~/.local/bin/browser_tabswap# get web browser tab titles and URLs, select one, display next to current desktop windowbindsym$mod+Shift+uexec~/.local/bin/browser_tabadd# get current buffers from emacs, select one, display at current desktop windowbindsym$mod+bexec~/.local/bin/emacs_buffersswap# get current buffers from emacs, select one, display next to current desktop windowbindsym$mod+Shift+bexec~/.local/bin/emacs_buffersadd# get recentf list from emacs, select one, display at current desktop windowbindsym$mod+rexec~/.local/bin/emacs_recentfswap# get recentf list from emacs, select one, display next to current desktop windowbindsym$mod+Shift+rexec~/.local/bin/emacs_recentfaddNote for sway: An alternative to wm_window_switch is to use swayr command 'swap-focused-with', seehttps://sr.ht/~tsdh/swayrRequirements to get info from the nyxt browseri3-sway-switch-window currently uses emacsclient and emacs server to communicate with nyxt.
This is a stopgap measure until a simpler means of getting info from nyxt, has been implemented.browser_tab will attempt to get info from nyxt, only if nyxt is running.
The check for a running nyxt is done using python package psutil.emacs currently uses a modified version ofhttps://github.com/ag91/emacs-with-nyxtto communicate with nyxt,
as the version in the ag91 repo seems to be for an older version of nyxt (the elisp file is dated 230327).
You can find the modified version of 'emacs-with-nyxt.el' here:emacs-with-nyxt.elA few functions have been commented out, and the require for 'sly' has been uncommented.In my emacs config I have the following code to load 'emacs-with-nyxt.el':(defunload-emacs-with-nyxt()(interactive)(load"/home/someuser/.config/doom/emacs-with-nyxt.el"))You need to add this (with the correct file path), to your emacs config, if you do not load 'emacs-with-nyxt.el' at start of emacs.Nyxt must also be configured to start a 'slynk' server. To do this add the line:(start-slynk)to your nyxt config.Developer infoTo build the package:Download the repo. E.g. git clonehttps://github.com/johanwiden/i3-sway-switch-window.gitCreate a virtual environment, for development. E.g. with condaconda create --name i3envconda activate i3envconda install -c anaconda pippip install i3ipc
This is a package dependencypip install psutil
This is a package dependencypip install pyyaml
This is a package dependencypip install build
This is the tool to build the package.Change directory to the downloaded repopython3 -m build
This should build the package, the result is stored in subdirectory 'dist'Running the applicationsOne can execute the entry points directly in the development environment, from the repo directory, without installing the package:python3 -c "import i3_sway_switch_window.main; import sys; sys.argv = [sys.argv[0]] + ['swap']; i3_sway_switch_window.main.cli_browser_tab()"python3 -c "import i3_sway_switch_window.main; import sys; sys.argv = [sys.argv[0]] + ['--browser','google-chrome','add']; i3_sway_switch_window.main.cli_browser_tab()"python3 -c "import i3_sway_switch_window.main; import sys; sys.argv = [sys.argv[0]] + ['--config','foo']; i3_sway_switch_window.main.cli_browser_tab()"python3 -c "import i3_sway_switch_window.main; import sys; sys.argv = [sys.argv[0]] + ['--version']; i3_sway_switch_window.main.cli_browser_tab()"To test installation of the package:From outside the virtual environment, or in a different virtual environment:Install pipx, if it is not already installed.pipx ensurepath
Ensure directories necessary for pipx operation are in your PATH environment variable.pipx install --force PATH-TO-REPO/dist/i3_sway_switch_window-0.1.0.tar.gzOne should now be able to execute the apps. They are usually stored in ~/.local/bin.📈 ReleasesYou can see the list of available releases on theGitHub Releasespage.We followSemantic Versionsspecification.We useRelease Drafter. As pull requests are merged, a draft release is kept up-to-date listing the changes, ready to publish when you’re ready. With the categories option, you can categorize pull requests in release notes using labels.List of labels and corresponding titlesLabelTitle in Releasesenhancement,feature🚀 Featuresbug,refactoring,bugfix,fix🔧 Fixes & Refactoringbuild,ci,testing📦 Build System & CI/CDbreaking💥 Breaking Changesdocumentation📝 Documentationdependencies⬆️ Dependencies updatesYou can update it inrelease-drafter.yml.GitHub creates thebug,enhancement, anddocumentationlabels for you. Dependabot creates thedependencieslabel. Create the remaining labels on the Issues tab of your GitHub repository, when you need them.🛡 LicenseThis project is licensed under the terms of theMITlicense. SeeLICENSEfor more details.📃 Citation@misc{i3-sway-switch-window,author={Johan Widén},title={In i3wm replace current window with emacs buffer, emacs recentf file, or browser tab},year={2023},publisher={GitHub},journal={GitHub repository},howpublished={\url{https://github.com/johanwiden/i3-sway-switch-window}}}