From fa1bb3f0e57ccc57b2f9d4d51ea9f840d0e4edc4 Mon Sep 17 00:00:00 2001 From: Daniel Pereira Date: Tue, 25 Jan 2022 14:50:59 -0400 Subject: [PATCH] WIP --- .gitmodules | 3 + bin/count_rotification.js | 9 ++ bin/count_rotification.py | 17 ++ bin/i3-cycle-tab.js | 26 +++ bin/i3-select-tab.js | 11 ++ bin/i3-tab.sh | 7 - bin/mic-volume.js | 29 ++++ bin/wallpaper.js | 63 ++++++++ bin/wallpaper.sh | 20 --- config/sway/sway.conf | 322 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 480 insertions(+), 27 deletions(-) create mode 100644 .gitmodules create mode 100644 bin/count_rotification.js create mode 100644 bin/count_rotification.py create mode 100644 bin/i3-cycle-tab.js create mode 100644 bin/i3-select-tab.js delete mode 100644 bin/i3-tab.sh create mode 100644 bin/mic-volume.js create mode 100644 bin/wallpaper.js delete mode 100755 bin/wallpaper.sh create mode 100644 config/sway/sway.conf diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c7bfd5b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "polybar-mic-volume"] + path = polybar-mic-volume + url = https://github.com/MarcDonald/polybar-mic-volume.git diff --git a/bin/count_rotification.js b/bin/count_rotification.js new file mode 100644 index 0000000..aec4a18 --- /dev/null +++ b/bin/count_rotification.js @@ -0,0 +1,9 @@ +const net = require('net'); + +const client = new net.Socket(); +client.connect("/tmp/rofi_notification_daemon",() => client.write('num\n')); + +client.on('data', function(data) { + console.log(data.toString().split(",")[0]); + client.destroy(); +}); diff --git a/bin/count_rotification.py b/bin/count_rotification.py new file mode 100644 index 0000000..cc77732 --- /dev/null +++ b/bin/count_rotification.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +#/home/infra/me/regolith-rofication/rofication-daemon + +# 936 type = custom/script +# 937 exec = /home/infra/me/regolith-rofication/count_rofi_notification +# 938 format-prefix =  + +import socket +import sys +server_address = '/tmp/rofi_notification_daemon' +sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +sock.connect(server_address) +sock.send(b'num\n') + +response = sock.recv(1024) + +print(response.decode().split(",")[0]) \ No newline at end of file diff --git a/bin/i3-cycle-tab.js b/bin/i3-cycle-tab.js new file mode 100644 index 0000000..ff0704c --- /dev/null +++ b/bin/i3-cycle-tab.js @@ -0,0 +1,26 @@ +const execSync = require('child_process').execSync; + +const args = process.argv.slice(2) +const windowIndex = parseInt(args[0]) +const state = JSON.parse(execSync(`swaymsg -t get_tree`)) + +const currentWorkspace = state.nodes; + +function getLeaves(root) { + const nodes = root.nodes; + const results = []; + while (nodes.length) { + const node = nodes.shift() + if (node.nodes.length > 0) { + nodes.push(...node.nodes) + } else { + results.push(node) + } + } + return results +} + +const programNodes = getLeaves(state) +const unfocusedVisibledWindow = programNodes.find(p => p.visible && !p.focused) +execSync(`swaymsg '[con_id="${unfocusedVisibledWindow.id}"] focus'`) + diff --git a/bin/i3-select-tab.js b/bin/i3-select-tab.js new file mode 100644 index 0000000..45c8999 --- /dev/null +++ b/bin/i3-select-tab.js @@ -0,0 +1,11 @@ +const execSync = require('child_process').execSync; + +const args = process.argv.slice(2) +const windowIndex = parseInt(args[0]) +const state = JSON.parse(execSync(`swaymsg -t get_tree`)) + +const currentWorkspace = parseInt(state.nodes.flat().find(i => i.active).current_workspace) +const nodes = state.nodes.find(i => i.active).nodes[0].nodes +const window = windowIndex == -1? nodes.pop() : nodes[windowIndex] + +execSync(`swaymsg '[con_id="${window.id}"] focus'`) \ No newline at end of file diff --git a/bin/i3-tab.sh b/bin/i3-tab.sh deleted file mode 100644 index f72d03c..0000000 --- a/bin/i3-tab.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -xe - -window_id=$1 -index=`i3-msg -t get_tree | jq -e -r "recurse(.nodes[];.nodes!=null)|select(.nodes[].focused).nodes[$window_id].id"` -i3-msg "[con_id=\"$index\"] focus" - diff --git a/bin/mic-volume.js b/bin/mic-volume.js new file mode 100644 index 0000000..e6f3adb --- /dev/null +++ b/bin/mic-volume.js @@ -0,0 +1,29 @@ +// # 0 8,12,23 * * * /home/infra/me/mydotfiles/bin/wallpaper.js + +const https = require('https'); +const fs = require('fs'); +const execSync = require('child_process').execSync; +const output = execSync(`amixer -c 0`).toString().trim().split("\n") +function parseAmixer(output) { + const result = {} + let lastKey; + output.forEach(line => { + if(line[0]!==" ") { + const startIndex = line.indexOf("'")+1 + const endIndex = line.indexOf(",")-1 + + lastKey=line.slice(startIndex,endIndex) + result[lastKey]={} + } else { + const [key, value] = line.split(":") + result[lastKey][key.trim()]=value.trim() + } + }) + return result +} + + +const mic = parseAmixer(output) +const rawValue = mic['Headset Mic Boost']['Front Left'] +const value = (/(\d*)%/).exec(rawValue)[0] +console.log(value) diff --git a/bin/wallpaper.js b/bin/wallpaper.js new file mode 100644 index 0000000..0f8fdc4 --- /dev/null +++ b/bin/wallpaper.js @@ -0,0 +1,63 @@ +// # 0 8,12,23 * * * /home/infra/me/mydotfiles/bin/wallpaper.js + +const https = require('https'); +const fs = require('fs'); +const execSync = require('child_process').execSync; + +const displays = ["eDP-1","eHDMI-1"] + +function streamToString(stream) { + const chunks = []; + return new Promise((resolve, reject) => { + stream.on('data', (chunk) => chunks.push(Buffer.from(chunk))); + stream.on('error', (err) => reject(err)); + stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); + }) +} + +function downloadImage(url, ext) { + return new Promise((resolve, reject) => https.get(url, resolve)) +} + +function getWallpaperStream() { + return new Promise((resolve, reject) => https.get("https://www.reddit.com/r/earthporn.json?sort=new", resolve)) +} + +async function saveFile(stream, fileName) { + return new Promise((resolve, reject) => { + stream.pipe(fs.createWriteStream(fileName)) + stream.on('error', reject); + stream.on('end', resolve); + }) +} + +function isValidImage(i) { + const data = i.data + const {width, height} = data.preview.images[0].source + return data.url_overridden_by_dest && width > height +} + +async function main() { + try { + const wallpapersStream = await getWallpaperStream(); + const wallpapersRestResponse = JSON.parse(await streamToString(wallpapersStream)) + const wallpapers = wallpapersRestResponse.data.children.filter(isValidImage).slice(0,2).map(i => i.data.url_overridden_by_dest) + const homePath = process.env.HOME + + const wallpaperPaths = wallpapers.map(async (wallpaper, i)=> { + const wallpaperStream = await downloadImage(wallpaper) + const extension = wallpaper.split(".").pop() + const wallpaperFile = `${homePath}/.wallpaper${i}.${extension}` + await saveFile(wallpaperStream, wallpaperFile) + return wallpaperFile + }) + + const paths = await Promise.all(wallpaperPaths) + paths.forEach( (wallpaperPath,i) => execSync(`swaymsg output "${displays[i]}" background ${wallpaperPath} fill`)) + + } catch (error) { + console.log(error) + } +} + +main() \ No newline at end of file diff --git a/bin/wallpaper.sh b/bin/wallpaper.sh deleted file mode 100755 index 0179c14..0000000 --- a/bin/wallpaper.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# crontab config -# 0 8,12,23 * * * ~/bin/wallpaper.sh - -set -xe - -# Original from https://gist.github.com/vojtabiberle/d46e09dc48d221adec3bbb4adc854a2f -TMP_FILE="$HOME/.wallpaper/tmp.wallpaper.png" -FILE="$HOME/.wallpaper/wallpaper.png" - -[ -f $TMP_FILE] && rm $TMP_FILE -curl 'https://source.unsplash.com/1920x1200//?stars,nature,sea,wather' \ - -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36' \ - --compressed -o $TMP_FILE -L -v - -if [ -f "$TMP_FILE" ]; then - mv $TMP_FILE $FILE - gsettings set org.gnome.desktop.screensaver picture-uri file://$FILE - gsettings set org.gnome.desktop.background picture-uri file://$FILE -fi diff --git a/config/sway/sway.conf b/config/sway/sway.conf new file mode 100644 index 0000000..361f729 --- /dev/null +++ b/config/sway/sway.conf @@ -0,0 +1,322 @@ +# config: ln ./config/sway/sway.conf ~/.config/i3/config +# xprop +# xev -event keyboard + +set $mod Mod4 +set $alt Mod1 +font pango:Chilanka Bold 8 +set $node_path /home/infra/.nvm/versions/node/v16.9.1/bin/node +set $i3_select_window_cmd $node_path /home/infra/me/mydotfiles/bin/i3-select-tab.js +set $i3_cycle_select_window_cmd $node_path /home/infra/me/mydotfiles/bin/i3-cycle-tab.js + +############################################################################### +# Launcher dialogs +############################################################################### + +## Launch // Terminal // <> Enter ## +bindsym $mod+Return exec gnome-terminal + +## Launch // Browser // <> Enter ## +bindsym $mod+Shift+Return exec gtk-launch $(xdg-settings get default-web-browser) + +## Launch // Application // <> Space ## +bindsym $mod+space exec $HOME/.config/rofi/launchers/colorful/launcher.sh + +## Launch // Command // <> Space ## +bindsym $mod+Shift+space exec rofi -show run + +## Navigate // Window by Name // <> Space ## +bindsym $mod+Ctrl+space exec rofi -show window + +############################################################################### +# Window and Workspace Navigation +############################################################################### + +## Navigate // Relative Window // <> ↑ ↓ ← → ## +bindsym $mod+Left focus left +bindsym $mod+Down focus down +bindsym $mod+Up focus up +bindsym $mod+Right focus right + +# Mode tab +bindsym $mod+Shift+t layout tabbed + +# split in horizontal orientation +bindsym $mod+Shift+h split h + +# split in vertical orientation +bindsym $mod+Shift+v split v + +# We use variables to avoid repeating the names in multiple places. +set $ws1 "1" +set $ws2 "2" +set $ws3 "3" +set $ws4 "4" +set $ws5 "5" +set $ws6 "6" +set $ws7 "7" +set $ws8 "8" +set $ws9 "9" +set $ws10 "10" + +# switch to workspace +bindsym $mod+1 workspace $ws1 +bindsym $mod+2 workspace $ws2 +bindsym $mod+3 workspace $ws3 +bindsym $mod+4 workspace $ws4 + +bindsym $mod+5 workspace $ws5 +bindsym $mod+6 workspace $ws6 +bindsym $mod+7 workspace $ws7 +bindsym $mod+8 workspace $ws8 +bindsym $mod+9 workspace $ws9 +bindsym $mod+0 workspace $ws10 + +## Navigate // Next Workspace // <> Tab ## +bindsym $mod+Tab exec $i3_cycle_select_window_cmd + + +## Navigate // Next Workspace // <> → ## +bindsym $mod+Control+Right workspace next + +## Navigate // Previous Workspace // <> ← ## +bindsym $mod+Control+Left workspace prev + +bindsym mod1+1 exec $i3_select_window_cmd 0 +bindsym mod1+2 exec $i3_select_window_cmd 1 +bindsym mod1+3 exec $i3_select_window_cmd 2 +bindsym mod1+4 exec $i3_select_window_cmd 3 +bindsym mod1+5 exec $i3_select_window_cmd 4 +bindsym mod1+6 exec $i3_select_window_cmd 5 +bindsym mod1+7 exec $i3_select_window_cmd 6 +bindsym mod1+8 exec $i3_select_window_cmd 7 +bindsym mod1+9 exec $i3_select_window_cmd -1 + +############################################################################### + +## Modify // Window Position // <> ↑ ↓ ← → ## +bindsym $mod+Shift+Left move left +bindsym $mod+Shift+Down move down +bindsym $mod+Shift+Up move up +bindsym $mod+Shift+Right move right + +## Modify // Containing Workspace // <> ↑ ↓ ← → ## +bindsym $mod+Ctrl+Shift+Left move workspace to output left +bindsym $mod+Ctrl+Shift+Down move workspace to output down +bindsym $mod+Ctrl+Shift+Up move workspace to output up +bindsym $mod+Ctrl+Shift+Right move workspace to output right + +## Modify // Window Fullscreen Toggle // <> f ## +bindsym $mod+f fullscreen toggle + +## Modify // Window Floating Toggle // <> f ## +bindsym $mod+Shift+f floating toggle + +## Navigate // Scratchpad // <> a ## +bindsym $mod+Ctrl+a scratchpad show + +## Modify // Move to Scratchpad // <> m ## +bindsym $mod+Ctrl+m move to scratchpad + +## Modify // Move Window to Workspace 1 - 10 // <> 0..9 ## +bindsym $mod+Shift+1 move container to workspace number $ws1 +bindsym $mod+Shift+2 move container to workspace number $ws2 +bindsym $mod+Shift+3 move container to workspace number $ws3 +bindsym $mod+Shift+4 move container to workspace number $ws4 +bindsym $mod+Shift+5 move container to workspace number $ws5 +bindsym $mod+Shift+6 move container to workspace number $ws6 +bindsym $mod+Shift+7 move container to workspace number $ws7 +bindsym $mod+Shift+8 move container to workspace number $ws8 +bindsym $mod+Shift+9 move container to workspace number $ws9 +bindsym $mod+Shift+0 move container to workspace number $ws10 + +############################################################################### +# Session Management +############################################################################### + +## Session // Exit App // <> q ## +bindsym $mod+Shift+q [con_id="__focused__"] kill + +## Session // Terminate App // <> q ## +bindsym $mod+$alt+q [con_id="__focused__"] exec --no-startup-id kill -9 $(xdotool getwindowfocus getwindowpid) + +## Session // Reload i3 Config // <> c ## +bindsym $mod+Shift+c reload + +## Session // Refresh Session // <> r ## +bindsym $mod+Shift+r exec --no-startup-id sway reload + +############################################################################### +# System Management +############################################################################### + +## Modify // Settings // <> c ## +bindsym $mod+s exec i3-msg '[class="Slack"] focus' + +## Modify // Display Settings // <> d ## +bindsym $mod+d exec i3-msg '[class="discord"] focus' +bindsym $mod+t exec i3-msg '[class="Thunderbird"] focus' + +## Modify // Wifi Settings // <> w ## +bindsym $mod+w exec gnome-control-center wifi + + +## Launch // File Browser // <> n ## +bindsym $mod+Shift+n exec nautilus --new-window + +## Launch // File Browser // <> s ## +bindsym $mod+Shift+s exec pavucontrol + +## Launch // Notification Viewer // <> n ## +bindsym $mod+n exec /home/infra/me/regolith-rofication/rofication-gui + +############################################################################### +# Workspace Management +############################################################################### + +# Cause Settings app to float above tiled windows +floating_maximum_size -1 x -1 + +############################################################################### +# Window Resize and Gaps +############################################################################### + + +## Resize // Enter Resize Mode // <> r ## +mode "Resize Mode" { + # These bindings trigger as soon as you enter the resize mode + + ## Resize // Resize Window // ↑ ↓ ← → ## + bindsym Left resize shrink width 6 px or 6 ppt + bindsym Down resize grow height 6 px or 6 ppt + bindsym Up resize shrink height 6 px or 6 ppt + bindsym Right resize grow width 6 px or 6 ppt + + bindsym Shift+Left resize shrink width 12 px or 12 ppt + bindsym Shift+Down resize grow height 12 px or 12 ppt + bindsym Shift+Up resize shrink height 12 px or 12 ppt + bindsym Shift+Right resize grow width 12 px or 12 ppt + + ## Resize // Window Gaps // + - ## + bindsym minus gaps inner current minus 6 + bindsym plus gaps inner current plus 6 + bindsym Shift+minus gaps inner current minus 12 + bindsym Shift+plus gaps inner current plus 12 + + ## Resize // Exit Resize Mode // Escape or Enter ## + bindsym Return mode "default" + bindsym Escape mode "default" + bindsym $mod+r mode "default" +} + +bindsym $mod+r mode "Resize Mode" + +############################################################################### +# Color +############################################################################### + +client.focused #2E3440 #243435 #d37a32 #cf937a +client.focused_inactive #2E3440 #243435 #CF937A #CF937A +client.unfocused #2E3440 #243435 #ffffff #cf937a +client.urgent #d6b2a1 #d6b2a1 #000000 #cf937a + +############################################################################### +# External programs launched with i3 +############################################################################### + +# Custom thing +title_align center +workspace_layout tabbed +default_border pixel 1 +default_floating_border pixel 1 +focus_follows_mouse yes + +# Use Mouse+$mod to drag floating windows to their wanted position +floating_modifier $mod +hide_edge_borders none +default_border pixel 0 + +# Pulse Audio controls +bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5% +bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5% +bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle + +bindsym $mod+Prior exec pactl set-sink-volume @DEFAULT_SINK@ +5% +bindsym $mod+Shift+Prior exec pactl set-sink-volume 1 +5% +bindsym $mod+Next exec pactl set-sink-volume @DEFAULT_SINK@ -5% +bindsym $mod+Shift+Next exec pactl set-sink-volume 1 -5% +bindsym $mod+m exec amixer set Capture toggle +bindsym $mod+Shift+m exec pactl set-source-volume @DEFAULT_SOURCE@ 30% + +# Control display backlight +bindsym XF86MonBrightnessUp exec xbacklight -inc 20 # increase screen brightness +bindsym XF86MonBrightnessDown exec xbacklight -dec 20 # decrease screen brightness + +# Media player controls +bindsym XF86AudioPlay exec playerctl -p spotify play-pause +bindsym Pause exec playerctl -p spotify play-pause +bindsym XF86AudioStop exec playerctl -p spotify stop +bindsym $mod+End exec playerctl -p spotify next +bindsym $mod+Home exec playerctl -p spotify previous +bindsym Print exec grim -g "$(slurp)" - | wl-copy +bindsym $mod+Print exec wf-recorder -g "$(slurp)" "~/Pictures/recoding-`date --iso-8601=date`".mp4 + +# Jump to urgent window +bindsym $mod+x split h, layout splith, focus right, move left, focus left +bindsym $mod+z split h, layout tabbed, focus right, move left, focus left +bindsym $mod+p focus parent + +for_window [class="Spotify"] move --no-auto-back-and-forth to workspace $ws3 +for_window [class="Slack"] move --no-auto-back-and-forth to workspace $ws2 +for_window [class=".*Teams.*"] move --no-auto-back-and-forth to workspace $ws2 +for_window [class="discord"] move --no-auto-back-and-forth to workspace $ws2 + +# xprop +# xev -event keyboard +bindsym $mod+Shift+k exec killall java chrome code node + +############################################################################### +# Inicialization +############################################################################### + +exec --no-startup-id "/home/infra/me/regolith-rofication/rofication-daemon" +exec --no-startup-id "nm-applet --indicator" +exec --no-startup-id wl-paste -t text --watch clipman store --no-persist + +bar { + swaybar_command waybar +} + +input * { + xkb_layout "br" + xkb_variant "abnt2" + xkb_options "" +} + +set $primary eDP-1 +set $secondary HDMI-A-1 + +workspace $ws1 output $primary +workspace $ws2 output $primary +workspace $ws3 output $primary + +#workspace $ws4 output $secondary +#workspace $ws5 output $secondary +#workspace $ws6 output $secondary +# swaymsg -t get_outputs +# wlr-randr --output eDP-1 --preferred --pos 0,0 --output HDMI-A-1 --preferred --pos 1366,0 + +output "eDP-1" bg `ls ~/.wallpaper0* -1|head -n 1` fill +output "HDMI-A-1" bg `ls ~/.wallpaper1* -1|head -n 1` fill + +output $primary pos 0 0 +output $secondary pos 1366 0 + +input type:touchpad { + tap enabled + natural_scroll enabled +} + +input * xkb_numlock enable + +