commit be81075e228b6d0591d1929dcee936ab929940f2 Author: GRMrGecko Date: Fri Jul 29 20:51:50 2022 -0500 Initial diff --git a/.config/fish/config.fish b/.config/fish/config.fish new file mode 100644 index 0000000..cda2505 --- /dev/null +++ b/.config/fish/config.fish @@ -0,0 +1,37 @@ +if command -vq flatpak + set -ga fish_user_paths ~/.local/share/flatpak/exports/bin /var/lib/flatpak/exports/bin + set -gx --path XDG_DATA_DIRS /usr/local/share/ /usr/share/ ~/.local/share/flatpak/exports/share + for install_dir in (flatpak --installations) + set -gxa XDG_DATA_DIRS $install_dir/exports/share + end +end + +egrep "^export " ~/.bash_profile | while read e + set var (echo $e | sed -E "s/^export ([A-Za-z_]+)=(.*)\$/\1/") + set value (echo $e | sed -E "s/^export ([A-Za-z_]+)=(.*)\$/\2/") + + # remove surrounding quotes if existing + set value (echo $value | sed -E "s/^\"(.*)\"\$/\1/") + + if test $var = "PATH" + # replace ":" by spaces. this is how PATH looks for Fish + set value (echo $value | sed -E "s/:/ /g") + + # use eval because we need to expand the value + eval set -xg $var $value + + continue + end + + # evaluate variables. we can use eval because we most likely just used "$var" + set value (eval echo $value) + + #echo "set -xg '$var' '$value' (via '$e')" + set -xg $var $value +end + +if status --is-interactive + neofetch +end + +set -U fish_user_paths /usr/local/ubin ~/bin ~/go/bin ~/anaconda3/bin $fish_user_paths diff --git a/.config/mpv/f3kdb.vpy b/.config/mpv/f3kdb.vpy new file mode 100644 index 0000000..71415e6 --- /dev/null +++ b/.config/mpv/f3kdb.vpy @@ -0,0 +1,9 @@ +import vapoursynth as vs +core = vs.get_core() + +#core.std.LoadPlugin("/usr/local/lib/libf3kdb.so") + +clip = video_in +clip = core.f3kdb.Deband(clip, grainy=0, grainc=0, output_depth=16) + +clip.set_output() diff --git a/.config/mpv/input.conf b/.config/mpv/input.conf new file mode 100755 index 0000000..63885ab --- /dev/null +++ b/.config/mpv/input.conf @@ -0,0 +1,208 @@ +# mpv keybindings +# +# Location of user-defined bindings: ~/.config/mpv/input.conf +# +# Lines starting with # are comments. Use SHARP to assign the # key. +# Copy this file and uncomment and edit the bindings you want to change. +# +# List of commands and further details: DOCS/man/input.rst +# List of special keys: --input-keylist +# Keybindings testing mode: mpv --input-test --force-window --idle +# +# Use 'ignore' to unbind a key fully (e.g. 'ctrl+a ignore'). +# +# Strings need to be quoted and escaped: +# KEY show_text "This is a single backslash: \\ and a quote: \" !" +# +# You can use modifier-key combinations like Shift+Left or Ctrl+Alt+x with +# the modifiers Shift, Ctrl, Alt and Meta (may not work on the terminal). +# +# The default keybindings are hardcoded into the mpv binary. +# You can disable them completely with: --no-input-default-bindings + +# Developer note: +# On compilation, this file is baked into the mpv binary, and all lines are +# uncommented (unless '#' is followed by a space) - thus this file defines the +# default key bindings. + +# If this is enabled, treat all the following bindings as default. +#default-bindings start + +#MOUSE_BTN0 ignore # don't do anything +#MOUSE_BTN0_DBL cycle fullscreen # toggle fullscreen on/off +#MOUSE_BTN2 cycle pause # toggle pause on/off +#MOUSE_BTN3 seek 10 +#MOUSE_BTN4 seek -10 +#MOUSE_BTN5 add volume 2 +#MOUSE_BTN6 add volume -2 + +# Mouse wheels, touchpad or other input devices that have axes +# if the input devices supports precise scrolling it will also scale the +# numeric value accordingly +#AXIS_UP seek 10 +#AXIS_DOWN seek -10 +#AXIS_LEFT seek 5 +#AXIS_RIGHT seek -5 + +## Seek units are in seconds, but note that these are limited by keyframes +RIGHT seek 10 +LEFT seek -5 +UP seek 20 +DOWN seek -20 +# Do smaller, always exact (non-keyframe-limited), seeks with shift. +# Don't show them on the OSD (no-osd). +#Shift+RIGHT no-osd seek 1 exact +#Shift+LEFT no-osd seek -1 exact +#Shift+UP no-osd seek 5 exact +#Shift+DOWN no-osd seek -5 exact +# Skip to previous/next subtitle (subject to some restrictions; see manpage) +#Ctrl+LEFT no-osd sub_seek -1 +#Ctrl+RIGHT no-osd sub_seek 1 +#PGUP add chapter 1 # skip to next chapter +#PGDWN add chapter -1 # skip to previous chapter +#Shift+PGUP seek 600 +#Shift+PGDWN seek -600 +#[ multiply speed 0.9091 # scale playback speed +#] multiply speed 1.1 +#{ multiply speed 0.5 +#} multiply speed 2.0 +#BS set speed 1.0 # reset speed to normal +#q quit +#Q quit_watch_later +#q {encode} quit +#ESC set fullscreen no +#ESC {encode} quit +#p cycle pause # toggle pause/playback mode +#. frame_step # advance one frame and pause +#, frame_back_step # go back by one frame and pause +#SPACE cycle pause +#> playlist_next # skip to next file +#ENTER playlist_next # skip to next file +#< playlist_prev # skip to previous file +#O osd # cycle through OSD mode +c cycle osd-fractions +#o show_progress +#P show_progress +#I show_text "${filename}" # display filename in osd +#z add sub-delay -0.1 # subtract 100 ms delay from subs +#x add sub-delay +0.1 # add +#ctrl++ add audio-delay 0.100 # this changes audio/video sync +#ctrl+- add audio-delay -0.100 +#9 add volume -2 +/ cycle pause +#0 add volume 2 +#* add volume 2 +#m cycle mute +#1 add contrast -1 +#2 add contrast 1 +#3 add brightness -1 +#4 add brightness 1 +#5 add gamma -1 +#6 add gamma 1 +#7 add saturation -1 +#8 add saturation 1 +#d cycle framedrop # cycle through framedrop modes +# toggle deinterlacer (automatically inserts or removes required filter) +d cycle deinterlace +b cycle deband +#r add sub-pos -1 # move subtitles up +#t add sub-pos +1 # down +#v cycle sub-visibility +# stretch SSA/ASS subtitles with anamorphic videos to match historical +#V cycle ass-vsfilter-aspect-compat +# switch between applying no style overrides to SSA/ASS subtitles, and +# overriding them almost completely with the normal subtitle style +#u cycle_values ass-style-override "force" "no" +#j cycle sub # cycle through subtitles +#J cycle sub down # ...backwards +#SHARP cycle audio # switch audio streams +#_ cycle video +#T cycle ontop # toggle video window ontop of other windows +#f cycle fullscreen # toggle fullscreen +#s screenshot # take a screenshot +#S screenshot video # ...without subtitles +#Ctrl+s screenshot window # ...with subtitles and OSD, and scaled +#Alt+s screenshot each-frame # automatically screenshot every frame +#w add panscan -0.1 # zoom out with -panscan 0 -fs +#e add panscan +0.1 # in +# cycle video aspect ratios; "-1" is the container aspect +#A cycle_values video-aspect "16:9" "4:3" "2.35:1" "-1" +#POWER quit +#PLAY cycle pause +#PAUSE cycle pause +#PLAYPAUSE cycle pause +#STOP quit +#FORWARD seek 60 +#REWIND seek -60 +#NEXT playlist_next +#PREV playlist_prev +#VOLUME_UP add volume 2 +#VOLUME_DOWN add volume -2 +#MUTE cycle mute +#CLOSE_WIN quit +#CLOSE_WIN {encode} quit +#E cycle edition # next edition +#l ab_loop # Set/clear A-B loop points +#L cycle_values loop "inf" "no" # toggle infinite looping +#ctrl+c quit + +# Apple Remote section +#AR_PLAY cycle pause +#AR_PLAY_HOLD quit +#AR_CENTER cycle pause +#AR_CENTER_HOLD quit +#AR_NEXT seek 10 +#AR_NEXT_HOLD seek 120 +#AR_PREV seek -10 +#AR_PREV_HOLD seek -120 +#AR_MENU show_progress +#AR_MENU_HOLD cycle mute +#AR_VUP add volume 2 +#AR_VUP_HOLD add chapter 1 +#AR_VDOWN add volume -2 +#AR_VDOWN_HOLD add chapter -1 + +# For dvdnav:// and bdnav:// + +# navigation controls during playback +#ENTER {discnav} discnav menu # DISCNAV MENU +# BS {discnav} discnav prev # DISCNAV PREVIOUS menu (in the order chapter->title->root) +# navigation controls when showing menu (additionally to the controls above) +#UP {discnav-menu} discnav up # DISCNAV UP +#DOWN {discnav-menu} discnav down # DISCNAV DOWN +#LEFT {discnav-menu} discnav left # DISCNAV LEFT +#RIGHT {discnav-menu} discnav right # DISCNAV RIGHT +#ENTER {discnav-menu} discnav select # DISCNAV SELECT (ok) +#MOUSE_BTN0 {discnav-menu} discnav mouse +#MOUSE_MOVE {discnav-menu} discnav mouse_move + +# For tv:// +#h cycle tv-channel -1 # previous channel +#k cycle tv-channel +1 # next channel + +# +# Legacy bindings (may or may not be removed in the future) +# +#! add chapter -1 # skip to previous chapter +#@ add chapter 1 # next + +# +# Not assigned by default +# (not an exhaustive list of unbound commands) +# + +2 add sub-scale +0.1 # increase subtitle font size +1 add sub-scale -0.1 # decrease subtitle font size +# ? sub_step -1 # immediately display next subtitle +# ? sub_step +1 # previous +# ? cycle_values window-scale 0.5 2 1 # switch between 1/2, 2x, unresized window size +# ? cycle colormatrix +# ? add audio-delay 0.100 # this changes audio/video sync +# ? add audio-delay -0.100 +# ? cycle angle # switch DVD/Bluray angle +# ? add balance -0.1 # adjust audio balance in favor of left +# ? add balance 0.1 # right +# ? cycle sub-forced-only # toggle DVD forced subs +# ? cycle program # cycle transport stream programs +# ? stop # stop playback (quit or enter idle mode) + diff --git a/.config/mpv/motioninterpolation.vpy b/.config/mpv/motioninterpolation.vpy new file mode 100644 index 0000000..26af94b --- /dev/null +++ b/.config/mpv/motioninterpolation.vpy @@ -0,0 +1,74 @@ +# vim: set ft=python: + +# see the README at https://gist.github.com/phiresky/4bfcfbbd05b3c2ed8645 +# source: https://github.com/mpv-player/mpv/issues/2149 +# source: https://github.com/mpv-player/mpv/issues/566 +# source: https://github.com/haasn/gentoo-conf/blob/nanodesu/home/nand/.mpv/filters/mvtools.vpy + +import vapoursynth + +core = vapoursynth.get_core() +# ref: http://avisynth.org.ru/mvtools/mvtools2.html#functions +# default is 400, less means interpolation will only happen when it will work well +ignore_threshold=140 +# if n% of blocks change more than threshold then don't interpolate at all (default is 51%) +scene_change_percentage=15 + +dst_fps = display_fps +# Interpolating to fps higher than 60 is too CPU-expensive, smoothmotion can handle the rest. +# while (dst_fps > 60): +# dst_fps /= 2 + +if "video_in" in globals(): + # realtime + clip = video_in + # Needed because clip FPS is missing + src_fps_num = int(container_fps * 1e8) + src_fps_den = int(1e8) + clip = core.std.AssumeFPS(clip, fpsnum = src_fps_num, fpsden = src_fps_den) +else: + # run with vspipe + clip = core.ffms2.Source(source=in_filename) + dst_fps=float(dst_fps) + +# resolution in megapixels. 1080p ≈ 2MP, 720p ≈ 1MP +mpix = clip.width * clip.height / 1000000 + +# Skip interpolation for >1080p or 60 Hz content due to performance +if not (mpix > 2.5 or clip.fps_num/clip.fps_den > 59): + analParams = { + 'overlap': 0, + 'search': 3, + 'truemotion': True, + #'chrome': True, + #'blksize':16, + #'searchparam':1 + } + blockParams = { + 'thscd1': ignore_threshold, + 'thscd2': int(scene_change_percentage*255/100), + 'mode': 3, + } + + if mpix > 1.5: + # can't handle these on Full HD with Intel i5-2500k + # see the description of these parameters in http://avisynth.org.ru/mvtools/mvtools2.html#functions + analParams['search'] = 0 + blockParams['mode'] = 0 + quality = 'low' + else: + quality = 'high' + + + dst_fps_num = int(dst_fps * 1e4) + dst_fps_den = int(1e4) + print("Reflowing from {} fps to {} fps (quality={})".format(clip.fps_num/clip.fps_den,dst_fps_num/dst_fps_den,quality)) + + sup = core.mv.Super(clip, pel=2) + bvec = core.mv.Analyse(sup, isb=True, **analParams) + fvec = core.mv.Analyse(sup, isb=False, **analParams) + clip = core.mv.BlockFPS(clip, sup, bvec, fvec, + num=dst_fps_num, den=dst_fps_den, + **blockParams) + +clip.set_output() diff --git a/.config/mpv/mpv.conf b/.config/mpv/mpv.conf new file mode 100644 index 0000000..14c2c72 --- /dev/null +++ b/.config/mpv/mpv.conf @@ -0,0 +1,151 @@ +# +# mpv configuration file +# +# Configuration files are read system-wide from /usr/local/etc/mpv.conf +# and per-user from ~/.config/mpv/mpv.conf, where per-user settings override +# system-wide settings, all of which are overridden by the command line. +# +# Configuration file settings and the command line options use the same +# underlying mechanisms. Most options can be put into the configuration file +# by dropping the preceding '--'. See the man page for a complete list of +# options. +# +# Lines starting with '#' are comments and are ignored. +# +# See the CONFIGURATION FILES section in the man page +# for a detailed description of the syntax. +# +# Profiles should be placed at the bottom of the configuration file to ensure +# that settings wanted as defaults are not restricted to specific profiles. +# +# Note that the commented example options usually do _not_ set the default +# values. Calling mpv with --list-options is a nice way to see the default +# values for most options. + +input-unix-socket=~/.config/mpv/mpv.sock + +################## +# video settings # +################## + +no-border +no-osd-bar +osd-level=0 +osd-fractions + +# Specify default video driver (see --vo=help for a list). +#vo=vdpau + +# Start in fullscreen mode by default. +#fs=yes + +# force starting with centered window +#geometry=50%:50% + +# don't allow a new window to have a size larger than 90% of the screen size +#autofit-larger=90%x90% + +# Disable the On Screen Controller (OSC). +#osc=no + +# Keep the player window on top of all other windows. +#ontop=yes + +################## +# audio settings # +################## + +# Specify default audio driver (see --ao=help for a list). +#ao=alsa + +# Disable softvol usage, and always use the system mixer if available. +#softvol=no + +# Scale audio tempo by playback speed without altering pitch. (By default does +# nothing if playback speed is not changed. May introduce artifacts.) +#af=scaletempo + +# Output 5.1 audio natively, and upmix/downmix audio with a different format. +#audio-channels=5.1 +# Disable any automatic remix, _if_ the audio output accepts the audio format. +# of the currently played file. +#audio-channels=empty +audio-normalize-downmix=yes + +################## +# other settings # +################## + +# Pretend to be a web browser. Might fix playback with some streaming sites, +# but also will break with shoutcast streams. +#user-agent="Mozilla/5.0" + +# cache settings +# +# Use 8MB input cache by default. The cache is enabled for network streams only. +#cache-default=8192 +# +# Use 8MB input cache for everything, even local files. +#cache=8192 +# +# If a seek is issued, and the target is 1024KB past the cached range, then +# keep reading until the seek target is hit, instead of doing a real seek. +#cache-seek-min=1024 +# +# Disable the behavior that the player will pause if the cache goes below a +# certain fill size. +#cache-pause=no +# +# Read ahead about 5 seconds of audio and video packets. +#demuxer-readahead-secs=5.0 + +# Display English subtitles if available. +slang=en + +# Play Finnish audio if available, fall back to English otherwise. +alang=jpn,en + +# Change subtitle encoding. For Arabic subtitles use 'cp1256'. +# If the file seems to be valid UTF-8, prefer UTF-8. +#sub-codepage=utf8:cp1256 + +# Enable hardware decoding if available. Often, this requires using an certain +# video output, otherwise no hardware decoding will be used. +#hwdec=auto + +############ +# Profiles # +############ + +# The options declared as part of profiles override global default settings, +# but only take effect when the profile is active. + +# The following profile can be enabled on the command line with: --profile=vdpau + +#[vdpau] +# The profile forces the vdpau VO. +#vo=vdpau +# Use hardware decoding (this might break playback of some h264 files) +#hwdec=vdpau +# Most video filters do not work with hardware decoding. +#vf-clr=yes + +#vo=opengl-hq +#vo=opengl-hq:interpolation +hwdec=vaapi +#hwdec=cuda +#hwdec=auto +vo=gpu + +video-sync=display-resample + +#vf=dejudder +#vf=format=yuv420p,vapoursynth=~~/motioninterpolation.vpy:4:4 + +# You can also include other configuration files. +#include=/path/to/the/file/you/want/to/include + +screenshot-format=png +screenshot-template="~/Desktop/%tF %tH-%tM-%tS screenshot" +fullscreen + diff --git a/.config/mpv/shaders/deband.glsl b/.config/mpv/shaders/deband.glsl new file mode 100755 index 0000000..b473f78 --- /dev/null +++ b/.config/mpv/shaders/deband.glsl @@ -0,0 +1,84 @@ +// GLSL debanding shader, use as: source-shader=path/to/deband.glsl +// (Loosely based on flash3kyuu_deband, but expanded to multiple iterations) + +//------------ Configuration section ------------ +// The threshold of difference below which a pixel is considered to be part of +// a gradient. Higher = more debanding, but setting it too high diminishes image +// details. +#define THRESHOLD 64 + +// The range (in source pixels) at which to sample for neighbours. Higher values +// will find more gradients, but lower values will deband more aggressively. +#define RANGE 8 + +// The number of debanding iterations to perform. Each iteration samples from +// random positions, so increasing the number of iterations is likely to +// increase the debanding quality. Conversely, it slows the shader down. +// (Each iteration will use a multiple of the configured RANGE, and a +// successively lower THRESHOLD - so setting it much higher has little effect) +#define ITERATIONS 4 + +// (Optional) Add some extra noise to the image. This significantly helps cover +// up remaining banding and blocking artifacts, at comparatively little visual +// quality. Higher = more grain. Setting it to 0 disables the effect. +#define GRAIN 48 + +// Note: If performance is too slow, try eg. RANGE=16 ITERATIONS=2. In general, +// an increase in the number of ITERATIONS should roughly correspond to a +// decrease in RANGE and perhaps an increase in THRESHOLD. +//------------ End of configuration ------------ + +// Wide usage friendly PRNG, shamelessly stolen from a GLSL tricks forum post +float mod289(float x) { return x - floor(x / 289.0) * 289.0; } +float permute(float x) { return mod289((34.0*x + 1.0) * x); } +float rand(float x) { return fract(x / 41.0); } + +// Helper: Calculate a stochastic approximation of the avg color around a pixel +vec4 average(sampler2D tex, vec2 pos, float range, inout float h) +{ + // Compute a random rangle and distance + float dist = rand(h) * range; h = permute(h); + float dir = rand(h) * 6.2831853; h = permute(h); + + vec2 pt = dist / image_size; + vec2 o = vec2(cos(dir), sin(dir)); + + // Sample at quarter-turn intervals around the source pixel + vec4 ref[4]; + ref[0] = texture(tex, pos + pt * vec2( o.x, o.y)); + ref[1] = texture(tex, pos + pt * vec2(-o.y, o.x)); + ref[2] = texture(tex, pos + pt * vec2(-o.x, -o.y)); + ref[3] = texture(tex, pos + pt * vec2( o.y, -o.x)); + + // Return the (normalized) average + return cmul*(ref[0] + ref[1] + ref[2] + ref[3])/4.0; +} + +vec4 sample(sampler2D tex, vec2 pos, vec2 tex_size) +{ + float h; + // Initialize the PRNG by hashing the position + a random uniform + vec3 m = vec3(pos, random) + vec3(1.0); + h = permute(permute(permute(m.x)+m.y)+m.z); + + // Sample the source pixel + vec4 col = cmul*texture(tex, pos); + + for (int i = 1; i <= ITERATIONS; i++) { + // Use the average instead if the difference is below the threshold + vec4 avg = average(tex, pos, i*RANGE, h); + vec4 diff = abs(col - avg); + col = mix(avg, col, greaterThan(diff, vec4(THRESHOLD/(i*16384.0)))); + } + + // Add some random noise to the output + vec3 noise; + noise.x = rand(h); h = permute(h); + noise.y = rand(h); h = permute(h); + noise.z = rand(h); h = permute(h); + col.rgb += (GRAIN/8192.0) * (noise - vec3(0.5)); + + return col; +} + +// vim: set ft=glsl: diff --git a/.config/mpv/xrandr.lua b/.config/mpv/xrandr.lua new file mode 100644 index 0000000..7e3f63a --- /dev/null +++ b/.config/mpv/xrandr.lua @@ -0,0 +1,261 @@ +-- use xrandr command to set output to best fitting fps rate +-- when playing videos with mpv. + +utils = require 'mp.utils' + + + +xrandr_blacklist = {} +function xrandr_parse_blacklist() + -- Parse the optional "blacklist" from a string into an array for later use. + -- For now, we only support a list of rates, since the "mode" is not subject + -- to automatic change (mpv is better at scaling than most displays) and + -- this also makes the blacklist option more easy to specify: + local b = mp.get_opt("xrandr-blacklist") + if (b == nil) then + return + end + + local i = 1 + for s in string.gmatch(b, "([^, ]+)") do + xrandr_blacklist[i] = 0.0 + s + i = i+1 + end +end +xrandr_parse_blacklist() + + +function xrandr_check_blacklist(mode, rate) + -- check if (mode, rate) is black-listed - e.g. because the + -- computer display output is known to be incompatible with the + -- display at this specific mode/rate + + for i=1,#xrandr_blacklist do + r = xrandr_blacklist[i] + + if (r == rate) then + mp.msg.log("info", "will not use mode '" .. mode .. "' with rate " .. rate .. " because option -script-opts=xrandr-blacklist said so") + return true + end + end + + return false +end + +xrandr_detect_done = false +xrandr_modes = {} +xrandr_connected_outputs = {} +function xrandr_detect_available_rates() + if (xrandr_detect_done) then + return + end + xrandr_detect_done = true + + -- invoke xrandr to find out which fps rates are available on which outputs + + local p = {} + p["cancellable"] = false + p["args"] = {} + p["args"][1] = "xrandr" + p["args"][2] = "-q" + local res = utils.subprocess(p) + + if (res["error"] ~= nil) then + mp.msg.log("info", "failed to execute 'xrand -q', error message: " .. res["error"]) + return + end + + mp.msg.log("v","xrandr -q\n" .. res["stdout"]) + + local output_idx = 1 + for output in string.gmatch(res["stdout"], '\n([^ ]+) connected') do + + table.insert(xrandr_connected_outputs, output) + + -- the first line with a "*" after the match contains the mode associated with the mode + local mls = string.match(res["stdout"], "\n" .. string.gsub(output, "%p", "%%%1") .. " connected.*") + local r + local mode + mode, r = string.match(mls, '\n ([0-9x]+) ([^*\n]*%*[^\n]*)') + + if (r == nil) then + -- if no refresh rate is reported active for an output by xrandr, + -- search for the mode that is "recommended" (marked by "+" in xrandr's output) + mode, r = string.match(mls, '\n ([0-9x]+) ([^+\n]*%+[^\n]*)') + end + mp.msg.log("info", "output " .. output .. " mode=" .. mode .. " refresh rates = " .. r) + + xrandr_modes[output] = { mode = mode, rates_s = r, rates = {} } + local i = 1 + for s in string.gmatch(r, "([^ +*]+)") do + + -- check if rate "r" is black-listed - this is checked here because + if (not xrandr_check_blacklist(mode, 0.0 + s)) then + xrandr_modes[output].rates[i] = 0.0 + s + i = i+1 + end + end + + output_idx = output_idx + 1 + end + +end + +function xrandr_find_best_fitting_rate(fps, output) + + local xrandr_rates = xrandr_modes[output].rates + + -- try integer multipliers of 1 to 3, in that order + for m=1,3 do + + -- check for a "perfect" match (where fps rates of e.g. 60.0 are not equal 59.9 or such) + for i=1,#xrandr_rates do + r = xrandr_rates[i] + if (math.abs(r-(m * fps)) < 0.001) then + return r + end + end + + end + + for m=1,3 do + + -- check for a "less precise" match (where fps rates of e.g. 60.0 and 59.9 are assumed "equal") + for i=1,#xrandr_rates do + r = xrandr_rates[i] + if (math.abs(r-(m * fps)) < 0.2) then + if (m == 1) then + -- pass the original rate to xrandr later, because + -- e.g. a 23.976 Hz mode might be displayed as "24.0", + -- but still xrandr may set the better matching mode + -- if the exact number is passed + return fps + else + return r + end + + end + end + + end + + -- if no known frame rate is any "good", use the highest available frame rate, + -- as this will probably cause the least "jitter" + + local mr = 0.0 + for i=1,#xrandr_rates do + r = xrandr_rates[i] + -- mp.msg.log("v","r=" .. r .. " mr=" .. mr) + if (r > mr) then + mr = r + end + end + + return mr +end + + +xrandr_active_outputs = {} +function xrandr_set_active_outputs() + local dn = mp.get_property("display-names") + + if (dn ~= nil) then + mp.msg.log("v","display-names=" .. dn) + xrandr_active_outputs = {} + for w in (dn .. ","):gmatch("([^,]*),") do + table.insert(xrandr_active_outputs, w) + end + end +end + +-- last detected non-nil video frame rate: +xrandr_cfps = nil + +-- for each output, we remember which refresh rate we set last, so +-- we do not unnecessarily set the same refresh rate again +xrandr_previously_set = {} + +function xrandr_set_rate() + + local f = mp.get_property_native("fps") + if (f == nil or f == xrandr_cfps) then + -- either no change or no frame rate information, so don't set anything + return + end + xrandr_cfps = f + + xrandr_detect_available_rates() + + xrandr_set_active_outputs() + + local vdpau_hack = false + local old_vid = nil + local old_position = nil + if (mp.get_property("options/vo") == "vdpau") then + -- enable wild hack: need to close and re-open video for vdpau, + -- because vdpau barfs if xrandr is run while it is in use + + vdpau_hack = true + old_position = mp.get_property("time-pos") + old_vid = mp.get_property("vid") + mp.set_property("vid", "no") + end + + local outs = {} + if (#xrandr_active_outputs == 0) then + -- No active outputs - probably because vo (like with vdpau) does + -- not provide the information which outputs are covered. + -- As a fall-back, let's assume all connected outputs are relevant. + mp.msg.log("v","no output is known to be used by mpv, assuming all connected outputs are used.") + outs = xrandr_connected_outputs + else + outs = xrandr_active_outputs + end + + -- iterate over all relevant outputs used by mpv's output: + for n, output in ipairs(outs) do + + local bfr = xrandr_find_best_fitting_rate(xrandr_cfps, output) + + if (bfr == 0.0) then + mp.msg.log("info", "no non-blacklisted rate available, not invoking xrandr") + else + mp.msg.log("info", "container fps is " .. xrandr_cfps .. "Hz, for output " .. output .. " mode " .. xrandr_modes[output].mode .. " the best fitting display fps rate is " .. bfr .. "Hz") + + if (bfr == xrandr_previously_set[output]) then + mp.msg.log("v", "output " .. output .. " was already set to " .. bfr .. "Hz before - not changing") + else + -- invoke xrandr to set the best fitting refresh rate for output + local p = {} + p["cancellable"] = false + p["args"] = {} + p["args"][1] = "xrandr" + p["args"][2] = "--output" + p["args"][3] = output + p["args"][4] = "--mode" + p["args"][5] = xrandr_modes[output].mode + p["args"][6] = "--rate" + p["args"][7] = bfr + + local res = utils.subprocess(p) + + if (res["error"] ~= nil) then + mp.msg.log("error", "failed to set refresh rate for output " .. output .. " using xrandr, error message: " .. res["error"]) + else + xrandr_previously_set[output] = bfr + end + end + end + + end + + if (vdpau_hack) then + mp.set_property("vid", old_vid) + mp.commandv("seek", old_position, "absolute", "keyframes") + end +end + +-- we'll consider setting refresh rates whenever the video fps or the active outputs change: +mp.observe_property("fps", "native", xrandr_set_rate) +mp.observe_property("display-names", "native", xrandr_set_rate) + diff --git a/.config/polybar/config b/.config/polybar/config new file mode 100644 index 0000000..6b399ba --- /dev/null +++ b/.config/polybar/config @@ -0,0 +1,162 @@ +;========================================================== +; +; +; ██████╗ ██████╗ ██╗ ██╗ ██╗██████╗ █████╗ ██████╗ +; ██╔══██╗██╔═══██╗██║ ╚██╗ ██╔╝██╔══██╗██╔══██╗██╔══██╗ +; ██████╔╝██║ ██║██║ ╚████╔╝ ██████╔╝███████║██████╔╝ +; ██╔═══╝ ██║ ██║██║ ╚██╔╝ ██╔══██╗██╔══██║██╔══██╗ +; ██║ ╚██████╔╝███████╗██║ ██████╔╝██║ ██║██║ ██║ +; ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ +; +; +; To learn more about how to configure Polybar +; go to https://github.com/polybar/polybar +; +; The README contains a lot of information +; +;========================================================== + +[colors] +;background = ${xrdb:color0:#222} +background = #002b2f2f +background-alt = #002b2f2f +;foreground = ${xrdb:color7:#222} +foreground = #ffffff +foreground-alt = #ffffff +primary = #fffff +secondary = #ffffff +alert = #bd2c40 + +[paddings] +inner = 2.5 +outer = 5 + +[bar/top] +width = 1000 +height = 24 +offset-x = 1220 +offset-y = 0 +radius = 0.0 +fixed-center = true + +background = ${colors.background} +foreground = ${colors.foreground} + +line-size = 3 +line-color = #f00 + +border-size = 0 +border-color = #00000000 + +padding-left = 0 +padding-right = 2 + +module-margin-left = 1 +module-margin-right = 1 + +font-0 = fixed:pixelsize=10;1 +font-1 = unifont:fontformat=truetype:size=9:antialias=false;0 +font-2 = siji:pixelsize=11;1 + +modules-left = +modules-center = filesystem filesystem-data eth memory cpu temperature +modules-right = + +;tray-position = none +;tray-padding = 2 +;tray-background = #0063ff + +;wm-restack = bspwm + +;i3 stuff +;wm-restack = i3 +;override-redirect = true + +;kde stuff +override-redirect = false + +;scroll-up = bspwm-desknext +;scroll-down = bspwm-deskprev + +;scroll-up = i3wm-wsnext +;scroll-down = i3wm-wsprev + +cursor-click = pointer +cursor-scroll = ns-resize + + +[module/filesystem] +type = internal/fs +interval = 25 + +mount-0 = / + +label-mounted = %{F#00B6A6}%mountpoint%%{F-}: %percentage_used%% %free% +label-unmounted = %mountpoint% not mounted +label-unmounted-foreground = ${colors.foreground-alt} + +[module/cpu] +type = internal/cpu +interval = 2 +format-prefix = " " +format-prefix-foreground = ${colors.foreground-alt} +format-underline = #f90000 +label = %percentage:2%% + +[module/memory] +type = internal/memory +interval = 2 +format-prefix = " " +format-prefix-foreground = ${colors.foreground-alt} +format-underline = #4bffdc +label = %percentage_used%% + +[module/eth] +type = internal/network +interface = enp6s0 +interval = 3.0 + +format-connected-underline = #55aa55 +format-connected-prefix = " " +format-connected-prefix-foreground = ${colors.foreground-alt} +label-connected = %local_ip% %downspeed:8% %upspeed:8% + +format-disconnected = +;format-disconnected = +;format-disconnected-underline = ${self.format-connected-underline} +;label-disconnected = %ifname% disconnected +;label-disconnected-foreground = ${colors.foreground-alt} + +[module/temperature] +type = internal/temperature +interval = 2 +hwmon-path = /sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon2/temp1_input +warn-temperature = 60 + +format =