SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2015-06-02 16:33:42

easysid
#! CrunchBanger
From: India
Registered: 2013-01-25
Posts: 150

HowTo: Toggleable conky using lemonbar (or dzen2)

HowTo: Toggleable conky using lemonbar (or dzen2)

If you are using a tiling window manager, and using a bar like lemonbar or dzen2 to pipe your system info, you can use the clickable area feature of these bars to create conkys that can be toggled between a compact form with minimal info and an expanded form with more info.
For example in This setup, the conky can be toggled by clicking on the '+/-' sign.
iqNpkJW.png
cVPylyx.png

Here is a gif


The idea is nothing new. It is similar to interactive conky. Store the toggle state information in a file and use that information to format the conky display. We can use ${if_existing} object to determine the toggle state.

read toggle state
if toggle state is 1
     display long info
else
     display short info
endif
this info is always displayed

So, we need 3 things for this to work (as of now. Maybe someone can point out how to acieve this more efficiently)

  1. A bar supporting clickable areas (lemonbar in this example)

  2. The conky itself

  3. a file to store the toggle state

  4. *[Optional] A script to toggle the state. We can always code it inline, but a separate script keeps things cleaner.



Create a file to store toggle state.

$ echo 1 > /tmp/conkytoggle

Now we can write a conky that reads this file and displays the info accordingly.
(The %{A} are for lemonbar click areas)
toggle_conkyrc

# toggle conky for lemonbar

# conky settings

background no
update_interval 1
cpu_avg_samples 1
total_run_times 0
override_utf8_locale yes
short_units yes
pad_percents 2
uppercase no
out_to_console yes
out_to_x no


TEXT
%{r}\
${if_existing /tmp/conkytoggle 1}%{A:toggleconky.sh:} - %{A}\
# long part
cpu ${cpu cpu0}%% ram ${mem} | \
cpu ${hwmon 1 temp 2}° ati ${hwmon 2 temp 1}° | \
net ${if_existing /proc/net/route wlan0}${wireless_essid wlan0}${else}-*- ${endif} | \
bat ${battery BAT0}% \
${else} %{A:toggleconky.sh:} + %{A}\
# shorter part 
${if_existing /proc/net/route wlan0}${wireless_essid wlan0}${endif} | \
${battery_short BAT0}% \
${endif}\
# This part is always visible
| ${time %a, %d %b} ${time %H:%M} \

toggleconky.sh is trivial. Used to change state in the file.

#! /bin/bash

# Make sure the following file exists.
FILE='/tmp/conkytoggle'

[[ $(< $FILE) -eq 0 ]] && echo -n 1 > $FILE || echo -n 0 > $FILE

Now pipe this info to lemonbar, and you are done.

$ conky -c toggle_conkyrc | lemonbar -p -g "1300x14+50+30" -B "#262626" -F "#a0a0a0" \
                   -f "-lucy-tewi-medium-r-normal--11-90-75-75-p-58-iso10646-1" \
                | while read line; do eval "$line"; done 

If you are using dzen2 instead of lemonbar, just modify the conky according to dzen2's syntax
toggle_conkyrc (for dzen2)

# toggle conky for dzen2

# conky settings

background no
update_interval 1
cpu_avg_samples 1
total_run_times 0
override_utf8_locale yes
short_units yes
pad_percents 2
uppercase no
out_to_console yes
out_to_x no


TEXT
${if_existing /tmp/conkytoggle 1}^ca(1, toggleconky.sh) - ^ca()\
# long part
cpu ${cpu cpu0}% ram ${mem} | \
cpu ${hwmon 1 temp 2}° ati ${hwmon 2 temp 1}° | \
net ${if_existing /proc/net/route wlan0}${wireless_essid wlan0}${else}-*- ${endif} | \
bat ${battery BAT0} \
${else} ^ca(1, toggleconky.sh) - ^ca()\
# shorter part 
${if_existing /proc/net/route wlan0}${wireless_essid wlan0}${endif} | \
${battery_short BAT0} \
${endif}\
# This part is always visible
| ${time %a, %d %b} ${time %H:%M} \

Pipe it to dezen2 and done

$ conky -c toggle_conkyrc | dzen2 [options]

Here is how these look.

n0V1SgB.png
rkh7NBo.png

This conky is quite barebones. Add decorations, colors, and all that jazz according to taste.

Thanks for reading. Hope it helps.  smile  smile


Edit-3: Changed a bit of code
Edit-2: Added gif
Edit-1: Added conkyrc example for dzen2

Last edited by easysid (2015-06-04 08:57:35)

Offline

Help fund CrunchBang, donate to the project!

#2 2015-06-02 18:44:01

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: HowTo: Toggleable conky using lemonbar (or dzen2)

easysid wrote:
HowTo: Toggleable conky using lemonbar (or dzen2)

Now that really cool.  Thank you!


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#3 2015-06-02 18:46:22

Head_on_a_Stick
CatMod
From: A world of pure imagination
Registered: 2014-01-21
Posts: 4,797

Re: HowTo: Toggleable conky using lemonbar (or dzen2)

@easysid -- thank you very much for this, very useful!
smile

EDIT: I think you should request that the mods move this to it's own thread in the "Tutorials" section, it may get "lost" in this one wink

Last edited by Head_on_a_Stick (2015-06-02 18:48:37)

Offline

#4 2015-06-02 19:19:15

Nili
#! Die Hard
From: 127.0.0.1
Registered: 2013-03-20
Posts: 811
Website

Re: HowTo: Toggleable conky using lemonbar (or dzen2)

conky-cli+dzen2 how great. On my new system didn't installed conky or conky-all enough to make a cool bar with conky-cli and dzen. Much more lightweight on CPU. Just awesome.


# Debian GNU/Linux 8:8.2 (netinst/stable)
# Packages Installed: 541
# Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.7-ckt11-1+deb8u4 (2015-09-19) i686 GNU/Linux
# Startup finished in 2.850s (kernel) + 6.473s (userspace) = 9.324s

Offline

#5 2015-06-02 19:31:09

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: HowTo: Toggleable conky using lemonbar (or dzen2)

Head_on_a_Stick wrote:

move this to it's own thread in the "Tutorials" section, it may get "lost" in this one wink

Like this???   Good Idea HoaS!!!


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#6 2015-06-02 19:37:33

Head_on_a_Stick
CatMod
From: A world of pure imagination
Registered: 2014-01-21
Posts: 4,797

Re: HowTo: Toggleable conky using lemonbar (or dzen2)

Good work S11!

I'll be able to find this again now smile

Offline

#7 2015-06-02 19:42:41

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: HowTo: Toggleable conky using lemonbar (or dzen2)

It's going in the conky Archive thread too.

I've seen other "panel" conkys - but "toggle" ... PRICELESS!  I love finding out new things for conky - even is I can't** use it personally.

** Read: I don't use lemonbar or dzen2


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#8 2015-06-04 13:20:04

xero
#! Junkie
From: 0x000000
Registered: 2013-09-30
Posts: 382
Website

Re: HowTo: Toggleable conky using lemonbar (or dzen2)

awesome! great work!


▬▬ι═════════-
dotfiles http://git.io/.files

Offline

#9 2015-06-04 15:47:53

userx-bw
#! Die Hard
From: stuck in an unknown reality
Registered: 2013-11-19
Posts: 735

Re: HowTo: Toggleable conky using lemonbar (or dzen2)

Sector11 wrote:

** Read: I don't use lemonbar or dzen2

why don't you try these LemonBars
lemonsquares.jpg
You can even have a dzen2
  big_smile enjoy!!!

Last edited by userx-bw (2015-06-04 15:52:10)


"How can you learn how to fix it, if you don't break it first? :8
"the only way to get away with murder is - by killing time" swp 1997  8o
"A computer is only as smart as the person using it"
"Just plug it in and see if it blows up, if not then take it apart and figure out how it works."

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo