dslinux/user/pixil/sys/pixilwm/old backlight.c battery.c date.c
amadeus
dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:27:16 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/pixil/sys/pixilwm/old
In directory antilope:/tmp/cvs-serv11916/sys/pixilwm/old
Added Files:
backlight.c battery.c date.c
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it
--- NEW FILE: backlight.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#include <par/par.h>
#include <pixlib/pixlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <nano-X.h>
#include "nxdraw.h"
#include "apps.h"
#include "nanowm.h"
#include "config.h"
#include "powerman.h"
static GR_IMAGE_ID idON;
static GR_IMAGE_ID idOFF;
static GR_BOOL blON = 1;
static GR_WINDOW_ID blWid;
static void backlight_wndproc(win * window, GR_EVENT * ep);
#define BLOFFICON "bloff.gif"
#define BLONICON "blon.gif"
void
backlight_create(void)
{
int ih, iw, ypos;
GR_WINDOW_ID wid;
GR_SCREEN_INFO si;
GR_IMAGE_INFO iinfo;
/* Load the images first so I can center the window on the screen */
idON = loadIconImage(BLONICON, 0, 0);
idOFF = loadIconImage(BLOFFICON, 0, 0);
if (!idON || !idOFF)
return;
GrGetImageInfo(idON, &iinfo);
ih = iinfo.height;
iw = iinfo.width;
GrGetImageInfo(idOFF, &iinfo);
if (iinfo.height > ih)
ih = iinfo.height;
if (iinfo.width > iw)
iw = iinfo.width;
GrGetScreenInfo(&si);
ypos = si.ws_height + (((20 - ih) / 2) + 1);
wid = GrNewWindowEx(GR_WM_PROPS_NODECORATE, NULL, GR_ROOT_WINDOW_ID,
2, ypos, iw, ih, wm_getColor(WM_TASKBAR));
add_window(wid, GR_ROOT_WINDOW_ID, 0, backlight_wndproc);
GrSelectEvents(wid, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_EXPOSURE);
GrMapWindow(wid);
blWid = wid;
}
static void
backlight_draw(GR_WINDOW_ID id) {
GR_GC_ID gc = GrNewGC();
GrSetGCForeground(gc, wm_getColor(WM_TASKBAR));
GrFillRect(id, gc, 0, 0, 10, 16);
/* draw image in actual size */
GrDrawImageToFit(id, gc, 0, 0, -1, -1, blON ? idON : idOFF);
GrDestroyGC(gc);
}
static void
backlight_exposure(win * window, GR_EVENT_EXPOSURE * ep)
{
backlight_draw(ep->wid);
}
static void
backlight_buttondown(win * window, GR_EVENT_BUTTON * ep)
{
GR_EVENT_EXPOSURE expose;
GR_WINDOW_INFO info;
blON = !blON;
/* dummy full area expose event */
GrGetWindowInfo(ep->wid, &info);
expose.type = GR_EVENT_TYPE_EXPOSURE;
expose.wid = ep->wid;
expose.x = 0;
expose.y = 0;
expose.width = info.width;
expose.height = info.height;
backlight_exposure(window, &expose);
pm_backlight(blON ? BL_ON : BL_OFF);
}
static void
backlight_wndproc(win * window, GR_EVENT * ep)
{
switch (ep->type) {
case GR_EVENT_TYPE_EXPOSURE:
backlight_exposure(window, &ep->exposure);
break;
case GR_EVENT_TYPE_BUTTON_DOWN:
backlight_buttondown(window, &ep->button);
break;
}
}
void
pm_set_bl_state(int state) {
blON = (state == BL_ON) ? 1 : 0;
backlight_draw(blWid);
}
int
pm_get_bl_state(void) {
return (blON ? BL_ON :BL_OFF);
}
--- NEW FILE: date.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#include <pixil_config.h>
#include <langinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <nano-X.h>
#include "nanowm.h"
#include "apps.h"
#include "config.h"
#include <par/par.h>
#ifdef CONFIG_PIXILWM_MENUS
#include "sys_menu.h"
#endif
#define DATE_12_HOUR_MODE 0x00
#define DATE_24_HOUR_MODE 0x01
#define BUFFER_LENGTH 20
static int DateToggle = 0;
static int DateMode = DATE_12_HOUR_MODE;
#ifdef NOTUSED
static char *DAY[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static char *MON[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
#endif
static void date_wndproc(win * window, GR_EVENT * ep);
int check_par_tz_flag = 1;
static GR_FONT_ID g_fontid;
void
date_create(void)
{
win *window;
GR_WINDOW_ID wid;
GR_SCREEN_INFO si;
GrGetScreenInfo(&si);
g_fontid = GrCreateFont(GR_FONT_GUI_VAR, 0, NULL);
wid = GrNewWindowEx(GR_WM_PROPS_NODECORATE, NULL, GR_ROOT_WINDOW_ID,
32, si.ws_height + 4, 70, 16,
wm_getColor(WM_TASKBAR));
window = add_window(wid, GR_ROOT_WINDOW_ID, 0, date_wndproc);
GrSelectEvents(wid, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP |
GR_EVENT_MASK_EXPOSURE);
GrMapWindow(wid);
timeout_setproc(date_wndproc, window);
}
static void
date_exposure(win * window, GR_EVENT_EXPOSURE * ep)
{
char hmtz_flg = 0, tmzone[64 + 1] = { '\0' };
time_t t;
struct tm *tv;
char buf[BUFFER_LENGTH];
GR_GC_ID gc = GrNewGC();
db_handle *pardb;
GrSetGCForeground(gc, wm_getColor(WM_TASKBAR));
GrSetGCBackground(gc, wm_getColor(WM_BGCOLOR));
GrFillRect(ep->wid, gc, ep->x, ep->y, ep->width, ep->height);
/* open par */
if (check_par_tz_flag != 0) {
char *tzone;
if ((pardb =
db_openDB(db_getDefaultDB(), PAR_DB_MODE_RDONLY)) != NULL) {
/* Get the values from par */
par_getGlobalPref(pardb, "timezone", "home_active", PAR_BOOL,
&hmtz_flg, sizeof(char));
if (hmtz_flg)
par_getGlobalPref(pardb, "timezone", "home_tz", PAR_TEXT,
tmzone, sizeof(tmzone) - 1);
else
par_getGlobalPref(pardb, "timezone", "visit_tz", PAR_TEXT,
tmzone, sizeof(tmzone) - 1);
if (tmzone[0] > ' ') {
if ((tzone = strrchr(tmzone, ',')) != NULL)
tzone++;
else
tzone = tmzone;
setenv("TZ", tzone, 1);
tzset();
} /* end of if */
db_closeDB(pardb);
} /* end of if */
check_par_tz_flag = 0;
}
/* end of if */
t = time(0);
tv = localtime(&t);
if (DateToggle) {
/*
* jeffm:
* %X = Show localized date w/ out time.
*/
// strftime(buf, BUFFER_LENGTH, "%x", tv);
strftime(buf, BUFFER_LENGTH, nl_langinfo(D_FMT), tv);
} else {
if (DateMode == DATE_24_HOUR_MODE) {
/*
* jeffm:
* %k = 24 hour mode from 0 - 23.
* %M = Minutes
*/
// strftime(buf, BUFFER_LENGTH, "%k:%M", tv);
strftime(buf, BUFFER_LENGTH, nl_langinfo(T_FMT), tv);
} else {
/*
* jeffm:
* %l = 12 hour mode from 1 - 12.
* %M = Minutes
* %P = 'am' or 'pm' or a corresponding string for the current local.
*/
// strftime(buf, BUFFER_LENGTH, "%l:%M %P", tv);
strftime(buf, BUFFER_LENGTH, nl_langinfo(T_FMT_AMPM), tv);
}
}
GrSetGCForeground(gc, wm_getColor(WM_BGCOLOR));
GrSetGCBackground(gc, wm_getColor(WM_TASKBAR));
GrSetGCFont(gc, g_fontid);
GrText(ep->wid, gc, 0, 1, buf, -1, GR_TFTOP);
GrDestroyGC(gc);
}
static void
date_redraw(win * window)
{
GR_EVENT_EXPOSURE expose;
GR_WINDOW_INFO info;
/* dummy full area expose event */
GrGetWindowInfo(window->wid, &info);
expose.type = GR_EVENT_TYPE_EXPOSURE;
expose.wid = window->wid;
expose.x = 0;
expose.y = 0;
expose.width = info.width;
expose.height = info.height;
date_exposure(window, &expose);
}
#ifdef CONFIG_PIXILWM_MENUS
static void
date_set_format(void *val)
{
if ((int) val == DATE_24_HOUR_MODE)
DateMode = DATE_24_HOUR_MODE;
else
DateMode = DATE_12_HOUR_MODE;
}
static wm_menu_t date_sys_menu[] = {
{"12 Hour", MENU_TYPE_CHECK, date_set_format, (void *) DATE_12_HOUR_MODE},
{"24 Hour", MENU_TYPE_CHECK, date_set_format, (void *) DATE_24_HOUR_MODE},
{"", MENU_TYPE_END, 0}
};
#endif
static void
date_buttondown(win * window, GR_EVENT_BUTTON * ep)
{
#ifdef CONFIG_PIXILWM_MENUS
if (ep->buttons & GR_BUTTON_R) {
GR_SCREEN_INFO si;
GrGetScreenInfo(&si);
date_sys_menu[0].checked = GR_FALSE;
date_sys_menu[1].checked = GR_FALSE;
if (DateMode == DATE_12_HOUR_MODE)
date_sys_menu[0].checked = GR_TRUE;
else
date_sys_menu[1].checked = GR_TRUE;
if (open_system_menu(GR_ROOT_WINDOW_ID, 32, si.ws_height,
MENU_DIR_UP, date_sys_menu))
return;
}
#endif
DateToggle = !DateToggle;
date_redraw(window);
}
static void
date_wndproc(win * window, GR_EVENT * ep)
{
switch (ep->type) {
case GR_EVENT_TYPE_EXPOSURE:
date_exposure(window, &ep->exposure);
break;
case GR_EVENT_TYPE_BUTTON_DOWN:
date_buttondown(window, &ep->button);
break;
case GR_EVENT_TYPE_TIMEOUT:
date_redraw(window);
break;
}
}
--- NEW FILE: battery.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/* Battery monitor for those apps with APM support */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <nano-X.h>
#include <nxcolors.h>
#include <pixlib/pixlib.h>
#include "nanowm.h"
#include "apps.h"
#include "config.h"
#define APPICON "battery.gif"
/* This is how many times a second the timer refreshes */
#define TIMERRATE 2
#define TTL_TIMEOUT 2
#define TTL_WIN 1
#define BAT_WIN 2
struct battery_t
{
unsigned short percent;
unsigned short ttl;
unsigned char status;
};
static struct battery_t global_battery;
/* Some local globals */
static GR_WINDOW_ID ttl_wid = 0;
static unsigned char ttl_timer = 0;
static GR_IMAGE_ID batimage = 0;
static unsigned long timer = 0;
static int apm_fd;
static void
ttl_exposure(win * window, GR_EVENT_EXPOSURE * ep)
{
int c;
int swidth;
GR_FONT_INFO info;
char buf[20];
GR_GC_ID gc = GrNewGC();
GR_FONT_ID fontid = GrCreateFont(GR_FONT_GUI_VAR, 0, NULL);
/* If we are charging, indicate that fact */
if (global_battery.status)
sprintf(buf, "Charging");
else
sprintf(buf, "%d:%02d left", global_battery.ttl / 60, global_battery.ttl % 60);
swidth = 0;
GrGetFontInfo(fontid, &info);
for (c = 0; c < strlen(buf); c++) {
swidth += info.widths[(unsigned char) buf[c]];
}
GrResizeWindow(ttl_wid, swidth + 4, 15);
GrSetGCForeground(gc, wm_getColor(WM_ICONTEXT));
GrSetGCUseBackground(gc, GR_FALSE);
GrSetGCFont(gc, fontid);
GrText(ep->wid, gc, 1, 1, buf, -1, GR_TFTOP);
GrDestroyFont(fontid);
GrDestroyGC(gc);
}
static void
battery_exposure(win * window, GR_EVENT_EXPOSURE * ep)
{
GR_GC_ID batgc = GrNewGC();
int perc = global_battery.percent;
int height = 0;
GrSetGCForeground(batgc, wm_getColor(WM_TASKBAR));
GrFillRect(ep->wid, batgc, 0, 0, 7, 14);
GrSetGCBackground(batgc, wm_getColor(WM_TASKBAR));
/* Draw the battery */
GrDrawImageToFit(ep->wid, batgc, 0, 0, -1, -1, batimage);
/* If we are charging, the percentage is always 100% */
if (global_battery.status) {
perc = 100;
color = GR_COLOR_GREEN;
}
else {
if (perc > 100) perc = 100;
if (perc < 0) perc = 0;
if (perc > 50) color = GR_COLOR_WHITE;
else if (perc <= 50 && perc > 10) color = GR_COLOR_YELLOW;
else color = GR_COLOR_RED;
}
height = (11 * perc) / 100;
GrSetGCForeground(batgc, color);
GrFillRect(ep->wid, batgc, 1, 12 - height, 5, height);
GrDestroyGC(batgc);
}
int
get_battery_info(struct battery_t *bptr) {
bptr->percent = pix_pwr_getbat(PWR_BAT_PERCENT);
bptr->ttl = pix_pwr_getbat(PWR_BAT_SECONDS);
/* Returns 1 if charging, 0 if not, or -1 if unknown */
bptr->status = pix_pwr_isCharging();
return 0;
}
static void
redraw_window(win * window, int type)
{
GR_EVENT_EXPOSURE expose;
GR_WINDOW_INFO info;
/* dummy full area expose event */
GrGetWindowInfo(window->wid, &info);
expose.type = GR_EVENT_TYPE_EXPOSURE;
expose.wid = window->wid;
expose.x = 0;
expose.y = 0;
expose.width = info.width;
expose.height = info.height;
if (type == TTL_WIN)
ttl_exposure(window, &expose);
else
battery_exposure(window, &expose);
}
static void
battery_wndproc(win * window, GR_EVENT * ep)
{
GR_EVENT_MOUSE *em;
if (ep->type == GR_EVENT_TYPE_TIMER)
printf("go timer event\n");
switch (ep->type) {
case GR_EVENT_TYPE_EXPOSURE:
if (ep->exposure.wid == ttl_wid && ttl_timer)
ttl_exposure(window, &ep->exposure);
else
battery_exposure(window, &ep->exposure);
break;
case GR_EVENT_TYPE_BUTTON_DOWN:
if (ttl_timer) {
ttl_timer = 0;
GrUnmapWindow(ttl_wid);
} else {
ttl_timer = 1;
get_battery_info(&global_battery);
em = (GR_EVENT_MOUSE *) ep;
GrMoveWindow(ttl_wid, em->rootx, em->rooty - 15);
GrRaiseWindow(ttl_wid);
GrMapWindow(ttl_wid);
}
break;
case GR_EVENT_TYPE_TIMEOUT:
if (ttl_timer) {
ttl_timer++;
/* Hide the ttl timer after a short timeout */
if (ttl_timer == (TTL_TIMEOUT * TIMERRATE)) {
ttl_timer = 0;
GrUnmapWindow(ttl_wid);
}
}
if (timer++ % (TIMERRATE * 30)) {
unsigned short pperc = global_battery.percent;
if (!get_battery_info(&global_battery))
break;
/* Only redraw if the value has changed */
if (pperc != global_battery.percent)
redraw_window(window, BAT_WIN);
}
break;
}
}
void
battery_create(void)
{
int ypos;
GR_IMAGE_INFO iinfo;
win *window, *ttlwindow;
GR_WINDOW_ID wid;
GR_SCREEN_INFO si;
GR_WM_PROPERTIES props;
/* Open up a link to the apm data file */
apm_fd = open("/proc/apm", O_RDONLY);
if (apm_fd == -1) {
//fprintf(stderr, "Couldn't open /proc/apm\n");
//return;
}
if (!get_battery_info(&global_battery))
return;
batimage = loadIconImage(APPICON, 0, 0);
if (!batimage)
return;
GrGetScreenInfo(&si);
GrGetImageInfo(batimage, &iinfo);
ypos = si.ws_height + (((20 - iinfo.height) / 2) + 1);
wid = GrNewWindowEx(GR_WM_PROPS_NODECORATE,
NULL, GR_ROOT_WINDOW_ID,
18, ypos, 7, 14, wm_getColor(WM_TASKBAR));
window = add_window(wid, GR_ROOT_WINDOW_ID, 0, battery_wndproc);
ttl_wid =
GrNewWindowEx(GR_WM_PROPS_NODECORATE, NULL, GR_ROOT_WINDOW_ID, 22,
si.ws_height - 17, 45, 15, wm_getColor(WM_DIALOG));
props.flags = GR_WM_FLAGS_BORDERSIZE;
props.bordersize = 1;
GrSetWMProperties(ttl_wid, &props);
ttlwindow = add_window(ttl_wid, GR_ROOT_WINDOW_ID, 0, battery_wndproc);
GrSelectEvents(wid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_TIMEOUT |
GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP);
GrSelectEvents(ttl_wid, GR_EVENT_MASK_EXPOSURE);
GrMapWindow(wid);
timeout_setproc(battery_wndproc, window);
}
More information about the dslinux-commit
mailing list