I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

Create DWM statusbar

From Rosetta Code
Create DWM statusbar is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Description:

Create a "statusbar" program to the "DWM" window manager! You can read about this window manager program in details at this link: https://dwm.suckless.org/

The statusbar program must be started from the .xinitrc file by the way as:

path_of_your_programminglanguage path_of_statusbarprogram &

(in case of your programming language produces executable bytecode the "path_of_your_programminglanguage" part from the line above is not necessary).

The necessary features:

The style of the output on the statusbar:

Output:
98 % _8 K ^0 K 0.06 (51) [11] 2020.06.08 21:23:06 H    91; 76

or

Output:
!!!_POWER_OFF_!!! 98 % _8 K ^0 K 0.06 (51) [11] 2020.06.08 21:23:06 H    91; 76

where the meanings of the symbols above are the followings:

!!!_POWER_OFF_!!! = it is printed only if the computer is not connected to the wall-socket, or, if there are no power in that wall-socket.

98 % = the percentage of the battery-capacity

_8 K = The current download speed of the net interface. The _ character is the symbol of "download".

^0 K = The current upload speed of the net interface. The ^ character is the symbol of "upload".

The character K may be even M or G, in case if the speed is so high (megabyte or gigabyte in every second).

It is allowed for the net interface being "hardwired" in the source code of the program. ( eth0 or wlan0 or so on).

0.06 = Load average in the last 1 minute.

(51) = the free memory percent of the installed RAM. Please calculate it with the following formula:

freememorypercentage=(((double)MemFree+(double)Cached)/(double)MemTotal)*100;

[11] = The free (non-privileged) capacity (in percent) on the root filesystem (so, on the path "/").

2020.06.08 = the system date in YYYY.MM.DD format.

21:23:06 = the system time in HH:MM:SS format. Precision: 1 sec.

H = The day of the week, with maximum 3 characters, use the name of that day in your native language. It is okay if the name of the days are "hardwired" into the source code.

91; = The volume in percent of the Master audio-channel.

76 = The volume in percent of the PCM audio-channel.

Additional requirement:

In case of the audiochannel(s) got muted, then the output of this statusbar on the end must be closed between parenthesis, like this:

Output:
98 % _8 K ^0 K 0.06 (51) [11] 2020.06.08 21:23:06 H   ( 91; 76)

It is allowed to use any external library, if it is necessary.


Furor[edit]

 
 
###sysinclude X.uh
###sysinclude dir.uh
###sysinclude alsa.uh
###sysinclude system.uh
"/" sto mypath
opendisplay sto mydisplay
200 mem sto sb
{...
#g sb AC !{ "!!!_POWER_OFF_!!! " }{ " " } #s =
battery #g !(#s) noleftspc dup sum sb free " %" sum sb
"eth0" " _" " ^" netusage dup sum sb free " " sum sb
loadaverage dup 0 3 |-| swap free dup sum sb free
" (" sum sb
freemempercent #g !(#s) noleftspc dup sum sb free
") " sum sb
@mypath freenonpriv #g 100 * @mypath filesystemsize /
!(#s) noleftspc dup
"[" sum sb sum sb free
"] " sum sb
sysdatetime dup sum sb free " " sum sb
#g getmute dup !{ #s "(" sum sb #g }
"Master" sbr §volumecreate ";" sum sb
"PCM" sbr §volumecreate
#g !{ #s ")" sum sb #g }
@mydisplay @sb statusbar
...}
@mydisplay closedisplay
end
volumecreate:
getvolume #g (#s) sto vol #g @vol @vol~ -- @vol~ 3 - |-| dup #s sum sb free @vol free
rts
{ „mydisplay” }
{ „mypath” }
{ „vol” }
{ „sb” }