WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Flit: an FLTK-native "tray" with clock, sound control, and battery monitor  (Read 35568 times)

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
I've been working with flwm, and like some parts of it (and working on fixing a few I don't  >:(), but I really missed having a clock on-screen like I have in jwm and other desktops (gnome, windows).  I didn't see much that was FLTK-native, so, of course I decided to make my own.  ::)  While I was at it, I decided to also add a battery monitor (since I use TC on a laptop) and an easy to adjust sound control.  ;D

I call this little "tray" application Flit.  It works something like the system tray in Windows XP and some aspects of the panel UIs in GNOME and other X11 desktops.  But of course, being made with tight FLTK code, it is really small... less than 20 kb!  Each applet can be individually toggled on and off, so if you don't want to see one or two of them, that's OK.  There are few color options, and the location is flexible too.  Your preferences can be saved so they automatically used each time you launch Flit.

At this alpha release stage, I don't have it packaged up yet... Maybe Jason will beat me to making a .tce/.tcz package.  ;)

I've attached a screenshot, the source code, and a make file.  I'll also post the full help text to this thread.  Maybe later I'll highlight a few interesting parts of the code.  If you have any issues or suggestions, please post them here.  If there is interest, I may add CPU monitor and/or network activity monitor applets.

I hope it's useful to others, especially users of flwm or other light environments like openbox/fluxbox.
--
Mike Lockmoore

EDIT: Source code updated to version 0.9.2, which has keyboard shortcuts along with the previous flexibility to configure it to work with various sound hardware via OSS.  See reply #28 and #32 to get more details.

EDIT: Source code updated to version 0.9.4, which calculates a battery charging/discharging rate if ACPI fails to provide a nonzero value.  See reply #46 and #51 for details.

EDIT: Source code updated to version 0.9.5(b),  which  prevents sound applet from unhiding if OSS not present, surpresses batt. charge/discharge remaining time estimates for three minutes after a change in status, and automatically shows menu as soon as Alt key is pressed for better keyboard usage.

EDIT: Source code updated to version 0.9.6,  which  replaces the Alt key bindings with Ctrl key bindings. Also, the tooltip text formatting was changed slightly for better readability.

EDIT: Source code updated to version 0.9.7, Removed non-FLTK-standard "Esc opens context menu" with "Esc closes window/app", also added '%' char above batt. icon when it's discharging.

EDIT: Source code updated to version 0.9.8, with option to disable the Ctrl "hotkey"-triggered opening of the right-click menu, as well immediately releasing input focus on application startup.

EDIT: Source code updated to version 0.9.9, to handle case where battery rate is non-numeric by allowing battery charging/discharging rate calculations to proceed using derived rates.

EDIT: Let's call this major version done! Source code updated to 1.0.0. Same code with the updated version string.
« Last Edit: October 03, 2009, 08:39:50 PM by MikeLockmoore »

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
The help text for Flit (ver. 1.0.0):

INTRO

Flit is an applet 'tray', currently offering clock, master sound volume control, and battery monitor. It is written to be small and low-overhead, using the FLTK user interface library, so it is especially efficient on TinyCore Linux. The source code of Flit is released under the GNU license. See http://www.gnu.org/licenses/ for more details.

There is a menu of choices made available through right-clicking on Flit. The sound control applet has several additional keyboard shortcuts (see below). The Flit menu may optionally be opened automatically by a Ctrl key, as defined in the General Options section.

If you don't want to see all three applets, you can disable one or two of them in the right-click menu, but not all three!

'Hover' your mouse pointer over each applet to get more detailed information. The battery recharge time estimate is very approximate in this release. (I hope to improve the algorithm soon!)

If you want to start Flit automatically, invoke it in your /opt/bootlocal.sh startup script or make a custom .xsession script file, and use a & symbol to return control immediately to the script, like this:
     /path/to/flit &
Note: The base configuration of TinyCore Linux (at least version 2.3) includes and
automatically starts Flit if the default window manager flwm is used.

CLOCK
The only option for the clock is 24-hour time format, or 12-hour format with AM or PM indication. Use the right-click menu to toggle between these modes. Hover the mouse pointer to see date and year in addition to time.

SOUND CONTROL
The current sound volume level is indicated by the number and size of the sound "rays" next to the speaker icon. To adjust the volume, place your mouse cursor over the speaker and use the mouse scroll wheel (or equivalent) to adjust the sound volume in 5% increments. You may also use the following keystrokes:

Louder: Ctrl+U, or Up arrow cursor key, or + key
Quieter: Ctrl+L, or Down arrow cursor key, or - key
Mute/Unmute: Ctrl+M, or Pause key

Future versions may also provide a pop-up slider control.

The sound control requires an OSS "mixer" device '/dev/mixer' to be present. There is a lot of variation in how sound devices can be controlled, but Flit will try to support some common methods. By default, Flit will try to find an appropriate mixer control to adjust the overall playback volume. You can override this behavior by specifying an exact OSS mixer control name in the .flit.conf file, in the "oss_control_name =" statement. If the name is "autosel", Flit will do the default auto-selection. But if you know that you get best results from a specific mixer control, such as "vol" or "pcm" or something else, put it name into the .flit.conf file, such as:

    oss_control_name = pcm

If flit is not successful in finding a suitable control (which must be marked with the MASTER_VOLUME or PCM_VOLUME in OSS), you won't see the sound control applet in Flit, and you won't be able to "unhide" it. You may want to try the graphical mixer application ossxmix (note the X in the name) or command-line application ossmix and experiment with the controls made available for your hardware to see which ones can control the volume. If OSS + your hardware don't support an adjustable output volume, you may still be able to use a mute control with Flit.

LIMITATIONS: The OSS vmix software mixer control will only work if vmix is fully "attached" to your audio hardware (beyond the scope of this document). ALSA is not supported (at least not yet, anyway).

BATTERY MONITOR
In the battery icon, charge is colored green if the level is 40% or higher, yellow when 20% or higher, and red below 20%. If the estimated charge Is less than 13%, the outline of the battery icon will slowly flash red. When recharging power is available, an AC power plug icon is shown over the battery icon. If the battry is discharging, the remaining charge percentage number is shown above the battery icon.

The battery monitor requires information in the /proc/acpi system information, so you must boot Linux with the 'laptop' kernel option or load the appropriate ACPI kernel module. About three minutes after a switch between charging and discharging, Flit will begin showing estimates of the remaining time.

GENERAL OPTIONS
By default, Flit will automatically pop up the right-click menu if Flit has the keyboard focus and you press either Ctrl key, which you may do as part of a Ctrl+key combination. If you would prefer to not have Flit open the menu on Ctrl keypress, select the 'Toggle Ctrl key menu activation' menu option and then save the configuration.

You can choose one of appearance styles:
 a) Normal: black on light gray, with a sunken tray effect
 b) Inverse: light gray on black, also with a sunken tray effect
 c) 'Transparent', which has a background color slightly lighter than the
     X11 root window where Flit plans to appear and a contrasting
     foreground color, with a flat effect, which matches
     wbar nicely. If the planned location is occupied
     by a window when Flit starts, its background color
     will be based on that.

You may reposition Flit with your mouse (left-click + drag), or hand-edit the .flit.conf configuration file (see cautions below). The location can be defined to one of the four corners (se = SouthEast, i.e. the lower-right corner, and so on) or a x,y pair. See the configuration file for an example.

SAVING PREFERENCES
Use the 'Save configuration' command to make flit remember your preferences by writing the .flit.conf file in your home directory (as defined by the $HOME environment variable). You may edit this file with a text editor, but please preserve the spelling, capitalization, and spacing of content to prevent parsing problems. You can revert to default settings by deleting the .flit.conf file and restarting Flit.


EDIT: Attached help file here.  The preferred place for this help file as of version 0.9.3 (and modified 0.9.2 in TC 2.3) is now /usr/share/doc/tc/flit_help.htm.
« Last Edit: October 03, 2009, 08:40:32 PM by MikeLockmoore »

Offline alu

  • Sr. Member
  • ****
  • Posts: 429
sounds great and useful; can i use it with evilwm?

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
alu: If you have the setup and inclination to compile it, just give it a try!  If not, we should have an "alpha" release package ready within a few days.

As long as you still have the FLTK dynamic libraries around, I would think Flit will work fine in evilwm.  Flit does not need window decorations anyway.

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Seems to compile and work fine for me so far  :)

Edit: 'Spoke too soon - after loading OSS:
Code: [Select]
$ /mnt/sda1/tmp/flit &
$ No config file found!
Bad mixer control name(987) 'vol

..maybe needs an "always on top" switch in order to be visible above maximised windows?
« Last Edit: August 28, 2009, 06:28:11 AM by Juanito »

Offline alu

  • Sr. Member
  • ****
  • Posts: 429
thanks Mike, great, i surely shall use it, i don't have time right now to compile it and test it on my own, so i shall wait a bit

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Juanito:

The "always on top" property is a good idea. I'll look into how to do that.

Your first "No config file found!" message is harmless and expected if you've never saved your configuration (maybe I'll get rid of it).  

The mixer message is more puzzling.  Flit is just trying to run ossmix to get or set the volume, so if OSS is truly active, I'm suprised it failed like that.  Maybe repeat the test but run ossmix on the command line first?  Could you post the output of your ossmix (with no arguments) here?  Maybe there is some way your OSS implementation names the sound volume differently than in mine.
--
Mike
« Last Edit: August 28, 2009, 09:42:23 AM by MikeLockmoore »

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Code: [Select]
$ ossmix
Selected mixer 0/High Definition Audio STAC9200
Known controls are:
jack.black.mode1 <select|input> (currently select)
jack.black.select1 <pcm|select> (currently pcm)
jack.black.select2 [<leftvol>:<rightvol>] (currently 38.9:38.9 dB)
jack.int-speaker.mode <select|input> (currently select)
jack.int-mic.mode <select|input> (currently select)
jack.black.mode2 <select|input> (currently input)
record.select.select1 [<leftvol>:<rightvol>] (currently 39.9:39.9 dB)
record.select.select2 <select|select> (currently select)
record.select.select3 [<leftvol>:<rightvol>] (currently 19.4:19.4 dB)
misc <-28.-8dB|-19.-2dB|-9.-6dB|0.0dB|mute> (currently 131(too large (a=5)?))
vmix0-enable ON|OFF (currently ON)
vmix0-rate <decimal value> (currently 48000) (Read-only)
vmix0-channels <Stereo|Multich> (currently Stereo)
vmix0-src <Fast|Low|Medium|High|High+|Production|OFF> (currently Fast)
vmix0-outvol <monovol> (currently 25.0 dB)
vmix0-invol <monovol> (currently 25.0 dB)
vmix0.pcm4 [<leftvol>:<rightvol>] (currently 25.0:25.0 dB)
vmix0.pcm5 [<leftvol>:<rightvol>] (currently 25.0:25.0 dB)
vmix0.pcm6 [<leftvol>:<rightvol>] (currently 25.0:25.0 dB)
vmix0.pcm7 [<leftvol>:<rightvol>] (currently 25.0:25.0 dB)

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Juanito:  :o  That looks really different.  The killer is that ossmix is dealing is dealing with dB for your device, not percentages!  I was hoping ossmix would make different sound devices appear more consistent than this. 

If you wanted to use ossmix to set the volume, do you know how you would do it?  ???
--
Mike

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Mike: Looks great. However, I too have an issue with ossmix
flit reports: Bad mixer control name (987) 'vol'

In my /opt/bootlocal.sh I set the volume with:
ossmix -d0 misc.pcm1 90:90
10+ Years Contributing to Linux Open Source Projects.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
« Last Edit: August 28, 2009, 10:44:41 AM by MikeLockmoore »

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
There are two versions of OSS extension for v2.x
4.1 and 4.0 which there have been reports of differences in operation.
I am using 4.1
10+ Years Contributing to Linux Open Source Projects.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
I'll check to see which OSS version I'm using later tonight.  If I'm on 4.0, maybe I'll update to 4.1 and figure out how to make it work as consistently as posible.  Juanito's device looks like it might be a bugger to support! :-\
--
ML

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
OK, I've changed the interface to the OSS audio system.  I'm now opening the device "file" /dev/mixer and using the OSS-published ioctl( ) interface.  It works just as well for me, and I'm hoping it works at least somewhat OK for others.  The new code iterates through all of the mixer control paramters and tries to find a control that is of "main volume" or "PCM  volume type".  As I don't know yet a way to select a "best" one, it quits searching as soon as it finds one of either type.  I hope this first one will work for most OSS users.   

Juanito and RobertS: if you can spare a few minutes, please try this version and tell me how it works for you.  If it does not work, maybe enable the #define DIAG manifest constant and see if the output can tell us anything.

I also updated the code that looks at the background to set the transparent color... it now actually looks at the spot it plans to appear in, not just the 0,0 corner of the screen... so now if Flit appears over a background, it should hopefully choose a color related to its location.
--
Mike L.
--

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Juanito and RobertS: if you can spare a few minutes, please try this version and tell me how it works for you.  If it does not work, maybe enable the #define DIAG manifest constant and see if the output can tell us anything.

No problem to try, but where is it?  :)