suaveant has asked for the wisdom of the Perl Monks concerning the following question:

I was using my laptop in KDE the other day and thought it would be nice to have a one pixel battery meter that stayed always on top at the edge of the screen. I searched around and could find no projects that seemed to supply this, so I figured I would write my own.

Is there a way to do something like this in Perl? Write a floating graphic in X without the window manager putting a title bar on it and placing it where it wants. I assume there is but need a point in the right direction.

If it can't be done in Perl maybe someone can point me in the right direction for C/C++ (though I am much more comfortable with Perl).

I thought maybe Tk::Xlib would do it, but none of the demos did anything unmanaged and I haven't been able to construct a good google search to find what I need.

                - Ant
                - Some of my best work - (1 2 3)

Replies are listed 'Best First'.
Re: Making Unmanaged X Graphics?
by PreferredUserName (Pilgrim) on Dec 30, 2004 at 18:52 UTC
    You want to hide your main window, and then put up a different window and mark it as "transient", which means it's a menu or popup or something like that. The following works for me, though I don't have KDE.

    Also, in some window managers (like fvwm), you can configure different window decorations for different window names. So you could have a config line like "Style BatteryMeter NoTitle" or something along those lines.

    #!/usr/bin/perl -w use strict; use Tk; use constant UPDATE_PERIOD => 30; # seconds use constant METER_MAX_LEN => 500; our $BatteryMeter; sub set_meter_size { my $percent_strength = shift; my $new_len = int $percent_strength * METER_MAX_LEN; $new_len = 1 if $new_len < 1; # Geometry format is WidthxHeight+OffsetFromLeft+OffsetFromTop $BatteryMeter->geometry("${new_len}x2+10+200"); } sub update_battery_strength { my $battery_strength = rand(); # instead of rand(), figure out you +r # battery life set_meter_size($battery_strength); } my $main_window = MainWindow->new(); $main_window->withdraw(); $BatteryMeter = $main_window->Toplevel(-background => 'red'); $BatteryMeter->transient($main_window); update_battery_strength(); $BatteryMeter->repeat(1000 * UPDATE_PERIOD, \&update_battery_strength) +; MainLoop();
    Good luck!
Re: Making Unmanaged X Graphics?
by amw1 (Friar) on Dec 30, 2004 at 17:12 UTC
    You can modify the window with your xresources file. It's been so many years since I've done much with manually setting up the xrdb that I forget the exact syntax but it's something vaugly like:
    yourapp.title: none
    put the appropriate lines into a file then run xrdb --merge <filename>
Re: Making Unmanaged X Graphics?
by zentara (Cardinal) on Dec 31, 2004 at 13:19 UTC
    You can do this real easy with the Tk overrideredirect and geometry methods. Here is a simple example. In a real case, you might want to add a menu" with a right-click, etc.etc.
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::ProgressBar; my $mw = MainWindow->new(); $mw->overrideredirect(1); $mw->geometry('-0-0'); my $p = $mw->ProgressBar( -blocks => 1, -width => 20, -length => 200, -from => 0, -to => 100, -variable => \( my $foo ), -colors => [0,'hotpink'], )->pack(); $foo = 0; $mw->repeat( 10, sub { $foo = ( $foo + 1 ) % 100 } ); MainLoop;

    I'm not really a human, but I play one on earth. flash japh