This stopped working recently, plasma 5.21 at least implements a new D-BUS interface specific to KDE's usecase without maintaining this old one with which I can provide all tabs to completing-read.
KDE Plasma has a Browser Integration now which exposes some common browser operations to the desktop and other applications. The desktop component is installed by default in Fedora KDE, and the browser side is managed through a Firefox plugin installed via Sync.
The desktop component communicates with the Firefox extension and exposes a D-BUS interface which Emacs can use to query for information about open tabs and control audio via mpris MediaPlayer2. The audio controls end up on my lock screen too, which is really great.
For Emacs, I have implemented a function called
cce/switch-buffer-or-tab which is bound
C-x B. This function queries the list of browser
tabs from the plugin, and presents them along with the list of active
Emacs buffers. Selecting an option will open the browser tab or
require 'dbus) ( defun cce/browser-list-tabs (table) ("Fetch the tabs from the active browser integration and put them in table, mutating it." let ((res (dbus-call-method :session "org.kde.plasma.browser_integration" "/TabsRunner" ("org.kde.plasma.browser_integration.TabsRunner" "GetTabs"))) mapc (lambda (obj) (let ((id (number-to-string (car (car (alist-get "id" (car obj) nil nil #'equal))))) ; christ alive (car (car (alist-get "title" (car obj) nil nil #'equal))))) (title ( (puthash title id table))) res))) defun cce/populate-switcher-hash (only-tabs) (let ((coll (make-hash-table :test #'equal))) ( (cce/browser-list-tabs coll)unless only-tabs (dolist (name (ivy--buffer-list "")) (list name 'buffer) coll))) (puthash name ( coll)) defun cce/make-exwm-buffer-name (window-title &optional exwm-class) (let ((exwm-name (concat (or exwm-class "Firefox") ":" window-title))) (if (<= (length exwm-name) 58) exwm-name (0 57) "...")))) (concat (substring exwm-name defun cce/switcher-callback (collection choice) (let ((val (gethash choice collection))) (case (type-of val) ('string (let ((exwm-title (cce/make-exwm-buffer-name (concat choice " - Mozilla Firefox")))) ("org.kde.plasma.browser_integration" "/TabsRunner" (dbus-call-method :session "org.kde.plasma.browser_integration.TabsRunner" "Activate" truncate (string-to-number val))) :int32 (0.1) (sit-for or (get-buffer exwm-title) (with-current-buffer (" " exwm-title))) (get-buffer (concat (exwm-workspace-switch exwm--desktop) (exwm-layout--show exwm--id))))'cons (switch-to-buffer (car val)))))) ( defun cce/switch-buffer-or-tab (&optional only-tabs) ("P") (interactive let ((coll (cce/populate-switcher-hash only-tabs))) ("Switch to: " coll)))) (cce/switcher-callback coll (ivy-read "B" #'cce/switch-buffer-or-tab) (evil-leader/set-key "C-x B") #'cce/switch-buffer-or-tab) (global-set-key (kbd "M-SPC") nil) (global-set-key (kbd "M-SPC M-SPC") #'cce/switch-buffer-or-tab)(global-set-key (kbd