From: copycat-killer Date: Thu, 12 Jan 2017 17:33:57 +0000 (+0100) Subject: quake: skip_wibox option added #263; mpd: removed mpdcover script call (much faster... X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/d549219a2eaa9bcd8e9c2a3c65a0342dca74d1b1?ds=inline;hp=--cc quake: skip_wibox option added #263; mpd: removed mpdcover script call (much faster now) --- d549219a2eaa9bcd8e9c2a3c65a0342dca74d1b1 diff --git a/layout/uselessfair.lua b/layout/uselessfair.lua deleted file mode 100644 index e1284e0..0000000 --- a/layout/uselessfair.lua +++ /dev/null @@ -1,108 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2014, projektile, worron - * (c) 2013, Luke Bonham - * (c) 2012, Josh Komoroske - * (c) 2010-2012, Peter Hofmann - ---]] - -local beautiful = require("beautiful") -local ipairs = ipairs -local math = { ceil = math.ceil, sqrt = math.sqrt, floor = math.floor, max = math.max } -local tonumber = tonumber - -local uselessfair = {} - --- Transformation functions -local function swap(geometry) - return { x = geometry.y, y = geometry.x, width = geometry.height, height = geometry.width } -end - --- Client geometry correction depending on useless gap and window border -local function size_correction(c, geometry, useless_gap) - geometry.width = math.max(geometry.width - 2 * c.border_width - useless_gap, 1) - geometry.height = math.max(geometry.height - 2 * c.border_width - useless_gap, 1) - geometry.x = geometry.x + useless_gap / 2 - geometry.y = geometry.y + useless_gap / 2 -end - --- Main tiling function -local function fair(p, orientation) - - -- Theme vars - local useless_gap = beautiful.useless_gap_width or 0 - local global_border = beautiful.global_border_width or 0 - - -- Aliases - local wa = p.workarea - local cls = p.clients - - -- Nothing to tile here - if #cls == 0 then return end - - -- Workarea size correction depending on useless gap and global border - wa.height = wa.height - 2 * global_border - useless_gap - wa.width = wa.width - 2 * global_border - useless_gap - wa.x = wa.x + useless_gap / 2 + global_border - wa.y = wa.y + useless_gap / 2 + global_border - - -- Geometry calculation - local row, col = 0, 0 - - local rows = math.ceil(math.sqrt(#cls)) - local cols = math.ceil(#cls / rows) - - for i, c in ipairs(cls) do - local g = {} - - -- find tile orientation for current client and swap geometry if need - local need_swap = (orientation == "east" and #cls <= 2) or (orientation == "south" and #cls > 2) - local area = need_swap and swap(wa) or wa - - -- calculate geometry - if #cls < (cols * rows) and row == cols - 1 then - g.width = area.width / (rows - ((cols * rows) - #cls)) - else - g.width = area.width / rows - end - - g.height = area.height / cols - g.x = area.x + col * g.width - g.y = area.y + row * g.height - - -- turn back to real if geometry was swapped - if need_swap then g = swap(g) end - - -- window size correction depending on useless gap and window border - size_correction(c, g, useless_gap) - - -- set geometry - c:geometry(g) - - -- update tile grid coordinates - col = i % rows - row = math.floor(i / rows) - end -end - --- Layout constructor -local function construct_layout(name, direction) - return { - name = name, - -- @p screen The screen number to tile - arrange = function(p) return fair(p, direction) end - } -end - --- Build layouts with different tile direction -uselessfair.vertical = construct_layout("uselessfair", "south") -uselessfair.horizontal = construct_layout("uselessfairh", "east") - --- Module aliase -uselessfair.arrange = uselessfair.vertical.arrange -uselessfair.name = uselessfair.vertical.name - -return uselessfair diff --git a/layout/uselesspiral.lua b/layout/uselesspiral.lua deleted file mode 100644 index c388961..0000000 --- a/layout/uselesspiral.lua +++ /dev/null @@ -1,123 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2014, projektile - * (c) 2013, Luke Bonham - * (c) 2009, Uli Schlachter - * (c) 2008, Julien Danjolu - ---]] - -local beautiful = require("beautiful") -local ipairs = ipairs -local tonumber = tonumber -local math = require("math") - -local uselesspiral = {} - -local function spiral(p, spiral) - -- A useless gap (like the dwm patch) can be defined with - -- beautiful.useless_gap_width. - local useless_gap = tonumber(beautiful.useless_gap_width) or 0 - if useless_gap < 0 then useless_gap = 0 end - - -- A global border can be defined with - -- beautiful.global_border_width - local global_border = tonumber(beautiful.global_border_width) or 0 - if global_border < 0 then global_border = 0 end - - -- Themes border width requires an offset - local bw = tonumber(beautiful.border_width) or 0 - - -- get our orientation right - local wa = p.workarea - local cls = p.clients - local n = #cls -- number of windows total; k = which window number - - wa.height = wa.height - ((global_border * 2) + (bw * 2)) - wa.width = wa.width - ((global_border * 2) + (bw * 2)) - - local static_wa = wa - - for k, c in ipairs(cls) do - if k < n then - if k % 2 == 0 then - wa.height = (wa.height / 2) - else - wa.width = (wa.width / 2) - end - end - - if k % 4 == 0 and spiral then - wa.x = wa.x - wa.width - elseif k % 2 == 0 or - (k % 4 == 3 and k < n and spiral) then - wa.x = wa.x + wa.width - end - - if k % 4 == 1 and k ~= 1 and spiral then - wa.y = wa.y - wa.height - elseif k % 2 == 1 and k ~= 1 or - (k % 4 == 0 and k < n and spiral) then - wa.y = wa.y + wa.height - end - - local wa2 = {} - wa2.x = wa.x + (useless_gap / 2) + global_border - wa2.y = wa.y + (useless_gap / 2) + global_border - wa2.height = wa.height - (useless_gap / 2) - wa2.width = wa.width - (useless_gap / 2) - - -- Useless gap. - if useless_gap > 0 - then - -- Top and left clients are shrinked by two steps and - -- get moved away from the border. Other clients just - -- get shrinked in one direction. - - top = false - left = false - - if wa2.y == static_wa.y then - top = true - end - - if wa2.x == static_wa.x then - left = true - end - - if top then - wa2.height = wa2.height - useless_gap - wa2.y = wa2.y - (useless_gap / 2) - else - wa2.height = wa2.height - (useless_gap / 2) - end - - if left then - wa2.width = wa2.width - useless_gap - wa2.x = wa2.x - (useless_gap / 2) - else - wa2.width = wa2.width - (useless_gap / 2) - end - end - -- End of useless gap. - - c:geometry(wa2) - end -end - ---- Dwindle layout -uselesspiral.dwindle = {} -uselesspiral.dwindle.name = "uselessdwindle" -function uselesspiral.dwindle.arrange(p) - return spiral(p, false) -end - ---- Spiral layout -uselesspiral.name = "uselesspiral" -function uselesspiral.arrange(p) - return spiral(p, true) -end - -return uselesspiral diff --git a/layout/uselesstile.lua b/layout/uselesstile.lua deleted file mode 100644 index ee33060..0000000 --- a/layout/uselesstile.lua +++ /dev/null @@ -1,231 +0,0 @@ - ---[[ - - Licensed under GNU General Public License v2 - * (c) 2014, projektile, worron - * (c) 2013, Luke Bonham - * (c) 2009, Donald Ephraim Curtis - * (c) 2008, Julien Danjolu - ---]] - -local tag = require("awful.tag") -local beautiful = require("beautiful") -local ipairs = ipairs -local math = { floor = math.floor, - ceil = math.ceil, - max = math.max, - min = math.min } -local tonumber = tonumber - -local uselesstile = {} - --- Transformation functions -local function flip(canvas, geometry) - return { - -- vertical only - x = 2 * canvas.x + canvas.width - geometry.x - geometry.width, - y = geometry.y, - width = geometry.width, - height = geometry.height - } -end - -local function swap(geometry) - return { x = geometry.y, y = geometry.x, width = geometry.height, height = geometry.width } -end - --- Find geometry for secondary windows column -local function cut_column(wa, n, index) - local width = math.floor(wa.width / n) - local area = { x = wa.x + (index - 1) * width, y = wa.y, width = width, height = wa.height } - - return area -end - --- Find geometry for certain window in column -local function cut_row(wa, factor, index, used) - local height = math.floor(wa.height * factor.window[index] / factor.total) - local area = { x = wa.x, y = wa.y + used, width = wa.width, height = height } - - return area -end - --- Client geometry correction depending on useless gap and window border -local function size_correction(c, geometry, useless_gap) - geometry.width = math.max(geometry.width - 2 * c.border_width - useless_gap, 1) - geometry.height = math.max(geometry.height - 2 * c.border_width - useless_gap, 1) - geometry.x = geometry.x + useless_gap / 2 - geometry.y = geometry.y + useless_gap / 2 -end - --- Check size factor for group of clients and calculate total -local function calc_factor(n, winfactors) - local factor = { window = winfactors, total = 0, min = 1 } - - for i = 1, n do - if not factor.window[i] then - factor.window[i] = factor.min - else - factor.min = math.min(factor.window[i], factor.min) - if factor.window[i] < 0.05 then factor.window[i] = 0.05 end - end - factor.total = factor.total + factor.window[i] - end - - return factor -end - --- Tile group of clients in given area --- @canvas need for proper transformation only --- @winfactors table with clients size factors -local function tile_column(canvas, area, list, useless_gap, transformation, winfactors) - local used = 0 - local factor = calc_factor(#list, winfactors) - - for i, c in ipairs(list) do - local g = cut_row(area, factor, i, used) - if i == #list then g.height = area.height - used end - used = used + g.height - - -- swap workarea dimensions - if transformation.flip then g = flip(canvas, g) end - if transformation.swap then g = swap(g) end - - -- useless gap and border correction - size_correction(c, g, useless_gap) - - - c:geometry(g) - end -end - ---Main tile function -local function tile(p, orientation) - - -- Theme vars - local useless_gap = beautiful.useless_gap_width or 0 - local global_border = beautiful.global_border_width or 0 - - -- Aliases - local wa = p.workarea - local cls = p.clients - local t = tag.selected(p.screen) - - -- Nothing to tile here - if #cls == 0 then return end - - -- Get tag prop - local nmaster = math.min(tag.getnmaster(t), #cls) - local mwfact = tag.getmwfact(t) - - if nmaster == 0 then - mwfact = 0 - elseif nmaster == #cls then - mwfact = 1 - end - - -- clients size factor - local data = tag.getdata(t).windowfact - - if not data then - data = {} - tag.getdata(t).windowfact = data - end - - -- Workarea size correction depending on useless gap and global border - wa.height = wa.height - 2 * global_border - useless_gap - wa.width = wa.width - 2 * global_border - useless_gap - wa.x = wa.x + useless_gap / 2 + global_border - wa.y = wa.y + useless_gap / 2 + global_border - - -- Find which transformation we need for given orientation - local transformation = { - swap = orientation == 'top' or orientation == 'bottom', - flip = orientation == 'left' or orientation == 'top' - } - - -- Swap workarea dimensions if orientation vertical - if transformation.swap then wa = swap(wa) end - - -- Split master and other windows - local cls_master, cls_other = {}, {} - - for i, c in ipairs(cls) do - if i <= nmaster then - table.insert(cls_master, c) - else - table.insert(cls_other, c) - end - end - - -- Tile master windows - local master_area = { - x = wa.x, - y = wa.y, - width = nmaster > 0 and math.floor(wa.width * mwfact) or 0, - height = wa.height - } - - if not data[0] then data[0] = {} end - tile_column(wa, master_area, cls_master, useless_gap, transformation, data[0]) - - -- Tile other windows - local other_area = { - x = wa.x + master_area.width, - y = wa.y, - width = wa.width - master_area.width, - height = wa.height - } - - -- get column number for other windows - local ncol = math.min(tag.getncol(t), #cls_other) - - if ncol == 0 then ncol = 1 end - - -- split other windows to column groups - local last_small_column = ncol - #cls_other % ncol - local rows_min = math.floor(#cls_other / ncol) - - local client_index = 1 - local used = 0 - for i = 1, ncol do - local position = transformation.flip and ncol - i + 1 or i - local rows = i <= last_small_column and rows_min or rows_min + 1 - local column = {} - - for j = 1, rows do - table.insert(column, cls_other[client_index]) - client_index = client_index + 1 - end - - -- and tile - local column_area = cut_column(other_area, ncol, position) - if i == ncol then column_area.width = other_area.width - used end - used = used + column_area.width - - if not data[i] then data[i] = {} end - tile_column(wa, column_area, column, useless_gap, transformation, data[i]) - end -end - --- Layout constructor -local function construct_layout(name, orientation) - return { - name = name, - -- @p screen number to tile - arrange = function(p) return tile(p, orientation) end - } -end - --- Build layouts with different tile direction -uselesstile.right = construct_layout("uselesstile", "right") -uselesstile.left = construct_layout("uselesstileleft", "left") -uselesstile.bottom = construct_layout("uselesstilebottom", "bottom") -uselesstile.top = construct_layout("uselesstiletop", "top") - --- Module aliase -uselesstile.arrange = uselesstile.right.arrange -uselesstile.name = uselesstile.right.name - -return uselesstile diff --git a/scripts/mpdcover b/scripts/mpdcover deleted file mode 100755 index a611666..0000000 --- a/scripts/mpdcover +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash -# -# A simple cover fetcher script for current playing song on mpd. -# -# Original author: Wolfgang Mueller -# -# Adapted for Lain internal use. -# https://github.com/copycat-killer/lain -# -# You can use, edit and redistribute this script in any way you like. -# -# Dependencies: imagemagick. -# -# Usage: mpdcover - -# Configuration------------------------------------------------------- - -# Music directory -MUSIC_DIR=$1 - -# Song file -file=$2 - -# Regex expression used for image search -IMG_REG="(Front|front|Cover|cover|Art|art|Folder|folder)\.(jpg|jpeg|png|gif)$" - -# Path of temporary resized cover -TEMP_PATH="/tmp/mpdcover.png" - -# Resize cover -COVER_RESIZE="$3x$3" - -if [ $COVER_RESIZE == "x" ]; then - COVER_RESIZE="100x100" -fi - -# The default cover to use (optional) -DEFAULT_ART=$4 - -#-------------------------------------------------------------------- - -# check if anything is playing at all -[[ -z $file ]] && exit 1 - -# Art directory -art="$MUSIC_DIR/${file%/*}" - -# find every file that matches IMG_REG set the first matching file to be the -# cover. -cover="$(find "$art/" -maxdepth 1 -type f | egrep -i -m1 "$IMG_REG")" - -# when no cover is found, use DEFAULT_ART as cover -cover="${cover:=$DEFAULT_ART}" - -# check if art is available -if [[ -n $cover ]]; then - if [[ -n $COVER_RESIZE ]]; then - convert "$cover" -scale $COVER_RESIZE "$TEMP_PATH" - cover="$TEMP_PATH" - fi -else - rm $TEMP_PATH -fi - -exit 0 diff --git a/util/quake.lua b/util/quake.lua index 8a530f3..9f548a8 100644 --- a/util/quake.lua +++ b/util/quake.lua @@ -97,7 +97,12 @@ function quake:display() end function quake:compute_size() - local geom = screen[self.screen].workarea + local geom + if self.skip_wibox then + geom = screen[self.screen].workarea + else + geom = screen[self.screen].geometry + end local width, height = self.width, self.height if width <= 1 then width = math.floor(geom.width * width) - 2 * self.border end if height <= 1 then height = math.floor(geom.height * height) end @@ -114,14 +119,15 @@ end function quake:new(config) local conf = config or {} - conf.app = conf.app or "xterm" -- application to spawn - conf.name = conf.name or "QuakeDD" -- window name - conf.argname = conf.argname or "-name %s" -- how to specify window name - conf.extra = conf.extra or "" -- extra arguments - conf.visible = conf.visible or false -- initially not visible - conf.border = conf.border or 1 -- client border width - conf.followtag = conf.followtag or true -- spawn on currently focused screen - conf.screen = conf.screen or awful.screen.focused() + conf.app = conf.app or "xterm" -- application to spawn + conf.name = conf.name or "QuakeDD" -- window name + conf.argname = conf.argname or "-name %s" -- how to specify window name + conf.extra = conf.extra or "" -- extra arguments + conf.visible = conf.visible or false -- initially not visible + conf.border = conf.border or 1 -- client border width + conf.followtag = conf.followtag or true -- spawn on currently focused screen + conf.skip_wibox = conf.skip_wibox or true -- skip the wibox (defaut) or overlap it + conf.screen = conf.screen or awful.screen.focused() -- If width or height <= 1 this is a proportion of the workspace conf.height = conf.height or 0.25 -- height diff --git a/widgets/mpd.lua b/widgets/mpd.lua index ce48014..ebdda98 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -7,20 +7,18 @@ --]] -local helpers = require("lain.helpers") local async = require("lain.asyncshell") +local helpers = require("lain.helpers") local escape_f = require("awful.util").escape local focused = require("awful.screen").focused local naughty = require("naughty") local wibox = require("wibox") -local os = { execute = os.execute, - getenv = os.getenv } -local math = { floor = math.floor } -local string = { format = string.format, - match = string.match, - gmatch = string.gmatch } +local os = { getenv = os.getenv } +local string = { format = string.format, + gmatch = string.gmatch, + match = string.match } local setmetatable = setmetatable @@ -29,22 +27,22 @@ local setmetatable = setmetatable local mpd = helpers.make_widget_textbox() local function worker(args) - local args = args or {} - local timeout = args.timeout or 2 - local password = args.password or "" - local host = args.host or "127.0.0.1" - local port = args.port or "6600" - local music_dir = args.music_dir or os.getenv("HOME") .. "/Music" - local cover_size = args.cover_size or 100 - local default_art = args.default_art or "" - local notify = args.notify or "on" - local followtag = args.followtag or false - local echo_cmd = args.echo_cmd or "echo" - local settings = args.settings or function() end - - local mpdcover = helpers.scripts_dir .. "mpdcover" - local mpdh = "telnet://" .. host .. ":" .. port - local echo = echo_cmd .. " 'password " .. password .. "\nstatus\ncurrentsong\nclose'" + local args = args or {} + local timeout = args.timeout or 2 + local password = args.password or "" + local host = args.host or "127.0.0.1" + local port = args.port or "6600" + local music_dir = args.music_dir or os.getenv("HOME") .. "/Music" + local cover_pattern = args.cover_pattern or "*\\.(jpg|jpeg|png|gif)$" + local cover_size = args.cover_size or 100 + local default_art = args.default_art or "" + local notify = args.notify or "on" + local followtag = args.followtag or false + local echo_cmd = args.echo_cmd or "echo" + local settings = args.settings or function() end + + local mpdh = string.format("telnet://%s:%s", host, port) + local echo = string.format("%s 'password %s\nstatus\ncurrentsong\nclose'", echo_cmd, password) mpd_notification_preset = { title = "Now playing", @@ -54,7 +52,7 @@ local function worker(args) helpers.set_map("current mpd track", nil) function mpd.update() - async.request(echo .. " | curl --connect-timeout 1 -fsm 3 " .. mpdh, function (f) + async.request(string.format("%s | curl --connect-timeout 1 -fsm 3 %s", echo, mpdh), function (f) mpd_now = { random_mode = false, single_mode = false, @@ -103,34 +101,28 @@ local function worker(args) widget = mpd.widget settings() - if mpd_now.state == "play" - then - if notify == "on" and mpd_now.title ~= helpers.get_map("current mpd track") - then + if mpd_now.state == "play" then + if notify == "on" and mpd_now.title ~= helpers.get_map("current mpd track") then helpers.set_map("current mpd track", mpd_now.title) - if string.match(mpd_now.file, "http.*://") == nil - then -- local file - os.execute(string.format("%s %q %q %d %q", mpdcover, music_dir, - mpd_now.file, cover_size, default_art)) - current_icon = "/tmp/mpdcover.png" - else -- http stream - current_icon = default_art - end + local current icon = default_art - if followtag then - mpd_notification_preset.screen = focused() + if not string.match(mpd_now.file, "http.*://") then -- local file instead of http stream + local path = string.format("%s/%s", music_dir, string.match(mpd_now.file, ".*/")) + local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path, cover_pattern) + current_icon = helpers.read_pipe(cover):gsub("\n", "") end + if followtag then mpd_notification_preset.screen = focused() end + mpd.id = naughty.notify({ - preset = mpd_notification_preset, - icon = os.execute(string.format("ls %s &> /dev/null", current_icon)) - and current_icon, + preset = mpd_notification_preset, + icon = current_icon, + icon_size = cover_size, replaces_id = mpd.id, }).id end - elseif mpd_now.state ~= "pause" - then + elseif mpd_now.state ~= "pause" then helpers.set_map("current mpd track", nil) end end) diff --git a/wiki b/wiki index 9a9d036..b0e838a 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 9a9d036e50fce8ba3fcd89a8f384743b0147b306 +Subproject commit b0e838ade84ae851bceb2479bb16c1447057abb7