From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Ahmed Khanzada Newsgroups: gmane.emacs.devel Subject: [PATCH] Fix battery information on FreeBSD Date: Mon, 11 Mar 2019 15:47:05 -0700 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="253984"; mail-complaints-to="usenet@blaine.gmane.org" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 12 00:06:40 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3U0E-0013vA-R9 for ged-emacs-devel@m.gmane.org; Tue, 12 Mar 2019 00:06:38 +0100 Original-Received: from localhost ([127.0.0.1]:41739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3U0D-00060w-Nq for ged-emacs-devel@m.gmane.org; Mon, 11 Mar 2019 19:06:37 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:45998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3TuR-0000lV-Cc for emacs-devel@gnu.org; Mon, 11 Mar 2019 19:00:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3ThX-0008My-UF for emacs-devel@gnu.org; Mon, 11 Mar 2019 18:47:21 -0400 Original-Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:33238) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3ThX-0008M0-Hx for emacs-devel@gnu.org; Mon, 11 Mar 2019 18:47:19 -0400 Original-Received: by mail-lj1-x243.google.com with SMTP id z7so603171lji.0 for ; Mon, 11 Mar 2019 15:47:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enzu-ru.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=rhkhT/Pcy4+wsuXp1nwYi+Yh6oGUuY7WWhCLNN97pXs=; b=U6xNMU2HJtuXegUewyObpbJvH7epctQrCXEn6Kqq7j7rLaMiFCFZYNYDs8UkKUInux Bk8SMDfWvbUWYCcJqpaSkRJzyByDJicfymN/h8yANiW79paW5vfMAL/tPjsdX2aolc82 fr3+VMAllMBZNJPt3ZiGQxfGXwC2H3QE2K8kWXTrs0nV/JRJak5NgO6BIrV+cuQBjlxZ fd6qJokjSiL0THN2TwoWrECTkeSBm+WvH9fNjnKc8lEAn/4myIa9RBhfB9C/fInBZXsC MvcyYMwx6ofweQFzfojua9PLu7L1tzxCc6HIyXPEnHbGOeY3nuKJK6yoWZlPJtl47x4y 5Ltg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=rhkhT/Pcy4+wsuXp1nwYi+Yh6oGUuY7WWhCLNN97pXs=; b=NmkWcFYdCcxJMl9VtyCZX2UKUPMLH+g0ziWtF8X8ZK8zvR2Jpay3eHfE2965qIaQx9 UeE4V1PSFNrZrgnu91uJ72uEzdZVddqqpRnKQXp7irQmSd5Y6B0uR0YmUw7PGVWDF8F4 zLGJbw40Gyqc0sU5VoJ2lX0DfC72ZTQTDv6ve0qiV7qR964qsVgLocnh2qmFrZV1+SRE pmhD9Nc1WirHSE5zrn5NGTr2gU8YAgxnvVcmhZAeV5+IK22sKkhAND6xJ44Psf9+Eo2N NKar36XPWKDpgiy1CWJGknGTwf4Y2r+vjiM48RJwORUea1XAau7aUTwE8+efp1RYSDj2 4yUw== X-Gm-Message-State: APjAAAUzxGJmo/hf2/cUIxBk21qtUzKFTrF0/a9yZ16QJ/XGQ1DPeCJy GQBgl6YKyLtqpC0JXKvNkdMrHegWTTFhtOsNDg7hi77O5YWpk7/d X-Google-Smtp-Source: APXvYqxCLRdxWqJb7lWCn7O3cbZoRAwO0m3EeA9XvELmPdeFN92KNi0CskchYcWwBGYJOwqYWczr9nIosdXD0BBShx8= X-Received: by 2002:a2e:97ce:: with SMTP id m14mr17861484ljj.162.1552344436553; Mon, 11 Mar 2019 15:47:16 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::243 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:234081 Archived-At: I just emailed my signed document to become a GNU contributor. I am in the US so my turnaround should be quick. Battery status was not working for me on FreeBSD. I have made an attempt to fix that. Sorry if I am doing anything wrong. I will need some guidance on this patching process. I hope to be an efficient GNU contributor soon. I have only tested this on FreeBSD, as I do not have a laptop with OpenBSD or NetBSD on it. I was wondering if maybe I should test these changes on those OSs on some USB stick. Man documents for APM on each BSD platform: NetBSD: http://netbsd.gw.com/cgi-bin/man-cgi?apm++NetBSD-current OpenBSD: https://man.openbsd.org/apm.8 FreeBSD: https://www.freebsd.org/cgi/man.cgi?apm diff --git a/lisp/battery.el b/lisp/battery.el index efd2a2181a..b14a9e45c2 100644 --- a/lisp/battery.el +++ b/lisp/battery.el @@ -618,30 +618,37 @@ battery-bsd-apm %t Remaining battery charge time in the form `h:min'" (let* ((os-name (car (split-string (shell-command-to-string "/usr/bin/uname")))) - (apm-flag (if (equal os-name "OpenBSD") "P" "s")) - (apm-cmd (concat "/usr/sbin/apm -ablm" apm-flag)) + (apm-flag (if (equal os-name "OpenBSD") "Pm")) + (apm-flag (if (equal os-name "NetBSD") "sm")) + (apm-flag (if (equal os-name "FreeBSD") "st")) + (apm-cmd (concat "/usr/sbin/apm -abl" apm-flag)) (apm-output (split-string (shell-command-to-string apm-cmd))) + (battery-status-index (if (equal os-name "FreeBSD") 1 0)) + (apm-mode-index (if (equal os-name "FreeBSD") 3 4)) + (battery-percentage-index (if (equal os-name "FreeBSD") 2 1)) + (battery-life-index (if (equal os-name "FreeBSD") 4 3)) + (ac-index (if (equal os-name "FreeBSD") 0 3)) ;; Battery status (battery-status - (let ((stat (string-to-number (nth 0 apm-output)))) + (let ((stat (string-to-number (nth battery-status-index apm-output)))) (cond ((eq stat 0) '("high" . "")) ((eq stat 1) '("low" . "-")) ((eq stat 2) '("critical" . "!")) ((eq stat 3) '("charging" . "+")) ((eq stat 4) '("absent" . nil))))) ;; Battery percentage - (battery-percentage (nth 1 apm-output)) + (battery-percentage (nth battery-percentage-index apm-output)) ;; Battery life - (battery-life (nth 2 apm-output)) + (battery-life (nth battery-life-index apm-output)) ;; AC status (line-status - (let ((ac (string-to-number (nth 3 apm-output)))) + (let ((ac (string-to-number (nth ac-index apm-output)))) (cond ((eq ac 0) "disconnected") ((eq ac 1) "connected") ((eq ac 2) "backup power")))) ;; Advanced power savings mode (apm-mode - (let ((apm (string-to-number (nth 4 apm-output)))) + (let ((apm (string-to-number (nth apm-mode-index apm-output)))) (if (string= os-name "OpenBSD") (cond ((eq apm 0) "manual") ((eq apm 1) "automatic")