8000 GitHub - mjkalyan/dbar: A simple, cross-platform slider bar.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

mjkalyan/dbar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dbar

A simple, generic, cross-platform slider bar.

About

Simple utilities which are easily integrated into scripts or chained together with other utilities are a joy to use. Text-based shell utilities often work like this but, sadly, not many graphical programs share the same philosophy.

Enter dbar: it’s just a slider bar! It writes the selected value to stdout or plugs the value of the bar into a command supplied via --command / -c or --command-on-click / -C. It’s up to you, the user, to decide what you want to do with the output or what command to give dbar.

Installation

Gentoo

When dbar matures I’ll add it to the GURU repository. For now, enable my personal overlay, synchronize it, then emerge!

eselect repository add james-overlay git https://github.com/mjkalyan/james-overlay.git
emaint sync -r james-overlay
emerge app-misc/dbar

Cargo

Not yet uploaded to crates.io.

Instead you can download the source or clone the project and run cargo install.

Usage

When in doubt, run dbar -h for an overview of the available commands.

There are 3 main ways to use dbar:

  1. Dynamically run a shell command from dbar every time the dbar value changes
  2. Statically choose a single value to plug into another program
  3. Run a command like case 1 but every time you click instead of every time the value changes

My guess is most users will be looking for the first functionality as it provides smooth slider functionality, but there are some times you just want to pick a value once, avoid recomputing a command a bunch of times, or execute the same command with the same bar multiple times on demand.

Using dbar dynamically

The --command or -c option expects a string that will be entered into a shell after dbar replaces any occurrences of %v in the string with the current bar value. Concretely, dbar -c "echo %v" will print the current value of the bar (from 0 to 100 inclusively by default) whenever the mouse moves horizontally.

Examples

Set the screen brightness with xrandr

Use -f to for floating point values. Set the minimum value to 0.3 so we don’t accidentally make the screen pitch black and a maximum value of 1 avoid exceeding 100% brightness.

dbar -f -i 1 -c "xrandr --output <monitor> --brightness %v" 0.3 1

Note: you should use xbacklight instead if your hardware supports it (nearly all modern laptops should support xbacklight). xbacklight changes the actual hardware brightness whereas xrandr only changes gamma on a software level.

Set the Pulseaudio default device volume using pamixer:

-i allows setting the initial bar position to the current volume.

dbar -v -i 0.$(pamixer --get-volume) -t "Volume Control" -c "pamixer --set-volume %v"

Using dbar statically

dbar can be used statically by retrieving its output via pipe (dbar | foo), command expansion (foo $(dbar)), etc.

Examples

Assign a rating to each film in a file:

Given a file (films.txt) with a movie name on each line, we write a new file rating each of the movies from 1 to 6.

echo -e "shrek\nshrek 2\npuss in boots" > films.txt
while read line
    do
        echo "$line rating:" $(dbar 1 6 -v -t "Rate the movie: $line") "golden eggs" >> ratings.txt
    done < films.txt

Notice we use -t to set the window title such that we know what movie we are currently rating and -v to show the prospective value we will assign.

Execute a command every time you click

With --command-on-click / -C dbar will send a command (with the same format as --command) every time you click and will only exit when you press escape.

Examples

Seek to positions in the current song playing with mpd+mpc

mpc allows seeking by percentage with mpc seek <num>%, so we need only append a % to the default output (0 -100) of dbar.

We could use dbar statically with

mpc seek $(dbar)%

but what if we wanted to seek to different positions in the song? This solution requires reloading dbar over and over again each time we want to seek. Running dbar dynamically doesn’t work out that well either - we don’t want to send the seek command every time the bar updates because it’ll jumble our music and waste CPU resources.

This looks like a job for --command-on-click (-C):

dbar -C "mpc seek %v%" -t "MPC: Seek to a position in $(mpc current)"

This works exactly as we want, hooray! Also note we took advantage of being in a shell environment to put information about the currently running song into the dbar window title using $(mpc current).

One might prefer to keep dbar sitting around with --no-mouse-capture to have a song-seeking interface to mpd as long as dbar is kept open:

dbar -C "mpc seek %v%" --no-mouse-capture

Tips

Don’t forget -c

When choosing a shell/interpreter to run with dbar’s --command, make sure you invoke the right shell/interpreter flag to run a command. For example, if you wanted to run some python code directly, use python -c (for sh and bash it’s also -c).

e.g.

dbar -c 'python -c "print(\"hello from python\", %v * 123)"'

Also note the usage of escaped quotations. Nesting commands involving strings can get messy in bash. If that’s too troublesome, call dbar from another language.

Use Hotkeys!

When you come up with interesting uses for dbar, bind them to a hotkey with your window manager or a hotkey daemon like sxhkd. You’ll have a nicely integrated and multi-purpose slider bar in no time :)

Write scripts

Don’t be afraid to lift your dbar calls into their own files when they get complicated.

In the static examples above, we rated movies in a movie file, it’s sensible to put that into its own file (let’s say, dbar_example.sh) like so:

#! /usr/bin/bash

while read line
    do
        echo "$line rating:" $(dbar 1 6 -v -t "Rate the movie: $line") "golden eggs" >> $2
    done < $1

And then call it with whatever parameters we like (where $1 is the films file and $2 is the output ratings file):

dbar_example.sh more_films.txt ratings.txt

If all goes well, your imagination is the limit!

Use a higher refresh rate (lower -r setting) on high refresh rate displays if you notice dbar is too jagged

Dependencies

See cargo.toml

  • SDL2

Alternatives

If you like dbar, you may also like:

  • The --scale option for zenity This may be desireable if you never use dbar’s -c/-C and/or you already have zenity installed.

License

dbar is distributed under the GPL. See the COPYING file included with dbar for a copy of the license.

Author

M. James Kalyan - contact by email

About

A simple, cross-platform slider bar.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0