[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/bluetooth 273306e1e0 25/32: update the list view more i
From: |
Stefan Kangas |
Subject: |
[elpa] externals/bluetooth 273306e1e0 25/32: update the list view more intelligently |
Date: |
Mon, 3 Jan 2022 15:11:08 -0500 (EST) |
branch: externals/bluetooth
commit 273306e1e000c0f27fbfe42992bcf8a6d0b3803e
Author: Raffael Stocker <r.stocker@mnet-mail.de>
Commit: Raffael Stocker <r.stocker@mnet-mail.de>
update the list view more intelligently
The list view is not updated after every command anymore, but only when the
buffer is reverted or if in discovery mode. Properties of paired devices
are
updated by the signal handler, otherwise ‘revert-buffer’ must be called to
update. A mode line update is now forced in the adapter signal handler.
* bluetooth.el (bluetooth--update-timer): update timer
(bluetooth--update-all): new function, used in tabulated-list-revert-hook
(bluetooth--print-list): renamed from bluetooth--update-list
(bluetooth--update-print): new function
---
bluetooth.el | 40 ++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/bluetooth.el b/bluetooth.el
index 93162804bd..1da5fc1158 100644
--- a/bluetooth.el
+++ b/bluetooth.el
@@ -156,6 +156,9 @@ property and state.")
(defvar bluetooth--device-info nil "Device info obtained from Bluez.")
+(defvar bluetooth--update-timer nil
+ "The bluetooth device table update timer.")
+
;;;; internal functions
@@ -303,13 +306,15 @@ as they are used to gather the information from Bluez.")
dev-id))))
queried-devices))))
+(defun bluetooth--update-all ()
+ "Update the device info for all adapters."
+ (mapc #'bluetooth--update-device-info
+ (bluetooth--query-adapters)))
+
;; This function provides the list entries for the tabulated-list
;; view. It is called from `tabulated-list-print'.
(defun bluetooth--list-entries ()
"Provide the list entries for the tabulated view."
- (mapc #'bluetooth--update-device-info
- (bluetooth--query-adapters)) ; TODO this can later
be removed when
-
; update is by dbus change notifications
(let (dev-list)
(maphash (lambda (dev dev-info)
(push (list dev
@@ -320,14 +325,20 @@ as they are used to gather the information from Bluez.")
bluetooth--device-info)
dev-list))
-(defun bluetooth--update-list ()
- "Update the list view."
+(defun bluetooth--print-list ()
+ "Print the device list."
(with-current-buffer bluetooth-buffer-name
(tabulated-list-print t)
(and (fboundp 'hl-line-highlight)
(bound-and-true-p hl-line-mode)
(hl-line-highlight))))
+(defun bluetooth--update-print ()
+ "Update device info and print device list view."
+ (ignore-errors
+ (bluetooth--update-all)
+ (bluetooth--print-list)))
+
;; Build up the index for Imenu. This function is used as
;; `imenu-create-index-function'.
(defun bluetooth--create-imenu-index ()
@@ -366,7 +377,7 @@ as they are used to gather the information from Bluez.")
(let ((dev-id (tabulated-list-get-id)))
(apply #'bluetooth--call-method dev-id api
#'dbus-call-method-asynchronously method
- #'bluetooth--update-list :timeout bluetooth--timeout args)))
+ nil :timeout bluetooth--timeout args)))
(defun bluetooth--dbus-toggle (property api)
"Toggle boolean PROPERTY on D-Bus API."
@@ -374,14 +385,12 @@ as they are used to gather the information from Bluez.")
(value (bluetooth--call-method dev-id api
#'dbus-get-property property)))
(bluetooth--call-method dev-id api #'dbus-set-property property
- (not value))
- (bluetooth--update-list)))
+ (not value))))
(defun bluetooth--dbus-set (property arg api)
"Set PROPERTY to ARG on D-Bus API."
(let ((dev-id (tabulated-list-get-id)))
- (bluetooth--call-method dev-id api #'dbus-set-property property arg)
- (bluetooth--update-list)))
+ (bluetooth--call-method dev-id api #'dbus-set-property property arg)))
(defun bluetooth--initialize-mode-info ()
"Get the current adapter state and display it.
@@ -438,7 +447,8 @@ update the status display accordingly."
(cl-destructuring-bind (prop (value)) elt
(when-let (property (cl-rest (assoc prop
bluetooth--mode-state)))
(setf (bluetooth-property-active-p property)
value))))
- data)))
+ data)
+ (force-mode-line-update)))
(defun bluetooth--register-signal-handler ()
"Register a signal handler for adapter property changes.
@@ -4027,14 +4037,11 @@ profiles."
(bluetooth--dbus-method ,method ,api)
,@body)))
-(defvar bluetooth--update-timer nil
- "The bluetooth device table update timer.")
-
(bluetooth-defun-method "StartDiscovery" :adapter
"Start discovery mode."
(setq bluetooth--update-timer
(run-at-time nil bluetooth-update-interval
- #'bluetooth--update-list)))
+ #'bluetooth--update-print)))
(bluetooth-defun-method "StopDiscovery" :adapter
"Stop discovery mode."
@@ -4074,7 +4081,7 @@ profiles."
:adapter
#'dbus-call-method-asynchronously
"RemoveDevice"
- #'bluetooth--update-list
+ nil
:timeout
bluetooth--timeout
:object-path
:path-devid)))
@@ -4186,6 +4193,7 @@ profiles."
tabulated-list-entries #'bluetooth--list-entries
tabulated-list-padding 0
tabulated-list-sort-key (cons "Alias" nil))
+ (add-hook 'tabulated-list-revert-hook #'bluetooth--update-all)
(tabulated-list-init-header)
(tabulated-list-print)
(hl-line-mode))
- [elpa] externals/bluetooth updated (4c7d18c99b -> 7ed3db7260), Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 6aebc228b5 02/32: fix a typo in the info display, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 72cb48584f 01/32: widen address field in tab view to accommodate var-pitch fonts, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 3d0fe7ed9d 09/32: use a struct for the adapter property display in the mode line, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth ada89f2faa 10/32: clean up the signal handler function, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f971b21d66 03/32: use a structure and hash table for device-info, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 8edeb34f61 05/32: add bluetooth--adapter-properties function, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth bd95b1ca0b 15/32: revert to mapc instead of --map when used for side-effects only, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 273306e1e0 25/32: update the list view more intelligently,
Stefan Kangas <=
- [elpa] externals/bluetooth 9878aa8051 14/32: add adapter parameters in adapter-properties and devices functions, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f2d43ebab5 16/32: make bluetooth--choose-uuid somewhat more readable, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 5a49391b00 07/32: clean up device property handling (breaks info view code), Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 0627cceab3 08/32: clean up the info view code and add an adapter info view, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f75ac5e43d 11/32: clean up the method registration function, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth e69e4151ff 12/32: clean things up for readability, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth a411243fbe 17/32: add a function for bluetooth device info access, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 7a78351220 19/32: set tabulated-list-padding to 0, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 1f048b5949 20/32: clean up and drop multiple adapter plans, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth fa3761da3c 21/32: add timer to periodically update the device table in discovery mode, Stefan Kangas, 2022/01/03