-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# i3-quiet | ||
|
||
Distraction free [i3](https://i3wm.org/) experience. | ||
|
||
## Why | ||
|
||
Sometimes my brain needs to dive into a *single threaded* activity such as writing a blog post, coding a small piece of a program, reading an article, and so on. While [fullscreen][1] fullfills some of my needs, sometimes it's not enough: I find fullscreen **too** full, especially when working on a large external display. I prefer to have some whitespace around my working window. | ||
|
||
That's the reason why I've created `i3-quiet`. It's a tool built on my preferences, but I'm open sourcing it since some other people might find it useful. Here is a screenshot of `i3-quiet` in action. | ||
|
||
![Screenshot or i3-quiet](./images/screenshot.png) | ||
|
||
## How | ||
|
||
`i3-quiet` moves the focused window to workspace `99`, it makes it smaller and centers it, and toggles the visibility of the status bar. Only one window can be in quiet mode. The window can be moved back to its original workspace with another command. | ||
|
||
This is accomplished by two scripts, one to enable *quiet-mode*, and another one to toggle the visibility of [polybar][2] (no support for `i3-bar` at the moment, feel free to make a PR if you need it). | ||
|
||
## Install | ||
|
||
Make sure to install [`i3ipc-python`][3], then copy the two python scripts to your `.config/i3` directory, and configure `i3`. I use `mod+q` to move a window to the quiet workspace, and `mod+shift+q` to move it back to its original place. (I use `mod+Shift+backslash` to kill the focused window.) | ||
|
||
My configuration looks like this: | ||
|
||
``` | ||
# Quiet mode | ||
bindsym $mod+q exec $HOME/.config/i3/quiet-cmd.py | ||
bindsym $mod+Shift+q exec $HOME/.config/i3/quiet-cmd.py toggle | ||
exec_always $HOME/.config/i3/quiet-toggle-bar.py | ||
``` | ||
|
||
[1]: https://i3wm.org/docs/userguide.html#_toggling_fullscreen_mode_for_a_window | ||
[2]: https://github.com/polybar/polybar/ | ||
[3]: https://github.com/altdesktop/i3ipc-python/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import json | ||
import subprocess | ||
|
||
ZEN_NUMBER = 99 | ||
ZEN_NAME = 'zen' | ||
|
||
WIDTH_PERC=50 | ||
MAX_WIDTH=800 | ||
HEIGHT_PERC=90 | ||
MAX_HEIGHT=1024 | ||
|
||
def enable_zen_mode(workspace_current, workspace_width, workspace_height): | ||
width = round(min(workspace_width * WIDTH_PERC / 100, MAX_WIDTH)) | ||
height = round(min(workspace_height * HEIGHT_PERC / 100, MAX_HEIGHT)) | ||
workspace_name = '{}: {}'.format(ZEN_NUMBER, workspace_current) | ||
return ';'.join([ | ||
'move container to workspace {}'.format(workspace_name), | ||
'workspace {}'.format(workspace_name), | ||
'floating enable', | ||
'border none', | ||
'resize set width {}'.format(width), | ||
'resize set height {}'.format(height), | ||
'move position center' | ||
]) | ||
|
||
def disable_zen_mode(workspace_previous): | ||
return ';'.join([ | ||
'move container to workspace {}'.format(workspace_previous), | ||
'workspace {}'.format(workspace_previous), | ||
'floating disable', | ||
'border normal' | ||
]) | ||
|
||
def goto_zen(workspace_name): | ||
return 'workspace {}'.format(workspace_name) | ||
|
||
out = subprocess.run(['i3-msg', '-t', 'get_workspaces'], capture_output=True) | ||
workspaces = json.loads(out.stdout) | ||
|
||
workspace_current = list(filter(lambda w: w['focused'], workspaces))[0] | ||
workspace_zen = list(filter(lambda w: w['num'] == ZEN_NUMBER, workspaces)) | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) > 1: | ||
if len(workspace_zen): | ||
msg = disable_zen_mode(workspace_zen[0]['name'].split(':')[1].strip()) | ||
else: | ||
if len(workspace_zen): | ||
msg = goto_zen(workspace_zen[0]['name']) | ||
else: | ||
msg = enable_zen_mode(workspace_current['num'], | ||
workspace_current['rect']['width'], | ||
workspace_current['rect']['height']) | ||
print(msg) | ||
subprocess.run(['i3-msg', msg]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from subprocess import run | ||
from i3ipc.aio import Connection | ||
from i3ipc import Event | ||
import asyncio | ||
|
||
async def main(): | ||
def on_event(self, e): | ||
if e.current.num == 99: | ||
run(['polybar-msg', 'cmd', 'hide']) | ||
elif e.old and e.old.num == 99: | ||
run(['polybar-msg', 'cmd', 'show']) | ||
|
||
c = await Connection(auto_reconnect=True).connect() | ||
workspaces = await c.get_workspaces() | ||
c.on(Event.WORKSPACE_FOCUS, on_event) | ||
await c.main() | ||
|
||
asyncio.get_event_loop().run_until_complete(main()) |