Improve configs and minor bugs.
This commit is contained in:
@@ -1,136 +1,174 @@
|
||||
# ==== State ====
|
||||
system 'bash ~/main/ocaml/epq/scripts/startup.sh >/dev/null 2>&1 &'
|
||||
|
||||
MAX_PROJECTS = 9
|
||||
SUBS = 2 # workspaces per project
|
||||
|
||||
$current_project = 1 # 1..MAX_PROJECTS
|
||||
$current_sub = 0 # 0..SUBS-1
|
||||
|
||||
# For each special workspace, remembers which workspace you were on
|
||||
# before you jumped into it -- so hitting the mode key again toggles back.
|
||||
$special_origin = {}
|
||||
MAX_PROJECTS = 3
|
||||
|
||||
SPECIAL = {
|
||||
terminal: { cmd: "kitty" },
|
||||
browser: { cmd: "firefox" },
|
||||
music: { cmd: "spotify" },
|
||||
misc: { cmd: nil }, # doesn't start anything
|
||||
todo: { cmd: nil }, # doesn't start anything
|
||||
term1: { cmd: 'kitty' },
|
||||
term2: { cmd: 'kitty' },
|
||||
browser: { cmd: 'firefox' },
|
||||
misc: { cmd: nil }
|
||||
}
|
||||
|
||||
# ==== Helpers ====
|
||||
$current = 0
|
||||
|
||||
def project_ws(n, sub)
|
||||
:"p#{n}_#{sub}"
|
||||
$p_sub = Array.new(9, 0)
|
||||
|
||||
def project_ws(n)
|
||||
:"p#{n}_#{$p_sub[$current]}"
|
||||
end
|
||||
|
||||
def running?(process)
|
||||
system("pgrep #{process} > /dev/null 2>&1")
|
||||
end
|
||||
|
||||
def go_project(n, sub)
|
||||
$current_project = n
|
||||
$current_sub = sub
|
||||
jump_ws project_ws(n, sub)
|
||||
def go_project(n)
|
||||
$current = n
|
||||
jump_ws project_ws($current)
|
||||
end
|
||||
|
||||
def in_project?(ws)
|
||||
!SPECIAL.key?(ws)
|
||||
end
|
||||
|
||||
puts "hello1"
|
||||
|
||||
# Toggle between a special-mode workspace (terminal/browser/music/misc/todo)
|
||||
# and whatever workspace you were last on. Starts the associated app if
|
||||
# it isn't already running. `ws` is the current workspace, passed in by
|
||||
# the bind block (bind gives us (window, current_ws)).
|
||||
def go_special(name, ws)
|
||||
cfg = SPECIAL.fetch(name)
|
||||
|
||||
if ws == name
|
||||
target = $special_origin[name] || project_ws($current_project, $current_sub)
|
||||
target = project_ws($current)
|
||||
jump_ws target
|
||||
else
|
||||
$special_origin[name] = ws
|
||||
jump_ws name
|
||||
system("#{cfg[:cmd]} >/dev/null 2>&1 &") if cfg[:cmd] && !running?(cfg[:cmd])
|
||||
system("#{cfg[:cmd]} >/dev/null 2>&1 &") if cfg[:cmd] && ws_empty?(name)
|
||||
end
|
||||
end
|
||||
|
||||
# ==== Untouched bindings ====
|
||||
|
||||
bind ?q do |x|
|
||||
bind 'q' do |x|
|
||||
kill x
|
||||
end
|
||||
|
||||
bind ?w do
|
||||
system "kitty >/dev/null 2>&1 &"
|
||||
bind 'w' do
|
||||
system 'kitty >/dev/null 2>&1 &'
|
||||
end
|
||||
|
||||
bind ?e do
|
||||
exit
|
||||
bind 'e' do
|
||||
system 'bash ~/main/ocaml/epq/scripts/power.sh >/dev/null 2>&1 &'
|
||||
end
|
||||
|
||||
bind ?f do |x|
|
||||
bind 'd' do
|
||||
system 'bash ~/main/ocaml/epq/scripts/run.sh >/dev/null 2>&1 &'
|
||||
end
|
||||
|
||||
bind 'v' do
|
||||
system 'CM_LAUNCHER=rofi clipmenu >/dev/null 2>&1 &'
|
||||
end
|
||||
|
||||
bind 'a' do
|
||||
system 'bash', '-c', "
|
||||
maim -c 0.3,0.5,1.0,0.8 -s | tee /tmp/screenshot_temp.png | xclip -selection clipboard -t image/png;
|
||||
if [ -s '/tmp/screenshot_temp.png' ]; then
|
||||
mv /tmp/screenshot_temp.png ~/screenshots/$(date +%Y-%m-%d_%H:%M:%S).png;
|
||||
fi
|
||||
"
|
||||
end
|
||||
|
||||
bind 123, :none do
|
||||
system 'bash', '-c', %q(
|
||||
pactl set-sink-volume @DEFAULT_SINK@ +5%;
|
||||
vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1);
|
||||
dunstify "Volume Adjusted" "" -h int:value:$vol -r 997
|
||||
)
|
||||
end
|
||||
|
||||
bind 122, :none do
|
||||
system 'bash', '-c', %q(
|
||||
pactl set-sink-volume @DEFAULT_SINK@ -5%;
|
||||
vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1);
|
||||
dunstify "Volume Adjusted" "" -h int:value:$vol -r 997
|
||||
)
|
||||
end
|
||||
|
||||
bind 121, :none do
|
||||
system 'bash', '-c', %q(
|
||||
pactl set-sink-mute @DEFAULT_SINK@ toggle;
|
||||
vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1);
|
||||
dunstify "Volume Adjusted" "" -h int:value:$vol -r 997
|
||||
)
|
||||
end
|
||||
|
||||
bind 232, :none do
|
||||
system 'bash', '-c', %q(
|
||||
brightnessctl set 5%-;
|
||||
pct=$(brightnessctl -m | cut -d, -f4 | tr -d ' %');
|
||||
dunstify "Brightness" "" -h int:value:$pct -r 998
|
||||
)
|
||||
end
|
||||
|
||||
bind 233, :none do
|
||||
system 'bash', '-c', %q(
|
||||
brightnessctl set 5%+;
|
||||
pct=$(brightnessctl -m | cut -d, -f4 | tr -d ' %');
|
||||
dunstify "Brightness" "" -h int:value:$pct -r 998
|
||||
)
|
||||
end
|
||||
|
||||
bind 'x' do
|
||||
system 'kitty -e fish -c "editor" >/dev/null 2>&1 &'
|
||||
end
|
||||
|
||||
bind 'c' do
|
||||
system 'kitty -e fish -c "y" >/dev/null 2>&1 &'
|
||||
end
|
||||
|
||||
bind 's' do |x|
|
||||
toggle_float x
|
||||
end
|
||||
|
||||
# ==== Mode switches ====
|
||||
|
||||
bind ?[ do |_, ws|
|
||||
go_special :terminal, ws
|
||||
bind 'f' do
|
||||
system 'kitty -e fish -c "btop" >/dev/null 2>&1 &'
|
||||
end
|
||||
|
||||
bind ?] do |_, ws|
|
||||
go_special :misc, ws
|
||||
bind '[' do |_, ws|
|
||||
go_special :term1, ws
|
||||
end
|
||||
|
||||
bind "tab" do |_, ws|
|
||||
bind ']' do |_, ws|
|
||||
go_special :term2, ws
|
||||
end
|
||||
|
||||
bind 79, :none do |_, ws|
|
||||
go_special :browser, ws
|
||||
end
|
||||
|
||||
bind 89 do |_, ws|
|
||||
go_special :music, ws
|
||||
go_special :misc, ws
|
||||
end
|
||||
|
||||
bind 81 do |_, ws|
|
||||
go_special :todo, ws
|
||||
bind 118, :none do
|
||||
system 'bash', '-c',
|
||||
'dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause >/dev/null 2>&1 &'
|
||||
end
|
||||
|
||||
puts "hello2"
|
||||
|
||||
# ==== Project navigation ====
|
||||
|
||||
(1..MAX_PROJECTS).each do |n|
|
||||
bind n.to_s do
|
||||
go_project(n, $current_sub)
|
||||
(0..MAX_PROJECTS - 1).each do |n|
|
||||
bind (n + 1).to_s do
|
||||
go_project(n)
|
||||
end
|
||||
end
|
||||
|
||||
bind 86, :none do |_, ws|
|
||||
next unless in_project?(ws)
|
||||
n = (($current_project - 2) % MAX_PROJECTS) + 1
|
||||
go_project(n, $current_sub)
|
||||
|
||||
n = (($current - 1 + MAX_PROJECTS) % MAX_PROJECTS)
|
||||
go_project(n)
|
||||
end
|
||||
|
||||
bind 82, :none do |_, ws|
|
||||
next unless in_project?(ws)
|
||||
n = ($current_project % MAX_PROJECTS) + 1
|
||||
go_project(n, $current_sub)
|
||||
end
|
||||
|
||||
bind 79, :none do |_, ws|
|
||||
next unless in_project?(ws)
|
||||
go_project($current_project, ($current_sub + 1) % SUBS)
|
||||
n = (($current + 1) % MAX_PROJECTS)
|
||||
go_project(n)
|
||||
end
|
||||
|
||||
bind 80, :none do |_, ws|
|
||||
next unless in_project?(ws)
|
||||
go_project($current_project, ($current_sub - 1 + SUBS) % SUBS)
|
||||
|
||||
$p_sub[$current] = $p_sub[$current] == 1 ? 0 : 1
|
||||
go_project($current)
|
||||
end
|
||||
|
||||
# ==== Startup ====
|
||||
|
||||
go_project(1, 0)
|
||||
|
||||
puts "hello3"
|
||||
go_project(0)
|
||||
|
||||
Reference in New Issue
Block a user