From 791ea7971b097a8146e993ed5ba490ccf0b2c72c Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Tue, 2 Nov 2021 20:15:32 -0600 Subject: More XMobar sexiness. Revamped the install script to make it easier to handle the install process. --- .gitignore | 1 + assets/wallpaper.jpg | Bin 767997 -> 0 bytes build-script.sh | 17 ------ compton.conf | 52 ---------------- extras/HOME/.config/compton.conf | 49 +++++++++++++++ extras/HOME/.local/.local/bin/spotify-control | 40 +++++++++++++ extras/HOME/.local/.local/bin/vim | 83 ++++++++++++++++++++++++++ extras/HOME/.local/bin/bluetooth-select.sh | 14 +++++ extras/HOME/.local/bin/spotify-control | 40 +++++++++++++ extras/HOME/.xmobarrc | 71 ++++++++++++++++++++++ extras/HOME/.xmonad/build | 17 ++++++ extras/HOME/.xmonad/startup | 38 ++++++++++++ extras/HOME/.xmonad/wallpaper.jpg | Bin 0 -> 767997 bytes extras/HOME/.xmonad/xmobar-bluetooth | 18 ++++++ extras/HOME/.xmonad/xmobar-logo | 9 +++ install.sh | 24 ++++++-- src/Internal/Keys.hs | 6 +- src/Main.hs | 2 +- startup | 38 ------------ xmobar/extras/battery/battery.c | 44 +++++++++++--- xmobarrc | 62 ------------------- 21 files changed, 441 insertions(+), 184 deletions(-) delete mode 100644 assets/wallpaper.jpg delete mode 100755 build-script.sh delete mode 100644 compton.conf create mode 100644 extras/HOME/.config/compton.conf create mode 100755 extras/HOME/.local/.local/bin/spotify-control create mode 100755 extras/HOME/.local/.local/bin/vim create mode 100755 extras/HOME/.local/bin/bluetooth-select.sh create mode 100755 extras/HOME/.local/bin/spotify-control create mode 100644 extras/HOME/.xmobarrc create mode 100755 extras/HOME/.xmonad/build create mode 100755 extras/HOME/.xmonad/startup create mode 100644 extras/HOME/.xmonad/wallpaper.jpg create mode 100755 extras/HOME/.xmonad/xmobar-bluetooth create mode 100755 extras/HOME/.xmonad/xmobar-logo delete mode 100755 startup delete mode 100644 xmobarrc diff --git a/.gitignore b/.gitignore index f5570ff..bb6c218 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .stack-work/* *.cabal *.lock +build/* diff --git a/assets/wallpaper.jpg b/assets/wallpaper.jpg deleted file mode 100644 index 4976715..0000000 Binary files a/assets/wallpaper.jpg and /dev/null differ diff --git a/build-script.sh b/build-script.sh deleted file mode 100755 index 72b6310..0000000 --- a/build-script.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -actual_bin=$(readlink -f "$0") -proj_dir="$(dirname $actual_bin)" -olddir="$(pwd)" - -cd "$proj_dir" -stack install - -ec="$?" -if [ "$ec" -ne 0 ] ; then - exit "$ec" -fi - -cd "$olddir" - -ln -sf "$HOME/.local/bin/jrahm-xmonad" "$1" diff --git a/compton.conf b/compton.conf deleted file mode 100644 index 90be41d..0000000 --- a/compton.conf +++ /dev/null @@ -1,52 +0,0 @@ -backend = "glx"; - -### Shadow -shadow = true; -no-dnd-shadow = true; -# no-dock-shadow = true; -# clear-shadow = true; -shadow-radius = 7; -shadow-offset-x = -10; -shadow-offset-y = -5; -shadow-opacity = 0.8; -shadow-red = 0.0; -shadow-green = 0.0; -shadow-blue = 0.0; - -inactive-dim=0.1 -inactive-opacity=0.99 - -shadow-exclude = [ - # From the Ubuntu forums link ('screaminj3sus') - # "! name~=''", - # "n:e:Notification", - # "n:e:Plank", - # "n:e:Docky", - # "g:e:Synapse", - # "g:e:Kupfer", - # "g:e:Conky", - # "n:w:*Firefox*", - # "class_g ?= 'Notify-osd'", - # "class_g ?= 'Cairo-dock'", - # "class_g ?= 'Xfce4-notifyd'", - # "class_g ?= 'Xfce4-power-manager'" -]; -shadow-ignore-shaped = false; - -blur-background = true; - -wintypes: -{ - tooltip = - { - fade = true; - shadow = false; - opacity = 0.85; - focus = true; - } - - - -} -# shadow-exclude-reg = "x10+0+0"; -# xinerama-shadow-crop = true; diff --git a/extras/HOME/.config/compton.conf b/extras/HOME/.config/compton.conf new file mode 100644 index 0000000..2728ce1 --- /dev/null +++ b/extras/HOME/.config/compton.conf @@ -0,0 +1,49 @@ +backend = "glx"; + +### Shadow +shadow = true; +no-dnd-shadow = true; +# no-dock-shadow = true; +# clear-shadow = true; +shadow-radius = 7; +shadow-offset-x = -10; +shadow-offset-y = -5; +shadow-opacity = 0.8; +shadow-red = 0.0; +shadow-green = 0.0; +shadow-blue = 0.0; + +inactive-dim=0.1 +inactive-opacity=0.99 + +shadow-exclude = [ + # From the Ubuntu forums link ('screaminj3sus') + # "! name~=''", + # "n:e:Notification", + # "n:e:Plank", + # "n:e:Docky", + # "g:e:Synapse", + # "g:e:Kupfer", + # "g:e:Conky", + # "n:w:*Firefox*", + # "class_g ?= 'Notify-osd'", + # "class_g ?= 'Cairo-dock'", + # "class_g ?= 'Xfce4-notifyd'", + # "class_g ?= 'Xfce4-power-manager'" +]; +shadow-ignore-shaped = false; + +blur-background = false; + +wintypes: +{ + tooltip = + { + fade = true; + shadow = false; + opacity = 0.85; + focus = true; + } +} +# shadow-exclude-reg = "x10+0+0"; +# xinerama-shadow-crop = true; diff --git a/extras/HOME/.local/.local/bin/spotify-control b/extras/HOME/.local/.local/bin/spotify-control new file mode 100755 index 0000000..751f562 --- /dev/null +++ b/extras/HOME/.local/.local/bin/spotify-control @@ -0,0 +1,40 @@ +#!/bin/bash + +if [ $# -lt 1 ] +then + echo "No command?" + exit +fi + +if [ "$(pidof spotify)" = "" ] +then + echo "Spotify is not running" + exit +fi + +case $1 in + "play") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause + ;; + "next") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next + ;; + "prev") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous + ;; + "getTitle") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$ + ;; + "getArtist") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "artist"|egrep -v "artist"|egrep -v "array"|cut -b 27-|cut -d '"' -f 1|egrep -v ^$ + ;; + "getAlbum") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "album"|egrep -v "album"|egrep -v "array"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$ + ;; + "getStatus") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'|grep 'string "[^"]*"'|sed 's/.*"\(.*\)"[^"]*$/\1/' + ;; + *) + echo "Unknown command: " $1 + ;; +esac diff --git a/extras/HOME/.local/.local/bin/vim b/extras/HOME/.local/.local/bin/vim new file mode 100755 index 0000000..d0aafa5 --- /dev/null +++ b/extras/HOME/.local/.local/bin/vim @@ -0,0 +1,83 @@ +#!/usr/bin/python3 + +import neovim, os, re, sys, time + +# Get a list of buffers that haven't been deleted. `nvim.buffers` includes +# buffers that have had `:bdelete` called on them and aren't in the buffer +# list, so we have to filter those out. +def get_listed_buffers(nvim): + return set(buf.number for buf in nvim.buffers \ + if nvim.eval('buflisted(%d)' % buf.number)) + + +def resolve_google3(fname): + if fname.startswith('//depot/google3'): + cwd = os.getcwd() + if "/google3" in cwd: + depot_dir = cwd[:cwd.find('/google3')] + realfname = fname.replace('//depot', depot_dir) + return realfname + return fname + +# For now, treat all arguments that don't start with - or + as filenames. This +# is good enough to recognize '-f' and `+11`, which is all this script really +# needs right now. +filenames = [ + re.sub(' ', '\ ', os.path.abspath(resolve_google3(arg))) + for arg in sys.argv[1:] if not arg[0] in ['-', '+'] +] + +try: + nvim_socket = os.environ["NVIM_LISTEN_ADDRESS"] +except KeyError: + # If we aren't running inside a `:terminal`, just exec nvim. + os.execvp(u'nvim', sys.argv) + +nvim = neovim.attach('socket', path=nvim_socket) + +existing_buffers = get_listed_buffers(nvim) + +nvim.command('split') +nvim.command('args %s' % ' '.join(filenames)) + +new_buffers = get_listed_buffers(nvim).difference(existing_buffers) + +for arg in sys.argv: + if arg[0] == '+': + nvim.command(arg[1:]) + +# The '-f' flag is a signal that we're in a situation like a `git commit` +# invocation where we need to block until the user is done with the file(s). +if '-f' in sys.argv and len(new_buffers) > 0: + # The rule here is that the user is 'done' with the opened files when none + # of them are visible onscreen. This allows for use cases like hitting `:q` + # on a `git commit` tempfile. However, we can't just poll to see if they're + # visible, because using `nvim.windows`, `nvim.eval()`, or `nvim.call()` + # will interrupt any multi-key mappings the user may be inputting. The + # solution is to set a buffer-local autocmd on each opened buffer so that + # we only check for visibility immediately after the user either closes or + # hides one of the buffers. + channel_id = nvim.channel_id + for buffer in new_buffers: + nvim.command(( + 'autocmd BufDelete,BufHidden ' + + 'call rpcnotify(%d, "check_buffers")' + ) % (buffer, channel_id)) + + stay_open = True + while stay_open: + nvim.next_message() # block until `rpcnotify` is called + open_buffers = [window.buffer.number for window in nvim.windows] + stay_open = any([buffer in open_buffers for buffer in new_buffers]) + + # Now that none of the opened files are visible anymore, we do a few + # cleanup steps before ending the script: + # * Clear the arg list, since otherwise `:next` would reopen the tempfile + # or whatever. + # * Clear the autocmds we added, since `bdelete` just hides the buffer and + # the autocmds will still be active if the user reopens the file(s). + # * Delete each of the buffers we created. + nvim.command('argdel *') + for buffer in new_buffers: + nvim.command('autocmd! BufDelete,BufHidden ' % buffer) + nvim.command('bdelete! %d' % buffer) diff --git a/extras/HOME/.local/bin/bluetooth-select.sh b/extras/HOME/.local/bin/bluetooth-select.sh new file mode 100755 index 0000000..a0b8559 --- /dev/null +++ b/extras/HOME/.local/bin/bluetooth-select.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +devices="$(bluetoothctl -- devices | sed 's#^Device ##')" +selection="$( + echo -e "$devices\nDisconnect" | + dmenu -i -nf "#8888ff" -sb "#8888ff" -p "Connect Bluetooth" -l 12)" + +macaddr="${selection%% *}" + +if [[ "$macaddr" == "Disconnect" ]] ; then + exec bluetoothctl -- disconnect +fi + +exec bluetoothctl -- connect "$macaddr" diff --git a/extras/HOME/.local/bin/spotify-control b/extras/HOME/.local/bin/spotify-control new file mode 100755 index 0000000..751f562 --- /dev/null +++ b/extras/HOME/.local/bin/spotify-control @@ -0,0 +1,40 @@ +#!/bin/bash + +if [ $# -lt 1 ] +then + echo "No command?" + exit +fi + +if [ "$(pidof spotify)" = "" ] +then + echo "Spotify is not running" + exit +fi + +case $1 in + "play") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause + ;; + "next") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next + ;; + "prev") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous + ;; + "getTitle") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$ + ;; + "getArtist") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "artist"|egrep -v "artist"|egrep -v "array"|cut -b 27-|cut -d '"' -f 1|egrep -v ^$ + ;; + "getAlbum") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "album"|egrep -v "album"|egrep -v "array"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$ + ;; + "getStatus") + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'|grep 'string "[^"]*"'|sed 's/.*"\(.*\)"[^"]*$/\1/' + ;; + *) + echo "Unknown command: " $1 + ;; +esac diff --git a/extras/HOME/.xmobarrc b/extras/HOME/.xmobarrc new file mode 100644 index 0000000..ecf53ed --- /dev/null +++ b/extras/HOME/.xmobarrc @@ -0,0 +1,71 @@ +Config + { font = "xft:Monofur Nerd Font:size=15" + , additionalFonts = [ + "xft:Monofur bold Nerd Font:style=bold:size=12", + "xft:Monofur Nerd Font:size=9", + "xft:Monofur bold Nerd Font:size=9", + "xft:Monofur Nerd Font:size=6", + "xft:Monofur bold Nerd Font:size=40", + "xft:Monofur Nerd Font:style=bold:size=12" + ] + , borderColor = "black" + , border = FullBM -1 + , borderWidth = 2 + , bgColor = "#17171b" + , fgColor = "white" + , alpha = 250 -- default: 255 + , position = TopSize L 100 40 + , textOffset = -1 -- default: -1 + , iconOffset = -1 -- default: -1 + , lowerOnStart = True + , pickBroadest = False -- default: False + , persistent = True + , hideOnStart = False + , iconRoot = "/usr/local/google/home/rahm/.xmonad/resources" -- default: "." + , allDesktops = True -- default: True + , overrideRedirect = False -- default: True + , sepChar = "%" + , alignSep = "}{" + , template = + " %logo% %uname% │\ + \ %date% │ \ + \%StdinReader%}%time%\ + \{ %cpu% \ + \│ %KLMO% │\ + \ %mpris2% │ \ + \%bluetooth%%bat% " + , commands = [ + Run StdinReader, + Run Memory ["-t", ""] 10, + Run Date "%H:%M:%S" "time" 10, + Run Date "%m/%d" "date" 10, + Run Cpu [ + "-t", "", + "-L", "3", + "-H", "50", + "-b", "─", + "-f", "─", + "--normal", "green", + "--high", "red" + ] 10, + Run WeatherX "KLMO" + [ ("clear", "") + , ("sunny", "") + , ("mostly clear", "") + , ("mostly sunny", "") + , ("partly sunny", "") + , ("fair", "🌑") + , ("cloudy","摒") + , ("overcast","") + , ("partly cloudy", "杖") + , ("mostly cloudy", "") + , ("considerable cloudiness", "ﭽ")] + ["--template", " \ + \°F"] 360000, + Run Mpris2 "spotify" ["-t", "</fn>"] 20, + Run Com ".xmonad/xmobar-logo" [] "logo" 0, + Run Com "uname" ["-r"] "uname" 0, + Run Com ".xmonad/xmobar-bluetooth" [] "bluetooth" 50, + Run Com ".xmonad/xmobar-battery" [] "bat" 20 + ] + } diff --git a/extras/HOME/.xmonad/build b/extras/HOME/.xmonad/build new file mode 100755 index 0000000..72b6310 --- /dev/null +++ b/extras/HOME/.xmonad/build @@ -0,0 +1,17 @@ +#!/bin/sh + +actual_bin=$(readlink -f "$0") +proj_dir="$(dirname $actual_bin)" +olddir="$(pwd)" + +cd "$proj_dir" +stack install + +ec="$?" +if [ "$ec" -ne 0 ] ; then + exit "$ec" +fi + +cd "$olddir" + +ln -sf "$HOME/.local/bin/jrahm-xmonad" "$1" diff --git a/extras/HOME/.xmonad/startup b/extras/HOME/.xmonad/startup new file mode 100755 index 0000000..dc302b7 --- /dev/null +++ b/extras/HOME/.xmonad/startup @@ -0,0 +1,38 @@ +#!/bin/bash + +common() { + # Startup commands common to all the hosts. + xsetroot -cursor_name left_ptr + xset r rate 200 60 +} + +hostname_rahm1() { + # Startup commands specific to my worktop. + xinput set-prop "TPPS/2 Elan TrackPoint" "Coordinate Transformation Matrix" 3 0 0 0 3 0 0 0 1 + xinput set-prop "SYNA8004:00 06CB:CD8B Touchpad" "Coordinate Transformation Matrix" 3 0 0 0 3 0 0 0 1 + + if [ -z "$(ps aux | grep compton | grep -v grep)" ] ; then + __GL_SYNC_TO_VBLANK=1 nohup compton --backend=glx &>/dev/null & + fi + + feh --bg-scale "$HOME/wp.jpg" +} + +hostname_photon() { + # Startup commands specific to my desktop. + + if [ -z "$(ps aux | grep compton | grep -v grep)" ] ; then + __GL_SYNC_TO_VBLANK=1 nohup compton --backend=glx &>/dev/null & + fi + xrandr --output DVI-I-1 --right-of DP-5 --mode 2560x1440 + feh --bg-scale "/home/rahm/.xmonad/wallpaper.jpg" +} + + +common + +hostname_fn="hostname_$(hostname)" + +if [[ "$(type -t "$hostname_fn")" == function ]] ; then + "$hostname_fn" +fi diff --git a/extras/HOME/.xmonad/wallpaper.jpg b/extras/HOME/.xmonad/wallpaper.jpg new file mode 100644 index 0000000..4976715 Binary files /dev/null and b/extras/HOME/.xmonad/wallpaper.jpg differ diff --git a/extras/HOME/.xmonad/xmobar-bluetooth b/extras/HOME/.xmonad/xmobar-bluetooth new file mode 100755 index 0000000..93caa50 --- /dev/null +++ b/extras/HOME/.xmonad/xmobar-bluetooth @@ -0,0 +1,18 @@ +#!/bin/sh + +cur="" + +bluetoothctl -- info | while read line ; do + key=${line%%: *} + value=${line//*: } + + if [ "$key" == "Name" ] ; then + cur="$value" + fi + + if [ "$key" == "Connected" -a "$value" == "yes" ] ; then + exec echo "<fc=#4287f5></fc> <fc=#a0a0a0><fn=3>$cur</fn></fc> <fc=#404040>│</fc> " + fi +done + +exec echo "<fc=#a0a0a0></fc> <fc=#404040>│</fc>" diff --git a/extras/HOME/.xmonad/xmobar-logo b/extras/HOME/.xmonad/xmobar-logo new file mode 100755 index 0000000..848ebd2 --- /dev/null +++ b/extras/HOME/.xmonad/xmobar-logo @@ -0,0 +1,9 @@ +#!/bin/bash + +case "$(uname -a)" in + *-arch-*) exec echo '<fn=5><fc=#1785bd></fc></fn>' ;; + *Debian*) exec echo '<fn=5><fc=#c00649></fc></fn>' ;; + *Ubuntu*) exec echo '<fn=5><fc=#ff8888></fc></fn>' ;; + *Linux*) exec echo '<fn=5><fc=#ffffff></fc></fn>' ;; + *BSD*) exec echo '<fn=5><fc=#ff4444></fc></fn>' ;; +esac diff --git a/install.sh b/install.sh index a965ad8..59a5078 100755 --- a/install.sh +++ b/install.sh @@ -4,11 +4,23 @@ real_dir=$(dirname $(readlink -f "$0")) cd "$real_dir" mkdir -p "$HOME/.xmonad" +mkdir -p "$HOME/.config" -cc -o ~/.xmonad/xmobar-battery xmobar/extras/battery/battery.c -lm +mkdir -p build/extras/HOME/.xmonad -ln -sfv "$real_dir/build-script.sh" "$HOME/.xmonad/build" -ln -sfv "$real_dir/compton.conf" "$HOME/.config/compton.conf" -ln -sfv "$real_dir/startup" "$HOME/.xmonad/startup" -ln -sfv "$real_dir/xmobarrc" "$HOME/.xmobarrc" -ln -sfv "$real_dir/assets/wallpaper.jpg" "$HOME/.xmonad/wallpaper.jpg" +cc -o \ + build/extras/HOME/.xmonad/xmobar-battery \ + xmobar/extras/battery/battery.c \ + -lm + +GLOBIGNORE=".:.." +shopt -u dotglob + +cd "$HOME" +cp -rsvf \ + "$real_dir"/extras/HOME/* \ + "$real_dir"/extras/HOME/.* \ + "$real_dir"/build/extras/HOME/* \ + "$real_dir"/build/extras/HOME/.* \ + . +cd "$real_dir" diff --git a/src/Internal/Keys.hs b/src/Internal/Keys.hs index c97736f..3dff864 100644 --- a/src/Internal/Keys.hs +++ b/src/Internal/Keys.hs @@ -85,7 +85,8 @@ newKeys markContext = , ((modm .|. mod1Mask, xK_s), (void $ spawn "sudo systemctl suspend && xsecurelock")) , ((modm .|. shiftMask, xK_c), kill) , ((modm .|. shiftMask, xK_t), withFocused $ windows . W.sink) - , ((mod4Mask, xK_Escape), (void $ spawn "xterm")) + , ((mod4Mask, xK_BackSpace), (void $ spawn "xterm")) + , ((mod3Mask, xK_BackSpace), (void $ spawn "pkill -SIGUSR1 xmobar")) , ((mod3Mask, xK_t), (void $ spawn (terminal config))) , ((modm, xK_m), (submap $ mapAlpha modm (markCurrentWindow markContext))) , ((modm, xK_w), runXPlus markContext config windowJump) @@ -122,6 +123,9 @@ newKeys markContext = , ((modm, xK_q), spawn "xmonad --recompile && xmonad --restart") , ((modm, xK_z), sendMessage ToggleZoom) + , ((modm, xK_x), spawn "bluetooth-select.sh") + , ((modm .|. shiftMask, xK_x), spawn "bluetoothctl -- disconnect") + , ((modm, xK_Tab), windows W.focusDown) , ((modm .|. shiftMask, xK_Tab), windows W.focusUp) diff --git a/src/Main.hs b/src/Main.hs index 195c151..85d18c7 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -58,7 +58,7 @@ main = do "xmobar" xmobarPP { ppCurrent = xmobarColor "#ff8888" "red" . printf "<fn=1>%s</fn>" - , ppVisible = xmobarColor "#8888ff" "" . printf "<fn=0>%s</fn>" + , ppVisible = xmobarColor "#8888ff" "" . printf "<fn=6>%s</fn>" , ppHidden = xmobarColor "#888888" "" . printf "<fn=2>%s</fn>" , ppWsSep = "<fn=1><fc=#808080> </fc></fn>" , ppTitle = diff --git a/startup b/startup deleted file mode 100755 index dc302b7..0000000 --- a/startup +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -common() { - # Startup commands common to all the hosts. - xsetroot -cursor_name left_ptr - xset r rate 200 60 -} - -hostname_rahm1() { - # Startup commands specific to my worktop. - xinput set-prop "TPPS/2 Elan TrackPoint" "Coordinate Transformation Matrix" 3 0 0 0 3 0 0 0 1 - xinput set-prop "SYNA8004:00 06CB:CD8B Touchpad" "Coordinate Transformation Matrix" 3 0 0 0 3 0 0 0 1 - - if [ -z "$(ps aux | grep compton | grep -v grep)" ] ; then - __GL_SYNC_TO_VBLANK=1 nohup compton --backend=glx &>/dev/null & - fi - - feh --bg-scale "$HOME/wp.jpg" -} - -hostname_photon() { - # Startup commands specific to my desktop. - - if [ -z "$(ps aux | grep compton | grep -v grep)" ] ; then - __GL_SYNC_TO_VBLANK=1 nohup compton --backend=glx &>/dev/null & - fi - xrandr --output DVI-I-1 --right-of DP-5 --mode 2560x1440 - feh --bg-scale "/home/rahm/.xmonad/wallpaper.jpg" -} - - -common - -hostname_fn="hostname_$(hostname)" - -if [[ "$(type -t "$hostname_fn")" == function ]] ; then - "$hostname_fn" -fi diff --git a/xmobar/extras/battery/battery.c b/xmobar/extras/battery/battery.c index 8e5e58e..791bc69 100644 --- a/xmobar/extras/battery/battery.c +++ b/xmobar/extras/battery/battery.c @@ -13,7 +13,7 @@ char* icons[] = { "", "", "", - "", + "", "", "", "", @@ -162,14 +162,22 @@ uint32_t percentage_to_color(int percentage) return hsv_to_rgb(h, s, v); } -void get_time_left(char* buf, size_t sz, llong_t energy, llong_t power) +void get_time_left( + char* buf, + size_t sz, + llong_t energy, + llong_t power) { + if (power == 0) { + buf[0] = 0; + return; + } llong_t minutes_left = energy * 60 / power; llong_t hours = minutes_left / 60; llong_t minutes = minutes_left % 60; - snprintf(buf, sz - 1, "%2lluh%2llum", hours, minutes); + snprintf(buf, sz - 1, "%lluh%2llum", hours, minutes); buf[sz - 1] = 0; } @@ -177,9 +185,12 @@ int main(int argc, char** argv) { char* icon; char timeleft[128]; + char watts[128]; + char percent[128]; llong_t capacity; llong_t energy_now; + llong_t energy_full; llong_t ac_online; llong_t power; @@ -206,18 +217,37 @@ int main(int argc, char** argv) ac_online = !! ac_online; int percentage = (int) capacity; - if (percentage >= 100) { + if (percentage >= 98) { icon = icons[10 + ac_online]; } else { int quintile = percentage / 20; icon = icons[quintile + (5 * ac_online) ]; } - get_time_left(timeleft, sizeof(timeleft), energy_now, power); + if (ac_online) { + if ((energy_full = get_energy_full()) < 0) { + fprintf(stderr, "Unable to get current energy."); + goto fail; + } + get_time_left(timeleft, sizeof(timeleft), energy_full - energy_now, power); + } else { + get_time_left(timeleft, sizeof(timeleft), energy_now, power); + } + + watts[0] = 0; + percent[0] = 0; + if (power) { + double dpower = power / 1000000.0; + snprintf(watts, sizeof(watts), "%2.1fW ", dpower); + } + + if (percentage < 99 || ! ac_online) { + snprintf(percent, sizeof(percent), "%2d%% ", percentage); + } - double dpower = power / 1000000.0; uint32_t color = percentage_to_color(percentage); - printf("<fc=#%06x>%s </fc><fc=#8888ff>%d%% %2.1fW %s</fc>", color, icon, percentage, dpower, timeleft); + printf("<fc=#%06x>%s </fc><fn=3><fc=#a0a0a0>%s%s%s</fc></fn>", + color, icon, percent, watts, timeleft); return 0; fail: diff --git a/xmobarrc b/xmobarrc deleted file mode 100644 index 2893a17..0000000 --- a/xmobarrc +++ /dev/null @@ -1,62 +0,0 @@ -Config - { font = "xft:Monofur Nerd Font:size=15" - , additionalFonts = [ - "xft:Monofur bold Nerd Font:style=bold:size=15", - "xft:Monofur Nerd Font:size=12", - "xft:Monofur Nerd Font:size=12" ] - , borderColor = "black" - , border = FullB - , borderWidth = 2 - , bgColor = "#17171b" - , fgColor = "white" - , alpha = 250 -- default: 255 - , position = TopSize L 100 50 - , textOffset = -1 -- default: -1 - , iconOffset = -1 -- default: -1 - , lowerOnStart = True - , pickBroadest = False -- default: False - , persistent = True - , hideOnStart = False - , iconRoot = "/usr/local/google/home/rahm/.xmonad/resources" -- default: "." - , allDesktops = True -- default: True - , overrideRedirect = False -- default: True - , sepChar = "%" - , alignSep = "}{" - , template = " <fc=#ff8888></fc> <fc=#404040> │</fc><fc=#ff8888> %date%</fc><fc=#404040> │ </fc>%StdinReader% }<fc=#8888ff>%time%</fc>{ %cpu% <fc=#404040>│</fc> %KBDU% <fc=#404040>│</fc> <fc=#8888ff>%uname%</fc> <fc=#404040>│ </fc>%bat% " - , commands = [ - Run Battery [ "--template" , "<fn=1><acstatus></fn>" - , "--Low" , "10" -- units: % - , "--High" , "80" -- units: % - , "--low" , "darkred" - , "--normal" , "darkorange" - , "--high" , "darkgreen" - - , "--" -- battery specific options - -- discharging status - , "-o" , " (<left>%, <timeleft>)" - -- AC "on" status - , "-O" , "<fc=#dA20A5> (<left>%)</fc>" - -- charged status - , "-i" , "<fc=#006000></fc>" - ] 50, - Run StdinReader, - Run Date "%H:%M:%S" "time" 10, - Run Date "%m/%d" "date" 10, - Run Cpu ["-t", "<total>%", "-L","3","-H","50","--normal","green","--high","red"] 10, - Run WeatherX "KBDU" - [ ("clear", "<fc=#ddcf04>") - , ("sunny", "<fc=#ddcf04>") - , ("mostly clear", "<fc=#ddcf04>") - , ("mostly sunny", "<fc=#ddcf04>") - , ("partly sunny", "<fc=#ddcf04>") - , ("fair", "<fc=#a0a0a0>🌑") - , ("cloudy","<fc=#a0a0a0>摒") - , ("overcast","<fc=#808080>") - , ("partly cloudy", "<fc=#a0a0a0>杖") - , ("mostly cloudy", "<fc=#808080>") - , ("considerable cloudiness", "<fc=#a0a0a0>ﭽ")] - ["--template", "<skyConditionS></fc><fc=#8888ff> <tempF>°F</fc>"] 360000, - Run Com "uname" ["-r"] "uname" 0, - Run Com ".xmonad/xmobar-battery" [] "bat" 20 - ] - } -- cgit