From 01f78b92c7004265642fbbb67f1ee85a4021c47a Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 2 Mar 2011 18:23:38 -0500 Subject: [PATCH 01/16] bindings: Kill the globalbinds Nop entries. I haven't used globalbinds in a long time. Add MPD bindings to the WM config. --- common/bindings | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/common/bindings b/common/bindings index d9a03fa..c3e474a 100644 --- a/common/bindings +++ b/common/bindings @@ -1,10 +1,13 @@ -# Globalbinds covers these. -Key Page_Down A CM Nop -Key Page_Up A CM Nop -Key End A CM Nop -Key Home A CM Nop -Key Insert A CM Nop -Key N A CM Nop +# MPD shortcuts +Key Page_Up A CM Exec exec mpc prev +Key Page_Down A CM Exec exec mpc next +Key End A CM Exec exec mpc stop +Key Home A CM Exec exec mpc pause +Key Insert A CM Exec exec mpc play +Key Page_Down A CM Exec exec mpc next + +Mouse 4 A CM Exec exec mpc prev +Mouse 5 A CM Exec exec mpc next # Window management Key F4 A M Close -- 2.43.2 From d012bc360e002eaf8e3bd58fa528439638332258 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 3 Mar 2011 11:35:45 -0500 Subject: [PATCH 02/16] bindings: Use scroll lock to lock the screen. This is as good a use for the key as any. --- common/bindings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/bindings b/common/bindings index c3e474a..f87c136 100644 --- a/common/bindings +++ b/common/bindings @@ -36,7 +36,7 @@ Key grave A CM Exec exec $[TERMINAL] -e zsh -f Key F3 A M Module FvwmConsole -terminal urxvt # Screen locking -Key XF86Standby A A Exec exec xscreensaver-command -lock +Key Scroll_Lock A A Exec exec xscreensaver-command -lock DestroyFunc DoPageMove AddToFunc DoPageMove -- 2.43.2 From 74a217f96316193daa602b8a5f4a81cc922a42af Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 26 Feb 2012 14:35:54 -0500 Subject: [PATCH 03/16] mpdmenu: Use a specialized script to send playid commands to MPD. This avoids the dependency on a patched mpc. --- scripts/mpdexec.pl | 40 ++++++++++++++++++++++++++++++++++++++++ scripts/mpdmenu.pl | 7 +++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100755 scripts/mpdexec.pl diff --git a/scripts/mpdexec.pl b/scripts/mpdexec.pl new file mode 100755 index 0000000..9c6e069 --- /dev/null +++ b/scripts/mpdexec.pl @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +# +# Copyright © 2012 Nick Bowler +# +# Simple program to send a command to MPD. The result is printed to standard +# output. +# +# License WTFPL2: Do What The Fuck You Want To Public License, version 2. +# This is free software: you are free to do what the fuck you want to. +# There is NO WARRANTY, to the extent permitted by law. + +use strict; + +use utf8; +use encoding 'utf8'; +use IO::Socket::INET6; + +my $host = $ENV{MPD_HOST} // "localhost"; +my $port = $ENV{MPD_PORT} // 6600; + +my $sock = new IO::Socket::INET6( + PeerAddr => $host, + PeerPort => $port, + Proto => 'tcp', +) or die "failed to connect to MPD: $!"; +binmode($sock, ":utf8"); + +if (!(<$sock> =~ /^OK MPD ([0-9]+)\.([0-9]+)\.([0-9]+)$/)) { + die "MPD failed to announce version: $!"; +} + +print $sock join(' ', @ARGV), "\n"; +while (<$sock>) { + last if (/^OK/); + print; + exit 1 if (/^ACK/); +} + +print $sock "close\n"; +close $sock; diff --git a/scripts/mpdmenu.pl b/scripts/mpdmenu.pl index 0da4c7f..ca7d2be 100755 --- a/scripts/mpdmenu.pl +++ b/scripts/mpdmenu.pl @@ -104,7 +104,8 @@ if (defined $album) { $t_title = sanitise($t_title, 0); my $cmd = sprintf "AddToMenu $menu \"%d\t%s - %s\"" - ." Exec mpc playid %d", + ." Exec exec $FVWM/scripts/mpdexec.pl" + ." playid %d", $t_trackno, $t_artist, $t_title, $t_id; cmd($cmd); @@ -248,7 +249,9 @@ if (defined $album) { $thumb =~ s/\n//sg; $thumb = "%$thumb%" if (-f $thumb); - cmd("AddToMenu $menu \"$thumb$t_artist - $t_title\" Exec mpc playid $t_id"); + cmd("AddToMenu $menu \"$thumb$t_artist - $t_title\"" + ." Exec exec $FVWM/scripts/mpdexec.pl" + ." playid $t_id"); } } # end use locale workaround } else { -- 2.43.2 From e6b5052ce732b83c89e8badbe78f3c59da8b613d Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 26 Feb 2012 14:39:52 -0500 Subject: [PATCH 04/16] mpdmenu: Replace all uses of mpc with mpdexec. May as well eliminate this dependency. --- scripts/mpdmenu.pl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/mpdmenu.pl b/scripts/mpdmenu.pl index ca7d2be..d477ca3 100755 --- a/scripts/mpdmenu.pl +++ b/scripts/mpdmenu.pl @@ -317,25 +317,25 @@ if (defined $album) { if ($state eq "play" || $state eq "pause") { cmd("AddToMenu $menu \"\t\tNext%$icons/next.svg:16x16%\" " - ."Exec exec mpc next"); + ."Exec exec $FVWM/scripts/mpdexec.pl next"); cmd("AddToMenu $menu \"\t\tPause%$icons/pause.svg:16x16%\" " - ."Exec exec mpc pause") if ($state eq "play"); + ."Exec exec $FVWM/scripts/mpdexec.pl pause"); cmd("AddToMenu $menu \"\t\tPlay%$icons/play.svg:16x16%\" " - ."Exec exec mpc play") if ($state eq "pause"); + ."Exec exec $FVWM/scripts/mpdexec.pl play"); cmd("AddToMenu $menu \"\t\tStop%$icons/stop.svg:16x16%\" " - ."Exec exec mpc stop"); + ."Exec exec $FVWM/scripts/mpdexec.pl stop"); cmd("AddToMenu $menu \"\t\tPrev%$icons/prev.svg:16x16%\" " - ."Exec exec mpc prev"); + ."Exec exec $FVWM/scripts/mpdexec.pl previous"); } elsif ($state eq "stop") { cmd("AddToMenu $menu \"\t\tPlay%$icons/play.svg:16x16%\" " - ."Exec exec mpc play"); + ."Exec exec $FVWM/scripts/mpdexec.pl play"); } else { die("Unknown MPD state!\n"); } cmd("AddToMenu $menu \"\" Nop"); cmd("AddToMenu $menu \"\t\tShuffle%$icons/shuffle.svg:16x16%\" " - ."Exec exec mpc shuffle"); + ."Exec exec $FVWM/scripts/mpdexec.pl shuffle"); cmd("DestroyMenu MenuMPDTitle"); cmd("AddToMenu MenuMPDTitle DynamicPopUpAction MakeMenuMPDTitle"); -- 2.43.2 From 54790622a95b55707635631c4f04e1cf3031bdac Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 20 Mar 2012 19:34:01 -0400 Subject: [PATCH 05/16] Don't lock the screen on a double scroll lock. A double scroll lock is used to communicate with my KVM. This should not have a side effect of locking the screen, so arrange for the screen to only lock if the scroll lock key is pressed once. Unfortunately, FVWM does not appear to have "single press" versus "double press" for key bindings (although it does for mouse bindings...), so we simulate it using a timer. --- common/bindings | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/common/bindings b/common/bindings index f87c136..afc2962 100644 --- a/common/bindings +++ b/common/bindings @@ -35,8 +35,20 @@ Key grave A C Exec exec $[TERMINAL] Key grave A CM Exec exec $[TERMINAL] -e zsh -f Key F3 A M Module FvwmConsole -terminal urxvt -# Screen locking -Key Scroll_Lock A A Exec exec xscreensaver-command -lock +# Screen locking. Since a double scroll lock is used to communicate with the +# KVM, take some care to only lock the screen if the scroll lock key is pressed +# once. +DestroyFunc FinishLock +AddToFunc FinishLock + + I Key Scroll_Lock A A LockScreen + + I $* + +DestroyFunc LockScreen +AddToFunc LockScreen + + I Schedule 750 FinishLock Exec exec xscreensaver-command -lock + + I Key Scroll_Lock A A FinishLock Deschedule $[schedule.last] + +Key Scroll_Lock A A LockScreen DestroyFunc DoPageMove AddToFunc DoPageMove -- 2.43.2 From c00c795114efcbb26c9466c62e856451932875d8 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 20 Mar 2012 21:41:09 -0400 Subject: [PATCH 06/16] Fix window positioning in Mega Fullscreen. --- global/fullscreen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global/fullscreen b/global/fullscreen index e651371..17aff18 100644 --- a/global/fullscreen +++ b/global/fullscreen @@ -35,7 +35,7 @@ DestroyFunc DoMegaFullScreen AddToFunc DoMegaFullScreen + I WindowStyle !Borders, !Title, !Iconifiable + I UpdateStyles -+ I Move 0 0 ++ I Move 0 0 ewmhiwa + I Layer 0 7 + I Exec exec xrandr -s $[cw.width]x$[cw.height] + I Windowstyle FPGrabFocus, FPLenient -- 2.43.2 From a88a55d3ba864830eb578e1a8f48ccc9f1a59114 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Fri, 9 Nov 2012 20:00:00 -0500 Subject: [PATCH 07/16] Set BusyCursor False in all contexts. New default in fvwm 2.6.4 is ugly. --- config | 1 + 1 file changed, 1 insertion(+) diff --git a/config b/config index e4d12f5..9c0b79d 100644 --- a/config +++ b/config @@ -49,6 +49,7 @@ CursorStyle Default left_ptr CursorStyle Title left_ptr CursorStyle Root left_ptr CursorStyle Menu left_ptr +BusyCursor * False # Global Styles and Options HideGeometryWindow Move -- 2.43.2 From 39ca59d182ecb5ac3957372ef683adcdec39c074 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 4 Oct 2011 10:21:59 -0400 Subject: [PATCH 08/16] scripts: Add copyright header to thumbnail.zsh. --- scripts/thumbnail.zsh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/thumbnail.zsh b/scripts/thumbnail.zsh index 9734575..de5e44f 100755 --- a/scripts/thumbnail.zsh +++ b/scripts/thumbnail.zsh @@ -1,4 +1,14 @@ #!/usr/bin/env zsh +# +# Copyright © 2008 Nick Bowler +# +# Simple thumbnail generator for use with FVWM. Thumbnails can be generated at +# any desired size, and are cached for future use. Prints the cached filename +# to standard output. +# +# License WTFPL2: Do What The Fuck You Want To Public License, version 2. +# This is free software: you are free to do what the fuck you want to. +# There is NO WARRANTY, to the extent permitted by law. if [[ -z "$MUSIC" ]]; then MUSIC=/home/music -- 2.43.2 From 122cafd7b21284e28496235a6df8b311bcb6930c Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 4 Oct 2011 10:26:23 -0400 Subject: [PATCH 09/16] bindings: Improve titlebar mouse bindings. Having a double-click action (the default behaviour) on left-click delays raising the window when clicking on the titlebar. Remove that action so that the raise is instantaneous. --- common/bindings | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/bindings b/common/bindings index afc2962..ff0d4e7 100644 --- a/common/bindings +++ b/common/bindings @@ -27,6 +27,15 @@ Key 6 A CM GotoPage 5 0 Mouse 5 R A GotoPage wrapx +1p 0p Mouse 4 R A GotoPage wrapx -1p 0p +# Window titlebar bindings +DestroyFunc Title_M1Func +AddToFunc Title_M1Func + + C Raise + + M Move + +Mouse 1 T N Title_M1Func +Mouse 2 T N Menu MenuWindow +Mouse 3 T N Lower Mouse 4 T N Windowshade True Mouse 5 T N Windowshade False -- 2.43.2 From 7caf3c5660e3a3a2da810bb36f8b5348dfc42e85 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 4 Oct 2011 10:27:31 -0400 Subject: [PATCH 10/16] xaspect: Relicense as WTFPL2. --- scripts/C/xaspect.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/C/xaspect.c b/scripts/C/xaspect.c index 3900c6d..16d151f 100644 --- a/scripts/C/xaspect.c +++ b/scripts/C/xaspect.c @@ -1,10 +1,11 @@ /* - * Copyright (C) 2007 Nick Bowler - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. This file is offered as-is, - * without any warranty. + * Copyright © 2007 Nick Bowler + * + * License WTFPL2: Do What The Fuck You Want To Public License, version 2. + * This is free software: you are free to do what the fuck you want to. + * There is NO WARRANTY, to the extent permitted by law. */ + #include #include #include -- 2.43.2 From 37e0a7cf0f51aac830678b88d4735f092a028c6f Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 3 Aug 2014 16:21:34 -0400 Subject: [PATCH 11/16] Update emergent root menu. --- emergent/rootmenu | 3 ++- icons/aurora.png | Bin 0 -> 1260 bytes 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 icons/aurora.png diff --git a/emergent/rootmenu b/emergent/rootmenu index daf5a31..4b99bc2 100644 --- a/emergent/rootmenu +++ b/emergent/rootmenu @@ -12,7 +12,7 @@ AddToFunc MakeMenuFvwmRoot + I DestroyMenu recreate MenuFvwmRoot + I PipeRead 'echo AddToMenu MenuFvwmRoot "$USER@`hostname`" Title' + I AddToMenu MenuFvwmRoot "Terminal%terminal.svg:16x16%" Exec exec $[TERMINAL] -+ I AddToMenu MenuFvwmRoot "IceCat%icecat.png%" Exec exec icecat ++ I AddToMenu MenuFvwmRoot "Pentadactyl%aurora.png%" Exec exec firefox + I PipeRead "xlsclients -a | grep ' gmpc$' >/dev/null || echo\ AddToMenu MenuFvwmRoot 'GMPC%gmpc.png%' Exec exec gmpc" + I AddToMenu MenuFvwmRoot "" Nop @@ -28,6 +28,7 @@ AddToFunc MakeMenuFvwmRoot DestroyMenu MenuNetwork AddToMenu MenuNetwork + "Pan Newsreader%pan.png%" Exec exec env LC_ALL=en_CA.UTF-8 pan ++ "VNC Viewer" Exec exec vncviewer DestroyMenu MenuMPD AddToMenu MenuMPD diff --git a/icons/aurora.png b/icons/aurora.png new file mode 100644 index 0000000000000000000000000000000000000000..60583c13ac831baa97b442afd7a79c764c2141c7 GIT binary patch literal 1260 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GXl4m}Uj|gt!8^3^_ZP6BcJwt?Zw% zXUmq;=T6;xaR0@-7q9;RKK1{V;Gd($B96r-9yMQ{p85BF-T#*@e~wu)$UBQF+W-Ie z>;L0e24Q`60hNF6mj8dx&LCy+<>8V4KPEAX8Ze6J{r>fvkze!qohOW3%2y9wW@M8+ zz5OgBi^SclkC<5{D?;1<|Nqa%CEr@Ulv_wOBD9y$CXGj2OF&djQ`1|=KA$;b1B03a z1HTjt2OqbfypV*Jq`aA!oP~gtF}siolYSs$$|?q4Q3hrfkT2kXiHU)Yhfz#}$t)%= zX~v`}8x9^kar@?t=T9HMymiJ_-!0KGxF@q_eO>GEnceqx&wF=m(~l?H|9?HDDX)|4 zA5`e+H68ER;Fn;ChlDupVmC8(+t8*7yrDwi23ml~>P zsB6Tk*syWQD#*zjDQW2O%i0LbdPvB}>8KVsnr2(+g{vre$?E#*#|nrlD9foU@yqE5 z%9#qwTZu}BnwVNk$XiHhS!no3NvJDJs%uDU=tyho$?54RnTyLBZRNhL4~$cl(8-<*{{EL_W*vz=>4io=RQ@5PZYX58%)AQFEeZ3}kN-qEV zXNd}%Vaxds|2|ykvEybE)O8OD^D-7=={$Nh5oj7?lDE5yR`9+n^MD-A0*}aIAngIh zZYQ(tfC~6LT^vIsE+;22Fs6xxnU(SR>E#*pH@06tef#+J^Yi=T9R!Yu3-NLAaPe{S za`y`evVJ;xM0xR|zfTAHcKP5A*61N7iG>aaf21$?& t!TD(=<%vb942~)JNvR5+xryniL8*x;m4zo$ZGegxJYD@<);T3K0RYI9+FJks literal 0 HcmV?d00001 -- 2.43.2 From eb9fcc54a7417c5e8b3a06409f558d2c3da05fef Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 18 Dec 2013 22:49:33 -0500 Subject: [PATCH 12/16] Switch XChat to HexChat in artemis root menu. --- artemis/rootmenu | 4 +- icons/hexchat.svg | 547 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 549 insertions(+), 2 deletions(-) create mode 100644 icons/hexchat.svg diff --git a/artemis/rootmenu b/artemis/rootmenu index 4b9a73c..919d73e 100644 --- a/artemis/rootmenu +++ b/artemis/rootmenu @@ -13,8 +13,8 @@ AddToFunc MakeMenuFvwmRoot + I PipeRead 'echo AddToMenu MenuFvwmRoot "$USER@`hostname`" Title' + I AddToMenu MenuFvwmRoot "Terminal%terminal.svg:16x16%" Exec exec $[TERMINAL] + I AddToMenu MenuFvwmRoot "IceCat%icecat.png%" Exec exec icecat -+ I PipeRead "xlsclients -a | grep ' xchat$' >/dev/null || echo\ - AddToMenu MenuFvwmRoot 'Xchat%xchat.png%' Exec exec xchat" ++ I PipeRead "xlsclients -a | grep ' hexchat$' >/dev/null || echo\ + AddToMenu MenuFvwmRoot 'HexChat%hexchat.svg:16x16%' Exec exec hexchat" + I PipeRead "xlsclients -a | grep ' gmpc$' >/dev/null || echo\ AddToMenu MenuFvwmRoot 'GMPC%gmpc.png%' Exec exec gmpc" + I AddToMenu MenuFvwmRoot "" Nop diff --git a/icons/hexchat.svg b/icons/hexchat.svg new file mode 100644 index 0000000..148fb4e --- /dev/null +++ b/icons/hexchat.svg @@ -0,0 +1,547 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Guglielmi David + + + + + + Peter Zelezny + + + + + + + + + + + + + + + + + + + + + -- 2.43.2 From 61db326451517da54d7bf4ec3216effd5a774900 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 18 Dec 2013 22:51:12 -0500 Subject: [PATCH 13/16] Switch XChat to HexChat in amythaon root menu. --- amythaon/rootmenu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/amythaon/rootmenu b/amythaon/rootmenu index 1fcf820..643dff5 100644 --- a/amythaon/rootmenu +++ b/amythaon/rootmenu @@ -13,8 +13,8 @@ AddToFunc MakeMenuFvwmRoot + I PipeRead 'echo AddToMenu MenuFvwmRoot "$USER@`hostname`" Title' + I AddToMenu MenuFvwmRoot "Terminal%terminal.svg:16x16%" Exec exec $[TERMINAL] + I AddToMenu MenuFvwmRoot "IceCat%icecat.png%" Exec exec icecat -+ I PipeRead "xlsclients -a | grep ' xchat$' >/dev/null || echo\ - AddToMenu MenuFvwmRoot 'Xchat%xchat.png%' Exec exec xchat" ++ I PipeRead "xlsclients -a | grep ' hexchat$' >/dev/null || echo\ + AddToMenu MenuFvwmRoot 'HexChat%hexchat.svg:16x16%' Exec exec hexchat" + I PipeRead "xlsclients -a | grep ' gmpc$' >/dev/null || echo\ AddToMenu MenuFvwmRoot 'GMPC%gmpc.png%' Exec exec gmpc" + I AddToMenu MenuFvwmRoot "" Nop -- 2.43.2 From cb413f94ce2cd07780082b28613856651082a925 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 8 Apr 2015 23:00:10 -0400 Subject: [PATCH 14/16] Fix resize.sh to work in dash. "echo -n" is not portable to dash, so this script breaks horribly. Avoid that, but also just rewrite the script because those shell tests are awful and we can do better with grid coordinates. --- scripts/resize.sh | 65 ++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/scripts/resize.sh b/scripts/resize.sh index a375ddd..65d646c 100755 --- a/scripts/resize.sh +++ b/scripts/resize.sh @@ -1,36 +1,49 @@ #!/bin/sh -# resize.sh mouseX mouseY windowW windowH +# +# Copyright © 2008, 2015 Nick Bowler +# # Emits an FVWM directed resize command based on the position of the mouse # cursor within a window (mouseX, mouseY) and the width and height of the # window (windowW, windowH). +# +# License WTFPL2: Do What The Fuck You Want To Public License, version 2. +# This is free software: you are free to do what the fuck you want to. +# There is NO WARRANTY, to the extent permitted by law. if [ $# -lt 4 ]; then - echo "usage: $0 mouseX mouseY windowW windowH" + printf 'usage: %s mouseX mouseY windowW windowH\n' "$0" 1>&2 exit 1 fi -echo -n "Resize Direction " +# The window's area is divided into a 4x4 grid of equally sized rectangles. +# We return a resize direction depending on which rectangle was clicked, +# according to the following diagram: +# +# ┏━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━┓ +# ┃ NorthWest │ North │ NorthEast ┃ +# ┠───────────┼───────────┬───────────┼───────────┨ +# ┃ │ NorthWest │ NorthEast │ ┃ +# ┃ West ├───────────┼───────────┤ East ┃ +# ┃ │ SouthWest │ SouthEast │ ┃ +# ┠───────────┼───────────┴───────────┼───────────┨ +# ┃ SouthWest │ South │ SouthEast ┃ +# ┗━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━┛ -# Straight directions -if [ $1 -le $(($3/4)) -a $2 -ge $(($4/3)) -a $2 -le $(($4/3*2)) ]; then - echo "West" -elif [ $1 -ge $(($3/4*3)) -a $2 -ge $(($4/3)) -a $2 -le $(($4/3*2)) ]; then - echo "East" -elif [ $2 -le $(($4/4)) -a $1 -ge $(($3/3)) -a $1 -le $(($3/3*2)) ]; then - echo "North" -elif [ $2 -ge $(($4/4*3)) -a $1 -ge $(($3/3)) -a $1 -le $(($3/3*2)) ]; then - echo "South" -# Quadrants -elif [ $1 -le $(($3/2)) ]; then - if [ $2 -le $(($4/2)) ]; then - echo "NorthWest" - else - echo "SouthWest" - fi -else - if [ $2 -le $(($4/2)) ]; then - echo "NorthEast" - else - echo "SouthEast" - fi -fi +rect_w=$(($3/4)) +rect_h=$(($4/4)) +grid_x=$(($1/$rect_w)) +grid_y=$(($2/$rect_h)) + +case $grid_x$grid_y in +11|00) dir=NorthWest ;; +21|30) dir=NorthEast ;; +12|03) dir=SouthWest ;; +22|33) dir=SouthEast ;; +?0) dir=North ;; +0?) dir=West ;; +3?) dir=East ;; +?3) dir=South ;; +*) exit 1 ;; +esac + +printf 'Resize Direction %s\n' "$dir" -- 2.43.2 From 01c0c7e8df66f488f498bf088a5850def432f41c Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 19 Oct 2017 21:39:17 -0400 Subject: [PATCH 15/16] thumbnailer: Follow only one level of symbolic link. Since my music is all in git annex now, the thumbnailer follows the cover art symlinks all the way to the annex object directory. This is less than helpful, since the intention was to locate the album scan directory. Change the --image mode to just read the link once and then stop. --- scripts/thumbnail.zsh | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/thumbnail.zsh b/scripts/thumbnail.zsh index de5e44f..a275749 100755 --- a/scripts/thumbnail.zsh +++ b/scripts/thumbnail.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # -# Copyright © 2008 Nick Bowler +# Copyright © 2008, 2017 Nick Bowler # # Simple thumbnail generator for use with FVWM. Thumbnails can be generated at # any desired size, and are cached for future use. Prints the cached filename @@ -10,6 +10,22 @@ # This is free software: you are free to do what the fuck you want to. # There is NO WARRANTY, to the extent permitted by law. +# resolve_file [file] +# +# If the argument is a symbolic link, print the target of that link. +# Otherwise, prints the basename of file. +resolve_file () { + test $# -eq 1 || return + + # Ensure filename won't be confused for any kind of find argument... + case $1 in + /*) :;; + *) set x "./$1"; shift + esac + + find "$1" -prune \( -type l -printf '%l' -o -printf '%f' \) +} + if [[ -z "$MUSIC" ]]; then MUSIC=/home/music fi @@ -60,8 +76,11 @@ else fi [[ ! -f "$imgpath" ]] && exit 0 - -image="$(readlink -f -- "$imgpath")" +image=`resolve_file "$imgpath"` +case $image in +/*) :;; +*) image=`dirname $imgpath`/$image +esac [[ ! -f "$image" ]] && exit 0 thumb="$thumbs/$(echo -n $image | md5sum - | cut -d ' ' -f 1)_$size.png" -- 2.43.2 From 6ea5fd2e47b06873f28160fc414f4ef90c82f2fe Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Fri, 7 Apr 2017 21:29:30 -0400 Subject: [PATCH 16/16] Improve wallpaper menu generation. Update the wallpaper menu script to be more portable and hopefully faster, and enhance the xaspect tool to work on rotated displays. --- common/wallpaper | 2 +- scripts/C/xaspect.c | 50 ++++++++++++++++++++++++++------------------- scripts/bgmenu.sh | 47 ++++++++++++++++++++++++++++++++++++++++++ scripts/bgmenu.zsh | 20 ------------------ 4 files changed, 77 insertions(+), 42 deletions(-) create mode 100755 scripts/bgmenu.sh delete mode 100755 scripts/bgmenu.zsh diff --git a/common/wallpaper b/common/wallpaper index 07e40cd..1bc5002 100644 --- a/common/wallpaper +++ b/common/wallpaper @@ -15,7 +15,7 @@ DestroyFunc MakeMenuWallpaper AddToFunc MakeMenuWallpaper + I DestroyMenu recreate MenuWallpaper + I AddToMenu MenuWallpaper Wallpaper Title - + I PipeRead 'exec $[FVWM_USERDIR]/scripts/bgmenu.zsh $[BGROOT] MenuWallpaper' + + I PipeRead 'exec $[FVWM_USERDIR]/scripts/bgmenu.sh --menu=MenuWallpaper $[BGROOT]' DestroyFunc SetWallpaper AddToFunc SetWallpaper diff --git a/scripts/C/xaspect.c b/scripts/C/xaspect.c index 16d151f..0009424 100644 --- a/scripts/C/xaspect.c +++ b/scripts/C/xaspect.c @@ -1,5 +1,5 @@ /* - * Copyright © 2007 Nick Bowler + * Copyright © 2008, 2017 Nick Bowler * * License WTFPL2: Do What The Fuck You Want To Public License, version 2. * This is free software: you are free to do what the fuck you want to. @@ -13,18 +13,15 @@ #include #include -#define MKASPECT(w, h) { (double)w/h, #w ":" #h } - /* Table of common monitor aspect ratios. Add to this as necessary. */ -static struct aspect { - double ratio; - char *name; +static const struct aspect { + unsigned num, denom; } aspects[] = { - MKASPECT(16, 10), - MKASPECT(16, 9), - MKASPECT(8, 3), - MKASPECT(5, 4), - MKASPECT(4, 3) + { 16, 10 }, + { 16, 9 }, + { 8, 3 }, + { 5, 4 }, + { 4, 3 } }; /* @@ -46,24 +43,32 @@ static xcb_screen_t *getscreen(xcb_connection_t *c, int screen) return NULL; } -char *testaspect(xcb_screen_t *screen) +void find_nearest_aspect(xcb_screen_t *screen, struct aspect *out) { unsigned int w = screen->width_in_millimeters; unsigned int h = screen->height_in_millimeters; - double ratio = (double)w/h; - double diff = 0; - char *best = NULL; + double r = (double)w/h; + double d = HUGE_VAL; int i; for (i = 0; i < (sizeof aspects / sizeof aspects[0]); i++) { - if (!best || fabs(aspects[i].ratio - ratio) < diff) { - best = aspects[i].name; - diff = fabs(aspects[i].ratio - ratio); + double t = (double) aspects[i].num / aspects[i].denom; + double cmp; + + cmp = fabs(r - t); + if (cmp < d) { + *out = aspects[i]; + d = cmp; } - } - return best; + cmp = fabs(r - 1/t); + if (cmp < d) { + out->num = aspects[i].denom; + out->denom = aspects[i].num; + d = cmp; + } + } } struct options { @@ -91,6 +96,7 @@ struct options { int main(int argc, char **argv) { + struct aspect screenaspect; xcb_connection_t *display; xcb_screen_t *screen; int screen_num; @@ -115,7 +121,9 @@ int main(int argc, char **argv) printf("%" PRIu16 "x%" PRIu16 "-", screen->width_in_pixels, screen->height_in_pixels); } - printf("%s\n", testaspect(screen)); + + find_nearest_aspect(screen, &screenaspect); + printf("%u:%u\n", screenaspect.num, screenaspect.denom); xcb_disconnect(display); return EXIT_SUCCESS; diff --git a/scripts/bgmenu.sh b/scripts/bgmenu.sh new file mode 100755 index 0000000..98a2a1d --- /dev/null +++ b/scripts/bgmenu.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# +# Copyright © 2008, 2017 Nick Bowler +# +# Generates an FVWM menu for selecting the PNG images found in a given +# directory. Thumbnails for the images are generated on the fly using +# the thumbnailer.zsh script. Menu items run the specified function +# with the filename as the first argument. + +thumber="$FVWM_USERDIR/scripts/thumbnail.zsh --size x160" +xaspect=$FVWM_USERDIR/scripts/C/xaspect +menu=MenuWallpaper +func=SetWallpaper + +lastarg= +dashdash= +for arg; do + if test ${lastarg:+y}; then + arg=$lastarg=$arg + lastarg= + fi + + case $dashdash$arg in + --menu=*) menu=${arg#--menu=} ;; + --func=*) func=${arg#--func=} ;; + --menu|--func) lastarg=$arg ;; + --) dashdash=: ;; + -*) printf '%s: unrecognized argument: %s\n' "$0" "$arg" 1>&2; exit 1 ;; + *) set x "$@" "$arg"; shift + esac + + shift +done + +case $# in +1) dir=$1 ;; +*) printf 'usage: %s [options] directory\n' "$0" 1>&2 +esac + +size=`$xaspect -dimensions` +find $1 -maxdepth 1 -name "*$size.png" -print0 -exec $thumber {} \; | + awk -F '\0' '{ + gsub(/["\\]/, "\\\\&"); + caption = gensub(/.*\/(.*)\..*/, "\\1", 1, $1); + print "AddToMenu", menuname, "\"" caption "*" $2 "*\"", + funcname, "\"" $1 "\"" + }' "menuname=$menu" "funcname=$func" diff --git a/scripts/bgmenu.zsh b/scripts/bgmenu.zsh deleted file mode 100755 index 15bbd2a..0000000 --- a/scripts/bgmenu.zsh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env zsh -# Generates an FVWM menu for selecting the PNG images found in a given -# directory. Thumbnails for the images are generated on the fly using convert -# from ImageMagick, and stored in the .thumbs subdirectory. The menu items -# run the specified function with the filename as the first argument. - -menu="MenuWallpaper" -func="SetWallpaper" -thumber="$FVWM_USERDIR/scripts/thumbnail.zsh" - -if [ ! -d "$1" ]; then - echo "usage: $0 [menuname]" 1>&2 - exit 1 -fi -[ -n "$2" ] && menu="$2" - -for i in "$1"/*$($FVWM_USERDIR/scripts/C/xaspect).png; do - thumb="`$thumber --size x160 "$i"`" - echo "AddToMenu $menu \"`basename "${i%.png}"`*$thumb*\" $func \"$i\"" -done -- 2.43.2