You are not logged in.

#1 2018-09-30 06:27:49

ohnonot
...again
Registered: 2015-09-29
Posts: 3,194
Website

Handy config stuff or scripts (GUI version)

I originally wanted to post here, but realised that my handy snippet is Xorg (or GUI in general - let's see some wayland stuff) dependent.

So, just like its inspiration, this thread is meant for short snippets of code or configuration that might be useful in a GUI. Please post your interesting discoveries or all-time favourites!

(Longer scripts that might trigger a discussion would be better off in their own thread.)
______________________________________

Last edited by ohnonot (2018-09-30 06:28:34)

Offline

#2 2018-09-30 06:43:53

ohnonot
...again
Registered: 2015-09-29
Posts: 3,194
Website

Re: Handy config stuff or scripts (GUI version)

My first is a recommendation & some configuration:
Use old X-apps and pimp them for the third millenium!
E.g. xvkbd as a virtual keyboard!
It's available, it's ultra-lightweight, it does what it should.

Why?
I sometimes watch video with mpv from a distance.
I have a wireless mouse, but not a wireless keyboard.
this helps me to control mpv.
Nice large buttons & labels, and no F keys or keypad required.

Make it a little more suitable for larger (i.e. anything beyond VGA) screens by adding this to your Xresources:

! These settings are hardcoded in xvkbd.c as fallback resouces, too,
! and this file is not required in general.
! This is intended to be included in another app-defaults files
! (XVkbd-german, for example), as:
!
!     #include "XVkbd-common"
!
! because fallback resouces may be ignored when such app-defaults file
! (application class resource file) is loaded.

! USE A DIFFERENT BITMAP FOR THE FOCUS BUTTON
!xvkbd*Focus.internalWidth: 16
!xvkbd*Focus.bitmap: /usr/include/X11/bitmaps/target

xvkbd.functionkey: false
xvkbd.keypad: false

! ADDS A SMALL ARROW TO BOTTOM LEFT
xvkbd.minimizable: true

! NO REMOTE ACCESS?
xvkbd.secure: true

! DISABLES PANEL ICON
xvkbd*wmToolbar: true

! BUT NOT ON TOP OF MPV FULLSCREEN
xvkbd*alwaysOnTop: true

! AUTO REPEAT AND DELAY
XVkbd*Repeater.initialDelay: 300
XVkbd*Repeater.minimumDelay: 30
XVkbd*Repeater.decay: 500

XVkbd*Font: -*-uniread v-medium-r-*-*-12-*-*-*-*-*-*-*
XVkbd*generalFont: -*-uniread v-bold-r-*-*-12-*-*-*-*-*-*-*
XVkbd*letterFont: -*-uniread v-bold-r-*-*-18-*-*-*-*-*-*-*
XVkbd*specialFont: -*-uniread v-bold-r-*-*-12-*-*-*-*-*-*-*
XVkbd*keypadFont: -*-uniread v-bold-r-*-*-12-*-*-*-*-*-*-*
XVkbd*banner.font: -*-uniread v-bold-r-*-*-12-*-*-*-*-*-*-*
XVkbd*display_panel*label.font: -*-uniread v-bold-r-*-*-12-*-*-*-*-*-*-*

! COLORS - LIGHT, GRAYISH
!XVkbd*Background: gray50
!XVkbd*generalBackground: gray70
!XVkbd*title*Background: white
!XVkbd*Text*background: white
!XVkbd*specialBackground: gray60
!XVkbd*focusBackground: #ff9876
!XVkbd*remoteFocusBackground: lightcyan1
!XVkbd*Foreground: black
!XVkbd*highlightBackground: gray80
!XVkbd*highlightForeground: forestgreen

! COLORS - DARK WITH GREEN GLOW
XVkbd*Background: gray5
XVkbd*generalBackground: gray10
XVkbd*title*Background: gray15
XVkbd*Text*background: gray15
XVkbd*specialBackground: gray15
XVkbd*focusBackground: #551111
XVkbd*remoteFocusBackground: lightcyan1
XVkbd*Foreground: green
XVkbd*highlightBackground: gray25
XVkbd*highlightForeground: forestgreen

! VARIOUS UI DESIGN
XVkbd*topShadowContrast: 20
XVkbd*bottomShadowContrast: 50
XVkbd*shadowWidth: 2
XVkbd*Label.shadowWidth: 0
XVkbd*MainMenu.shadowWidth: 0
XVkbd*MainMenu.topShadowContrast: 0
XVkbd*MainMenu.bottomShadowContrast: 0
XVkbd*highlightThickness: 1
XVkbd*Form.resizable: true
XVkbd*defaultDistance: 0
XVkbd*Form.borderWidth: 0
XVkbd*Label.borderWidth: 0
XVkbd*Command.internalWidth: 2
XVkbd*Repeater.internalWidth: 2
XVkbd*Command.resize: false
XVkbd*Repeater.resize: false
XVkbd*Command.justify: center
XVkbd*Repeater.justify: center

XVkbd*row1.vertDistance: 0
XVkbd*F5.horizDistance: 0
XVkbd*F9.horizDistance: 0
XVkbd*BackSpace.horizDistance: 0

! SIZES OF KEYS ETC.
XVkbd*Command.height: 50
XVkbd*Repeater.height: 50
XVkbd*row0.Repeater.height: 50
XVkbd*Command.width: 50
XVkbd*Repeater.width: 50
XVkbd*space.width: 180
XVkbd*Tab.width: 65
XVkbd*Control_L.width: 70
XVkbd*Shift_L.width: 75
XVkbd*Shift_R.width: 65
XVkbd*Multi_key.width: 50
XVkbd*Caps_Lock.width: 50
XVkbd*Alt_L.width: 50
XVkbd*Alt_R.width: 50
XVkbd*Meta_L.width: 50
XVkbd*Meta_R.width: 50
XVkbd*BackSpace.width: 90
XVkbd*Delete.width: 50
XVkbd*Return.width: 70
XVkbd*row5.Focus.width: 50
xvkbd*Mode_switch.width: 50

XVkbd*keypad.vertDistance: 0
XVkbd*keypad.horizDistance: 10
XVkbd*keypad*Command.width: 50
XVkbd*keypad*Repeater.width: 50
XVkbd*keypad*Command.justify: left
XVkbd*keypad*Repeater.justify: left
XVkbd*keypad*pad3,3.height: 100
XVkbd*keypad*pad4,0.width: 101

! TOOLTIP
XVkbd.balloonBackground: grey10
XVkbd.launchBalloonBackground: Cyan
XVkbd*balloon_panel.Label.width: 100
XVkbd*balloon_panel.Label.resize: true
XVkbd*balloon_panel.Label.justify: center

! BANNER (TOP RIGHT)
XVkbd*banner.height: 50
XVkbd*banner.width: 210
XVkbd*banner.justify: right

! MENU BUTTON (BOTTOM LEFT)
XVkbd*MainMenu.width: 50
XVkbd*MainMenu.height: 50
XVkbd*MainMenu.label: xvkbd
XVkbd*MainMenu.justify: center
XVkbd*MainMenu.internalWidth: 2
XVkbd*MainMenu.highlightThickness: 1

! MENU
XVkbd*menu*shadowWidth: 0

XVkbd*menu.about.label: About...
XVkbd*menu.man.label: Manual...
XVkbd*menu.keypad.label: Keypad...
XVkbd*menu.sun_fkey.label: Sun Function Keys...
XVkbd*menu.deadkey.label: Dead Keys...
XVkbd*menu.completion.label: Word Completion...
XVkbd*menu.select_layout.label: Change Keyboard Layout...
XVkbd*menu.edit_fkey.label: Edit Function Keys...
XVkbd*menu.show_keypad.label: Show Keypad
XVkbd*menu.show_functionkey.label: Show Function Keys
XVkbd*menu.props.label: Property...
XVkbd*menu.open_display.label: Connect to Remote Display...
XVkbd*menu.close_display.label: Revert to Local Display
XVkbd*menu.quit.label: Quit
XVkbd*menu.SmeBSB.rightMargin: 30

caveat:
if you choose a different language keyboard layout from the menu you lose some of the customisations.

Uniread V is part of the excellent Linux Font Project. get the lfpfonts package from here.

I have added a miniscript 'xvkbd-toggle' to my ~/bin and to my openbox menu:

#!/bin/sh
pidof xvkbd && killall xvkbd || xvkbd &
exit

dark version:
http://dt.iki.fi/stuff/forums/xvkbd.png
btw, the "xvkbd" logo on the bottom left opens the menu.

Last edited by ohnonot (2018-09-30 07:54:43)

Offline

#3 2018-09-30 06:58:20

ohnonot
...again
Registered: 2015-09-29
Posts: 3,194
Website

Re: Handy config stuff or scripts (GUI version)

Quick Urbandictionary Lookup

somebody invoked Rule 34A on reddit. everybody else seems to understand, but you don't.
obviously you won't find this on wikipedia.
with my script (best bind it to a hotkey in rc.xml) you can highlight the term in question, execute the script, and get results in color and nicely formatted.

the script uses xclip by default to get the selection, and opens the results in a suitably sized terminal (*), but it recognizes if you give a search term on the command line or if it's run from a terminal interactively, and will behave accordingly.

(*) i use the custom environment variable $XTERMINAL to define my default terminal. if this is undefined, the script defaults to xterm.

#!/bin/bash

# if you want to:
#~ XTERMINAL=something_else

# how many results do you want max.
max=3

if [ -t 0 ]; then 
	width="$(tput cols)"
else
	# define width here
	width=60
fi

# which character the header line consists of
headchar=":"

function header { # outputs a header with string $1 in the middle
	x=$width
	half=$(( ( $x - ${#1} ) / 2 ))
	x=$(( $x - ( $half + $half + ${#1} ) ))  
	putline $half "$headchar"
	echo -n "$1"
	putline $half "$headchar"
	echo
}
function putline { # outputs a line $1 long, consisting of $2 characters
    for (( p=1; p<=$1; p++ )); do
       echo -n "$2"
    done
}

# xclip or command line $1?
[[ "$@" == "" ]] && term="$(xclip -o)" || term="$@"
[[ "$term" == "" ]] && echo "no input :(" && exit 1

# terms with spaces etc: systutorials.com/241492/how-to-encode-spaces-in-curl-get-request-url-on-linux
stuff="$(curl -sG --data-urlencode "term=$term" "https://api.urbandictionary.com/v0/define")"

string=""
fullstring=""
for (( i=0 ; i<$max ; i++ )); do
	# build a header out of number & word, if available
	word="$(echo "$stuff" | jshon -e list -e $i -e word -u)"
	[[ "$word" == "" ]] && break
	string="$(echo "$stuff" | jshon -e list -e $i -e definition -u | fold -s -w $width)\n\nExample:\n\n$(echo "$stuff" | jshon -e list -e $i -e example -u | fold -s -w $width)"
	# if there's an actual definition, print it out
	# if there's an example, print it out
	# remove square and curly brackets from definition & example
	string="${string//[/}"
	string="${string//]/}"
	string="${string//\{/}"
	string="${string//\}/}"
	# add color & header to front of string, and add it to fullstring
	color="$((i+1))"
	(( color > 7 )) && color="$((i-6))"
	string="\e[0;3${color}m$(header " $((i+1)): $word ")\n\n$string"
	(( i > 0 )) && fullstring="$fullstring\n\n$string" || fullstring="$fullstring$string"
done
[[ "X$fullstring" == "X" ]] && fullstring="Nothing found for \"$term\" :("

title="\"$term\" on urbandictionary.com"

if [ -t 0 ]; then
	echo -e "$title\n\n$fullstring"
else
	# If stdin is not a tty, start it in a terminal - unix.stackexchange.com/a/26691
	height="$(echo -e "$fullstring"|wc -l)"
	((height++))
	# don't let it get too tall
	(( height > 60 )) && height=60
	${XTERMINAL-xterm} -T "$title" -geometry ${width}x${height} -e bash -c 'tput civis; echo -en "$@"; read' ud "$fullstring"
fi

screenshot:
http://dt.iki.fi/stuff/forums/ud.png

PS: except for xclip, this isn't even gui dependent.

Last edited by ohnonot (2018-09-30 07:56:25)

Offline

Board footer

Powered by FluxBB