View | Details | Raw Unified | Return to bug 138489
Collapse All | Expand All

(-)src/aapm.cc (-9 / +127 lines)
Lines 31-38 Link Here
31
#include <sys/file.h>
31
#include <sys/file.h>
32
#include <sys/ioctl.h>
32
#include <sys/ioctl.h>
33
#include <sys/types.h>
33
#include <sys/types.h>
34
#ifdef i386
34
#include <machine/apm_bios.h>
35
#include <machine/apm_bios.h>
35
#endif
36
#endif
37
#include <sys/sysctl.h>
38
#include <dev/acpica/acpiio.h>
39
#endif
36
40
37
#ifdef __NetBSD__
41
#ifdef __NetBSD__
38
#include <sys/file.h>
42
#include <sys/file.h>
Lines 63-69 static YColor *taskBarBg = 0; Link Here
63
67
64
68
65
void ApmStr(char *s, bool Tool) {
69
void ApmStr(char *s, bool Tool) {
66
#ifdef __FreeBSD__
70
#if defined(__FreeBSD__) && defined(i386) 
67
    struct apm_info ai;
71
    struct apm_info ai;
68
#elif defined __NetBSD__
72
#elif defined __NetBSD__
69
    struct apm_power_info ai;
73
    struct apm_power_info ai;
Lines 88-94 void ApmStr(char *s, bool Tool) { Link Here
88
        error = 1;
92
        error = 1;
89
        return ;
93
        return ;
90
    }
94
    }
91
#ifdef __FreeBSD__
95
#if defined(__FreeBSD__) && defined(i386)
92
    if (ioctl(fd,APMIO_GETINFO, &ai) == -1)
96
    if (ioctl(fd,APMIO_GETINFO, &ai) == -1)
93
    {
97
    {
94
        static int error = 0;
98
        static int error = 0;
Lines 231-236 int YApm::ignore_directory_ac_entry(stru Link Here
231
void YApm::AcpiStr(char *s, bool Tool) {
235
void YApm::AcpiStr(char *s, bool Tool) {
232
    char buf[80], buf2[80], bat_info[250];
236
    char buf[80], buf2[80], bat_info[250];
233
    FILE *fd;
237
    FILE *fd;
238
    int      acpifd;
234
    //name of the battery
239
    //name of the battery
235
    char *BATname;
240
    char *BATname;
236
    //battery is present or absent
241
    //battery is present or absent
Lines 250-261 void YApm::AcpiStr(char *s, bool Tool) { Link Here
250
    //status of ac-adapter online/offline
255
    //status of ac-adapter online/offline
251
    int ACstatus;
256
    int ACstatus;
252
    int i;
257
    int i;
258
    size_t len;
253
259
254
    *s='\0';
260
    *s='\0';
255
261
256
    //assign some default values, in case
262
    //assign some default values, in case
257
    //the file in /proc/acpi will contain unexpected values
263
    //the file in /proc/acpi will contain unexpected values
258
    ACstatus = -1;
264
    ACstatus = -1;
265
#ifndef __FreeBSD__
259
    if (acpiACName && acpiACName[0] != 0) {
266
    if (acpiACName && acpiACName[0] != 0) {
260
        strcat3(buf, "/proc/acpi/ac_adapter/", acpiACName, "/state", sizeof(buf));
267
        strcat3(buf, "/proc/acpi/ac_adapter/", acpiACName, "/state", sizeof(buf));
261
        fd = fopen(buf, "r");
268
        fd = fopen(buf, "r");
Lines 285-290 void YApm::AcpiStr(char *s, bool Tool) { Link Here
285
            fclose(fd);
292
            fclose(fd);
286
        }
293
        }
287
    }
294
    }
295
#else
296
    len = sizeof(i);
297
    if (sysctlbyname("hw.acpi.acline", &i, &len, NULL, 0) >= 0) {
298
	if (i == 1)
299
	    ACstatus = AC_ONLINE;
300
	else if (i = 0)
301
	    ACstatus = AC_OFFLINE;
302
	else
303
	    ACstatus = AC_UNKNOWN;
304
    }
305
#endif
288
306
289
    int n = 0;
307
    int n = 0;
290
    for (i = 0; i < batteryNum; i++) {
308
    for (i = 0; i < batteryNum; i++) {
Lines 299-304 void YApm::AcpiStr(char *s, bool Tool) { Link Here
299
        BATrate = -1;
317
        BATrate = -1;
300
        BATtime_remain = -1;
318
        BATtime_remain = -1;
301
319
320
#ifndef __FreeBSD__
302
        strcat3(buf, "/proc/acpi/battery/", BATname, "/state", sizeof(buf));
321
        strcat3(buf, "/proc/acpi/battery/", BATname, "/state", sizeof(buf));
303
        fd = fopen(buf, "r");
322
        fd = fopen(buf, "r");
304
        if (fd == NULL) {
323
        if (fd == NULL) {
Lines 347-356 void YApm::AcpiStr(char *s, bool Tool) { Link Here
347
            }
366
            }
348
            fclose(fd);
367
            fclose(fd);
349
        }
368
        }
369
#else
370
	int      acpifd;
371
372
#define ACPIDEV         "/dev/acpi"
373
	acpifd = open(ACPIDEV, O_RDONLY);
374
	if (acpifd != -1) {
375
	    union acpi_battery_ioctl_arg battio;
376
	    
377
	    battio.unit = i;
378
	    if (ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio) != -1) {
379
		if (battio.battinfo.state != ACPI_BATT_STAT_NOT_PRESENT) {
380
		    BATpresent = BAT_PRESENT;
381
		    if (battio.battinfo.state == 0)
382
			BATstatus = BAT_FULL;
383
		    else if (battio.battinfo.state & ACPI_BATT_STAT_CHARGING)
384
			BATstatus = BAT_CHARGING;
385
		    else if (battio.battinfo.state & ACPI_BATT_STAT_DISCHARG)
386
			BATstatus = BAT_DISCHARGING;
387
		    else
388
			BATstatus = BAT_UNKNOWN;
389
		    if (battio.battinfo.cap != -1 && acpiBatteries[i]->capacity_full != -1)
390
			BATcapacity_remain = acpiBatteries[i]->capacity_full *
391
			    battio.battinfo.cap / 100;
392
		    if (battio.battinfo.min != -1)
393
			BATtime_remain = battio.battinfo.min;
394
		    if (battio.battinfo.rate != -1)
395
			BATrate = battio.battinfo.rate;
396
		} else
397
		    BATpresent = BAT_ABSENT;
398
	    }
399
	}
400
#endif
350
401
351
        if (BATpresent == BAT_PRESENT) { //battery is present now
402
        if (BATpresent == BAT_PRESENT) { //battery is present now
352
            if (acpiBatteries[i]->present == BAT_ABSENT) { //and previously was absent
403
            if (acpiBatteries[i]->present == BAT_ABSENT) { //and previously was absent
353
                //read full-capacity value
404
                //read full-capacity value
405
#ifndef __FreeBSD__
354
                strcat3(buf, "/proc/acpi/battery/", BATname, "/info", sizeof(buf));
406
                strcat3(buf, "/proc/acpi/battery/", BATname, "/info", sizeof(buf));
355
                fd = fopen(buf, "r");
407
                fd = fopen(buf, "r");
356
                if (fd != NULL) {
408
                if (fd != NULL) {
Lines 372-377 void YApm::AcpiStr(char *s, bool Tool) { Link Here
372
                    if (BATcapacity_remain > BATcapacity_full && BATcapacity_design > 0)
424
                    if (BATcapacity_remain > BATcapacity_full && BATcapacity_design > 0)
373
                        BATcapacity_full = BATcapacity_design;
425
                        BATcapacity_full = BATcapacity_design;
374
                }
426
                }
427
#else
428
		union acpi_battery_ioctl_arg battio;
429
#define UNKNOWN_CAP 0xffffffff                                                  
430
#define UNKNOWN_VOLTAGE 0xffffffff                                              
431
	    
432
		battio.unit = i;
433
		if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) != -1) {
434
		    if (battio.bif.dcap != UNKNOWN_CAP)
435
			BATcapacity_design = battio.bif.dcap;
436
		    if (battio.bif.lfcap != UNKNOWN_CAP)
437
			BATcapacity_full = battio.bif.lfcap;
438
                    if (BATcapacity_remain > BATcapacity_full && BATcapacity_design > 0)
439
                        BATcapacity_full = BATcapacity_design;
440
		}
441
#endif
375
                acpiBatteries[i]->capacity_full = BATcapacity_full;
442
                acpiBatteries[i]->capacity_full = BATcapacity_full;
376
            }
443
            }
377
            else {
444
            else {
Lines 380-385 void YApm::AcpiStr(char *s, bool Tool) { Link Here
380
        }
447
        }
381
        acpiBatteries[i]->present = BATpresent;
448
        acpiBatteries[i]->present = BATpresent;
382
449
450
#ifdef __FreeBSD__
451
	close(acpifd);
452
#endif
453
454
        bat_info[0] = 0;
383
        if (!Tool &&
455
        if (!Tool &&
384
            taskBarShowApmTime &&
456
            taskBarShowApmTime &&
385
            BATpresent == BAT_PRESENT &&
457
            BATpresent == BAT_PRESENT &&
Lines 387-393 void YApm::AcpiStr(char *s, bool Tool) { Link Here
387
            BATstatus == BAT_DISCHARGING &&
459
            BATstatus == BAT_DISCHARGING &&
388
            //did we parse the needed values successfully?
460
            //did we parse the needed values successfully?
389
            BATcapacity_full >= 0 && BATcapacity_remain >= 0 && BATrate > 0) {
461
            BATcapacity_full >= 0 && BATcapacity_remain >= 0 && BATrate > 0) {
390
            BATtime_remain = (int) (60 * (double)(BATcapacity_remain) / BATrate);
462
	    if (BATtime_remain == -1)
463
        	BATtime_remain = (int) (60 * (double)(BATcapacity_remain) / BATrate);
391
            sprintf(bat_info, "%d:%02d", BATtime_remain / 60, BATtime_remain % 60);
464
            sprintf(bat_info, "%d:%02d", BATtime_remain / 60, BATtime_remain % 60);
392
        }
465
        }
393
        else if (BATpresent == BAT_PRESENT &&
466
        else if (BATpresent == BAT_PRESENT &&
Lines 397-413 void YApm::AcpiStr(char *s, bool Tool) { Link Here
397
            sprintf(bat_info, "%3.0f%%",
470
            sprintf(bat_info, "%3.0f%%",
398
                    100 * (double)BATcapacity_remain / BATcapacity_full);
471
                    100 * (double)BATcapacity_remain / BATcapacity_full);
399
        }
472
        }
400
        else {
401
            //battery is absent or we didn't parse some needed values
402
            bat_info[0] = 0;
403
        }
404
473
405
        if (BATstatus == BAT_CHARGING) {
474
        if (BATstatus == BAT_CHARGING) {
406
            if (Tool)
475
            if (Tool)
407
                strcat(bat_info, _(" - Charging"));
476
                strcat(bat_info, _(" - Charging"));
408
            else
477
            else
409
                strcat(bat_info, _("C"));
478
                strcat(bat_info, _("C"));
410
        }
479
	} else if (BATstatus == BAT_FULL && Tool)
480
                strcat(bat_info, _(" - Full"));
481
482
	if (Tool && BATrate > 0) {
483
	    sprintf(buf, " %d", BATrate);
484
            strcat(bat_info, buf);
485
	}
411
486
412
        if ((n > 0) && (*bat_info)) {
487
        if ((n > 0) && (*bat_info)) {
413
            if (Tool)
488
            if (Tool)
Lines 738-743 void YApm::PmuStr(char *s, const bool to Link Here
738
YApm::YApm(YWindow *aParent): YWindow(aParent) {
813
YApm::YApm(YWindow *aParent): YWindow(aParent) {
739
    struct dirent **de;
814
    struct dirent **de;
740
    int n, i;
815
    int n, i;
816
    size_t s;
741
    FILE *pmu_info;
817
    FILE *pmu_info;
742
                    char buf[80];
818
                    char buf[80];
743
                    FILE *fd;
819
                    FILE *fd;
Lines 747-752 YApm::YApm(YWindow *aParent): YWindow(aP Link Here
747
    fCurrentState = 0;
823
    fCurrentState = 0;
748
824
749
    //search for acpi info first
825
    //search for acpi info first
826
#ifndef __FreeBSD__
750
    n = scandir("/sys/class/power_supply", &de, 0, alphasort);
827
    n = scandir("/sys/class/power_supply", &de, 0, alphasort);
751
    if (n < 0) {
828
    if (n < 0) {
752
        n = scandir("/proc/acpi/battery", &de, 0, alphasort);
829
        n = scandir("/proc/acpi/battery", &de, 0, alphasort);
Lines 824-830 YApm::YApm(YWindow *aParent): YWindow(aP Link Here
824
            acpiACName = (char*)malloc(sizeof(char));
901
            acpiACName = (char*)malloc(sizeof(char));
825
            *acpiACName = '\0';
902
            *acpiACName = '\0';
826
        }
903
        }
904
#else
905
    int acpifd;
906
    
907
    acpifd = open(ACPIDEV, O_RDONLY);
908
    if (acpifd != -1) {
909
	mode = ACPI;
827
910
911
        //scan for batteries
912
        i = 0;
913
        while (i < 64 && batteryNum < MAX_ACPI_BATTERY_NUM) {
914
	    union acpi_battery_ioctl_arg battio;
915
	    
916
	    battio.unit = i;
917
	    if (ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio) != -1) {
918
    		acpiBatteries[batteryNum] =
919
	            (bat_info*)malloc(sizeof(bat_info));
920
	    	asprintf(&acpiBatteries[batteryNum]->name, "Battery%d", i);
921
	        //initially set as absent, to force reading of
922
	        //full-capacity value
923
	        acpiBatteries[batteryNum]->present = BAT_ABSENT;
924
	        acpiBatteries[batteryNum]->capacity_full = -1;
925
	        batteryNum++;
926
	    }
927
	    i++;
928
	}
929
930
	asprintf(&acpiACName, "AC1");
931
#endif
828
    } else if ( (pmu_info = fopen("/proc/pmu/info", "r")) != NULL) {
932
    } else if ( (pmu_info = fopen("/proc/pmu/info", "r")) != NULL) {
829
       mode = PMU;
933
       mode = PMU;
830
       char line[80];
934
       char line[80];
Lines 870-876 YApm::~YApm() { Link Here
870
}
974
}
871
975
872
void YApm::updateToolTip() {
976
void YApm::updateToolTip() {
873
    setToolTip(fCurrentState);
977
    char s[64] = {' ', ' ', ' ', 0, 0, 0, 0, 0};
978
979
    switch (mode) {
980
    case ACPI:
981
        AcpiStr(s, 1);
982
        break;
983
    case APM:
984
        ApmStr(s, 1);
985
        break;
986
    case PMU:
987
        PmuStr(s, 1);
988
        break;
989
    }
990
991
    setToolTip(s);
874
}
992
}
875
993
876
int YApm::calcInitialWidth() {
994
int YApm::calcInitialWidth() {
(-)src/aapm.h (-1 / +1 lines)
Lines 1-5 Link Here
1
1
2
#if defined(linux) || (defined (__FreeBSD__) && defined(i386)) || (defined(__NetBSD__) && defined(i386))
2
#if defined(linux) || (defined (__FreeBSD__)) || (defined(__NetBSD__) && defined(i386))
3
3
4
#include "ywindow.h"
4
#include "ywindow.h"
5
#include "ytimer.h"
5
#include "ytimer.h"
(-)src/wmtaskbar.cc (+1 lines)
Lines 458-463 void TaskBar::initApplets() { Link Here
458
#ifdef CONFIG_APPLET_APM
458
#ifdef CONFIG_APPLET_APM
459
    if (taskBarShowApm && (access(APMDEV, 0) == 0 ||
459
    if (taskBarShowApm && (access(APMDEV, 0) == 0 ||
460
                           access("/proc/acpi", 0) == 0 ||
460
                           access("/proc/acpi", 0) == 0 ||
461
                           access("/dev/acpi", 0) == 0 ||
461
	                   access("/proc/pmu", R_OK|X_OK) == 0))
462
	                   access("/proc/pmu", R_OK|X_OK) == 0))
462
    {
463
    {
463
        fApm = new YApm(this);
464
        fApm = new YApm(this);

Return to bug 138489