From 47a341e159a7a8cb785c1f8d2a5201cc704dfe6d Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Wed, 15 Sep 2021 17:32:22 +0200 Subject: fix: #82 split windows sensibly in exwm/webkit --- org-roam-ui.el | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'org-roam-ui.el') diff --git a/org-roam-ui.el b/org-roam-ui.el index 85f9e97..45849b7 100644 --- a/org-roam-ui.el +++ b/org-roam-ui.el @@ -133,6 +133,10 @@ Defaults to #'browse-url." (defvar oru-ws nil "The websocket for org-roam-ui.") +(defvar org-roam-ui--window nil + "The window for displaying nodes opened from within ORUI. +This is mostly to prevent issues with EXWM and the Webkit browser.") + ;; (defvar org-roam-ui-ws nil ;; "The websocket server for org-roam-ui.") @@ -175,9 +179,20 @@ This serves the web-build and API over HTTP." (command (alist-get 'command msg)) (data (alist-get 'data msg))) (cond ((string= command "open") - (org-roam-node-visit - (org-roam-populate (org-roam-node-create - :id (alist-get 'id data))) (not (org-roam-buffer-p)))) + (let* ((node (org-roam-populate (org-roam-node-create + :id (alist-get 'id data)))) + (pos (org-roam-node-point node)) + (buf (org-roam-node-find-noselect node))) + (unless (window-live-p org-roam-ui--window) + (if-let ((windows (window-list)) + (or-windows (seq-filter (lambda (window) (org-roam-buffer-p (window-buffer window))) windows)) + (newest-window (car (seq-sort-by #'window-use-time #'> or-windows)))) + (setq org-roam-ui--window newest-window) + (split-window-horizontally) + (setq org-roam-ui--window (frame-selected-window)))) + (set-window-buffer org-roam-ui--window buf) + (select-window org-roam-ui--window) + (goto-char pos))) ((string= command "delete") (progn (message "Deleted %s" (alist-get 'file data)) -- cgit v1.2.3