mirror of
https://github.com/amiwm/amiwm.git
synced 2026-03-24 01:24:15 +00:00
[amiwm] Add the basic battery info printing bits
* add a batteryinfo config option to enable whether or not to display the current battery info string * populate that battery info string whenever we receive a battery update from the module * document it all This is very specific to a battery thing rather than a generic menu widget thing, but I think I'll go and twiddle with this stuff a bit more first and then work on a more generic "menu widget" thing later. It'd be nice to have "menu bar things" like battery and the date/time field on a linked list of "things". There's also some bugs - notably, rendering artifacts when the string length shrinks, and it only updating on the 'current' menu bar (when you have multiple desktops visible at once.) Those also should be fixed for completeness. :-)
This commit is contained in:
6
amiwm.1
6
amiwm.1
@@ -94,6 +94,12 @@ The time string is formatted with the standard strftime() parameters.
|
|||||||
The default is "%c". It has been found that "%a %b %e %Y %l:%M %p" works
|
The default is "%c". It has been found that "%a %b %e %Y %l:%M %p" works
|
||||||
well too. Number is the update interval in seconds.
|
well too. Number is the update interval in seconds.
|
||||||
|
|
||||||
|
.SH BatteryInfo {yes|no}
|
||||||
|
|
||||||
|
This lets you display battery information on the menu bar.
|
||||||
|
It reqiures a module (such as Battery) to gather current battery status
|
||||||
|
and push it into amiwm to display.
|
||||||
|
|
||||||
.SH ToolItem \f1\*(lq\f3name" \f1\*(lq\f3command" \f1\*(lq\f3hotkey"
|
.SH ToolItem \f1\*(lq\f3name" \f1\*(lq\f3command" \f1\*(lq\f3hotkey"
|
||||||
|
|
||||||
Adds an item in the Tools menu with the specified name, which executes
|
Adds an item in the Tools menu with the specified name, which executes
|
||||||
|
|||||||
2
gram.y
2
gram.y
@@ -66,6 +66,7 @@ static int ti_level=0;
|
|||||||
%token <num> INTERSCREENGAP AUTORAISE FOCUS FOLLOWMOUSE CLICKTOTYPE SLOPPY
|
%token <num> INTERSCREENGAP AUTORAISE FOCUS FOLLOWMOUSE CLICKTOTYPE SLOPPY
|
||||||
%token <num> CUSTOMICONSONLY
|
%token <num> CUSTOMICONSONLY
|
||||||
%token <num> TITLEBARCLOCK TITLECLOCKFORMAT
|
%token <num> TITLEBARCLOCK TITLECLOCKFORMAT
|
||||||
|
%token <num> BATTERYINFO
|
||||||
%token <num> OPAQUEMOVE OPAQUERESIZE SCREENMENU STYLE CLASS TITLE ICONTITLE ICON
|
%token <num> OPAQUEMOVE OPAQUERESIZE SCREENMENU STYLE CLASS TITLE ICONTITLE ICON
|
||||||
%token <num> SHORTLABELICONS
|
%token <num> SHORTLABELICONS
|
||||||
%token <ptr> STRING
|
%token <ptr> STRING
|
||||||
@@ -118,6 +119,7 @@ stmt : error
|
|||||||
prefs.titleclockinterval=$2;
|
prefs.titleclockinterval=$2;
|
||||||
prefs.titleclockformat=$3; }
|
prefs.titleclockformat=$3; }
|
||||||
| SCREENMENU truth { prefs.screenmenu=$2; }
|
| SCREENMENU truth { prefs.screenmenu=$2; }
|
||||||
|
| BATTERYINFO truth { prefs.battery_info = $2; }
|
||||||
| stylespec styleitems RIGHTBRACE
|
| stylespec styleitems RIGHTBRACE
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
11
menu.c
11
menu.c
@@ -37,6 +37,8 @@ extern struct Library *XLibBase;
|
|||||||
#define CHECKED 2
|
#define CHECKED 2
|
||||||
#define DISABLED 4
|
#define DISABLED 4
|
||||||
|
|
||||||
|
char battery_status[128];
|
||||||
|
|
||||||
extern Display *dpy;
|
extern Display *dpy;
|
||||||
extern Cursor wm_curs;
|
extern Cursor wm_curs;
|
||||||
extern XContext screen_context, client_context;
|
extern XContext screen_context, client_context;
|
||||||
@@ -303,7 +305,7 @@ void redraw_item(struct Item *i, Window w)
|
|||||||
XSetForeground(dpy, scr->menubargc, scr->dri.dri_Pens[BARDETAILPEN]);
|
XSetForeground(dpy, scr->menubargc, scr->dri.dri_Pens[BARDETAILPEN]);
|
||||||
XSetBackground(dpy, scr->menubargc, scr->dri.dri_Pens[BARBLOCKPEN]);
|
XSetBackground(dpy, scr->menubargc, scr->dri.dri_Pens[BARBLOCKPEN]);
|
||||||
}
|
}
|
||||||
if(i->text)
|
if(i->text) {
|
||||||
#ifdef USE_FONTSETS
|
#ifdef USE_FONTSETS
|
||||||
XmbDrawImageString(dpy, w, scr->dri.dri_FontSet,
|
XmbDrawImageString(dpy, w, scr->dri.dri_FontSet,
|
||||||
scr->menubargc, (i->flags&CHECKIT)?1+scr->checkmarkspace:1,
|
scr->menubargc, (i->flags&CHECKIT)?1+scr->checkmarkspace:1,
|
||||||
@@ -312,8 +314,9 @@ void redraw_item(struct Item *i, Window w)
|
|||||||
XDrawImageString(dpy, w, scr->menubargc, (i->flags&CHECKIT)?1+scr->checkmarkspace:1,
|
XDrawImageString(dpy, w, scr->menubargc, (i->flags&CHECKIT)?1+scr->checkmarkspace:1,
|
||||||
scr->dri.dri_Ascent+1, i->text, i->textlen);
|
scr->dri.dri_Ascent+1, i->text, i->textlen);
|
||||||
#endif
|
#endif
|
||||||
else
|
} else {
|
||||||
XFillRectangle(dpy, w, scr->menubargc, 2, 2, m->width-10, 2);
|
XFillRectangle(dpy, w, scr->menubargc, 2, 2, m->width-10, 2);
|
||||||
|
}
|
||||||
if(i->sub) {
|
if(i->sub) {
|
||||||
int x=m->width-6-scr->hotkeyspace-1+8;
|
int x=m->width-6-scr->hotkeyspace-1+8;
|
||||||
#ifdef USE_FONTSETS
|
#ifdef USE_FONTSETS
|
||||||
@@ -547,11 +550,11 @@ void redrawmenubar(Window w)
|
|||||||
/*
|
/*
|
||||||
* Update the battery indicator if it's enabled.
|
* Update the battery indicator if it's enabled.
|
||||||
*/
|
*/
|
||||||
if (1) {
|
if (prefs.battery_info) {
|
||||||
char battery_buf[512];
|
char battery_buf[512];
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
sprintf(battery_buf, "| Battery |");
|
sprintf(battery_buf, "| %s |", battery_status);
|
||||||
#ifdef USE_FONTSETS
|
#ifdef USE_FONTSETS
|
||||||
l = XmbTextEscapement(scr->dri.dri_FontSet, battery_buf, strlen(battery_buf));
|
l = XmbTextEscapement(scr->dri.dri_FontSet, battery_buf, strlen(battery_buf));
|
||||||
XmbDrawImageString(dpy, w, scr->dri.dri_FontSet, scr->menubargc,
|
XmbDrawImageString(dpy, w, scr->dri.dri_FontSet, scr->menubargc,
|
||||||
|
|||||||
17
module.c
17
module.c
@@ -493,19 +493,34 @@ static void handle_module_cmd(struct module *m, char *data, int data_len)
|
|||||||
case MCMD_UPDATE_BATTERY:
|
case MCMD_UPDATE_BATTERY:
|
||||||
{
|
{
|
||||||
struct mcmd_update_battery *batt;
|
struct mcmd_update_battery *batt;
|
||||||
|
extern char battery_status[];
|
||||||
|
|
||||||
|
if (data == NULL) {
|
||||||
|
reply_module(m, NULL, -1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (data_len != sizeof(struct mcmd_update_battery)) {
|
if (data_len != sizeof(struct mcmd_update_battery)) {
|
||||||
reply_module(m, NULL, -1);
|
reply_module(m, NULL, -1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
batt = (void *) data;
|
batt = (void *) data;
|
||||||
|
|
||||||
|
#if 0
|
||||||
fprintf(stderr, "%s: called, BATTERY, pct=%d, time=%d, ac=%d\n",
|
fprintf(stderr, "%s: called, BATTERY, pct=%d, time=%d, ac=%d\n",
|
||||||
__func__,
|
__func__,
|
||||||
batt->battery_pct,
|
batt->battery_pct,
|
||||||
batt->battery_time,
|
batt->battery_time,
|
||||||
batt->battery_ac);
|
batt->battery_ac);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* XXX TODO: update the battery menu thingy here */
|
/*
|
||||||
|
* XXX TODO: for now we're just populating a string here.
|
||||||
|
* Later on we should just store the current battery state
|
||||||
|
* somewhere (a key/value table would be nice!) and then
|
||||||
|
* the widget code can pull out its needed state to render.
|
||||||
|
*/
|
||||||
|
snprintf(battery_status, 128, "%d pct%s", batt->battery_pct,
|
||||||
|
batt->battery_ac == 1 ? " A" : " -");
|
||||||
|
|
||||||
reply_module(m, NULL, 0);
|
reply_module(m, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
|||||||
1
prefs.h
1
prefs.h
@@ -17,6 +17,7 @@ extern struct prefs_struct {
|
|||||||
char *titleclockformat; /* format to use for the clock */
|
char *titleclockformat; /* format to use for the clock */
|
||||||
int titleclockinterval; /* how often do we update the clock?*/
|
int titleclockinterval; /* how often do we update the clock?*/
|
||||||
int icontray; // if true then icons will be shown in a tray on top of each screen (besides clock and screen name)
|
int icontray; // if true then icons will be shown in a tray on top of each screen (besides clock and screen name)
|
||||||
|
int battery_info; /* display battery info? */
|
||||||
struct _Style *firststyle, *laststyle;
|
struct _Style *firststyle, *laststyle;
|
||||||
} prefs;
|
} prefs;
|
||||||
|
|
||||||
|
|||||||
1
rc.c
1
rc.c
@@ -105,6 +105,7 @@ struct keyword { char *name; int token; } keywords[] = {
|
|||||||
{ "barblockpen", T_BARBLOCKPEN },
|
{ "barblockpen", T_BARBLOCKPEN },
|
||||||
{ "bardetailpen", T_BARDETAILPEN },
|
{ "bardetailpen", T_BARDETAILPEN },
|
||||||
{ "bartrimpen", T_BARTRIMPEN },
|
{ "bartrimpen", T_BARTRIMPEN },
|
||||||
|
{ "batteryinfo", BATTERYINFO },
|
||||||
{ "blockpen", T_BLOCKPEN },
|
{ "blockpen", T_BLOCKPEN },
|
||||||
{ "both", BOTH },
|
{ "both", BOTH },
|
||||||
{ "bottom", BOTTOM },
|
{ "bottom", BOTTOM },
|
||||||
|
|||||||
Reference in New Issue
Block a user