Floating "Calculator" Window in Sway
For a while now, I’ve wanted a quick way to do arithmetic on my Linux laptop (which runs Sway), similar to Spotlight on OS X.
If I’m already in a terminal, it’s easy. But sometimes I’m focused on some other app, and I want to make a quick calculation.
So, in .config/sway/config.d/60-bindings-interactive-python.conf, I have:
for_window [app_id="terminal-floating"] floating enable
bindsym $mod+Semicolon exec '$term --app-id=terminal-floating python3 -q'
- The first line ensures windows with the given app-id (
terminal-floating) will be shown as floating windows. - The second line adds a key binding that runs
python3 -qin a new terminal window.- The
--app-idflag will differ between terminal emulators. I’m using foot. - The
-qflag suppresses the default version and copyright messages. - Control+
dcloses the window when you’re done.
- The
Alternatives
- The choice of
python3is personal – I picked it because I’m familiar with it. You could do the exact same thing withbc -q, for example. - rofi-calc also looks nice. (Though in this case, I don’t want to add another dependency to my desktop environment.)
Previous Post: Terminal Bell as Notification Mechanism